Commit 9be43efe authored by 郭阔's avatar 郭阔

fix(macOS): notify-mail empty-array under set -u; digest skip empty result JSON

- notify-mail.sh: bash 3.2 (stock macOS) treats expanding an empty array
  under set -u as unbound variable — drop the MSMTP_ARGS array for direct
  branch invocation (works identically on Linux bash 5)
- daily-digest.sh: empty result .json files (run killed / watchdog timeout,
  claude never wrote output) pass 'jq empty' but emit nothing on extraction,
  corrupting the summary array with consecutive commas; treat non-empty-size
  files as parse errors so killed runs show up honestly as interrupted
parent 3b49d654
......@@ -85,7 +85,10 @@ build_summary() {
rest="${base#*.}"
ts="${base%.json}"; ts="${ts##*.}"
if ! jq empty "$f" 2>/dev/null; then
# 空文件(任务被杀/看门狗超时,claude 未写完)骗不过 jq empty 之外的场景:
# jq 对空输入合法,但后续提取对空文件无输出,会使汇总数组出现连续逗号。
# 故空文件与解析失败同等处理,如实标记为被中断的运行。
if [ ! -s "$f" ] || ! jq empty "$f" 2>/dev/null; then
[ "$first" = "1" ] || echo -n ","; first=0
jq -nc --arg src "$src" --arg ts "$ts" --arg file "$f" \
'{source:$src,time:$ts,provider:"unknown",status:"PARSE_ERROR",cost:0,max_budget_usd:0,duration_ms:0,
......
......@@ -42,11 +42,14 @@ case "$FORMAT" in
esac
# --- msmtp 配置文件 ---
MSMTP_ARGS=()
# 注意:macOS 自带 bash 3.2 在 set -u 下展开空数组会报 unbound variable,
# 故不用 MSMTP_ARGS 数组,改为分支直接传参(与 Linux bash 5 行为一致)。
if [ -n "${MSMTP_CONFIG:-}" ] && [ -f "$MSMTP_CONFIG" ]; then
MSMTP_ARGS+=(--file="$MSMTP_CONFIG")
printf 'To: %s\nSubject: %s\nContent-Type: %s\n\n%s' \
"$TO_HEADER" "$SUBJECT" "$CT" "$BODY" \
| msmtp --file="$MSMTP_CONFIG" "${RECIPIENTS[@]}"
else
printf 'To: %s\nSubject: %s\nContent-Type: %s\n\n%s' \
"$TO_HEADER" "$SUBJECT" "$CT" "$BODY" \
| msmtp "${RECIPIENTS[@]}"
fi
printf 'To: %s\nSubject: %s\nContent-Type: %s\n\n%s' \
"$TO_HEADER" "$SUBJECT" "$CT" "$BODY" \
| msmtp "${MSMTP_ARGS[@]}" "${RECIPIENTS[@]}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment