teamsmith 0.4.6 → 0.4.7

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 (70) hide show
  1. package/README.md +6 -6
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +24 -0
  4. package/skills/teamsmith/SKILL.md +32 -23
  5. package/skills/teamsmith/extension/team-bg.ts +5 -3
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +14 -3
  7. package/skills/teamsmith/extension/team-notify.ts +20 -13
  8. package/skills/teamsmith/extension/team-remind.ts +189 -0
  9. package/skills/teamsmith/extension/team-reply.ts +4 -7
  10. package/skills/teamsmith/references/migration.md +101 -0
  11. package/skills/teamsmith/references/openspec.md +43 -27
  12. package/skills/teamsmith/references/protocol.md +26 -15
  13. package/skills/teamsmith/references/reminders.md +153 -161
  14. package/skills/teamsmith/references/troubleshooting.md +12 -7
  15. package/skills/teamsmith/references/workflows.md +84 -31
  16. package/skills/teamsmith/scripts/lib/cmd-agents.sh +10 -4
  17. package/skills/teamsmith/scripts/lib/cmd-project.sh +88 -6
  18. package/skills/teamsmith/scripts/lib/cmd-remind.sh +88 -2
  19. package/skills/teamsmith/scripts/lib/cmd-review.sh +42 -4
  20. package/skills/teamsmith/scripts/lib/cmd-watch.sh +48 -11
  21. package/skills/teamsmith/scripts/lib/common.sh +83 -13
  22. package/skills/teamsmith/scripts/panel/panel.js +179 -179
  23. package/skills/teamsmith/scripts/panel/src/data.ts +71 -15
  24. package/skills/teamsmith/scripts/panel/src/layout.ts +20 -8
  25. package/skills/teamsmith/scripts/panel/src/main.tsx +83 -21
  26. package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
  27. package/skills/teamsmith/scripts/remind-store.mjs +55 -24
  28. package/skills/teamsmith/scripts/remind-tick.mjs +5 -2
  29. package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
  30. package/skills/teamsmith/scripts/state-authority.mjs +72 -6
  31. package/skills/teamsmith/scripts/team +1 -0
  32. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +11 -8
  33. package/skills/teamsmith/templates/DECISIONS.md.tmpl +2 -2
  34. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +3 -3
  35. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +19 -14
  36. package/skills/teamsmith/templates/memory-seed.md.tmpl +2 -2
  37. package/skills/teamsmith/templates/pm-prompt.md.tmpl +31 -19
  38. package/skills/teamsmith/templates/report.md.tmpl +33 -0
  39. package/skills/teamsmith/tests/bg-ledger-harness.mjs +217 -33
  40. package/skills/teamsmith/tests/bg-ledger.sh +24 -10
  41. package/skills/teamsmith/tests/checkout-shape-probe.sh +7 -6
  42. package/skills/teamsmith/tests/fixtures/remind-adversarial-delay.ts +27 -0
  43. package/skills/teamsmith/tests/fixtures/remind-tool-provider.ts +65 -0
  44. package/skills/teamsmith/tests/help-surface.sh +3 -5
  45. package/skills/teamsmith/tests/isolation-ledger.sh +6 -2
  46. package/skills/teamsmith/tests/key-replies-ui.sh +53 -0
  47. package/skills/teamsmith/tests/key-replies.sh +307 -106
  48. package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
  49. package/skills/teamsmith/tests/loop-inventory.tsv +1 -0
  50. package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
  51. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +163 -0
  52. package/skills/teamsmith/tests/remind-adversarial-faults.sh +26 -0
  53. package/skills/teamsmith/tests/remind-adversarial-real.sh +27 -0
  54. package/skills/teamsmith/tests/remind-cli.sh +108 -3
  55. package/skills/teamsmith/tests/remind-delivery-node.mjs +13 -0
  56. package/skills/teamsmith/tests/remind-delivery.sh +123 -35
  57. package/skills/teamsmith/tests/remind-lifecycle.sh +197 -0
  58. package/skills/teamsmith/tests/remind-pulse.sh +199 -0
  59. package/skills/teamsmith/tests/remind-recovery-real.sh +5 -0
  60. package/skills/teamsmith/tests/remind-recovery-unit.sh +118 -0
  61. package/skills/teamsmith/tests/remind-tool-node.mjs +159 -0
  62. package/skills/teamsmith/tests/remind-tool-real.mjs +754 -0
  63. package/skills/teamsmith/tests/remind-tool-real.sh +5 -0
  64. package/skills/teamsmith/tests/reply-capture-real.mjs +93 -2
  65. package/skills/teamsmith/tests/routes.sh +213 -293
  66. package/skills/teamsmith/tests/section-paths.tsv +10 -8
  67. package/skills/teamsmith/tests/smoke.sh +484 -28
  68. package/skills/teamsmith/tests/state-authority.sh +152 -8
  69. package/skills/teamsmith-init/SKILL.md +5 -5
  70. package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
@@ -1763,13 +1763,14 @@ team_inbox_append() { # <agent> <tag> <msg> [<sender>]
1763
1763
  # 明细记录数;明细写失败 → 本事件不合并、行带 `detail=unavailable`、日志点名,该行也不做锚;
1764
1764
  # ④ 只有 [auto*] 类行参与合并与明细;[manual]/[draft]/[nudge]/pulse 行原样追加。
1765
1765
 
1766
- # 行 → 合并键(seat|class|task|awaiting)。非 [auto*] 类 / 解析不成立 → rc 1(调用方按「不可合并」处理)。
1766
+ # 行 → 合并键(seat|class|task|awaiting|delivered-tip)。非 [auto*] 类 / 解析不成立 → rc 1。
1767
1767
  # awaiting 是**集合**(去重、排序;缺字段与空集是两个不同的值);task 取 task= 戳里的 ID,否则取
1768
- # agent 后的第一个 <ID> token;branch/tip/uncommitted 不进键(它们只更新显示值)。
1768
+ # agent 后的第一个 <ID> token。只有 delivered 用十二位 tip 分量区分修订;无戳发送者用统一的 NOREV,
1769
+ # suspended/interrupted 用空标记,所以它们的跨 tip 进度仍合并。branch/uncommitted 只更新显示值。
1769
1770
  team_notify_line_key() {
1770
1771
  local body="$1"
1771
1772
  case "$body" in '- '*) body="${body#- }" ;; esac
1772
- local iso rest tag class seat fields aw nrm t
1773
+ local iso rest tag class seat fields aw nrm t rev
1773
1774
  iso="${body%% *}"
1774
1775
  case "$iso" in ''|*[!0-9TZ:.-]*) return 1 ;; esac
1775
1776
  rest="${body#"$iso" }"
@@ -1811,7 +1812,12 @@ team_notify_line_key() {
1811
1812
  t="${t%% *}"
1812
1813
  fi
1813
1814
  [ -n "$t" ] || t='?'
1814
- printf '%s|%s|%s|%s\n' "$seat" "$class" "$t" "$nrm"
1815
+ rev='-'
1816
+ if [ "$class" = delivered ]; then
1817
+ rev='NOREV'
1818
+ if [[ "$fields" =~ tip=([0-9a-f]{12})([[:space:]]|$) ]]; then rev="T:${BASH_REMATCH[1]}"; fi
1819
+ fi
1820
+ printf '%s|%s|%s|%s|%s\n' "$seat" "$class" "$t" "$nrm" "$rev"
1815
1821
  }
1816
1822
 
1817
1823
  # 尾行能不能当锚:带 detail=unavailable 的行不是锚(否则下一次成功的事件会把它抹掉,缺口就不可见了)。
@@ -254,6 +254,20 @@ team_init_model_policy_resolve() { # <cfg> <task_models|''> <pm_model|''> <task_
254
254
  return 0
255
255
  }
256
256
 
257
+ # PROTOCOL 是公开账本:命令路径从项目根解析,不记录运行 CLI 的绝对家目录。
258
+ # 源仓直接使用随仓库提交的技能;普通项目使用 init 随后安装的项目副本;跳过安装时只给明确占位。
259
+ team_init_protocol_skill_dir() { # <install-mode>
260
+ case "$1" in
261
+ --no-skills) printf '<skill-dir>\n'; return 0 ;;
262
+ esac
263
+ if [ -f "$TEAM_MAIN_ROOT/skills/teamsmith/SKILL.md" ] \
264
+ && [ -f "$TEAM_MAIN_ROOT/skills/teamsmith/scripts/team" ]; then
265
+ printf 'skills/teamsmith\n'
266
+ else
267
+ printf '.pi/skills/teamsmith\n'
268
+ fi
269
+ }
270
+
257
271
  team_cmd_init() {
258
272
  local session="" agents="" vcs="" gates="" docs="" pmwin="" force=0 install_mode=""
259
273
  local task_models="" pm_model="" task_models_set=0 pm_model_set=0
@@ -399,6 +413,7 @@ team_cmd_init() {
399
413
 
400
414
  # 2) 文档骨架
401
415
  local tdir; tdir="$(team_tmpl_dir)"
416
+ local docs_skill_dir; docs_skill_dir="$(team_init_protocol_skill_dir "$install_mode")"
402
417
  TEAM_DOCS_ABS="$TEAM_MAIN_ROOT/$docs"
403
418
  mkdir -p "$TEAM_DOCS_ABS"/{tasks,reports,threads,inbox,reviews}
404
419
  team_render_to "$tdir/BOARD.md.tmpl" "$TEAM_DOCS_ABS/BOARD.md" "$force" "PROJECT=$project" "TODAY=$(date +%F)"
@@ -408,7 +423,7 @@ team_cmd_init() {
408
423
  team_render_to "$tdir/threads-README.md" "$TEAM_DOCS_ABS/threads/README.md" "$force" "PROJECT=$project" "AGENTS=$agents"
409
424
  team_render_to "$tdir/PROTOCOL.md.tmpl" "$TEAM_DOCS_ABS/PROTOCOL.md" "$force" \
410
425
  "PROJECT=$project" "DOCS_DIR=$docs" "WORKTREES_DIR=$(basename "${TEAM_WORKTREES_DIR:-.worktrees}")" \
411
- "SKILL_DIR=$TEAM_SKILL_DIR" "GATES=${gates:-<未配置>}" "SESSION=$session"
426
+ "SKILL_DIR=$docs_skill_dir" "GATES=${gates:-<未配置>}" "SESSION=$session"
412
427
  for d in tasks reports reviews; do
413
428
  [ -f "$TEAM_DOCS_ABS/$d/.gitkeep" ] || : > "$TEAM_DOCS_ABS/$d/.gitkeep"
414
429
  done
@@ -416,10 +431,16 @@ team_cmd_init() {
416
431
  printf '# 复验日志:本地证据,不入库\n*.log\n' > "$TEAM_DOCS_ABS/reviews/.gitignore"
417
432
 
418
433
  # 3) AGENTS.md 协议段落
434
+ # 普通项目的技能只装在主检出:worker 从 worktree 调命令时也通过 git common-dir 找同一份安装。
435
+ # 源仓的 skills/ 随分支检出,直接复用 PROTOCOL 的仓库相对路径;--no-skills 保留明确占位。
436
+ local agents_skill_dir="$docs_skill_dir"
437
+ if [ "$agents_skill_dir" = '.pi/skills/teamsmith' ]; then
438
+ agents_skill_dir='"$(git rev-parse --path-format=absolute --git-common-dir)/../.pi/skills/teamsmith"'
439
+ fi
419
440
  local section; section="$(mktemp)"
420
441
  team_render "$tdir/AGENTS.section.md.tmpl" \
421
442
  "PROJECT=$project" "DOCS_DIR=$docs" "SESSION=$session" "PM_WINDOW=$pmwin" \
422
- "SKILL_DIR=$TEAM_SKILL_DIR" "AGENTS=$agents" "GATES=${gates:-<未配置>}" \
443
+ "SKILL_DIR=$agents_skill_dir" "AGENTS=$agents" "GATES=${gates:-<未配置>}" \
423
444
  "WORKTREES_DIR=${TEAM_WORKTREES_DIR:-.worktrees}" "PROTECTED_BRANCH=main" > "$section"
424
445
  # 旧名标记迁移(<=1.12 的项目 AGENTS.md 里是 pi-team:begin/end):交给同一个写入器,按同一处
425
446
  # 范围编辑把标记行的文字换掉(围栏外那对才动,示例里的旧标记逐字节保留)。
@@ -561,11 +582,13 @@ team_cmd_doctor() {
561
582
  fi
562
583
  fi
563
584
 
585
+ # P427:doctor 是只读面 —— 外部命令一律走 team_readonly_run(关掉子进程的编译缓存 / jiti 缓存 /
586
+ # 插件日志:`pi` 的入口会调 enableCompileCache(),拿到 TMPDIR 就把它建出来了)。
564
587
  check "pi"; if [ -n "${TEAM_AGENT_CMD:-}" ]; then
565
588
  pass "本项目用自定义 agent adapter:不需要 pi"
566
589
  elif team_have_cmd pi; then
567
- local pv; pv="$(pi --version 2>/dev/null | head -1 || true)"
568
- if pi --help 2>&1 | grep -q -- '--session-id'; then pass "${pv:-present}"; else fail "pi 版本过旧:缺 --session-id"; fi
590
+ local pv; pv="$(team_readonly_run pi --version 2>/dev/null | head -1 || true)"
591
+ if team_readonly_run pi --help 2>&1 | grep -q -- '--session-id'; then pass "${pv:-present}"; else fail "pi 版本过旧:缺 --session-id"; fi
569
592
  else fail "缺 pi(PATH 里没有)"; fi
570
593
 
571
594
  # agent adapter:空 TEAM_AGENT_CMD = 内置 Pi(默认);配了就用任意 TUI agent 的命令模板。
@@ -668,7 +691,7 @@ team_cmd_doctor() {
668
691
  local os_bin os_ver
669
692
  os_bin="$(team_openspec_bin_path)"
670
693
  if command -v "$os_bin" >/dev/null 2>&1; then
671
- os_ver="$("$os_bin" --version 2>/dev/null | head -1)"
694
+ os_ver="$(team_readonly_run "$os_bin" --version 2>/dev/null | head -1)"
672
695
  pass "${os_ver:-已解析}($os_bin)"
673
696
  elif [ "${TEAM_REQUIRE_OPENSPEC:-1}" = "1" ]; then
674
697
  fail "找不到:$os_bin(装上 OpenSpec CLI 并确保在 PATH 里,或设 TEAM_OPENSPEC_BIN;临时可 TEAM_REQUIRE_OPENSPEC=0 降级)"
@@ -705,6 +728,35 @@ team_cmd_doctor() {
705
728
  warn "找到了但版本判不出:${js_path:-?} ${js_ver:-}${js_detail:+($js_detail)}——确认它能跑 --version" ;;
706
729
  esac
707
730
 
731
+ # Standby 与 Reminder 共用这一个 OS 锁;没有 Reminder 的项目也不能缺少它。
732
+ # 已初始化时再对真实 authority.lock 取一次锁:PATH 里有可执行文件不等于这个文件系统支持锁。
733
+ check "状态锁 flock"
734
+ local flock_st flock_path flock_detail flock_probe="" flock_probe_rc=0
735
+ IFS=$'\t' read -r flock_st flock_path flock_detail <<< "$(team_flock_check)"
736
+ case "$flock_st" in
737
+ missing)
738
+ fail "PATH 里没有可执行 flock:安装 util-linux(提供 flock),或把可执行文件放进 PATH;Standby/Reminder 不会无锁写入" ;;
739
+ unusable)
740
+ fail "$flock_path 存在但不可执行或不是普通文件:修复执行权限(chmod +x $(printf '%q' "$flock_path")),或安装 util-linux 并修正 PATH" ;;
741
+ unavailable)
742
+ if [ "${TEAM_REQUIRE_JS:-1}" = "1" ]; then fail "$flock_detail:先修上面的 JS 运行时,再重跑 doctor"
743
+ else warn "$flock_detail(TEAM_REQUIRE_JS=0 已降级);Standby/Reminder 仍需 JS 与 flock" ; fi ;;
744
+ ok)
745
+ if ! "$flock_path" --version >/dev/null 2>&1; then
746
+ fail "$flock_path 无法执行(--version 失败):重新安装 util-linux,或修正 PATH 指向可用的 flock;不会无锁降级"
747
+ elif [ -f "$TEAM_MAIN_ROOT/.pi/team/reminder-locator.json" ] && [ -f "$TEAM_STATE_DIR/reminders/authority.lock" ]; then
748
+ flock_probe="$(team_authority_flock_probe 2>&1)" || flock_probe_rc=$?
749
+ if [ "$flock_probe_rc" -eq 0 ]; then
750
+ pass "$flock_path(真实 authority.lock 排他锁可用)"
751
+ else
752
+ fail "真实 authority.lock 加锁失败:$flock_probe;检查 $TEAM_STATE_DIR/reminders 所在文件系统是否支持 flock,修复或迁到支持排他锁的文件系统;不会无锁降级"
753
+ fi
754
+ else
755
+ pass "$flock_path(状态权威尚未初始化;首次 Standby/Reminder 写入会验证文件系统锁)"
756
+ fi ;;
757
+ *) fail "flock 诊断返回未知状态:$flock_st $flock_detail" ;;
758
+ esac
759
+
708
760
  # M53 · wake 通道的 inotify 余量:额度 + **可证明**的占用 + 一次性注册探针。降级 ≠ 故障 ——
709
761
  # 这是环境事实,只警告(fails 不动)并给修法;探针不是 ok 或已知余量低于底线才开口。
710
762
  check "inotify 额度"
@@ -751,6 +803,36 @@ team_cmd_doctor() {
751
803
  fi ;;
752
804
  esac
753
805
 
806
+ # P442 · PM 自我提醒工具:证据只来自当前扩展自己发布的注册/错误记录,并与活进程和启动记录核对。
807
+ # 查不到另一个 Pi 进程里的工具表,所以缺失/过期/不匹配只能报 unknown,不能报加载失败或成功。
808
+ check "PM 提醒工具"
809
+ local remind_runner remind_runtime="" remind_inspect_rc=0
810
+ remind_runner="$(team_js_runner)"
811
+ if [ -n "$remind_runner" ] && { [[ "$pmstate" == running:* ]] || [ -f "$TEAM_STATE_DIR/remind-tool/current.json" ]; }; then
812
+ remind_runtime="$(team_readonly_run "$remind_runner" -e '
813
+ import(require("node:url").pathToFileURL(process.argv[1]).href).then(m => {
814
+ const [root,state,config,session,window,skill] = process.argv.slice(2);
815
+ const r = m.inspectRemindCapability({root,state,config,session,window,skill});
816
+ console.log(`${r.state} ${r.reason}; at=${r.at || "unknown"}; loaded=${r.loaded || "unknown"}; disk=${r.disk || "unknown"}`);
817
+ }).catch(e => { console.error(`capability diagnostic unavailable: ${e.code || e.name}`); process.exitCode=1 })
818
+ ' "$TEAM_SKILL_DIR/scripts/remind-capability.mjs" "$TEAM_MAIN_ROOT" "$TEAM_STATE_DIR" "${TEAM_CONFIG:-${TEAM_CONFIG_FILE:-}}" "$TEAM_SESSION" "$TEAM_PM_WINDOW" "$TEAM_SKILL_DIR")" || remind_inspect_rc=$?
819
+ fi
820
+ if [ -n "$(team_trim "${TEAM_PM_CMD:-}${TEAM_PM_BIN:-}")" ]; then
821
+ warn "unknown:自定义 PM adapter 不支持 team_remind 能力证据"
822
+ elif [[ "$remind_runtime" == error\ * ]]; then
823
+ # A live extension can diagnose a bad generated session/window even though that same config hides the PM pane.
824
+ warn "$remind_runtime"
825
+ elif [[ "$pmstate" != running:* ]]; then
826
+ warn "not-running:PM 未在运行($pmstate)"
827
+ elif [ -z "$remind_runner" ]; then
828
+ warn "unknown:无可用 JS 运行时,未核实注册证据"
829
+ elif [ "$remind_inspect_rc" -eq 0 ] && [ -n "$remind_runtime" ]; then
830
+ case "$remind_runtime" in
831
+ ready\ *) pass "$remind_runtime" ;;
832
+ *) warn "$remind_runtime" ;;
833
+ esac
834
+ else warn "unknown:注册证据诊断执行失败(未当作启用或加载失败)"; fi
835
+
754
836
  # M46 · 投递通道:PM 没有 inbox-watch 注册时,通知会退回输入框粘贴慢路径 —— 这条降级必须看得见。
755
837
  # 只在「内置 Pi 的 PM」这条 lane 上判(自定义 PM CLI 不吃这个扩展,绝不劝告);PM 没在跑且
756
838
  # 没有活痕迹时不刷行(没有可降级的目标);注册在 → pass 一行,让人知道快路径真的连着。
@@ -778,7 +860,7 @@ team_cmd_doctor() {
778
860
  reply_runner="$(team_js_runner)"
779
861
  if [ -z "$reply_runner" ]; then
780
862
  warn "unknown:无可用 JS 运行时,未核实 live 注册"
781
- elif reply_runtime="$("$reply_runner" -e '
863
+ elif reply_runtime="$(team_readonly_run "$reply_runner" -e '
782
864
  import(require("node:url").pathToFileURL(process.argv[1]).href).then(m => {
783
865
  const [root,state,config,session,window,skill] = process.argv.slice(2);
784
866
  const r = m.inspectRuntime({root,state,config,session,window,skill});
@@ -27,15 +27,101 @@ team_remind_usage() {
27
27
  # tick:巡检窗口的**轻量**到期检查(agent-self-reminder 4.1)。两种巡检形态都调同一份入口:
28
28
  # 它只读一份有界快照,没到点就直接退出(不拿锁、不扫项目、不调模型);到点才提交入队。
29
29
  # 失败必须看得见(不是静默跳过),但不能把巡检循环带走 —— 记一行 watchdog.log 后返回 0。
30
- team_remind_due_tick() { # <pulse 实例起点 ISO>
30
+ team_remind_due_tick() { # <pulse 实例起点 ISO>;同时给出是否需要一个 Reminder-only 恢复决定
31
31
  local runner out rc
32
+ TEAM_REMIND_RECOVERY_REQUIRED=0; TEAM_REMIND_RECOVERY_SIGNATURE=''
32
33
  runner="$(team_js_runner)"
33
34
  [ -n "$runner" ] || { team_warn "remind: 缺 JS 运行时,到期检查没跑(显式失败,不是通过)"; return 0; }
34
35
  out="$("$runner" "${TEAM_SKILL_DIR:-$(team_skill_dir)}/scripts/remind-tick.mjs" \
35
- --root "$TEAM_MAIN_ROOT" --state-dir "$TEAM_STATE_DIR" --pulse-started "${1:-}" 2>&1)"
36
+ --root "$TEAM_MAIN_ROOT" --state-dir "$TEAM_STATE_DIR" --pulse-started "${1:-}" --json 2>&1)"
36
37
  rc=$?
37
38
  if [ "$rc" -ne 0 ]; then
38
39
  team_wlog "remind tick 失败(rc=$rc):$(printf '%s' "$out" | head -2 | tr '\n' ' ')"
40
+ elif printf '%s' "$out" | grep -q '"recoveryRequired":true'; then
41
+ TEAM_REMIND_RECOVERY_REQUIRED=1
42
+ TEAM_REMIND_RECOVERY_SIGNATURE="$(printf '%s' "$out" | sed -n 's/.*"recoveryIds":\[\([^]]*\)\].*/\1/p')"
43
+ fi
44
+ return 0
45
+ }
46
+
47
+ # Reminder-only 恢复:只处理权威里已 queued、尚未进入 intent 的提醒。它复用普通 PM 启动的
48
+ # 身份、continuity、starting、窗口与重启额度判据,但不写/不带通用 pm-prompt,也不先处理 backlog。
49
+ team_remind_recovery_log() { # <结果> [证据]
50
+ local line="$(team_timestamp) reminder-recovery $1${2:+ $2}"
51
+ printf '%s\n' "$line" >> "$TEAM_STATE_DIR/reminders.log"
52
+ printf '%s\n' "$line"
53
+ }
54
+
55
+ team_remind_recovery() { # [pulse 实例起点 ISO]
56
+ mkdir -p "$TEAM_STATE_DIR"
57
+ team_remind_due_tick "${1:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}"
58
+ [ "${TEAM_REMIND_RECOVERY_REQUIRED:-0}" = "1" ] || return 0
59
+
60
+ if [ -n "$(team_trim "${TEAM_PM_CMD:-}")" ]; then
61
+ team_remind_recovery_log 'result=unsupported-adapter' 'reason=custom PM adapter has no prompt-free Pi watcher contract'
62
+ return 0
63
+ fi
64
+ local required
65
+ for required in extension/team-bg.ts extension/team-inbox-watch.ts extension/team-reply.ts extension/team-remind.ts \
66
+ scripts/state-authority.mjs scripts/reminder-delivery.mjs; do
67
+ if [ ! -f "$TEAM_SKILL_DIR/$required" ]; then
68
+ team_remind_recovery_log 'result=missing-extension' "path=$TEAM_SKILL_DIR/$required"
69
+ return 0
70
+ fi
71
+ done
72
+
73
+ local st; st="$(team_pm_state)"
74
+ case "$st" in
75
+ running:*)
76
+ team_remind_recovery_log 'result=running' "evidence=$(team_pm_evidence "$st")"
77
+ return 0 ;;
78
+ starting:*)
79
+ team_remind_recovery_log 'result=starting' "evidence=$(team_pm_evidence "$st")"
80
+ return 0 ;;
81
+ esac
82
+
83
+ # 与普通 patrol 相同:缺窗口时默认只报告,不由 Pulse 改建 tmux;显式允许时才走同一组身份检查。
84
+ case "$st" in
85
+ idle:*|unknown:*) ;;
86
+ foreign:*)
87
+ team_remind_recovery_log 'result=foreign-window' "evidence=$(team_pm_evidence "$st")"
88
+ return 0 ;;
89
+ *)
90
+ if [ "$TEAM_PULSE_REBUILD_TMUX" != "1" ]; then
91
+ team_remind_recovery_log 'result=missing-window' "evidence=$(team_pm_evidence "$st")"
92
+ return 0
93
+ fi
94
+ if ! team_assert_own_session 'reminder recovery 重建 tmux'; then
95
+ team_remind_recovery_log 'result=foreign-session' 'reason=refused to rebuild a session owned by another project'
96
+ return 0
97
+ fi
98
+ if ! team_tmux_has_session "$TEAM_SESSION"; then
99
+ team_tmux_ensure_session || { team_remind_recovery_log 'result=start-failed' 'reason=tmux session creation failed'; return 0; }
100
+ team_tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
101
+ fi
102
+ if ! team_pm_window_exists; then
103
+ team_tmux_new_window "$TEAM_SESSION" "$TEAM_PM_WINDOW" || { team_remind_recovery_log 'result=start-failed' 'reason=PM window creation failed'; return 0; }
104
+ fi ;;
105
+ esac
106
+
107
+ if ! team_pm_identity_guard; then
108
+ team_remind_recovery_log 'result=identity-refused' 'reason=PM model/continuity/launch identity guard rejected the start'
109
+ return 0
110
+ fi
111
+ if ! team_pm_restart_allowed; then
112
+ team_remind_recovery_log 'result=quota-refused' "evidence=$(team_pm_evidence "$st")"
113
+ return 0
114
+ fi
115
+ team_pm_attempt_record "reason=reminder state=${st%%:*} evidence=$(team_pm_evidence "$st")"
116
+ if TEAM_REMINDER_ONLY_RECOVERY=1 team_pm_start; then
117
+ if [ "${TEAM_PM_START_OUTCOME:-}" = 'started' ]; then
118
+ team_pm_restart_record "reason=reminder state=${st%%:*} evidence=$(team_pm_evidence "$st")"
119
+ team_remind_recovery_log 'result=started' "pid=$(team_pm_recorded_pid) capacity=$(team_capacity_line)"
120
+ else
121
+ team_remind_recovery_log "result=${TEAM_PM_START_OUTCOME:-running}" 'reason=another start won the race; no second restart was recorded'
122
+ fi
123
+ else
124
+ team_remind_recovery_log 'result=start-failed' 'reason=PM did not obtain launch proof; Standby and Reminder outcome are unchanged'
39
125
  fi
40
126
  return 0
41
127
  }
@@ -90,6 +90,42 @@ team_task_title() { # <ID> → 标题(BOARD 的「任务」列,其次任务
90
90
  # 分支不是被判对象;其余任务仍是任务分支当前 tip。
91
91
  team_review_record_path() { printf '%s\n' "$TEAM_DOCS_ABS/reviews/$1.md"; }
92
92
 
93
+ # root/ 一律替换;裸 root 的 ASCII 字母数字后缀,以及后随字母数字的 -_. 才算兄弟路径延续。
94
+ # 句末 -_. 与其它右边界(含所有中文标点)都接受,不维护分隔符白名单,也不依赖 locale 的字符分类。
95
+ team_review_ledger_display_root() { # <文本> <绝对根> <占位>
96
+ local rest="$1" root="$2" marker="$3" out="" before after right continuation skip
97
+ [ -n "$root" ] || { printf '%s' "$rest"; return 0; }
98
+ rest="${rest//"${root}/"/"${marker}/"}"
99
+ while [[ "$rest" == *"$root"* ]]; do
100
+ before="${rest%%"$root"*}"
101
+ after="${rest#*"$root"}"
102
+ right="${after:0:1}"
103
+ continuation=0
104
+ case "$right" in
105
+ [A-Za-z0-9]) continuation=1 ;;
106
+ [-_.]) case "${after:1:1}" in [A-Za-z0-9]) continuation=1 ;; esac ;;
107
+ esac
108
+ if [ "$continuation" = "1" ]; then
109
+ skip=$(( ${#before} + 1 ))
110
+ out="$out${rest:0:skip}"; rest="${rest:skip}"
111
+ else
112
+ out="$out$before$marker"; rest="$after"
113
+ fi
114
+ done
115
+ printf '%s' "$out$rest"
116
+ }
117
+
118
+ # 公开账本只保留可移植的显示路径。执行仍使用真实绝对路径;这里只净化最终 Markdown,
119
+ # 因而模板字段、锁记录、报告摘录与门禁输出都走同一规则,独立 /var/tmp checkout 不受影响。
120
+ team_review_ledger_display() {
121
+ local line main="${TEAM_MAIN_ROOT%/}" home="${HOME%/}"
122
+ while IFS= read -r line || [ -n "$line" ]; do
123
+ line="$(team_review_ledger_display_root "$line" "$main" '<main-root>')"
124
+ line="$(team_review_ledger_display_root "$line" "$home" '<home>')"
125
+ printf '%s\n' "$line"
126
+ done
127
+ }
128
+
93
129
  # 128+n → 信号名(写复验记录用;认不出来就给数字,不编名字)
94
130
  team_review_signal_name() { # <signal number> → SIGTERM / SIGKILL / SIG<n>
95
131
  local n="${1:-}" name=""
@@ -1349,11 +1385,13 @@ $(printf '%s\n' "$ignored_list" | head -5)
1349
1385
  [ "$gates_marker" = "mutexbroken" ] && head_flags="$head_flags · gate mutex broken(互斥被破坏:判定不可信)"
1350
1386
  # 被信号终止(不是超时):把信号名写进抬头,别拿「超时」顶替「被杀」(M6.5 / F15)
1351
1387
  [ -n "$gate_signal" ] && head_flags="$head_flags · gate killed: $gate_signal"
1388
+ local executor; executor="$(team_sender_from_dir)"; [ -n "$executor" ] || executor="unknown"
1352
1389
  {
1353
- printf '# %s · PM 独立复验\n\n' "$id"
1390
+ printf '# %s · 独立复验\n\n' "$id"
1354
1391
  printf '时间: %s · 分支: `%s` · HEAD: `%s` · 判定: **%s**%s\n\n' "$(team_timestamp)" "$branch" "${head:0:9}" "$verdict" "$head_flags"
1355
1392
  printf '## 复验方式\n\n'
1356
- printf -- '- 独立 checkout:`%s`(PM 提供,skill 只读;不信任 agent 工作区)\n' "$revdir"
1393
+ printf -- '- 实际执行者:`%s`(从调用者的运行时工作树身份解析;与 checkout 准备者、实现作者及 PM 接受分开)\n' "$executor"
1394
+ printf -- '- 独立 checkout:`%s`(PM 准备;被验内容只读,不信任 agent 工作区)\n' "$revdir"
1357
1395
  printf -- '- 记录绑定:本判定只对上面的 HEAD `%s` 负责(分支再动一格,digest/status 会把它重新列为待复验)\n' "${head:0:9}"
1358
1396
  printf -- '- 门禁命令:`%s`(硬超时 %ss%s;TIMEOUT 需要「包装器 124/137 + 用时贴住 deadline」两条证据,按失败处理)\n' \
1359
1397
  "${TEAM_GATES:-<未配置>}" "${TEAM_REVIEW_TIMEOUT:-1800}" "${gate_elapsed:+,实际用时 ${gate_elapsed}s}"
@@ -1434,7 +1472,7 @@ $(printf '%s\n' "$ignored_list" | head -5)
1434
1472
  else
1435
1473
  printf '## agent 报告原文\n\n**缺失**:分支上没有 `%s/reports/%s-<agent>.md`,这本身就是问题。\n\n' "$TEAM_DOCS_DIR" "$id"
1436
1474
  fi
1437
- printf '## PM 结论\n\n'
1475
+ printf '## PM 接受清单(由 PM 审阅填写;不代表 PM 执行了上述门禁)\n\n'
1438
1476
  case "$verdict" in
1439
1477
  PASS) printf -- '- [ ] 已读 diff,与任务书交付物一致\n- [ ] 未发现「报告与实际不符」\n- [ ] 可以合并:squash 到 `%s` 并 push 之后,再 `%s board set %s done`\n' "$TEAM_PROTECTED_BRANCH" "$TEAM_CLI" "$id" ;;
1440
1478
  FAIL) printf -- '- [ ] 门禁失败:退回 agent(`%s say <agent> "..."`)或 PM 自行修复\n' "$TEAM_CLI"
@@ -1447,7 +1485,7 @@ $(printf '%s\n' "$ignored_list" | head -5)
1447
1485
  TIMEOUT) printf -- '- [ ] 门禁被硬超时终止(TIMEOUT→按失败处理):查门禁自己为何挂死,或调 `TEAM_REVIEW_TIMEOUT` 后重跑\n' ;;
1448
1486
  *) printf -- '- [ ] 人工评审(门禁未跑/未配置:这不等于通过,digest 会继续把它列为待复验)\n' ;;
1449
1487
  esac
1450
- } > "$report"
1488
+ } | team_review_ledger_display > "$report"
1451
1489
  team_scan_invalidate review # M50:同进程里「写完再读」必须读到新记录
1452
1490
  [ -n "$queue_marker" ] && rm -f "$queue_marker" 2>/dev/null
1453
1491
  team_ok "复验记录:${report#"$TEAM_MAIN_ROOT"/}($verdict)"
@@ -731,10 +731,27 @@ team_cmd_watch() {
731
731
 
732
732
  team_require_cmd tmux "pulse 需要 tmux 来拉起 PM/agent"
733
733
  team_watch_lock || return 1
734
- trap 'team_watch_unlock' EXIT
735
- # INT/TERM 必须立刻生效:sleep 放后台 + wait(被捕获的信号会立刻打断 wait),handler 里 exit 走 EXIT trap 解锁。
736
- # 原来是 trap '…' EXIT INT TERM 一把抓:bash 会把前台的 sleep 跑完才执行 handler,解了锁还继续巡 ——
737
- # Ctrl-C 和 kill 都停不下巡检循环(P8 实测:kill TERM 后 wait 永久阻塞)。
734
+ local patrol_pid='' recovery_pid='' sleep_pid='' recovery_pending=0 recovery_seen=''
735
+ team_watch_loop_alive() { # <pid>:kill -0 对等待 wait 的僵尸仍为真,不能拿它当“还在跑”
736
+ local stat; stat="$(ps -o stat= -p "$1" 2>/dev/null | tr -d '[:space:]')"
737
+ [ -n "$stat" ] && [[ "$stat" != Z* ]]
738
+ }
739
+ team_watch_loop_cleanup() {
740
+ local pid child
741
+ for pid in "$patrol_pid" "$recovery_pid" "$sleep_pid"; do
742
+ [ -n "$pid" ] || continue
743
+ # The patrol/recovery is a shell child; stop its current external command too (for example a
744
+ # patrol sleep), then wait for the direct child. A process that already exited is expected here.
745
+ for child in $(ps -o pid= --ppid "$pid" 2>/dev/null); do
746
+ kill "$child" 2>/dev/null || true # 留:外部命令可能已先退出;仍须继续回收其余子进程
747
+ done
748
+ kill "$pid" 2>/dev/null || true # 留:登记的子进程可能已先退出;继续解锁
749
+ wait "$pid" 2>/dev/null || true # 留:被 TERM 的子进程 wait 返回 143(或已被回收),这不是清理失败
750
+ done
751
+ team_watch_unlock
752
+ }
753
+ trap 'team_watch_loop_cleanup' EXIT
754
+ # INT/TERM 必须立刻生效:sleep 放后台 + wait(被捕获的信号会立刻打断 wait),handler 里 exit 走 EXIT trap。
738
755
  trap 'exit 130' INT
739
756
  trap 'exit 143' TERM
740
757
  fp0="$(team_watch_code_fp)"
@@ -748,15 +765,35 @@ team_cmd_watch() {
748
765
  case "$slice" in ''|*[!0-9]*|0) slice=10 ;; esac
749
766
  pulse_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
750
767
  while :; do
751
- now="$(date +%s)"
768
+ # Reap first: a finished child must never look like an in-flight reason to skip the coalesced recheck.
769
+ if [ -n "$patrol_pid" ] && ! team_watch_loop_alive "$patrol_pid"; then
770
+ wait "$patrol_pid"; patrol_pid=''; next_patrol=$(( $(date +%s) + interval )); recovery_seen=''
771
+ fi
772
+ if [ -n "$recovery_pid" ] && ! team_watch_loop_alive "$recovery_pid"; then
773
+ wait "$recovery_pid"; recovery_pid=''
774
+ fi
775
+
776
+ # The lightweight child is synchronous and independent of the long patrol below. Queueing can
777
+ # therefore commit during that patrol; one bit coalesces every recovery need until it ends.
752
778
  team_remind_due_tick "$pulse_started"
753
- if [ "$now" -ge "$next_patrol" ]; then
779
+ if [ "${TEAM_REMIND_RECOVERY_REQUIRED:-0}" = "1" ] && [ "${TEAM_REMIND_RECOVERY_SIGNATURE:-}" != "$recovery_seen" ]; then
780
+ recovery_pending=1
781
+ fi
782
+
783
+ # A due ordinary patrol goes first; recovery runs in the gap after it. Without this priority a
784
+ # permanently refused recovery would consume every free slot and starve the ordinary patrol.
785
+ now="$(date +%s)"
786
+ if [ "$now" -ge "$next_patrol" ] && [ -z "$patrol_pid" ] && [ -z "$recovery_pid" ]; then
754
787
  # M9.8:判定必须用磁盘上的代码(漂移就重启本进程)—— 否则唤醒理由可能比 digest 旧
755
788
  team_watch_reexec_if_stale "$fp0" watch ${argv[@]+"${argv[@]}"}
756
- team_watch_once
757
- next_patrol=$(( $(date +%s) + interval ))
789
+ team_watch_once & patrol_pid=$!
790
+ fi
791
+ if [ -z "$patrol_pid" ] && [ -z "$recovery_pid" ] && [ "$recovery_pending" = "1" ]; then
792
+ recovery_pending=0; recovery_seen="${TEAM_REMIND_RECOVERY_SIGNATURE:-}"
793
+ team_remind_recovery "$pulse_started" & recovery_pid=$!
758
794
  fi
759
- sleep "$slice" & wait $!
795
+ sleep "$slice" & sleep_pid=$!
796
+ wait "$sleep_pid"; sleep_pid=''
760
797
  done
761
798
  }
762
799
 
@@ -1463,8 +1500,8 @@ team_panel_detail_rel() { # <绝对路径> → 相对 main root(不在 root
1463
1500
  }
1464
1501
 
1465
1502
  # ---- 详情读路径的落点判据(P424)---------------------------------------------------------
1466
- # 软链不再按「路径上任一段是软链」一律拒绝:项目内的软链是用户自己的账本摆放(例如 ai_interview 的
1467
- # `docs/team → ai-interview-algo/docs/team`),读它没有越界风险。越界的定义是**解析后的落点**:
1503
+ # 软链不再按「路径上任一段是软链」一律拒绝:项目内的软链是用户自己的账本摆放(例如
1504
+ # `docs/team → module/docs/team`),读它没有越界风险。越界的定义是**解析后的落点**:
1468
1505
  # * 落点在边界内(允许根在项目内时 = 项目根的物理路径)→ 可读,并把经过的软链段如实报给详情块;
1469
1506
  # * 落点在边界外 → 拒绝,点名「真实落点」与边界(不再只报「哪一段是软链」);
1470
1507
  # * 允许根**在项目外**(绝对路径的 TEAM_DOCS_DIR / TEAM_SPEC_DIR)时没有更外层的可信锚点 ——