@whyshu/argent-engine 0.7.8 → 0.8.0-rc.10

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 (114) hide show
  1. package/MANIFEST.json +67 -45
  2. package/engine/VERSION +1 -1
  3. package/engine/core/contracts/argent.contracts.json +2 -2
  4. package/engine/core/contracts/verbs.schema.json +64 -1
  5. package/engine/core/lib/argent-datadir.mjs +6 -0
  6. package/engine/core/lib/contract.mjs +30 -0
  7. package/engine/core/mcp/server.mjs +171 -2
  8. package/engine/scripts/appointment-create.mjs +2 -2
  9. package/engine/scripts/argent-doctor.mjs +44 -3
  10. package/engine/scripts/argent-machine-setup.mjs +3 -1
  11. package/engine/scripts/argent-runner.mjs +4 -2
  12. package/engine/scripts/argent-schedule.mjs +6 -0
  13. package/engine/scripts/base-bootstrap.sh +0 -0
  14. package/engine/scripts/billing-mode-daily.sh +0 -0
  15. package/engine/scripts/build-doc-index.mjs +68 -0
  16. package/engine/scripts/build-engine-package.mjs +18 -3
  17. package/engine/scripts/capability-packs.lock.json +66 -65
  18. package/engine/scripts/check-argent-desktop.mjs +91 -0
  19. package/engine/scripts/check-billing-mode.sh +0 -0
  20. package/engine/scripts/check-docs-drift.mjs +51 -4
  21. package/engine/scripts/check-dsh-web-expose.sh +0 -0
  22. package/engine/scripts/ci-run.sh +2 -2
  23. package/engine/scripts/customer-readiness.sh +0 -0
  24. package/engine/scripts/daily-report-run.sh +68 -0
  25. package/engine/scripts/daily-report-status.mjs +130 -0
  26. package/engine/scripts/daily-report-timer-plist.sh +89 -0
  27. package/engine/scripts/daily-report-timers.sh +199 -0
  28. package/engine/scripts/daily-report.mjs +136 -7
  29. package/engine/scripts/daily-report.sh +0 -0
  30. package/engine/scripts/desktop-trial.sh +0 -0
  31. package/engine/scripts/dev-window.sh +0 -0
  32. package/engine/scripts/doc-status.mjs +212 -0
  33. package/engine/scripts/drill-clean-room.sh +0 -0
  34. package/engine/scripts/drill-handover.sh +0 -0
  35. package/engine/scripts/dsh-backup-scope.sh +0 -0
  36. package/engine/scripts/dsh-overlay-pin.sh +0 -0
  37. package/engine/scripts/dsh-release-watch-daily.sh +0 -0
  38. package/engine/scripts/dsh-remote-check.sh +0 -0
  39. package/engine/scripts/dsh-restart.sh +0 -0
  40. package/engine/scripts/dsh-restore.sh +0 -0
  41. package/engine/scripts/dsh-url.sh +0 -0
  42. package/engine/scripts/erp_invoice_shadow.py +62 -0
  43. package/engine/scripts/erp_invoice_writeback.py +93 -0
  44. package/engine/scripts/flow-requirements.json +4 -4
  45. package/engine/scripts/flow-session-retention.mjs +2 -1
  46. package/engine/scripts/flow-timers-plist.sh +0 -0
  47. package/engine/scripts/flow-timers.sh +11 -0
  48. package/engine/scripts/flow-trigger-wake.mjs +6 -3
  49. package/engine/scripts/flow-trigger.sh +0 -0
  50. package/engine/scripts/flow_config.py +16 -0
  51. package/engine/scripts/flow_failure.py +3 -0
  52. package/engine/scripts/flow_source.py +10 -1
  53. package/engine/scripts/flow_sources/__init__.py +1 -0
  54. package/engine/scripts/flow_sources/erp.py +54 -0
  55. package/engine/scripts/fulfillment_sites.py +46 -0
  56. package/engine/scripts/gen-agent-bundles.mjs +1 -1
  57. package/engine/scripts/init-ml.sh +0 -0
  58. package/engine/scripts/invoice-table.sh +0 -0
  59. package/engine/scripts/invoice_lip_runner.py +43 -0
  60. package/engine/scripts/invoice_runner.py +5 -3
  61. package/engine/scripts/invoice_stageb.py +21 -4
  62. package/engine/scripts/lib/argent-datadir.sh +0 -0
  63. package/engine/scripts/lib/argent_datadir.py +5 -0
  64. package/engine/scripts/lib/daily-report-status.mjs +227 -0
  65. package/engine/scripts/lib/plugin-packages.mjs +3 -0
  66. package/engine/scripts/lib/repo-root.sh +0 -0
  67. package/engine/scripts/migrate-skills.sh +0 -0
  68. package/engine/scripts/ml-ads.mjs +181 -0
  69. package/engine/scripts/ml-oauth-setup.mjs +1 -1
  70. package/engine/scripts/ml_hub_status.py +3 -3
  71. package/engine/scripts/npm-publish-argent.sh +0 -0
  72. package/engine/scripts/orchestrator.py +228 -31
  73. package/engine/scripts/orchestrator_br.py +14412 -0
  74. package/engine/scripts/patches/retire-check.sh +0 -0
  75. package/engine/scripts/poll-fulfillment.sh +0 -0
  76. package/engine/scripts/poll-invoice.sh +0 -0
  77. package/engine/scripts/provider-select.sh +0 -0
  78. package/engine/scripts/provider-switch.sh +0 -0
  79. package/engine/scripts/python-runtime.sh +0 -0
  80. package/engine/scripts/query_runner.py +2 -3
  81. package/engine/scripts/release-argent.sh +0 -0
  82. package/engine/scripts/release-gate-0.8.mjs +81 -0
  83. package/engine/scripts/run-tests.sh +0 -0
  84. package/engine/scripts/s1-audit.mjs +4 -1
  85. package/engine/scripts/session-handoff.mjs +2 -1
  86. package/engine/scripts/setup.sh +0 -0
  87. package/engine/scripts/skuflow_invoice_runner.py +164 -0
  88. package/engine/scripts/sync-plugins.sh +0 -0
  89. package/engine/scripts/sync-presets.sh +0 -0
  90. package/engine/scripts/sync-scripts.sh +0 -0
  91. package/engine/scripts/telemetry.py +6 -2
  92. package/engine/scripts/usage-anchor.sh +0 -0
  93. package/engine/scripts/vertical-lint.mjs +19 -0
  94. package/engine/scripts/wenyao-browser.sh +0 -0
  95. package/engine/scripts/wenyao-login.sh +0 -0
  96. package/engine/scripts/xzh-browser.sh +2 -1
  97. package/engine/scripts/xzh_browser.py +1 -1
  98. package/engine/scripts/ziniao-auth-probe.sh +67 -18
  99. package/engine/scripts/ziniao-keepalive.sh +0 -0
  100. package/engine/scripts/ziniao-post-upgrade-check.sh +0 -0
  101. package/engine/scripts/ziniao-windows.sh +0 -0
  102. package/engine/skills/ml-fulfillment-sop/SKILL.md +29 -0
  103. package/engine/skills/ml-fulfillment-sop/references/agentic-runtime-v3.md +39 -0
  104. package/engine/skills/ml-fulfillment-sop/scripts/poll-and-execute.sh +0 -0
  105. package/engine/skills/ml-store-daily-report/SKILL.md +68 -0
  106. package/engine/tools/agentic/README.md +95 -0
  107. package/engine/tools/agentic/mcp_server.py +212 -0
  108. package/engine/tools/agentic/ml_agent_tools.py +602 -0
  109. package/engine/version.mjs +1 -1
  110. package/engine/verticals/_engine-words.baseline.txt +16 -2
  111. package/engine/verticals/mercadolibre/brazil-full-sop.json +47 -0
  112. package/engine/verticals/mercadolibre/flows.json +15 -5
  113. package/engine/verticals/mercadolibre/prompts/full.failure.md +39 -1
  114. package/package.json +1 -1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -50,9 +50,8 @@ def _default_orchestrator() -> Path:
50
50
  profile_home / "scripts/orchestrator.py",
51
51
  profile_home / "roles/ml-fulfillment/scripts/orchestrator.py",
52
52
  profile_home / "skills/mercadolibre/ml-fulfillment-sop/scripts/fulfillment_orchestrator.py",
53
- Path.home() / "Code/argent-ml-seller/scripts/orchestrator.py",
54
- Path.home() / "Code/argent-ml/roles/ml-fulfillment/scripts/orchestrator.py",
55
- Path.home() / "Code/argent-ml/skills/mercadolibre/ml-fulfillment-sop/scripts/fulfillment_orchestrator.py",
53
+ # 2026-10-29:legacy 仓(argent-ml / argent-ml-seller)已归档;只认当前主线仓
54
+ Path.home() / "Code/argent-dsh/scripts/orchestrator.py",
56
55
  ]
57
56
  for c in candidates:
58
57
  if c.is_file():
File without changes
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Argent 0.8 发布门禁(release gate)——只跑“影响客户机运行/发布完整性”的判据。
4
+ *
5
+ * 为什么不是直接跑 run-tests.sh:仓库里有大量历史/文档/测试夹具门禁,
6
+ * 它们对发布安全有价值,但不能把“旧文档计数”当成客户机阻塞项。
7
+ * 本清单是唯一发布门禁;其余测试继续保留在全量套件里,作为后续硬化。
8
+ *
9
+ * 用法:
10
+ * node scripts/release-gate-0.8.mjs
11
+ * node scripts/release-gate-0.8.mjs --list
12
+ * node scripts/release-gate-0.8.mjs --json
13
+ */
14
+ import { spawnSync } from 'node:child_process'
15
+ import { existsSync } from 'node:fs'
16
+ import { dirname, join, resolve } from 'node:path'
17
+ import { fileURLToPath } from 'node:url'
18
+
19
+ const REPO = resolve(dirname(fileURLToPath(import.meta.url)), '..')
20
+ const TESTS = [
21
+ 'scripts/tests/version-consistency.test.mjs',
22
+ 'scripts/tests/capability-pack.test.mjs',
23
+ 'scripts/tests/manifest-consistency.test.mjs',
24
+ 'scripts/tests/js-syntax.test.mjs',
25
+ 'scripts/tests/engine-package.test.mjs',
26
+ 'scripts/tests/kernel-purity.test.mjs',
27
+ 'scripts/tests/plugin-peer-coverage.test.mjs',
28
+ 'scripts/tests/is-direct-run.test.mjs',
29
+ 'scripts/tests/config-validate.test.mjs',
30
+ 'scripts/tests/profile-doctor.test.mjs',
31
+ 'scripts/tests/argent-datadir.test.mjs',
32
+ 'scripts/tests/datadir-literal-gate.test.mjs',
33
+ 'scripts/tests/datadir-writes-gate.test.mjs',
34
+ 'scripts/tests/agentic-no-lip.test.mjs',
35
+ 'scripts/tests/core-mcp-shared.test.mjs',
36
+ 'scripts/tests/mcp-tool-annotations.test.mjs',
37
+ 'scripts/tests/mcp-collapse.test.mjs',
38
+ 'scripts/tests/mcp-host-poc.test.mjs',
39
+ 'scripts/tests/setup-hook.test.mjs',
40
+ 'scripts/tests/customer-config-migrate.test.mjs',
41
+ 'scripts/tests/dsh-versions.test.mjs',
42
+ 'scripts/tests/capability-stats.test.mjs',
43
+ 'scripts/tests/readme-install-path.test.mjs',
44
+ 'scripts/tests/agent-bundle-generation.test.mjs',
45
+ ]
46
+ const OUT_OF_GATE = [
47
+ ['docs-consistency / criteria-fresh / handover-fresh', '文档/历史计数,不影响客户机运行'],
48
+ ['argent-datadir-parity', '旧的 shell/Python 二级链白名单;主 datadir 判据已在门禁内'],
49
+ ['setup-hook-wiring / argv 等', '测试会写真实数据目录;属测试夹具问题'],
50
+ ['flow-auto-retry / flow-failure / flow-preflight', '旧流程断言;0.8 RC 发布后作为硬化项'],
51
+ ['arg... 旧插件设置入口', '兼容插件,不阻塞 Agentic Runtime 发布'],
52
+ ['Python 旧流程断言', '同上;需产品级回归后再纳入'],
53
+ ]
54
+
55
+ const args = process.argv.slice(2)
56
+ if (args.includes('--list')) {
57
+ console.log(TESTS.join('\n'))
58
+ process.exit(0)
59
+ }
60
+ if (!existsSync(join(REPO, 'VERSION'))) {
61
+ console.error('不是 Argent 仓库根(缺 VERSION)')
62
+ process.exit(2)
63
+ }
64
+ let failed = 0
65
+ const rows = []
66
+ for (const rel of TESTS) {
67
+ const file = join(REPO, rel)
68
+ if (!existsSync(file)) { rows.push({ rel, ok: false, msg: 'missing' }); failed++; continue }
69
+ const r = spawnSync(process.execPath, [file], { cwd: REPO, encoding: 'utf8', timeout: 180000 })
70
+ const ok = r.status === 0
71
+ rows.push({ rel, ok, msg: String(r.stdout || r.stderr || '').trim().split('\n').slice(-1)[0] || '' })
72
+ if (!ok) failed++
73
+ }
74
+ if (args.includes('--json')) {
75
+ console.log(JSON.stringify({ release: '0.8.0-rc.2', gate: TESTS.length, failed, rows, outOfGate: OUT_OF_GATE }, null, 2))
76
+ } else {
77
+ for (const r of rows) console.log(`${r.ok ? '✅' : '❌'} ${r.rel}${r.msg ? ` ${r.msg}` : ''}`)
78
+ console.log(`\n${failed ? '❌' : '✅'} release-gate-0.8: ${TESTS.length - failed}/${TESTS.length} 通过`)
79
+ if (failed) console.log('\n不在本门禁内的历史/夹具项:\n' + OUT_OF_GATE.map(([a, b]) => ` · ${a} — ${b}`).join('\n'))
80
+ }
81
+ process.exit(failed ? 1 : 0)
File without changes
@@ -6,7 +6,10 @@ import { readdirSync, readFileSync, statSync } from 'node:fs'
6
6
  import { join, relative, dirname } from 'node:path'
7
7
  import { fileURLToPath } from 'node:url'
8
8
  const REPO = join(dirname(fileURLToPath(import.meta.url)), '..')
9
- const SKIP = new Set(['.git', 'node_modules', 'dist', '__pycache__', 'attic', '.venv', 'docs', 'patches', 'tests'])
9
+ // `archive/` 与 `attic` 同义:**退役留存件**(git 历史外的人工归档),不是运行期代码,
10
+ // 2026-11-01 清债时把三个一次性运维/发布脚本移进去 —— 它们硬编码旧数据目录,但永远不会被执行。
11
+ const SKIP = new Set(['.git', 'node_modules', 'dist', '__pycache__', 'attic', '.venv',
12
+ 'docs', 'patches', 'tests', 'archive'])
10
13
  const RE = /\.dsh\/argent|~\/\.dsh|\$HOME\/\.dsh|\$\{HOME\}\/\.dsh/
11
14
  function walk(dir, out = []) {
12
15
  for (const e of readdirSync(dir)) {
@@ -9,13 +9,14 @@ import { readFileSync, readdirSync, statSync, mkdirSync, writeFileSync, existsSy
9
9
  import { join } from 'node:path'
10
10
  import { homedir } from 'node:os'
11
11
  import { zstdDecompressSync } from 'node:zlib'
12
+ import { resolveDataDir } from './lib/argent-datadir.mjs'
12
13
 
13
14
  const args = process.argv.slice(2)
14
15
  const has = (f) => args.includes(f)
15
16
  const val = (f, d) => { const i = args.indexOf(f); return i >= 0 && args[i + 1] ? args[i + 1] : d }
16
17
  const HOME = process.env.HOME || homedir()
17
18
  const ROOT = join(HOME, '.dsh', 'sessions')
18
- const OUT = join(HOME, '.dsh', 'argent', 'session-handoffs')
19
+ const OUT = join(resolveDataDir({ env: process.env }).dir, 'session-handoffs')
19
20
  const FORMAT = val('--format', 'v3'); const LIMIT = Number(val('--limit', '0')) || 0; const WRITE = has('--write')
20
21
  const DAYS = Number(val('--days', '10')) || 0 // 只处理最近 N 天内动过的主会话(0 = 全部)
21
22
  const CHILDREN = has('--include-children') // 默认**排除**子会话(delegationDepth>0)
File without changes
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env python3
2
+ """SkuFlow bulkLabel 发票适配器(鑫中航;复用既有 invoice_runner/invoice_stageb)。
3
+
4
+ 输入:--record-json '<json>'(SkuFlow task.context)
5
+ 输出:stdout 最后一行 JSON {ok, invoicePath, bulkLabelPath, orderNo} 或 {ok:false,error}
6
+ 注意:默认会调用既有鑫中航上传/下载流程;离线只生成用 --generate-only。
7
+ """
8
+ import argparse
9
+ import json
10
+ import os
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ HERE = Path(__file__).resolve().parent
15
+ sys.path.insert(0, str(HERE))
16
+ DATA = Path(os.environ.get('ARGENT_DATA_DIR') or (Path.home() / '.dsh' / 'argent'))
17
+
18
+ from invoice_runner import load_mapping, generate_invoice # noqa: E402
19
+
20
+
21
+ def build_record(ctx: dict) -> dict:
22
+ return {
23
+ '货件号': str(ctx.get('shipmentNo') or ''),
24
+ '店铺名称': str(ctx.get('store') or ''),
25
+ '品名': str(ctx.get('productName') or ctx.get('sku') or ''),
26
+ '数量': int(ctx.get('quantity') or 0),
27
+ '箱数': int(ctx.get('boxCount') or 0),
28
+ '国内收货仓库': '深圳仓',
29
+ '备注': str(ctx.get('content') or 'SkuFlow'),
30
+ '到达时间': str(ctx.get('shipDate') or ''),
31
+ 'sku_data': {
32
+ '品名英文': str(ctx.get('nameEn') or ctx.get('productName') or ctx.get('sku') or ''),
33
+ '海关编码': str(ctx.get('hsCode') or ''),
34
+ '材质英文': str(ctx.get('materialEn') or ''),
35
+ '材质中文': str(ctx.get('material') or ''),
36
+ '重量(kg/箱)': ctx.get('weight') or '',
37
+ '长(cm)': ctx.get('length') or '',
38
+ '宽(cm)': ctx.get('width') or '',
39
+ '高(cm)': ctx.get('height') or '',
40
+ },
41
+ }
42
+
43
+
44
+ def _download_product_image(url: str, dest) -> str:
45
+ """下载 ERP 签名 URL 的产品图(模板 R 列必填)。"""
46
+ import urllib.request
47
+ req = urllib.request.Request(url, headers={'User-Agent': 'whyshu-skuflow/1.0'})
48
+ with urllib.request.urlopen(req, timeout=25) as r:
49
+ data = r.read()
50
+ dest.write_bytes(data)
51
+ return str(dest)
52
+
53
+
54
+ def build_wenyao_fixture(ctx: dict, rec: dict) -> dict:
55
+ boxes = max(1, int(rec['箱数'] or 1))
56
+ return {
57
+ '产品名称': rec['品名'], '货件号': rec['货件号'], 'SKU': str(ctx.get('sku') or ''),
58
+ '店铺': str(ctx.get('store') or ''), '数量': int(rec['数量'] or 0), '箱数': boxes,
59
+ '装箱数': max(1, int(rec['数量'] or 0) // boxes),
60
+ '重量': float(ctx.get('weight') or 0), '长': float(ctx.get('length') or 0),
61
+ '宽': float(ctx.get('width') or 0), '高': float(ctx.get('height') or 0),
62
+ '材质': str(ctx.get('material') or ''), 'HS编码': str(ctx.get('hsCode') or ''),
63
+ '产品图': '',
64
+ }
65
+
66
+
67
+ def run_wenyao(ctx: dict, rec: dict, generate_only: bool) -> dict:
68
+ """文鳐:SkuFlow fixture → p3/p4 → 门户 p6-p14;门户回写由本适配器接管,不写 lip。"""
69
+ import wenyao_run as wr
70
+ shipment = rec['货件号']
71
+ fixture = build_wenyao_fixture(ctx, rec)
72
+ wr.FIX_DIR.mkdir(parents=True, exist_ok=True)
73
+ fx = wr.FIX_DIR / f'skuflow-{ctx.get("skuFlowId","")}-{shipment}.json'
74
+ fx.write_text(json.dumps(fixture, ensure_ascii=False))
75
+ template = wr.DOWN_DIR / '跨境电商-下单模板.xlsx'
76
+ if not template.exists():
77
+ raise RuntimeError(f'文鳐模板不存在: {template}')
78
+ r3 = wr.p3_fill(str(fx), str(ctx.get('nameEn') or rec['品名']), '', None,
79
+ material_en=str(ctx.get('materialEn') or ''), write_dict=False)
80
+ wr.p4_verify(r3['xlsx'], str(template))
81
+ out = {'ok': True, 'invoicePath': r3['xlsx'], 'bulkLabelPath': '', 'orderNo': shipment}
82
+ if generate_only:
83
+ return out
84
+ import wenyao_portal as wp
85
+ orig = wr._writeback
86
+ wr._writeback = lambda *a, **k: None # 门户 P13/P14 的 lip 回写由 SkuFlow/ERP 接管
87
+ try:
88
+ class A: pass
89
+ a = A(); a.shipment = shipment; a.english_name = str(ctx.get('nameEn') or rec['品名'])
90
+ r1 = {'record_id': ''}
91
+ r2 = {'fixture': fixture}
92
+ with wp.portal_lock(site=f'portal.{shipment}', timeout=wp.portal_lock_timeout(),
93
+ reporter=lambda m: None) as waited:
94
+ final = wr.p6_p14_portal(a, r1, r2, r3, 1, wp, waited)
95
+ if not final:
96
+ raise RuntimeError('文鳐大货标签未生成')
97
+ out['bulkLabelPath'] = str(final)
98
+ finally:
99
+ wr._writeback = orig
100
+ return out
101
+
102
+
103
+ def main() -> int:
104
+ ap = argparse.ArgumentParser()
105
+ ap.add_argument('--record-json', required=True)
106
+ ap.add_argument('--generate-only', action='store_true')
107
+ ap.add_argument('--template', default='')
108
+ a = ap.parse_args()
109
+ out = {}
110
+ try:
111
+ ctx = json.loads(a.record_json)
112
+ rec = build_record(ctx)
113
+ missing = [k for k in ('货件号', '店铺名称', '数量', '箱数') if not rec.get(k)]
114
+ if missing:
115
+ raise RuntimeError(f"缺字段: {', '.join(missing)}")
116
+ sku = rec['sku_data']
117
+ miss2 = [k for k in ('海关编码', '材质中文', '重量(kg/箱)', '长(cm)', '宽(cm)', '高(cm)') if not sku.get(k)]
118
+ if miss2:
119
+ raise RuntimeError(f"SKU 发票主数据缺: {', '.join(miss2)}")
120
+ forwarder = str(ctx.get('forwarder') or '')
121
+ if '文鳐' in forwarder:
122
+ out = run_wenyao(ctx, rec, a.generate_only)
123
+ print(json.dumps(out, ensure_ascii=False))
124
+ return 0 if out.get('ok') else 1
125
+ if '鑫中航' not in forwarder:
126
+ raise RuntimeError(f"未知货代: {forwarder or '(空)'}")
127
+ mapping = load_mapping()
128
+ tpl = Path(a.template) if a.template else (DATA / 'invoice-templates' / 'xzh-template.xlsx')
129
+ if not tpl.exists():
130
+ tpl = Path(str(mapping.get('templates', {}).get('鑫中航') or ''))
131
+ if not tpl.exists():
132
+ raise RuntimeError(f"模板不存在: {tpl}")
133
+ import openpyxl
134
+ wb = openpyxl.load_workbook(tpl)
135
+ out_dir = DATA / 'invoice-output'
136
+ out_dir.mkdir(parents=True, exist_ok=True)
137
+ # 产品图(2026-11-03):模板 R 列必填;ERP 给短期签名 URL,下载后由 generate_invoice 嵌入
138
+ img_url = str(ctx.get('productImageUrl') or '')
139
+ if img_url:
140
+ try:
141
+ dest = out_dir / f"skuflow-{ctx.get('skuFlowId','')}-{rec['货件号']}.png"
142
+ sku['产品图本地'] = _download_product_image(img_url, dest)
143
+ print('产品图已下载:', sku['产品图本地'], flush=True)
144
+ except Exception as e:
145
+ print('产品图下载失败:', e, flush=True)
146
+ invoice = out_dir / f"skuflow-{ctx.get('skuFlowId','')}-{rec['货件号']}.xlsx"
147
+ generate_invoice(rec, mapping, wb, invoice)
148
+ out = {'ok': True, 'invoicePath': str(invoice), 'bulkLabelPath': '', 'orderNo': rec['货件号']}
149
+ if not a.generate_only:
150
+ from invoice_stageb import upload_invoice, download_label
151
+ if not upload_invoice(str(invoice), order_no=rec['货件号']):
152
+ raise RuntimeError('鑫中航上传失败')
153
+ label = download_label(rec['货件号'])
154
+ if not label:
155
+ raise RuntimeError('大货标签下载失败')
156
+ out['bulkLabelPath'] = str(label)
157
+ except Exception as e:
158
+ out = {'ok': False, 'error': str(e)[:500]}
159
+ print(json.dumps(out, ensure_ascii=False))
160
+ return 0 if out.get('ok') else 1
161
+
162
+
163
+ if __name__ == '__main__':
164
+ raise SystemExit(main())
File without changes
File without changes
File without changes
@@ -374,9 +374,13 @@ def flow_of_case(case_id: str) -> str:
374
374
  return cid.split('__', 1)[0] if '__' in cid else ''
375
375
 
376
376
 
377
- # 引擎级失败的"合成票号"(不是真实货物票):这类由**触发链**发 kind=engine,
377
+ # 引擎级失败的"合成票号"(不是真实货物票):这类由**触发链/探针**发 kind=engine,
378
378
  # 台账钩子要跳过,否则同一次失败会产生两条事件(一条 failure + 一条 engine)。
379
- ENGINE_CASE_PREFIXES = ('claim__', 'preflight__', 'invoice-ready-leftover__')
379
+ # 2026-11-01 补 `wake__` / `auth__`:实测客户机一次唤醒失败 = 13 条 engine + 13 条 failure,
380
+ # 一次授权探针失败 = 2 条/12h(`failure` 那条的 flow 还会被拆成假的 `auth` 流程)——
381
+ # 都是"同一次失败两条事件"的重复推送,判据见 docs/日志上报与排障.md §3.3。
382
+ ENGINE_CASE_PREFIXES = ('claim__', 'preflight__', 'invoice-ready-leftover__',
383
+ 'wake__', 'auth__')
380
384
 
381
385
 
382
386
  def is_engine_case(case_id: str) -> bool:
File without changes
@@ -228,6 +228,25 @@ for (const vid of VIDS) {
228
228
  if (String(flow.trigger?.mode) === 'real' && !(flow.guards?.writeFields || []).length) {
229
229
  warn('guards', `${id}: mode=real 但没有声明 guards.writeFields(写路径白名单)—— 确认这是有意的`)
230
230
  }
231
+ // ── 1.35 交付方式声明(2026-10-30)──────────────────────────────────────
232
+ // `trigger.delivery`:这条流程的定时**谁在跑**
233
+ // · `session`(缺省)= 激活垫片唤醒角色会话(flow-trigger.sh → dsh 宿主);
234
+ // · `launchd-script` = launchd 直跑确定性脚本(日报:`scripts/daily-report-timers.sh`),
235
+ // ⛔ 不进 flow-timers 的安装面、⛔ 不许同时启用宿主排程(单一调度者)。
236
+ // 判据与安装器(`scripts/flow-timers.sh` / `scripts/daily-report-timers.sh`)同源:两边都读这个键。
237
+ const delivery = flow.trigger?.delivery
238
+ if (delivery !== undefined) {
239
+ const atD = `${id}: trigger.delivery`
240
+ if (!['session', 'launchd-script'].includes(String(delivery))) {
241
+ err('delivery', `${atD}=${JSON.stringify(delivery)} 不在 session|launchd-script 内`)
242
+ }
243
+ if (String(delivery) === 'launchd-script' && flow.trigger?.schedule?.enabled === true) {
244
+ err('delivery', `${atD}=launchd-script 时 trigger.schedule.enabled 必须为 false —— 同一条流程只能有一个调度者(launchd 确定性脚本 vs 宿主排程)`)
245
+ }
246
+ if (String(delivery) === 'launchd-script' && String(flow.trigger?.wake) !== 'session') {
247
+ warn('delivery', `${atD}=launchd-script 但 trigger.wake=${JSON.stringify(flow.trigger?.wake)} —— 脚本交付不需要唤醒,建议保持 session 以外的值时才改`)
248
+ }
249
+ }
231
250
  // ── 1.4 宿主排程声明(P1-A,2026-10-12)──────────────────────────────────
232
251
  // 判据与运行期读取点(`scripts/flow_config.py` 的 schedule 段)**同一套**:这里是资产门禁,
233
252
  // 那里是唯一读取点 —— 两处各判一次不是"第二份真源",而是"声明期拦住 + 运行期不静默"。
File without changes
File without changes
@@ -2,7 +2,8 @@
2
2
  # 鑫中航常驻浏览器:启动/停止/状态(保留一个标签页给登录态)
3
3
  set -u
4
4
  ROOT="${ARGENT_DSH_HOME:-$HOME/.argent-dsh}"
5
- DATA="${ARGENT_DATA_DIR:-$HOME/.dsh/argent}"
5
+ . "$ROOT/scripts/lib/argent-datadir.sh"
6
+ DATA="$ARGENT_DATA_DIR_RESOLVED"
6
7
  PY="$DATA/venv/bin/python3"
7
8
  [ -x "$PY" ] || PY="$(command -v python3)"
8
9
  LOG="$DATA/xzh-browser.log"
@@ -3,7 +3,7 @@
3
3
 
4
4
  用法:
5
5
  python3 scripts/xzh_browser.py # 前台常驻(调试)
6
- nohup ... > ~/.dsh/argent/xzh-browser.log 2>&1 &
6
+ nohup ... > <数据目录>/xzh-browser.log 2>&1 &
7
7
  启动后监听 127.0.0.1:9223;invoice_stageb 会自动 connect_over_cdp。
8
8
  """
9
9
  import json
@@ -136,8 +136,10 @@ except Exception as exc:
136
136
  print(f"IPC_FAIL {type(exc).__name__}: {exc}")
137
137
  PY
138
138
  )"
139
+ # ⚠️ 输出**不是**以 `OK ipc` 开头:`webdriver_ipc` 会先打 `[时间] 🌐 ...` 日志行
140
+ # (2026-11-01 实测:旧写法 `OK\ ipc*` 只匹配开头 ⇒ 明明 IPC 正常也报"不可用")
139
141
  case "$wd_out" in
140
- OK\ ipc*) log "① WebDriver IPC 正常:${wd_out#OK ipc }" ;;
142
+ *OK\ ipc*) log "① WebDriver IPC 正常:$(printf '%s' "$wd_out" | grep -oE 'OK ipc windows=[0-9]+' | tail -1)" ;;
141
143
  *) log "① WebDriver IPC **不可用**:${wd_out}(常驻模式应先启动客户端;本轮先尝试自愈)" ;;
142
144
  esac
143
145
 
@@ -152,23 +154,42 @@ creds = m._load_wd_creds()
152
154
  if creds is None:
153
155
  print("SKIP 未配置 ziniao-webdriver.env(ZINIAO_WD_COMPANY/USERNAME/PASSWORD)")
154
156
  raise SystemExit(0)
157
+ import io as _io, contextlib as _ctx
155
158
  try:
156
159
  m.wd_apply_auth(cfg, creds) # 授权(幂等:等价于"续期/确认")
157
- stores = m.wd_list_stores(cfg, creds)
160
+ _err = _io.StringIO()
161
+ with _ctx.redirect_stderr(_err): # 多余店的 warn 走 stderr ⇒ 不能让它顶在 OK 前面
162
+ stores = m.wd_list_stores(cfg, creds)
158
163
  print(f"OK auth stores={len(stores)}")
164
+ _w = _err.getvalue().strip()
165
+ if _w:
166
+ print("WARN " + _w.replace(chr(10), " "))
159
167
  except Exception as exc:
160
168
  print(f"AUTH_FAIL {type(exc).__name__}: {exc}")
161
169
  PY
162
170
  )"
171
+ # 判据用 `*OK auth*`(不是 `OK auth*`):输出前面总有 `[时间] 🌐 ...` 日志行
163
172
  case "$cred_out" in
164
- OK\ auth*) log "② 授权链路正常:${cred_out#OK auth }" ;;
165
- SKIP*) log "② 跳过:${cred_out#SKIP }"; exit 3 ;;
173
+ *SKIP*) log "② 跳过:$(printf '%s' "$cred_out" | sed -n 's/.*SKIP //p' | head -1)"; exit 3 ;;
174
+ *OK\ auth*) log "② 授权链路正常:$(printf '%s' "$cred_out" | grep -oE 'OK auth stores=[0-9]+' | tail -1)" ;;
166
175
  *) log "② 授权链路**失败**:$cred_out" ;;
167
176
  esac
168
177
  case "$wd_out$cred_out" in
169
178
  *OK\ ipc*OK\ auth*) log "✅ 紫鸟凭证/授权心跳正常(无需人工干预)"; exit 0 ;;
170
179
  esac
171
180
 
181
+ # 失败**性质**分开判:`名单不一致` 与 `授权/登录失效` 的处置完全不同。
182
+ # 2026-11-01 客户机实测:客户端里多 3 个非本流程店铺(Shopee/TikTok)⇒ `wd_list_stores` 三方校验失败
183
+ # ⇒ 本探针把它写成"授权链路不可用",每 12h 推两条遥测告警(而授权链路其实 statusCode=0 全正常)。
184
+ _cred_kind=""
185
+ case "$cred_out" in
186
+ *"三方校验"*) _cred_kind="store-mismatch" ;;
187
+ AUTH_FAIL*) _cred_kind="auth-fail" ;;
188
+ esac
189
+ if [ "$_cred_kind" = "store-mismatch" ]; then
190
+ log "② 失败性质:**店铺名单与 stores.json 不一致**(不是授权/登录失效)"
191
+ fi
192
+
172
193
  # ── ③ 自愈:可用 API Key 程序化登录(ziniao-cli 1.1.3+ 的 zclaw login,无需人工点击)──
173
194
  # ⚠️ 供应商对该接口**限流**:实测连续调用会返回
174
195
  # `{"ok":false,"error":{"type":"auth","message":"apiKey 登录验证次数过多,请1分钟后再试"}}`(exit 3)。
@@ -178,7 +199,10 @@ esac
178
199
  LOGIN_STAMP="$DATA/.ziniao-auth-probe.login-attempt"
179
200
  LOGIN_MIN_S="${ZINIAO_LOGIN_MIN_INTERVAL_S:-600}"
180
201
  login_limited=0
181
- if ziniao-cli zclaw login --help >/dev/null 2>&1; then
202
+ if [ "$_cred_kind" = "store-mismatch" ]; then
203
+ # 名单不一致 ≠ 授权失效:zclaw login 修不好它,还会白吃供应商限流(实测有 600s 限速)
204
+ log "③ 跳过程序化登录:本次是**店铺名单不一致**,登录接口修不了它(省一次限流额度)"
205
+ elif ziniao-cli zclaw login --help >/dev/null 2>&1; then
182
206
  _since=999999
183
207
  if [ -f "$LOGIN_STAMP" ]; then
184
208
  _since="$(find "$LOGIN_STAMP" -mmin -$(( (LOGIN_MIN_S + 59) / 60 )) 2>/dev/null | wc -l | tr -d ' ')"
@@ -201,15 +225,22 @@ m = importlib.util.module_from_spec(spec); sys.modules["orch"] = m; spec.loader.
201
225
  cfg = m.load_config(); creds = m._load_wd_creds()
202
226
  if creds is None:
203
227
  print("SKIP"); raise SystemExit(0)
228
+ import io as _io, contextlib as _ctx
204
229
  try:
205
- m.wd_apply_auth(cfg, creds); stores = m.wd_list_stores(cfg, creds)
230
+ m.wd_apply_auth(cfg, creds)
231
+ _err = _io.StringIO()
232
+ with _ctx.redirect_stderr(_err):
233
+ stores = m.wd_list_stores(cfg, creds)
206
234
  print(f"OK auth stores={len(stores)}")
235
+ _w = _err.getvalue().strip()
236
+ if _w:
237
+ print("WARN " + _w.replace(chr(10), " "))
207
238
  except Exception as exc:
208
239
  print(f"AUTH_FAIL {type(exc).__name__}: {exc}")
209
240
  PY
210
241
  )"
211
242
  case "$retry" in
212
- OK\ auth*) log "✅ 自愈成功(zclaw login)⇒ 无需人工"; exit 0 ;;
243
+ *OK\ auth*) log "✅ 自愈成功(zclaw login)⇒ 无需人工"; exit 0 ;;
213
244
  *) log "✗ 自愈后仍失败:$retry" ;;
214
245
  esac
215
246
  else
@@ -231,7 +262,10 @@ fi
231
262
  _gui_mode=0
232
263
  case "$client_mode" in *GUI*) _gui_mode=1 ;; esac
233
264
  {
234
- if [ "$_gui_mode" = "1" ] && case "$wd_out" in *FAIL*) true ;; *) false ;; esac; then
265
+ if [ "$_cred_kind" = "store-mismatch" ]; then
266
+ echo "❌ **店铺名单与 stores.json 不一致** ⇒ 需要人工核对"
267
+ echo " 这**不是**授权/登录失效(applyAuth 已成功、客户端登录态正常);是两边的店铺清单对不上。"
268
+ elif [ "$_gui_mode" = "1" ] && case "$wd_out" in *FAIL*) true ;; *) false ;; esac; then
235
269
  echo "❌ 紫鸟**当前是 GUI 模式**(人工打开过客户端)⇒ 常驻 WebDriver 模式被顶掉,IPC 不存在"
236
270
  echo " 这不是授权/登录过期:同一客户端实例不能同时是 GUI 与 WebDriver。"
237
271
  echo " 处置:关掉这个 GUI 实例,再按部署约定重启为常驻模式:"
@@ -245,24 +279,39 @@ case "$client_mode" in *GUI*) _gui_mode=1 ;; esac
245
279
  echo " 授权链路=${cred_out}(applyAuth/getBrowserList,随请求带凭据)"
246
280
  case "$client_mode" in
247
281
  GUI*) echo " ⇒ 判定:**启动模式不对**(GUI 实例占位,WebDriver IPC 不会起来)⇒ 先按上面第一行处置" ;;
248
- *) case "$client_login" in
249
- *尚未登录*|*CLIENT_LOGGED_OUT*) echo " ⇒ 判定:**客户端登录态失效**(这一层需要人点一次;WebDriver 自动化本身未必受影响)" ;;
250
- *) echo " ⇒ 判定:客户端登录态看起来正常 ⇒ 问题在 WebDriver 侧(看上面 IPC/授权两行)" ;;
251
- esac ;;
282
+ *) if [ "$_cred_kind" = "store-mismatch" ]; then
283
+ echo " ⇒ 判定:**名单不一致**(上面 AUTH 那行已逐项列出差异)"
284
+ echo " 处置:本流程要用的店 ⇒ 补 stores.json;不归本流程的店(Shopee/TikTok 等)⇒ 可忽略,"
285
+ echo " 新版本已把「客户端有、stores.json 无」降级为 warn,只有「stores.json 有、客户端无」才判红。"
286
+ else
287
+ case "$client_login" in
288
+ *尚未登录*|*CLIENT_LOGGED_OUT*) echo " ⇒ 判定:**客户端登录态失效**(这一层需要人点一次;WebDriver 自动化本身未必受影响)" ;;
289
+ *) echo " ⇒ 判定:客户端登录态看起来正常 ⇒ 问题在 WebDriver 侧(看上面 IPC/授权两行)" ;;
290
+ esac
291
+ fi ;;
252
292
  esac
253
- echo " 处置顺序:① 打开紫鸟客户端确认登录态;② 若被登出,先试 ziniao-cli zclaw login;"
254
- echo " ③ 仍不行再人工登录一次(密码/短信验证无法自动化)"
255
- echo " 影响:常驻 WebDriver 模式下,授权失效会让所有票在开跑前失败(不是票的问题)"
293
+ if [ "$_cred_kind" = "store-mismatch" ]; then
294
+ echo " 影响:本流程的票会在开跑前被名单校验拦下(不是票的问题)"
295
+ else
296
+ echo " 处置顺序:① 打开紫鸟客户端确认登录态;② 若被登出,先试 ziniao-cli zclaw login;"
297
+ echo " ③ 仍不行再人工登录一次(密码/短信验证无法自动化)"
298
+ echo " 影响:常驻 WebDriver 模式下,授权失效会让所有票在开跑前失败(不是票的问题)"
299
+ fi
256
300
  if [ "$login_limited" = "1" ]; then
257
301
  echo " ⚠️ 注意:本次「程序化登录」被供应商限流,**未真正判定**登录态;1 分钟后可复跑确认"
258
302
  elif [ "$login_limited" = "2" ]; then
259
303
  echo " ⚠️ 注意:本次跳过了程序化登录(${LOGIN_MIN_S}s 内已试过)⇒ 登录态结论为**未判定**"
260
304
  fi
261
305
  } >&2
306
+ _ledger_detail="紫鸟授权链路不可用且 zclaw login 自愈失败:IPC=${wd_out:0:60} AUTH=${cred_out:0:60}"
307
+ _tel_detail="紫鸟授权链路不可用(需人工;已尝试 zclaw login)"
308
+ if [ "$_cred_kind" = "store-mismatch" ]; then
309
+ _ledger_detail="店铺名单与 stores.json 不一致(非授权失效):${cred_out:0:200}"
310
+ _tel_detail="店铺名单与 stores.json 不一致(需人工核对;非授权失效)"
311
+ fi
262
312
  "$PY" "$REPO/scripts/flow_ledger.py" --case-id "auth__ziniao" --event blocked \
263
- --by ziniao-auth-probe --detail "紫鸟授权链路不可用且 zclaw login 自愈失败:IPC=${wd_out:0:60} AUTH=${cred_out:0:60}" \
264
- >/dev/null 2>&1 || true
313
+ --by ziniao-auth-probe --detail "$_ledger_detail" >/dev/null 2>&1 || true
265
314
  "$PY" "$REPO/scripts/telemetry.py" --emit --kind engine --flow full --error-class needs_human \
266
- --detail "紫鸟授权链路不可用(需人工;已尝试 zclaw login)" >/dev/null 2>&1 || true
315
+ --detail "$_tel_detail" >/dev/null 2>&1 || true
267
316
  "$PY" "$REPO/scripts/telemetry.py" --flush >/dev/null 2>&1 || true
268
317
  exit 2
File without changes
File without changes
File without changes
@@ -138,6 +138,35 @@ description: "美客多美客多 FULL 货件管理技能(Argent on DSH)—
138
138
 
139
139
  ---
140
140
 
141
+ ## 失败评估(2026-10-24 起)
142
+
143
+ FULL 一轮约 10 分钟,且包含建单/预约/上传等写操作;**失败后默认不自动重跑**。
144
+
145
+ 先只读取证:
146
+
147
+ - `failures.jsonl` 的 `page_url` / `hub_status` / `dom_summary` / `screenshot`;
148
+ - 失败现场截图(用 `read_image` 看);
149
+ - 预约、产品标签、箱唛当前状态。
150
+
151
+ 再输出结构化判断:
152
+
153
+ ```json
154
+ {
155
+ "verdict": "complete | retry | repair_script | needs_human",
156
+ "confidence": 0.0,
157
+ "reason": "...",
158
+ "evidence": ["..."],
159
+ "safe_to_retry": false
160
+ }
161
+ ```
162
+
163
+ - `complete`:门户已完成 ⇒ 不重跑、不取消预约;
164
+ - `retry`:仅瞬时故障且没有写坏状态,最多受控重跑 1 次;
165
+ - `repair_script`:页面改版/选择器失效 ⇒ 建开发工单,不直接改生产;
166
+ - `needs_human`:缺数据/业务状态/预约需人工核对 ⇒ 落卡等人。
167
+
168
+ 禁止:无评估直接 `--allow-write`、失败分支自动取消预约、为“试试看”重跑、自动修改生产脚本。
169
+
141
170
  ## 异常处理
142
171
 
143
172
  | 异常问题 | 核心原因 | 解决方案 |
@@ -0,0 +1,39 @@
1
+ # Agentic Runtime v3(FULL)
2
+
3
+ > 适用:Argent 0.8.0+;与 `docs/agentic-tools-contract-v1.md` 配套。
4
+ > 本文件是 Agent 会话的行为规则;确定性 SOP 仍在 SKILL.md / pitfalls.md。
5
+
6
+ ## 会话启动
7
+
8
+ 1. 读取本文件 + `ml-fulfillment-sop/SKILL.md` 的 8 步流程;
9
+ 2. 读取 ERP 下发 `AgentTask.context`(货件号、店铺、SKU、数量、箱数、约束、预算);
10
+ 3. 先调用 `ml_probe_hub` 确认整票状态,再决定是否需要执行。
11
+
12
+ ## 只允许使用工具
13
+
14
+ - 工具清单见 `docs/agentic-tools-contract-v1.md`;
15
+ - **禁止**编写/执行临时 Python/JS 脚本、禁止直接调用浏览器点击、禁止直接写飞书表;
16
+ - 工具不满足需求时:停止并在结果中说明「缺工具 X」,不要现场发明脚本。
17
+
18
+ ## 执行循环
19
+
20
+ ```text
21
+ probe → 判断 → 调用工具 → 读回验证 → 继续 / 信号 ERP / 结束
22
+ ```
23
+
24
+ - 每个写工具调用后必须立即读回验证;
25
+ - 同一动作最多 3 次;不得连续重试同一失败页面;
26
+ - 平台选项不可用/前置未完成 → 立即 `needs_decision`,附截图/选项;
27
+ - 数量/费用/运输方式冲突 → 必须人工决策,不得自行选择。
28
+
29
+ ## 异常信号
30
+
31
+ 按契约 §5 发送 `AgentSignal`,字段:
32
+ `phase / kind / evidence / observed / options / suggestedAction / requiresApproval`。
33
+ 发送后进入等待,不重复提交写操作。
34
+
35
+ ## 完成条件
36
+
37
+ - `ml_probe_hub` 五项/整票状态与任务目标一致;
38
+ - 需要回写的文件已通过 ERP AgentTask 完成态接口读回验证;0.8 不再写 lip 表。
39
+ - 输出 `done` + 证据 + 耗时/成本摘要。