@whyshu/argent-engine 0.8.0-rc.9 → 0.13.28
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/MANIFEST.json +102 -40
- package/bin/runtime-install.mjs +92 -0
- package/engine/VERSION +1 -1
- package/engine/configs/billing-actions.json +30 -0
- package/engine/configs/mcp-tools.snapshot.json +47 -0
- package/engine/core/contracts/argent.contracts.json +2 -2
- package/engine/core/lib/account-token.mjs +37 -0
- package/engine/core/lib/redact.mjs +34 -0
- package/engine/core/mcp/billing-upload.mjs +77 -0
- package/engine/core/mcp/erp-server.mjs +300 -0
- package/engine/core/mcp/gateway.mjs +333 -0
- package/engine/core/mcp/meter.mjs +101 -0
- package/engine/core/mcp/server.mjs +245 -0
- package/engine/core/mcp/vault.mjs +78 -0
- package/engine/scripts/appointment-worker.mjs +456 -35
- package/engine/scripts/appointment_grab.py +1389 -264
- package/engine/scripts/appointment_rules.py +118 -0
- package/engine/scripts/argent-timers.mjs +227 -0
- package/engine/scripts/argent-web-preflight.mjs +123 -0
- package/engine/scripts/argent-web-verify.mjs +105 -0
- package/engine/scripts/billing-upload.mjs +26 -0
- package/engine/scripts/build-engine-package.mjs +7 -1
- package/engine/scripts/capability-packs.lock.json +323 -300
- package/engine/scripts/check-version-consistency.mjs +14 -1
- package/engine/scripts/collect-intel.mjs +108 -0
- package/engine/scripts/daily-report-timer-plist.sh +18 -4
- package/engine/scripts/daily-report-timers.sh +36 -3
- package/engine/scripts/daily-report.mjs +78 -2
- package/engine/scripts/dsh-web-doctor.mjs +84 -0
- package/engine/scripts/engine-manifest.mjs +90 -0
- package/engine/scripts/engine-runtime-install.mjs +92 -0
- package/engine/scripts/erp-ui-install.mjs +127 -0
- package/engine/scripts/erp-ui-preflight.mjs +104 -0
- package/engine/scripts/erp-ui-verify.mjs +135 -0
- package/engine/scripts/flow-requirements.json +122 -99
- package/engine/scripts/full-exec-worker.mjs +251 -0
- package/engine/scripts/gen-preset-rows.mjs +1 -1
- package/engine/scripts/invoice_lip_runner.py +1 -0
- package/engine/scripts/invoice_runner.py +17 -6
- package/engine/scripts/invoice_stageb.py +21 -4
- package/engine/scripts/lib/bootcheck-wiring.mjs +7 -5
- package/engine/scripts/lib/intel-card.mjs +43 -0
- package/engine/scripts/lib/invoice_names.py +23 -0
- package/engine/scripts/lib/ml-ads-core.mjs +100 -18
- package/engine/scripts/lib/ml-ads-rules.mjs +275 -0
- package/engine/scripts/lib/ml-bridge-auth.mjs +50 -0
- package/engine/scripts/lib/ml-category-core.mjs +120 -0
- package/engine/scripts/lib/ml-insight-core.mjs +621 -0
- package/engine/scripts/lib/ml-insight-facts.mjs +424 -0
- package/engine/scripts/lib/ml-items.mjs +40 -0
- package/engine/scripts/lib/ml-listing-core.mjs +342 -0
- package/engine/scripts/lib/ml-market-core.mjs +774 -0
- package/engine/scripts/lib/plugin-packages.mjs +13 -0
- package/engine/scripts/lib/webdriver_ipc.py +61 -1
- package/engine/scripts/line_pack.py +196 -0
- package/engine/scripts/mcp-gateway-switch.mjs +100 -0
- package/engine/scripts/migrate-providers.mjs +3 -3
- package/engine/scripts/ml-ads-advice.mjs +140 -0
- package/engine/scripts/ml-ads.mjs +40 -0
- package/engine/scripts/ml-category-baseline.mjs +174 -0
- package/engine/scripts/ml-insight-diagnose.mjs +247 -0
- package/engine/scripts/ml-insight-run.sh +183 -0
- package/engine/scripts/ml-insight-timers.sh +224 -0
- package/engine/scripts/ml-listing-audit.mjs +170 -0
- package/engine/scripts/ml-market-matrix.mjs +84 -0
- package/engine/scripts/ml-market-snapshot.mjs +261 -0
- package/engine/scripts/ml-messages.mjs +145 -0
- package/engine/scripts/npm-publish-argent.mjs +14 -0
- package/engine/scripts/ops-codefix-pr.mjs +87 -0
- package/engine/scripts/ops-codefix-queue.mjs +30 -0
- package/engine/scripts/ops-digest.mjs +98 -0
- package/engine/scripts/ops-verify.mjs +67 -0
- package/engine/scripts/orchestrator.py +410 -20
- package/engine/scripts/orchestrator_br.py +146 -4
- package/engine/scripts/plugin-bootcheck.mjs +50 -1
- package/engine/scripts/publish-engine.mjs +111 -0
- package/engine/scripts/restart-dsh-with-tunnel.sh +129 -0
- package/engine/scripts/skuflow_invoice_runner.py +43 -3
- package/engine/scripts/v0.9-acceptance.mjs +107 -0
- package/engine/scripts/vertical-lint.mjs +12 -1
- package/engine/scripts/web-switch.mjs +121 -0
- package/engine/scripts/wenyao_fill_template.py +52 -15
- package/engine/scripts/wenyao_run.py +2 -1
- package/engine/skills/README.md +3 -3
- package/engine/skills/bilibili-upload/SKILL.md +109 -0
- package/engine/skills/douyin-upload/SKILL.md +74 -0
- package/engine/skills/internal.json +28 -0
- package/engine/skills/kuaishou-upload/SKILL.md +109 -0
- package/engine/skills/ml-appointment-safety/SKILL.md +42 -0
- package/engine/skills/ml-full-appointment/SKILL.md +23 -0
- package/engine/skills/ml-invoice/SKILL.md +2 -2
- package/engine/skills/ml-invoice/references/template-fill-contract.md +1 -1
- package/engine/skills/ml-label-recovery/SKILL.md +43 -0
- package/engine/skills/ml-listing-audit/SKILL.md +66 -0
- package/engine/skills/ml-store-daily-report/SKILL.md +68 -0
- package/engine/skills/ml-store-daily-report/scripts/generate.js +35 -0
- package/engine/skills/ml-store-insight/SKILL.md +81 -0
- package/engine/skills/tencent-upload/SKILL.md +60 -0
- package/engine/skills/weibo-upload/SKILL.md +106 -0
- package/engine/skills/whyshu-social-ops/SKILL.md +136 -0
- package/engine/skills/xiaohongshu-upload/SKILL.md +122 -0
- package/engine/version.mjs +1 -1
- package/engine/verticals/README.md +7 -0
- package/engine/verticals/_engine-words.baseline.txt +27 -59
- package/engine/verticals/mercadolibre/manifest.json +132 -6
- package/package.json +5 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""抢预约「时间规则」在引擎侧的编译(2026-11-19)。
|
|
2
|
+
|
|
3
|
+
与 ERP `appointmentRuleService.compileRulePreview` 同一口径:
|
|
4
|
+
· 工作日 = 周一至周五(周末不计入「工作日后 N 天」)
|
|
5
|
+
· leadWorkdays=0 从今天开始;N>0 往后数 N 个工作日
|
|
6
|
+
· dailyAdvanceAt 到点后起点 +1 天(按墨西哥时间)
|
|
7
|
+
· horizonDays 只约 N 天内(含起点)
|
|
8
|
+
· windows 按 ISO 周几(1=周一…7=周日)配置,可多段;空=当天不约
|
|
9
|
+
· skipDates 跳过
|
|
10
|
+
|
|
11
|
+
平台时区固定 America/Mexico_City = UTC-6(墨西哥 2022 年起无夏令时),
|
|
12
|
+
引擎运行在客户机(中国时区)⇒ 所有“今天/到点判断”都必须走本模块,⛔ 不用本机时间。
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from datetime import date, datetime, timedelta, timezone
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
MX_TZ = timezone(timedelta(hours=-6))
|
|
20
|
+
_WD_CACHE: dict[str, Any] = {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def mexico_now(now: datetime | None = None) -> datetime:
|
|
24
|
+
if now is None:
|
|
25
|
+
return datetime.now(MX_TZ)
|
|
26
|
+
if now.tzinfo is None:
|
|
27
|
+
return now.replace(tzinfo=MX_TZ)
|
|
28
|
+
return now.astimezone(MX_TZ)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _minutes(hhmm: str) -> int | None:
|
|
32
|
+
try:
|
|
33
|
+
h, m = str(hhmm).split(':')[:2]
|
|
34
|
+
return int(h) * 60 + int(m)
|
|
35
|
+
except Exception:
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _is_workday(d: date, skip: set[str]) -> bool:
|
|
40
|
+
return d.isoweekday() <= 5 and d.isoformat() not in skip
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def compile_rule(spec: dict | None, today: date, *, now: datetime | None = None) -> dict[str, list[dict]]:
|
|
44
|
+
"""返回 {YYYY-MM-DD: [{from, to}, ...]};空 dict = 当前没有可约日期。"""
|
|
45
|
+
spec = spec if isinstance(spec, dict) else {}
|
|
46
|
+
skip = {str(x) for x in (spec.get('skipDates') or []) if str(x)}
|
|
47
|
+
try:
|
|
48
|
+
lead = max(0, int(spec.get('leadWorkdays') or 0))
|
|
49
|
+
except Exception:
|
|
50
|
+
lead = 0
|
|
51
|
+
try:
|
|
52
|
+
horizon = max(1, int(spec.get('horizonDays') or 7))
|
|
53
|
+
except Exception:
|
|
54
|
+
horizon = 7
|
|
55
|
+
windows = spec.get('windows') or {}
|
|
56
|
+
advance_raw = str(spec.get('dailyAdvanceAt') or '').strip()
|
|
57
|
+
advance = _minutes(advance_raw) if advance_raw else None
|
|
58
|
+
clock = mexico_now(now)
|
|
59
|
+
|
|
60
|
+
start = today
|
|
61
|
+
if lead > 0:
|
|
62
|
+
counted = 0
|
|
63
|
+
while counted < lead:
|
|
64
|
+
start = start + timedelta(days=1)
|
|
65
|
+
if _is_workday(start, skip):
|
|
66
|
+
counted += 1
|
|
67
|
+
if advance is not None and (clock.hour * 60 + clock.minute) >= advance:
|
|
68
|
+
start = start + timedelta(days=1)
|
|
69
|
+
|
|
70
|
+
out: dict[str, list[dict]] = {}
|
|
71
|
+
for i in range(horizon):
|
|
72
|
+
d = start + timedelta(days=i)
|
|
73
|
+
key = d.isoformat()
|
|
74
|
+
if key in skip:
|
|
75
|
+
continue
|
|
76
|
+
raw = windows.get(d.isoweekday()) or windows.get(str(d.isoweekday())) or []
|
|
77
|
+
segs: list[dict] = []
|
|
78
|
+
for seg in raw if isinstance(raw, list) else []:
|
|
79
|
+
frm = str((seg or {}).get('from') or '').strip()
|
|
80
|
+
to = str((seg or {}).get('to') or '').strip()
|
|
81
|
+
fm, tm = _minutes(frm), _minutes(to)
|
|
82
|
+
if fm is None or tm is None or fm >= tm:
|
|
83
|
+
continue
|
|
84
|
+
segs.append({'from': frm, 'to': to})
|
|
85
|
+
if segs:
|
|
86
|
+
out[key] = segs
|
|
87
|
+
return out
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def targets(spec: dict | None, today: date, *, now: datetime | None = None) -> list[date]:
|
|
91
|
+
return sorted(date.fromisoformat(k) for k in compile_rule(spec, today, now=now))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def slot_datetime(date_iso: str, slot_text: str) -> datetime | None:
|
|
95
|
+
"""把平台日期+时段文本(9:45 / 09:45)转成墨西哥绝对时间;解析失败返回 None。"""
|
|
96
|
+
try:
|
|
97
|
+
base = date.fromisoformat(str(date_iso)[:10])
|
|
98
|
+
except ValueError:
|
|
99
|
+
return None
|
|
100
|
+
import re
|
|
101
|
+
m = re.search(r'(\d{1,2})\s*[::.]\s*(\d{2})', str(slot_text or ''))
|
|
102
|
+
if not m:
|
|
103
|
+
return None
|
|
104
|
+
return datetime(base.year, base.month, base.day, int(m.group(1)), int(m.group(2)), tzinfo=MX_TZ)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def min_lead_ok(date_iso: str, slot_text: str, min_hours: float, *, now: datetime | None = None) -> bool:
|
|
108
|
+
"""预约绝对时间是否 ≥ 现在 + 至少提前小时数。无法解析的时段不拦(交给页面真实时段判断)。"""
|
|
109
|
+
try:
|
|
110
|
+
hours = float(min_hours or 0)
|
|
111
|
+
except Exception:
|
|
112
|
+
hours = 0
|
|
113
|
+
if hours <= 0:
|
|
114
|
+
return True
|
|
115
|
+
dt = slot_datetime(date_iso, slot_text)
|
|
116
|
+
if dt is None:
|
|
117
|
+
return True
|
|
118
|
+
return dt >= mexico_now(now) + timedelta(hours=hours)
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* argent-timers.mjs —— **系统定时器清单(只读)**:launchctl 在册 + plist 排程 + 状态文件。
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要它(2026-11-20):
|
|
6
|
+
* · 客户机上 argent 会装多条 LaunchAgent(worker / 日报 / Listing 体检 / 竞品快照…),
|
|
7
|
+
* 还有历史残留(flow-trigger / fulfillment-poll)—— 客户"到底有几条、哪条停了"没有单一出口;
|
|
8
|
+
* · 桌宠健康只显示"日报定时器"一条;ERP 控制台没有定时器视图。
|
|
9
|
+
* 本 CLI 是**唯一取数口**:MCP 工具 `argent_timers` 调它,将来 ERP 机器心跳也复用它。
|
|
10
|
+
*
|
|
11
|
+
* 纪律:
|
|
12
|
+
* · **只读**:只读 launchctl 输出 / plist 文件 / 状态 JSON;⛔ 不 bootstrap/bootout、不写任何文件;
|
|
13
|
+
* · 判据可注入(`--launchctl-file` / `--plist-dir` / `--data-dir`)⇒ 离线可回归;
|
|
14
|
+
* · 失败不静默:launchctl 不可用 ⇒ `ok:false` + 原因;单条 plist 读不了 ⇒ 该条 `schedule:null` + note。
|
|
15
|
+
*
|
|
16
|
+
* 用法:
|
|
17
|
+
* node scripts/argent-timers.mjs # 人读
|
|
18
|
+
* node scripts/argent-timers.mjs --json # 结构化(MCP / ERP 心跳复用)
|
|
19
|
+
* node scripts/argent-timers.mjs --json --launchctl-file /tmp/launchctl.txt --plist-dir /tmp/plists --data-dir /tmp/data
|
|
20
|
+
*/
|
|
21
|
+
import { execFileSync } from 'node:child_process'
|
|
22
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
|
23
|
+
import { homedir } from 'node:os'
|
|
24
|
+
import { join } from 'node:path'
|
|
25
|
+
import { pathToFileURL } from 'node:url'
|
|
26
|
+
import { resolveDataDir } from './lib/argent-datadir.mjs'
|
|
27
|
+
|
|
28
|
+
/** 已知 label 的释义与归属(未知 label 也照实列出,⛔ 不丢)。 */
|
|
29
|
+
export const KNOWN_LABELS = Object.freeze({
|
|
30
|
+
'com.whyshu.appointment-worker': { desc: '抢预约 worker(常驻)', kind: 'worker' },
|
|
31
|
+
'com.whyshu.full-booking-worker': { desc: 'FULL 自动预约 worker(full 模式)', kind: 'worker' },
|
|
32
|
+
'com.whyshu.daily-report-timer': { desc: '日报(每小时直跑脚本)', kind: 'report', statusFile: 'daily-report-timer-status.json' },
|
|
33
|
+
'com.whyshu.ml-listing-timer': { desc: 'Listing 体检 + 推 ERP', kind: 'insight', statusFile: 'ml-insight-listing-status.json' },
|
|
34
|
+
'com.whyshu.ml-market-timer': { desc: '竞品快照(只读)', kind: 'insight', statusFile: 'ml-insight-market-status.json' },
|
|
35
|
+
'com.whyshu.dsh-web': { desc: 'dsh web 宿主(按机器角色)', kind: 'host' },
|
|
36
|
+
'com.whyshu.argent-bridge': { desc: '飞书桥(按机器角色)', kind: 'host' },
|
|
37
|
+
'com.whyshu.fulfillment-poll': { desc: '旧轮询(已退役,应清理)', kind: 'retired' },
|
|
38
|
+
// 2026-11-27:客户机实测清单里出现但我们漏收录的(截图里显示"未知"的正是这些)
|
|
39
|
+
'com.whyshu.ml-insight-timer': { desc: '店铺诊断(每小时 :20 跟随日报快照)', kind: 'insight', statusFile: 'ml-insight-diagnose-status.json' },
|
|
40
|
+
'com.whyshu.ziniao-keepalive': { desc: '紫鸟浏览器保活(每 3 分钟)', kind: 'host' },
|
|
41
|
+
'com.whyshu.caffeinate': { desc: '防休眠(常驻)', kind: 'host' },
|
|
42
|
+
'com.whyshu.xzh-browser': { desc: '鑫中航浏览器(常驻,旧流程遗留)', kind: 'host' },
|
|
43
|
+
'com.whyshu.argent-runner': { desc: '旧 argent runner(旧插件版,应退役)', kind: 'retired' },
|
|
44
|
+
'com.whyshu.argent-web': { desc: '旧 argent web(旧插件版,应退役)', kind: 'retired' },
|
|
45
|
+
'com.whyshu.dsh-portforward': { desc: 'dsh 端口转发(常驻,开发机用)', kind: 'host' },
|
|
46
|
+
'com.whyshu.dsh-release-watch': { desc: '发布监控(每日,开发/运维用)', kind: 'host' },
|
|
47
|
+
'com.whyshu.usage-anchor': { desc: '用量统计锚点(每日)', kind: 'host' },
|
|
48
|
+
'com.whyshu.billing-mode-check': { desc: '计费模式自检(每 3 小时)', kind: 'host' },
|
|
49
|
+
'com.whyshu.argent-ci': { desc: 'CI 任务(运维用)', kind: 'host' },
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
/** 前缀级退役/历史判定。 */
|
|
53
|
+
export function classifyLabel(label) {
|
|
54
|
+
const name = String(label || '')
|
|
55
|
+
const hit = KNOWN_LABELS[name]
|
|
56
|
+
if (hit) return { label: name, ...hit }
|
|
57
|
+
if (name.startsWith('com.whyshu.flow-trigger')) {
|
|
58
|
+
return { label: name, desc: '流程触发器(2026-10-29 起退役;新机不应有,残留应清理)', kind: 'retired' }
|
|
59
|
+
}
|
|
60
|
+
if (name.startsWith('com.whyshu.publish-')) return { label: name, desc: '发布任务(运维用,按时段)', kind: 'host' }
|
|
61
|
+
if (name.startsWith('com.whyshu.')) return { label: name, desc: '本机运维定时器(未收录用途;技术详情可见标签)', kind: 'unknown' }
|
|
62
|
+
return { label: name, desc: '非 whyshu 标签', kind: 'other' }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 纯函数:解析 `launchctl list` 输出(每行 `PID\tStatus\tLabel`)。
|
|
67
|
+
* @returns {Array<{label:string, pid:number|null, lastExit:number|null}>}
|
|
68
|
+
*/
|
|
69
|
+
export function parseLaunchctlList(text) {
|
|
70
|
+
const out = []
|
|
71
|
+
for (const line of String(text || '').split('\n')) {
|
|
72
|
+
const cols = line.trim().split(/\s+/)
|
|
73
|
+
if (cols.length < 3) continue
|
|
74
|
+
const [pidRaw, exitRaw, ...rest] = cols
|
|
75
|
+
const label = rest.join(' ')
|
|
76
|
+
if (!label.startsWith('com.whyshu.')) continue
|
|
77
|
+
const pid = pidRaw === '-' ? null : Number(pidRaw)
|
|
78
|
+
const lastExit = exitRaw === '-' ? null : Number(exitRaw)
|
|
79
|
+
out.push({ label, pid: Number.isFinite(pid) ? pid : null, lastExit: Number.isFinite(lastExit) ? lastExit : null })
|
|
80
|
+
}
|
|
81
|
+
return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 纯函数:从 plist XML 里读排程(支持 `StartCalendarInterval` 的 Hour/Minute 与 `StartInterval` 秒)。
|
|
86
|
+
* @returns {{type:'calendar',hour:number|null,minute:number}|{type:'interval',seconds:number}|null}
|
|
87
|
+
*/
|
|
88
|
+
export function parsePlistSchedule(xml) {
|
|
89
|
+
const s = String(xml || '')
|
|
90
|
+
const cal = s.match(/<key>StartCalendarInterval<\/key>[\s\S]*?<\/dict>/)
|
|
91
|
+
if (cal) {
|
|
92
|
+
const block = cal[0]
|
|
93
|
+
const hour = block.match(/<key>Hour<\/key>\s*<integer>(\d+)<\/integer>/)
|
|
94
|
+
const minute = block.match(/<key>Minute<\/key>\s*<integer>(\d+)<\/integer>/)
|
|
95
|
+
if (minute) return { type: 'calendar', hour: hour ? Number(hour[1]) : null, minute: Number(minute[1]) }
|
|
96
|
+
}
|
|
97
|
+
const interval = s.match(/<key>StartInterval<\/key>\s*<integer>(\d+)<\/integer>/)
|
|
98
|
+
if (interval) return { type: 'interval', seconds: Number(interval[1]) }
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 纯函数:把三路事实合成清单。
|
|
104
|
+
* @param {{launchctlText?:string, plists?:Record<string,string>, statuses?:Record<string,object>}} p
|
|
105
|
+
*/
|
|
106
|
+
export function buildInventory({ launchctlText = '', plists = {}, statuses = {} } = {}) {
|
|
107
|
+
const loaded = parseLaunchctlList(launchctlText)
|
|
108
|
+
const byLabel = new Map()
|
|
109
|
+
for (const row of loaded) {
|
|
110
|
+
const c = classifyLabel(row.label)
|
|
111
|
+
const schedule = plists[row.label] ? parsePlistSchedule(plists[row.label]) : null
|
|
112
|
+
const status = c.statusFile ? statuses[c.statusFile] || null : null
|
|
113
|
+
byLabel.set(row.label, {
|
|
114
|
+
...c,
|
|
115
|
+
loaded: true,
|
|
116
|
+
pid: row.pid,
|
|
117
|
+
lastExit: row.lastExit,
|
|
118
|
+
plist: Boolean(plists[row.label]),
|
|
119
|
+
schedule,
|
|
120
|
+
lastRunAt: status?.lastRunAt || null,
|
|
121
|
+
lastFinishAt: status?.lastFinishAt || null,
|
|
122
|
+
nextDueAt: status?.nextDueAt || null,
|
|
123
|
+
lastError: status?.lastError || (row.lastExit && row.lastExit !== 0 ? `launchd lastExit=${row.lastExit}` : ''),
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
// 有 plist 但没加载(装了没 bootstrap / 被 bootout)也要可见 —— 这是"静默停摆"的常见形态
|
|
127
|
+
for (const [label, xml] of Object.entries(plists)) {
|
|
128
|
+
if (byLabel.has(label)) continue
|
|
129
|
+
const c = classifyLabel(label)
|
|
130
|
+
const status = c.statusFile ? statuses[c.statusFile] || null : null
|
|
131
|
+
byLabel.set(label, {
|
|
132
|
+
...c, loaded: false, pid: null, lastExit: null, plist: true,
|
|
133
|
+
schedule: parsePlistSchedule(xml),
|
|
134
|
+
lastRunAt: status?.lastRunAt || null, lastFinishAt: status?.lastFinishAt || null,
|
|
135
|
+
nextDueAt: status?.nextDueAt || null,
|
|
136
|
+
lastError: 'plist 在,但 launchd 未加载(装了没 bootstrap/被 bootout)',
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
const timers = [...byLabel.values()].sort((a, b) => {
|
|
140
|
+
const rank = { worker: 0, report: 1, insight: 2, host: 3, retired: 8, unknown: 9, other: 9 }
|
|
141
|
+
return (rank[a.kind] ?? 9) - (rank[b.kind] ?? 9) || a.label.localeCompare(b.label)
|
|
142
|
+
})
|
|
143
|
+
return {
|
|
144
|
+
count: timers.length,
|
|
145
|
+
loadedCount: timers.filter((t) => t.loaded).length,
|
|
146
|
+
retiredCount: timers.filter((t) => t.kind === 'retired').length,
|
|
147
|
+
missingCount: timers.filter((t) => !t.loaded).length,
|
|
148
|
+
timers,
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 取读文件的安全版(缺/坏 ⇒ null)。 */
|
|
153
|
+
function readMaybe(file) {
|
|
154
|
+
try { return readFileSync(file, 'utf8') } catch { return null }
|
|
155
|
+
}
|
|
156
|
+
function readJsonMaybe(file) {
|
|
157
|
+
const t = readMaybe(file)
|
|
158
|
+
if (!t) return null
|
|
159
|
+
try { const v = JSON.parse(t); return v && typeof v === 'object' ? v : null } catch { return null }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** 只读采集:launchctl + LaunchAgents plist + 状态文件。 */
|
|
163
|
+
export function collect({ launchctlFile = '', plistDir = '', dataDir = '' } = {}) {
|
|
164
|
+
const notes = []
|
|
165
|
+
let launchctlText = ''
|
|
166
|
+
if (launchctlFile) {
|
|
167
|
+
launchctlText = readMaybe(launchctlFile) || ''
|
|
168
|
+
if (!launchctlText) notes.push(`launchctl 文件读不到:${launchctlFile}`)
|
|
169
|
+
} else {
|
|
170
|
+
try {
|
|
171
|
+
launchctlText = execFileSync('launchctl', ['list'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
|
|
172
|
+
} catch (e) {
|
|
173
|
+
notes.push(`launchctl list 失败:${String((e && e.message) || e).slice(0, 200)}`)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const dir = plistDir || join(homedir(), 'Library', 'LaunchAgents')
|
|
177
|
+
const plists = {}
|
|
178
|
+
try {
|
|
179
|
+
for (const f of readdirSync(dir)) {
|
|
180
|
+
if (!f.endsWith('.plist') || !f.startsWith('com.whyshu.')) continue
|
|
181
|
+
const xml = readMaybe(join(dir, f))
|
|
182
|
+
if (xml) plists[f.slice(0, -'.plist'.length)] = xml
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
notes.push(`plist 目录读不到:${dir}(${String((e && e.message) || e).slice(0, 120)})`)
|
|
186
|
+
}
|
|
187
|
+
const statuses = {}
|
|
188
|
+
for (const spec of Object.values(KNOWN_LABELS)) {
|
|
189
|
+
if (!spec.statusFile) continue
|
|
190
|
+
const v = readJsonMaybe(join(dataDir, spec.statusFile))
|
|
191
|
+
if (v) statuses[spec.statusFile] = v
|
|
192
|
+
}
|
|
193
|
+
const inv = buildInventory({ launchctlText, plists, statuses })
|
|
194
|
+
return { ok: notes.length === 0 || inv.count > 0, notes, ...inv }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const isDirect = (() => {
|
|
198
|
+
try { return import.meta.url === pathToFileURL(process.argv[1] || '').href } catch { return false }
|
|
199
|
+
})()
|
|
200
|
+
|
|
201
|
+
if (isDirect) {
|
|
202
|
+
const args = process.argv.slice(2)
|
|
203
|
+
const argVal = (n) => { const i = args.indexOf(n); return i >= 0 && args[i + 1] ? args[i + 1] : null }
|
|
204
|
+
const has = (n) => args.includes(n)
|
|
205
|
+
if (has('-h') || has('--help')) {
|
|
206
|
+
console.log(`系统定时器清单(只读)
|
|
207
|
+
|
|
208
|
+
用法: node scripts/argent-timers.mjs [选项]
|
|
209
|
+
--json 结构化输出(MCP / ERP 心跳复用)
|
|
210
|
+
--launchctl-file <p> 从文件读 launchctl list 输出(离线夹具)
|
|
211
|
+
--plist-dir <p> LaunchAgents 目录(默认 ~/Library/LaunchAgents)
|
|
212
|
+
--data-dir <p> 数据根(读状态文件,默认 argent 数据目录)
|
|
213
|
+
说明:只读;⛔ 不 bootstrap/bootout、不写文件。`)
|
|
214
|
+
process.exit(0)
|
|
215
|
+
}
|
|
216
|
+
const dataDir = argVal('--data-dir') || resolveDataDir({ env: process.env }).dir
|
|
217
|
+
const result = collect({ launchctlFile: argVal('--launchctl-file') || '', plistDir: argVal('--plist-dir') || '', dataDir })
|
|
218
|
+
if (has('--json')) { console.log(JSON.stringify(result, null, 2)); process.exit(result.ok ? 0 : 2) }
|
|
219
|
+
console.log(`系统定时器:${result.count} 条(已加载 ${result.loadedCount} / 未加载 ${result.missingCount} / 退役残留 ${result.retiredCount})`)
|
|
220
|
+
for (const t of result.timers) {
|
|
221
|
+
const sched = t.schedule ? (t.schedule.type === 'calendar' ? `${t.schedule.hour ?? '*'}:${String(t.schedule.minute).padStart(2, '0')}` : `每 ${t.schedule.seconds}s`) : '—'
|
|
222
|
+
const state = t.loaded ? '✅ 在跑' : '⚠️ 未加载'
|
|
223
|
+
console.log(` ${state} ${t.label}(${t.desc})排程=${sched}${t.lastRunAt ? ' · 上次=' + t.lastRunAt : ''}${t.lastError ? ' · ' + t.lastError : ''}`)
|
|
224
|
+
}
|
|
225
|
+
for (const n of result.notes) console.log(` ℹ ${n}`)
|
|
226
|
+
process.exit(result.ok ? 0 : 2)
|
|
227
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* argent-web-preflight.mjs —— **启动 web 之前**的结构自检(2026-11-05)
|
|
4
|
+
*
|
|
5
|
+
* 为什么:desktop 那次 boot 失败(plugins 被重置)教训是——profile 改完到启动之间,
|
|
6
|
+
* 任何一环错都只表现为"启动失败",且没有报错。本脚本把能提前发现的都查一遍。
|
|
7
|
+
*
|
|
8
|
+
* 查六类:
|
|
9
|
+
* 1. profile package.json:bundles 是否正好 base/web-app/argent-web
|
|
10
|
+
* 2. patch 每一行的 name 是否可解析(包在不在 node_modules / 本地文件在不在)
|
|
11
|
+
* 3. node_modules/@whyshu/argent-web 是否软链到仓库
|
|
12
|
+
* 4. 宿主插件能否 import + apply(假 ctx)
|
|
13
|
+
* 5. 客户端 bundle 能否装载并注册 shell.overlay
|
|
14
|
+
* 6. 关键端点文件/依赖是否齐全(office-runtime/auth/health/llm-whyshu)
|
|
15
|
+
*
|
|
16
|
+
* 退出码:0 全通 | 1 有 FAIL
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs'
|
|
19
|
+
import { createRequire } from 'node:module'
|
|
20
|
+
import { homedir } from 'node:os'
|
|
21
|
+
import { join, resolve } from 'node:path'
|
|
22
|
+
|
|
23
|
+
const REPO = resolve(import.meta.dirname, '..')
|
|
24
|
+
const profileArg = process.argv.includes('--profile') ? process.argv[process.argv.indexOf('--profile') + 1] : 'web'
|
|
25
|
+
const profileDir = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', profileArg)
|
|
26
|
+
const req = createRequire(join(profileDir, 'package.json'))
|
|
27
|
+
|
|
28
|
+
let fails = 0
|
|
29
|
+
const ok = (c, msg) => { console.log(`${c ? '✅' : '❌'} ${msg}`); if (!c) fails++ }
|
|
30
|
+
const warn = (msg) => console.log(`⚠️ ${msg}`)
|
|
31
|
+
|
|
32
|
+
// 0) 版本门禁(2026-11-05 事故:用户用 `npx @deepseek-ai/dsh` 起 web,拉到 rc.5,
|
|
33
|
+
// 而 profile 插件是 rc.2 ⇒ 一堆核心插件等待服务 ⇒ 启动失败)
|
|
34
|
+
{
|
|
35
|
+
const { execFileSync } = await import('node:child_process')
|
|
36
|
+
let profVer = ''
|
|
37
|
+
try { profVer = JSON.parse(readFileSync(join(profileDir, 'node_modules', '@deepseek-ai', 'dsh-base', 'package.json'), 'utf8')).version } catch { /* ignore */ }
|
|
38
|
+
let hostVer = ''
|
|
39
|
+
try { hostVer = execFileSync('dsh', ['--version'], { encoding: 'utf8', timeout: 5000 }).trim() } catch { /* ignore */ }
|
|
40
|
+
if (!profVer && hostVer) {
|
|
41
|
+
console.log(`✅ profile 不自带 dsh 包(由宿主提供)|全局 dsh ${hostVer} ⇒ 不会版本混用`)
|
|
42
|
+
} else if (profVer && hostVer) {
|
|
43
|
+
if (profVer === hostVer) console.log(`✅ 版本一致:profile 插件 ${profVer} ⇄ 全局 dsh ${hostVer}`)
|
|
44
|
+
else {
|
|
45
|
+
console.log(`❌ 版本不一致:profile 插件 ${profVer} ≠ 全局 dsh ${hostVer}`)
|
|
46
|
+
console.log(` ⇒ 用不匹配的宿主启动会「一堆插件等待服务」而失败(2026-11-05 实测 rc.5 vs rc.2)`)
|
|
47
|
+
console.log(` 请用:npx @deepseek-ai/dsh@${profVer} web 或 dsh web(全局已装 ${hostVer})`)
|
|
48
|
+
fails++ // fails 在下方声明,见下
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
console.log('ℹ️ 版本门禁跳过(没读到 profile 插件版本或全局 dsh)')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 1) package.json
|
|
56
|
+
const pkg = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8'))
|
|
57
|
+
const bundles = (pkg.dsh && pkg.dsh.profile && pkg.dsh.profile.bundles) || []
|
|
58
|
+
const want = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', '@whyshu/argent-web']
|
|
59
|
+
ok(JSON.stringify([...bundles].sort()) === JSON.stringify([...want].sort()), `bundles 正好 3 个(${bundles.join(', ')})`)
|
|
60
|
+
ok(Boolean((pkg.dependencies || {})['@whyshu/argent-web']), '依赖含 @whyshu/argent-web')
|
|
61
|
+
|
|
62
|
+
// 2) patch 每行的 name 可解析
|
|
63
|
+
const patch = readFileSync(join(profileDir, 'cordis.patch.yml'), 'utf8')
|
|
64
|
+
const names = [...patch.matchAll(/^\s+name:\s*['"]([^'"]+)['"]/gm)].map((m) => m[1])
|
|
65
|
+
const unresolved = []
|
|
66
|
+
for (const n of names) {
|
|
67
|
+
if (n.startsWith('./') || n.startsWith('../')) {
|
|
68
|
+
if (!existsSync(join(profileDir, n))) unresolved.push(`${n}(本地文件不存在)`)
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
try { req.resolve(`${n}/package.json`) } catch { try { req.resolve(n) } catch { unresolved.push(n) } }
|
|
72
|
+
}
|
|
73
|
+
ok(unresolved.length === 0, unresolved.length ? `patch 有 ${unresolved.length} 个 name 解析不到:${unresolved.join(', ')}` : `patch ${names.length} 个 name 全部可解析`)
|
|
74
|
+
|
|
75
|
+
// 3) 软链
|
|
76
|
+
const nm = join(profileDir, 'node_modules', '@whyshu', 'argent-web')
|
|
77
|
+
if (!existsSync(nm)) ok(false, 'node_modules 缺 @whyshu/argent-web')
|
|
78
|
+
else {
|
|
79
|
+
ok(lstatSync(nm).isSymbolicLink() && realpathSync(nm) === realpathSync(join(REPO, 'plugins', 'argent-web')), 'node_modules/@whyshu/argent-web 软链指向仓库')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 4) 宿主插件 apply
|
|
83
|
+
{
|
|
84
|
+
const mod = await import(join(REPO, 'plugins', 'argent-web', 'src', 'index.js'))
|
|
85
|
+
ok(typeof mod.apply === 'function' && mod.name === 'argent-web', '宿主插件可 import(name=argent-web)')
|
|
86
|
+
const regs = []
|
|
87
|
+
const plugins = []
|
|
88
|
+
const ctx = { webServer: { register: (e) => regs.push(e.path) }, plugin: (mod, cfg) => plugins.push({ mod, cfg }), on: () => {}, effect: (f) => f(), get: () => null }
|
|
89
|
+
try { await mod.apply(ctx) } catch (e) { ok(false, `apply 抛异常:${e.message}`) }
|
|
90
|
+
ok(regs.includes('/api/argent-web/health'), `注册 health 端点(${regs.join(', ')})`)
|
|
91
|
+
ok(regs.includes('/api/argent-web/account'), '注册 account 端点(积分)')
|
|
92
|
+
ok(regs.includes('/api/argent-web/auth'), '注册 auth 端点(一键登录)')
|
|
93
|
+
const mcp = plugins.find((p) => p.cfg && p.cfg.serverName === 'argent')
|
|
94
|
+
ok(Boolean(mcp), '自注册 MCP 网关(serverName=argent)')
|
|
95
|
+
ok(existsSync(join(REPO, 'plugins', 'argent-web', 'mcp', 'gateway.mjs')), '网关文件存在:mcp/gateway.mjs')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 5) 客户端 bundle
|
|
99
|
+
{
|
|
100
|
+
const src = readFileSync(join(REPO, 'plugins', 'argent-web', 'dist', 'client.js'), 'utf8')
|
|
101
|
+
let mod = null
|
|
102
|
+
const reactStub = { createElement: () => null, useState: (v) => [v, () => {}], useEffect: () => {}, useCallback: (f) => f, useRef: () => ({ current: null }), useMemo: (f) => f() }
|
|
103
|
+
try {
|
|
104
|
+
new Function('window', src)({ __ModuleLoader__: { load: ({ factory }) => { mod = factory((n) => (n === 'react' ? reactStub : {})) } } })
|
|
105
|
+
const regs = []
|
|
106
|
+
mod.apply({ slots: { inject: (n, f) => { const it = f(); let r = it.next(); while (!r.done) r = it.next() }, register: (m) => { regs.push(m.name); return { dispose() {} } } } })
|
|
107
|
+
ok(regs.includes('shell.overlay'), `客户端注册 shell.overlay(伞伞)`)
|
|
108
|
+
} catch (e) { ok(false, `客户端 bundle 装载失败:${e.message}`) }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 6) 关键文件
|
|
112
|
+
for (const f of ['src/office-runtime.js', 'src/whyshu-auth.mjs', 'src/health.mjs', 'src/llm-whyshu.mjs', 'src/lease.mjs', 'src/account-token.mjs']) {
|
|
113
|
+
ok(existsSync(join(REPO, 'plugins', 'argent-web', f)), `文件存在:${f}`)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// provider 解析(dsh 宿主内通常可解析;裸 Node 可能不行 ⇒ 只告警)
|
|
117
|
+
{
|
|
118
|
+
try { await import(join(REPO, 'plugins', 'argent-web', 'src', 'llm-whyshu.mjs')) ; console.log('✅ provider 模块可加载(问述代理)') }
|
|
119
|
+
catch { warn('provider 在裸 Node 下不可加载(缺 @deepseek-ai/dsh-llm*);dsh 宿主内一般可解析,若启动后模型列表没有「问述代理」再查这条') }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(fails ? `\n❌ ${fails} 项未通过 —— 先修再启动 web` : '\n✅ 结构自检全通:可以启动 dsh web')
|
|
123
|
+
process.exit(fails ? 1 : 0)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* argent-web-verify.mjs —— dsh web 的 Argent 单 bundle 验收(P5)
|
|
4
|
+
*
|
|
5
|
+
* 两段:
|
|
6
|
+
* A. **离线**校验 profile 是否已收敛:bundles == [dsh-base, dsh-web-app, @whyshu/argent-web],
|
|
7
|
+
* patch 里没有 argent-core/flow/gateway/ml/presets/llm-whyshu 残留,node_modules 指向仓库
|
|
8
|
+
* B. **在线**校验端点:/api/argent-web/health(轮询角色)、/api/argent-web/account(积分)
|
|
9
|
+
*
|
|
10
|
+
* 用法:
|
|
11
|
+
* node scripts/argent-web-verify.mjs # 自动找 web 端口(默认 3080)
|
|
12
|
+
* node scripts/argent-web-verify.mjs --base http://127.0.0.1:3080
|
|
13
|
+
* node scripts/argent-web-verify.mjs --offline # 只跑 A
|
|
14
|
+
*
|
|
15
|
+
* 退出码:0 全通 | 1 未就绪(多半是 web 没启动)| 2 结构不对
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs'
|
|
18
|
+
import { execSync } from 'node:child_process'
|
|
19
|
+
import { homedir } from 'node:os'
|
|
20
|
+
import { join } from 'node:path'
|
|
21
|
+
|
|
22
|
+
const args = process.argv.slice(2)
|
|
23
|
+
const offline = args.includes('--offline')
|
|
24
|
+
const baseArg = args.includes('--base') ? args[args.indexOf('--base') + 1] : ''
|
|
25
|
+
const profileDir = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', 'web')
|
|
26
|
+
|
|
27
|
+
let fails = 0
|
|
28
|
+
const ok = (c, msg) => { console.log(`${c ? '✅' : '❌'} ${msg}`); if (!c) fails++ }
|
|
29
|
+
|
|
30
|
+
// ── A. profile 结构 ──
|
|
31
|
+
const pkgFile = join(profileDir, 'package.json')
|
|
32
|
+
const patchFile = join(profileDir, 'cordis.patch.yml')
|
|
33
|
+
if (!existsSync(pkgFile)) { ok(false, `找不到 ${pkgFile}`); process.exit(2) }
|
|
34
|
+
const pkg = JSON.parse(readFileSync(pkgFile, 'utf8'))
|
|
35
|
+
const bundles = (pkg.dsh && pkg.dsh.profile && pkg.dsh.profile.bundles) || []
|
|
36
|
+
const want = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', '@whyshu/argent-web'].sort()
|
|
37
|
+
ok(JSON.stringify([...bundles].sort()) === JSON.stringify(want), `bundles 收敛为 3 个(实际:${bundles.join(', ')})`)
|
|
38
|
+
ok(Boolean((pkg.dependencies || {})['@whyshu/argent-web']), '依赖含 @whyshu/argent-web')
|
|
39
|
+
const leftovers = Object.keys(pkg.dependencies || {}).filter((d) => /^(argent-(core|flow|gateway|presets)|@whyshu\/argent-(ml|skin|dsh))$/.test(d))
|
|
40
|
+
ok(leftovers.length === 0, `deps 无 argent 旧包残留${leftovers.length ? ':' + leftovers.join(',') : ''}`)
|
|
41
|
+
|
|
42
|
+
const patch = readFileSync(patchFile, 'utf8')
|
|
43
|
+
const patchLeft = ['argent-core', 'argent-flow', 'argent-gateway', 'argent-ml', 'argent-presets', 'llm-whyshu'].filter((id) => patch.includes(`id: ${id}`))
|
|
44
|
+
ok(patchLeft.length === 0, `patch 无旧行残留${patchLeft.length ? ':' + patchLeft.join(',') : ''}`)
|
|
45
|
+
|
|
46
|
+
const nm = join(profileDir, 'node_modules', '@whyshu', 'argent-web')
|
|
47
|
+
if (!existsSync(nm)) ok(false, 'node_modules 缺 @whyshu/argent-web')
|
|
48
|
+
else {
|
|
49
|
+
ok(lstatSync(nm).isSymbolicLink(), 'node_modules/@whyshu/argent-web 是软链(改仓库即生效)')
|
|
50
|
+
ok(realpathSync(nm) === realpathSync(join(process.cwd(), 'plugins', 'argent-web')), '软链指向仓库 plugins/argent-web')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (offline) { console.log(fails ? `\n❌ ${fails} 项未通过` : '\n✅ profile 结构正确'); process.exit(fails ? 2 : 0) }
|
|
54
|
+
|
|
55
|
+
// ── B. 在线端点 ──
|
|
56
|
+
/**
|
|
57
|
+
* 端口发现:web 的端口可能不是 3080(可 --port 或 --base 指定)。
|
|
58
|
+
* 先试 3080,再用 lsof 找 dsh 进程监听端口逐个探测 /api/argent-web/health。
|
|
59
|
+
*/
|
|
60
|
+
async function discoverBase() {
|
|
61
|
+
if (baseArg) return baseArg.replace(/\/+$/, '')
|
|
62
|
+
const candidates = []
|
|
63
|
+
try {
|
|
64
|
+
const out = execSync("lsof -nP -iTCP -sTCP:LISTEN 2>/dev/null | grep -iE 'deepseek|node' | grep -oE ':[0-9]{4,5}' | tr -d ':' | sort -u", { encoding: 'utf8', timeout: 8000 })
|
|
65
|
+
for (const p of out.split('\n').filter(Boolean)) candidates.push(Number(p))
|
|
66
|
+
} catch { /* ignore */ }
|
|
67
|
+
for (const p of [3080, ...candidates]) {
|
|
68
|
+
const b = `http://127.0.0.1:${p}`
|
|
69
|
+
try {
|
|
70
|
+
const r = await fetch(`${b}/api/argent-web/health`, { signal: AbortSignal.timeout(1200) })
|
|
71
|
+
if (r.status) return b
|
|
72
|
+
} catch { /* next */ }
|
|
73
|
+
}
|
|
74
|
+
return 'http://127.0.0.1:3080'
|
|
75
|
+
}
|
|
76
|
+
const base = await discoverBase()
|
|
77
|
+
const get = async (p) => {
|
|
78
|
+
const r = await fetch(base + p, { signal: AbortSignal.timeout(8000) })
|
|
79
|
+
return { status: r.status, body: await r.json().catch(() => ({})) }
|
|
80
|
+
}
|
|
81
|
+
let h
|
|
82
|
+
try { h = await get('/api/argent-web/health') } catch (e) {
|
|
83
|
+
ok(false, `连不上 ${base}:${e.message}(web 没启动?启动后重跑)`)
|
|
84
|
+
console.log(`\n❌ ${fails} 项未通过(结构 OK,在线部分未验)`)
|
|
85
|
+
process.exit(1)
|
|
86
|
+
}
|
|
87
|
+
ok(h.status === 200 && h.body.ok === true, `/api/argent-web/health 200(role=${h.body.role})`)
|
|
88
|
+
const acct = await get('/api/argent-web/account')
|
|
89
|
+
ok(acct.status === 200 && acct.body.ok === true, `/api/argent-web/account 200(积分=${acct.body.points} · 套餐=${acct.body.plan})`)
|
|
90
|
+
// poller 模式的 health 由 office-runtime 生成,不带 role 字段 ⇒ 用 /api/argent-office 是否可达来判定
|
|
91
|
+
let mode = h.body.role
|
|
92
|
+
if (!mode) {
|
|
93
|
+
const probe = await fetch(`${base}/api/argent-office/snapshot`, { signal: AbortSignal.timeout(3000) }).catch(() => null)
|
|
94
|
+
mode = probe && probe.status < 500 ? 'poller' : 'ui'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (mode === 'poller') {
|
|
98
|
+
const off = await get('/api/argent-office/snapshot').catch(() => null)
|
|
99
|
+
ok(Boolean(off && off.status < 500), `poller 模式:/api/argent-office 可达(${off && off.status})`)
|
|
100
|
+
} else {
|
|
101
|
+
console.log(`ℹ️ 本端为 UI 模式(轮询由 pid ${(h.body.holder && h.body.holder.pid) || '?'} 持有),跳过 ERP 端点`)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(fails ? `\n❌ ${fails} 项未通过` : '\n✅ argent-web 全通:单 bundle + 端点 + 积分')
|
|
105
|
+
process.exit(fails ? 2 : 0)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* billing-upload.mjs —— 计费事件上报 CLI(v0.9.0,默认**不发**)
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* node scripts/billing-upload.mjs # 未配置 URL ⇒ 只打印 not_configured
|
|
7
|
+
* ARGENT_BILLING_URL=https://... node scripts/billing-upload.mjs
|
|
8
|
+
*
|
|
9
|
+
* 环境:
|
|
10
|
+
* ARGENT_DATA_DIR 数据根(默认 ~/.dsh/argent)
|
|
11
|
+
* ARGENT_BILLING_URL 上报端点(**唯一开关**;不给就绝不发)
|
|
12
|
+
* ARGENT_BILLING_TOKEN 可选 Bearer
|
|
13
|
+
*
|
|
14
|
+
* 退出码:0 完成(含"没东西要传")|2 有批次失败(下次会重试)
|
|
15
|
+
*/
|
|
16
|
+
import { homedir } from 'node:os'
|
|
17
|
+
import { join } from 'node:path'
|
|
18
|
+
import { uploadPending } from '../core/mcp/billing-upload.mjs'
|
|
19
|
+
|
|
20
|
+
const dataDir = process.env.ARGENT_DATA_DIR || join(homedir(), '.dsh', 'argent')
|
|
21
|
+
const url = process.env.ARGENT_BILLING_URL || ''
|
|
22
|
+
const token = process.env.ARGENT_BILLING_TOKEN || ''
|
|
23
|
+
|
|
24
|
+
const r = await uploadPending({ dataDir, url, token })
|
|
25
|
+
console.log(JSON.stringify({ dataDir, configured: Boolean(url), ...r }))
|
|
26
|
+
process.exit(r.ok === false ? 0 : r.failed > 0 ? 2 : 0)
|
|
@@ -53,7 +53,8 @@ function pkgManifest() {
|
|
|
53
53
|
description: 'Argent 引擎(L1):流程/台账/重试/守卫/审计/浏览器自动化 —— 逐字节来自 argent-dsh 仓库',
|
|
54
54
|
type: 'module',
|
|
55
55
|
engines: { node: '>=20' },
|
|
56
|
-
files: ['engine/', 'MANIFEST.json', 'requirements.txt'],
|
|
56
|
+
files: ['engine/', 'bin/', 'MANIFEST.json', 'requirements.txt'],
|
|
57
|
+
bin: { 'argent-engine-runtime': 'bin/runtime-install.mjs' },
|
|
57
58
|
exports: {
|
|
58
59
|
'./version': './engine/version.mjs',
|
|
59
60
|
'./registry': './engine/scripts/lib/registry.mjs',
|
|
@@ -87,6 +88,11 @@ export function build(outDir) {
|
|
|
87
88
|
// Python 侧车需求清单(复核批指出缺口:包内没有需求清单,客户机无法装运行时)
|
|
88
89
|
const REQS = ['openpyxl', 'pyyaml', 'pillow', 'playwright', 'selenium']
|
|
89
90
|
writeFileSync(join(outDir, 'requirements.txt'), REQS.join('\n') + '\n')
|
|
91
|
+
// 自带 runtime 安装器(替代已退役启动器):客户机 npx 自拉即可更新 ~/.argent-dsh
|
|
92
|
+
mkdirSync(join(outDir, 'bin'), { recursive: true })
|
|
93
|
+
const installer = readFileSync(join(REPO, 'scripts', 'engine-runtime-install.mjs'))
|
|
94
|
+
writeFileSync(join(outDir, 'bin', 'runtime-install.mjs'), installer)
|
|
95
|
+
chmodSync(join(outDir, 'bin', 'runtime-install.mjs'), 0o755)
|
|
90
96
|
writeFileSync(join(outDir, 'package.json'), pkgManifest())
|
|
91
97
|
writeFileSync(join(outDir, 'MANIFEST.json'), JSON.stringify(manifest, null, 2) + '\n')
|
|
92
98
|
return { outDir, count: files.length, manifest }
|