@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,224 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ml-insight-timers.sh —— **Listing 体检 / 竞品快照**的确定性定时器(安装/卸载/状态,2026-11-20)。
|
|
3
|
+
#
|
|
4
|
+
# 目的(零命令化):客户不敲命令 —— 装一次定时器,之后每天自动跑:
|
|
5
|
+
# · com.whyshu.ml-listing-timer → ml-insight-run.sh listing(体检 + 推 ERP「刊登优化」页)
|
|
6
|
+
# · com.whyshu.ml-market-timer → ml-insight-run.sh market (自有在售 + 客户竞品快照)
|
|
7
|
+
# · com.whyshu.ml-insight-timer → ml-insight-run.sh diagnose(店铺诊断 + 推 ERP「AI 建议」tab)
|
|
8
|
+
#
|
|
9
|
+
# 开关与时间来自设置页写入的 `daily-report.env`:
|
|
10
|
+
# ML_LISTING_ENABLED / ML_LISTING_TIME(默认 09:40)/ ML_LISTING_LIMIT(默认 20)
|
|
11
|
+
# ML_MARKET_ENABLED / ML_MARKET_TIME(默认 10:10)/ ML_MARKET_DAYS(默认 30)
|
|
12
|
+
# ML_ADS_ENABLED / ML_ADS_TIME(默认 11:00)/ ML_ADS_DAYS(默认 7)
|
|
13
|
+
# ML_MESSAGES_ENABLED / ML_MESSAGES_TIME(默认 11:30)/ ML_MESSAGES_LIMIT(默认 20)
|
|
14
|
+
# ML_CATEGORY_ENABLED / ML_CATEGORY_TIME(默认 12:00)/ ML_CATEGORY_LIMIT(默认 50)
|
|
15
|
+
# ML_INSIGHT_ENABLED(开关;小时 :20 跑,只处理 ≤6h 新日报快照,零请求;无新快照自动跳过)
|
|
16
|
+
# ⚠️ 时间是**客户机本地时区**(当前=北京时间);改时间后需重跑 install 让 plist 生效。
|
|
17
|
+
#
|
|
18
|
+
# 用法:
|
|
19
|
+
# bash scripts/ml-insight-timers.sh status
|
|
20
|
+
# bash scripts/ml-insight-timers.sh print-plist [listing|market|diagnose]
|
|
21
|
+
# bash scripts/ml-insight-timers.sh install [--dry-run] [--force] [--allow-non-production]
|
|
22
|
+
# bash scripts/ml-insight-timers.sh uninstall
|
|
23
|
+
# bash scripts/ml-insight-timers.sh run-now <listing|market|diagnose>
|
|
24
|
+
#
|
|
25
|
+
# ⛔ 开发机默认拒绝 install(生产姿态门禁);真装必须在客户机(本机 bootstrap 生产型调度器是红线)。
|
|
26
|
+
set -euo pipefail
|
|
27
|
+
|
|
28
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
29
|
+
. "$SCRIPT_DIR/lib/argent-datadir.sh"
|
|
30
|
+
|
|
31
|
+
LABEL_LISTING="com.whyshu.ml-listing-timer"
|
|
32
|
+
LABEL_MARKET="com.whyshu.ml-market-timer"
|
|
33
|
+
LABEL_DIAGNOSE="com.whyshu.ml-insight-timer"
|
|
34
|
+
LABEL_ADS="com.whyshu.ml-ads-timer"
|
|
35
|
+
LABEL_MESSAGES="com.whyshu.ml-messages-timer"
|
|
36
|
+
LABEL_CATEGORY="com.whyshu.ml-category-timer"
|
|
37
|
+
AGENTS="$HOME/Library/LaunchAgents"
|
|
38
|
+
DATA_HOME="${ARGENT_DATA_DIR_RESOLVED:?数据根解析失败:请显式给 ARGENT_DATA_DIR}"
|
|
39
|
+
LOG_DIR="$DATA_HOME/ml-insight-logs"
|
|
40
|
+
RUNNER="$SCRIPT_DIR/ml-insight-run.sh"
|
|
41
|
+
GEN="$SCRIPT_DIR/daily-report-timer-plist.sh"
|
|
42
|
+
ENV_FILE="$DATA_HOME/daily-report.env"
|
|
43
|
+
|
|
44
|
+
usage() { sed -n '2,22p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
|
|
45
|
+
now() { date '+%F %T'; }
|
|
46
|
+
|
|
47
|
+
find_bin_dir() { # $1=可执行名;$2..=回退候选目录
|
|
48
|
+
local name="$1"; shift
|
|
49
|
+
local hit; hit="$(command -v "$name" 2>/dev/null || true)"
|
|
50
|
+
if [ -n "$hit" ]; then dirname "$hit"; return 0; fi
|
|
51
|
+
local d
|
|
52
|
+
for d in "$@"; do [ -x "$d/$name" ] && { printf '%s' "$d"; return 0; }; done
|
|
53
|
+
printf '/usr/local/bin'
|
|
54
|
+
}
|
|
55
|
+
node_dir() { find_bin_dir node "$HOME/.local/node/bin" "$HOME/node/bin" /opt/homebrew/bin /usr/local/bin; }
|
|
56
|
+
lark_dir() { find_bin_dir lark-cli "$HOME/.local/bin" "$HOME/.local/node/bin" /opt/homebrew/bin /usr/local/bin; }
|
|
57
|
+
|
|
58
|
+
env_get() {
|
|
59
|
+
[ -f "$ENV_FILE" ] || return 0
|
|
60
|
+
grep -E "^[[:space:]]*$1=" "$ENV_FILE" 2>/dev/null | tail -1 | cut -d= -f2- | tr -d '"' | tr -d "'" | sed 's/[[:space:]]*$//'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# "HH:MM" → HOUR MINUTE(缺省 09:40 / 10:10;非法值回落缺省并显式告警)
|
|
64
|
+
split_hhmm() { # $1=值 $2=缺省
|
|
65
|
+
local v="${1:-}"; local def="$2"
|
|
66
|
+
[ -n "$v" ] || v="$def"
|
|
67
|
+
case "$v" in
|
|
68
|
+
[0-2][0-9]:[0-5][0-9]) ;;
|
|
69
|
+
*) echo "⚠ $v 不是 HH:MM,回落缺省 $def" >&2; v="$def" ;;
|
|
70
|
+
esac
|
|
71
|
+
HOUR="${v%%:*}"; MINUTE="${v##*:}"
|
|
72
|
+
# 去掉前导 0 供 launchd integer
|
|
73
|
+
HOUR="$((10#$HOUR))"; MINUTE="$((10#$MINUTE))"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
gen() { # $1=listing|market(纯 stdout)
|
|
77
|
+
local job="$1" hour minute label logname
|
|
78
|
+
if [ "$job" = "listing" ]; then
|
|
79
|
+
split_hhmm "$(env_get ML_LISTING_TIME)" "09:40"; label="$LABEL_LISTING"; logname="ml-listing-timer"
|
|
80
|
+
elif [ "$job" = "category" ]; then
|
|
81
|
+
split_hhmm "$(env_get ML_CATEGORY_TIME)" "12:00"; label="$LABEL_CATEGORY"; logname="ml-category-timer"
|
|
82
|
+
elif [ "$job" = "messages" ]; then
|
|
83
|
+
split_hhmm "$(env_get ML_MESSAGES_TIME)" "11:30"; label="$LABEL_MESSAGES"; logname="ml-messages-timer"
|
|
84
|
+
elif [ "$job" = "ads" ]; then
|
|
85
|
+
split_hhmm "$(env_get ML_ADS_TIME)" "11:00"; label="$LABEL_ADS"; logname="ml-ads-timer"
|
|
86
|
+
elif [ "$job" = "diagnose" ]; then
|
|
87
|
+
# 2026-11-25:诊断跟日报节拍(日报每小时 :05 按站点本地时间门控)⇒ 诊断每小时 :20 跑,
|
|
88
|
+
# 脚本内只处理"≤6h 新快照"的店;没有新快照就跳过(零请求)。
|
|
89
|
+
HOUR=""; MINUTE="20"; label="$LABEL_DIAGNOSE"; logname="ml-insight-timer"
|
|
90
|
+
else
|
|
91
|
+
split_hhmm "$(env_get ML_MARKET_TIME)" "10:10"; label="$LABEL_MARKET"; logname="ml-market-timer"
|
|
92
|
+
fi
|
|
93
|
+
# ⚠️ macOS bash 3.2 + `set -u`:**空数组展开会报 unbound variable**(2026-11-29 客户机实测),
|
|
94
|
+
# 所以有/无 --hour 两条分支各写一遍,⛔ 不要用 "${arr[@]}" 展开可能为空的数组。
|
|
95
|
+
if [ -n "$HOUR" ]; then
|
|
96
|
+
bash "$GEN" --label "$label" --script "$RUNNER" \
|
|
97
|
+
--data-dir "$DATA_HOME" --log-dir "$LOG_DIR" \
|
|
98
|
+
--node-dir "$(node_dir)" --lark-dir "$(lark_dir)" \
|
|
99
|
+
--log-name "$logname" --arg "$job" --hour "$HOUR" --minute "$MINUTE"
|
|
100
|
+
else
|
|
101
|
+
bash "$GEN" --label "$label" --script "$RUNNER" \
|
|
102
|
+
--data-dir "$DATA_HOME" --log-dir "$LOG_DIR" \
|
|
103
|
+
--node-dir "$(node_dir)" --lark-dir "$(lark_dir)" \
|
|
104
|
+
--log-name "$logname" --arg "$job" --minute "$MINUTE"
|
|
105
|
+
fi
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
is_production() {
|
|
109
|
+
# 放行条件(任一):config.json dailyReport.role=production | allowedChatIds 非空 | --allow-non-production
|
|
110
|
+
local role allow
|
|
111
|
+
role="$(/usr/bin/python3 - "$DATA_HOME/config.json" <<'PYEOF' 2>/dev/null || true
|
|
112
|
+
import json, sys
|
|
113
|
+
try:
|
|
114
|
+
d = json.load(open(sys.argv[1]))
|
|
115
|
+
print((d.get('dailyReport') or {}).get('role', ''))
|
|
116
|
+
except Exception:
|
|
117
|
+
print('')
|
|
118
|
+
PYEOF
|
|
119
|
+
)"
|
|
120
|
+
allow="$(/usr/bin/python3 - "$DATA_HOME/config.json" <<'PYEOF' 2>/dev/null || true
|
|
121
|
+
import json, sys
|
|
122
|
+
try:
|
|
123
|
+
d = json.load(open(sys.argv[1]))
|
|
124
|
+
print(len((d.get('dailyReport') or {}).get('allowedChatIds') or []))
|
|
125
|
+
except Exception:
|
|
126
|
+
print('0')
|
|
127
|
+
PYEOF
|
|
128
|
+
)"
|
|
129
|
+
[ "$role" = "production" ] && return 0
|
|
130
|
+
[ "${allow:-0}" -gt 0 ] && return 0
|
|
131
|
+
return 1
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
label_for_job() {
|
|
135
|
+
case "$1" in
|
|
136
|
+
listing) echo "$LABEL_LISTING" ;;
|
|
137
|
+
market) echo "$LABEL_MARKET" ;;
|
|
138
|
+
ads) echo "$LABEL_ADS" ;;
|
|
139
|
+
messages) echo "$LABEL_MESSAGES" ;;
|
|
140
|
+
category) echo "$LABEL_CATEGORY" ;;
|
|
141
|
+
*) echo "$LABEL_DIAGNOSE" ;;
|
|
142
|
+
esac
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
do_install() {
|
|
146
|
+
local dry=0 force=0 allow_np=0
|
|
147
|
+
for a in "$@"; do
|
|
148
|
+
case "$a" in
|
|
149
|
+
--dry-run) dry=1 ;;
|
|
150
|
+
--force) force=1 ;;
|
|
151
|
+
--allow-non-production) allow_np=1 ;;
|
|
152
|
+
*) echo "未知参数: $a" >&2; exit 2 ;;
|
|
153
|
+
esac
|
|
154
|
+
done
|
|
155
|
+
if [ "$allow_np" = "0" ] && ! is_production; then
|
|
156
|
+
cat >&2 <<MSG
|
|
157
|
+
❌ 拒绝安装:本机不是「Listing 体检/竞品快照」生产机(dailyReport.role=$(/usr/bin/python3 - "$DATA_HOME/config.json" <<'PY' 2>/dev/null || true
|
|
158
|
+
import json,sys
|
|
159
|
+
try: print((json.load(open(sys.argv[1])).get('dailyReport') or {}).get('role',''))
|
|
160
|
+
except Exception: print('')
|
|
161
|
+
PY
|
|
162
|
+
),allowedChatIds 见 config.json)
|
|
163
|
+
这条定时器会定时打平台 API 并推客户 ERP ⇒ 开发机装它 = 双跑。
|
|
164
|
+
要在客户机装:在客户的 ~/.dsh/argent/config.json 设
|
|
165
|
+
"dailyReport": { "role": "production" }
|
|
166
|
+
或显式加 --allow-non-production(自己承担后果)。
|
|
167
|
+
MSG
|
|
168
|
+
exit 3
|
|
169
|
+
fi
|
|
170
|
+
[ -n "$(env_get ML_LISTING_ENABLED)$(env_get ML_MARKET_ENABLED)$(env_get ML_INSIGHT_ENABLED)" ] || echo "⚠ daily-report.env 里没有 ML_LISTING_ENABLED/ML_MARKET_ENABLED/ML_INSIGHT_ENABLED;定时器会每小时空跑(脚本内判断启用)" >&2
|
|
171
|
+
mkdir -p "$AGENTS" "$LOG_DIR"
|
|
172
|
+
# ⚠️ 新增任务必须同时加进这个循环(2026-12-01 客户机实测:漏了 ads/messages/category ⇒
|
|
173
|
+
# "安装"显示成功但新定时器没装上)。
|
|
174
|
+
# ⚠️ 标签用独立函数取:multi-line case 放进 $( ) 在 macOS bash 3.2 会被拆错
|
|
175
|
+
# (客户机 0.13.25 实测:filename "esac ).plist: File name too long")。
|
|
176
|
+
for job in listing market diagnose ads messages category; do
|
|
177
|
+
local plist="$AGENTS/$(label_for_job "$job").plist"
|
|
178
|
+
gen "$job" > /tmp/ml-insight-$job.plist
|
|
179
|
+
if [ "$dry" = "1" ]; then
|
|
180
|
+
echo "── 将写入 ${plist}:"; cat /tmp/ml-insight-$job.plist
|
|
181
|
+
continue
|
|
182
|
+
fi
|
|
183
|
+
cp /tmp/ml-insight-$job.plist "$plist"
|
|
184
|
+
chmod 644 "$plist"
|
|
185
|
+
launchctl bootout "gui/$(id -u)" "$plist" 2>/dev/null || true
|
|
186
|
+
launchctl bootstrap "gui/$(id -u)" "$plist"
|
|
187
|
+
echo "✅ 已安装 $plist"
|
|
188
|
+
done
|
|
189
|
+
[ "$dry" = "1" ] || { chmod +x "$RUNNER" 2>/dev/null || true; echo "✅ 入口脚本可执行:$RUNNER"; }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
do_status() {
|
|
193
|
+
echo "数据根:$DATA_HOME"
|
|
194
|
+
[ -f "$ENV_FILE" ] && echo "env:$ENV_FILE" || echo "env:(缺)"
|
|
195
|
+
echo "开关:ML_LISTING_ENABLED=$(env_get ML_LISTING_ENABLED || true) ML_MARKET_ENABLED=$(env_get ML_MARKET_ENABLED || true) ML_INSIGHT_ENABLED=$(env_get ML_INSIGHT_ENABLED || true)"
|
|
196
|
+
echo "时间:ML_LISTING_TIME=$(env_get ML_LISTING_TIME || true) ML_MARKET_TIME=$(env_get ML_MARKET_TIME || true) ML_ADS_TIME=$(env_get ML_ADS_TIME || true) insight=每小时 :20(跟随日报快照) (客户机本地时区)"
|
|
197
|
+
for l in "$LABEL_LISTING" "$LABEL_MARKET" "$LABEL_DIAGNOSE" "$LABEL_ADS" "$LABEL_MESSAGES" "$LABEL_CATEGORY"; do
|
|
198
|
+
if launchctl list 2>/dev/null | grep -q "[[:space:]]$l\$"; then echo "launchd:$l ✅ 已加载"; else echo "launchd:$l ❌ 未加载"; fi
|
|
199
|
+
done
|
|
200
|
+
ls -1 "$LOG_DIR"/*.log 2>/dev/null | sed 's/^/日志:/' || true
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
do_uninstall() {
|
|
204
|
+
for l in "$LABEL_LISTING" "$LABEL_MARKET" "$LABEL_DIAGNOSE" "$LABEL_ADS" "$LABEL_MESSAGES" "$LABEL_CATEGORY"; do
|
|
205
|
+
local plist="$AGENTS/$l.plist"
|
|
206
|
+
if [ -f "$plist" ]; then
|
|
207
|
+
launchctl bootout "gui/$(id -u)" "$plist" 2>/dev/null || true
|
|
208
|
+
rm -f "$plist"; echo "✅ 已卸载 $l"
|
|
209
|
+
else
|
|
210
|
+
echo "(未安装)$l"
|
|
211
|
+
fi
|
|
212
|
+
done
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
cmd="${1:-}"; shift || true
|
|
216
|
+
case "$cmd" in
|
|
217
|
+
status) do_status ;;
|
|
218
|
+
print-plist) job="${1:-listing}"; case "$job" in listing|market|diagnose|ads|messages|category) gen "$job" ;; *) echo "print-plist 只接受 listing|market|diagnose|ads|messages|category" >&2; exit 2 ;; esac ;;
|
|
219
|
+
install) do_install "$@" ;;
|
|
220
|
+
uninstall) do_uninstall ;;
|
|
221
|
+
run-now) job="${1:-}"; case "$job" in listing|market|diagnose|ads|messages|category) bash "$RUNNER" "$job" ;; *) echo "run-now 只接受 listing|market|diagnose|ads|messages|category" >&2; exit 2 ;; esac ;;
|
|
222
|
+
-h|--help|'') usage ;;
|
|
223
|
+
*) echo "未知命令: $cmd" >&2; usage; exit 2 ;;
|
|
224
|
+
esac
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ml-listing-audit.mjs —— Listing 体检(**只读**):官方质量分 + 该改什么。
|
|
4
|
+
*
|
|
5
|
+
* ## 干什么
|
|
6
|
+
* 逐店抽样在售商品 → `GET /item/{id}/performance`(官方 0–100 分 + 待办 rules + 深链)
|
|
7
|
+
* → 中文整改清单(按平台 WARNING/OPPORTUNITY 排序)。
|
|
8
|
+
*
|
|
9
|
+
* ## 用法
|
|
10
|
+
* node scripts/ml-listing-audit.mjs # 全部已授权店铺 · 每店抽查 20 个
|
|
11
|
+
* node scripts/ml-listing-audit.mjs --store 1店 # 店铺子串过滤
|
|
12
|
+
* node scripts/ml-listing-audit.mjs --limit 50 # 每店抽查数(上限 200,单 item 接口)
|
|
13
|
+
* node scripts/ml-listing-audit.mjs --offset 20 # 跳过前 N 个在售(轮换抽查)
|
|
14
|
+
* node scripts/ml-listing-audit.mjs --json # 结构化输出(stdout 纯 JSON)
|
|
15
|
+
* node scripts/ml-listing-audit.mjs --lines # 只出中文卡片行(角色回复/日报复用)
|
|
16
|
+
*
|
|
17
|
+
* ## 只读纪律(与 ml-ads.mjs 同一条授权链)
|
|
18
|
+
* · 只发 GET;⛔ 不改标题/属性/图片/价格,也不写任何客户数据;
|
|
19
|
+
* · 唯一写盘 = token 轮换回写(refresh_token 单链,不写回下次必 429):原子写 + 600;
|
|
20
|
+
* · API 基址:`ML_API_BASE` → 默认平台地址(lib 里⛔不含域名)。
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync, writeFileSync, renameSync, existsSync, mkdirSync, chmodSync } from 'node:fs'
|
|
23
|
+
import { join, dirname } from 'node:path'
|
|
24
|
+
import { resolveDataDir } from './lib/argent-datadir.mjs'
|
|
25
|
+
import {
|
|
26
|
+
loadEnvFile, refreshStoreToken, apiGet as coreApiGet,
|
|
27
|
+
SITE_CURRENCY, fallbackSite, matchStores,
|
|
28
|
+
} from './lib/daily-report-core.mjs'
|
|
29
|
+
import { runListingAudit, listingCardLines, GRADE_THRESHOLDS, buildListingBridgePayload, pushListingReport } from './lib/ml-listing-core.mjs'
|
|
30
|
+
import { resolveBridgeAuth, readAgentReport, assertBridgeAuth } from './lib/ml-bridge-auth.mjs'
|
|
31
|
+
|
|
32
|
+
const API_BASE = () => process.env.ML_API_BASE || 'https://api.mercadolibre.com'
|
|
33
|
+
// 引擎侧 `apiGet` 不硬编码域名(vertical 门禁)⇒ CLI 必须把基址注入进程环境,
|
|
34
|
+
// 否则 refreshStoreToken 这条内部路径会报「缺少 API 基址」(2026-11-28 客户机实测:竞品定时器全店失败)。
|
|
35
|
+
if (!process.env.ML_API_BASE) process.env.ML_API_BASE = API_BASE()
|
|
36
|
+
|
|
37
|
+
const args = process.argv.slice(2)
|
|
38
|
+
const argVal = (n) => { const i = args.indexOf(n); return i >= 0 && args[i + 1] ? args[i + 1] : null }
|
|
39
|
+
const has = (n) => args.includes(n)
|
|
40
|
+
|
|
41
|
+
if (has('-h') || has('--help')) {
|
|
42
|
+
console.log(`Listing 体检(只读)
|
|
43
|
+
|
|
44
|
+
用法: node scripts/ml-listing-audit.mjs [选项]
|
|
45
|
+
--store <名或uid> 店铺过滤(名称子串 / uid 全等,与日报同一判据)
|
|
46
|
+
--limit <n> 每店抽查数,默认 20(上限 200;单 item 接口,注意配额)
|
|
47
|
+
--offset <n> 跳过前 n 个在售,用于轮换抽查
|
|
48
|
+
--json 结构化 JSON(stdout)
|
|
49
|
+
--lines 中文卡片行(日报分区/角色回复复用)
|
|
50
|
+
--push 把体检结果上报 ERP(POST /reports/listing/bridge;只报结果,不改商品)
|
|
51
|
+
需要:ARGENT_API_BASE / ARGENT_TENANT / DAILY_REPORT_BRIDGE_SECRET(或 APPOINTMENT_BRIDGE_SECRET)
|
|
52
|
+
--dry-run 配 --push 时只打印上报 body(不联网),用于核对契约
|
|
53
|
+
--api <url> ERP 地址(缺省读 ARGENT_API_BASE)
|
|
54
|
+
--tenant <appId> 租户 appId(缺省读 ARGENT_TENANT)
|
|
55
|
+
--top <n> 卡片里展示的最差商品数,默认 3
|
|
56
|
+
--env <path> daily-report.env 路径
|
|
57
|
+
退出码: 0 正常 | 1 用法/取数失败 | 2 全部店铺失败`)
|
|
58
|
+
process.exit(0)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const DATA_DIR = resolveDataDir({ env: process.env }).dir
|
|
62
|
+
const ENV_PATH = argVal('--env') || join(DATA_DIR, 'daily-report.env')
|
|
63
|
+
const STORES_PATH = process.env.ML_API_STORES_JSON || join(DATA_DIR, 'ml-api-stores.json')
|
|
64
|
+
const env = loadEnvFile(ENV_PATH)
|
|
65
|
+
const doc = existsSync(STORES_PATH) ? JSON.parse(readFileSync(STORES_PATH, 'utf8')) : { stores: [] }
|
|
66
|
+
const stores = doc.stores || []
|
|
67
|
+
|
|
68
|
+
const persistStores = () => {
|
|
69
|
+
try {
|
|
70
|
+
mkdirSync(dirname(STORES_PATH), { recursive: true })
|
|
71
|
+
const tmp = `${STORES_PATH}.tmp`
|
|
72
|
+
writeFileSync(tmp, JSON.stringify({ stores }, null, 2) + '\n', { mode: 0o600 })
|
|
73
|
+
renameSync(tmp, STORES_PATH)
|
|
74
|
+
chmodSync(STORES_PATH, 0o600)
|
|
75
|
+
} catch (e) { console.error(`✗ token 写回失败:${e.message}`) }
|
|
76
|
+
}
|
|
77
|
+
const apiGet = (path, token) => coreApiGet(path, token, { base: API_BASE() })
|
|
78
|
+
|
|
79
|
+
const FLAG_JSON = has('--json')
|
|
80
|
+
const FLAG_LINES = has('--lines')
|
|
81
|
+
const FLAG_PUSH = has('--push')
|
|
82
|
+
const FLAG_DRY = has('--dry-run')
|
|
83
|
+
const limit = Math.max(1, Math.min(200, Number(argVal('--limit') || env.ML_LISTING_LIMIT || process.env.ML_LISTING_LIMIT || 20)))
|
|
84
|
+
const offset = Math.max(0, Number(argVal('--offset') || 0))
|
|
85
|
+
const topN = Math.max(1, Number(argVal('--top') || 3))
|
|
86
|
+
|
|
87
|
+
const picked = matchStores(stores, (argVal('--store') || '').split(',').map((x) => x.trim()).filter(Boolean))
|
|
88
|
+
if (!picked.length) {
|
|
89
|
+
console.error(`✗ 没有匹配到店铺(已授权 ${stores.length} 家)`)
|
|
90
|
+
process.exit(1)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const results = []
|
|
94
|
+
for (const store of picked) {
|
|
95
|
+
const site = fallbackSite(store.site)
|
|
96
|
+
const row = { store: store.name, site, uid: store.user_id, currency: SITE_CURRENCY[site] || '' }
|
|
97
|
+
try {
|
|
98
|
+
const token = await refreshStoreToken(env, store, { onRotate: persistStores })
|
|
99
|
+
const r = await runListingAudit({ apiGet, token, site, uid: store.user_id, limit, offset })
|
|
100
|
+
row.summary = r.summary
|
|
101
|
+
row.note = r.note || ''
|
|
102
|
+
row.items = r.items
|
|
103
|
+
results.push(row)
|
|
104
|
+
} catch (e) {
|
|
105
|
+
row.error = String(e.message || e)
|
|
106
|
+
results.push(row)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const ok = results.filter((r) => !r.error)
|
|
111
|
+
if (!ok.length) {
|
|
112
|
+
if (FLAG_JSON) console.log(JSON.stringify({ results }, null, 2))
|
|
113
|
+
else for (const r of results) console.error(`✗ ${r.store}:${r.error}`)
|
|
114
|
+
process.exit(2)
|
|
115
|
+
}
|
|
116
|
+
// ── 上报 ERP(--push):只上报体检结果,⛔ 不改任何商品 ─────────────────
|
|
117
|
+
if (FLAG_PUSH) {
|
|
118
|
+
const report = readAgentReport({ file: join(DATA_DIR, 'agent-report.json') })
|
|
119
|
+
const auth = resolveBridgeAuth({ env: { ...process.env, ...(argVal('--api') ? { ARGENT_API_BASE: argVal('--api') } : {}), ...(argVal('--tenant') ? { ARGENT_TENANT: argVal('--tenant') } : {}) }, agentReport: report })
|
|
120
|
+
assertBridgeAuth(auth)
|
|
121
|
+
let fail = 0
|
|
122
|
+
for (const r of ok) {
|
|
123
|
+
const payload = buildListingBridgePayload(r, { limit, offset, capturedAt: new Date().toISOString() })
|
|
124
|
+
if (FLAG_DRY) {
|
|
125
|
+
const url = `${auth.base.replace(/\/+$/, '')}/api/argent/v1/tenants/${encodeURIComponent(auth.tenant)}/reports/listing/bridge`
|
|
126
|
+
console.log(JSON.stringify({ dryRun: true, authMode: auth.mode, url, payload }, null, 2))
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const res = await pushListingReport(payload, { base: auth.base, tenant: auth.tenant, secret: auth.secret, machineToken: auth.machineToken })
|
|
131
|
+
if (res.ok) console.error(`✓ ${r.store} 已上报 ERP(HTTP ${res.status})`)
|
|
132
|
+
else { r.pushError = res.error; fail++; console.error(`✗ ${r.store} 上报失败:${res.error}`) }
|
|
133
|
+
} catch (e) {
|
|
134
|
+
r.pushError = String((e && e.message) || e); fail++
|
|
135
|
+
console.error(`✗ ${r.store} 上报失败:${r.pushError}`)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (fail && fail === ok.length) process.exit(2)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (FLAG_JSON) {
|
|
142
|
+
console.log(JSON.stringify({ generatedAt: new Date().toISOString(), limit, offset, thresholds: GRADE_THRESHOLDS, results }, null, 2))
|
|
143
|
+
process.exit(0)
|
|
144
|
+
}
|
|
145
|
+
if (FLAG_LINES) {
|
|
146
|
+
for (const r of ok) {
|
|
147
|
+
console.log(`### ${r.store}`)
|
|
148
|
+
console.log(listingCardLines(r, { currency: r.currency, topN }).join('\n'))
|
|
149
|
+
}
|
|
150
|
+
process.exit(0)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 默认:Markdown 报告(按分数升序,最差在前)
|
|
154
|
+
let text = `## 🩺 Listing 体检(每店抽查 ${limit} 个在售,offset=${offset})\n\n`
|
|
155
|
+
for (const r of results) {
|
|
156
|
+
if (r.error) { text += `### ${r.store}(${r.site})\n✗ ${r.error}\n\n`; continue }
|
|
157
|
+
const s = r.summary || {}
|
|
158
|
+
text += `### ${r.store}(${r.site})\n`
|
|
159
|
+
if (r.note) text += `> ${r.note}\n`
|
|
160
|
+
const g = s.grades || {}
|
|
161
|
+
text += `平均分 **${s.avg == null ? '—' : s.avg}**(已评分 ${s.scored}/${s.count})· A ${g.A || 0} / B ${g.B || 0} / C ${g.C || 0} / D ${g.D || 0} · 待办 ${s.pendingTotal || 0} 项\n\n`
|
|
162
|
+
const rows = [...(r.items || [])].sort((a, b) => (a.score == null ? 101 : a.score) - (b.score == null ? 101 : b.score))
|
|
163
|
+
text += '| 商品 | 分数 | 等级 | 待办 | 优先整改 |\n|---|---|---|---|---|\n'
|
|
164
|
+
for (const it of rows.slice(0, 15)) {
|
|
165
|
+
const acts = (it.actions || []).slice(0, 2).map((a) => a.hint || a.title).filter(Boolean).join(';')
|
|
166
|
+
text += `| ${it.id}${it.title ? ' ' + String(it.title).slice(0, 20) : ''} | ${it.score == null ? '—' : it.score} | ${it.grade} | ${it.pendingCount} | ${acts || '—'} |\n`
|
|
167
|
+
}
|
|
168
|
+
text += '\n'
|
|
169
|
+
}
|
|
170
|
+
console.log(text)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ml-market-matrix.mjs —— 竞品矩阵/趋势(P2b,只读):读 ml-market 快照 JSONL → 矩阵 + 趋势。
|
|
4
|
+
* 数据已有(定时器每日采集),本命令**不新增平台请求**;`--push` 把矩阵推到 ERP「智能分析 → 竞品矩阵」。
|
|
5
|
+
* 口径:销量/库存=平台分桶参考值(估算);趋势从接入日起算。
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
import { resolveDataDir } from './lib/argent-datadir.mjs'
|
|
10
|
+
import { storeKey } from './lib/daily-report-core.mjs'
|
|
11
|
+
import { parseSnapshotJsonl, buildMarketMatrix, buildMarketBridgePayload, marketMatrixLines } from './lib/ml-market-core.mjs'
|
|
12
|
+
import { resolveBridgeAuth, readAgentReport, assertBridgeAuth } from './lib/ml-bridge-auth.mjs'
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2)
|
|
15
|
+
const argVal = (n) => { const i = args.indexOf(n); return i >= 0 && args[i + 1] ? args[i + 1] : null }
|
|
16
|
+
const has = (n) => args.includes(n)
|
|
17
|
+
if (has('-h') || has('--help')) {
|
|
18
|
+
console.log(`竞品矩阵/趋势(只读)
|
|
19
|
+
|
|
20
|
+
用法: node scripts/ml-market-matrix.mjs [选项]
|
|
21
|
+
--store <名或uid> 店铺过滤(名称子串 / uid 全等)
|
|
22
|
+
--file <path> 快照 JSONL(默认数据目录 ml-market/<storeKey>.jsonl;多店时当目录)
|
|
23
|
+
--days <n> 标注的估算窗口(默认 30)
|
|
24
|
+
--json 结构化 JSON
|
|
25
|
+
--lines 中文卡片行
|
|
26
|
+
--push 推到 ERP 竞品矩阵 tab(机器令牌/共享密钥;先 --dry-run 核对)
|
|
27
|
+
--dry-run 配 --push 时只打印 payload
|
|
28
|
+
退出码: 0 正常 | 1 用法/无数据 | 2 推送失败`)
|
|
29
|
+
process.exit(0)
|
|
30
|
+
}
|
|
31
|
+
const DATA_DIR = resolveDataDir({ env: process.env }).dir
|
|
32
|
+
const days = Math.max(1, Math.min(180, Number(argVal('--days') || 30)))
|
|
33
|
+
const storesPath = process.env.ML_API_STORES_JSON || join(DATA_DIR, 'ml-api-stores.json')
|
|
34
|
+
const stores = existsSync(storesPath) ? (JSON.parse(readFileSync(storesPath, 'utf8')).stores || []) : []
|
|
35
|
+
const queries = (argVal('--store') || '').split(',').map((x) => x.trim()).filter(Boolean)
|
|
36
|
+
const picked = stores.filter((s) => !queries.length || queries.some((q) => String(s.name || '').includes(q) || String(s.user_id) === q))
|
|
37
|
+
const fileArg = argVal('--file')
|
|
38
|
+
|
|
39
|
+
function snapFile(store) {
|
|
40
|
+
if (fileArg) {
|
|
41
|
+
if (existsSync(fileArg) && !fileArg.endsWith('/')) return fileArg
|
|
42
|
+
const f = join(fileArg, `${storeKey(store)}.jsonl`)
|
|
43
|
+
return existsSync(f) ? f : null
|
|
44
|
+
}
|
|
45
|
+
const f = join(DATA_DIR, 'ml-market', `${storeKey(store)}.jsonl`)
|
|
46
|
+
return existsSync(f) ? f : null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const results = []
|
|
50
|
+
for (const store of picked.length ? picked : [{ name: '', user_id: '' }]) {
|
|
51
|
+
const f = snapFile(store)
|
|
52
|
+
if (!f) { results.push({ store: store.name, error: '没有竞品快照(先跑 ml-market-snapshot / 等定时器)' }); continue }
|
|
53
|
+
const parsed = parseSnapshotJsonl(readFileSync(f, 'utf8'))
|
|
54
|
+
if (!parsed.records.length) { results.push({ store: store.name, error: '快照为空或不可解析' }); continue }
|
|
55
|
+
const matrix = buildMarketMatrix(parsed.records)
|
|
56
|
+
results.push({ store: store.name || matrix.store, site: matrix.site, file: f, matrix })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const ok = results.filter((r) => !r.error)
|
|
60
|
+
if (!ok.length) {
|
|
61
|
+
if (has('--json')) console.log(JSON.stringify({ results }, null, 2))
|
|
62
|
+
else for (const r of results) console.error(`✗ ${r.store || '-'}:${r.error}`)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (has('--push')) {
|
|
67
|
+
const auth = resolveBridgeAuth({ env: process.env, agentReport: readAgentReport({ file: join(DATA_DIR, 'agent-report.json') }) })
|
|
68
|
+
assertBridgeAuth(auth)
|
|
69
|
+
let fail = 0
|
|
70
|
+
for (const r of ok) {
|
|
71
|
+
const payload = buildMarketBridgePayload(r.matrix, { days })
|
|
72
|
+
if (has('--dry-run')) { console.log(JSON.stringify({ dryRun: true, authMode: auth.mode, payload }, null, 2)); continue }
|
|
73
|
+
const url = `${auth.base.replace(/\/+$/, '')}/api/argent/v1/tenants/${encodeURIComponent(auth.tenant)}/reports/market/bridge`
|
|
74
|
+
const headers = { 'content-type': 'application/json', ...(auth.machineToken ? { authorization: `Bearer ${auth.machineToken}` } : {}), ...(auth.secret ? { 'x-appointment-secret': auth.secret } : {}) }
|
|
75
|
+
const res = await fetch(url, { method: 'POST', headers, body: JSON.stringify(payload), signal: AbortSignal.timeout(20000) }).catch((e) => ({ ok: false, status: 0, text: () => String(e.message) }))
|
|
76
|
+
const body = typeof res.json === 'function' ? await res.json().catch(() => ({})) : {}
|
|
77
|
+
if (res.ok) console.error(`✓ ${r.store} 已推到 ERP 竞品矩阵`)
|
|
78
|
+
else { fail++; console.error(`✗ ${r.store} 推送失败:HTTP ${res.status} ${JSON.stringify(body).slice(0, 160)}`) }
|
|
79
|
+
}
|
|
80
|
+
if (fail) process.exit(2)
|
|
81
|
+
}
|
|
82
|
+
if (has('--json')) { console.log(JSON.stringify({ generatedAt: new Date().toISOString(), days, results: ok }, null, 2)); process.exit(0) }
|
|
83
|
+
if (has('--lines')) { for (const r of ok) { console.log(`### ${r.store}`); console.log(marketMatrixLines(r.matrix).join('\n')) } process.exit(0) }
|
|
84
|
+
for (const r of ok) console.log(marketMatrixLines(r.matrix).join('\n') + '\n')
|