teamsmith 0.4.5 → 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 (81) hide show
  1. package/README.md +6 -6
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +37 -1
  4. package/skills/teamsmith/SKILL.md +32 -23
  5. package/skills/teamsmith/extension/team-bg.ts +12 -11
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +149 -5
  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 +28 -18
  13. package/skills/teamsmith/references/reminders.md +133 -98
  14. package/skills/teamsmith/references/troubleshooting.md +12 -7
  15. package/skills/teamsmith/references/workflows.md +85 -34
  16. package/skills/teamsmith/scripts/lib/cmd-agents.sh +28 -5
  17. package/skills/teamsmith/scripts/lib/cmd-project.sh +100 -15
  18. package/skills/teamsmith/scripts/lib/cmd-remind.sh +135 -10
  19. package/skills/teamsmith/scripts/lib/cmd-review.sh +42 -4
  20. package/skills/teamsmith/scripts/lib/cmd-update.sh +90 -88
  21. package/skills/teamsmith/scripts/lib/cmd-watch.sh +322 -159
  22. package/skills/teamsmith/scripts/lib/common.sh +156 -26
  23. package/skills/teamsmith/scripts/panel/panel.js +182 -182
  24. package/skills/teamsmith/scripts/panel/src/data.ts +113 -6
  25. package/skills/teamsmith/scripts/panel/src/layout.ts +26 -4
  26. package/skills/teamsmith/scripts/panel/src/main.tsx +103 -14
  27. package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
  28. package/skills/teamsmith/scripts/remind-store.mjs +404 -17
  29. package/skills/teamsmith/scripts/remind-tick.mjs +105 -0
  30. package/skills/teamsmith/scripts/reminder-delivery.mjs +76 -0
  31. package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
  32. package/skills/teamsmith/scripts/state-authority.mjs +334 -20
  33. package/skills/teamsmith/scripts/strings/commands.tsv +3 -3
  34. package/skills/teamsmith/scripts/strings/help.en.tsv +12 -12
  35. package/skills/teamsmith/scripts/strings/help.zh.tsv +12 -12
  36. package/skills/teamsmith/scripts/team +4 -3
  37. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +13 -11
  38. package/skills/teamsmith/templates/DECISIONS.md.tmpl +2 -2
  39. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +3 -3
  40. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +19 -14
  41. package/skills/teamsmith/templates/memory-seed.md.tmpl +2 -2
  42. package/skills/teamsmith/templates/pm-prompt.md.tmpl +36 -18
  43. package/skills/teamsmith/templates/report.md.tmpl +33 -0
  44. package/skills/teamsmith/tests/bg-ledger-harness.mjs +217 -33
  45. package/skills/teamsmith/tests/bg-ledger.sh +24 -10
  46. package/skills/teamsmith/tests/checkout-shape-probe.sh +7 -6
  47. package/skills/teamsmith/tests/death-cause.sh +5 -0
  48. package/skills/teamsmith/tests/fixtures/remind-adversarial-delay.ts +27 -0
  49. package/skills/teamsmith/tests/fixtures/remind-tool-provider.ts +65 -0
  50. package/skills/teamsmith/tests/help-surface.sh +14 -151
  51. package/skills/teamsmith/tests/isolation-ledger.sh +89 -0
  52. package/skills/teamsmith/tests/key-replies-ui.sh +53 -0
  53. package/skills/teamsmith/tests/key-replies.sh +307 -106
  54. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +17 -1
  55. package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
  56. package/skills/teamsmith/tests/live-capture-probe.sh +12 -2
  57. package/skills/teamsmith/tests/loop-inventory.tsv +1 -0
  58. package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
  59. package/skills/teamsmith/tests/pulse-nudge-key.sh +5 -0
  60. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +163 -0
  61. package/skills/teamsmith/tests/remind-adversarial-faults.sh +26 -0
  62. package/skills/teamsmith/tests/remind-adversarial-real.sh +27 -0
  63. package/skills/teamsmith/tests/remind-cli.sh +108 -3
  64. package/skills/teamsmith/tests/remind-delivery-node.mjs +189 -0
  65. package/skills/teamsmith/tests/remind-delivery.sh +699 -0
  66. package/skills/teamsmith/tests/remind-lifecycle.sh +197 -0
  67. package/skills/teamsmith/tests/remind-pulse.sh +199 -0
  68. package/skills/teamsmith/tests/remind-recovery-real.sh +5 -0
  69. package/skills/teamsmith/tests/remind-recovery-unit.sh +118 -0
  70. package/skills/teamsmith/tests/remind-tool-node.mjs +159 -0
  71. package/skills/teamsmith/tests/remind-tool-real.mjs +754 -0
  72. package/skills/teamsmith/tests/remind-tool-real.sh +5 -0
  73. package/skills/teamsmith/tests/reply-capture-real.mjs +93 -2
  74. package/skills/teamsmith/tests/routes.sh +213 -293
  75. package/skills/teamsmith/tests/section-paths.tsv +14 -12
  76. package/skills/teamsmith/tests/smoke.sh +876 -130
  77. package/skills/teamsmith/tests/state-authority.sh +392 -28
  78. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +58 -8
  79. package/skills/teamsmith/tests/tmux-identity-leak.sh +12 -16
  80. package/skills/teamsmith-init/SKILL.md +5 -5
  81. package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
@@ -3,7 +3,7 @@
3
3
  # 由 scripts/team 与各 cmd-*.sh source;不要直接执行。
4
4
  # 约定:所有函数名以 team_ 前缀;不依赖 jq / python / node。
5
5
 
6
- TEAM_VERSION="0.4.5"
6
+ TEAM_VERSION="0.4.7"
7
7
 
8
8
  # ---------------------------------------------------------------- 输出
9
9
  if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
@@ -509,6 +509,7 @@ team_identity_resolve() {
509
509
  TEAM_IDENTITY_INHERIT_MAIN_ROOT="${TEAM_IDENTITY_INHERIT_MAIN_ROOT-${TEAM_MAIN_ROOT:-}}"
510
510
  TEAM_IDENTITY_INHERIT_PROJECT="${TEAM_IDENTITY_INHERIT_PROJECT-${TEAM_PROJECT:-}}"
511
511
  TEAM_IDENTITY_INHERIT_SESSION="${TEAM_IDENTITY_INHERIT_SESSION-${TEAM_SESSION:-}}"
512
+ TEAM_IDENTITY_INHERIT_STATE_DIR="${TEAM_IDENTITY_INHERIT_STATE_DIR-${TEAM_STATE_DIR:-}}"
512
513
  # 注意:这六个 TEAM_IDENTITY_* 一律**不 export** —— 它们是本进程内部的判定输入,
513
514
  # 泄进子进程会让子进程拿父进程的冲突档案去判自己的身份(M40 实测:panel 的 __panel-data 孩子被误拒)。
514
515
  # M50:先在父进程上下文把目录身份装进 memo($(…) 子 shell 里的 memo 写留不下来,
@@ -771,7 +772,7 @@ team_identity_env_prefix() { # [<目标目录>]
771
772
  root="$wt"
772
773
  fi
773
774
  fi
774
- out="unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM TEAM_CONFIG_FILE"
775
+ out="unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM TEAM_CONFIG_FILE TEAM_REMINDER_ONLY_RECOVERY"
775
776
  out="$out TEAM_IDENTITY_LOCKED TEAM_IDENTITY_ROOT TEAM_IDENTITY_MAIN_ROOT TEAM_IDENTITY_PROJECT"
776
777
  out="$out TEAM_IDENTITY_INHERIT_ROOT TEAM_IDENTITY_INHERIT_MAIN_ROOT TEAM_IDENTITY_INHERIT_PROJECT TEAM_IDENTITY_INHERIT_SESSION; "
777
778
  for v in TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION; do
@@ -1147,6 +1148,25 @@ team_load_config() {
1147
1148
  # TEAM_STATE_DIR 可以被显式指定(夹具把它指到临时目录 → 队列/收件箱一点都不写进真仓库;
1148
1149
  # delivery-guard 的 spec 场景「TEAM_STATE_DIR moves the queue」就是这一条)
1149
1150
  TEAM_STATE_DIR="${TEAM_STATE_DIR:-$TEAM_MAIN_ROOT/.pi/team/state}"
1151
+ # P420 · state 目录也是「调用者身份」(与上面的身份四件套同一族):继承来的 TEAM_STATE_DIR 指向
1152
+ # **别的项目**的 `.pi/team/state` 时不许采用 —— 否则派单会按别人的席位记录判守卫(实测:PM 窗口里跑
1153
+ # 门禁,沙盒派单读到了真实项目的 state/dev.env),还会把派单提示词与 assignment 写进那个项目。
1154
+ # 临时/替代目录形状照旧生效(夹具靠它)。唯一的例外是 reload:它整条命令就是在写这个目录,
1155
+ # 判据更硬(拒绝并点名两个目录,见 team_cmd_reload)—— 所以这里不替它做决定。
1156
+ # state-authority 自己也在例外名单里:它的定位函数要看到**原始**的 state 根才能拒绝外来项目
1157
+ # (P406 的「inside another project's .pi/team」断言);先在这里替换掉,它就只能看到替换后的值。
1158
+ # Only rewrite an **inherited** value. A caller that explicitly set TEAM_STATE_DIR for this invocation
1159
+ # (the authority fixture, a deliberate alternative root) is not inheritance: the authority must see it
1160
+ # verbatim so it can refuse a foreign root instead of silently landing on the project's own one.
1161
+ # An explicit per-invocation value that names another project is still rejected by the authority's own
1162
+ # locator, so the shell boundary does not need to rewrite it.
1163
+ _sa_inherited=0
1164
+ if [ "${TEAM_STATE_DIR_EXPLICIT:-0}" != 1 ] && [ "${TEAM_STATE_DIR:-}" = "${TEAM_IDENTITY_INHERIT_STATE_DIR:-__unset__}" ] && [ -n "${TEAM_STATE_DIR:-}" ]; then _sa_inherited=1; fi
1165
+ if [ "${CMD:-}" != reload ] && [ "$_sa_inherited" = 1 ] && team_state_dir_foreign; then
1166
+ team_warn "TEAM_STATE_DIR=$TEAM_STATE_DIR 是别的项目的 state 目录(本项目是 $TEAM_MAIN_ROOT/.pi/team/state):继承值被忽略,本命令按本项目执行"
1167
+ team_dim " 清掉继承变量:env -u TEAM_STATE_DIR …(或 cd 到那个项目再执行)" >&2
1168
+ TEAM_STATE_DIR="$TEAM_MAIN_ROOT/.pi/team/state"
1169
+ fi
1150
1170
  TEAM_CLI="${TEAM_CLI:-team}"
1151
1171
  }
1152
1172
 
@@ -1209,7 +1229,7 @@ team_branch_for_agent() { # <agent> <ID> → 该 agent 在这个任务上应该
1209
1229
 
1210
1230
  # 输出一份「可直接写进派单提示词」的路径清单(agent_adapter = 当前生效的 agent 适配器)
1211
1231
  team_paths_json() {
1212
- printf '{ "project": "%s", "main_root": "%s", "worktree": "%s", "docs": "%s", "worktrees": "%s", "session": "%s", "pm_window": "%s", "agent_adapter": "%s", "agent_bin": "%s", "openspec_bin": "%s", "spec_dir": "%s", "require_magic_context": "%s", "require_openspec": "%s", "pulse_window": "%s", "pulse_interval": "%s", "js_runner": "%s", "require_js": "%s" }\n' \
1232
+ printf '{ "project": "%s", "main_root": "%s", "worktree": "%s", "docs": "%s", "worktrees": "%s", "session": "%s", "pm_window": "%s", "agent_adapter": "%s", "agent_bin": "%s", "openspec_bin": "%s", "spec_dir": "%s", "require_magic_context": "%s", "require_openspec": "%s", "pulse_window": "%s", "pulse_interval": "%s", "js_runner": "%s", "require_js": "%s", "flock_runner": "%s" }\n' \
1213
1233
  "$(team_json_escape "$TEAM_PROJECT")" "$(team_json_escape "$TEAM_MAIN_ROOT")" "$(team_json_escape "$TEAM_ROOT")" \
1214
1234
  "$(team_json_escape "$TEAM_DOCS_ABS")" "$(team_json_escape "$TEAM_MAIN_ROOT/$TEAM_WORKTREES_DIR")" \
1215
1235
  "$(team_json_escape "$TEAM_SESSION")" "$(team_json_escape "$TEAM_PM_WINDOW")" \
@@ -1217,7 +1237,8 @@ team_paths_json() {
1217
1237
  "$(team_json_escape "$(team_openspec_bin_path)")" "$(team_json_escape "$(team_spec_dir_abs)")" \
1218
1238
  "$(team_json_escape "$TEAM_REQUIRE_MAGIC_CONTEXT")" "$(team_json_escape "$TEAM_REQUIRE_OPENSPEC")" \
1219
1239
  "$(team_json_escape "$(team_pulse_window)")" "$(team_json_escape "$TEAM_PULSE_INTERVAL")" \
1220
- "$(team_json_escape "$(team_js_runner)")" "$(team_json_escape "$TEAM_REQUIRE_JS")"
1240
+ "$(team_json_escape "$(team_js_runner)")" "$(team_json_escape "$TEAM_REQUIRE_JS")" \
1241
+ "$(team_json_escape "$(team_flock_runner)")"
1221
1242
  }
1222
1243
 
1223
1244
  # ---------------------------------------------------------------- JS 运行时(必需依赖,D19)
@@ -1240,6 +1261,22 @@ team_js_runner() { # → 解析出的运行时绝对路径;解析不到(含
1240
1261
  return 0
1241
1262
  }
1242
1263
 
1264
+ # flock 的解析只有 state-authority.mjs 一份:paths、doctor 与实际事务都读它。
1265
+ # 输出 <ok|missing|unusable|unavailable>\t<路径>\t<说明>;unavailable 表示连解析助手都跑不了。
1266
+ team_flock_check() {
1267
+ local runner out
1268
+ runner="$(team_js_runner)"
1269
+ if [ -z "$runner" ]; then printf 'unavailable\t\t缺 JS 运行时,无法调用共享 flock 解析器\n'; return 0; fi
1270
+ out="$("$runner" "${TEAM_SKILL_DIR:-$(team_skill_dir)}/scripts/state-authority.mjs" --flock-check 2>/dev/null)"
1271
+ if [ -n "$out" ]; then printf '%s\n' "$out"; else printf 'unavailable\t\t共享 flock 解析器执行失败\n'; fi
1272
+ }
1273
+ team_flock_runner() {
1274
+ local st path detail
1275
+ IFS=$'\t' read -r st path detail <<< "$(team_flock_check)"
1276
+ [ "$st" = "ok" ] && printf '%s\n' "$path"
1277
+ return 0
1278
+ }
1279
+
1243
1280
  team_js_version() { # <可执行路径> → 版本字符串(v24.19.0 / 1.3.14);判不出 → 空
1244
1281
  local v
1245
1282
  v="$("$1" --version 2>/dev/null | head -1 | tr -d '[:space:]' || true)" # 留:本机可能没这项能力,按回退走
@@ -1356,6 +1393,9 @@ team_inotify_probe() {
1356
1393
  # team_tmp_root_prepare,于是跑一次 doctor 就把尚未创建的默认根建出来了,与规格
1357
1394
  # `never created by a read-only surface` 相反)。根还不存在时,探针落在最近的存在祖先上:
1358
1395
  # 与「余量行按祖先判」同一个判据,同一个文件系统,注册能力也相同。
1396
+ # P427:落地目录落在祖先上还不够 —— **运行时自己**也看 TMPDIR(Node 的编译缓存、jiti 的转换
1397
+ # 缓存、pi 插件日志都写在 `os.tmpdir()` 下),所以跑它一律走 team_readonly_run(关掉那些写入,
1398
+ # 不换目录:换目录只是换个被污染的地方)。
1359
1399
  root="$(team_tmp_root)" || root=""
1360
1400
  [ -n "$root" ] || { printf 'unavailable\n'; return 0; }
1361
1401
  probe_base="$root"
@@ -1382,9 +1422,9 @@ try {
1382
1422
  process.stdout.write(verdict + '\n')
1383
1423
  TEAM_INOTIFY_PROBE_JS
1384
1424
  if command -v timeout >/dev/null 2>&1; then
1385
- out="$(TEAM_INOTIFY_ROOT="$probe_base" TEAM_INOTIFY_NS="$ns" timeout "${TEAM_INOTIFY_PROBE_TIMEOUT:-10}" "$runner" "$script" 2>/dev/null || true)" # 留:本机可能没这项能力,按回退走
1425
+ out="$(TEAM_INOTIFY_ROOT="$probe_base" TEAM_INOTIFY_NS="$ns" team_readonly_run timeout "${TEAM_INOTIFY_PROBE_TIMEOUT:-10}" "$runner" "$script" 2>/dev/null || true)" # 留:本机可能没这项能力,按回退走
1386
1426
  else
1387
- out="$(TEAM_INOTIFY_ROOT="$probe_base" TEAM_INOTIFY_NS="$ns" "$runner" "$script" 2>/dev/null || true)" # 留:本机可能没这项能力,按回退走
1427
+ out="$(TEAM_INOTIFY_ROOT="$probe_base" TEAM_INOTIFY_NS="$ns" team_readonly_run "$runner" "$script" 2>/dev/null || true)" # 留:本机可能没这项能力,按回退走
1388
1428
  fi
1389
1429
  rm -f "$script"
1390
1430
  case "$out" in
@@ -1668,11 +1708,43 @@ team_authority_cli() { # <resolve|init|read|allocate> [参数];助手自己取
1668
1708
  main="$(team_authority_main_root)" || return 1
1669
1709
  state="${TEAM_STATE_DIR:-}"
1670
1710
  [ -n "$state" ] || { team_err "state-authority:TEAM_STATE_DIR 未解析(先 team_load_config)"; return 1; }
1711
+ # The common layer deliberately tolerates a foreign inherited state directory (it is only a warning for
1712
+ # dispatch paths), but the authority must never silently adopt it: a fixture pointing at another project's
1713
+ # .pi/team/state would otherwise start a second authority over there. The helper's locate() refuses that
1714
+ # shape, so make the shell boundary fail closed as well.
1715
+ # Unlike the ordinary warning in the common layer, this is a fail-closed refusal: the authority must
1716
+ # never silently adopt a foreign root (a fixture pointing at another project's .pi/team/state would
1717
+ # otherwise create a second authority there). Compare canonical paths, because a worktree main root
1718
+ # may be a symlink target different from the directory that was passed in.
1719
+ # Compare against the root the helper itself resolved, not against the environment variable:
1720
+ # inside a fixture that runs from another project's directory the two differ, and the refusal must
1721
+ # fire on the project the authority would actually create.
1722
+ case "$state" in
1723
+ */.pi/team/state)
1724
+ _sa_other="${state%/.pi/team/state}"
1725
+ if [ -n "$_sa_other" ] && { [ -d "$_sa_other/.git" ] || [ -f "$_sa_other/.git" ]; }; then
1726
+ if [ "$_sa_other" != "$main" ]; then
1727
+ team_err "state-authority:state 根在别的项目的 .pi/team 下(inside another project's .pi/team):$state(本项目 $main/.pi/team/state)——请传本项目自己的状态根"
1728
+ return 2
1729
+ fi
1730
+ fi
1731
+ ;;
1732
+ esac
1671
1733
  "$runner" "${TEAM_SKILL_DIR:-$(team_skill_dir)}/scripts/state-authority.mjs" --cli "$main" "$state" "$@"
1672
1734
  }
1673
- team_authority_state_root() { team_authority_cli resolve --print stateRoot; }
1674
- team_authority_init() { team_authority_cli init; }
1675
- team_authority_read() { team_authority_cli read; }
1735
+ # 只读诊断:已初始化的项目对它真实的 authority.lock 取一次排他锁,不读改快照、不建文件。
1736
+ team_authority_flock_probe() {
1737
+ local runner main state
1738
+ runner="$(team_js_runner)"
1739
+ [ -n "$runner" ] || { team_err "state-authority:缺 JS 运行时,无法验证 flock"; return 1; }
1740
+ main="$(team_authority_main_root)" || return 1
1741
+ state="${TEAM_STATE_DIR:-}"
1742
+ [ -n "$state" ] || { team_err "state-authority:TEAM_STATE_DIR 未解析"; return 1; }
1743
+ "$runner" "${TEAM_SKILL_DIR:-$(team_skill_dir)}/scripts/state-authority.mjs" --flock-lock-check "$main" "$state"
1744
+ }
1745
+ team_authority_state_root() { TEAM_AUTHORITY_CALL=1 team_authority_cli resolve --print stateRoot; }
1746
+ team_authority_init() { TEAM_AUTHORITY_CALL=1 team_authority_cli init; }
1747
+ team_authority_read() { TEAM_AUTHORITY_CALL=1 team_authority_cli read; }
1676
1748
  team_authority_allocate() { # <reminder|batch|queue> → 分配到的序号(持久 high-water,不重用)
1677
1749
  local kind="${1:-}"
1678
1750
  [ -n "$kind" ] || { team_err "state-authority:allocate 需要序号类别(reminder|batch|queue)"; return 1; }
@@ -2033,6 +2105,24 @@ team_unique_sid() {
2033
2105
  }
2034
2106
 
2035
2107
  # ---------------------------------------------------------------- 状态(PM 的仪表盘)
2108
+ # 项目身份(M40 同族;P417 的 reload 守卫与 P420 的派单身份共用**这一处**判据):
2109
+ # `<某根>/.pi/team/state` 而那个根不是本项目 = 别的项目的 state 目录。临时/替代目录形状(夹具靠它)
2110
+ # 不算:`TEAM_STATE_DIR` 允许被显式指到任何地方,只有「另一个项目的 state」才是继承事故的形状。
2111
+ team_state_dir_foreign() { # [<目录>](默认 TEAM_STATE_DIR)→ 0 = 看起来是别的项目的 state 目录
2112
+ local dir="${1:-${TEAM_STATE_DIR:-}}" root
2113
+ case "$dir" in
2114
+ */.pi/team/state) root="${dir%/.pi/team/state}" ;;
2115
+ *) return 1 ;;
2116
+ esac
2117
+ [ -n "$root" ] || return 1
2118
+ root="$(cd "$root" 2>/dev/null && pwd -P)" || return 1 # 留:目录不存在=解析不出,按“不是我们的”处理
2119
+ [ -n "$root" ] || return 1
2120
+ case "$root" in
2121
+ "$TEAM_MAIN_ROOT"|"$TEAM_MAIN_ROOT"/*) return 1 ;;
2122
+ esac
2123
+ return 0
2124
+ }
2125
+
2036
2126
  team_state_dir() { mkdir -p "$TEAM_STATE_DIR"; printf '%s\n' "$TEAM_STATE_DIR"; }
2037
2127
 
2038
2128
  team_state_set() { # <agent> <key> <value>
@@ -3107,6 +3197,8 @@ team_pm_prompt() { # PM 开场/恢复提示词(模板在 skill 内,可随 sk
3107
3197
  # 优先级裁断(也写进 `team help` 的 up 行):本次启动里 --fresh-pm **最优先** —— TEAM_PM_SESSION_ID /
3108
3198
  # TEAM_PM_RESUME_ARGS 这一次都不生效(显式的人造意图 > 持久配置键)。
3109
3199
  team_pm_fresh_launch() { [ "${TEAM_PM_FRESH_LAUNCH:-0}" = "1" ]; }
3200
+ # Only the eligible-Reminder recovery path sets this for the one start. Ordinary up/watch stays promptful.
3201
+ team_pm_reminder_only() { [ "${TEAM_REMINDER_ONLY_RECOVERY:-0}" = "1" ]; }
3110
3202
 
3111
3203
  # Required independent PM policy. No worker/default fallback, even when empty.
3112
3204
  team_pm_model_resolve() { printf '%s\n' "${TEAM_PM_MODEL:-}"; }
@@ -3274,7 +3366,7 @@ team_pm_abort_uncommitted() { # only the window started by this attempt
3274
3366
  team_tmux_kill_window "$target" || { team_err "uncommitted PM stop failed: $target;检查保存的诊断"; return 1; }
3275
3367
  }
3276
3368
 
3277
- team_pm_pi_args() { # PM 定向加载 bg/inbox-watch/reply,不加载 notify;默认 -c 延续本目录上一个会话
3369
+ team_pm_pi_args() { # PM 定向加载 bg/inbox-watch/reply/remind,不加载 notify;默认 -c 延续本目录上一个会话
3278
3370
  team_pm_identity_guard || return 1
3279
3371
  local model="$(team_pm_model_resolve)" args=()
3280
3372
  args=(--provider "${model%%/*}" --model "${model#*/}")
@@ -3283,6 +3375,8 @@ team_pm_pi_args() { # PM 定向加载 bg/inbox-watch/reply,不加载 notify;
3283
3375
  # M30:PM 的收件箱监视唤醒(投递换道:pi 通道不再往输入框粘贴)
3284
3376
  [ -d "$TEAM_SKILL_DIR" ] && args+=(-e "$TEAM_SKILL_DIR/extension/team-inbox-watch.ts")
3285
3377
  [ -d "$TEAM_SKILL_DIR" ] && args+=(-e "$TEAM_SKILL_DIR/extension/team-reply.ts")
3378
+ # P442:PM 自我提醒工具只在已验证的主检出 PM 里激活;worker 与 /team 不注入。
3379
+ [ -d "$TEAM_SKILL_DIR" ] && args+=(-e "$TEAM_SKILL_DIR/extension/team-remind.ts")
3286
3380
  [ -d "$TEAM_SKILL_DIR" ] && args+=(--skill "$TEAM_SKILL_DIR")
3287
3381
  # 续跑参数(M8.1):TEAM_PM_SESSION_ID > 显式 TEAM_PM_RESUME_ARGS > 历史的 -c。
3288
3382
  # 默认三个都空 = 与历史逐字节一致;显式配了 resume 参数就换掉默认的 -c(同一套键也服务于自定义 CLI)。
@@ -3571,12 +3665,23 @@ team_pm_launch_cmd() { # <prompt_file> <spawn_file> → respawn-pane 的 shell-c
3571
3665
  if [ -z "$(team_trim "${TEAM_PM_CMD:-}")" ]; then
3572
3666
  pi_bin="$(team_pm_bin_path)"
3573
3667
  # M40:启动前先清洗身份 env(继承的 TEAM_* 一律清掉,只写本命令推导出的身份)
3574
- printf '%s%sexport TEAM_STATE_DIR=%q TEAM_CONFIG_FILE=%q TEAM_PM_WINDOW=%q; cd %q && printf "%%s\\n" $$ > %q && exec %q %s @%q' \
3575
- "$(team_identity_env_prefix "$TEAM_MAIN_ROOT")" "$(team_tmux_shim_exports)" \
3576
- "$TEAM_STATE_DIR" "${TEAM_CONFIG:-${TEAM_CONFIG_FILE:-}}" "$TEAM_PM_WINDOW" \
3577
- "$TEAM_MAIN_ROOT" "$spawnfile" "$pi_bin" "$(team_pm_pi_args)" "$pf"
3668
+ if team_pm_reminder_only; then
3669
+ printf '%s%sexport TEAM_STATE_DIR=%q TEAM_CONFIG_FILE=%q TEAM_PM_WINDOW=%q TEAM_REMINDER_ONLY_RECOVERY=1; cd %q && printf "%%s\\n" $$ > %q && exec %q %s' \
3670
+ "$(team_identity_env_prefix "$TEAM_MAIN_ROOT")" "$(team_tmux_shim_exports)" \
3671
+ "$TEAM_STATE_DIR" "${TEAM_CONFIG:-${TEAM_CONFIG_FILE:-}}" "$TEAM_PM_WINDOW" \
3672
+ "$TEAM_MAIN_ROOT" "$spawnfile" "$pi_bin" "$(team_pm_pi_args)"
3673
+ else
3674
+ printf '%s%sexport TEAM_STATE_DIR=%q TEAM_CONFIG_FILE=%q TEAM_PM_WINDOW=%q; cd %q && printf "%%s\\n" $$ > %q && exec %q %s @%q' \
3675
+ "$(team_identity_env_prefix "$TEAM_MAIN_ROOT")" "$(team_tmux_shim_exports)" \
3676
+ "$TEAM_STATE_DIR" "${TEAM_CONFIG:-${TEAM_CONFIG_FILE:-}}" "$TEAM_PM_WINDOW" \
3677
+ "$TEAM_MAIN_ROOT" "$spawnfile" "$pi_bin" "$(team_pm_pi_args)" "$pf"
3678
+ fi
3578
3679
  return 0
3579
3680
  fi
3681
+ if team_pm_reminder_only; then
3682
+ team_err 'Reminder-only recovery supports the built-in Pi PM only; a custom adapter has no verified prompt-free watcher contract'
3683
+ return 1
3684
+ fi
3580
3685
  expanded="$(team_agent_expand pm "$TEAM_PM_CMD" pm "${TEAM_PM_SESSION_ID:-}" \
3581
3686
  "$TEAM_MAIN_ROOT" "$pf" "" "" "$(team_pm_model_resolve)")" || return 1
3582
3687
  # 裸名字 → 解析出的绝对路径(M8.1 退回点 1;见 team_pm_subst_first_word 的注释)。
@@ -3660,6 +3765,7 @@ team_pm_continuity_note() { # 打在启动成功之后:延续 or 明确说「
3660
3765
  # 否则从 respawn 到拿到证据之间那一拍看起来像「没有 PM」,并发的另一拍会把刚刚起来的 PM 杀掉。
3661
3766
  team_pm_start() {
3662
3767
  local target state cmd pf i wait apid age
3768
+ TEAM_PM_START_OUTCOME=''
3663
3769
  target="$(team_pm_target)"
3664
3770
  team_pm_window_exists || return 1
3665
3771
  # 已经有一次启动在飞行中(同一窗口、标记新鲜)→ 不重复拉起:再 respawn 一次会把
@@ -3668,11 +3774,12 @@ team_pm_start() {
3668
3774
  if team_pm_starting; then
3669
3775
  age="$(team_pm_starting_age || echo '?')"
3670
3776
  team_dim " PM 正在启动(${age}s 前发起,证据:$(team_pm_evidence)):不重复拉起"
3777
+ TEAM_PM_START_OUTCOME='already-starting'
3671
3778
  return 0
3672
3779
  fi
3673
3780
  state="$(team_pm_state)"
3674
3781
  case "$state" in
3675
- running:*) team_dim " PM 已在运行(${state#running:})"; return 0 ;;
3782
+ running:*) team_dim " PM 已在运行(${state#running:})"; TEAM_PM_START_OUTCOME='already-running'; return 0 ;;
3676
3783
  idle:*) ;;
3677
3784
  unknown:*)
3678
3785
  local ucwd; ucwd="$(team_pane_cwd "$target" 2>/dev/null || echo '?')" # 留:进程/窗口可能刚消失(竞态),调用方按空值处理
@@ -3691,8 +3798,12 @@ team_pm_start() {
3691
3798
  team_pm_identity_guard || return 1
3692
3799
  team_pm_check_launch
3693
3800
  team_pm_check_bin
3801
+ if team_pm_reminder_only && [ -n "$(team_trim "${TEAM_PM_CMD:-}")" ]; then
3802
+ team_err 'Reminder-only recovery 不支持自定义 PM adapter(没有 prompt-free Pi watcher 契约)'
3803
+ return 1
3804
+ fi
3694
3805
  local pm_nonce="$(date +%s)-$BASHPID-$RANDOM-$RANDOM"
3695
- pf="$(team_pm_write_prompt)"
3806
+ if team_pm_reminder_only; then pf=''; else pf="$(team_pm_write_prompt)"; fi
3696
3807
  # spawn 证明(M6.3 F30):让 pane 里的 shell 在 exec 之前把自己的 pid 写盘。
3697
3808
  # wrapper agent(脚本最后 exec 掉自己,用来钉环境变量/flags)会换掉进程映像,
3698
3809
  # 配置的 agent 名字就看不到了 —— 但那个 pid 仍然是我们启动的、还在本项目里。
@@ -3726,6 +3837,7 @@ team_pm_start() {
3726
3837
  }
3727
3838
  team_pm_starting_end
3728
3839
  team_pm_continuity_note # 延续了就说怎么延续;没延续就明说 + 指出靠 docs/team/** 与 inbox 接手
3840
+ TEAM_PM_START_OUTCOME='started'
3729
3841
  return 0
3730
3842
  fi
3731
3843
  apid="$(team_pm_spawn_pid 2>/dev/null || true)" # 留:进程/窗口可能刚消失(竞态),调用方按空值处理
@@ -3737,6 +3849,7 @@ team_pm_start() {
3737
3849
  }
3738
3850
  team_pm_starting_end
3739
3851
  team_pm_continuity_note
3852
+ TEAM_PM_START_OUTCOME='started'
3740
3853
  return 0
3741
3854
  fi
3742
3855
  i=$((i + 1))
@@ -3754,6 +3867,7 @@ team_pm_start() {
3754
3867
  team_dim " 手工复现:在隔离窗口跑诊断中的 render;或写绝对路径:TEAM_PM_BIN=/abs/path/<cli> $TEAM_CLI up" >&2
3755
3868
  team_dim " 常见原因:CLI 在窗口的登录 PATH 里不存在(本工具已把裸名字换成解析出的绝对路径)、参数/模型不认、未登录" >&2
3756
3869
  team_pm_abort_uncommitted "$target"
3870
+ TEAM_PM_START_OUTCOME='failed'
3757
3871
  return 1
3758
3872
  }
3759
3873
 
@@ -4175,6 +4289,22 @@ team_tmp_root_ancestor_note() { # <path> → "" 或「(尚未创建,按 <祖
4175
4289
  printf '(尚未创建,按 %s 的文件系统判)' "$a"
4176
4290
  }
4177
4291
 
4292
+ # ---------------------------------------------------------------- 只读面的子进程环境(P427)
4293
+ # 只读面不许替操作者把根建出来(规格 verification:`never created by a read-only surface`),
4294
+ # 也**不许把这份写入挪到另一个目录**去换个地方污染(独立复核 2026-11-09:把子进程 TMPDIR 指到
4295
+ # 最近的存在祖先,于是缓存落在了被检的基准目录里 —— 只是换了个地方留下东西)。
4296
+ # 写入的来源是**子进程自己**:Node ≥ 23 的编译缓存、jiti 的转换缓存、pi 插件(magic-context)的
4297
+ # 日志默认都落在 `os.tmpdir()` 下,并会把那个目录递归建出来。2026-11-07 夜间实测:
4298
+ # `TMPDIR=<尚不存在的目录> pi --version` 把整个根建了出来(里面是 `node-compile-cache/`)。
4299
+ # 所以只读面交给子进程的不是「另一个临时目录」,而是**关掉这些写入的开关**(探针命令用环境变量
4300
+ # 关缓存是既有做法,同 GIT_OPTIONAL_LOCKS=0 / PIP_NO_CACHE_DIR=1);TMPDIR 原样不动。
4301
+ # 根不存在时:余量行照旧按最近的存在祖先判、报告照旧读解析出的那个根。
4302
+ # 新的写入者会被 §40 咬住(「显式根跑完仍然不存在」「默认基准下一个条目没多」)—— 到那时在这里
4303
+ # 补一个开关,而不是换目录。
4304
+ team_readonly_run() { # <cmd> [args...] → 子进程的 stdout/stderr/rc 原样
4305
+ NODE_DISABLE_COMPILE_CACHE=1 JITI_FS_CACHE=false MAGIC_CONTEXT_LOG_PATH=/dev/null "$@"
4306
+ }
4307
+
4178
4308
  # 「谁负责建这个还不存在的根」——只对**不存在**的根说话(存在时返回空串)。三条腿三种答案,
4179
4309
  # 绝不用一句话糊过去(V59 §1.4:把「不会被创建」这层意思按 source 挡住,配置来的根就只剩「还没有」,
4180
4310
  # 读者会以为它会自己出现):
@@ -4658,18 +4788,18 @@ team_pending_nudge_empty() { # <counts|空=现读> → 0 = 没有正类别(空
4658
4788
  }
4659
4789
 
4660
4790
  # ---------------------------------------------------------------- 待命(PM 主动停工)
4661
- team_standby_file() { printf '%s\n' "$TEAM_STATE_DIR/standby"; }
4791
+ # 读写都走项目状态权威(scripts/state-authority.mjs 的事务) —— 统一状态里的 standby 槽位是唯一真相,
4792
+ # 旧的 state/standby 标记只由迁移读一次,之后就不再被当成真相。这里没有第二个文件、第二把锁;
4793
+ # 缺 flock / 等锁超时 / 快照读不懂都由权威层显式失败(不落回写文件,也不冒充「已关掉」)。
4794
+ # 读(status / in_standby / 面板)不建定位器、不发布快照:展示路径不写盘。
4662
4795
  team_standby_on() { # <reason>
4663
- mkdir -p "$TEAM_STATE_DIR"
4664
- printf '%s %s\n' "$(team_timestamp)" "${1:--}" > "$(team_standby_file)"
4665
- }
4666
- team_standby_off() { rm -f "$(team_standby_file)"; }
4667
- team_standby_reason() {
4668
- local f; f="$(team_standby_file)"
4669
- [ -f "$f" ] || return 1
4670
- sed -n '1p' "$f" | cut -d' ' -f2-
4796
+ team_authority_cli standby-on --reason "${1:--}" >/dev/null
4671
4797
  }
4672
- team_in_standby() { [ -f "$(team_standby_file)" ]; }
4798
+ team_standby_off() { team_authority_cli standby-off >/dev/null; }
4799
+ team_standby_reason() { team_authority_cli standby-read --print reason; }
4800
+ team_standby_status() { team_authority_cli standby-read; } # 已渲染好的一行:standby: on(自 …,原因:…)
4801
+ team_standby_migrate() { team_authority_cli standby-import; }
4802
+ team_in_standby() { [ "$(team_authority_cli standby-read --print on)" = "true" ]; }
4673
4803
 
4674
4804
  # 提醒(叫醒)PM:只写记录 + 尽力敲一下窗口,不靠它保证送达
4675
4805
  # P174:第二个参数是**叫醒键**(类别集合,省略时按当前快照现算)——watchdog.nudge 与