@whyshu/argent-engine 0.8.0-rc.8 → 0.13.27

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 (113) hide show
  1. package/MANIFEST.json +109 -43
  2. package/bin/runtime-install.mjs +92 -0
  3. package/engine/VERSION +1 -1
  4. package/engine/configs/billing-actions.json +30 -0
  5. package/engine/configs/mcp-tools.snapshot.json +47 -0
  6. package/engine/core/contracts/argent.contracts.json +3 -3
  7. package/engine/core/contracts/verbs.schema.json +64 -1
  8. package/engine/core/lib/account-token.mjs +37 -0
  9. package/engine/core/lib/contract.mjs +30 -0
  10. package/engine/core/lib/redact.mjs +34 -0
  11. package/engine/core/mcp/billing-upload.mjs +77 -0
  12. package/engine/core/mcp/erp-server.mjs +300 -0
  13. package/engine/core/mcp/gateway.mjs +333 -0
  14. package/engine/core/mcp/meter.mjs +101 -0
  15. package/engine/core/mcp/server.mjs +416 -2
  16. package/engine/core/mcp/vault.mjs +78 -0
  17. package/engine/scripts/appointment-worker.mjs +456 -35
  18. package/engine/scripts/appointment_grab.py +1389 -264
  19. package/engine/scripts/appointment_rules.py +118 -0
  20. package/engine/scripts/argent-timers.mjs +227 -0
  21. package/engine/scripts/argent-web-preflight.mjs +123 -0
  22. package/engine/scripts/argent-web-verify.mjs +105 -0
  23. package/engine/scripts/billing-upload.mjs +26 -0
  24. package/engine/scripts/build-doc-index.mjs +68 -0
  25. package/engine/scripts/build-engine-package.mjs +7 -1
  26. package/engine/scripts/capability-packs.lock.json +323 -300
  27. package/engine/scripts/check-docs-drift.mjs +51 -4
  28. package/engine/scripts/check-version-consistency.mjs +14 -1
  29. package/engine/scripts/ci-run.sh +2 -2
  30. package/engine/scripts/collect-intel.mjs +108 -0
  31. package/engine/scripts/daily-report-timer-plist.sh +18 -4
  32. package/engine/scripts/daily-report-timers.sh +36 -3
  33. package/engine/scripts/daily-report.mjs +78 -2
  34. package/engine/scripts/doc-status.mjs +212 -0
  35. package/engine/scripts/dsh-web-doctor.mjs +84 -0
  36. package/engine/scripts/engine-manifest.mjs +90 -0
  37. package/engine/scripts/engine-runtime-install.mjs +92 -0
  38. package/engine/scripts/erp-ui-install.mjs +127 -0
  39. package/engine/scripts/erp-ui-preflight.mjs +104 -0
  40. package/engine/scripts/erp-ui-verify.mjs +135 -0
  41. package/engine/scripts/flow-requirements.json +122 -99
  42. package/engine/scripts/full-exec-worker.mjs +251 -0
  43. package/engine/scripts/gen-preset-rows.mjs +1 -1
  44. package/engine/scripts/invoice_lip_runner.py +1 -0
  45. package/engine/scripts/invoice_runner.py +17 -6
  46. package/engine/scripts/invoice_stageb.py +21 -4
  47. package/engine/scripts/lib/bootcheck-wiring.mjs +7 -5
  48. package/engine/scripts/lib/intel-card.mjs +43 -0
  49. package/engine/scripts/lib/invoice_names.py +23 -0
  50. package/engine/scripts/lib/ml-ads-core.mjs +100 -18
  51. package/engine/scripts/lib/ml-ads-rules.mjs +275 -0
  52. package/engine/scripts/lib/ml-bridge-auth.mjs +50 -0
  53. package/engine/scripts/lib/ml-category-core.mjs +120 -0
  54. package/engine/scripts/lib/ml-insight-core.mjs +621 -0
  55. package/engine/scripts/lib/ml-insight-facts.mjs +424 -0
  56. package/engine/scripts/lib/ml-items.mjs +40 -0
  57. package/engine/scripts/lib/ml-listing-core.mjs +342 -0
  58. package/engine/scripts/lib/ml-market-core.mjs +774 -0
  59. package/engine/scripts/lib/plugin-packages.mjs +13 -0
  60. package/engine/scripts/lib/webdriver_ipc.py +61 -1
  61. package/engine/scripts/line_pack.py +196 -0
  62. package/engine/scripts/mcp-gateway-switch.mjs +100 -0
  63. package/engine/scripts/migrate-providers.mjs +3 -3
  64. package/engine/scripts/ml-ads-advice.mjs +140 -0
  65. package/engine/scripts/ml-ads.mjs +221 -0
  66. package/engine/scripts/ml-category-baseline.mjs +174 -0
  67. package/engine/scripts/ml-insight-diagnose.mjs +247 -0
  68. package/engine/scripts/ml-insight-run.sh +183 -0
  69. package/engine/scripts/ml-insight-timers.sh +224 -0
  70. package/engine/scripts/ml-listing-audit.mjs +170 -0
  71. package/engine/scripts/ml-market-matrix.mjs +84 -0
  72. package/engine/scripts/ml-market-snapshot.mjs +261 -0
  73. package/engine/scripts/ml-messages.mjs +145 -0
  74. package/engine/scripts/ml-oauth-setup.mjs +1 -1
  75. package/engine/scripts/npm-publish-argent.mjs +14 -0
  76. package/engine/scripts/ops-codefix-pr.mjs +87 -0
  77. package/engine/scripts/ops-codefix-queue.mjs +30 -0
  78. package/engine/scripts/ops-digest.mjs +98 -0
  79. package/engine/scripts/ops-verify.mjs +67 -0
  80. package/engine/scripts/orchestrator.py +410 -20
  81. package/engine/scripts/orchestrator_br.py +146 -4
  82. package/engine/scripts/plugin-bootcheck.mjs +50 -1
  83. package/engine/scripts/publish-engine.mjs +111 -0
  84. package/engine/scripts/restart-dsh-with-tunnel.sh +129 -0
  85. package/engine/scripts/skuflow_invoice_runner.py +43 -3
  86. package/engine/scripts/v0.9-acceptance.mjs +107 -0
  87. package/engine/scripts/vertical-lint.mjs +12 -1
  88. package/engine/scripts/web-switch.mjs +121 -0
  89. package/engine/scripts/wenyao_fill_template.py +52 -15
  90. package/engine/scripts/wenyao_run.py +2 -1
  91. package/engine/skills/README.md +3 -3
  92. package/engine/skills/bilibili-upload/SKILL.md +109 -0
  93. package/engine/skills/douyin-upload/SKILL.md +74 -0
  94. package/engine/skills/internal.json +28 -0
  95. package/engine/skills/kuaishou-upload/SKILL.md +109 -0
  96. package/engine/skills/ml-appointment-safety/SKILL.md +42 -0
  97. package/engine/skills/ml-full-appointment/SKILL.md +23 -0
  98. package/engine/skills/ml-invoice/SKILL.md +2 -2
  99. package/engine/skills/ml-invoice/references/template-fill-contract.md +1 -1
  100. package/engine/skills/ml-label-recovery/SKILL.md +43 -0
  101. package/engine/skills/ml-listing-audit/SKILL.md +66 -0
  102. package/engine/skills/ml-store-daily-report/SKILL.md +68 -0
  103. package/engine/skills/ml-store-daily-report/scripts/generate.js +35 -0
  104. package/engine/skills/ml-store-insight/SKILL.md +81 -0
  105. package/engine/skills/tencent-upload/SKILL.md +60 -0
  106. package/engine/skills/weibo-upload/SKILL.md +106 -0
  107. package/engine/skills/whyshu-social-ops/SKILL.md +136 -0
  108. package/engine/skills/xiaohongshu-upload/SKILL.md +122 -0
  109. package/engine/version.mjs +1 -1
  110. package/engine/verticals/README.md +7 -0
  111. package/engine/verticals/_engine-words.baseline.txt +27 -59
  112. package/engine/verticals/mercadolibre/manifest.json +132 -6
  113. package/package.json +5 -1
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 运维日报(问述内部):拉取运维层 overview/incidents,输出 Markdown。
4
+ * 用法:node scripts/ops-digest.mjs [--json]
5
+ * 凭据:OPS_TOKEN 环境变量 或 ~/.dsh/argent/ops-token.env(600,仅本机)
6
+ * 设计:docs/Argent-运维层-客户机健康与自愈-设计与操作方案.md §8
7
+ */
8
+ import { readFileSync, mkdirSync, writeFileSync } from 'node:fs'
9
+ import { homedir } from 'node:os'
10
+ import { join } from 'node:path'
11
+
12
+ const BASE = process.env.OPS_BASE || 'https://whyshu.com'
13
+ const RULE_LABEL = {
14
+ task_tab_mismatch: '任务数 > 预约标签页', store_over_concurrency: '同店超并发',
15
+ task_stalled: '任务卡死', window_missing: '窗口缺失/不可用',
16
+ noise_tab_present: '噪音标签', duplicate_shipment_task: '同货件重复任务',
17
+ machine_offline: '客户机离线', version_drift: '版本落后',
18
+ platform_no_slot: '平台无号(黑五常态)',
19
+ }
20
+
21
+ function opsToken() {
22
+ if (process.env.OPS_TOKEN) return process.env.OPS_TOKEN
23
+ try {
24
+ const raw = readFileSync(join(homedir(), '.dsh', 'argent', 'ops-token.env'), 'utf8')
25
+ const m = raw.match(/^OPS_TOKEN=(.+)$/m)
26
+ return m ? m[1].trim() : ''
27
+ } catch { return '' }
28
+ }
29
+
30
+ async function get(path) {
31
+ const token = opsToken()
32
+ if (!token) throw new Error('缺少 OPS_TOKEN(~/.dsh/argent/ops-token.env)')
33
+ const res = await fetch(`${BASE}${path}`, { headers: { 'x-ops-token': token }, signal: AbortSignal.timeout(15000) })
34
+ const json = await res.json().catch(() => ({}))
35
+ if (!res.ok) throw new Error(json?.error?.message || `HTTP ${res.status}`)
36
+ return json.data ?? json
37
+ }
38
+
39
+ const jsonMode = process.argv.includes('--json')
40
+ const [overview, incs, logsResp] = await Promise.all([
41
+ get('/api/ops/v1/internal/overview'),
42
+ get('/api/ops/v1/internal/incidents?status=open&limit=200'),
43
+ get('/api/ops/v1/internal/remediation-logs?limit=50').catch(() => ({ logs: [] })),
44
+ ])
45
+ const machines = overview.machines || []
46
+ const incidents = incs.incidents || []
47
+ const logs = (logsResp && logsResp.logs) || []
48
+ const dayAgo = Date.now() - 24 * 3600 * 1000
49
+ const recentLogs = logs.filter((x) => x.createdAt && new Date(x.createdAt).getTime() >= dayAgo)
50
+ const logCount = {}
51
+ for (const x of recentLogs) logCount[x.action] = (logCount[x.action] || 0) + 1
52
+ const now = new Date()
53
+ const online = machines.filter((m) => m.online).length
54
+
55
+ if (jsonMode) {
56
+ console.log(JSON.stringify({ at: now.toISOString(), overview, incidents }, null, 2))
57
+ process.exit(0)
58
+ }
59
+
60
+ const lines = []
61
+ lines.push(`# 运维日报 ${now.toLocaleString('zh-CN', { hour12: false })}`)
62
+ lines.push('')
63
+ lines.push(`## 概览`)
64
+ lines.push(`- 客户机:${online}/${machines.length} 在线`)
65
+ lines.push(`- 未闭环 incident:${incidents.length}(critical ${incidents.filter((x) => x.level === 'critical').length} / warning ${incidents.filter((x) => x.level === 'warning').length})`)
66
+ for (const m of machines) {
67
+ const stores = m.storeDetail || []
68
+ const mismatch = stores.filter((s) => (s.claimed || 0) > (s.appointmentTabs || 0)).length
69
+ lines.push(`- ${m.tenantId} / ${m.machineId}:${m.online ? '在线' : `离线 ${m.offlineFor ?? '?'} 分钟`},插件 ${m.pluginVersion || '-'} / 引擎 ${m.engineVersion || '-'},店铺 ${stores.length}${mismatch ? `,**${mismatch} 个店铺任务数>标签页数**` : ''}`)
70
+ }
71
+ lines.push('')
72
+ lines.push(`## 最近 24h 自愈审计`)
73
+ lines.push(recentLogs.length ? Object.entries(logCount).map(([k, n]) => `- ${k} ×${n}`).join('\n') : '- 无')
74
+ lines.push('')
75
+ lines.push(`## 未闭环 incident`)
76
+ if (!incidents.length) lines.push('- 无')
77
+ else {
78
+ for (const x of incidents.slice(0, 30)) {
79
+ lines.push(`- [${x.level}] ${x.tenantId} / ${x.machineId} / ${x.store || '-'}:${RULE_LABEL[x.rule] || x.rule} ×${x.count ?? 1}(${new Date(x.lastSeenAt).toLocaleString('zh-CN', { hour12: false })})`)
80
+ }
81
+ if (incidents.length > 30) lines.push(`- … 其余 ${incidents.length - 30} 条`)
82
+ }
83
+ const md = lines.join('\n') + '\n'
84
+ // 写入运维层(看板展示最新日报;--no-push 可跳过)
85
+ if (!process.argv.includes('--no-push')) {
86
+ try {
87
+ const res = await fetch(`${BASE}/api/ops/v1/internal/digest`, {
88
+ method: 'POST',
89
+ headers: { 'content-type': 'application/json', 'x-ops-token': opsToken() },
90
+ body: JSON.stringify({ markdown: md, summary: { machines: machines.length, online, incidents: incidents.length, at: now.toISOString() } }),
91
+ signal: AbortSignal.timeout(10000),
92
+ })
93
+ if (!res.ok) console.error('日报写入运维层失败:', res.status)
94
+ } catch (e) { console.error('日报写入运维层失败:', e.message) }
95
+ }
96
+ const dir = join(homedir(), '.dsh', 'argent', 'ops-digests')
97
+ try { mkdirSync(dir, { recursive: true }); writeFileSync(join(dir, `${now.toISOString().slice(0, 10)}.md`), md) } catch { /* noop */ }
98
+ console.log(md)
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 运维层验收脚本(问述内部):心跳新鲜度 / 版本 / 任务数 vs 标签页 / incident。
4
+ * 用法:node scripts/ops-verify.mjs [--min-version 0.12.5] [--max-heartbeat-age 180]
5
+ * 退出码:0 全部通过;1 有失败项(输出逐项结果)。
6
+ */
7
+ import { readFileSync } from 'node:fs'
8
+ import { homedir } from 'node:os'
9
+ import { join } from 'node:path'
10
+
11
+ const BASE = process.env.OPS_BASE || 'https://whyshu.com'
12
+ const args = process.argv.slice(2)
13
+ const opt = (n, d) => { const i = args.indexOf(`--${n}`); return i >= 0 ? args[i + 1] : d }
14
+ const MIN_VERSION = opt('min-version', '')
15
+ const ONLY_MACHINE = opt('machine', '')
16
+ const MAX_AGE = Number(opt('max-heartbeat-age', '180'))
17
+
18
+ function token() {
19
+ if (process.env.OPS_TOKEN) return process.env.OPS_TOKEN
20
+ try {
21
+ const raw = readFileSync(join(homedir(), '.dsh', 'argent', 'ops-token.env'), 'utf8')
22
+ const m = raw.match(/^OPS_TOKEN=(.+)$/m)
23
+ return m ? m[1].trim() : ''
24
+ } catch { return '' }
25
+ }
26
+ async function get(path) {
27
+ const res = await fetch(`${BASE}${path}`, { headers: { 'x-ops-token': token() }, signal: AbortSignal.timeout(15000) })
28
+ const j = await res.json().catch(() => ({}))
29
+ if (!res.ok) throw new Error(j?.error?.message || `HTTP ${res.status}`)
30
+ return j.data ?? j
31
+ }
32
+ const cmp = (a, b) => {
33
+ const pa = String(a || '').split('.').map(Number), pb = String(b || '').split('.').map(Number)
34
+ for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
35
+ const x = pa[i] || 0, y = pb[i] || 0
36
+ if (x !== y) return x > y ? 1 : -1
37
+ }
38
+ return 0
39
+ }
40
+
41
+ const checks = []
42
+ const ok = (name, cond, detail = '') => checks.push({ name, ok: Boolean(cond), detail })
43
+ try {
44
+ const [overview, incs] = await Promise.all([get('/api/ops/v1/internal/overview'), get('/api/ops/v1/internal/incidents?status=open&limit=200')])
45
+ const allMachines = overview.machines || []
46
+ const machines = ONLY_MACHINE ? allMachines.filter((m) => String(m.machineId) === ONLY_MACHINE) : allMachines
47
+ ok('存在客户机心跳', machines.length > 0, `machines=${machines.length}`)
48
+ for (const m of machines) {
49
+ const ageMin = m.at ? Math.round((Date.now() - new Date(m.at).getTime()) / 60000) : null
50
+ ok(`心跳新鲜:${m.machineId}`, ageMin != null && ageMin <= MAX_AGE, `age=${ageMin}min`)
51
+ if (MIN_VERSION) ok(`插件版本:${m.machineId} >= ${MIN_VERSION}`, cmp(m.pluginVersion, MIN_VERSION) >= 0, `plugin=${m.pluginVersion}`)
52
+ for (const s of m.storeDetail || []) {
53
+ if (Number(s.claimed) > Number(s.appointmentTabs)) ok(`任务数<=标签页:${s.store}`, false, `claimed=${s.claimed} tabs=${s.appointmentTabs}`)
54
+ else ok(`任务数<=标签页:${s.store}`, true, `claimed=${s.claimed} tabs=${s.appointmentTabs}`)
55
+ ok(`窗口可连:${s.store}`, Boolean(s.cdpPort) || Number(s.claimed) === 0, `port=${s.cdpPort || 0}`)
56
+ }
57
+ }
58
+ const critical = (incs.incidents || []).filter((x) => x.level === 'critical')
59
+ ok('无 critical incident', critical.length === 0, critical.map((x) => `${x.rule}@${x.machineId}/${x.store || '-'}`).join('; '))
60
+ } catch (e) {
61
+ ok('拉取运维数据', false, e.message)
62
+ }
63
+
64
+ const failed = checks.filter((c) => !c.ok)
65
+ for (const c of checks) console.log(`${c.ok ? '✅' : '❌'} ${c.name}${c.detail ? `(${c.detail})` : ''}`)
66
+ console.log(`\n${failed.length ? `❌ ${failed.length} 项未通过` : '✅ 全部通过'}`)
67
+ process.exit(failed.length ? 1 : 0)