teamsmith 0.3.3 → 0.3.4

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 (32) hide show
  1. package/README.md +4 -4
  2. package/package.json +2 -6
  3. package/skills/teamsmith/CHANGELOG.md +47 -0
  4. package/skills/teamsmith/SKILL.md +1 -1
  5. package/skills/teamsmith/extension/team-inbox-watch.ts +30 -1
  6. package/skills/teamsmith/extension/team-notify.ts +161 -20
  7. package/skills/teamsmith/references/agent-adapters.md +3 -1
  8. package/skills/teamsmith/references/config.md +1 -1
  9. package/skills/teamsmith/references/protocol.md +21 -0
  10. package/skills/teamsmith/references/troubleshooting.md +7 -3
  11. package/skills/teamsmith/scripts/lib/cmd-agents.sh +213 -19
  12. package/skills/teamsmith/scripts/lib/cmd-config.sh +1 -1
  13. package/skills/teamsmith/scripts/lib/cmd-status.sh +177 -21
  14. package/skills/teamsmith/scripts/lib/cmd-watch.sh +11 -1
  15. package/skills/teamsmith/scripts/lib/common.sh +7 -3
  16. package/skills/teamsmith/scripts/lib/outbox.sh +31 -3
  17. package/skills/teamsmith/scripts/panel/panel.js +1 -1
  18. package/skills/teamsmith/scripts/panel/src/strings/en.ts +1 -1
  19. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +1 -1
  20. package/skills/teamsmith/scripts/team +1 -0
  21. package/skills/teamsmith/templates/config.sh.tmpl +2 -1
  22. package/skills/teamsmith/tests/bg-ledger-harness.mjs +17 -6
  23. package/skills/teamsmith/tests/bg-ledger.sh +16 -5
  24. package/skills/teamsmith/tests/help-surface.sh +1 -1
  25. package/skills/teamsmith/tests/install-shape.sh +88 -38
  26. package/skills/teamsmith/tests/panel-choices.sh +11 -7
  27. package/skills/teamsmith/tests/section-paths.tsv +2 -2
  28. package/skills/teamsmith/tests/smoke.sh +594 -11
  29. package/skills/teamsmith/tests/task-model-routing.sh +10 -1
  30. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +33 -0
  31. package/skills/teamsmith/tests/team-notify-knock-marker.mjs +91 -0
  32. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -1800,15 +1800,38 @@ team_notify_line_events() {
1800
1800
  printf '%s\n' "$n"
1801
1801
  }
1802
1802
 
1803
+ # 行里的 `knock=`(指针行的 run 级字段;记录行从不带它 → 空)。
1804
+ team_notify_knock_of() { # <行> → knock= 的值(没有 → 空)
1805
+ local head="${1#- }"
1806
+ head="${head%% :: *}"
1807
+ case "$head" in
1808
+ *'knock='*) head="${head#*knock=}"; printf '%s\n' "${head%% *}" ;;
1809
+ *) printf '\n' ;;
1810
+ esac
1811
+ }
1812
+
1803
1813
  # 汇总行 = **最后一条事件的行** + 首事件时间戳 + 字段区 `×N first= last=`(branch/tip/uncommitted 自动是最后一条的值)。
1804
- team_notify_line_merge() { # <新事件行> <首时间戳> <n> <末时间戳>
1805
- local c="$1" first="$2" n="$3" last="$4" head tail rest
1814
+ # 第 5 参 <已存在的行> 只服务一条 run 级字段规则:两边都有 `knock=` 时取**已存在那一行**的值 ——
1815
+ # 叫醒只发生在 run 的第一个事件上(state=new 才入队,扩展一律不入队),让扩展事件把 knock 改写会
1816
+ # 让这一行说谎。记录行从不带 knock=,所以对记录行的输出逐字节无影响。
1817
+ team_notify_line_merge() { # <新事件行> <首时间戳> <n> <末时间戳> [<已存在的行>]
1818
+ local c="$1" first="$2" n="$3" last="$4" prev="${5:-}" head tail rest pk pre post cur
1806
1819
  case "$c" in
1807
1820
  *' :: '*) head="${c%% :: *}"; tail="${c#* :: }" ;;
1808
1821
  *) head="$c"; tail='' ;;
1809
1822
  esac
1810
1823
  rest="${head#* }"
1811
1824
  head="${first} ${rest} · ×${n} first=${first} last=${last}"
1825
+ if [ -n "$prev" ]; then
1826
+ pk="$(team_notify_knock_of "$prev")"
1827
+ case "$head" in
1828
+ *'knock='*)
1829
+ if [ -n "$pk" ]; then
1830
+ pre="${head%%knock=*}"; post="${head#*knock=}"; cur="${post%% *}"
1831
+ head="${pre}knock=${pk}${post#"$cur"}"
1832
+ fi ;;
1833
+ esac
1834
+ fi
1812
1835
  if [ "${c%% :: *}" != "$c" ]; then printf '%s :: %s\n' "$head" "$tail"; else printf '%s\n' "$head"; fi
1813
1836
  }
1814
1837
 
@@ -1840,8 +1863,10 @@ team_notify_detail_events() { # <明细文件> → 事件行数(轮转头不
1840
1863
  }
1841
1864
 
1842
1865
  # 先明细:一行一事件(内容 = 该事件单发形状的收件箱行)。越界 → 轮转一代到 <file>.1 + 新代轮转头。
1843
- team_notify_detail_append() { # <事件行> <明细文件> → 0 = 已落盘;1 = 失败(调用方写 detail=unavailable)
1844
- local content="$1" file="$2" dir max count
1866
+ # 第 3 参只影响轮转在扩展日志里的名字:结果账(notify-knock.log)与明细共用这一个轮转器与同一个上界,
1867
+ # 但两件东西不是一回事,日志里点错名字会让下一次查现场的人找错文件。
1868
+ team_notify_detail_append() { # <事件行> <文件> [轮转日志里的名字=detail] → 0 = 已落盘;1 = 失败(调用方写 detail=unavailable)
1869
+ local content="$1" file="$2" label="${3:-detail}" dir max count
1845
1870
  dir="$(dirname "$file")"
1846
1871
  mkdir -p "$dir" || return 1
1847
1872
  max="$(team_notify_detail_max)"
@@ -1849,7 +1874,7 @@ team_notify_detail_append() { # <事件行> <明细文件> → 0 = 已落盘;1
1849
1874
  if [ "$count" -ge "$max" ]; then
1850
1875
  mv -f "$file" "$file.1" || return 1
1851
1876
  printf '%s\n' "# rotation $(team_timestamp) moved=${count} path=${file}.1" > "$file" || return 1
1852
- team_notify_log_line "notify detail rotated: moved=${count} to=${file}.1"
1877
+ team_notify_log_line "notify ${label} rotated: moved=${count} to=${file}.1"
1853
1878
  fi
1854
1879
  printf -- '- %s\n' "$content" >> "$file" 2>/dev/null || return 1
1855
1880
  return 0
@@ -1869,12 +1894,95 @@ team_inbox_rewrite_last() { # <收件箱文件> <新尾行> → 0 = 已重写;
1869
1894
  return 0
1870
1895
  }
1871
1896
 
1872
- # 临界区(调用方持锁):先明细 → 尾行锚判定 → 截尾重写或追加 → 打印写入结果。
1873
- team_inbox_write_locked() { # <recipient> <行> <文件> <明细> → state=new|extended first=<ISO> key=<键>
1897
+ # 指针行派生(turn-notice-in-pm-inbox · design §2):记录行 → PM 收件箱里的那一行。
1898
+ # 由**写入侧**从记录行派生,而不是在扩展里另拼一份 —— 「什么算同一个 run」只有 team_notify_line_key
1899
+ # 一份实现,两边才不可能在缺字段/awaiting 顺序/⚠ 前缀上分叉。四处变换,字段顺序写死:
1900
+ # ① 删 `⚠ 未提交 N 个文件 · ` 前缀(告警框是事件级的告警,指针不复制它);
1901
+ # ② 只留 run 级字段 `task=<ID> tip=<hex>`、`awaiting=<ids>`、`detail=unavailable`:
1902
+ # branch=/uncommitted=/unpushed= 是「last= 那一刻」的事件级快照,抄进 run 级摘要只会显示一个
1903
+ # 过期瞬间(PM 要判断这些时读的是 see= 指的那份记录);
1904
+ # ③ 插入 `knock=<outcome> · see=docs/team/inbox/<seat>.md`;
1905
+ # ④ 删 ` :: <末消息>` 尾巴(摘要在记录行与敲门载荷里各有一份;pm.md 的行数是 PM 的待办数)。
1906
+ # 记录行的状态类(design §6 的 class= 字段):[auto] → delivered、[auto·suspended] → suspended、
1907
+ # [auto·interrupted] → interrupted;其余(没有记录行 / 非 auto 行)是 `-`。
1908
+ # 与 team_inbox_line_is_record / 合并键共用同一套 tag 拼写,不另立一份。
1909
+ team_notify_line_class() { # <记录行> → delivered|suspended|interrupted|-
1910
+ local body tag
1911
+ body="${1#- }"
1912
+ case "$body" in *'['*) ;; *) printf '%s\n' '-' ; return 0 ;; esac
1913
+ tag="${body#*\[}"; tag="${tag%%\]*}"
1914
+ case "$tag" in
1915
+ auto) printf '%s\n' delivered ;;
1916
+ 'auto·suspended') printf '%s\n' suspended ;;
1917
+ 'auto·interrupted') printf '%s\n' interrupted ;;
1918
+ *) printf '%s\n' '-' ;;
1919
+ esac
1920
+ }
1921
+
1922
+ # 结果账(turn-notice-in-pm-inbox · A2):一行一次 settle —— 项目内那个跨 ack、跨轮转之后还能回答
1923
+ # 「今天 skipped 了几次、为什么」的地方。与 state/notify.log 同一个轮转器与同一个上界(不新增配置键)。
1924
+ team_notify_knock_ledger_path() { printf '%s/notify-knock.log\n' "$(team_state_dir)"; }
1925
+
1926
+ team_notify_knock_ledger_append() { # <seat> <task> <class> <outcome> <pointer> <identity> → 0 = 已落盘
1927
+ local line
1928
+ line="$(team_timestamp) seat=$1 · task=$2 · class=$3 · outcome=$4 · pointer=$5 · identity=$6"
1929
+ team_notify_detail_append "$line" "$(team_notify_knock_ledger_path)" knock
1930
+ }
1931
+
1932
+ team_notify_pointer_line() { # <记录行> <outcome> → 指针行(解析不成立 → rc 1)
1933
+ local body="$1" outcome="$2"
1934
+ local iso rest tag seat tok head f task_f='' aw_f='' ask_f='' det_f=''
1935
+ iso="${body%% *}"
1936
+ case "$iso" in ''|*[!0-9TZ:.-]*) return 1 ;; esac
1937
+ rest="${body#"$iso" }"
1938
+ [ "$rest" != "$body" ] || return 1
1939
+ case "$rest" in '⚠'*) rest="${rest#*· }" ;; esac
1940
+ case "$rest" in '['*) ;; *) return 1 ;; esac
1941
+ tag="${rest%%\]*}"; tag="${tag#\[}"
1942
+ rest="${rest#*\] }"
1943
+ case "$rest" in agent:*) ;; *) return 1 ;; esac
1944
+ seat="${rest#agent:}"; seat="${seat%% *}"
1945
+ [ -n "$seat" ] || return 1
1946
+ rest="${rest#"agent:$seat"}"
1947
+ case "$rest" in ' '*|'') ;; *) return 1 ;; esac
1948
+ rest="${rest# }"
1949
+ case "$rest" in '· '*) rest="${rest#· }" ;; *) return 1 ;; esac
1950
+ head="${rest%% :: *}"
1951
+ tok="${head%% · *}"
1952
+ [ -n "$tok" ] || return 1
1953
+ rest="${head#"$tok"}"
1954
+ case "$rest" in ' · '*) rest="${rest# · }" ;; *) rest='' ;; esac
1955
+ while [ -n "$rest" ]; do
1956
+ f="${rest%% · *}"
1957
+ if [ "$f" = "$rest" ]; then rest=''; else rest="${rest#* · }"; fi
1958
+ case "$f" in
1959
+ task=*) task_f="$f" ;;
1960
+ awaiting=*) aw_f="$f" ;;
1961
+ # notice-fulltext-and-asks:`asks=` 是**事件级**字段(跟 branch=/tip= 同类),但它是 PM 唯一可行动
1962
+ # 的信号,所以在这里被有意复制 —— PM 读的是 pm.md,不是 worker 的收件箱。branch=/uncommitted=/unpushed=
1963
+ # 仍然不复制(它们只描述 last= 那一刻的快照)。
1964
+ asks=*) ask_f="$f" ;;
1965
+ 'detail=unavailable') det_f="$f" ;;
1966
+ *) : ;; # branch=/uncommitted=/unpushed= 与未识别字段:事件级,不属于指针
1967
+ esac
1968
+ done
1969
+ printf '%s [%s] agent:%s · %s · knock=%s · see=%s/inbox/%s.md' \
1970
+ "$iso" "$tag" "$seat" "$tok" "$outcome" "$TEAM_DOCS_DIR" "$seat"
1971
+ [ -n "$task_f" ] && printf ' · %s' "$task_f"
1972
+ [ -n "$ask_f" ] && printf ' · %s' "$ask_f"
1973
+ [ -n "$aw_f" ] && printf ' · %s' "$aw_f"
1974
+ [ -n "$det_f" ] && printf ' · %s' "$det_f"
1975
+ printf '\n'
1976
+ }
1977
+
1978
+ # 临界区(调用方持锁):明细(detail=- → 不写)→ 尾行锚判定 → 截尾重写或追加 → 打印写入结果。
1979
+ # turn-notice-in-pm-inbox:记录行与指针行走**同一段**合并逻辑,唯一区别是明细写不写 —— 指针行不进
1980
+ # 明细,所以一个 run 的 ×N 仍然等于它的记录数(把指针也记进明细会让两边分家)。
1981
+ team_inbox_merge_or_append() { # <recipient> <行> <文件> <明细|-> → state=new|extended first=<ISO> key=<键>
1874
1982
  local recipient="$1" content="$2" file="$3" detail="$4"
1875
1983
  local key='' detail_failed=0 newcontent="$content" state=new first='' tail_line merged n
1876
1984
  key="$(team_notify_line_key "$content" || true)"
1877
- if [ -n "$key" ]; then
1985
+ if [ -n "$key" ] && [ "$detail" != '-' ]; then
1878
1986
  if ! team_notify_detail_append "$content" "$detail"; then
1879
1987
  detail_failed=1
1880
1988
  newcontent="$(team_notify_line_mark_detail "$content")"
@@ -1887,7 +1995,7 @@ team_inbox_write_locked() { # <recipient> <行> <文件> <明细> → state=new|
1887
1995
  if [ -n "$tail_line" ] && team_notify_line_anchor_ok "$tail_line" \
1888
1996
  && [ "$(team_notify_line_key "$tail_line" 2>/dev/null || true)" = "$key" ]; then
1889
1997
  n=$(( $(team_notify_line_events "$tail_line") + 1 ))
1890
- merged="$(team_notify_line_merge "$newcontent" "$(team_notify_line_iso "$tail_line")" "$n" "$first")"
1998
+ merged="$(team_notify_line_merge "$newcontent" "$(team_notify_line_iso "$tail_line")" "$n" "$first" "$tail_line")"
1891
1999
  if team_inbox_rewrite_last "$file" "$merged"; then
1892
2000
  state=extended
1893
2001
  first="$(team_notify_line_iso "$tail_line")"
@@ -1897,25 +2005,36 @@ team_inbox_write_locked() { # <recipient> <行> <文件> <明细> → state=new|
1897
2005
  if [ "$state" = new ]; then
1898
2006
  printf -- '- %s\n' "$newcontent" >> "$file" || return 1
1899
2007
  fi
1900
- # 写入结果协议(单行一段,扩展用 ^first=/^key= 解析):state=new|extended
1901
- printf 'state=%s\nfirst=%s\nkey=%s\n' "$state" "$first" "${key:--}"
2008
+ # 写入结果协议(单行一段,扩展用 ^state=/^first=/^key=/^lineno= 解析):state=new|extended
2009
+ # notice-fulltext-and-asks:`lineno=` = 这次写入之后那条记录在文件里的**1 基行号**(追加与截尾重写两条腿
2010
+ # 都是「文件的最后一行」)。为什么由写入侧给:敲门载荷的 `full=<文件>:<行>` 必须resolveable,
2011
+ # 而行号只有持锁的临界区里数才不会与并发追加错位(扩展自己算的数会错位 → 假定位)。
2012
+ local lineno
2013
+ lineno="$(LC_ALL=C wc -l < "$file" 2>/dev/null | tr -d ' ' || true)"
2014
+ case "$lineno" in ''|*[!0-9]*) lineno=0 ;; esac
2015
+ printf 'state=%s\nfirst=%s\nkey=%s\nlineno=%s\n' "$state" "$first" "${key:--}" "$lineno"
1902
2016
  return 0
1903
2017
  }
1904
2018
 
2019
+ # 记录行那条腿:参数与行为逐字节不变(明细 + 收件人自己的收件箱)。
2020
+ team_inbox_write_locked() { # <recipient> <行> <文件> <明细>
2021
+ team_inbox_merge_or_append "$1" "$2" "$3" "$4"
2022
+ }
2023
+
1905
2024
  # 每收件人一把锁的写入口(team_inbox_append 与扩展的 __inbox-write 共用)。
1906
- team_inbox_write_line() { # <recipient> <行> → 打印写入结果(同 team_inbox_write_locked)
1907
- local recipient="$1" content="$2"
1908
- local dir file detail lockfd rc=0
1909
- dir="$(team_inbox_dir)"; file="$dir/$recipient.md"
2025
+ # 第 4 参 = 明细文件或 `-`(指针行走的是同一个临界区,只是不写明细)。
2026
+ team_inbox_write_with_lock() { # <recipient> <行> <文件> <明细|->
2027
+ local recipient="$1" content="$2" file="$3" detail="$4"
2028
+ local dir lockfd rc=0
1910
2029
  local state; state="$(team_state_dir)"
1911
- detail="$state/notify.log"
2030
+ dir="$(dirname "$file")"
1912
2031
  mkdir -p "$dir" || return 1
1913
2032
  if command -v flock >/dev/null 2>&1; then
1914
2033
  # exec 加**不带命令**的重定向会永久改变当前 shell:`exec {fd}>&- 2>/dev/null` 会把 stderr 永久接到
1915
2034
  # /dev/null(P251 实测:say 的 team_warn 从此消失)。这里只关 fd,不带任何 stderr 重定向。
1916
2035
  if ! exec {lockfd}>"$state/inbox-$recipient.lock"; then return 1; fi
1917
2036
  if flock -w 10 "$lockfd"; then
1918
- team_inbox_write_locked "$recipient" "$content" "$file" "$detail" || rc=$?
2037
+ team_inbox_merge_or_append "$recipient" "$content" "$file" "$detail" || rc=$?
1919
2038
  else
1920
2039
  team_notify_log_line "inbox lock timeout: $state/inbox-$recipient.lock"
1921
2040
  rc=1
@@ -1923,7 +2042,24 @@ team_inbox_write_line() { # <recipient> <行> → 打印写入结果(同 team_
1923
2042
  exec {lockfd}>&-
1924
2043
  return $rc
1925
2044
  fi
1926
- team_inbox_write_locked "$recipient" "$content" "$file" "$detail"
2045
+ team_inbox_merge_or_append "$recipient" "$content" "$file" "$detail"
2046
+ }
2047
+
2048
+ team_inbox_write_line() { # <recipient> <行> → 打印写入结果(同 team_inbox_write_locked)
2049
+ local recipient="$1" content="$2" dir
2050
+ dir="$(team_inbox_dir)"
2051
+ team_inbox_write_with_lock "$recipient" "$content" "$dir/$recipient.md" "$(team_state_dir)/notify.log"
2052
+ }
2053
+
2054
+ # 指针行写进 PM 的收件箱(同一把 pm 锁;不写明细)。
2055
+ team_inbox_write_pointer_line() { # <指针行> → 0 = 已落盘;1 = 没写成
2056
+ local content="$1" file
2057
+ file="$(team_inbox_dir)/pm.md"
2058
+ # 存在却不可写 → 直接判失败:截尾重写是「mktemp + mv」,它会把一次被禁止的写入伪装成成功
2059
+ # (只读文件所在的目录可写)。指针写不进去这件事必须让调用方看得见(pointer=failed)。
2060
+ if [ -e "$file" ]; then [ -w "$file" ] || return 1; fi
2061
+ # 内层的 state=/first=/key= 是给 __inbox-write 的协议,指针腿不消费它(调用方只看 pointer=)。
2062
+ team_inbox_write_with_lock pm "$content" "$file" '-' >/dev/null
1927
2063
  }
1928
2064
 
1929
2065
  # 内部命令(扩展消费写入结果;不进 help):--agent <席位> --from-file <单行文件>
@@ -1942,10 +2078,68 @@ team_cmd_inbox_write() {
1942
2078
  [ -n "$agent" ] || team_usage_die "__inbox-write: 需要 --agent <席位>"
1943
2079
  if [ -z "$src" ] || [ ! -f "$src" ]; then team_usage_die "__inbox-write: 需要 --from-file <行文件>"; fi
1944
2080
  local content; content="$(head -n 1 "$src")"
1945
- if [ -z "$content" ]; then printf 'state=failed\nfirst=-\nkey=-\n'; return 1; fi
2081
+ if [ -z "$content" ]; then printf 'state=failed\nfirst=-\nkey=-\nlineno=0\n'; return 1; fi
1946
2082
  team_inbox_write_line "$agent" "$content"
1947
2083
  }
1948
2084
 
2085
+ # 内部命令(扩展消费;不进 help):一次 settle 的旁路记账入口。
2086
+ # --agent <seat> --outcome <enqueued|skipped:<类>> [--record-from-file <行文件>] [--identity <id>] [--task <ID>]
2087
+ # 两步,顺序写死(design §4):
2088
+ # (a) 指针腿:有记录行 → 从它派生指针行并写进 PM 的收件箱(持 pm 的收件箱锁);没有记录行 →
2089
+ # 什么都写(没有东西可以指)。
2090
+ # (b) 结果账:每一次 settle 一行 → state/notify-knock.log(与明细同一个轮转器与上界)。它必须在
2091
+ # 指针尝试**之后**写,才带得上 pointer=failed —— 反过来只能记一个假值或二次改写。
2092
+ # 两次写都是旁路:无论成败都退出 0,把结果打印成 pointer=ok|failed|none 与 ledger=ok|failed。
2093
+ team_cmd_notify_settle() {
2094
+ local agent='' outcome='' src='' identity='-' task='-'
2095
+ while [ $# -gt 0 ]; do
2096
+ case "$1" in
2097
+ --agent) agent="${2:?--agent 需要值}"; shift 2 ;;
2098
+ --agent=*) agent="${1#*=}"; shift ;;
2099
+ --outcome) outcome="${2:?--outcome 需要值}"; shift 2 ;;
2100
+ --outcome=*) outcome="${1#*=}"; shift ;;
2101
+ --record-from-file) src="${2:?--record-from-file 需要文件}"; shift 2 ;;
2102
+ --record-from-file=*) src="${1#*=}"; shift ;;
2103
+ --identity) identity="${2:?--identity 需要值}"; shift 2 ;;
2104
+ --identity=*) identity="${1#*=}"; shift ;;
2105
+ --task) task="${2:?--task 需要值}"; shift 2 ;;
2106
+ --task=*) task="${1#*=}"; shift ;;
2107
+ -*) team_usage_die "__notify-settle: 未知参数 $1" ;;
2108
+ *) team_usage_die "__notify-settle: 多余参数 $1" ;;
2109
+ esac
2110
+ done
2111
+ [ -n "$agent" ] || team_usage_die "__notify-settle: 需要 --agent <席位>"
2112
+ case "$outcome" in
2113
+ ''|-) team_usage_die "__notify-settle: 需要 --outcome <enqueued|skipped:<类>>" ;;
2114
+ enqueued) ;;
2115
+ skipped:?*) ;;
2116
+ *) team_usage_die "__notify-settle: --outcome 只有 enqueued 与 skipped:<类> 两种形状(收到 $outcome)" ;;
2117
+ esac
2118
+ local record pointer='none' cls='-'
2119
+ # 发送者是 PM 自己时没有「指针」:PM 的收件箱就是记录的落点(账照样记,它是一个 settle)。
2120
+ if [ "$agent" != pm ] && [ -n "$src" ] && [ -f "$src" ]; then
2121
+ record="$(head -n 1 "$src")"
2122
+ cls="$(team_notify_line_class "$record")"
2123
+ local pointer_line
2124
+ if ! pointer_line="$(team_notify_pointer_line "$record" "$outcome")" || [ -z "$pointer_line" ]; then
2125
+ team_notify_log_line "notify pointer derivation failed: seat=$agent outcome=$outcome"
2126
+ pointer=failed
2127
+ elif team_inbox_write_pointer_line "$pointer_line"; then
2128
+ pointer=ok
2129
+ else
2130
+ team_notify_log_line "notify pointer write failed: seat=$agent outcome=$outcome task=$task identity=$identity"
2131
+ pointer=failed
2132
+ fi
2133
+ fi
2134
+ if team_notify_knock_ledger_append "$agent" "$task" "$cls" "$outcome" "$pointer" "$identity"; then
2135
+ printf 'pointer=%s\nledger=ok\n' "$pointer"
2136
+ else
2137
+ team_notify_log_line "notify knock ledger write failed: seat=$agent outcome=$outcome pointer=$pointer"
2138
+ printf 'pointer=%s\nledger=failed\n' "$pointer"
2139
+ fi
2140
+ return 0
2141
+ }
2142
+
1949
2143
  # notify 的去重键:内容 + 长度(同一份通知在 TEAM_NOTIFY_DEDUP_SEC 内只入队/投递一次)。
1950
2144
  # 扩展走的是它自己的键(<agent>|<tag>|<summary>|<len>:<hash>),两边都进同一个队列条目。
1951
2145
  team_notify_dedup_key() { # <agent> <msg>
@@ -126,7 +126,7 @@ TEAM_ZRAM_WARN_PCT|apply|pct|0,100|plain|85|-||70,80,85,90|delivery
126
126
  TEAM_AGENT_MEM_MB|apply|mb|1,|plain|6144|-||2048,4096,6144|delivery
127
127
  TEAM_NOTIFY_TMUX|apply|bool||plain|1|-|||delivery
128
128
  TEAM_NOTIFY_DEDUP_SEC|apply|seconds|0,|plain|20|-|||delivery
129
- TEAM_INBOX_MAX_CHARS|apply|int|1,|plain|150|-||100,150,300|delivery
129
+ TEAM_INBOX_MAX_CHARS|apply|int|1,|plain|150|预览字数:敲门载荷里引用末消息的字数上限;收件箱行与 state/notify.log 存全文||100,150,300|delivery
130
130
  TEAM_NOTIFY_DETAIL_MAX|apply|int|1,|plain|2048|state/notify.log 的事件上界:越界轮转到 state/notify.log.1(只留一代)||512,2048,8192|delivery
131
131
  TEAM_NOTIFY_LOG|apply|path|file,opt|plain|/tmp/teamsmith-notify.log|-|||delivery
132
132
  TEAM_DEFER_TTL|apply|seconds|0,|plain|300|0 = 投递队列入队即过期||60,300,900|delivery
@@ -28,16 +28,24 @@ team_inbox_ack_set() { # <agent> <行数>:只写 sidecar(原子替换),
28
28
  printf '%s\n' "$2" > "$tmp" && mv -f "$tmp" "$dir/$1.inbox"
29
29
  }
30
30
 
31
- team_inbox_new() { # <agent> → 未 ack 的行数
32
- local total acked; total="$(team_inbox_total "$1")"; acked="$(team_inbox_acked "$1")"
33
- # 文件被截短/重建(acked > total)时 ack 基线失效:把剩下的行当未读重新展示一次。
34
- # 不这样,一条新消息会因为旧的 ack 计数比文件行数大而**永远看不见**(F26 的 live 现场)。
35
- case "$acked" in ''|*[!0-9]*) acked=0 ;; esac
36
- [ "$acked" -gt "$total" ] && acked=0
37
- [ "$total" -gt "$acked" ] && printf '%s\n' "$((total - acked))" || printf '0\n'
31
+ # turn-notice-in-pm-inbox · 「一条通知只数一次」的判据(唯一实现,team_inbox_new / team_inbox_since 共用):
32
+ # 一条 auto 类行([auto] / [auto·suspended] / [auto·interrupted])的 `agent:<name>` 等于**这个收件箱文件
33
+ # 自己的席位名**时,它是该席位的**记录**(历史/明细),不是它的未读流量;否则它是流量([manual]/
34
+ # [draft]/[nudge]/pulse 行,以及 pm.md 里的指针行 —— 指针的 agent: 是发送者)。
35
+ # 不写成「文件名是 pm」的特例:判据只看行与文件席位,别的席位之间同样成立。
36
+ team_inbox_line_is_record() { # <文件席位> <行> → 0 = 该席位自己的记录
37
+ local seat="$1" line="$2" body tag ag
38
+ body="${line#- }"
39
+ case "$body" in *' ['*) ;; *) return 1 ;; esac
40
+ tag="${body#*\[}"; tag="${tag%%\]*}"
41
+ case "$tag" in auto|'auto·suspended'|'auto·interrupted') ;; *) return 1 ;; esac
42
+ case "$body" in *agent:*) ;; *) return 1 ;; esac
43
+ ag="${body#*agent:}"; ag="${ag%% *}"
44
+ [ "$ag" = "$seat" ]
38
45
  }
39
46
 
40
- team_inbox_since() { # <agent> → 未 ack 的行
47
+ # 未 ack 的**原始**行(不筛记录):ack 基线记的是行数,所以必须按行取完再筛。
48
+ team_inbox_raw_since() { # <agent> → 未 ack 的行
41
49
  local f start total
42
50
  f="$(team_inbox_file "$1")"
43
51
  [ -f "$f" ] || return 0
@@ -48,6 +56,117 @@ team_inbox_since() { # <agent> → 未 ack 的行
48
56
  [ "$start" -gt 0 ] && tail -n +"$((start + 1))" "$f" || cat "$f"
49
57
  }
50
58
 
59
+ team_inbox_since() { # <agent> → 未 ack 的行(不含该席位自己的 auto 记录)
60
+ local seat="$1" line
61
+ team_inbox_raw_since "$seat" | while IFS= read -r line; do
62
+ team_inbox_line_is_record "$seat" "$line" && continue
63
+ printf '%s\n' "$line"
64
+ done
65
+ }
66
+
67
+ team_inbox_new() { # <agent> → 未 ack 的**流量**行数(记录不计数:一次交付让待办 +1 而不是 +2)
68
+ local total acked n
69
+ total="$(team_inbox_total "$1")"; acked="$(team_inbox_acked "$1")"
70
+ # 文件被截短/重建(acked > total)时 ack 基线失效:把剩下的行当未读重新展示一次。
71
+ # 不这样,一条新消息会因为旧的 ack 计数比文件行数大而**永远看不见**(F26 的 live 现场)。
72
+ case "$acked" in ''|*[!0-9]*) acked=0 ;; esac
73
+ [ "$acked" -gt "$total" ] && acked=0
74
+ n="$(team_inbox_since "$1" | wc -l | tr -d ' ')"
75
+ case "$n" in ''|*[!0-9]*) n=0 ;; esac
76
+ printf '%s\n' "$n"
77
+ }
78
+
79
+ # ---------------------------------------------------------------- turn-notice-in-pm-inbox(A2)
80
+ # digest 的「未敲门」与「指针缺失」两行(design §5)。
81
+ # 未敲门 = PM 收件箱里**尚未 ack** 的指针行的 `knock=skipped:<类>`(一条 run 一行);读了并按 --ack
82
+ # 标记就归零 —— 它是「还没被回答」的量,不需要第二个已读通道。
83
+ # 指针缺失 = 结果账**当前代**里 pointer=failed 的条数:这一档不会随阅读消失(pm.md 里本来就没有那行)。
84
+ # 两行都**只显示**:不进 team_pending_text、不进任何叫醒判据(挂起只记录不叫醒是用户的裁定,
85
+ # 一条不会自己消失的故障也不该每一拍都把 PM 叫醒一次)。
86
+ TEAM_KNOCK_SKIPPED_CLASSES=" suspended merged dedup turn-unfinished write-failed notify-off no-pane pm-not-running pm-window-missing enqueue-failed "
87
+
88
+ team_knock_class_known() { # <类> → 0 = 在闭集里
89
+ case "$TEAM_KNOCK_SKIPPED_CLASSES" in *" $1 "*) return 0 ;; *) return 1 ;; esac
90
+ }
91
+
92
+ # 读侧遇到闭集外的类**原样打印**(归在 `其它(<类> <n>)` 里)—— 不吞、不改写、不丢。
93
+ team_inbox_skipped_knock_summary() { # → "<N>\t<suspended 1 · 其它(something-new 1)>";0 条 → 什么都不打印
94
+ local line cls i total=0 hit part out=''
95
+ local classes=() counts=()
96
+ while IFS= read -r line; do
97
+ [ -n "$line" ] || continue
98
+ case "$line" in *'knock=skipped:'*) ;; *) continue ;; esac
99
+ cls="${line#*knock=skipped:}"; cls="${cls%% *}"
100
+ [ -n "$cls" ] || cls='-'
101
+ total=$((total + 1))
102
+ hit=0
103
+ for i in "${!classes[@]}"; do
104
+ if [ "${classes[$i]}" = "$cls" ]; then counts[$i]=$(( ${counts[$i]} + 1 )); hit=1; break; fi
105
+ done
106
+ [ "$hit" = 1 ] || { classes+=("$cls"); counts+=(1); }
107
+ done < <(team_inbox_raw_since pm)
108
+ [ "$total" -gt 0 ] || return 0
109
+ for i in "${!classes[@]}"; do
110
+ if team_knock_class_known "${classes[$i]}"; then
111
+ part="${classes[$i]} ${counts[$i]}"
112
+ else
113
+ part="其它(${classes[$i]} ${counts[$i]})"
114
+ fi
115
+ out="${out}${out:+ · }$part"
116
+ done
117
+ printf '%s\t%s\n' "$total" "$out"
118
+ }
119
+
120
+ # notice-fulltext-and-asks · digest 的「待回答」一行(design §6):
121
+ # 范围 = PM 收件箱里**未 ack 的指针行**中 asks>=1 的那些 —— 与「未敲门」读同一个来源
122
+ # (team_inbox_raw_since pm),**一条 run 算一条**(指针行本来就是合并后的一行,不按事件数算)。
123
+ # 指针行的判据 = 带 run 级字段 knock=(pm.md 里只有指针行带它;手写/别人的行不会被误数)。
124
+ # 只显示:不进 team_pending_text —— 那行通知本身已经在唤醒判据里,再加一条理由等于对同一件事
125
+ # 敲两次(与「未敲门」「指针缺失」两行同一口径)。为 0 时什么都不打印。
126
+ # 点名最多 3 条,剩下的压成「… 另 N 条」:这一行是索引,全文在 pm.md 的那一行上。
127
+ team_inbox_asks_summary() { # → "<N>\t<agent:x · P1 · asks=1;…>";0 条 → 什么都不打印
128
+ local line head seat av task after total=0
129
+ local items=() i out=''
130
+ while IFS= read -r line; do
131
+ [ -n "$line" ] || continue
132
+ head="${line%% :: *}"
133
+ case "$head" in *'knock='*) ;; *) continue ;; esac
134
+ av=''
135
+ case "$head" in *'asks='*) av="${head#*asks=}"; av="${av%% *}" ;; esac
136
+ case "$av" in ''|*[!0-9]*) continue ;; esac
137
+ [ "$av" -ge 1 ] || continue
138
+ case "$head" in *'agent:'*) ;; *) continue ;; esac
139
+ seat="${head#*agent:}"; seat="${seat%% *}"
140
+ [ -n "$seat" ] || continue
141
+ task=''
142
+ case "$head" in *'task='*) task="${head#*task=}"; task="${task%% *}" ;; esac
143
+ if [ -z "$task" ]; then
144
+ after="${head#*agent:$seat }"; after="${after#· }"; task="${after%% · *}"
145
+ fi
146
+ [ -n "$task" ] || task='-'
147
+ total=$((total + 1))
148
+ items+=("agent:$seat · $task · asks=$av")
149
+ done < <(team_inbox_raw_since pm)
150
+ [ "$total" -gt 0 ] || return 0
151
+ for i in "${!items[@]}"; do
152
+ [ "$i" -ge 3 ] && break
153
+ out="${out}${out:+;}${items[$i]}"
154
+ done
155
+ [ "$total" -gt 3 ] && out="${out};… 另 $((total - 3)) 条"
156
+ printf '%s\t%s\n' "$total" "$out"
157
+ }
158
+
159
+ team_knock_ledger_path() { printf '%s/notify-knock.log\n' "$(team_state_dir)"; }
160
+
161
+ team_knock_pointer_failed_count() { # → 当前代的 pointer=failed 条数(轮转出去的那一代不计)
162
+ local f n
163
+ f="$(team_knock_ledger_path)"
164
+ [ -f "$f" ] || { printf '0\n'; return 0; }
165
+ n="$(grep -c '^- .*pointer=failed' "$f" 2>/dev/null || true)"
166
+ case "$n" in ''|*[!0-9]*) n=0 ;; esac
167
+ printf '%s\n' "$n"
168
+ }
169
+
51
170
  # worker 存活判据(team_agent_live / team_agent_window_exists)在 common.sh —— digest 的「停了的 agent」
52
171
  # (team_pending_counts)与 roster / resume / 面板 agents 块必须共用同一份判据(M37)。
53
172
 
@@ -883,6 +1002,25 @@ team_cmd_digest() {
883
1002
  fi
884
1003
  done
885
1004
  [ "$any" -eq 0 ] && team_dim " (无)"
1005
+ # turn-notice-in-pm-inbox(A2):敲门被跳过的通知、以及没写进 PM 收件箱的指针 —— 两行只为回答
1006
+ # 「为什么我没收到通知」;为 0 不打印,也不进待办计数(叫醒判据在 team_pending_text)。
1007
+ local skipped pfailed
1008
+ skipped="$(team_inbox_skipped_knock_summary || true)"
1009
+ if [ -n "$skipped" ]; then
1010
+ printf ' 未敲门 %s 条已记录的通知没有叫醒 PM(%s)—— 见 %s/inbox/pm.md 的 knock= 字段\n' \
1011
+ "${skipped%%$'\t'*}" "${skipped#*$'\t'}" "$TEAM_DOCS_DIR"
1012
+ fi
1013
+ pfailed="$(team_knock_pointer_failed_count || true)"
1014
+ case "$pfailed" in ''|*[!0-9]*) pfailed=0 ;; esac
1015
+ if [ "$pfailed" -gt 0 ]; then
1016
+ printf ' 指针缺失 %s 条通知没有写进 PM 收件箱(pointer-write-failed;state/notify-knock.log 当前代,更早的代不计)\n' "$pfailed"
1017
+ fi
1018
+ # notice-fulltext-and-asks:一条完成消息的末尾在问 PM 要裁决时,它自己带 asks=<n>;这里只把它数给 PM 看。
1019
+ local asked; asked="$(team_inbox_asks_summary || true)"
1020
+ if [ -n "$asked" ]; then
1021
+ printf ' 待回答 %s 条完成消息里有待你回答的问题(%s)—— team inbox pm 读原文\n' \
1022
+ "${asked%%$'\t'*}" "${asked#*$'\t'}"
1023
+ fi
886
1024
  local ign; ign="$(team_reports_ignored || true)"
887
1025
  [ -n "$ign" ] && team_dim " 忽略的非任务报告:$(printf '%s' "$ign" | tr '\n' ' ')(里程碑/结项类;要计为任务就让它出现在 BOARD 里)"
888
1026
 
@@ -1047,18 +1185,40 @@ team_inbox_detail() { # <agent> → 0 = 当前代记录完整;1 = 有缺口(
1047
1185
  printf ' 读取:%s(缺失)\n' "$detail"
1048
1186
  fi
1049
1187
  [ -f "$rot_file" ] && printf ' 上一代:%s\n' "$rot_file"
1050
- # 当前代里属于这个席位的原始记录(键解析给出席位;非 auto 行/轮转头不算记录)
1051
- local -a RECS=()
1188
+ # 当前代的原始记录按**各自的合并键**计数(键的第一个分量就是发送者)。
1189
+ # turn-notice-in-pm-inbox:合并行的 ×N 必须与**该行自己的键**的记录比,不能按文件席位取:pm.md 里
1190
+ # 的指针行属于发送者(键是 dev|delivered|P362|-),按文件席位取会把每一条 ×N 指针行都判成缺口。
1191
+ # 缺口判据(缺文件、被轮转出去)一字不松。
1192
+ local -a RKEYS=()
1193
+ local -A KC=() SHOWN=()
1194
+ local runs_n
1052
1195
  if [ -f "$detail" ]; then
1053
1196
  while IFS= read -r line; do
1054
1197
  case "$line" in '- '*) ;; *) continue ;; esac
1055
1198
  k="$(team_notify_line_key "$line" 2>/dev/null || true)"
1056
- case "$k" in "$agent"'|'*) RECS+=("$line") ;; esac
1199
+ [ -n "$k" ] || continue
1200
+ RKEYS+=("$k"); KC["$k"]=$(( ${KC["$k"]:-0} + 1 ))
1057
1201
  done < "$detail"
1058
1202
  fi
1059
- recs_n="${#RECS[@]}"
1060
- printf ' 该席位的原始记录:%s 条\n' "$recs_n"
1061
- for r in "${RECS[@]:-}"; do [ -n "$r" ] && printf ' %s\n' "$r"; done
1203
+ # 列出的键 = 本文件里出现的键(合并行与单事件行都算)∪ 文件席位自己的键
1204
+ # (后一半让「行被删/被轮转出去」时原始记录仍然可读,与旧行为一致)。
1205
+ if [ -f "$f" ]; then
1206
+ while IFS= read -r line; do
1207
+ k="$(team_notify_line_key "$line" 2>/dev/null || true)"
1208
+ [ -n "$k" ] && SHOWN["$k"]=1
1209
+ done < "$f"
1210
+ fi
1211
+ for k in "${RKEYS[@]:-}"; do
1212
+ [ -n "$k" ] || continue
1213
+ [ "${k%%|*}" = "$agent" ] && SHOWN["$k"]=1
1214
+ done
1215
+ recs_n=0; runs_n=0
1216
+ for k in "${!SHOWN[@]}"; do runs_n=$((runs_n + 1)); recs_n=$((recs_n + ${KC["$k"]:-0})); done
1217
+ printf ' 原始记录:%s 条(%s 个 run;键的第一个分量是发送者)\n' "$recs_n" "$runs_n"
1218
+ for k in $(printf '%s\n' "${!SHOWN[@]}" | LC_ALL=C sort); do
1219
+ printf ' agent:%s · %s · %s · awaiting=%s → %s 条\n' \
1220
+ "${k%%|*}" "$(printf '%s' "$k" | cut -d'|' -f2)" "$(printf '%s' "$k" | cut -d'|' -f3)" "$(printf '%s' "$k" | cut -d'|' -f4)" "${KC["$k"]:-0}"
1221
+ done
1062
1222
  printf ' 合并行核对:\n'
1063
1223
  if [ -f "$f" ]; then
1064
1224
  while IFS= read -r line; do
@@ -1068,18 +1228,14 @@ team_inbox_detail() { # <agent> → 0 = 当前代记录完整;1 = 有缺口(
1068
1228
  merged_n=$((merged_n + 1))
1069
1229
  n="$(team_notify_line_events "$line")"
1070
1230
  k="$(team_notify_line_key "$line" 2>/dev/null || true)"
1071
- count=0
1072
- for r in "${RECS[@]:-}"; do
1073
- [ -n "$r" ] || continue
1074
- [ "$(team_notify_line_key "$r" 2>/dev/null || true)" = "$k" ] && count=$((count + 1))
1075
- done
1231
+ count="${KC["$k"]:-0}"
1076
1232
  pair="$(team_notify_line_iso "$line")/$(team_notify_line_iso_last "$line")"
1077
1233
  if [ "$count" -ge "$n" ]; then
1078
1234
  printf ' ×%s first=%s last=%s → 记录 %s/%s OK\n' "$n" "${pair%%/*}" "${pair#*/}" "$count" "$n"
1079
1235
  else
1080
1236
  gap_n=$((gap_n + 1))
1081
- printf ' ×%s first=%s last=%s → 记录 %s/%s **缺口**:state/notify.log 当前代只有 %s 条;更早的记录在 state/notify.log.1\n' \
1082
- "$n" "${pair%%/*}" "${pair#*/}" "$count" "$n" "$count"
1237
+ printf ' ×%s first=%s last=%s → 记录 %s/%s **缺口**(键 agent:%s · %s);state/notify.log 当前代只有 %s 条;更早的记录在 state/notify.log.1\n' \
1238
+ "$n" "${pair%%/*}" "${pair#*/}" "$count" "$n" "${k%%|*}" "$(printf '%s' "$k" | cut -d'|' -f2)" "$count"
1083
1239
  rc=1
1084
1240
  fi
1085
1241
  done < "$f"
@@ -380,7 +380,17 @@ team_cmd_up() {
380
380
  team_tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
381
381
  fi
382
382
  if ! team_pm_window_exists; then
383
- team_tmux_new_window "$TEAM_SESSION" "$TEAM_PM_WINDOW" || true
383
+ # V60 R2:这里曾经是 `|| true` + 无条件的成功行 —— 窗口没建出来(tmux 起不来 / 路径不可用)时
384
+ # 用户看到的是「✓ 创建 PM 窗口」,接着 up 按「窗口存在」的样子往下走。失败就用 rc 说话:
385
+ # 点名目标、保留 tmux 自己的诊断(不重定向),不打印成功行、也不继续。
386
+ local pm_win_rc=0
387
+ team_tmux_new_window "$TEAM_SESSION" "$TEAM_PM_WINDOW" || pm_win_rc=$?
388
+ if [ "$pm_win_rc" != "0" ]; then
389
+ team_err "创建 PM 窗口失败($TEAM_SESSION:$TEAM_PM_WINDOW,tmux new-window rc=$pm_win_rc;上面是 tmux 的诊断):窗口不存在,PM 没有起来"
390
+ team_dim " 修法:确认 tmux server 可用(tmux ls)后重跑 $TEAM_CLI up;窗口在、里面是空的:up 会重启 PM" >&2
391
+ team_up_backup_note
392
+ return 1
393
+ fi
384
394
  team_ok "创建 PM 窗口 $TEAM_SESSION:$TEAM_PM_WINDOW"
385
395
  fi
386
396
 
@@ -3,7 +3,7 @@
3
3
  # 由 scripts/team 与各 cmd-*.sh source;不要直接执行。
4
4
  # 约定:所有函数名以 team_ 前缀;不依赖 jq / python / node。
5
5
 
6
- TEAM_VERSION="0.3.3"
6
+ TEAM_VERSION="0.3.4"
7
7
 
8
8
  # ---------------------------------------------------------------- 输出
9
9
  if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
@@ -1122,7 +1122,6 @@ team_load_config() {
1122
1122
  # 明细文件(state/notify.log)的事件上界:越界轮转到 state/notify.log.1(只留一代)。
1123
1123
  TEAM_NOTIFY_DETAIL_MAX="${TEAM_NOTIFY_DETAIL_MAX:-2048}"
1124
1124
  TEAM_INBOX_IN_MAIN="${TEAM_INBOX_IN_MAIN:-1}"
1125
- TEAM_INBOX_MAX_CHARS="${TEAM_INBOX_MAX_CHARS:-150}"
1126
1125
  TEAM_CONFIRM_WRITES="${TEAM_CONFIRM_WRITES:-1}"
1127
1126
  TEAM_AGENTS="${TEAM_AGENTS:-}"
1128
1127
  TEAM_EXTRA_PI_ARGS="${TEAM_EXTRA_PI_ARGS:-}"
@@ -2844,7 +2843,12 @@ team_orphan_read_environ() { # <pid> → 环境文本;读不到 → 非 0
2844
2843
  local f
2845
2844
  f="$(team_orphan_proc_dir "${1:-}")/environ"
2846
2845
  [ -r "$f" ] || return 1
2847
- tr '\0' '\n' < "$f" || return 1
2846
+ # P366:`[ -r ]`(access(2))与真正的读**不是同一道门**。容器 `--pid=host` 下两者差得很远(实测一次全扫:
2847
+ # access 答「可读」600 条,其中 599 条真读被拒),宿主上也有同形状的进程(非 dumpable 的同 uid 进程)。
2848
+ # 读放在子 shell 里、把内核/shell 的报错收进**这条判定本身**:读不到 → rc≠0(身份未知,调用方跳过、
2849
+ # 不猜身份),stdout/stderr 一个字节都不多;读得到时 stdout 与改动前逐字节相同(子 shell 只透传,
2850
+ # 不缓冲、不改写)。诊断由**返回值**承担,不许让 shell 的报错顶替读数。
2851
+ ( tr '\0' '\n' < "$f" ) 2>/dev/null || return 1
2848
2852
  return 0
2849
2853
  }
2850
2854