teamsmith 0.3.2 → 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 (39) hide show
  1. package/README.md +5 -4
  2. package/package.json +2 -6
  3. package/skills/handover/SKILL.md +117 -0
  4. package/skills/teamsmith/CHANGELOG.md +65 -0
  5. package/skills/teamsmith/SKILL.md +2 -1
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +30 -1
  7. package/skills/teamsmith/extension/team-notify.ts +161 -20
  8. package/skills/teamsmith/references/agent-adapters.md +3 -1
  9. package/skills/teamsmith/references/config.md +1 -1
  10. package/skills/teamsmith/references/protocol.md +21 -0
  11. package/skills/teamsmith/references/troubleshooting.md +7 -3
  12. package/skills/teamsmith/scripts/lib/cmd-agents.sh +213 -19
  13. package/skills/teamsmith/scripts/lib/cmd-config.sh +1 -1
  14. package/skills/teamsmith/scripts/lib/cmd-init.sh +85 -9
  15. package/skills/teamsmith/scripts/lib/cmd-status.sh +177 -21
  16. package/skills/teamsmith/scripts/lib/cmd-watch.sh +11 -1
  17. package/skills/teamsmith/scripts/lib/common.sh +7 -3
  18. package/skills/teamsmith/scripts/lib/outbox.sh +31 -3
  19. package/skills/teamsmith/scripts/panel/panel.js +1 -1
  20. package/skills/teamsmith/scripts/panel/src/strings/en.ts +1 -1
  21. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +1 -1
  22. package/skills/teamsmith/scripts/strings/help.en.tsv +1 -1
  23. package/skills/teamsmith/scripts/strings/help.zh.tsv +1 -1
  24. package/skills/teamsmith/scripts/team +1 -0
  25. package/skills/teamsmith/templates/config.sh.tmpl +2 -1
  26. package/skills/teamsmith/tests/bg-ledger-harness.mjs +17 -6
  27. package/skills/teamsmith/tests/bg-ledger.sh +16 -5
  28. package/skills/teamsmith/tests/checkout-shape-probe.sh +10 -2
  29. package/skills/teamsmith/tests/help-surface.sh +1 -1
  30. package/skills/teamsmith/tests/install-shape.sh +234 -46
  31. package/skills/teamsmith/tests/panel-choices.sh +11 -7
  32. package/skills/teamsmith/tests/section-paths.tsv +2 -2
  33. package/skills/teamsmith/tests/skill-load.mjs +6 -2
  34. package/skills/teamsmith/tests/smoke.sh +643 -27
  35. package/skills/teamsmith/tests/task-model-routing.sh +10 -1
  36. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +33 -0
  37. package/skills/teamsmith/tests/team-notify-knock-marker.mjs +91 -0
  38. package/skills/teamsmith/tests/tmux-lint.pl +12 -2
  39. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -34,6 +34,26 @@ if [ "${SMOKE_SEL_CHILD:-0}" = "1" ] && [ -n "${SMOKE_SEL_SKILL_DIR:-}" ] \
34
34
  fi
35
35
  # P16:初始化指引是兄弟 skill(本仓库 skills/teamsmith-init;安装后 ~/.agents/skills/ 里并排的两条软链)。
36
36
  SKILL_INIT_DIR="$(cd -P "$SKILL_DIR/.." && pwd)/teamsmith-init"
37
+ # P361:技能源清单的真源 —— 包内 skills/ 下每个**真实目录**,且 SKILL.md 的 name: 与目录名一致。
38
+ # 凡是要「遍历所有随包技能」的地方(0b 的解析器加载、14b 的文档扫描、装技能的计数断言)都走这里:
39
+ # 写死名字的代价实测了两次 —— 夹具数「两个」时第三个技能对两边都不可见;§0b 写死 `handover` 时,
40
+ # 只拷两个技能目录的检出形状(checkout-shape-probe 的 scratch 树)会红。**别再加名字,走清单。**
41
+ SKILL_SRC_PARENT="$(cd -P "$SKILL_DIR/.." && pwd)" # = <repo>/skills(P361:源清单就在这一层)
42
+ skill_src_names() {
43
+ local d n
44
+ for d in "$SKILL_SRC_PARENT"/*/; do
45
+ [ -d "$d" ] || continue
46
+ [ -L "${d%/}" ] && continue
47
+ n="$(basename "$d")"
48
+ [ "$(sed -n 's/^name:[[:space:]]*//p' "$d/SKILL.md" 2>/dev/null | head -1)" = "$n" ] && printf '%s\n' "$n"
49
+ done | sort
50
+ }
51
+ skill_src_dirs() { # → 每个源技能的绝对目录(一行一个,顺序同 skill_src_names)
52
+ local n
53
+ while IFS= read -r n; do
54
+ [ -n "$n" ] && printf '%s/%s\n' "$SKILL_SRC_PARENT" "$n"
55
+ done <<< "$(skill_src_names)"
56
+ }
37
57
  TEAM="bash $SKILL_DIR/scripts/team"
38
58
  # P235:新鲜项目的 init/bootstrap 必须给显式的类别映射 + 独立 PM 模型(工具不再猜席位/默认模型)。
39
59
  # 夹具一律用这一对;断言要看真实值的用例自己覆盖。
@@ -1560,8 +1580,10 @@ assert_eq "M33 哨兵:后台哨兵活着,但不在作业表里(裸 wait
1560
1580
  # ---------------------------------------------------------------- 0b. skill 合法性(pi 自己的解析器)
1561
1581
  section "0b · skill 可被 pi 解析器加载"
1562
1582
  if [ -n "$JS_RUNNER" ]; then
1563
- # P16:两个 skill 都必须是合法可加载的(解析器期望的 name = 目录名)。
1564
- for P16_SD in "$SKILL_DIR" "$SKILL_INIT_DIR"; do
1583
+ # P16:每个 skill 都必须是合法可加载的(解析器期望的 name = 目录名)。
1584
+ # P361:清单从源派生(skill_src_dirs)—— 检出形状只带一部分技能时,扫的就是它带着的那几个。
1585
+ while IFS= read -r P16_SD; do
1586
+ [ -n "$P16_SD" ] || continue
1565
1587
  P16_SL="$TMP/skill-load-$(basename "$P16_SD").log"
1566
1588
  $JS_RUNNER "$SKILL_DIR/tests/skill-load.mjs" "$P16_SD" >"$P16_SL" 2>&1
1567
1589
  P16_RC=$?
@@ -1574,7 +1596,7 @@ if [ -n "$JS_RUNNER" ]; then
1574
1596
  else
1575
1597
  bad "skill-load 失败($(basename "$P16_SD"))"; cat "$P16_SL"
1576
1598
  fi
1577
- done
1599
+ done <<< "$(skill_src_dirs)"
1578
1600
  else
1579
1601
  printf ' (跳过:没有可用的 JS 运行时)\n'
1580
1602
  fi
@@ -2641,14 +2663,18 @@ assert_has "$REPO/docs/team/PROTOCOL.md" "references/openspec.md" "PROTOCOL.md
2641
2663
  assert_file "$REPO/docs/team/threads/README.md" "写入 threads/README"
2642
2664
  assert_has "$REPO/AGENTS.md" "<!-- teamsmith:begin -->" "AGENTS.md 注入协议段"
2643
2665
  assert_has "$REPO/.gitignore" ".worktrees/" ".gitignore 忽略 worktree"
2644
- # P40:init 的安装步 —— 两条软链装进项目 .pi/skills/,.gitignore 跟着忽略它
2666
+ # P40:init 的安装步 —— 源里每个技能一条软链装进项目 .pi/skills/,.gitignore 跟着忽略它
2645
2667
  # (本仓已跟踪的 .pi/skills/openspec-* 不受影响:忽略行不会 untrack 已跟踪文件)
2646
- assert_eq "P40 init 装了项目 skill:.pi/skills/teamsmith → 运行树" \
2647
- "$(readlink -f "$REPO/.pi/skills/teamsmith" 2>/dev/null || echo missing)" "$SKILL_DIR"
2648
- assert_eq "P40 init 装了兄弟条目 teamsmith-init" \
2649
- "$(readlink -f "$REPO/.pi/skills/teamsmith-init" 2>/dev/null || echo missing)" "$SKILL_INIT_DIR"
2668
+ # P361:数量与名字跟着源清单走(skill_src_names),不再写死「两条」
2669
+ while IFS= read -r P40_S; do
2670
+ [ -n "$P40_S" ] || continue
2671
+ assert_eq "P40 init 装了项目 skill:.pi/skills/$P40_S → 源" \
2672
+ "$(readlink -f "$REPO/.pi/skills/$P40_S" 2>/dev/null || echo missing)" \
2673
+ "$(readlink -f "$SKILL_SRC_PARENT/$P40_S" 2>/dev/null || echo missing)"
2674
+ done <<< "$(skill_src_names)"
2650
2675
  assert_has "$REPO/.gitignore" ".pi/skills/" "P40 .gitignore 忽略项目 skill 安装目录"
2651
- assert_eq "P40 .pi/skills/ 里恰好两条" "$(ls -1A "$REPO/.pi/skills" | wc -l)" "2"
2676
+ assert_eq "P40 .pi/skills/ 里的名字与源清单一致($(skill_src_names | tr '\n' ' '))" \
2677
+ "$(ls -1A "$REPO/.pi/skills" | sort | tr '\n' ' ')" "$(skill_src_names | tr '\n' ' ')"
2652
2678
 
2653
2679
  # 隔离自检(关键):team 必须把自己当成临时仓库 + 本测试 session
2654
2680
  ISOLATE="$($TEAM paths 2>/dev/null || true)"
@@ -2709,10 +2735,11 @@ else ok "模板全部渲染(无 {{ 残留)"; fi
2709
2735
  # 幂等:再 init 一次不应重复追加协议段
2710
2736
  $TEAM init --session "$SESSION" --agents "dev verify" --vcs local --gates "true" --docs docs/team "${P235_MODELS[@]}" >"$TMP/init-again.log" 2>&1
2711
2737
  assert_eq "AGENTS.md 协议段幂等(只出现一次)" "$(grep -cF '<!-- teamsmith:begin -->' "$REPO/AGENTS.md")" "1"
2712
- # P40:第二次 init 不重装、不覆盖 —— 两个 skill 都报 skip(逐 skill 一行)
2713
- assert_eq "P40 第二次 init 对两个 skill 都报 skip" \
2714
- "$(grep -cE '^ skip .*/\.pi/skills/(teamsmith|teamsmith-init)(' "$TMP/init-again.log" || true)" "2"
2715
- assert_eq "P40 第二次 init 后 .pi/skills/ 仍然只有两条" "$(ls -1A "$REPO/.pi/skills" | wc -l)" "2"
2738
+ # P40:第二次 init 不重装、不覆盖 —— 源里每个技能都报 skip(逐 skill 一行)
2739
+ assert_eq "P40 第二次 init 对每个技能都报 skip($(skill_src_names | wc -l | tr -d ' ') 条)" \
2740
+ "$(grep -cE '^ skip .*/\.pi/skills/[A-Za-z0-9._-]+(' "$TMP/init-again.log" || true)" "$(skill_src_names | wc -l | tr -d ' ')"
2741
+ assert_eq "P40 第二次 init 后 .pi/skills/ 仍与源清单一致" \
2742
+ "$(ls -1A "$REPO/.pi/skills" | sort | tr '\n' ' ')" "$(skill_src_names | tr '\n' ' ')"
2716
2743
 
2717
2744
  # 必需依赖(D10)的确定性夹具:magic-context 用假 settings + 假包,OpenSpec 用假 CLI + 假 spec 目录。
2718
2745
  # 都在 $TMP 下、用绝对路径 —— 本机装没装都不影响断言。
@@ -5048,6 +5075,256 @@ $TEAM notify pm "pm 是合法收件人" >/dev/null 2>&1 && ok "notify pm 仍然
5048
5075
  rm -f "$REPO/docs/team/inbox/devv.md"
5049
5076
  $TEAM inbox --ack >/dev/null 2>&1
5050
5077
 
5078
+ # ── turn-notice-in-pm-inbox(P364 · A1 写入面):指针行 / 一份计数 / --detail ───────────────────────
5079
+ # 专用夹具仓库(与主夹具的收件箱、ack 基线、明细互不干扰)。判据全部走真 CLI:指针行由写入侧
5080
+ # 从记录行派生,记录行逐字节不变,一次交付只让待办 +1。
5081
+ P364R="$TMP/p364repo"; rm -rf "$P364R"; mkdir -p "$P364R"
5082
+ ( cd "$P364R" && git init -q -b main && git config user.email smoke@teamsmith && git config user.name smoke \
5083
+ && git commit -q --allow-empty -m init ) >/dev/null 2>&1
5084
+ p364() { ( cd "$P364R" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_SKILL_DIR -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR "$@" ); }
5085
+ p364 $TEAM init --session "teamsmith-smoke-p364-$$" --agents dev,dev2 --vcs local --gates true --docs docs/team "${P235_MODELS[@]}" >"$TMP/p364-init.log" 2>&1 \
5086
+ && ok "P364 夹具仓库 init 成功" || bad "P364 夹具仓库 init 失败(见 $TMP/p364-init.log)"
5087
+ assert_eq "P364 隔离:team paths 的 main_root 就是 P364 夹具仓库" \
5088
+ "$(p364 $TEAM paths 2>/dev/null | sed -n 's/.*"main_root": "\([^"]*\)".*/\1/p')" "$P364R"
5089
+ # 库函数面(键相等 / 计数断言用):与 CLI 同一套 lib、同一份配置
5090
+ p364_fn() { # <在夹具仓库里执行的一小段(已加载配置)>
5091
+ ( cd "$P364R" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_SKILL_DIR \
5092
+ bash -c '. "'"$SKILL_DIR"'/scripts/lib/common.sh"; for _f in "'"$SKILL_DIR"'"/scripts/lib/cmd-*.sh; do . "$_f" 2>/dev/null || true; done; team_load_config >/dev/null 2>&1; '"$1" )
5093
+ }
5094
+ P364_R1='2026-10-22T05:42:38.123Z ⚠ 未提交 3 个文件 · [auto] agent:dev · P362 · branch=task/P362-x · uncommitted=3 · unpushed=1(no-upstream) · task=P362 tip=1a2b3c4d5e6f :: ALLDONE feature implemented'
5095
+ P364_R2='2026-10-22T05:43:00.456Z ⚠ 未提交 4 个文件 · [auto] agent:dev · P362 · branch=task/P362-x · uncommitted=4 · unpushed=2(no-upstream) · task=P362 tip=1a2b3c4d5e6f :: next event'
5096
+ printf '%s\n' "$P364_R1" > "$TMP/p364-r1.txt"
5097
+ printf '%s\n' "$P364_R2" > "$TMP/p364-r2.txt"
5098
+ p364 $TEAM __inbox-write --agent dev --from-file "$TMP/p364-r1.txt" >"$TMP/p364-w1.log" 2>&1
5099
+ assert_has "$TMP/p364-w1.log" "state=new" "P364:首事件写下新行(state=new)"
5100
+ cp "$P364R/docs/team/inbox/dev.md" "$TMP/p364-rec-before.txt"
5101
+ p364 $TEAM __notify-settle --agent dev --outcome enqueued --record-from-file "$TMP/p364-r1.txt" --task P362 >"$TMP/p364-s1.log" 2>&1; P364_RC=$?
5102
+ assert_eq "P364:settle 的旁路入口退出码恒 0" "$P364_RC" "0"
5103
+ assert_has "$TMP/p364-s1.log" "pointer=ok" "P364:settle 打印 pointer=ok"
5104
+ assert_eq "R2 指针是旁路:记录行逐字节不变(指针开/关同一结果)" \
5105
+ "$(cmp -s "$TMP/p364-rec-before.txt" "$P364R/docs/team/inbox/dev.md" && echo same || echo changed)" "same"
5106
+ P364_PTR="$(tail -n 1 "$P364R/docs/team/inbox/pm.md")"
5107
+ assert_eq "指针行形状(字段顺序写死:身份 · 任务 · knock · see · 修订戳)" "$P364_PTR" \
5108
+ "- 2026-10-22T05:42:38.123Z [auto] agent:dev · P362 · knock=enqueued · see=docs/team/inbox/dev.md · task=P362 tip=1a2b3c4d5e6f"
5109
+ assert_not_echo "$P364_PTR" " :: " "指针行不带末消息摘要(pm.md 的行数是 PM 的待办数)"
5110
+ assert_not_echo "$P364_PTR" "branch=" "指针行不带事件级的 branch="
5111
+ assert_not_echo "$P364_PTR" "uncommitted=" "指针行不带事件级的 uncommitted="
5112
+ assert_not_echo "$P364_PTR" "unpushed=" "指针行不带事件级的 unpushed="
5113
+ assert_not_echo "$P364_PTR" "⚠" "指针行不带 ⚠ 未提交 前缀"
5114
+ P364_REC="$(tail -n 1 "$P364R/docs/team/inbox/dev.md")"
5115
+ assert_not_echo "$P364_REC" "knock=" "记录行不带 knock=(指针字段不回流)"
5116
+ assert_not_echo "$P364_REC" "see=" "记录行不带 see=(指针字段不回流)"
5117
+ assert_eq "指针行与记录行同一个合并键(缺 task= 戳就退化成两条)" \
5118
+ "$(p364_fn 'team_notify_line_key "$(tail -n 1 docs/team/inbox/pm.md)"')" \
5119
+ "$(p364_fn 'team_notify_line_key "$(tail -n 1 docs/team/inbox/dev.md)"')"
5120
+ # 同 run 的第二个事件:记录行合并成 ×2,指针行也合并成一行 —— 但 knock= 保留首事件的取值
5121
+ p364 $TEAM __inbox-write --agent dev --from-file "$TMP/p364-r2.txt" >"$TMP/p364-w2.log" 2>&1
5122
+ assert_has "$TMP/p364-w2.log" "state=extended" "P364:同 run 的第二事件扩展既有行(state=extended)"
5123
+ cp "$P364R/docs/team/inbox/dev.md" "$TMP/p364-rec-before2.txt"
5124
+ p364 $TEAM __notify-settle --agent dev --outcome skipped:merged --record-from-file "$TMP/p364-r2.txt" --task P362 >"$TMP/p364-s2.log" 2>&1
5125
+ assert_has "$TMP/p364-s2.log" "pointer=ok" "P364:扩展事件的 settle 也写指针(pointer=ok)"
5126
+ assert_eq "R2 扩展事件也不动记录行(合并只发生在指针自己的文件里)" \
5127
+ "$(cmp -s "$TMP/p364-rec-before2.txt" "$P364R/docs/team/inbox/dev.md" && echo same || echo changed)" "same"
5128
+ P364_PTR2="$(tail -n 1 "$P364R/docs/team/inbox/pm.md")"
5129
+ assert_eq "R4 knock= 是 run 级字段:扩展事件不改写首事件的 enqueued" \
5130
+ "$(printf '%s' "$P364_PTR2" | grep -o 'knock=[^ ]*')" "knock=enqueued"
5131
+ assert_has_echo "$P364_PTR2" "×2 first=2026-10-22T05:42:38.123Z last=2026-10-22T05:43:00.456Z" "指针行合并成一个 run(×2 first= last=)"
5132
+ assert_eq "P364:同一个 run 在 pm.md 里只占一行" "$(wc -l < "$P364R/docs/team/inbox/pm.md" | tr -d ' ')" "1"
5133
+ assert_eq "P364/R5:明细每个事件一条(指针不进明细,×N 仍等于记录数)" \
5134
+ "$(grep -c '^- ' "$P364R/.pi/team/state/notify.log")" "2"
5135
+ # 一份计数:一次交付让待办 +1(席位自己那份记录不计数),指针行才是 PM 的未读
5136
+ assert_eq "R7:指针行让 PM 的未读从 0 变 1" "$(p364_fn 'team_inbox_new pm')" "1"
5137
+ assert_eq "R6:席位自己的 auto 记录不算它自己的未读流量" "$(p364_fn 'team_inbox_new dev')" "0"
5138
+ assert_has_echo "$(p364_fn 'team_pending_text')" "未读通知 1" "R6:待办里的未读通知 = 1(不是 2)"
5139
+ assert_not_echo "$(p364_fn 'team_pending_text')" "未读通知 2" "R6:待办没有把同一次交付数两遍"
5140
+ # 判据不是「文件名是 pm」的特例:别的席位之间同样成立(别人发来的 auto 行 + 手工行照旧计数)
5141
+ printf '%s\n' '- 2026-10-22T05:45:00.000Z [auto] agent:dev · P362 · branch=task/P362-x · uncommitted=0 · unpushed=0' >> "$P364R/docs/team/inbox/dev2.md"
5142
+ printf '%s\n' '- 2026-10-22T05:46:00.000Z [manual] agent:dev · 手工问一句' >> "$P364R/docs/team/inbox/dev2.md"
5143
+ assert_eq "R6:判据不是「文件名是 pm」的特例(别人发来的 auto 行 + 手工行都照旧计数)" "$(p364_fn 'team_inbox_new dev2')" "2"
5144
+ # R12:×N 指针行按**它自己的合并键**对账(按文件席位取记录会报假缺口)
5145
+ p364 $TEAM inbox pm --detail >"$TMP/p364-detail-pm.log" 2>&1; P364_RC=$?
5146
+ assert_eq "R12:team inbox pm --detail 退出码 0(×N 指针行不是缺口)" "$P364_RC" "0"
5147
+ assert_has "$TMP/p364-detail-pm.log" "记录 2/2 OK" "R12:指针行的 ×2 按自己的键对账(agent:dev · delivered)"
5148
+ assert_not "$TMP/p364-detail-pm.log" "缺口" "R12:指针行不报缺口"
5149
+ # R10:pm.md 不可写 → pointer=failed、退出码仍 0、记录行照旧落盘
5150
+ P364_R3='2026-10-22T05:47:00.000Z [auto] agent:dev2 · P364 · branch=task/P364-y · uncommitted=0 · unpushed=0 · task=P364 tip=abcdef123456 :: second seat delivered'
5151
+ printf '%s\n' "$P364_R3" > "$TMP/p364-r3.txt"
5152
+ p364 $TEAM __inbox-write --agent dev2 --from-file "$TMP/p364-r3.txt" >/dev/null 2>&1
5153
+ chmod 444 "$P364R/docs/team/inbox/pm.md"
5154
+ p364 $TEAM __notify-settle --agent dev2 --outcome enqueued --record-from-file "$TMP/p364-r3.txt" --task P364 >"$TMP/p364-s3.log" 2>&1; P364_RC=$?
5155
+ chmod 644 "$P364R/docs/team/inbox/pm.md"
5156
+ assert_eq "R10:指针写失败不改变退出码(旁路写)" "$P364_RC" "0"
5157
+ assert_has "$TMP/p364-s3.log" "pointer=failed" "R10:指针写失败被点名(pointer=failed)"
5158
+ assert_eq "R10:指针写失败时 pm.md 一行没多(不谎报已经落盘)" "$(wc -l < "$P364R/docs/team/inbox/pm.md" | tr -d ' ')" "1"
5159
+ assert_eq "R10:指针写失败不影响记录行落盘" "$(grep -c 'task=P364 tip=abcdef123456' "$P364R/docs/team/inbox/dev2.md")" "1"
5160
+ # 没有记录行的 settle(dedup / turn-unfinished / write-failed)不写指针:没有东西可以指
5161
+ p364 $TEAM __notify-settle --agent dev2 --outcome skipped:dedup >"$TMP/p364-s4.log" 2>&1
5162
+ assert_has "$TMP/p364-s4.log" "pointer=none" "P364:没有记录行的 settle 不写指针(pointer=none)"
5163
+ # 读了并按 --ack 标记 → PM 的未读归零(一条 run 回答一次)
5164
+ p364 $TEAM inbox pm --ack >/dev/null 2>&1
5165
+ assert_eq "P364:--ack 之后 PM 的未读归零" "$(p364_fn 'team_inbox_new pm')" "0"
5166
+
5167
+ # ── turn-notice-in-pm-inbox(P365 · A2):结果账 state/notify-knock.log 与 digest 的两行 ──────
5168
+ # 专用夹具仓库:账本、PM 收件箱、ack 基线与前面的段落互不干扰(P364 同款纪律)。
5169
+ # 判据走真 CLI:每次 settle 一行账(先指针、后账本),digest 从**未 ack 的指针行**与账本当前代读两行。
5170
+ P365R="$TMP/p365repo"; rm -rf "$P365R"; mkdir -p "$P365R"
5171
+ ( cd "$P365R" && git init -q -b main && git config user.email smoke@teamsmith && git config user.name smoke \
5172
+ && git commit -q --allow-empty -m init ) >/dev/null 2>&1
5173
+ p365() { ( cd "$P365R" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_SKILL_DIR -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR \
5174
+ TEAM_NOTIFY_LOG="$TMP/p365-notify.log" "$@" ); }
5175
+ p365 $TEAM init --session "teamsmith-smoke-p365-$$" --agents dev,dev2 --vcs local --gates true --docs docs/team "${P235_MODELS[@]}" >"$TMP/p365-init.log" 2>&1 \
5176
+ && ok "P365 夹具仓库 init 成功" || bad "P365 夹具仓库 init 失败(见 $TMP/p365-init.log)"
5177
+ assert_eq "P365 隔离:team paths 的 main_root 就是 P365 夹具仓库" \
5178
+ "$(p365 $TEAM paths 2>/dev/null | sed -n 's/.*"main_root": "\([^"]*\)".*/\1/p')" "$P365R"
5179
+ p365_fn() { # <在夹具仓库里执行的一小段(已加载配置)>
5180
+ ( cd "$P365R" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_SKILL_DIR \
5181
+ bash -c '. "'"$SKILL_DIR"'/scripts/lib/common.sh"; for _f in "'"$SKILL_DIR"'"/scripts/lib/cmd-*.sh; do . "$_f" 2>/dev/null || true; done; team_load_config >/dev/null 2>&1; '"$1" )
5182
+ }
5183
+ P365_LEDGER="$P365R/.pi/team/state/notify-knock.log"
5184
+ P365_R1='2026-10-22T07:00:00.000Z ⚠ 未提交 2 个文件 · [auto] agent:dev · P362 · branch=task/P362-x · uncommitted=2 · unpushed=1(no-upstream) · task=P362 tip=1a2b3c4d5e6f :: delivered one'
5185
+ P365_R1B='2026-10-22T07:01:00.000Z [auto] agent:dev · P362 · branch=task/P362-x · uncommitted=0 · unpushed=0 · task=P362 tip=1a2b3c4d5e6f :: delivered two'
5186
+ P365_R2='2026-10-22T07:02:00.000Z [auto·suspended] agent:dev2 · P363 · branch=task/P363-y · uncommitted=1 · awaiting=job-a'
5187
+ P365_R3='2026-10-22T07:03:00.000Z [auto] agent:dev2 · P364 · branch=task/P364-y · uncommitted=0'
5188
+ P365_R4='2026-10-22T07:04:00.000Z [auto·interrupted] agent:dev2 · P365 · branch=task/P365-y · uncommitted=1'
5189
+ P365_R5='2026-10-22T07:05:00.000Z [auto] agent:dev · P367 · branch=task/P367-z · uncommitted=0 · task=P367 tip=abcdef123456 :: pointer fails'
5190
+ printf '%s\n' "$P365_R1" > "$TMP/p365-r1.txt"
5191
+ printf '%s\n' "$P365_R1B" > "$TMP/p365-r1b.txt"
5192
+ printf '%s\n' "$P365_R2" > "$TMP/p365-r2.txt"
5193
+ printf '%s\n' "$P365_R3" > "$TMP/p365-r3.txt"
5194
+ printf '%s\n' "$P365_R4" > "$TMP/p365-r4.txt"
5195
+ printf '%s\n' "$P365_R5" > "$TMP/p365-r5.txt"
5196
+ p365 $TEAM __inbox-write --agent dev --from-file "$TMP/p365-r1.txt" >"$TMP/p365-w1.log" 2>&1
5197
+ assert_has "$TMP/p365-w1.log" "state=new" "P365 夹具:首事件写下记录行(state=new)"
5198
+ p365 $TEAM __notify-settle --agent dev --outcome enqueued --record-from-file "$TMP/p365-r1.txt" --task P362 --identity 'line|dev|delivered|P362|-|2026-10-22T07:00:00.000Z' >"$TMP/p365-s1.log" 2>&1; P365_RC=$?
5199
+ assert_eq "P365:结果账入口退出码恒 0(旁路写)" "$P365_RC" "0"
5200
+ assert_has "$TMP/p365-s1.log" "pointer=ok" "P365:首次 settle 打印 pointer=ok"
5201
+ assert_has "$TMP/p365-s1.log" "ledger=ok" "P365:首次 settle 打印 ledger=ok"
5202
+ # 同 run 的第二个事件:记录行扩展(state=extended)→ outcome=skipped:merged,仍是**一行账**
5203
+ p365 $TEAM __inbox-write --agent dev --from-file "$TMP/p365-r1b.txt" >"$TMP/p365-w1b.log" 2>&1
5204
+ assert_has "$TMP/p365-w1b.log" "state=extended" "P365 夹具:同 run 第二事件扩展记录行(state=extended)"
5205
+ p365 $TEAM __notify-settle --agent dev --outcome skipped:merged --record-from-file "$TMP/p365-r1b.txt" --task P362 >"$TMP/p365-s1b.log" 2>&1
5206
+ # 另外三个提交路径:挂起 / 关掉 tmux 通知 / 一个闭集外的类
5207
+ p365 $TEAM __inbox-write --agent dev2 --from-file "$TMP/p365-r2.txt" >/dev/null 2>&1
5208
+ p365 $TEAM __notify-settle --agent dev2 --outcome skipped:suspended --record-from-file "$TMP/p365-r2.txt" --task P363 >"$TMP/p365-s2.log" 2>&1
5209
+ p365 $TEAM __inbox-write --agent dev2 --from-file "$TMP/p365-r3.txt" >/dev/null 2>&1
5210
+ p365 $TEAM __notify-settle --agent dev2 --outcome skipped:notify-off --record-from-file "$TMP/p365-r3.txt" --task P364 >"$TMP/p365-s3.log" 2>&1
5211
+ p365 $TEAM __inbox-write --agent dev2 --from-file "$TMP/p365-r4.txt" >/dev/null 2>&1
5212
+ p365 $TEAM __notify-settle --agent dev2 --outcome skipped:something-new --record-from-file "$TMP/p365-r4.txt" --task P365 >"$TMP/p365-s4.log" 2>&1
5213
+ # 没有记录行的 settle(dedup / turn-unfinished / write-failed)也记一行:pointer=none、class=-
5214
+ p365 $TEAM __notify-settle --agent dev2 --outcome skipped:dedup --task P366 >"$TMP/p365-s5.log" 2>&1
5215
+ assert_has "$TMP/p365-s5.log" "pointer=none" "P365:没有记录行的 settle 不写指针(pointer=none)"
5216
+ assert_has "$TMP/p365-s5.log" "ledger=ok" "P365:没有记录行的 settle 仍然记账"
5217
+ # ① 五个真实 outcome 各一行账(字段顺序写死:seat · task · class · outcome · pointer · identity)
5218
+ assert_eq "P365:六个 settle 各一行账(一次 settle 一条,合并/挂起/去重都不漏)" "$(grep -c '^- ' "$P365_LEDGER")" "6"
5219
+ grep 'task=P362 · class=delivered · outcome=enqueued' "$P365_LEDGER" > "$TMP/p365-l-enq.log" 2>/dev/null || true
5220
+ assert_match "$TMP/p365-l-enq.log" '^- [0-9T:.-]+Z seat=dev · task=P362 · class=delivered · outcome=enqueued · pointer=ok · identity=line\|' \
5221
+ "P365:enqueued 的账行字段顺序与行身份(ISO · seat · task · class · outcome · pointer · identity)"
5222
+ grep 'outcome=skipped:merged' "$P365_LEDGER" > "$TMP/p365-l-merged.log" 2>/dev/null || true
5223
+ assert_match "$TMP/p365-l-merged.log" 'seat=dev · task=P362 · class=delivered · outcome=skipped:merged · pointer=ok' \
5224
+ "P365:合并进既有 run 的事件记 skipped:merged(不是没记)"
5225
+ grep 'outcome=skipped:suspended' "$P365_LEDGER" > "$TMP/p365-l-susp.log" 2>/dev/null || true
5226
+ assert_match "$TMP/p365-l-susp.log" 'seat=dev2 · task=P363 · class=suspended · outcome=skipped:suspended · pointer=ok' \
5227
+ "P365:挂起记 skipped:suspended,状态类从记录行的 tag 派生(class=suspended)"
5228
+ grep 'outcome=skipped:notify-off' "$P365_LEDGER" > "$TMP/p365-l-off.log" 2>/dev/null || true
5229
+ assert_match "$TMP/p365-l-off.log" 'seat=dev2 · task=P364 · class=delivered · outcome=skipped:notify-off · pointer=ok' \
5230
+ "P365:TEAM_NOTIFY_TMUX=0 记 skipped:notify-off"
5231
+ grep 'outcome=skipped:dedup' "$P365_LEDGER" > "$TMP/p365-l-dedup.log" 2>/dev/null || true
5232
+ assert_match "$TMP/p365-l-dedup.log" 'seat=dev2 · task=P366 · class=- · outcome=skipped:dedup · pointer=none · identity=-' \
5233
+ "P365:没有记录行的 settle 用 pointer=none / class=- / identity=- 记账"
5234
+ # ② 闭集外的类**原样**落账,读侧(digest)也原样打印 —— 不吞不丢
5235
+ assert_has "$P365_LEDGER" "outcome=skipped:something-new" "P365:闭集外的类原样落账"
5236
+ # ③ digest 的两行:3 条未敲门(挂起 / notify-off / 闭集外)——一条 run 一条
5237
+ p365 $TEAM digest >"$TMP/p365-digest1.log" 2>&1 || bad "P365:digest 失败"
5238
+ assert_has "$TMP/p365-digest1.log" "未敲门 3 条已记录的通知没有叫醒 PM(suspended 1 · notify-off 1 · 其它(something-new 1))" \
5239
+ "P365:未敲门按类分组(闭集外的类显示成 其它(原样))"
5240
+ assert_not "$TMP/p365-digest1.log" "指针缺失" "P365:还没有指针失败时不打印「指针缺失」"
5241
+ # 两行**只显示**:不进待办计数(不进 team_pending_text → 不进叫醒理由)
5242
+ assert_not_echo "$(p365_fn 'team_pending_text')" "未敲门" "P365:未敲门不进待办计数(挂起只记录不叫醒的裁定不被显示层推翻)"
5243
+ assert_not_echo "$(p365_fn 'team_pending_text')" "指针缺失" "P365:指针缺失不进待办计数(不会每一拍都叫醒一次)"
5244
+ # ④ R10:PM 收件箱不可写 → 指针失败被点名,而且账本带得上 pointer=failed
5245
+ p365 $TEAM __inbox-write --agent dev --from-file "$TMP/p365-r5.txt" >/dev/null 2>&1
5246
+ chmod 444 "$P365R/docs/team/inbox/pm.md"
5247
+ p365 $TEAM __notify-settle --agent dev --outcome enqueued --record-from-file "$TMP/p365-r5.txt" --task P367 >"$TMP/p365-s6.log" 2>&1; P365_RC=$?
5248
+ chmod 644 "$P365R/docs/team/inbox/pm.md"
5249
+ assert_eq "P365/R10:指针写失败不改变退出码" "$P365_RC" "0"
5250
+ assert_has "$TMP/p365-s6.log" "pointer=failed" "P365/R10:指针写失败被点名"
5251
+ assert_has "$P365_LEDGER" "task=P367 · class=delivered · outcome=enqueued · pointer=failed" "P365/R10:先指针后账本 —— 账行带得上 pointer=failed"
5252
+ p365 $TEAM digest >"$TMP/p365-digest2.log" 2>&1 || bad "P365:digest(指针失败)失败"
5253
+ assert_has "$TMP/p365-digest2.log" "指针缺失 1 条通知没有写进 PM 收件箱(pointer-write-failed;state/notify-knock.log 当前代,更早的代不计)" \
5254
+ "P365:指针缺失从账本当前代读出并点名文件"
5255
+ assert_has "$TMP/p365-digest2.log" "未敲门 3 条已记录的通知没有叫醒 PM" "P365:两行各自独立(指针失败不改「未敲门」的读数)"
5256
+ # ⑤ R9:读了并按 --ack 标记 → 「未敲门」消失;「指针缺失」不随阅读消失(它没有可读可 ack 的行)
5257
+ p365 $TEAM inbox pm --ack >/dev/null 2>&1
5258
+ p365 $TEAM digest >"$TMP/p365-digest3.log" 2>&1 || bad "P365:digest(ack 后)失败"
5259
+ assert_not "$TMP/p365-digest3.log" "未敲门" "P365/R9:ack 之后「未敲门」消失(它数的是尚未被回答的指针行)"
5260
+ assert_has "$TMP/p365-digest3.log" "指针缺失 1 条通知没有写进 PM 收件箱" "P365/R9:指针缺失仍然在(账本不随 ack 变)"
5261
+ # ⑥ 有界:把上限调小(测试内)→ 产生 .1,账本本身不超上限,轮转在扩展日志里点名
5262
+ rm -f "$P365_LEDGER" "$P365_LEDGER.1" "$TMP/p365-notify.log"
5263
+ for _i in 1 2 3 4; do
5264
+ p365 env TEAM_NOTIFY_DETAIL_MAX=2 $TEAM __notify-settle --agent dev --outcome skipped:dedup --task "P37$_i" >/dev/null 2>&1
5265
+ done
5266
+ assert_file "$P365_LEDGER.1" "P365:越界后产生一代 .1(只留一代)"
5267
+ assert_eq "P365:账本当前代不超过上限(2 条记录 + 1 行轮转头)" "$(wc -l < "$P365_LEDGER" | tr -d ' ')" "3"
5268
+ assert_eq "P365:当前代的记录数就是上限" "$(grep -c '^- ' "$P365_LEDGER")" "2"
5269
+ head -n 1 "$P365_LEDGER" > "$TMP/p365-rot-head.log"
5270
+ assert_match "$TMP/p365-rot-head.log" '^# rotation .* moved=2 path=.*/state/notify-knock\.log\.1$' \
5271
+ "P365:轮转头点名时间、被移动的条数与 .1 路径"
5272
+ assert_eq "P365:被轮转出去的那一代就是老的两条" "$(grep -c '^- ' "$P365_LEDGER.1")" "2"
5273
+ assert_has "$TMP/p365-notify.log" "notify knock rotated" "P365:轮转在扩展日志里点名(不是静默丢)"
5274
+ # 轮转之后「指针缺失」只算当前代:老的那代不计(账本的窗口就是它自己)
5275
+ p365 $TEAM digest >"$TMP/p365-digest4.log" 2>&1 || true
5276
+ assert_not "$TMP/p365-digest4.log" "指针缺失" "P365:轮转后旧的 pointer=failed 不再计入(当前代才是账本的窗口)"
5277
+ # ⑦ 两行都可以清掉:清账本 + ack 后,两行一起消失
5278
+ rm -f "$P365_LEDGER" "$P365_LEDGER.1"
5279
+ p365 $TEAM digest >"$TMP/p365-digest5.log" 2>&1 || true
5280
+ assert_not "$TMP/p365-digest5.log" "未敲门" "P365:清掉之后「未敲门」不再打印"
5281
+ assert_not "$TMP/p365-digest5.log" "指针缺失" "P365:清掉之后「指针缺失」不再打印"
5282
+
5283
+ # ── notice-fulltext-and-asks(P370 C):指针行复制 asks= / digest 的「待回答」一行 ─────────────
5284
+ # 判据:范围 = 未 ack 的**指针行**里 asks>=1 的那些,一条 run 算一条(不按事件数),ack 后归零;
5285
+ # 只显示 —— 不进 team_pending_text(那行通知本身已经在唤醒判据里,再加一条等于对同一件事敲两次)。
5286
+ P370_A='2026-10-22T09:00:00.000Z [auto] agent:dev · P370 · branch=task/P370-x · uncommitted=0 · task=P370 tip=0123456789ab · asks=1 :: 两点请裁决:① 合并 ② 分支'
5287
+ P370_B='2026-10-22T09:01:00.000Z [auto] agent:dev · P370 · branch=task/P370-x · uncommitted=0 · task=P370 tip=0123456789ab · asks=1 :: 同一个 run 的第二个事件'
5288
+ P370_C='2026-10-22T09:02:00.000Z [auto] agent:dev2 · P371 · branch=task/P371-y · uncommitted=0 · task=P371 tip=abcdef123456 · asks=2 :: 另外两件也等你确认'
5289
+ printf '%s\n' "$P370_A" > "$TMP/p370-a.txt"
5290
+ printf '%s\n' "$P370_B" > "$TMP/p370-b.txt"
5291
+ printf '%s\n' "$P370_C" > "$TMP/p370-c.txt"
5292
+ p365 $TEAM __inbox-write --agent dev --from-file "$TMP/p370-a.txt" >/dev/null 2>&1
5293
+ p365 $TEAM __notify-settle --agent dev --outcome enqueued --record-from-file "$TMP/p370-a.txt" --task P370 >/dev/null 2>&1
5294
+ assert_eq "P370:记录行带 asks=(事件级字段在字段区里)" \
5295
+ "$(printf '%s' "$(tail -n 1 "$P365R/docs/team/inbox/dev.md")" | grep -o 'asks=[0-9]*')" "asks=1"
5296
+ assert_eq "P370:指针行复制了 asks=(PM 读的是 pm.md)" \
5297
+ "$(printf '%s' "$(tail -n 1 "$P365R/docs/team/inbox/pm.md")" | grep -o 'asks=[0-9]*')" "asks=1"
5298
+ p365 $TEAM digest >"$TMP/p370-digest1.log" 2>&1 || bad "P370:digest 失败"
5299
+ assert_has "$TMP/p370-digest1.log" "待回答 1 条完成消息里有待你回答的问题(agent:dev · P370 · asks=1)" \
5300
+ "P370:digest 点名未答的完成消息(发送者 · 任务 · 计数)"
5301
+ assert_has "$TMP/p370-digest1.log" "team inbox pm 读原文" "P370:这一行给出读全文的命令"
5302
+ assert_not_echo "$(p365_fn 'team_pending_text')" "待回答" "P370:待回答只显示、不进唤醒判据(不把同一件事敲两次)"
5303
+ # 同 run 的第二个事件(×2)仍然只算**一条**:按事件数算的实现会读到 2
5304
+ p365 $TEAM __inbox-write --agent dev --from-file "$TMP/p370-b.txt" >/dev/null 2>&1
5305
+ p365 $TEAM __notify-settle --agent dev --outcome skipped:merged --record-from-file "$TMP/p370-b.txt" --task P370 >/dev/null 2>&1
5306
+ assert_has_echo "$(tail -n 1 "$P365R/docs/team/inbox/pm.md")" "×2" "P370 夹具:同 run 的第二个事件并进同一行指针"
5307
+ p365 $TEAM digest >"$TMP/p370-digest2.log" 2>&1 || true
5308
+ assert_has "$TMP/p370-digest2.log" "待回答 1 条完成消息" "P370:合并 run(×2)只算一条(按事件数算会红)"
5309
+ # 另一个席位的第二条:点名最多 3 条,顺序就是文件顺序
5310
+ p365 $TEAM __inbox-write --agent dev2 --from-file "$TMP/p370-c.txt" >/dev/null 2>&1
5311
+ p365 $TEAM __notify-settle --agent dev2 --outcome enqueued --record-from-file "$TMP/p370-c.txt" --task P371 >/dev/null 2>&1
5312
+ p365 $TEAM digest >"$TMP/p370-digest3.log" 2>&1 || true
5313
+ assert_has "$TMP/p370-digest3.log" "待回答 2 条完成消息里有待你回答的问题(agent:dev · P370 · asks=1;agent:dev2 · P371 · asks=2)" \
5314
+ "P370:两条未答的完成消息各自点名(含各自的 asks 计数)"
5315
+ # 没有 asks 的指针行不算:加一条普通指针,计数不变、名单里也不该出现它
5316
+ printf '%s\n' '2026-10-22T09:03:00.000Z [auto] agent:dev2 · P372 · branch=task/P372-z · uncommitted=0 · task=P372 tip=1234567890ab :: 纯汇报' > "$TMP/p370-d.txt"
5317
+ p365 $TEAM __inbox-write --agent dev2 --from-file "$TMP/p370-d.txt" >/dev/null 2>&1
5318
+ p365 $TEAM __notify-settle --agent dev2 --outcome enqueued --record-from-file "$TMP/p370-d.txt" --task P372 >/dev/null 2>&1
5319
+ p365 $TEAM digest >"$TMP/p370-digest4.log" 2>&1 || true
5320
+ assert_has "$TMP/p370-digest4.log" "待回答 2 条完成消息" "P370:多一条无问的指针不改计数"
5321
+ grep '待回答' "$TMP/p370-digest4.log" > "$TMP/p370-asked4.log" 2>/dev/null || true
5322
+ assert_not "$TMP/p370-asked4.log" "P372" "P370:没有 asks 的指针行不进「待回答」名单"
5323
+ # ack 之后归零(与「未敲门」同一个已读通道)
5324
+ p365 $TEAM inbox pm --ack >/dev/null 2>&1
5325
+ p365 $TEAM digest >"$TMP/p370-digest5.log" 2>&1 || true
5326
+ assert_not "$TMP/p370-digest5.log" "待回答" "P370:--ack 之后「待回答」归零(数的是还没被回答的量)"
5327
+
5051
5328
  # ----------------------------------------- 7b. digest 警告未入账的复验/报告记录(M31)
5052
5329
  section "7b · digest 警告未入账的复验/报告记录(M31)"
5053
5330
  # 专用夹具仓库(M16/M14 同款纪律):这里的「干净」是真干净。主夹具仓库在 4b 留下了
@@ -6010,6 +6287,17 @@ elif [ "$HAVE_TMUX" = "1" ]; then
6010
6287
  esac
6011
6288
  M65_PID="$(cat "$REPO/.pi/team/state/pm.pid" 2>/dev/null | tr -dc '0-9')"
6012
6289
  if [ -n "$M65_PID" ] && kill -0 "$M65_PID" 2>/dev/null; then ok "M6.5 ①:state/pm.pid 记录了活着的 PM pid"; else bad "M6.5 ①:state/pm.pid 缺失或指向死进程([$M65_PID])"; fi
6290
+ # ①c P376:PM 窗口建不出来时**不许报成功**(V60 R2:`|| true` 之后一行无条件打「✓ 创建 PM 窗口」,
6291
+ # 窗口根本不存在)。现场 = TMUX_TMPDIR 指向**普通文件**:真 tmux 直接报错起不了 server,也不会回退
6292
+ # 默认 socket,所以这条探针碰不到本轮的私有现场。TMUX/TMUX_PANE 要摘掉 —— 有它们在时 tmux 用那条
6293
+ # socket,TMUX_TMPDIR 根本不参与判定(「人在窗口外跑 team up」本来就没有 TMUX)。
6294
+ printf 'not a directory\n' > "$TMP/p376-notadir"
6295
+ ( cd "$REPO" && env -u TMUX -u TMUX_PANE TMUX_TMPDIR="$TMP/p376-notadir" $TEAM up ) >"$TMP/up-badtmux.log" 2>&1; RC_BADTMUX=$?
6296
+ assert_eq "P376:PM 窗口建不出来时 up 退非 0(失败不许看起来成功)" \
6297
+ "$([ "$RC_BADTMUX" -ne 0 ] && echo nonzero || echo zero)" "nonzero"
6298
+ assert_not "$TMP/up-badtmux.log" "创建 PM 窗口 $SESSION:$PMW" "P376:窗口没建出来时不打印成功行"
6299
+ assert_has "$TMP/up-badtmux.log" "创建 PM 窗口失败($SESSION:$PMW" "P376:失败行点名目标窗口"
6300
+ assert_has "$TMP/up-badtmux.log" "$TMP/p376-notadir" "P376:失败保留 tmux 自己的诊断(坏路径原样上屏)"
6013
6301
  # ①b 复现 PM 报告的确切格子(thread 第 2/3 条):cwd 在项目内 + 前台进程名是 `tmux`。
6014
6302
  # 老规则(窗口在 + 前台不是 shell)在这里就会输出 `running:tmux`;新规则必须报 unknown/idle
6015
6303
  # 且 up 真的把 PM 拉起来(argv 日志里出现 -c 与 @pm-prompt.md)。
@@ -7212,8 +7500,12 @@ doc_stale_hits() { # <skill 目录>
7212
7500
  done
7213
7501
  }
7214
7502
 
7215
- # P16:扫描范围是两个 skill 的读者面(拆分前只有日常 skill)。
7216
- REAL_HITS="$(doc_stale_hits "$SKILL_DIR"; doc_stale_hits "$SKILL_INIT_DIR")"
7503
+ # P16/P361:扫描范围是每个随包 skill 的读者面(清单从源派生:以后加技能自动进来)。
7504
+ REAL_HITS=""
7505
+ while IFS= read -r SC_SD; do
7506
+ [ -n "$SC_SD" ] || continue
7507
+ REAL_HITS="$REAL_HITS$(doc_stale_hits "$SC_SD")"
7508
+ done <<< "$(skill_src_dirs)"
7217
7509
  if [ -n "$REAL_HITS" ]; then
7218
7510
  bad "真树里有已删命令的用法:$(printf '%s' "$REAL_HITS" | head -1)"
7219
7511
  else
@@ -7661,6 +7953,15 @@ if (!lines[0].includes('agent:dev')) { console.error('FAIL: agent 名推断错
7661
7953
  rmSync(inbox, { force: true })
7662
7954
  rmSync(join(root, '.pi/team/state/notify-dedup'), { force: true })
7663
7955
  rmSync(join(root, '.pi/team/state/notify.log'), { force: true })
7956
+ // turn-notice-in-pm-inbox(P364 A1):PM 的指针行也从这个干净的现场开始
7957
+ const pmInbox = join(root, 'docs/team/inbox/pm.md')
7958
+ rmSync(pmInbox, { force: true })
7959
+ // P365 A2:结果账同理 —— 从空的现场开始,下面逐条断言「一次 settle 一行」与字段
7960
+ const ledgerPath = join(root, '.pi/team/state/notify-knock.log')
7961
+ rmSync(ledgerPath, { force: true })
7962
+ const ledger = () => existsSync(ledgerPath)
7963
+ ? readFileSync(ledgerPath, 'utf8').split('\n').filter(l => l.startsWith('- ')) : []
7964
+ const pmLines = () => existsSync(pmInbox) ? readFileSync(pmInbox, 'utf8').trim().split('\n').filter(Boolean) : []
7664
7965
  const prefix = 'All gates are green. I delivered the parser fix; the remaining work on this branch is'
7665
7966
  const ctxN = (text) => ({ cwd: wt, sessionManager: { getEntries: () => [{ message: { role: 'assistant', stopReason: 'stop', content: [{ text }] } }] } })
7666
7967
  const recs = () => existsSync(join(root, '.pi/team/state/notify.log'))
@@ -7669,10 +7970,127 @@ if (!lines[0].includes('agent:dev')) { console.error('FAIL: agent 名推断错
7669
7970
  const ls = readFileSync(inbox, 'utf8').trim().split('\n')
7670
7971
  if (ls.length !== 1 || !ls[0].includes('×3')) { console.error(`FAIL: F17 同 run 的三条简报应当合成一行 ×3(实际 ${ls.length} 行:${ls[0] ?? ''})`); process.exit(20) }
7671
7972
  if (recs() !== 3) { console.error(`FAIL: F17 三条简报的原始记录没有全进明细(${recs()} 条)`); process.exit(22) }
7973
+ // P364 A1:同 run 的三个事件在 PM 的收件箱里是**一行 ×3 指针** —— 由写入侧从记录行派生(不带摘要与
7974
+ // 事件级字段),扩展在本夹具里没有 tmux → outcome = skipped:no-pane。
7975
+ {
7976
+ const pl = pmLines()
7977
+ if (pl.length !== 1) { console.error(`FAIL: P364 指针行:pm.md 应为 1 行(实际 ${pl.length})`); process.exit(40) }
7978
+ if (!pl[0].includes('agent:dev')) { console.error(`FAIL: P364 指针行没点名发送者(${pl[0]})`); process.exit(41) }
7979
+ if (!pl[0].includes('knock=skipped:no-pane')) { console.error(`FAIL: P364 指针行没记下叫醒结果(${pl[0]})`); process.exit(42) }
7980
+ if (!pl[0].includes('see=docs/team/inbox/dev.md')) { console.error(`FAIL: P364 指针行没指回记录(${pl[0]})`); process.exit(43) }
7981
+ if (!pl[0].includes('×3')) { console.error(`FAIL: P364 指针行没合并成 ×3(${pl[0]})`); process.exit(44) }
7982
+ if (pl[0].includes(' :: ') || pl[0].includes('branch=') || pl[0].includes('uncommitted=') || pl[0].includes('⚠')) {
7983
+ console.error(`FAIL: P364 指针行带了摘要/事件级字段/⚠ 前缀(${pl[0]})`); process.exit(45)
7984
+ }
7985
+ }
7986
+ // P365 A2 / R8:每个 settle 都进结果账(这里没有 tmux → skipped:no-pane),指针成功、
7987
+ // 状态类从记录行的 tag 派生([auto] → delivered),行身份是 line|<席位|类|任务|awaiting>|<首事件 ISO>。
7988
+ {
7989
+ const lg = ledger()
7990
+ if (lg.length !== 3) { console.error(`FAIL: P365 结果账:三个 settle 应各记一行(实际 ${lg.length}:${lg.join(' | ')})`); process.exit(47) }
7991
+ if (!lg.every(l => l.includes('seat=dev') && l.includes('class=delivered') && l.includes('pointer=ok') && l.includes('identity=line|'))) {
7992
+ console.error(`FAIL: P365 结果账:settle 的公共字段不对(${lg.join(' | ')})`); process.exit(48)
7993
+ }
7994
+ // 三个同 run 事件:首事件没敲(no-pane),后两个并入既有 run(skipped:merged)—— 三种 outcome
7995
+ // 各自都要有账,不能只记首事件。
7996
+ if (!lg[0].includes('outcome=skipped:no-pane') || !lg[1].includes('outcome=skipped:merged') || !lg[2].includes('outcome=skipped:merged')) {
7997
+ console.error(`FAIL: P365 结果账:三个事件的 outcome 序列不对(${lg.map(l => (/outcome=(\S+)/.exec(l) ?? [])[1]).join(',')})`); process.exit(51)
7998
+ }
7999
+ }
7672
8000
  await handler({}, ctxN(prefix + ' the retry path.')) // 字节相同的一条:仍然要抑制
7673
8001
  const ls2 = readFileSync(inbox, 'utf8').trim().split('\n')
7674
8002
  if (ls2.length !== 1 || !ls2[0].includes('×3')) { console.error(`FAIL: F17 重复的同一条没有被去重(${ls2.length} 行)`); process.exit(21) }
7675
8003
  if (recs() !== 3) { console.error(`FAIL: F17 被去重的重复条进了明细(${recs()} 条)`); process.exit(23) }
8004
+ // 去重的 settle 没有记录行可指 → 一行指针都不写(DEDUP 不是一次新的通知)
8005
+ if (pmLines().length !== 1) { console.error(`FAIL: P364 去重的 settle 写了指针(pm.md ${pmLines().length} 行)`); process.exit(46) }
8006
+ // P365 A2:被去重的那次 settle 仍然是**一次 settle** —— 账本要给它一行(pointer=none、identity=-),
8007
+ // 否则「为什么今天没收到通知」在账本里是个洞。
8008
+ {
8009
+ const lg = ledger()
8010
+ if (lg.length !== 4) { console.error(`FAIL: P365 结果账:去重的 settle 也应当记账(实际 ${lg.length} 行)`); process.exit(49) }
8011
+ const last = lg[3]
8012
+ if (!last.includes('outcome=skipped:dedup') || !last.includes('pointer=none') || !last.includes('identity=-')) {
8013
+ console.error(`FAIL: P365 结果账:去重那一行的字段不对(${last})`); process.exit(50)
8014
+ }
8015
+ }
8016
+ }
8017
+ // ── notice-fulltext-and-asks(P370 A/C)· 记录存全文 / 硬上限具名 / asks 可数 ────────────────────
8018
+ // 判据全部走真扩展 + 真 CLI:先前实现在算出末消息的那一行就 `tail(messageText, maxChars)` 裁掉,
8019
+ // 于是收件箱行与 state/notify.log 明细在**写入时**就丢了内容,而文本里的 `…` 与模型自己写的省略号
8020
+ // 无法区分(P365 现场:PM 收到的交付末尾「两点请裁决:①…②…」被截掉,通知没说它被截掉)。
8021
+ {
8022
+ const stateDir = join(root, '.pi/team/state')
8023
+ const detailFile = join(stateDir, 'notify.log')
8024
+ const pmInbox = join(root, 'docs/team/inbox/pm.md')
8025
+ const reset = () => { for (const f of [inbox, pmInbox, detailFile, join(stateDir, 'notify-dedup')]) rmSync(f, { force: true }) }
8026
+ const ctxOf = (text) => ({ cwd: wt, sessionManager: { getEntries: () => [{ message: { role: 'assistant', stopReason: 'stop', content: [{ text }] } }] } })
8027
+ const recLines = () => existsSync(inbox) ? readFileSync(inbox, 'utf8').split('\n').filter(l => l.startsWith('- ')) : []
8028
+ const pmLines = () => existsSync(pmInbox) ? readFileSync(pmInbox, 'utf8').split('\n').filter(l => l.startsWith('- ')) : []
8029
+ const details = () => existsSync(detailFile) ? readFileSync(detailFile, 'utf8').split('\n').filter(l => l.startsWith('- ')) : []
8030
+ const fieldOf = (line) => line.split(' :: ')[0] ?? line
8031
+ const bodyOf = (line) => line.split(' :: ')[1] ?? ''
8032
+ const bytes = (s) => Buffer.byteLength(s, 'utf8')
8033
+ const fail = (msg) => { console.error(`FAIL: ${msg}`); process.exit(60) }
8034
+ let seq = 0
8035
+ // 每个用例前插一条手工行,把合并 run 断开(否则同 run 的事件会并成 ×N,读到的只是最后一次的值)
8036
+ const settle = async (text) => {
8037
+ writeFileSync(inbox, `- ${new Date().toISOString()} [manual] agent:dev · P370 separator ${++seq}\n`, { flag: 'a' })
8038
+ await handler({}, ctxOf(text))
8039
+ return { rec: recLines().at(-1) ?? '', ptr: pmLines().at(-1) ?? '' }
8040
+ }
8041
+
8042
+ // ① 全文:一条 4 KB 级交付,收件箱行与明细都**一个字节都不少**
8043
+ reset()
8044
+ const msg4k = 'HEAD-4K-' + 'x'.repeat(4071) + '-TAIL-4K' // 4087 B,纯 ASCII(字数 = 字节数)
8045
+ let r = await settle(msg4k)
8046
+ if (bodyOf(r.rec) !== msg4k) fail(`P370 ①:记录行没有存全文(${bytes(bodyOf(r.rec))}B ≠ ${bytes(msg4k)}B)`)
8047
+ if (bodyOf(details().at(-1) ?? '') !== msg4k) fail('P370 ①:notify.log 明细没有存全文')
8048
+ if (fieldOf(r.rec).includes('truncated=')) fail('P370 ①:4 KB 的正常消息不该触发任何截断标记')
8049
+ if (fieldOf(r.rec).includes('asks=')) fail('P370 ①:没有裁决标记的消息不该带 asks=')
8050
+ console.log(`P370 ①全文:record=${bytes(bodyOf(r.rec))}B detail=${bytes(bodyOf(details().at(-1) ?? ''))}B head=${JSON.stringify(bodyOf(r.rec).slice(0, 40))} tail=${JSON.stringify(bodyOf(r.rec).slice(-40))}`)
8051
+
8052
+ // ② 硬上限:200000 B → 正好留 65536 B,字段区具名,且**不带** full=(那份原文不在任何地方)
8053
+ reset()
8054
+ const huge = 'h'.repeat(200000)
8055
+ r = await settle(huge)
8056
+ if (bytes(bodyOf(r.rec)) !== 65536) fail(`P370 ②:200000B 的末消息应当只留 65536 字节(实际 ${bytes(bodyOf(r.rec))}B)`)
8057
+ if (!fieldOf(r.rec).includes('truncated=hard-limit:65536/200000B')) fail(`P370 ②:硬上限没有具名(${fieldOf(r.rec)})`)
8058
+ if (fieldOf(r.rec).includes('full=')) fail('P370 ②:硬上限标记带了 full=(原文不存在,定位是谎言)')
8059
+ const dh = details().at(-1) ?? ''
8060
+ if (bodyOf(dh) !== bodyOf(r.rec) || !fieldOf(dh).includes('truncated=hard-limit:65536/200000B')) {
8061
+ fail('P370 ②:明细记录的切法与标记与记录行不一致')
8062
+ }
8063
+ console.log(`P370 ②硬上限:kept=${bytes(bodyOf(r.rec))}B of ${bytes(huge)}B field=${JSON.stringify(fieldOf(r.rec).split(' · ').at(-1))}`)
8064
+ // 字符边界:30000 个「中」(90000 B)→ 留 65535 B(21845 个完整字符),不写出半个 UTF-8 序列
8065
+ const cjk = '中'.repeat(30000)
8066
+ r = await settle(cjk)
8067
+ if (bodyOf(r.rec) !== '中'.repeat(21845)) fail(`P370 ②:多字节消息的切点不在字符边界上(${bytes(bodyOf(r.rec))}B)`)
8068
+ if (!fieldOf(r.rec).includes('truncated=hard-limit:65535/90000B')) fail(`P370 ②:多字节的 kept 字节数不对(${fieldOf(r.rec)})`)
8069
+ // 上限必须高到**不碰正常消息**:20 KB 照旧全文(把上限改成 16 KiB 的实现会在这里红)
8070
+ const msg20k = 'k'.repeat(20480)
8071
+ r = await settle(msg20k)
8072
+ if (bodyOf(r.rec) !== msg20k || fieldOf(r.rec).includes('truncated=')) fail('P370 ②:20 KB 的正常消息被剪了(上限低到碰正常消息)')
8073
+
8074
+ // ③ asks:闭集标记 + 末尾 400 字窗口 + 最长优先/不重叠 + ASCII 折叠;缺席即不写字段
8075
+ const askCases = [
8076
+ ['两点请裁决:① 合并?② 分支?', '1'],
8077
+ ['收尾:请你确认,请确认', '2'],
8078
+ ['请你确认一下,另外等你拍板', '2'],
8079
+ ['这样行吗?那这样呢?还有别的问题吗?', ''],
8080
+ ['请裁决。' + 'x'.repeat(500) + ' 后面都是纯汇报,没有别的事。', ''],
8081
+ ['Done. Please Confirm the merge.', '1'],
8082
+ ]
8083
+ const seen = []
8084
+ for (const [text, want] of askCases) {
8085
+ r = await settle(text)
8086
+ const got = /asks=(\d+)/.exec(fieldOf(r.rec))?.[1] ?? ''
8087
+ const gotPtr = /asks=(\d+)/.exec(fieldOf(r.ptr))?.[1] ?? ''
8088
+ if (got !== want) fail(`P370 ③:记录行 asks 期望 ${want || '缺'}、实际 ${got || '缺'}(${text})`)
8089
+ if (gotPtr !== want) fail(`P370 ③:指针行 asks 期望 ${want || '缺'}、实际 ${gotPtr || '缺'}(${text})`)
8090
+ if (!want && (r.rec.includes('asks=0') || r.ptr.includes('asks=0'))) fail('P370 ③:不许写 asks=0(缺席与空值是两个不同的值)')
8091
+ seen.push(`${want || '缺'}`)
8092
+ }
8093
+ console.log(`P370 ③asks:${askCases.length} 条用例读数 ${seen.join('/')}(1/2/2/缺/缺/1)`)
7676
8094
  }
7677
8095
  // M40:继承来的 TEAM_ROOT 指到**工作树**(agent 工作树里有 config.sh 副本)也不许改变账本落点:回合通知
7678
8096
  // 必须照旧写主工作树的收件箱。旧实现 env 优先 → cwd 被判成「不在 worktrees 之下」→ 整个通知静默不发
@@ -7749,7 +8167,7 @@ EOF
7749
8167
  chmod +x "$TMP/ext-shim/tmux"
7750
8168
  : > "$TMP/ext-tmux.log"
7751
8169
  cat > "$TMP/ext-e-test.mjs" <<'EOF'
7752
- import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
8170
+ import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
7753
8171
  import { join } from 'node:path'
7754
8172
  const [, , ext, root, wt] = process.argv
7755
8173
  process.env.TMUX_PANE = 'smoke-fake-pane' // 有 pane 才会走“敲门”那条路
@@ -7765,7 +8183,10 @@ const emit = async (name, ...args) => { for (const fn of handlers[name] ?? []) a
7765
8183
  const inbox = join(root, 'docs/team/inbox/dev.md')
7766
8184
  const dedup = join(root, '.pi/team/state/notify-dedup')
7767
8185
  const knockLog = process.env.EXT_TMUX_LOG
7768
- const reset = () => { rmSync(inbox, { force: true }); rmSync(dedup, { force: true }); writeFileSync(knockLog, '') }
8186
+ // turn-notice-in-pm-inbox(P364 A1):每个 E 用例也从空的 PM 收件箱开始(指针行的现场)。
8187
+ const pmInbox = join(root, 'docs/team/inbox/pm.md')
8188
+ const pmLines = () => existsSync(pmInbox) ? readFileSync(pmInbox, 'utf8').trim().split('\n').filter(Boolean) : []
8189
+ const reset = () => { rmSync(inbox, { force: true }); rmSync(pmInbox, { force: true }); rmSync(dedup, { force: true }); writeFileSync(knockLog, '') }
7769
8190
  const cx = (list) => ({ cwd: wt, sessionManager: { getEntries: () => list.map(m => ({ message: m })) } })
7770
8191
  const lines = () => existsSync(inbox) ? readFileSync(inbox, 'utf8').trim().split('\n').filter(Boolean) : []
7771
8192
  const knocks = () => readFileSync(knockLog, 'utf8').split('\n').filter(l => l.includes('send-keys')).length
@@ -7781,6 +8202,7 @@ await emit('session_compact', { type: 'session_compact', reason: 'threshold' },
7781
8202
  await emit('agent_settled', {}, cx([earlier, midTurn]))
7782
8203
  if (lines().length !== 0) fail('E1:内部生命周期中的 settle 仍写了收件箱')
7783
8204
  if (knocks() !== 0) fail('E1:内部生命周期中的 settle 仍在敲 PM 窗口')
8205
+ if (pmLines().length !== 0) fail('E1:回合未完成的 settle 写了指针行(turn-unfinished 没有记录可指)')
7784
8206
  console.log('E1 回合内重启/压缩:没有收件箱行、没有敲门')
7785
8207
 
7786
8208
  // E2(对照组):同一回合里压缩过,但回合真的完成 → 照常一行 + 敲门(不许过度抑制)
@@ -7793,6 +8215,24 @@ if (ls.length !== 1) fail(`E2:完成的回合应当只有一行(实际 ${ls.
7793
8215
  if (!ls[0].includes('[auto]')) fail('E2:完成的回合应带 [auto] 标签')
7794
8216
  if (!ls[0].includes('M43-DONE genuine turn end')) fail('E2:完成的回合应带它的最终文本')
7795
8217
  if (knocks() < 1) fail('E2:完成的回合应敲 PM 窗口(对照组)')
8218
+ // P364 A1:交付在 PM 的收件箱里留下一条**指针行**,并记下这次叫醒的结果
8219
+ {
8220
+ const pl = pmLines()
8221
+ if (pl.length !== 1) fail(`E2:交付应在 pm.md 留下 1 行指针(实际 ${pl.length})`)
8222
+ if (!pl[0].includes('knock=enqueued')) fail(`E2:指针行没有记下 enqueued(${pl[0]})`)
8223
+ if (!pl[0].includes('see=docs/team/inbox/dev.md')) fail(`E2:指针行没指回记录(${pl[0]})`)
8224
+ }
8225
+ // R4:同 run 的扩展事件(state=extended → skipped:merged)不得改写 run 级字段 knock=,也不得再敲一次
8226
+ {
8227
+ const k_before = knocks()
8228
+ const finalAns2 = { role: 'assistant', stopReason: 'stop', content: [{ text: 'M43-DONE second event, same run' }] }
8229
+ await emit('agent_settled', {}, cx([midTurn, finalAns2]))
8230
+ const pl = pmLines()
8231
+ if (pl.length !== 1) fail(`R4:同 run 的扩展事件应并入一行(pm.md 现有 ${pl.length} 行)`)
8232
+ if (!pl[0].includes('knock=enqueued')) fail(`R4:扩展事件把 run 级 knock= 改写成了 skipped:merged(${pl[0]})`)
8233
+ if (!pl[0].includes('×2')) fail(`R4:同 run 的扩展事件没有合并成 ×2(${pl[0]})`)
8234
+ if (knocks() !== k_before) fail('R4:扩展事件又敲了一次 PM 窗口(计数抖动不得叫醒)')
8235
+ }
7796
8236
  console.log('E2 压缩过但已完成:一行 + 敲门(对照组)')
7797
8237
 
7798
8238
  // E3:被中断(Esc/错误)且没有生命周期事件 → 仍然告诉 PM,但绝不带摘要文本
@@ -7803,6 +8243,13 @@ ls = lines()
7803
8243
  if (ls.length !== 1) fail(`E3:被中断的回合仍应告诉 PM(期望 1 行,实际 ${ls.length})`)
7804
8244
  if (!ls[0].includes('[auto·interrupted]')) fail('E3:被中断的回合必须显式标记,不能冒充交付')
7805
8245
  if (ls[0].includes('EARLIER-DELIVERED-TEXT') || ls[0].includes("I'll start by reading")) fail('E3:不许拿未完成回合的文本当摘要')
8246
+ // P364 A1:中断也是要告诉 PM 的事 → 指针行同样落盘(它照样会叫醒)
8247
+ {
8248
+ const pl = pmLines()
8249
+ if (pl.length !== 1) fail(`E3:中断应在 pm.md 留下 1 行指针(实际 ${pl.length})`)
8250
+ if (!pl[0].includes('[auto·interrupted]')) fail(`E3:指针行丢了状态类(${pl[0]})`)
8251
+ if (!pl[0].includes('knock=enqueued')) fail(`E3:指针行没有记下这次叫醒(${pl[0]})`)
8252
+ }
7806
8253
  console.log('E3 被中断:一行、显式标记、没有编造的摘要')
7807
8254
 
7808
8255
  // E4:session_start(reload) 也算内部生命周期 → 未完成的 settle 同样不发
@@ -7811,7 +8258,44 @@ await emit('before_agent_start', { type: 'before_agent_start', prompt: 'go' }, c
7811
8258
  await emit('session_start', { type: 'session_start', reason: 'reload' }, cx([]))
7812
8259
  await emit('agent_settled', {}, cx([midTurn]))
7813
8260
  if (lines().length !== 0) fail('E4:reload 之后的未完成 settle 仍写了收件箱')
8261
+ if (pmLines().length !== 0) fail('E4:reload 打断的 settle 写了指针行')
7814
8262
  console.log('E4 reload 打断的回合:没有收件箱行')
8263
+
8264
+ // E5(notice-fulltext-and-asks · P370):长交付 → 记录行存**全文**,而敲门载荷是「有界预览 + 标记 + full=」
8265
+ // 每一处剪**自己**写出剪了多少、原文在哪(敲门的 full= 用持锁写入侧回报的行号)
8266
+ {
8267
+ reset()
8268
+ const longBody = 'P370-E5-' + 'q'.repeat(3000) + '-END'
8269
+ const draftDir = join(root, '.pi/team/state/draft')
8270
+ const beforeDrafts = existsSync(draftDir) ? readdirSync(draftDir) : []
8271
+ await emit('agent_settled', {}, cx([{ role: 'assistant', stopReason: 'stop', content: [{ text: longBody }] }]))
8272
+ const rec = lines().at(-1) ?? ''
8273
+ if ((rec.split(' :: ')[1] ?? '') !== longBody) fail(`E5:记录行没有存全文(只有 ${(rec.split(' :: ')[1] ?? '').length} 字)`)
8274
+ // 载荷走了 outbox:「TUI 没开 bracketed paste」时多行内容会落成 draft 文件(既有行为),单行时直接打。
8275
+ // 两种形状都找一遍 —— 找到的那一份就是 PM 会看到的文字。
8276
+ const walk = (d) => { try { return readdirSync(d, { withFileTypes: true }).flatMap(e => e.isDirectory() ? walk(join(d, e.name)) : [join(d, e.name)]) } catch { return [] } }
8277
+ const candidates = []
8278
+ if (existsSync(draftDir)) for (const f of readdirSync(draftDir)) if (!beforeDrafts.includes(f)) candidates.push(join(draftDir, f))
8279
+ candidates.push(...walk(join(root, '.pi/team/state/outbox')))
8280
+ const payload = candidates.map(f => { try { return readFileSync(f, 'utf8') } catch { return '' } }).find(t => t.includes('truncated=preview:')) ?? ''
8281
+ if (!payload) fail('E5:找不到带截断标记的敲门载荷(剪了却不说)')
8282
+ const m = /truncated=preview:(\d+)\/(\d+)B full=(\S+):(\d+)/.exec(payload)
8283
+ if (!m) fail(`E5:载荷里的标记形状不对(${payload.slice(0, 300)})`)
8284
+ const [, shown, total, file, linenum] = m
8285
+ const totalBytes = Buffer.byteLength(longBody, 'utf8')
8286
+ if (Number(total) !== totalBytes) fail(`E5:标记的 <total> 不是全文的字节数(${total} ≠ ${totalBytes})`)
8287
+ if (!(Number(shown) > 0 && Number(shown) < Number(total))) fail(`E5:<shown>/<total> 不是「留下一部分」(${shown}/${total})`)
8288
+ // R4:按 full=<path>:<line> 真的打出那一行来,` :: ` 之后必须就是全文(行号错位=假定位)
8289
+ const target = existsSync(file) ? file : join(root, file)
8290
+ const pointed = readFileSync(target, 'utf8').split('\n')[Number(linenum) - 1] ?? ''
8291
+ if ((pointed.split(' :: ')[1] ?? '') !== longBody) fail(`E5:full=${file}:${linenum} 没有指到那条全文记录`)
8292
+ // 摘要行带标记,而引用行仍是有界预览(以省略号收尾)
8293
+ const quoted = payload.split('\n').find(l => l.startsWith('> ')) ?? ''
8294
+ if (!quoted) fail('E5:载荷里没有引用行(> …)')
8295
+ if (!quoted.endsWith('\u2026')) fail(`E5:引用的预览行没有以省略号收尾(${JSON.stringify(quoted.slice(-20))})`)
8296
+ if (quoted.length > 160) fail(`E5:预览行超出预算(${quoted.length} 字)`)
8297
+ console.log(`E5 长交付:记录 ${totalBytes}B 全文 / 载荷预览 ${shown}/${total}B / full=${file}:${linenum} 可解析 / 预览 ${quoted.length} 字`)
8298
+ }
7815
8299
  console.log('ext-e-ok')
7816
8300
  EOF
7817
8301
  if env PATH="$TMP/ext-shim:$PATH" EXT_TMUX_LOG="$TMP/ext-tmux.log" \
@@ -7823,6 +8307,7 @@ EOF
7823
8307
  assert_has "$TMP/ext-e.log" "E1 回合内重启/压缩:没有收件箱行、没有敲门" "E1:存在压缩的未完成回合不发简报、不敲门"
7824
8308
  assert_has "$TMP/ext-e.log" "E2 压缩过但已完成:一行 + 敲门(对照组)" "E2:同回合压缩但已完成 → 照常通知(不过度抑制)"
7825
8309
  assert_has "$TMP/ext-e.log" "E3 被中断:一行、显式标记、没有编造的摘要" "E3:被中断的回合显式标记且不编造摘要"
8310
+ assert_has "$TMP/ext-e.log" "E5 长交付:" "P370:长交付的记录行存全文,敲门载荷是有界预览 + 标记 + 可解析的 full="
7826
8311
  assert_has "$TMP/ext-e.log" "E4 reload 打断的回合:没有收件箱行" "E4:reload 打断的回合不发简报"
7827
8312
  else
7828
8313
  printf ' (跳过扩展 E 测试:node 未启用类型剥离,且没有 bun/tsx)\n'
@@ -7879,10 +8364,15 @@ elif [ -z "$TS_RUNNER" ]; then
7879
8364
  elif [ -f "$SKILL_DIR/tests/bg-ledger.sh" ]; then
7880
8365
  # 13c 折进(P237 §4.3):A 刀的 wording/ledger 两组与 P236 的 suspend-shape/owner-scope 同入口同跑
7881
8366
  # —— 工具面口径与账本两类行从这里进主门禁(此前只在独立入口里跑)。
8367
+ # P368:merge/detail 两组此前**不在**子集里,原因是承接缺口而不是判定:这两组属于 P251
8368
+ # turn-notice-merge,落地晚于 P237 §4.3 的折进(当时入口里还没有这两个组),此后 P251 的验收
8369
+ # 只跑了独立入口,于是合并语义与明细读面从未进过门禁 —— A1 改了计数判据之后它们悄悄变红,
8370
+ # 门禁与 V96 都没看见。子集就在这里补齐;下面两条按**用例名**断言它们真的跑了(去掉子集里的
8371
+ # 这两个键 → 这两条 ✗,本段变红,不会静默少跑)。
7882
8372
  P236_RC=0
7883
- bash "$SKILL_DIR/tests/bg-ledger.sh" --select wording,ledger,suspend-shape,owner-scope >"$TMP/p236-owner.log" 2>&1 || P236_RC=$?
8373
+ bash "$SKILL_DIR/tests/bg-ledger.sh" --select wording,ledger,suspend-shape,owner-scope,merge,detail >"$TMP/p236-owner.log" 2>&1 || P236_RC=$?
7884
8374
  if [ "$P236_RC" -eq 0 ]; then
7885
- ok "P236/P237 车道合同入口:wording+ledger+suspend-shape+owner-scope 全绿($(grep -ac '✓' "$TMP/p236-owner.log" || true) 条断言)"
8375
+ ok "P236/P237 车道合同入口:wording+ledger+suspend-shape+owner-scope+merge+detail 全绿($(grep -ac '✓' "$TMP/p236-owner.log" || true) 条断言)"
7886
8376
  else
7887
8377
  bad "P236/P237 车道合同入口有失败(rc=$P236_RC)"
7888
8378
  grep -a '✗' "$TMP/p236-owner.log" | head -8 | sed 's/^/ /'
@@ -7895,6 +8385,9 @@ elif [ -f "$SKILL_DIR/tests/bg-ledger.sh" ]; then
7895
8385
  assert_has "$TMP/p236-owner.plain.log" "✓ owner-scope: a seat with no job of its own is not suspended by another seat’s job (dev2)" "空席位(dev2)不被别人的作业打成挂起"
7896
8386
  assert_has "$TMP/p236-owner.plain.log" "✓ owner-scope: a seat with no job of its own is not suspended by another seat’s job (dev3)" "第二个非拥有者席位(dev3)同样不被别人的作业打成挂起"
7897
8387
  assert_has "$TMP/p236-owner.plain.log" "✓ owner-scope: a live record with a missing, relative or unresolvable cwd does not suspend (fail-closed)" "缺 cwd / 解析失败的畸形记录不判挂起"
8388
+ # P368:合并语义(×N 与行计数读者)与明细读面(--detail 不 ack)从独立入口折进本段。
8389
+ assert_has "$TMP/p236-owner.plain.log" "✓ merge: line-counting readers count a merged line once" "P251 合并行在行计数读者里只算一行(merge 组折进 13c)"
8390
+ assert_has "$TMP/p236-owner.plain.log" "✓ detail: detail reading does not acknowledge" "P251 明细读面只读不 ack(detail 组折进 13c)"
7898
8391
  else
7899
8392
  bad "13c 缺 tests/bg-ledger.sh(P236 的挂起归属入口)"
7900
8393
  fi
@@ -9290,6 +9783,27 @@ else
9290
9783
  fi
9291
9784
  piw_reset
9292
9785
 
9786
+ # ⑪ notice-fulltext-and-asks(P370 B):预览被剪时 spool 行的**第 7 个字段**是发送方自己写的标记
9787
+ # —— `preview` 字段仍然是「≤ 700 字节的最长整字符前缀」(既有契约),标记必须在这个字段**外**;
9788
+ # 没剪时第 7 字段为空(一个字节都不加)。
9789
+ ob_reset; piw_reset
9790
+ piw_reg p370-dev "$SESSION:dev" dev
9791
+ P370_PAY="xy$(printf '红%.0s' $(seq 1 300))"
9792
+ ob_run $TEAM say dev "$P370_PAY" >"$TMP/p370-say.log" 2>&1 || true
9793
+ assert_has "$TMP/p370-say.log" "pi 监视通道" "P370 ⑪:走 pi 通道(spool 行就是发送方的产物)"
9794
+ assert_eq "P370 ⑪:剪断的 spool 行有 7 个字段(标记是独立字段)" \
9795
+ "$(LC_ALL=C awk -F'\t' 'NR==1 {print NF}' "$PIW/p370-dev.wake")" "7"
9796
+ assert_eq "P370 ⑪:preview 字段里没有标记(仍是纯前缀 698 B)" \
9797
+ "$(LC_ALL=C awk -F'\t' 'NR==1 {print (($5 ~ /truncated=/) ? "has-marker" : length($5))}' "$PIW/p370-dev.wake")" "698"
9798
+ LC_ALL=C awk -F'\t' 'NR==1 {print $7}' "$PIW/p370-dev.wake" > "$TMP/p370-marker-spool.txt"
9799
+ assert_has "$TMP/p370-marker-spool.txt" "truncated=preview:698/902B full=docs/team/inbox/dev.md" \
9800
+ "P370 ⑪:标记写出剪了多少(UTF-8 字节,同单位)与原文在哪(durable 收件箱)"
9801
+ assert_has "$REPO/docs/team/inbox/dev.md" "$P370_PAY" "P370 ⑪:durable 收件箱里仍是全文(剪的只是预览那份)"
9802
+ ob_run $TEAM say dev "p370 short no cut" >/dev/null 2>&1 || true
9803
+ assert_eq "P370 ⑪:没剪时第 7 字段为空(没剪就一个字节都不加)" \
9804
+ "$(LC_ALL=C awk -F'\t' 'END {print ($7 == "" ? "empty" : $7)}' "$PIW/p370-dev.wake")" "empty"
9805
+ piw_reset
9806
+
9293
9807
  # ⑨ 真扩展夹具(假 Pi 宿主 + 真 CLI 端到端):注册 / 监视唤醒 / 合并 / 基线 / 清场 / 账本
9294
9808
  # M53/B4:夹具现在先量前提(一次真 fs.watch)——前提不可用时**只**把 watcher 用例标成可见 SKIP,
9295
9809
  # 轮询兜底与 CLI 侧的用例照跑照判。所以这一段的具名断言按前提分两支,且分成两类:
@@ -9405,8 +9919,15 @@ else
9405
9919
  "12b-pi P81:唤醒文本的 id 能在 delivered.log 里一一定位(端到端)"
9406
9920
  if [ "$M53_IW_OK" = "1" ]; then
9407
9921
  assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S1 session_start creates exactly one .reg" "12b-pi 扩展写就绪注册(发送方的判据)"
9922
+ assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S4 the wake names its own cut and where the whole text is" \
9923
+ "P370:watcher 路径上 wake 层也自己写标记(与 S27 的轮询路径同一条行为)"
9408
9924
  assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S2 wake is a custom team-inbox message with triggerTurn+followUp" "12b-pi 唤醒用的是 sendMessage(followUp+triggerTurn)"
9409
9925
  assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S4 long payload is truncated in the wake (no payload dump)" "12b-pi 唤醒只带截断预览(不带 payload 全文)"
9926
+ # P370(S27):watcher 前提无关的同一条行为 —— 轮询路径上真跑真判,跳不过去
9927
+ assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S27 the wake names its own cut and where the whole text is" \
9928
+ "P370:wake 层自己写标记(被剪了就说出 shown/total 与 full=;轮询路径,不靠 watcher)"
9929
+ assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S27 a preview that was not cut carries no marker" \
9930
+ "P370:没剪时 wake 行一个字节都不加"
9410
9931
  assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S7 shutdown removes the registry file" "12b-pi 会话结束删注册(不骗发送方)"
9411
9932
  assert_has "$TMP/piw-harness.log" "TEAM-IW-CASE PASS S10 the running extension wakes the session (zero model calls)" \
9412
9933
  "12b-pi 端到端:真 CLI 投递 → 监视扩展唤醒(零模型调用)"
@@ -9455,6 +9976,29 @@ else
9455
9976
  fi
9456
9977
  assert_has "$TMP/piw-strict.log" "TEAM-IW-CASE FAIL S2 " "12b-pi/M53 严格模式点名 S2"
9457
9978
  assert_has "$TMP/piw-strict.log" "TEAM-IW-HARNESS FAIL" "12b-pi/M53 严格模式的总结行是 FAIL"
9979
+
9980
+ # P370 2.1.1:三处实现(TS ×2、bash ×1)必须产出**同一个字符串形状**,而三份样品都在**本段**造:
9981
+ # spool 层 ← ⑪ 的 spool 第 7 字段;wake 层 ← 上面 harness 的 S4 日志行;敲门层 ← 同一个扩展在一次性
9982
+ # 项目里跑一次(tests/team-notify-knock-marker.mjs)。
9983
+ # 缺一份样品就是红,不许 `continue`:那会让这条断言退化成「造出几份比几份」—— V100 正是这样抓到它
9984
+ # 只比了两处(spool 样品被写进另一个文件名,bash 那一层从未参与)。
9985
+ $TS_RUNNER "$SKILL_DIR/tests/team-notify-knock-marker.mjs" "$SKILL_DIR/extension/team-notify.ts" \
9986
+ >"$TMP/p370-marker-knock.txt" 2>"$TMP/p370-knock-err.log" || true
9987
+ grep 'TEAM-IW-CASE PASS S27 the wake names its own cut' "$TMP/piw-harness.log" 2>/dev/null \
9988
+ | grep -o 'truncated=preview:[0-9][0-9]*/[0-9][0-9]*B full=[^ ]*' | tail -1 >"$TMP/p370-marker-wake.txt" || true
9989
+ p370_shape() { # <含标记的文件> → 遮掉数字与路径后的形状(文件缺失或没有标记 → 空)
9990
+ grep -o 'truncated=preview:[0-9][0-9]*/[0-9][0-9]*B full=[^ ]*' "$1" 2>/dev/null \
9991
+ | tail -1 | sed -E 's/[0-9]+/N/g; s#full=.*#full=P#'
9992
+ }
9993
+ P370_KNOCK_S="$(p370_shape "$TMP/p370-marker-knock.txt")"
9994
+ P370_SPOOL_S="$(p370_shape "$TMP/p370-marker-spool.txt")"
9995
+ P370_WAKE_S="$(p370_shape "$TMP/p370-marker-wake.txt")"
9996
+ assert_eq "P370 2.1.1:敲门层(TS)有样品" "$([ -n "$P370_KNOCK_S" ] && echo yes || echo no)" "yes"
9997
+ assert_eq "P370 2.1.1:spool 层(bash)有样品" "$([ -n "$P370_SPOOL_S" ] && echo yes || echo no)" "yes"
9998
+ assert_eq "P370 2.1.1:wake 层(TS)有样品" "$([ -n "$P370_WAKE_S" ] && echo yes || echo no)" "yes"
9999
+ assert_eq "P370 2.1.1:三处写的是同一个形状(敲门 = spool = wake)" \
10000
+ "$([ -n "$P370_KNOCK_S" ] && [ "$P370_KNOCK_S" = "$P370_SPOOL_S" ] && [ "$P370_SPOOL_S" = "$P370_WAKE_S" ] && echo yes || echo "no knock=[$P370_KNOCK_S] spool=[$P370_SPOOL_S] wake=[$P370_WAKE_S]")" "yes"
10001
+ assert_eq "P370 2.1.1:遮掉数字与路径后的形状就是规格那一串" "$P370_KNOCK_S" "truncated=preview:N/NB full=P"
9458
10002
  fi
9459
10003
 
9460
10004
  # 不留注册:后面的段落(teardown / panel / …)不许被这条通道接管
@@ -9912,7 +10456,9 @@ real_skill_count() { # 仓库里**真实**(非软链)的 skill 目录数 —
9912
10456
  done
9913
10457
  printf '%s' "$n"
9914
10458
  }
9915
- assert_eq "仓库里真实(非软链)的 skill 目录数 = 2(teamsmith + teamsmith-init)" "$(real_skill_count)" "2"
10459
+ # P361:数量跟着源清单走(第三个技能是 handover);real_skill_count 与 skill_src_names 互为交叉核对
10460
+ assert_eq "仓库里真实(非软链)的 skill 目录数 = 源清单数($(skill_src_names | tr '\n' ' '))" \
10461
+ "$(real_skill_count)" "$(skill_src_names | wc -l | tr -d ' ')"
9916
10462
  # M22:仓库不再自带软链别名(`skills/pi-team` 已 git rm)—— 安装器「跳过软链」的守卫改用
9917
10463
  # 段末的 M22 夹具继续守,这里只钉住「仓库里没有旧入口」这个事实。
9918
10464
  if [ -e "$SRC_ROOT/skills/pi-team" ] || [ -L "$SRC_ROOT/skills/pi-team" ]; then
@@ -11273,6 +11819,28 @@ assert_not "$TMP/m98-a-watch.log" "有待办" "M9.8-①:没有把看板 done
11273
11819
  m98 $TEAM digest >"$TMP/m98-a-digest.log" 2>&1 || true
11274
11820
  assert_has "$TMP/m98-a-digest.log" "已按看板跳过 5 份报告" "M9.8-①:digest 点名它们为什么没被列(不静默丢)"
11275
11821
 
11822
+ # P365/A2(tasks 2.2.3 的守卫):digest 的「未敲门」「指针缺失」两行**只显示** —— 不进 team_pending_text、
11823
+ # 不进唤醒理由。否则「挂起只记录不叫醒」(用户 2026-10-14 裁定)会被显示层反悔,而一个不会自己消失的
11824
+ # 指针故障会每一拍都把 PM 叫醒一次。红侧:把这两行接进 team_pending_text → 下面那条「唤醒理由为空」变红。
11825
+ printf '%s\n' '2026-10-22T07:10:00.000Z [auto] agent:dev · P368 · branch=task/P368-x · uncommitted=0 · task=P368 tip=0123456789ab :: skipped knock fixture' > "$TMP/m98-a2-rec.txt"
11826
+ m98 $TEAM __inbox-write --agent dev --from-file "$TMP/m98-a2-rec.txt" >/dev/null 2>&1
11827
+ m98 $TEAM __notify-settle --agent dev --outcome skipped:suspended --record-from-file "$TMP/m98-a2-rec.txt" --task P368 >/dev/null 2>&1
11828
+ printf '%s\n' '- 2026-10-22T07:11:00Z seat=dev · task=P368 · class=- · outcome=enqueued · pointer=failed · identity=-' > "$M98/.pi/team/state/notify-knock.log"
11829
+ m98 $TEAM digest >"$TMP/m98-a2-digest.log" 2>&1 || true
11830
+ assert_has "$TMP/m98-a2-digest.log" "未敲门 1 条已记录的通知没有叫醒 PM(suspended 1)" "P365:未敲门在 digest [2] 里可见(不再只在 /tmp 日志里)"
11831
+ assert_has "$TMP/m98-a2-digest.log" "指针缺失 1 条通知没有写进 PM 收件箱" "P365:指针缺失在 digest [2] 里可见(读账本当前代)"
11832
+ # 唤醒理由仍然只有那条**指针行本身**(一次交付 +1,A1 的判据);「未敲门」不许再加一份 —— 精确等号,
11833
+ # 多出任何一个类别都会红。
11834
+ assert_eq "P365:未敲门不进唤醒计数(唤醒理由只有那一条未读通知)" "$(m98_wake)" "未读通知 1"
11835
+ m98 $TEAM inbox pm --ack >/dev/null 2>&1
11836
+ m98 $TEAM digest >"$TMP/m98-a2-digest2.log" 2>&1 || true
11837
+ assert_not "$TMP/m98-a2-digest2.log" "未敲门" "P365:ack 之后未敲门消失(数的是尚未被回答的指针行)"
11838
+ assert_has "$TMP/m98-a2-digest2.log" "指针缺失 1 条通知没有写进 PM 收件箱" "P365:指针缺失不随 ack 消失(它没有可读可 ack 的行)"
11839
+ assert_eq "P365:指针缺失不进唤醒计数(没有待办时唤醒理由为空)" "$(m98_wake)" ""
11840
+ m98 $TEAM watch --once >"$TMP/m98-a2-watch.log" 2>&1 || true
11841
+ assert_has "$TMP/m98-a2-watch.log" "无待办" "P365:一个不会自己消失的指针故障不会每一拍都叫醒 PM"
11842
+ rm -f "$M98/.pi/team/state/notify-knock.log"
11843
+
11276
11844
  # ② 1 份真待复验 → 叫醒(计数 = digest [3] 可行动清单的行数)
11277
11845
  m98_add M98F
11278
11846
  assert_eq "M9.8-②:1 份真待复验 → 待复验 1" "$(m98_count)" "1"
@@ -16965,6 +17533,8 @@ assert_eq "34b⑨b 新鲜心跳 + W=1000 → 上限正好 4000(硬顶 4×W)"
16965
17533
  # `silent_for`**(缓存值 120,实测该是 100),它的 `state`/`ceiling` 碰巧仍对。判据落在三个字段上,
16966
17534
  # 不落在任何一句文案上。「stalled 时这一轮就该结束」只断言一次(第 3 轮)—— 第 1 轮与它同一判断、
16967
17535
  # 只是换了数字,已按 V78 的冗余裁定删掉。
17536
+ # P372 补一句:下面那条「后一次给出的截止比前一次晚」不承担缓存判定 —— 截止是 `现在 − 已等 + 上限`,
17537
+ # `现在` 前移多少它就前移多少,缓存下照样成立(V78 §5 的两个变体里它都是绿的);缓存由 ⑨c 判。
16968
17538
  P338_W=100; P338_E=150
16969
17539
  p338_scene "$P338_HB" 0; touch -d "@$(( P338_PIN - 120 ))" "$P338_HB"
16970
17540
  IFS=$'\t' read -r P338_C1 P338_S1 P338_Q1 _ < <(p338_pat "$P338_W" "$P338_PIN")
@@ -16985,6 +17555,34 @@ assert_eq "34b⑨b 每轮重算 · 第 3 轮(心跳不再更新、从它最后
16985
17555
  "$P338_C3/$P338_S3/$P338_Q3" "100/stalled/100"
16986
17556
  assert_eq "34b⑨b 每轮重算 · 第 3 轮就该结束(已等 150 s >= 上限 100 s)" \
16987
17557
  "$([ "$P338_E" -ge "$P338_C3" ] && printf 超限 || printf 继续等)" "超限"
17558
+ # ⑨c **缓存反例**(change: gate-waiter-patience · 3.8,P372):同一次等待、**同一个进程**、两个「现在」。
17559
+ # ⑧ 的三轮读起来就是这件事,但每一轮都在 `$( )` / `( )` 里:一次求值一份新进程。把结果缓存在**变量**里的
17560
+ # 实现写的是那个子 shell 的副本,父进程那份从未被写过,于是在 ⑧ 上看起来一切正常;⑧ 的「后一次截止更晚」
17561
+ # 在缓存下也照样成立 —— 截止是 `现在 − 已等 + 上限`,`现在` 前移多少它就前移多少(P372 实测,见报告)。
17562
+ # 这一条把两次求值都交给**一个**子 shell 亲自跑(输出用重定向取,不用 `$( )`,后者又是一次 fork),
17563
+ # 中间只把心跳文件的 mtime 往后挪 —— 「同一份等待状态 + 更晚的现在 + 心跳更新过一次」三个条件同时成立:
17564
+ # 每轮重算 → 第 2 次读到本轮现算的 live/4×W/silent=10,且截止比第 1 次更晚、多走的量**超过**时钟走过的
17565
+ # 150 s(多出来的正是被重算出来的那 300 s 上限);
17566
+ # 排队时缓存(第一次算完就存起来)→ 第 2 次逐字等于第 1 次(stalled/100/120),两条断言一起红。
17567
+ # 判据仍只有喂值:时刻由 `gate_lock_now` 钉住,mtime 用绝对值写,不比秒数、不 sleep。
17568
+ P338_CE=150
17569
+ p338_scene "$P338_HB" 0; touch -d "@$(( P338_PIN - 120 ))" "$P338_HB"
17570
+ (
17571
+ gate_lock_now() { printf '%s\n' "$P338_NOW"; }
17572
+ P338_NOW="$P338_PIN"
17573
+ gate_lock_patience "$P281_LOCK" "$P338_W" > "$P281D/p372-l1"
17574
+ touch -d "@$(( P338_PIN + 140 ))" "$P338_HB" # 心跳又动了(实现读的是它的 mtime)
17575
+ P338_NOW="$(( P338_PIN + 150 ))"
17576
+ gate_lock_patience "$P281_LOCK" "$P338_W" > "$P281D/p372-l2"
17577
+ )
17578
+ IFS=$'\t' read -r P338_CC1 _ _ _ < "$P281D/p372-l1"
17579
+ IFS=$'\t' read -r P338_CC2 _ _ _ < "$P281D/p372-l2"
17580
+ assert_eq "34b⑨c 缓存反例 · 同一个进程里的第 2 次求值是**本轮现算**的(缓存的实现原样返回第 1 次那行 stalled/100/120)" \
17581
+ "$(cat "$P281D/p372-l2")" "$(p338_line 400 live 10 "$P338_HB")"
17582
+ P338_CD1=$(( P338_PIN - P338_CE + P338_CC1 ))
17583
+ P338_CD2=$(( P338_PIN + 150 - P338_CE + P338_CC2 ))
17584
+ assert_eq "34b⑨c 缓存反例 · 后一次给出的截止更晚,且多走的量超过时钟走过的 150 s($(( P338_CD2 - P338_CD1 )) > 150;只把上限缓存一次的实现两者相等)" \
17585
+ "$([ $(( P338_CD2 - P338_CD1 )) -gt 150 ] && printf 多出重算的那部分 || printf 只走了时钟)" "多出重算的那部分"
16988
17586
  rm -f "$P281_LOCK.holder" "$P338_HB" 2>/dev/null || true; rm -rf "$P281_LOCK.runs" 2>/dev/null || true
16989
17587
  # 席位按**运行时目录**解析,不取窗口名。推导只有一份(common.sh 的 team_seat_from_paths):这里断言的
16990
17588
  # 是「锁记录与 team notify 调的是**同一个函数**」—— 同一组目录两边给出同一个结果;解析不出时各自的
@@ -17597,16 +18195,34 @@ else
17597
18195
  P287D="$TMP/p287-id"; rm -rf "$P287D"; mkdir -p "$P287D"
17598
18196
  # 2.1 纯函数单测(P303 的留空项):伴生锁路径推导 —— 同行同目录、basename + `.machine`、点开头。
17599
18197
  # 两种输入:默认路径(未设 TEAM_SMOKE_LOCK)与私有 TEAM_SMOKE_LOCK —— 断言推导结果本身,不依赖真运行。
18198
+ #
18199
+ # P374/V105:段体执行时 TEAM_SMOKE_LOCK **一定非空**(smoke.sh 取锁前就把解析出的发布路径 export 回来了),
18200
+ # 所以「调用者没设」只能靠显式 unset 的子 shell 重新问一次产品函数;默认名这条常量因此无条件被断言,
18201
+ # 不再只在 TEAM_SMOKE_NO_LOCK=1 那条独立路径上可达。
17600
18202
  P287D_DEF="$(gate_lock_default_path)"
17601
- if [ -z "${TEAM_SMOKE_LOCK:-}" ]; then
17602
- assert_eq "34d 2.1 默认路径(未设 TEAM_SMOKE_LOCK)" "$(gate_lock_default_path)" "$P287D_DEF"
17603
- else
17604
- ok "34d 2.1 默认路径那一条:外层设了 TEAM_SMOKE_LOCK=$TEAM_SMOKE_LOCK → 按同一规矩换输入(避免误判)"
17605
- fi
18203
+ P287D_DEF_DEFAULT="$(unset TEAM_SMOKE_LOCK; gate_lock_default_path)"
18204
+ assert_eq "34d 2.1 未设 TEAM_SMOKE_LOCK → 默认发布路径的名字是 teamsmith-smoke.lock" \
18205
+ "$(basename "$P287D_DEF_DEFAULT")" "teamsmith-smoke.lock"
18206
+ assert_eq "34d 2.1 未设 TEAM_SMOKE_LOCK → 伴生锁就是同目录的 .teamsmith-smoke.lock.machine" \
18207
+ "$(gate_lock_companion_path "$P287D_DEF_DEFAULT")" \
18208
+ "$(dirname "$P287D_DEF_DEFAULT")/.teamsmith-smoke.lock.machine"
18209
+ assert_eq "34d 2.1 本次发布路径 = TEAM_SMOKE_LOCK(外面没给就是刚算出的默认值)" \
18210
+ "$P287D_DEF" "${TEAM_SMOKE_LOCK:-$P287D_DEF_DEFAULT}"
17606
18211
  # P309:锁的发布路径**不跟着临时根搬**(跨版本串行:新旧两版必须取同一把锁),所以这里对着锁自己的
17607
18212
  # 目录算伴生路径 —— 断言说的是「同行同目录、basename + .machine」,不是「在临时根下」。
17608
- assert_eq "34d 2.1 默认路径 → 伴生锁(同行同目录、basename + .machine)" \
17609
- "$(gate_lock_companion_path "$P287D_DEF")" "$(dirname "$P287D_DEF")/.teamsmith-smoke.lock.machine"
18213
+ # P374:期望值必须从**同一输入**派生。外层可以用 TEAM_SMOKE_LOCK 换成私有的发布路径(V103 实测
18214
+ # `7-1.lock`),伴生锁随之改名成 `.7-1.lock.machine`;把默认名写死成字面量只会给出假红。所以这里
18215
+ # 断言的是**规则**:同目录、点开头、名字 = 点 + basename(发布路径) + `.machine`(默认名那条常量另由上面
18216
+ # 两条无条件的字面量断言钉住,私有锁跑法下也能对上)。
18217
+ P287D_DEF_CMP="$(gate_lock_companion_path "$P287D_DEF")"
18218
+ assert_eq "34d 2.1 发布路径 → 伴生锁同目录(同行同目录,不跟着临时根搬)" \
18219
+ "$(dirname "$P287D_DEF_CMP")" "$(dirname "$P287D_DEF")"
18220
+ case "${P287D_DEF_CMP##*/}" in
18221
+ .*.machine)
18222
+ assert_eq "34d 2.1 发布路径 → 伴生锁名 = 点 + basename(发布路径) + .machine" \
18223
+ "${P287D_DEF_CMP##*/}" ".$(basename "$P287D_DEF").machine" ;;
18224
+ *) bad "34d 2.1 伴生锁名不是「点开头 + .machine 结尾」:$P287D_DEF_CMP" ;;
18225
+ esac
17610
18226
  P287D_PRIV="$P287D/priv.lock"
17611
18227
  P287D_PRIV_DEF="$(TEAM_SMOKE_LOCK="$P287D_PRIV"; export TEAM_SMOKE_LOCK; gate_lock_default_path)"
17612
18228
  assert_eq "34d 2.1 私有 TEAM_SMOKE_LOCK 形状 → 默认路径取它" "$P287D_PRIV_DEF" "$P287D_PRIV"