teamsmith 0.3.3 → 0.4.0

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 (82) hide show
  1. package/README.md +8 -8
  2. package/package.json +2 -6
  3. package/skills/teamsmith/CHANGELOG.md +77 -0
  4. package/skills/teamsmith/SKILL.md +83 -163
  5. package/skills/teamsmith/extension/team-inbox-watch.ts +30 -1
  6. package/skills/teamsmith/extension/team-notify.ts +162 -21
  7. package/skills/teamsmith/extension/team-reply.ts +105 -0
  8. package/skills/teamsmith/references/agent-adapters.md +4 -2
  9. package/skills/teamsmith/references/config.md +21 -12
  10. package/skills/teamsmith/references/migration.md +47 -3
  11. package/skills/teamsmith/references/protocol.md +85 -31
  12. package/skills/teamsmith/references/reminders.md +131 -0
  13. package/skills/teamsmith/references/troubleshooting.md +26 -8
  14. package/skills/teamsmith/references/workflows.md +18 -16
  15. package/skills/teamsmith/scripts/lib/cmd-agents.sh +290 -68
  16. package/skills/teamsmith/scripts/lib/cmd-config.sh +1 -1
  17. package/skills/teamsmith/scripts/lib/cmd-project.sh +193 -21
  18. package/skills/teamsmith/scripts/lib/cmd-remind.sh +103 -0
  19. package/skills/teamsmith/scripts/lib/cmd-status.sh +177 -21
  20. package/skills/teamsmith/scripts/lib/cmd-update.sh +7 -4
  21. package/skills/teamsmith/scripts/lib/cmd-watch.sh +11 -1
  22. package/skills/teamsmith/scripts/lib/common.sh +50 -6
  23. package/skills/teamsmith/scripts/lib/outbox.sh +103 -21
  24. package/skills/teamsmith/scripts/panel/panel.js +1 -1
  25. package/skills/teamsmith/scripts/panel/src/strings/en.ts +1 -1
  26. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +1 -1
  27. package/skills/teamsmith/scripts/remind-store.mjs +529 -0
  28. package/skills/teamsmith/scripts/replies.mjs +9 -3
  29. package/skills/teamsmith/scripts/reply-capture.mjs +596 -0
  30. package/skills/teamsmith/scripts/state-authority.mjs +500 -0
  31. package/skills/teamsmith/scripts/strings/commands.tsv +2 -1
  32. package/skills/teamsmith/scripts/strings/help.en.tsv +16 -2
  33. package/skills/teamsmith/scripts/strings/help.zh.tsv +16 -2
  34. package/skills/teamsmith/scripts/team +2 -0
  35. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +68 -123
  36. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +48 -55
  37. package/skills/teamsmith/templates/config.sh.tmpl +2 -1
  38. package/skills/teamsmith/templates/pm-prompt.md.tmpl +126 -119
  39. package/skills/teamsmith/tests/bg-ledger-harness.mjs +17 -6
  40. package/skills/teamsmith/tests/bg-ledger.sh +16 -5
  41. package/skills/teamsmith/tests/checkout-shape-probe.sh +6 -5
  42. package/skills/teamsmith/tests/delivery-truth.sh +82 -47
  43. package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +71 -23
  44. package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
  45. package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-dirty-ab.py +143 -0
  46. package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +26 -9
  47. package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +92 -20
  48. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +47 -3
  49. package/skills/teamsmith/tests/fixtures/reply-capture-provider.ts +76 -0
  50. package/skills/teamsmith/tests/flip-p410-order2.sh +205 -0
  51. package/skills/teamsmith/tests/frames/README.md +3 -1
  52. package/skills/teamsmith/tests/gate-guard.sh +20 -4
  53. package/skills/teamsmith/tests/help-surface.sh +61 -3
  54. package/skills/teamsmith/tests/install-shape.sh +400 -38
  55. package/skills/teamsmith/tests/key-replies-pty.sh +197 -21
  56. package/skills/teamsmith/tests/key-replies.sh +187 -68
  57. package/skills/teamsmith/tests/ledger-claim.sh +8 -6
  58. package/skills/teamsmith/tests/lib/box-judge.sh +2 -1
  59. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +104 -0
  60. package/skills/teamsmith/tests/lib/pm-window.sh +127 -0
  61. package/skills/teamsmith/tests/lib/reply-fixture.sh +7 -19
  62. package/skills/teamsmith/tests/lib/reply-guard.sh +188 -0
  63. package/skills/teamsmith/tests/lib/section-calls.pl +171 -0
  64. package/skills/teamsmith/tests/loop-inventory.tsv +7 -5
  65. package/skills/teamsmith/tests/meta-suite.sh +215 -0
  66. package/skills/teamsmith/tests/panel-b3-pty-mouse.py +154 -17
  67. package/skills/teamsmith/tests/panel-b3.sh +33 -4
  68. package/skills/teamsmith/tests/panel-choices.sh +11 -7
  69. package/skills/teamsmith/tests/remind-cli.sh +574 -0
  70. package/skills/teamsmith/tests/reply-capture-real.mjs +360 -0
  71. package/skills/teamsmith/tests/reply-capture-real.sh +5 -0
  72. package/skills/teamsmith/tests/reply-capture.mjs +622 -0
  73. package/skills/teamsmith/tests/section-paths.tsv +41 -10
  74. package/skills/teamsmith/tests/section-select.sh +180 -26
  75. package/skills/teamsmith/tests/smoke.sh +1829 -249
  76. package/skills/teamsmith/tests/state-authority-node.mjs +42 -0
  77. package/skills/teamsmith/tests/state-authority.sh +629 -0
  78. package/skills/teamsmith/tests/task-model-routing.sh +10 -1
  79. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +33 -0
  80. package/skills/teamsmith/tests/team-notify-knock-marker.mjs +91 -0
  81. package/skills/teamsmith/tests/workflow-entry.sh +123 -3
  82. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -6,21 +6,153 @@ team_help() { # 兼容入口:`team help` 的三级路由在 scripts/lib/cmd-he
6
6
  }
7
7
 
8
8
  # ---------------------------------------------------------------- init
9
- team_write_section() { # <file> <begin-marker> <end-marker> <content-file>
10
- local target="$1" begin="$2" end="$3" content="$4"
9
+ # ── 受管段扫描:这条规则的唯一实现(change instruction-context-slimming · decision 3b)─────
10
+ # 受管段 = 一对「围栏外、独占整行、逐字节等于标记」的行,两者之间的内容由 init 替换;文件里其它
11
+ # 每个字节都归项目自己。这里刻意不写第二个猜测式实现:写入器与 doctor 的迁移提示都读这一份结果。
12
+ #
13
+ # 扫描结果(全局,调用后立刻用):
14
+ # MS_LINES[i] 第 i 行的内容(只去掉行终止符;CRLF 的 CR 属于终止符,不在内容里)
15
+ # MS_TERM[i] 该行自己的终止符:$'\n' / $'\r\n' / ''(文件末行没有换行)
16
+ # 内容 + 自己的终止符 = 原字节,所以重写时逐字节还原,不做任何行尾归一化
17
+ # MS_IDX[] / MS_KIND[] 候选行:行下标 + curBegin|curEnd|legBegin|legEnd
18
+ # MS_FENCE_OPEN 1 = 文件结束在一个未闭合的代码围栏里(往那里追加会落进围栏、而且每次重跑都再追加一次)
19
+ #
20
+ # 围栏口径与已接受的 key-replies 解析器同一条窄词法规则(不是 Markdown 解析器):围栏行长 ≤3 个
21
+ # 前导空格 + 至少三个反引号或波浪号开启,只由同字符、长度不小于开启串、其后只有空白的行关闭;
22
+ # 反引号围栏的 info string 里再出现反引号则不算围栏。未闭合的围栏一直延续到文件末尾。
23
+ MS_FENCE_OPEN_RE='^ {0,3}(`{3,}|~{3,})(.*)$'
24
+ team_marker_scan() { # <file> <begin> <end> [<legacy-begin> <legacy-end>]
25
+ local f="$1" b="$2" e="$3" lb="${4:-}" le="${5:-}"
26
+ local -a raw=(); local c fc info op i n lastnl=1 tail_close_fence_re
27
+ MS_LINES=(); MS_TERM=(); MS_IDX=(); MS_KIND=(); MS_FENCE_OPEN=0
28
+ mapfile -t raw < "$f"
29
+ n=${#raw[@]}
30
+ [ "$n" -gt 0 ] || return 0
31
+ [ "$(tail -c 1 "$f" | wc -l)" -eq 1 ] || lastnl=0
32
+ fc=""
33
+ for ((i = 0; i < n; i++)); do
34
+ c="${raw[i]%$'\r'}"
35
+ MS_LINES[i]="$c"
36
+ if [ "$i" -eq $((n - 1)) ] && [ "$lastnl" = "0" ]; then
37
+ MS_TERM[i]=""
38
+ elif [ "${raw[i]}" != "$c" ]; then
39
+ MS_TERM[i]=$'\r\n'
40
+ else
41
+ MS_TERM[i]=$'\n'
42
+ fi
43
+ if [ -z "$fc" ]; then
44
+ if [[ $c =~ $MS_FENCE_OPEN_RE ]]; then
45
+ op="${BASH_REMATCH[1]}"; info="${BASH_REMATCH[2]}"
46
+ # 反引号围栏的 info string 里带反引号 → 不是围栏(CommonMark),按普通内容继续
47
+ if ! { [ "${op:0:1}" = '`' ] && [[ $info == *'`'* ]]; }; then
48
+ fc="${op:0:1}"; tail_close_fence_re="^ {0,3}${fc}{${#op},}[[:space:]]*$"
49
+ continue
50
+ fi
51
+ fi
52
+ case "$c" in
53
+ "$b") MS_IDX+=("$i"); MS_KIND+=(curBegin) ;;
54
+ "$e") MS_IDX+=("$i"); MS_KIND+=(curEnd) ;;
55
+ *)
56
+ if [ -n "$lb" ] && [ "$c" = "$lb" ]; then MS_IDX+=("$i"); MS_KIND+=(legBegin)
57
+ elif [ -n "$le" ] && [ "$c" = "$le" ]; then MS_IDX+=("$i"); MS_KIND+=(legEnd)
58
+ fi ;;
59
+ esac
60
+ elif [[ $c =~ $tail_close_fence_re ]]; then
61
+ fc=""
62
+ fi
63
+ done
64
+ # 只有「文件结束在围栏里」才影响决定:已闭合的围栏里那对示例行是普通内容
65
+ [ -n "$fc" ] && MS_FENCE_OPEN=1
66
+ return 0
67
+ }
68
+
69
+ # 只回答一件事:文件里有没有「可迁移的旧标记候选行」(给 doctor 的迁移提示用)。
70
+ # 漂在正文、缩进、或被围栏圈起来的旧标记示例不是候选 —— 提示只该指向 init 真会改的那两行。
71
+ team_legacy_marker_candidates() { # <file> <legacy-begin> <legacy-end> → 候选行数
72
+ local f="$1"
73
+ [ -f "$f" ] && [ -s "$f" ] || { printf '0'; return 0; }
74
+ team_marker_scan "$f" '<!-- teamsmith:begin -->' '<!-- teamsmith:end -->' "$2" "$3"
75
+ local i cnt=0
76
+ for i in "${MS_KIND[@]}"; do
77
+ case "$i" in legBegin|legEnd) cnt=$((cnt + 1)) ;; esac
78
+ done
79
+ printf '%s' "$cnt"
80
+ }
81
+
82
+ team_write_section() { # <file> <begin-marker> <end-marker> <content-file> [<legacy-begin> <legacy-end>]
83
+ local target="$1" begin="$2" end="$3" content="$4" lb="${5:-}" le="${6:-}"
84
+ local cb=0 ce=0 lbb=0 lee=0 bi=-1 ei=-1 lbi=-1 lei=-1 reason="" i
11
85
  mkdir -p "$(dirname "$target")"
12
86
  [ -f "$target" ] || : > "$target"
13
- if grep -qF "$begin" "$target"; then
14
- awk -v b="$begin" -v e="$end" -v cf="$content" '
15
- $0==b { inb=1; print; while ((getline l < cf) > 0) { if (l==b || l==e) continue; print l }; close(cf); next }
16
- inb { if ($0==e) { inb=0; print }; next }
17
- { print }
18
- ' "$target" > "$target.tmp" && mv "$target.tmp" "$target"
19
- team_ok "update $target(协议段落已刷新)"
20
- else
87
+ team_marker_scan "$target" "$begin" "$end" "$lb" "$le"
88
+ for i in "${!MS_KIND[@]}"; do
89
+ case "${MS_KIND[i]}" in
90
+ curBegin) cb=$((cb + 1)); bi=${MS_IDX[i]} ;;
91
+ curEnd) ce=$((ce + 1)); ei=${MS_IDX[i]} ;;
92
+ legBegin) lbb=$((lbb + 1)); lbi=${MS_IDX[i]} ;;
93
+ legEnd) lee=$((lee + 1)); lei=${MS_IDX[i]} ;;
94
+ esac
95
+ done
96
+ if [ "$((cb + ce + lbb + lee))" -eq 0 ]; then
97
+ # 无候选:追加一块;但文件结束在未闭合围栏里时追加会落进围栏、而且每次重跑都再长一块 → 拒绝
98
+ if [ "$MS_FENCE_OPEN" = "1" ]; then
99
+ team_err "AGENTS 受管段:$target 的标记形状无法确定,文件未改动"
100
+ team_dim " 原因:文件结束在一个未闭合的代码围栏里(追加的协议段会落进围栏、且每次重跑都会再追加一块);先补上围栏的结束行" >&2
101
+ return 1
102
+ fi
21
103
  { [ -s "$target" ] && printf '\n'; printf '%s\n' "$begin"; grep -vFxf <(printf '%s\n%s\n' "$begin" "$end") "$content"; printf '%s\n' "$end"; } >> "$target"
22
104
  team_ok "append $target(团队协议段落)"
105
+ return 0
106
+ fi
107
+ # 形状判定:先数完全部候选再决定,绝不「取第一对」
108
+ if { [ "$cb" -gt 0 ] || [ "$ce" -gt 0 ]; } && { [ "$lbb" -gt 0 ] || [ "$lee" -gt 0 ]; }; then
109
+ reason="新旧标记混用(当前 $((cb + ce)) 行、旧名 $((lbb + lee)) 行)——无法判断哪一对是受管段"
110
+ elif [ "$cb" -gt 1 ] || [ "$ce" -gt 1 ]; then
111
+ reason="有多对受管标记(开始 $cb 行、结束 $ce 行)"
112
+ elif [ "$cb" -eq 1 ] && [ "$ce" -eq 0 ]; then
113
+ reason="有开始标记没有结束标记(第 $((bi + 1)) 行)"
114
+ elif [ "$ce" -eq 1 ] && [ "$cb" -eq 0 ]; then
115
+ reason="有结束标记没有开始标记(第 $((ei + 1)) 行)"
116
+ elif [ "$cb" -eq 1 ] && [ "$ce" -eq 1 ] && [ "$bi" -ge "$ei" ]; then
117
+ reason="结束标记在开始标记之前(第 $((ei + 1)) 行 / 第 $((bi + 1)) 行)"
118
+ elif [ "$lbb" -gt 1 ] || [ "$lee" -gt 1 ]; then
119
+ reason="有多对旧名标记(开始 $lbb 行、结束 $lee 行)"
120
+ elif [ "$lbb" -eq 1 ] && [ "$lee" -eq 0 ]; then
121
+ reason="有旧名开始标记没有结束标记(第 $((lbi + 1)) 行)"
122
+ elif [ "$lee" -eq 1 ] && [ "$lbb" -eq 0 ]; then
123
+ reason="有旧名结束标记没有开始标记(第 $((lei + 1)) 行)"
124
+ elif [ "$((lbb + lee))" -gt 0 ] && [ "$lbi" -ge "$lei" ]; then
125
+ reason="旧名结束标记在开始标记之前(第 $((lei + 1)) 行 / 第 $((lbi + 1)) 行)"
126
+ fi
127
+ if [ -n "$reason" ]; then
128
+ team_err "AGENTS 受管段:$target 的标记形状无法确定,文件未改动"
129
+ team_dim " 原因:$reason;请手工改成恰好一对围栏外独占行的标记,再跑同一条命令" >&2
130
+ return 1
23
131
  fi
132
+ # 到这里的形状:一对当前标记,或一对旧名标记
133
+ if [ "$cb" -eq 0 ]; then
134
+ bi="$lbi"; ei="$lei"
135
+ fi
136
+ local bodyterm=$'\n' legacy=0
137
+ [ "$cb" -eq 0 ] && legacy=1
138
+ # 正文的终止符只由 begin 行自己决定(混合行尾文件里它是唯一权威)
139
+ [ "${MS_TERM[bi]}" = $'\r\n' ] && bodyterm=$'\r\n'
140
+ local -a body=(); mapfile -t body < "$content"
141
+ local k m=${#MS_LINES[@]}
142
+ {
143
+ for ((k = 0; k < bi; k++)); do printf '%s%s' "${MS_LINES[k]}" "${MS_TERM[k]}"; done
144
+ # 旧名对:两行标记本身也换成当前标记(同一处范围编辑,围栏外的示例一个字节都不动)
145
+ if [ "$legacy" = "1" ]; then printf '%s%s' "$begin" "${MS_TERM[bi]}"; else printf '%s%s' "${MS_LINES[bi]}" "${MS_TERM[bi]}"; fi
146
+ for k in "${!body[@]}"; do
147
+ if [ "${body[k]}" = "$begin" ] || [ "${body[k]}" = "$end" ]; then continue; fi
148
+ printf '%s%s' "${body[k]}" "$bodyterm"
149
+ done
150
+ if [ "$legacy" = "1" ]; then printf '%s%s' "$end" "${MS_TERM[ei]}"; else printf '%s%s' "${MS_LINES[ei]}" "${MS_TERM[ei]}"; fi
151
+ for ((k = ei + 1; k < m; k++)); do printf '%s%s' "${MS_LINES[k]}" "${MS_TERM[k]}"; done
152
+ } > "$target.tmp" && mv "$target.tmp" "$target"
153
+ [ "$legacy" = "1" ] && team_dim " 旧名标记已迁移为 teamsmith 标记"
154
+ team_ok "update $target(协议段落已刷新)"
155
+ return 0
24
156
  }
25
157
 
26
158
  team_gitignore_add() { # <entry> ...
@@ -148,12 +280,27 @@ team_cmd_init() {
148
280
  done
149
281
 
150
282
  local project; project="$(basename "$TEAM_MAIN_ROOT")"
283
+ local cfg="$TEAM_MAIN_ROOT/.pi/team/config.sh" had_config=0; [ -f "$cfg" ] && had_config=1
284
+ local gates_from_config=0
285
+ # P402:既有契约(且不是 --force 重渲染)时,命令行上没给的渲染参数取**契约里的现值** —— 受管块是
286
+ # agent 读到的「PM 在哪、有谁」的权威说明,写目录名/硬编码默认就是文档撒谎(2026-11-03 现场:
287
+ # TEAM_SESSION=teamsmith、TEAM_AGENTS="dev verify dev2 dev3 dev-bob" 的项目被渲染成 `pm-skills:pm`
288
+ # 与 `dev verify`)。显式参数仍然优先;键缺失(老契约/手改)是预期分支,保持下面的默认。
289
+ if [ "$had_config" = "1" ] && [ "$force" != "1" ]; then
290
+ local _cfgv
291
+ if [ -z "$session" ] && _cfgv="$(team_config_file_value "$cfg" TEAM_SESSION)"; then session="$_cfgv"; fi
292
+ if [ -z "$agents" ] && _cfgv="$(team_config_file_value "$cfg" TEAM_AGENTS)"; then agents="$_cfgv"; fi
293
+ if [ -z "$docs" ] && _cfgv="$(team_config_file_value "$cfg" TEAM_DOCS_DIR)"; then docs="$_cfgv"; fi
294
+ if [ -z "$pmwin" ] && _cfgv="$(team_config_file_value "$cfg" TEAM_PM_WINDOW)"; then pmwin="$_cfgv"; fi
295
+ if [ -z "$gates" ] && _cfgv="$(team_config_file_value "$cfg" TEAM_GATES)"; then
296
+ gates="$_cfgv"; gates_from_config=1
297
+ fi
298
+ fi
151
299
  session="${session:-$project}"
152
300
  agents="${agents:-dev verify}"
153
301
  vcs="${vcs:-$(team_detect_vcs)}"
154
302
  docs="${docs:-docs/team}"
155
303
  pmwin="${pmwin:-pm}"
156
- local cfg="$TEAM_MAIN_ROOT/.pi/team/config.sh" had_config=0; [ -f "$cfg" ] && had_config=1
157
304
 
158
305
  # 0) 模型策略闸门(P235):退休键 / 缺输入 / 非法值都在**任何写入之前**停住。
159
306
  # 已有合法新策略允许不带输入重入(保留策略);退休键则连 --force 都不能当迁移捷径。
@@ -202,6 +349,8 @@ team_cmd_init() {
202
349
  gates="$(team_detect_gates)"
203
350
  TEAM_GATES="$_gates_keep"
204
351
  fi
352
+ elif [ "$gates_from_config" = "1" ]; then
353
+ : # P402:契约现值(含空值)就是这次渲染的值,不再拿检测结果替换契约的「未配置」
205
354
  else
206
355
  gates="${gates:-$(team_detect_gates)}"
207
356
  fi
@@ -272,16 +421,12 @@ team_cmd_init() {
272
421
  "PROJECT=$project" "DOCS_DIR=$docs" "SESSION=$session" "PM_WINDOW=$pmwin" \
273
422
  "SKILL_DIR=$TEAM_SKILL_DIR" "AGENTS=$agents" "GATES=${gates:-<未配置>}" \
274
423
  "WORKTREES_DIR=${TEAM_WORKTREES_DIR:-.worktrees}" "PROTECTED_BRANCH=main" > "$section"
275
- # 旧名标记迁移(<=1.12 的项目 AGENTS.md 里是 pi-team:begin/end):
276
- # 就地换成新标记,这样 team_write_section 认得出"段落已存在",不会重复注入。
424
+ # 旧名标记迁移(<=1.12 的项目 AGENTS.md 里是 pi-team:begin/end):交给同一个写入器,按同一处
425
+ # 范围编辑把标记行的文字换掉(围栏外那对才动,示例里的旧标记逐字节保留)。
277
426
  local _agents="$TEAM_MAIN_ROOT/AGENTS.md"
278
- if [ -f "$_agents" ] \
279
- && grep -qF '<!-- pi-team:begin -->' "$_agents" \
280
- && ! grep -qF '<!-- teamsmith:begin -->' "$_agents"; then
281
- sed -i 's|<!-- pi-team:begin -->|<!-- teamsmith:begin -->|; s|<!-- pi-team:end -->|<!-- teamsmith:end -->|' "$_agents"
282
- fi
283
427
  team_write_section "$TEAM_MAIN_ROOT/AGENTS.md" \
284
- "<!-- teamsmith:begin -->" "<!-- teamsmith:end -->" "$section"
428
+ "<!-- teamsmith:begin -->" "<!-- teamsmith:end -->" "$section" \
429
+ "<!-- pi-team:begin -->" "<!-- pi-team:end -->" || { rm -f "$section"; return 1; }
285
430
  rm -f "$section"
286
431
 
287
432
  # 4) .gitignore
@@ -308,12 +453,15 @@ team_cmd_init() {
308
453
 
309
454
  # ---------------------------------------------------------------- doctor
310
455
  # M7.1:这个项目要不要读迁移指南?两个判据都来自可查的真实状态,不猜:
311
- # ① AGENTS.md 里还是旧名标记 <!-- pi-team:begin -->(init/bootstrap 会就地改写;改写后不再触发)
456
+ # ① AGENTS.md 里还有围栏外的旧名标记 <!-- pi-team:begin -->(init 会就地改写;改写后不再触发)——
457
+ # 判据是「可迁移的候选行」,所以正文里引用、缩进或围栏里的旧名示例不会让这条提示永不消失。
312
458
  # ② 本会话加载的 skill 比磁盘旧(mark-loaded 记的版本/指纹与磁盘不一致)—— 与 version --check 同口径
313
459
  # 干净项目上保持静默(doctor 不该多刷一行);返回原因字符串,没有原因则返回空。
314
460
  team_migration_reasons() {
315
461
  local reasons="" f="$TEAM_MAIN_ROOT/AGENTS.md" loaded
316
- if [ -f "$f" ] && grep -qF '<!-- pi-team:begin -->' "$f"; then
462
+ # 只看「init 真会改的那两行」:围栏外、独占整行、逐字节等于旧名标记。正文引用、缩进
463
+ # 或围栏里的旧名示例都不会被 init 改写,所以它们也不该让这条提示永不消失。
464
+ if [ -f "$f" ] && [ "$(team_legacy_marker_candidates "$f" '<!-- pi-team:begin -->' '<!-- pi-team:end -->')" -gt 0 ]; then
317
465
  reasons="AGENTS.md 还是旧名标记"
318
466
  fi
319
467
  loaded="$(team_loaded_version 2>/dev/null || true)"
@@ -620,6 +768,30 @@ team_cmd_doctor() {
620
768
  fi
621
769
  fi
622
770
 
771
+ # Disk, directed launch and actual process registration are separate evidence; mark-loaded is not runtime proof.
772
+ check "关键回复磁盘"
773
+ if [ -f "$TEAM_SKILL_DIR/extension/team-reply.ts" ] && [ -f "$TEAM_SKILL_DIR/scripts/reply-capture.mjs" ]; then
774
+ pass "捕获源码存在(不代表当前 PM 已加载)"
775
+ else warn "捕获源码缺失"; fi
776
+ check "关键回复启动"
777
+ if [ -z "$(team_trim "${TEAM_PM_CMD:-}")" ]; then
778
+ pass "内置 Pi 启动定向注入 team-reply;旧进程未带 -e 时 /reload 不会补入口,须获权重启"
779
+ else warn "自定义 PM 命令不注入捕获扩展,首版不承诺兼容"; fi
780
+ check "关键回复运行"
781
+ local reply_runner reply_runtime
782
+ reply_runner="$(team_js_runner)"
783
+ if [ -z "$reply_runner" ]; then
784
+ warn "unknown:无可用 JS 运行时,未核实 live 注册"
785
+ elif reply_runtime="$("$reply_runner" -e '
786
+ import(require("node:url").pathToFileURL(process.argv[1]).href).then(m => {
787
+ const [root,state,config,session,window,skill] = process.argv.slice(2);
788
+ const r = m.inspectRuntime({root,state,config,session,window,skill});
789
+ console.log(`${r.state} disk=${r.disk || "unknown"} loaded=${r.loaded || "unknown"} generation=${r.generation || "unknown"}; ${r.reason}`);
790
+ }).catch(e => { console.error(`runtime diagnostic unavailable: ${e.code || e.name}`); process.exitCode=1 })
791
+ ' "$TEAM_SKILL_DIR/scripts/reply-capture.mjs" "$TEAM_MAIN_ROOT" "$TEAM_STATE_DIR" "${TEAM_CONFIG:-${TEAM_CONFIG_FILE:-}}" "$TEAM_SESSION" "$TEAM_PM_WINDOW" "$TEAM_SKILL_DIR")"; then
792
+ case "$reply_runtime" in ready\ *) pass "$reply_runtime" ;; *) warn "$reply_runtime" ;; esac
793
+ else warn "unknown:live 注册诊断执行失败(未当作启用)"; fi
794
+
623
795
  check "巡检(pulse)"; local legacy_note; legacy_note="$(team_pulse_legacy_suffix)"
624
796
  case "$(team_pulse_state)" in
625
797
  off) warn "没在跑 → $TEAM_CLI pulse up(pulse 由 PM 配置)$legacy_note" ;;
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env bash
2
+ # teamsmith · `team remind`:给 PM 自己的定时提醒(change: agent-self-reminder 2.1/2.3 · P409)
3
+ #
4
+ # team remind add --at <RFC3339>|--after <30s|5m|2h> (--message <text> | --message-file <file>)
5
+ # [--key <id>] [--task <ref>] [--json]
6
+ # team remind list [--all] [--json]
7
+ # team remind show <id> [--json]
8
+ # team remind cancel <id> [--json]
9
+ #
10
+ # 这里只做三件事:解析人敲的参数、把正文按**字节**送进 stdin、把助手的结论原样打印。
11
+ # 状态、锁、原子写与视图派生全在 scripts/state-authority.mjs 的事务里(common.sh 的
12
+ # team_authority_cli 是唯一入口)—— 没有第二份文件读写,也没有第二把锁。
13
+ #
14
+ # 正文走 stdin 而不是 argv:不经过 shell 引号/长度限制,也不重新编码;`--message-file` 直接把文件
15
+ # 接给 stdin(`$(cat …)` 会吃掉结尾换行,那是正文的一部分)。
16
+ #
17
+ # 本片只有 `scheduled` 与 `cancelled` 两个相位由这里产生;`queued/intent/observed/unknown/resolved`
18
+ # 由 3.x/4.x 的投递与 Pulse 写入,读侧已经按同一份快照派生并显示它们。
19
+
20
+ team_remind_usage() {
21
+ printf 'usage: team remind add|list|show|cancel …(team help remind)\n' >&2
22
+ }
23
+
24
+ # team_remind_add — 参数面在这里拒绝;时间解析、正文字节与 key 幂等由事务里的同一份规则决定。
25
+ team_remind_add() {
26
+ local at="" after="" key="" task="" msg="" msgfile="" json="" has_msg=0 has_file=0
27
+ while [ $# -gt 0 ]; do
28
+ case "$1" in
29
+ --at) [ $# -ge 2 ] || team_usage_die "remind add: --at 需要时间"; at="$2"; shift 2 ;;
30
+ --after) [ $# -ge 2 ] || team_usage_die "remind add: --after 需要时长"; after="$2"; shift 2 ;;
31
+ --message) [ $# -ge 2 ] || team_usage_die "remind add: --message 需要正文"; msg="$2"; has_msg=1; shift 2 ;;
32
+ --message-file) [ $# -ge 2 ] || team_usage_die "remind add: --message-file 需要文件"; msgfile="$2"; has_file=1; shift 2 ;;
33
+ --key) [ $# -ge 2 ] || team_usage_die "remind add: --key 需要值"; key="$2"; shift 2 ;;
34
+ --task) [ $# -ge 2 ] || team_usage_die "remind add: --task 需要值"; task="$2"; shift 2 ;;
35
+ --json) json="--json"; shift ;;
36
+ -*) team_usage_die "remind add: 未知参数 $1" ;;
37
+ *) team_usage_die "remind add: 多余的参数 $1(正文用 --message 或 --message-file)" ;;
38
+ esac
39
+ done
40
+ if [ "$has_msg" = "1" ] && [ "$has_file" = "1" ]; then
41
+ team_usage_die "remind add: --message 与 --message-file 只能给一个"
42
+ fi
43
+ if [ "$has_msg" = "0" ] && [ "$has_file" = "0" ]; then
44
+ team_usage_die "remind add: 需要正文(--message <text> 或 --message-file <file>);正文不做截断,空正文会被拒绝"
45
+ fi
46
+ local args=(remind-add)
47
+ [ -n "$at" ] && args+=(--at "$at")
48
+ [ -n "$after" ] && args+=(--after "$after")
49
+ [ -n "$key" ] && args+=(--key "$key")
50
+ [ -n "$task" ] && args+=(--task "$task")
51
+ [ -n "$json" ] && args+=(--json)
52
+ if [ "$has_file" = "1" ]; then
53
+ [ -f "$msgfile" ] && [ -r "$msgfile" ] || team_die "remind add: 读不到正文文件 $msgfile"
54
+ team_authority_cli "${args[@]}" < "$msgfile"
55
+ else
56
+ printf '%s' "$msg" | team_authority_cli "${args[@]}"
57
+ fi
58
+ }
59
+
60
+ team_remind_list() {
61
+ local args=(remind-list) json=""
62
+ while [ $# -gt 0 ]; do
63
+ case "$1" in
64
+ --all) args+=(--all); shift ;;
65
+ --json) json="--json"; shift ;;
66
+ -*) team_usage_die "remind list: 未知参数 $1" ;;
67
+ *) team_usage_die "remind list: 多余的参数 $1" ;;
68
+ esac
69
+ done
70
+ [ -n "$json" ] && args+=(--json)
71
+ team_authority_cli "${args[@]}" < /dev/null
72
+ }
73
+
74
+ # show / cancel 共用一个「恰好一个 id」的参数面。
75
+ team_remind_one_id() { # <子命令> <默认动词> [args…]
76
+ local sub="$1" op="$2"; shift 2
77
+ local id="" json=""
78
+ while [ $# -gt 0 ]; do
79
+ case "$1" in
80
+ --json) json="--json"; shift ;;
81
+ -*) team_usage_die "remind $sub: 未知参数 $1" ;;
82
+ *) [ -z "$id" ] || team_usage_die "remind $sub: 多余的参数 $1"; id="$1"; shift ;;
83
+ esac
84
+ done
85
+ [ -n "$id" ] || team_usage_die "remind $sub: 需要一个提醒 id(team remind list 看 id)"
86
+ local args=("$op" --id "$id")
87
+ [ -n "$json" ] && args+=(--json)
88
+ team_authority_cli "${args[@]}" < /dev/null
89
+ }
90
+
91
+ team_cmd_remind() {
92
+ local sub="${1:-}"
93
+ [ $# -gt 0 ] && shift
94
+ case "$sub" in
95
+ add) team_remind_add "$@" ;;
96
+ list) team_remind_list "$@" ;;
97
+ show) team_remind_one_id show remind-show "$@" ;;
98
+ cancel) team_remind_one_id cancel remind-cancel "$@" ;;
99
+ "") team_remind_usage; return 2 ;;
100
+ -h|--help) team_remind_usage; return 0 ;;
101
+ *) team_usage_die "remind: 未知子命令 $sub(add|list|show|cancel)" ;;
102
+ esac
103
+ }
@@ -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"