@whyshu/argent-engine 0.14.2 → 0.14.3

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "schema": 1,
3
3
  "package": "@whyshu/argent-engine",
4
4
  "files": {
5
- "VERSION": "232cca15f9cab0453d820d20649067576ec18d279ce3b1dc6d2931d1eb638721",
5
+ "VERSION": "f562b78d53673f1c58695eacf0753914674f1930a8ef51196cffca98ed8bee12",
6
6
  "agents/catalog.json": "5356a812f2554dfd3115370363d4c3f787a82c9e5928a85d05b2a07c9e4b324d",
7
7
  "configs/_aliases.proposed.json": "3a59edf80563bcc20d410d488decad6fd787bd3de9489321367b0783904cd3e5",
8
8
  "configs/_migration-plan.proposed.json": "dd9f90b0b9b2f217dd23367a618402e57997d44f7fddcfa88a7cadf52e056c0d",
@@ -14,7 +14,7 @@
14
14
  "configs/mcp-tools.snapshot.json": "cfa94a6ba64a7ae9d133a4a878ce3d5e0e85e554ccd3e3ebaf0d51ad750acf6a",
15
15
  "configs/notify.json": "cb9ef11c1c498fcf99af99ec50271b8a2598061b77ed73a6099032e837474ef0",
16
16
  "core/cli/argent.mjs": "9a8977324c238ca4e20435f9817eb7ec76157da32b1d510977dc03e0feb416a9",
17
- "core/contracts/argent.contracts.json": "f61149e1a0a7b6e9cb0a042503129b559cf02985ded788952b56138419caa4a0",
17
+ "core/contracts/argent.contracts.json": "6f3b925258c219b605ae769f5c5a77db1582abb0af5817e704af4b2420b0105f",
18
18
  "core/contracts/verbs.schema.json": "54d726181c11536eb30bd25090584a7af103e4c0462f8ef078053c8177e19dcb",
19
19
  "core/lib/account-token.mjs": "35faad2c34e67755c1867f74a74885f0f268d5daabe01d339cf30dc747f86501",
20
20
  "core/lib/argent-datadir.mjs": "1fdd799c933382c4f9e36bd4af33d51b8ac4a466a9d67a8f2296bb267b5251ac",
@@ -70,7 +70,7 @@
70
70
  "scripts/argent-runner.mjs": "a4996d382cddc16d77cd760715eb89daf6fc38115df31d98a9a706d828009f15",
71
71
  "scripts/argent-schedule.mjs": "4d2485f454094ae7d9978334e0ee995aef22fdc7058f3694c1f7d363e8a51f09",
72
72
  "scripts/argent-setup-check.mjs": "44d3558ae6eebd5cc2dd25752019d3386190e63006b544e1ceee3f4f1c526aff",
73
- "scripts/argent-timers.mjs": "05e84245ce0f9a5c9fdf73ed410702bf3ef0d712d95c45faad0f2fdecdbea9a2",
73
+ "scripts/argent-timers.mjs": "bed030b80972f447fec4d13eaa6fd63b6ebe462f2a2fa47aec6388dc6bb4c50f",
74
74
  "scripts/argent-upgrade.mjs": "ba75148cb3c27b4aab2b184d1320d4b57a203adf8b90214fa3d62880685a0d81",
75
75
  "scripts/argent-web-preflight.mjs": "7aa67912098b23cab2dec68d78830f7e5dc1d6c9cb915f4e00628fcd47bb694d",
76
76
  "scripts/argent-web-verify.mjs": "9690885f7b379da87d879018e254e563ad6631b56381ee293ee06796ce605694",
@@ -311,7 +311,9 @@
311
311
  "scripts/patches/verify-session-migration.mjs": "0f6b3a177306fd4cbbe87b4423b7ff5f0d18e4e77bfa50b385ecc354dea90c17",
312
312
  "scripts/patches/verify-turn-outside-replace.mjs": "eeff9c907e8509652759fb3d1ce864e828a68ec882c977c8d819be165817f96d",
313
313
  "scripts/plan-role-rename.mjs": "63a52ddaeb1ca2a246fcbf069318166fe5d0abee6003e5304b3e771defb43da2",
314
- "scripts/platform-appointment-scan.py": "e3208ea7359e3f8d93d7f5dbf1e2dafdfcc0f0695e55b111096448f4bbac7caa",
314
+ "scripts/platform-appointment-scan.py": "955732419259690258cfd5001eb9c9ac9c54a717b125398c18ac53e301a5fc8e",
315
+ "scripts/platform-scan-run.sh": "0590e3b3a51835e22f2772d0f312cf988e8d6301cea4cd2255ca2509bfc119c7",
316
+ "scripts/platform-scan-timers.sh": "6ed5f1e6576c1b2dc652860ff60004a49eac0a3acb5d4ddcc25bf3ebb82cd8ff",
315
317
  "scripts/plugin-bootcheck.mjs": "bbfbfc9ec0fa409f9ca52012ecdd3b7b068bb4c0b31d49da491f1efc8784d977",
316
318
  "scripts/plugin-composition.json": "99c545b56828d81882bc126eac3c3826e04146c3bb68be288a2b3c3e4ed11b9d",
317
319
  "scripts/poc-mcp-host.mjs": "5c4befdc95f98bf9c84f94bb525b245248c751e08e3fc09bb987781e9e4859cb",
package/engine/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.2
1
+ 0.14.3
@@ -1,6 +1,6 @@
1
1
  {
2
- "argentVersion": "0.14.2",
3
- "_syncNote": "argentVersion 必须与仓库根 VERSION 同批更新:发布前置校验 scripts/check-version-consistency.mjs;2026-11-24 按 VERSION=0.14.2 校正。",
2
+ "argentVersion": "0.14.3",
3
+ "_syncNote": "argentVersion 必须与仓库根 VERSION 同批更新:发布前置校验 scripts/check-version-consistency.mjs;2026-11-24 按 VERSION=0.14.3 校正。",
4
4
  "principle": "宿主无关:宿主只依赖 `argent <verb>`;确定性逻辑在 CLI/MCP,不在提示词里。",
5
5
  "verbs": {
6
6
  "version": {
@@ -37,6 +37,7 @@ export const KNOWN_LABELS = Object.freeze({
37
37
  'com.whyshu.fulfillment-poll': { desc: '旧轮询(已退役,应清理)', kind: 'retired' },
38
38
  // 2026-11-27:客户机实测清单里出现但我们漏收录的(截图里显示"未知"的正是这些)
39
39
  'com.whyshu.ml-insight-timer': { desc: '店铺诊断(每小时 :20 跟随日报快照)', kind: 'insight', statusFile: 'ml-insight-diagnose-status.json' },
40
+ 'com.whyshu.platform-appointment-scan': { desc: '平台预约只读扫描(每 30 分钟)', kind: 'insight', statusFile: 'platform-scan-status.json' },
40
41
  'com.whyshu.ziniao-keepalive': { desc: '紫鸟浏览器保活(每 3 分钟)', kind: 'host' },
41
42
  'com.whyshu.caffeinate': { desc: '防休眠(常驻)', kind: 'host' },
42
43
  'com.whyshu.xzh-browser': { desc: '鑫中航浏览器(常驻,旧流程遗留)', kind: 'host' },
@@ -14,6 +14,7 @@ import json
14
14
  import os
15
15
  import pathlib
16
16
  import re
17
+ import socket
17
18
  import sys
18
19
  import time
19
20
  import urllib.request
@@ -171,13 +172,22 @@ def scan(store: str, cdp_port: int, *, base_url: str, max_pages: int = 20, wait_
171
172
  seen: set[str] = set()
172
173
  pages: list[int] = []
173
174
  with sync_playwright() as p:
174
- browser = p.chromium.connect_over_cdp(f"http://127.0.0.1:{int(cdp_port)}")
175
+ browser = p.chromium.connect_over_cdp(f"http://127.0.0.1:{int(cdp_port)}", timeout=15_000)
175
176
  ctx = browser.contexts[0] if browser.contexts else browser.new_context()
177
+ # 清掉上一次被 SIGKILL/超时留下的列表页,避免每轮扫描无限堆标签页;
178
+ # 只关 shipping/inbounds 列表页,绝不碰 /inbounds/<货件号>/... 的预约/执行页。
179
+ for old_page in list(ctx.pages):
180
+ try:
181
+ old_url = old_page.url or ""
182
+ if "/shipping/inbounds" in old_url and "/inbounds/" not in old_url:
183
+ old_page.close()
184
+ except Exception:
185
+ pass
176
186
  page = ctx.new_page()
177
187
  page.set_default_timeout(30_000)
178
188
  try:
179
189
  for page_no in range(1, max_pages + 1):
180
- page.goto(str(base_url).rstrip("/") + INBOUNDS_PATH.format(page=page_no), wait_until="domcontentloaded", timeout=45_000)
190
+ page.goto(str(base_url).rstrip("/") + INBOUNDS_PATH.format(page=page_no), wait_until="domcontentloaded", timeout=30_000)
181
191
  time.sleep(wait_sec)
182
192
  page_rows = _rows_from_page(page, store, page_no)
183
193
  fresh = [x for x in page_rows if x["shipmentNo"] not in seen]
@@ -214,10 +224,19 @@ def scan_all(*, cdp_map: str, base_url: str, max_pages: int, wait_sec: float) ->
214
224
  stores = sorted(set(stores))
215
225
  results = []
216
226
  for name, port in stores:
227
+ # 先做 TCP 探针:窗口没开就立即跳过,避免 Playwright 在死端口上等很久。
228
+ try:
229
+ with socket.create_connection(("127.0.0.1", int(port)), timeout=1.5):
230
+ pass
231
+ except Exception as e: # noqa: BLE001
232
+ results.append({"ok": False, "store": name, "cdpPort": port, "count": 0, "error": f"CDP 端口未监听:{str(e)[:120]}"})
233
+ continue
234
+ print(f"[scan] store={name} cdp={port} start", flush=True)
217
235
  try:
218
236
  r = scan(name, port, base_url=base_url, max_pages=max_pages, wait_sec=wait_sec)
219
237
  except Exception as e: # noqa: BLE001
220
238
  r = {"ok": False, "store": name, "cdpPort": port, "error": str(e)[:300]}
239
+ print(f"[scan] store={name} done ok={r.get('ok')} count={r.get('count', 0)}", flush=True)
221
240
  results.append(r)
222
241
  return {"ok": True, "mode": "all_stores", "stores": len(stores), "results": results, "scannedAt": datetime.now(timezone.utc).isoformat()}
223
242
 
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env bash
2
+ # platform-scan-run.sh —— 只读平台预约扫描器的定时入口(launchd 直跑)。
3
+ # 由 platform-scan-timers.sh 安装;不预约、不取消、不占 FULL 槽位。
4
+ set -euo pipefail
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ . "$SCRIPT_DIR/lib/argent-datadir.sh"
7
+ DATA_HOME="${ARGENT_DATA_DIR_RESOLVED:?数据根解析失败:请显式给 ARGENT_DATA_DIR}"
8
+ REPORT="$DATA_HOME/agent-report.json"
9
+ ENV_FILE="$DATA_HOME/daily-report.env"
10
+ STATUS="$DATA_HOME/platform-scan-status.json"
11
+ LOG_DIR="$DATA_HOME/platform-scan-logs"
12
+ LOCK="$DATA_HOME/platform-scan.lock"
13
+ mkdir -p "$LOG_DIR"
14
+ now() { date -u '+%Y-%m-%dT%H:%M:%SZ'; }
15
+ write_status() { # $1=exit $2=error
16
+ /usr/bin/python3 - "$STATUS" "$1" "${2:-}" "$STARTED" <<'PYEOF' 2>/dev/null || true
17
+ import json,sys,datetime
18
+ path,code,err,started=sys.argv[1:5]
19
+ now=datetime.datetime.now(datetime.timezone.utc)
20
+ try: doc=json.load(open(path))
21
+ except Exception: doc={}
22
+ doc.update({"lastRunAt":doc.get("lastRunAt") or started,"lastFinishAt":now.isoformat().replace("+00:00","Z"),"lastExit":int(code) if str(code).lstrip("-").isdigit() else 1,"lastError":err,"nextDueAt":(now+datetime.timedelta(minutes=30)).isoformat().replace("+00:00","Z")})
23
+ open(path,"w").write(json.dumps(doc,ensure_ascii=False,indent=2)+"\n")
24
+ PYEOF
25
+ }
26
+ env_get() { [ -f "$ENV_FILE" ] || return 0; grep -E "^[[:space:]]*$1=" "$ENV_FILE" 2>/dev/null | tail -1 | cut -d= -f2- | tr -d '"' | tr -d "'" | sed 's/[[:space:]]*$//'; }
27
+ if [ -f "$DATA_HOME/platform-scan.env" ]; then . "$DATA_HOME/platform-scan.env"; fi
28
+ if [ "$(env_get PLATFORM_SCAN_ENABLED)" != "true" ]; then exit 0; fi
29
+ if [ -d "$LOCK" ]; then exit 0; fi
30
+ mkdir "$LOCK" 2>/dev/null || exit 0
31
+ trap 'rmdir "$LOCK" 2>/dev/null || true' EXIT
32
+ if [ ! -f "$REPORT" ]; then write_status 1 "agent-report.json 缺失"; exit 1; fi
33
+ TOKEN="$("/usr/bin/python3" -c 'import json,sys; print(json.load(open(sys.argv[1])).get("machineToken",""))' "$REPORT" 2>/dev/null || true)"
34
+ APP="$("/usr/bin/python3" -c 'import json,sys; print(json.load(open(sys.argv[1])).get("tenantAppId","ly-0001"))' "$REPORT" 2>/dev/null || true)"
35
+ MID="$("/usr/bin/python3" -c 'import json,sys; print(json.load(open(sys.argv[1])).get("machineId",""))' "$REPORT" 2>/dev/null || true)"
36
+ BASE="$(env_get SELLER_CENTER_BASE)"
37
+ if [ -z "$BASE" ]; then echo "缺少 SELLER_CENTER_BASE:请在 $DATA_HOME/platform-scan.env 配置" >&2; write_status 1 "SELLER_CENTER_BASE 未配置"; exit 1; fi
38
+ PYBIN="$HOME/.dsh/argent/venv/bin/python3"; [ -x "$PYBIN" ] || PYBIN="$("/usr/bin/which" python3)"
39
+ STARTED="$(now)"
40
+ set +e
41
+ ARGENT_MACHINE_TOKEN="$TOKEN" ARGENT_ERP_BASE="${ARGENT_ERP_BASE:-https://whyshu.com}" ARGENT_TENANT_APP_ID="$APP" ARGENT_MACHINE_ID="$MID" SELLER_CENTER_BASE="$BASE" \
42
+ "$PYBIN" "$SCRIPT_DIR/platform-appointment-scan.py" --all-stores --max-pages 5 --wait 6 >>"$LOG_DIR/platform-scan.log" 2>&1
43
+ CODE=$?
44
+ set -e
45
+ write_status "$CODE" ""
46
+ exit "$CODE"
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env bash
2
+ # platform-scan-timers.sh —— 只读平台预约扫描器的 launchd 安装/卸载/状态。
3
+ # bash scripts/platform-scan-timers.sh install [--force] [--allow-non-production]
4
+ # bash scripts/platform-scan-timers.sh uninstall
5
+ # bash scripts/platform-scan-timers.sh status
6
+ # bash scripts/platform-scan-timers.sh run-now
7
+ set -euo pipefail
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ . "$SCRIPT_DIR/lib/argent-datadir.sh"
10
+ LABEL="com.whyshu.platform-appointment-scan"
11
+ AGENTS="$HOME/Library/LaunchAgents"
12
+ DATA_HOME="${ARGENT_DATA_DIR_RESOLVED:?数据根解析失败:请显式给 ARGENT_DATA_DIR}"
13
+ RUNNER="$SCRIPT_DIR/platform-scan-run.sh"
14
+ LOG_DIR="$DATA_HOME/platform-scan-logs"
15
+ PLIST="$AGENTS/$LABEL.plist"
16
+ ENV_FILE="$DATA_HOME/platform-scan.env"
17
+
18
+ usage() { sed -n '2,9p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
19
+ is_production() {
20
+ /usr/bin/python3 - "$DATA_HOME/config.json" <<'PYEOF' 2>/dev/null || exit 1
21
+ import json,sys
22
+ try:
23
+ d=json.load(open(sys.argv[1])); r=(d.get('dailyReport') or {}).get('role',''); a=len((d.get('dailyReport') or {}).get('allowedChatIds') or [])
24
+ raise SystemExit(0 if r=='production' or a>0 else 1)
25
+ except SystemExit: raise
26
+ except Exception: raise SystemExit(1)
27
+ PYEOF
28
+ }
29
+ gen() {
30
+ cat <<PLIST
31
+ <?xml version="1.0" encoding="UTF-8"?>
32
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
+ <plist version="1.0">
34
+ <dict>
35
+ <key>Label</key><string>$LABEL</string>
36
+ <key>ProgramArguments</key><array><string>/bin/bash</string><string>$RUNNER</string></array>
37
+ <key>StartInterval</key><integer>1800</integer>
38
+ <key>RunAtLoad</key><false/>
39
+ <key>AbandonProcessGroup</key><true/>
40
+ <key>EnvironmentVariables</key><dict>
41
+ <key>ARGENT_DATA_DIR</key><string>$DATA_HOME</string>
42
+ <key>PATH</key><string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
43
+ </dict>
44
+ <key>StandardOutPath</key><string>$LOG_DIR/platform-scan.out.log</string>
45
+ <key>StandardErrorPath</key><string>$LOG_DIR/platform-scan.err.log</string>
46
+ <key>WorkingDirectory</key><string>$HOME</string>
47
+ </dict>
48
+ </plist>
49
+ PLIST
50
+ }
51
+ do_install() {
52
+ local allow=0
53
+ for a in "$@"; do case "$a" in --allow-non-production) allow=1;; --force) :;; *) echo "未知参数 $a" >&2; exit 2;; esac; done
54
+ if [ "$allow" = 0 ] && ! is_production; then echo "❌ 拒绝安装:本机不是生产机(需 config.json dailyReport.role=production 或 --allow-non-production)" >&2; exit 3; fi
55
+ mkdir -p "$AGENTS" "$LOG_DIR" "$DATA_HOME"
56
+ if [ -n "${SELLER_CENTER_BASE:-}" ]; then printf 'SELLER_CENTER_BASE=%s\n' "$SELLER_CENTER_BASE" > "$ENV_FILE"; chmod 600 "$ENV_FILE"; fi
57
+ gen > "$PLIST"; chmod 644 "$PLIST"
58
+ launchctl bootout "gui/$(id -u)" "$PLIST" 2>/dev/null || true
59
+ launchctl bootstrap "gui/$(id -u)" "$PLIST"
60
+ echo "✅ 已安装 $LABEL(每 30 分钟)"
61
+ }
62
+ do_uninstall() {
63
+ if [ -f "$PLIST" ]; then launchctl bootout "gui/$(id -u)" "$PLIST" 2>/dev/null || true; rm -f "$PLIST"; echo "✅ 已卸载 $LABEL"; fi
64
+ }
65
+ do_status() {
66
+ if launchctl list 2>/dev/null | grep -q "[[:space:]]$LABEL\$"; then echo "$LABEL: loaded"; else echo "$LABEL: missing"; fi
67
+ cat "$DATA_HOME/platform-scan-status.json" 2>/dev/null || true
68
+ }
69
+ cmd="${1:-}"; shift || true
70
+ case "$cmd" in
71
+ install) do_install "$@" ;;
72
+ uninstall) do_uninstall ;;
73
+ status) do_status ;;
74
+ run-now) bash "$RUNNER" ;;
75
+ print-plist) gen ;;
76
+ *) usage; exit 2 ;;
77
+ esac
@@ -1 +1 @@
1
- export const VERSION = "0.14.2"
1
+ export const VERSION = "0.14.3"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyshu/argent-engine",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "Argent 引擎(L1):流程/台账/重试/守卫/审计/浏览器自动化 —— 逐字节来自 argent-dsh 仓库",
5
5
  "type": "module",
6
6
  "engines": {