@whyshu/argent-engine 0.8.0-rc.12 → 0.8.0-rc.13

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": "4b86fbb380ef1b5419b8003e9926a337fbeb070e06da3979389ec5ed39e5b619",
5
+ "VERSION": "e084d01e3c280b4fb061f3243fac8e7a44c272cf5b4f761a6e23562cd94065ee",
6
6
  "agents/catalog.json": "5356a812f2554dfd3115370363d4c3f787a82c9e5928a85d05b2a07c9e4b324d",
7
7
  "configs/_aliases.proposed.json": "3a59edf80563bcc20d410d488decad6fd787bd3de9489321367b0783904cd3e5",
8
8
  "configs/_migration-plan.proposed.json": "dd9f90b0b9b2f217dd23367a618402e57997d44f7fddcfa88a7cadf52e056c0d",
@@ -57,7 +57,7 @@
57
57
  "scripts/appointment-create.mjs": "3448966cebc767160cb151a27ccf2b6f6439c80f970f769621058871f95433cc",
58
58
  "scripts/appointment-stop.mjs": "2e0a965346d33ef8683da5473c48df7f4e66ee8a3167526ee6b568e1adf5c91d",
59
59
  "scripts/appointment-worker.mjs": "e79486eab2b902d351a75885258f2a74b871b29c0e83fccedd9eccc6029b2bdd",
60
- "scripts/appointment_grab.py": "c965625802585a9e20661f4b4442942bdeeed28c69ca72b0c557945bda0b87d7",
60
+ "scripts/appointment_grab.py": "ccc677262ac8867b4e161c8278e6d919930887cb7820c0c47383d80893d5e418",
61
61
  "scripts/archive/feishu-bridge.js": "e6714c72022892d0c527d1fc9ae0f8ff99f9ab3bd0363329979b423246684885",
62
62
  "scripts/argent-agents.mjs": "73f4a058df2cd6d62b285ea48a5e32881db678b63007d1ac2f218005cb28c18d",
63
63
  "scripts/argent-capabilities.mjs": "7186d7c19f733d987a7afe2355dd7d788333a15c0f80811c4cde4e7a32584c4e",
package/engine/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0-rc.12
1
+ 0.8.0-rc.13
@@ -10,6 +10,7 @@ import argparse
10
10
  import asyncio
11
11
  import time
12
12
  import json
13
+ import urllib.request
13
14
  import os
14
15
  import signal
15
16
  import sys
@@ -292,6 +293,8 @@ async def run_task(task: dict) -> dict:
292
293
  args = SimpleNamespace(record_id='', sku=task.get('sku', ''), qty=task.get('quantity'), box=task.get('boxCount'),
293
294
  shipment_id=task.get('shipmentNo') or '', store_name=store, no_lock=True)
294
295
  orch = O.Orchestrator(cfg, sel, args)
296
+ global _ORCH
297
+ _ORCH = orch
295
298
  orch.state.store_name = store
296
299
  orch.state.record_id = ''
297
300
  orch.state.sku = str(task.get('sku') or '')
@@ -445,6 +448,55 @@ async def run_task(task: dict) -> dict:
445
448
  _APPT_CLOSE_LAST = {'closed': 0}
446
449
 
447
450
 
451
+ _ORCH = None
452
+
453
+
454
+ def _http_sync(url: str, method: str = 'GET', timeout: float = 2.0):
455
+ req = urllib.request.Request(url, method=method)
456
+ with urllib.request.urlopen(req, timeout=timeout) as r:
457
+ return r.read()
458
+
459
+
460
+ def _close_appointment_tab_via_cdp(orch) -> int:
461
+ """同步 CDP 关闭(2026-11-07 第二轮修复)。
462
+
463
+ 停止信号会让事件循环提前关闭,``await page.close()`` 会报 ``no running event loop``
464
+ (客户机日志实证)⇒ 清理必须在**事件循环之外**用 CDP HTTP 同步完成。
465
+ """
466
+ closed = 0
467
+ try:
468
+ browser = getattr(orch, 'browser', None) if orch is not None else None
469
+ endpoint = str(getattr(browser, 'cdp_url', '') or '').rstrip('/')
470
+ if not endpoint:
471
+ return 0
472
+ targets = json.loads(_http_sync(f'{endpoint}/json/list').decode('utf-8', 'replace') or '[]')
473
+ appt = [t for t in targets if 'appointment-v2' in str(t.get('url') or '')]
474
+ if not appt:
475
+ try: orch._log(' ⚠️ 同步清理:未发现 appointment-v2 标签页')
476
+ except Exception: pass
477
+ return 0
478
+ # 先开占位页(保持紫鸟窗口存活),再逐个关闭预约页
479
+ try: _http_sync(f'{endpoint}/json/new?about:blank', method='PUT')
480
+ except Exception:
481
+ try: _http_sync(f'{endpoint}/json/new?about:blank')
482
+ except Exception: pass
483
+ for t in appt:
484
+ tid = str(t.get('id') or '')
485
+ if not tid: continue
486
+ try:
487
+ _http_sync(f'{endpoint}/json/close/{tid}')
488
+ closed += 1
489
+ try: orch._log(f' 🗂️ 同步 CDP 已关闭预约标签页({str(t.get("url"))[:100]})')
490
+ except Exception: pass
491
+ except Exception as e:
492
+ try: orch._log(f' ⚠️ 同步 CDP 关闭失败:{str(e)[:120]}')
493
+ except Exception: pass
494
+ except Exception as e:
495
+ try: orch._log(f' ⚠️ 同步 CDP 清理异常:{str(e)[:120]}')
496
+ except Exception: pass
497
+ return closed
498
+
499
+
448
500
  def _on_term(signum, frame):
449
501
  # SIGTERM 默认直接退出,不会执行 run_task 的 finally ⇒ 预约标签页残留。
450
502
  # 抛 KeyboardInterrupt 交给 asyncio.run 取消主任务,确保 finally 里的标签页清理执行。
@@ -459,6 +511,9 @@ def main():
459
511
  out = asyncio.run(run_task(task))
460
512
  except KeyboardInterrupt:
461
513
  closed = int(_APPT_CLOSE_LAST.get('closed') or 0)
514
+ # 事件循环已关闭 ⇒ await 清理不可用;用 CDP HTTP 同步兜底(2026-11-07 客户机实证)
515
+ if _ORCH is not None:
516
+ closed = max(closed, _close_appointment_tab_via_cdp(_ORCH))
462
517
  out = {
463
518
  'status': 'stopped',
464
519
  'summary': ('收到停止请求,已关闭预约标签页' if closed > 0
@@ -1 +1 @@
1
- export const VERSION = "0.8.0-rc.12"
1
+ export const VERSION = "0.8.0-rc.13"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyshu/argent-engine",
3
- "version": "0.8.0-rc.12",
3
+ "version": "0.8.0-rc.13",
4
4
  "description": "Argent 引擎(L1):流程/台账/重试/守卫/审计/浏览器自动化 —— 逐字节来自 argent-dsh 仓库",
5
5
  "type": "module",
6
6
  "engines": {