teamsmith 0.4.3 → 0.4.6

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 (44) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +33 -1
  4. package/skills/teamsmith/SKILL.md +1 -1
  5. package/skills/teamsmith/extension/team-bg.ts +7 -8
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +136 -3
  7. package/skills/teamsmith/references/protocol.md +2 -3
  8. package/skills/teamsmith/references/reminders.md +55 -12
  9. package/skills/teamsmith/references/workflows.md +1 -3
  10. package/skills/teamsmith/scripts/lib/cmd-agents.sh +18 -1
  11. package/skills/teamsmith/scripts/lib/cmd-project.sh +12 -9
  12. package/skills/teamsmith/scripts/lib/cmd-remind.sh +49 -10
  13. package/skills/teamsmith/scripts/lib/cmd-update.sh +90 -88
  14. package/skills/teamsmith/scripts/lib/cmd-watch.sh +281 -155
  15. package/skills/teamsmith/scripts/lib/common.sh +74 -14
  16. package/skills/teamsmith/scripts/panel/panel.js +134 -134
  17. package/skills/teamsmith/scripts/panel/src/data.ts +51 -0
  18. package/skills/teamsmith/scripts/panel/src/layout.ts +10 -0
  19. package/skills/teamsmith/scripts/panel/src/main.tsx +27 -0
  20. package/skills/teamsmith/scripts/remind-store.mjs +362 -6
  21. package/skills/teamsmith/scripts/remind-tick.mjs +102 -0
  22. package/skills/teamsmith/scripts/reminder-delivery.mjs +76 -0
  23. package/skills/teamsmith/scripts/reply-capture.mjs +53 -8
  24. package/skills/teamsmith/scripts/state-authority.mjs +265 -17
  25. package/skills/teamsmith/scripts/strings/commands.tsv +3 -3
  26. package/skills/teamsmith/scripts/strings/help.en.tsv +12 -12
  27. package/skills/teamsmith/scripts/strings/help.zh.tsv +12 -12
  28. package/skills/teamsmith/scripts/team +3 -3
  29. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +2 -3
  30. package/skills/teamsmith/templates/pm-prompt.md.tmpl +11 -5
  31. package/skills/teamsmith/tests/death-cause.sh +5 -0
  32. package/skills/teamsmith/tests/help-surface.sh +15 -150
  33. package/skills/teamsmith/tests/isolation-ledger.sh +85 -0
  34. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +17 -1
  35. package/skills/teamsmith/tests/live-capture-probe.sh +63 -0
  36. package/skills/teamsmith/tests/pulse-nudge-key.sh +5 -0
  37. package/skills/teamsmith/tests/remind-delivery-node.mjs +176 -0
  38. package/skills/teamsmith/tests/remind-delivery.sh +611 -0
  39. package/skills/teamsmith/tests/section-paths.tsv +6 -6
  40. package/skills/teamsmith/tests/smoke.sh +397 -107
  41. package/skills/teamsmith/tests/state-authority.sh +246 -26
  42. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +58 -8
  43. package/skills/teamsmith/tests/tmux-identity-leak.sh +12 -16
  44. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -741,11 +741,22 @@ team_cmd_watch() {
741
741
  team_hdr "teamsmith pulse · $TEAM_PROJECT(每 ${interval}s 一次;Ctrl-C 退出)"
742
742
  team_dim " 只做两件事:记录容量趋势 | PM 没在跑就在它的窗口里把 $(team_pm_cli_name) 拉起来"
743
743
  team_dim " 不管 tmux 布局,不管 agent(agent 归 PM 管:team resume)"
744
+ # agent-self-reminder 4.1:巡检节拍之外再加一个**轻量**的到期检查(默认 I10s)。它不是第二个后端、
745
+ # 不重扫项目、不调用模型:remind-tick.mjs 读一份有界快照,只在真到点时拿一次权威锁。完整巡检的
746
+ # 周期不变(下一个巡检点按 duration 从本次结束算,不会因为切片而变密)。
747
+ local slice="${TEAM_REMIND_TICK_SECS:-10}" next_patrol=0 now pulse_started
748
+ case "$slice" in ''|*[!0-9]*|0) slice=10 ;; esac
749
+ pulse_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
744
750
  while :; do
745
- # M9.8:判定必须用磁盘上的代码(漂移就重启本进程)—— 否则唤醒理由可能比 digest 旧
746
- team_watch_reexec_if_stale "$fp0" watch ${argv[@]+"${argv[@]}"}
747
- team_watch_once
748
- sleep "$interval" & wait $!
751
+ now="$(date +%s)"
752
+ team_remind_due_tick "$pulse_started"
753
+ if [ "$now" -ge "$next_patrol" ]; then
754
+ # M9.8:判定必须用磁盘上的代码(漂移就重启本进程)—— 否则唤醒理由可能比 digest 旧
755
+ team_watch_reexec_if_stale "$fp0" watch ${argv[@]+"${argv[@]}"}
756
+ team_watch_once
757
+ next_patrol=$(( $(date +%s) + interval ))
758
+ fi
759
+ sleep "$slice" & wait $!
749
760
  done
750
761
  }
751
762
 
@@ -975,8 +986,9 @@ team_panel_pm_json() { # PM 状态用**闭集**词表:running|starting|absent|
975
986
  }
976
987
 
977
988
  team_panel_standby_json() {
978
- if team_in_standby; then
979
- printf '{"on": true, "reason": %s}' "$(team_panel_json_str "$(team_standby_reason || echo '-')")"
989
+ # 全屏面板吞不下诊断(stderr 会弄花整帧):读不到权威时按 off 显示,诊断留给 `team standby status`。
990
+ if team_in_standby 2>/dev/null; then
991
+ printf '{"on": true, "reason": %s}' "$(team_panel_json_str "$(team_standby_reason 2>/dev/null || echo '-')")"
980
992
  else
981
993
  printf '{"on": false, "reason": ""}'
982
994
  fi
@@ -1252,9 +1264,10 @@ team_panel_change_tasks_json() { # <change id> → "tasks": [...], "tasks_more":
1252
1264
  team_panel_changes_json() {
1253
1265
  local spec_dir dir bin listed="" src="dir" out="[" first=1 id done total age phase n_changes=0
1254
1266
  spec_dir="$(team_spec_dir_abs)"; dir="$spec_dir/changes"
1255
- # F3:`openspec`(或它到项目根之间的段)或 `openspec/changes` 是软链时,本块不列任何条目 ——
1256
- # 只读预览的合同是「只读 openspec 目录内、不得读穿」,列表跟详情一样按同一条判据拒绝。
1257
- if team_panel_detail_symlink_hit "$spec_dir" "$dir" >/dev/null; then
1267
+ # 软链按**落点**判(P424):`openspec` 或 `openspec/changes` 整体搬到项目内别处照常列;
1268
+ # 落点在项目根外才一条都不列 —— 列表跟详情走同一条判据,不把根外条目画成可 enter 的行。
1269
+ if ! team_panel_detail_container_ok "$spec_dir" "$spec_dir" \
1270
+ || ! team_panel_detail_container_ok "$spec_dir" "$dir"; then
1258
1271
  printf '{"available": false, "source": "none", "changes": [], "count": 0}'; return 0
1259
1272
  fi
1260
1273
  bin="$(team_openspec_bin_path 2>/dev/null || true)"
@@ -1296,8 +1309,9 @@ team_panel_changes_json() {
1296
1309
  team_panel_specs_json() {
1297
1310
  local spec_dir bin listed="" src="dir" out="[" first=1 name reqs count=0 total=0 line
1298
1311
  spec_dir="$(team_spec_dir_abs)"
1299
- # F3:同 changes —— `openspec`(含到项目根之间的段)或 `openspec/specs` 是软链时不列。
1300
- if team_panel_detail_symlink_hit "$spec_dir" "$spec_dir/specs" >/dev/null; then
1312
+ # 同 changes:软链按落点判,项目内照常列,根外一条都不列。
1313
+ if ! team_panel_detail_container_ok "$spec_dir" "$spec_dir" \
1314
+ || ! team_panel_detail_container_ok "$spec_dir" "$spec_dir/specs"; then
1301
1315
  printf '{"available": false, "count": 0, "requirements": 0, "specs": []}'; return 0
1302
1316
  fi
1303
1317
  bin="$(team_openspec_bin_path 2>/dev/null || true)"
@@ -1334,8 +1348,10 @@ team_panel_specs_json() {
1334
1348
 
1335
1349
  team_panel_decisions_json() { # DECISIONS.md:标题数 + 最新三条(新→旧)
1336
1350
  local f="$TEAM_DOCS_ABS/DECISIONS.md" out="[" first=1 line count=0
1337
- # F3:`docs`(或它到项目根之间的段)是软链时,条目不列(详情面会点名那一段)。
1338
- if team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$f" >/dev/null; then
1351
+ # 软链按落点判:账本搬到项目内别处(例如 `docs/team` 指到项目内另一棵树)照常列,
1352
+ # 落点在项目根外才不列(详情面会点名真实落点与项目根)。
1353
+ if ! team_panel_detail_container_ok "$TEAM_DOCS_ABS" "$TEAM_DOCS_ABS" \
1354
+ || ! team_panel_detail_container_ok "$TEAM_DOCS_ABS" "$f"; then
1339
1355
  printf '{"count": 0, "recent": []}'; return 0
1340
1356
  fi
1341
1357
  [ -f "$f" ] || { printf '{"count": 0, "recent": []}'; return 0; }
@@ -1437,35 +1453,104 @@ team_panel_settings_json() {
1437
1453
  # `--file` 只服务**发现集里的**路径:任何别的路径都非 0 且不打印内容——面板不会变成任意文件读取器。
1438
1454
  # 正文上限 128 KiB(超出截断并带 truncated 标记),UTF-8 边界用 iconv -c 收尾。
1439
1455
 
1440
- # 发现记录:每行 `<相对路径>\t<tab 名>\t<字节数>\t<软链 0|1>`,顺序 = 树上/账本上的呈现序。
1456
+ # 发现记录:每行 `<相对路径>\t<tab 名>\t<字节数>\t<flag>\t<note>`,顺序 = 树上/账本上的呈现序。
1441
1457
  # source 缺省 entry(既有语义逐字不变);spec/change/decision 三类见各自函数。
1442
- # 软链的路径照旧出现在记录里但带 `1` 标记:json 把它排除出发现集(`--file` 选不到它)并在 reason 里点名。
1458
+ # P424:flag=0 = 可服务(note = 路径上经过的软链段,`|` 连接,可为空),flag=1 = 拒绝(note = 真实
1459
+ # 落点与边界)。被拒的路径排除出发现集(`--file` 选不到它)并在 reason 里点名两个路径。
1443
1460
  team_panel_detail_rel() { # <绝对路径> → 相对 main root(不在 root 下时原样)
1444
1461
  local f="$1"
1445
1462
  case "$f" in "$TEAM_MAIN_ROOT"/*) printf '%s' "${f#"$TEAM_MAIN_ROOT"/}" ;; *) printf '%s' "$f" ;; esac
1446
1463
  }
1447
1464
 
1448
- # F1 返修:目录段软链与叶软链一视同仁 —— 只挡叶节点时,`changes/<id>` / `specs/<cap>` 这一层是指向
1449
- # 根外(读穿 openspec 根)或根内另一个 change / `archive/`(越权服务)的软链,都会被当成正常路径。
1450
- # F3 返修:锚点从**源根**提到**项目根** —— `openspec` 本身、`docs` 本身也在被读路径上,必须一起判;
1451
- # 只从源根往下走,项目根到源根之间的段是软链时四类预览照样读树外正文。
1452
- # 沿**项目根 → 候选路径**逐段判定:命中软链就打印**那一段**(相对 main root)并退 0;整条路径没有软链退 1。
1453
- # 包含关系仍按调用方给的允许根判(`p` 必须在 `root` 之下);项目根自己(`p == TEAM_MAIN_ROOT`)不判 ——
1454
- # 项目根本身是软链属于本机布局,不在本合同的拒绝面里(路径前缀由 `read_nofollow` 的物理路径比对处理)。
1455
- team_panel_detail_symlink_hit() { # <允许根 abs> <候选路径 abs>
1456
- local root="$1" p="$2" rel cur c
1457
- case "$root" in "$TEAM_MAIN_ROOT"|"$TEAM_MAIN_ROOT"/*) ;; *) return 1 ;; esac
1458
- case "$p" in "$root"|"$root"/*) ;; *) return 1 ;; esac
1459
- rel="${p#"$TEAM_MAIN_ROOT"/}"
1460
- [ "$rel" != "$p" ] || return 1
1465
+ # ---- 详情读路径的落点判据(P424)---------------------------------------------------------
1466
+ # 软链不再按「路径上任一段是软链」一律拒绝:项目内的软链是用户自己的账本摆放(例如 ai_interview 的
1467
+ # `docs/team → ai-interview-algo/docs/team`),读它没有越界风险。越界的定义是**解析后的落点**:
1468
+ # * 落点在边界内(允许根在项目内时 = 项目根的物理路径)→ 可读,并把经过的软链段如实报给详情块;
1469
+ # * 落点在边界外 → 拒绝,点名「真实落点」与边界(不再只报「哪一段是软链」);
1470
+ # * 允许根**在项目外**(绝对路径的 TEAM_DOCS_DIR / TEAM_SPEC_DIR)时没有更外层的可信锚点 ——
1471
+ # 边界就是那个根自己(与改动前的锚点语义一致,不把根外布局读穿)。
1472
+ # 判据只有这一份:发现面(能不能进发现集)、读面(open 之后从 fd 量身份与落点)与列表块都用它。
1473
+ team_panel_detail_project_real() { # 项目根的物理路径(TEAM_MAIN_ROOT 自己是软链属本机布局)
1474
+ local real
1475
+ real="$(cd "$TEAM_MAIN_ROOT" 2>/dev/null && pwd -P)" || return 1
1476
+ printf '%s' "${real:-/}"
1477
+ }
1478
+
1479
+ # 逐段解析到物理落点:先跟完叶节点的软链(环上限 40),再把父目录 `pwd -P`(中间段软链一起解析)。
1480
+ # 落点不存在 / 解析不出 → rc 1(调用方按「不可读」处理,不做更宽的猜)。
1481
+ team_panel_detail_landing() { # <abs> → 物理落点
1482
+ local p="$1" d b t hops=0
1483
+ case "$p" in /*) ;; *) return 1 ;; esac
1484
+ while [ -L "$p" ]; do
1485
+ hops=$((hops + 1))
1486
+ [ "$hops" -le 40 ] || return 1
1487
+ t="$(readlink -- "$p" 2>/dev/null)" || return 1
1488
+ [ -n "$t" ] || return 1
1489
+ case "$t" in
1490
+ /*) p="$t" ;;
1491
+ *) d="$(dirname -- "$p")"; p="$d/$t" ;;
1492
+ esac
1493
+ done
1494
+ [ -e "$p" ] || return 1
1495
+ d="$(cd "$(dirname -- "$p")" 2>/dev/null && pwd -P)" || return 1
1496
+ b="$(basename -- "$p")" || return 1
1497
+ case "$d" in /) printf '/%s' "$b" ;; *) printf '%s/%s' "${d%/}" "$b" ;; esac
1498
+ }
1499
+
1500
+ # 落点边界:允许根在项目内(或允许根本身就是项目根)→ 项目根的物理路径;允许根在项目外 → 允许根自己。
1501
+ # 拿不到允许根的物理路径 → rc 1(fail-closed:拿不到边界就不放行)。
1502
+ team_panel_detail_boundary() { # <允许根|->
1503
+ local root="${1:-}" real
1504
+ case "$root" in
1505
+ -|'') root="$TEAM_MAIN_ROOT" ;;
1506
+ esac
1507
+ case "$root" in
1508
+ "$TEAM_MAIN_ROOT"|"$TEAM_MAIN_ROOT"/*) team_panel_detail_project_real ;;
1509
+ *)
1510
+ [ -d "$root" ] || return 1
1511
+ real="$(cd "$root" 2>/dev/null && pwd -P)" || return 1
1512
+ printf '%s' "${real%/}"
1513
+ ;;
1514
+ esac
1515
+ }
1516
+
1517
+ team_panel_detail_within() { # <边界 abs> <落点 abs>
1518
+ case "$2" in "$1"|"$1"/*) return 0 ;; esac
1519
+ return 1
1520
+ }
1521
+
1522
+ # 落点判定:rc=0 在边界内;rc=1 越界(打印「<真实落点> 不在 <边界> 内」);rc=5 解析不出。
1523
+ # 调用方把 rc=1 的这段字串拼进「软链拒绝:」后面的原因里 —— 两个路径都点名,排错时不用猜。
1524
+ team_panel_detail_landing_reason() { # <允许根> <abs>
1525
+ local root="$1" abs="$2" real boundary
1526
+ real="$(team_panel_detail_landing "$abs")" || return 5
1527
+ boundary="$(team_panel_detail_boundary "$root")" || return 5
1528
+ team_panel_detail_within "$boundary" "$real" && return 0
1529
+ printf '%s 不在 %s 内' "$real" "$boundary"
1530
+ return 1
1531
+ }
1532
+
1533
+ # 容器段(`openspec`、`docs`、`docs/team` 这类目录/文件):不存在的段不在这里判(缺目录由各块自己的
1534
+ # 缺省分支处理),存在就必须落在边界内 —— 列表块用它决定「照常列」还是「一条都不列」。
1535
+ team_panel_detail_container_ok() { # <允许根> <abs 目录/文件>
1536
+ [ -e "$2" ] || return 0
1537
+ team_panel_detail_landing_reason "$1" "$2" >/dev/null
1538
+ }
1539
+
1540
+ # 路径上从项目根到候选的**软链段**(相对项目根,`|` 连接;没有软链 → 空)。详情块把它当排错线索
1541
+ # 如实报告(`links` 字段),不当错误:项目内软链是合法布局。
1542
+ team_panel_detail_link_segs() { # <abs>
1543
+ local abs="$1" rel cur c out=""
1544
+ rel="$(team_panel_detail_rel "$abs")"
1545
+ [ "$rel" != "$abs" ] || return 0
1461
1546
  cur="$TEAM_MAIN_ROOT"
1462
1547
  local IFS=/
1463
1548
  for c in $rel; do
1464
1549
  [ -n "$c" ] || continue
1465
1550
  cur="$cur/$c"
1466
- if [ -L "$cur" ]; then team_panel_detail_rel "$cur"; return 0; fi
1551
+ if [ -L "$cur" ]; then out="${out:+$out|}${cur#"$TEAM_MAIN_ROOT"/}"; fi
1467
1552
  done
1468
- return 1
1553
+ printf '%s' "$out"
1469
1554
  }
1470
1555
 
1471
1556
  team_panel_detail_source_root() { # <source> → 该 source 的允许根(entry/decision 不走软链目录判定)
@@ -1484,49 +1569,33 @@ team_panel_detail_stat_id() { # <follow|nofollow> <路径>
1484
1569
  esac
1485
1570
  }
1486
1571
 
1487
- # F2 返修:把「判」与「读」合成原子 —— 一次 open,之后只从**同一个 fd** 读。
1488
- # 两轮动过的三种窗口都在这一个函数里关掉:
1489
- # ① fd 打开到的目标(`stat -L`)必须等于 ② 路径此刻的不跟随身份(`stat`)—— 叶节点在 open 前/后被换成
1490
- # 软链、或被换成另一个文件,两者必不相同(第一轮承诺的「发现之后、读之前被换也不读」在这里才成立);
1491
- # ③ 路径的每一段(含允许根本身)此刻都不是软链 —— 中间目录在 open 之后被换成软链也会命中(① 对
1492
- # 中间段无能为力:lstat 会跟完前缀,两侧拿到的都是树外那个目标)。
1493
- # 正文只从 ① 里那个 fd 读,所以「判据作用的对象」与「读出的内容」是同一个 inode。
1494
- # rc=0 读到(可能空正文 —— 与今天 `head -c` 打不开同形);rc=3 被换/命中软链(调用者按「软链拒绝」点名);
1495
- # rc=4 既没有 /proc/self/fd 也没有 /dev/fd:拿不到 fd 身份就不读(宁可拒,也不拿可能被换过的路径去读)。
1572
+ # 读面判据(P424):把「判」与「读」合成原子 —— 一次 open,之后只从**同一个 fd** 读。
1573
+ # * 落点 = fd 解析出的物理路径(`/proc/self/fd`,`/dev/fd` 兜底),必须在**边界**内:项目内的软链
1574
+ # (`docs/team` 指到项目内别处、`openspec` 整体搬家)照常读,越界(`/etc`、项目外的工作树…)仍然
1575
+ # 一个字节都不读。
1576
+ # * `stat -L` 的 fd 身份必须等于 `stat -L` 路径此刻的身份 —— open 前后被换成别的文件(含换成软链)
1577
+ # 仍然拒绝;正文只从 fd 读,所以「判据作用的对象」与「读出的内容」是同一个 inode。
1578
+ # * 非普通文件(FIFO、设备、目录、坏链)在 open **之前**就挡下:bash 没有 O_NONBLOCK 的 open,
1579
+ # FIFO 的 open 会一直等写者。发现面已按 `-f` 过滤过一次,这里是读前再判一次。
1580
+ # rc=0 读到(可能空正文 —— 与 `head -c` 打不开同形);rc=3 越界 / open 前后被换;rc=4 既没有
1581
+ # /proc/self/fd 也没有 /dev/fd(拿不到 fd 身份就不读,宁可拒也不拿可能被换过的路径去读)。
1496
1582
  # `<cap>` 写 `-` = 读到 EOF(决策源要拿到整篇才能切片)。
1497
1583
  team_panel_detail_read_nofollow() { # <允许根|-> <abs> <cap>
1498
- local root="$1" abs="$2" cap="$3" id_fd="" id_path="" p
1584
+ local root="$1" abs="$2" cap="$3" id_fd="" id_path="" p boundary real
1585
+ [ -f "$abs" ] || return 0
1499
1586
  { exec 9<"$abs"; } 2>/dev/null || return 0
1500
1587
  for p in /proc/self/fd/9 /dev/fd/9; do
1501
1588
  id_fd="$(team_panel_detail_stat_id follow "$p")"
1502
1589
  [ -n "$id_fd" ] && break
1503
1590
  done
1504
1591
  if [ -z "$id_fd" ]; then exec 9<&-; return 4; fi
1505
- id_path="$(team_panel_detail_stat_id nofollow "$abs")"
1592
+ id_path="$(team_panel_detail_stat_id follow "$abs")"
1506
1593
  if [ -z "$id_path" ] || [ "$id_fd" != "$id_path" ]; then exec 9<&-; return 3; fi
1507
- # F3/F4 返修:判据作用于**读的那个对象** —— 句柄自己解析出的路径(open 那一刻固定)必须逐字节等于
1508
- # 「锚点真实路径 + 字面相对路径」。锚点默认是**项目根**,所以 `openspec`/`docs` 本身、中间目录、叶节点
1509
- # 在 open 时是不是软链,在这一条里一次性可见(F2 的「读前再判一次」是按路径名走的,中间段换回真目录
1510
- # 就放行)。允许根不在项目树内(例如绝对路径的 TEAM_DOCS_DIR)时退回允许根做锚点:那类布局没有更外层
1511
- # 的可信锚点,仍按叶/前缀的物理路径比对。拿不到 fd 路径或锚点就拒绝(fail-closed)。
1512
- local fd_real root_real rel_real anchor="$TEAM_MAIN_ROOT"
1513
- case "$root" in
1514
- -|'') anchor="" ;;
1515
- "$TEAM_MAIN_ROOT"|"$TEAM_MAIN_ROOT"/*) ;;
1516
- *) anchor="$root" ;;
1517
- esac
1518
- # 判据无条件生效(没有「某条件不满足就跳过」的旁路):候选路径**必须**落在锚点之下,且句柄解析出的
1519
- # 路径**必须逐字节等于**「锚点真实路径 + 字面相对路径」。现有调用图里 abs 全部由允许根与发现集拼出,
1520
- # 前缀不匹配这条分支不可达;把它写成拒绝(而不是跳过)是为了让未来的调用方出错时也 fail-closed。
1521
- if [ -n "$anchor" ]; then
1522
- case "$abs" in "$anchor"/*) rel_real="${abs#"$anchor"/}" ;; *) exec 9<&-; return 3 ;; esac
1523
- fd_real="$(readlink /proc/self/fd/9 2>/dev/null || readlink /dev/fd/9 2>/dev/null)"
1524
- root_real="$(cd "$anchor" 2>/dev/null && pwd -P)"
1525
- if [ -z "$fd_real" ] || [ -z "$root_real" ] || [ "$fd_real" != "$root_real/$rel_real" ]; then
1526
- exec 9<&-; return 3
1527
- fi
1528
- fi
1529
- if [ -n "$root" ] && [ "$root" != - ] && team_panel_detail_symlink_hit "$root" "$abs" >/dev/null; then
1594
+ # 判据作用于**读的那个对象**:句柄自己解析出的物理路径必须在边界内(项目根;允许根在项目外时是
1595
+ # 允许根自己)。拿不到句柄路径或边界 → 拒绝(fail-closed)。
1596
+ real="$(readlink /proc/self/fd/9 2>/dev/null || readlink /dev/fd/9 2>/dev/null)"
1597
+ boundary="$(team_panel_detail_boundary "$root")"
1598
+ if [ -z "$real" ] || [ -z "$boundary" ] || ! team_panel_detail_within "$boundary" "$real"; then
1530
1599
  exec 9<&-; return 3
1531
1600
  fi
1532
1601
  if [ "$cap" = - ]; then
@@ -1538,85 +1607,117 @@ team_panel_detail_read_nofollow() { # <允许根|-> <abs> <cap>
1538
1607
  return 0
1539
1608
  }
1540
1609
 
1610
+ # 一条发现记录(P424):`<相对路径>\t<tab>\t<字节>\t<flag>\t<note>`。
1611
+ # flag=0 = 可服务(note = 路径上经过的软链段,`|` 连接,可为空);flag=1 = 拒绝(note = 真实落点与
1612
+ # 边界)。落点解析不出的文件不进发现集(与改动前的「坏链不可读」同形)。
1613
+ team_panel_detail_record_file() { # <允许根> <abs 文件> <tab> <字节>
1614
+ local root="$1" f="$2" tab="$3" size="${4:-0}" note rc
1615
+ rc=0
1616
+ note="$(team_panel_detail_landing_reason "$root" "$f")" || rc=$?
1617
+ case "$rc" in
1618
+ 0) printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$f")" "$tab" "$size" "0" "$(team_panel_detail_link_segs "$f")" ;;
1619
+ 1) printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$f")" "$tab" "$size" "1" "$note" ;;
1620
+ *) return 0 ;;
1621
+ esac
1622
+ }
1623
+
1624
+ # 非普通文件的人话类型(FIFO / 设备 / 目录 / 套接字 / 坏链)——拒绝原因要说得清拒绝的是什么。
1625
+ team_panel_detail_type_name() { # <abs>
1626
+ if [ -p "$1" ]; then printf 'FIFO'; return 0; fi
1627
+ if [ -b "$1" ] || [ -c "$1" ]; then printf '设备文件'; return 0; fi
1628
+ if [ -d "$1" ]; then printf '目录'; return 0; fi
1629
+ if [ -S "$1" ]; then printf '套接字'; return 0; fi
1630
+ if [ -L "$1" ]; then printf '坏链'; return 0; fi
1631
+ printf '不是普通文件'
1632
+ }
1633
+
1634
+ # 发现集的一条候选(P424):普通文件走落点判据;存在但不是普通文件的不服务、但要**点名**(FIFO 在
1635
+ # open 上会一直等写者,所以它连读面都进不去);不存在的候选静静跳过(各块自己的缺省分支会持)。
1636
+ team_panel_detail_record_path() { # <允许根> <abs> <tab>
1637
+ if [ -f "$2" ]; then
1638
+ # 读不到字节数(权限/IO)按 0 报:大小是展示值,不是判据(判据是落点与文件类型)。
1639
+ team_panel_detail_record_file "$1" "$2" "$3" "$(wc -c < "$2" 2>/dev/null | tr -d ' ' || true)"
1640
+ return 0
1641
+ fi
1642
+ if [ -e "$2" ] || [ -L "$2" ]; then
1643
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$2")" "$3" "0" "2" "$(team_panel_detail_type_name "$2")"
1644
+ fi
1645
+ return 0
1646
+ }
1647
+
1541
1648
  team_panel_detail_records_entry() { # <id>
1542
1649
  local LC_ALL=C
1543
- local id="$1" f name suffix tab size rel first=1 refused=0 hit
1544
- # F3:`docs`(或它到项目根之间的段)是软链时,整条发现集拒绝并点名那一段(与 spec/change 同形)。
1545
- if hit="$(team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$TEAM_DOCS_ABS")"; then
1546
- printf '%s\t%s\t%s\t%s\n' "$hit" "brief" "0" "1"
1547
- return 0
1650
+ local id="$1" f name suffix tab size note rc first=1
1651
+ # 账本根(`docs` 或 `docs/team`)整体是软链时按落点判:项目内照常发现,项目外整条拒绝并点名。
1652
+ if [ -e "$TEAM_DOCS_ABS" ] || [ -L "$TEAM_DOCS_ABS" ]; then
1653
+ rc=0
1654
+ note="$(team_panel_detail_landing_reason "$TEAM_DOCS_ABS" "$TEAM_DOCS_ABS")" || rc=$?
1655
+ if [ "$rc" != 0 ]; then
1656
+ [ "$rc" = 5 ] && note="落点解析不出(目标不存在或链成环)"
1657
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$TEAM_DOCS_ABS")" "brief" "0" "1" "$note"
1658
+ return 0
1659
+ fi
1548
1660
  fi
1549
1661
  [ -d "$TEAM_DOCS_ABS" ] || return 0
1550
1662
  for f in "$TEAM_DOCS_ABS/tasks/$id"-*.md; do
1551
- [ -f "$f" ] || continue
1552
1663
  name="${f##*/}"; suffix="${name#"$id"-}"; suffix="${suffix%.md}"
1553
- tab="brief"; [ "$first" = 1 ] || tab="brief:$suffix"; first=0
1554
- size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1555
- rel="$(team_panel_detail_rel "$f")"
1556
- refused=0; [ -L "$f" ] && refused=1
1557
- printf '%s\t%s\t%s\t%s\n' "$rel" "$tab" "${size:-0}" "$refused"
1664
+ tab="brief"; [ "$first" = 1 ] || tab="brief:$suffix"
1665
+ [ -f "$f" ] && first=0
1666
+ team_panel_detail_record_path "$TEAM_DOCS_ABS" "$f" "$tab"
1558
1667
  done
1559
1668
  for f in "$TEAM_DOCS_ABS/reports/$id"-*.md; do
1560
- [ -f "$f" ] || continue
1561
1669
  name="${f##*/}"; suffix="${name#"$id"-}"; suffix="${suffix%.md}"
1562
- size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1563
- rel="$(team_panel_detail_rel "$f")"
1564
- refused=0; [ -L "$f" ] && refused=1
1565
- printf '%s\t%s\t%s\t%s\n' "$rel" "report:$suffix" "${size:-0}" "$refused"
1670
+ team_panel_detail_record_path "$TEAM_DOCS_ABS" "$f" "report:$suffix"
1566
1671
  done
1567
1672
  f="$TEAM_DOCS_ABS/reviews/$id.md"
1568
- if [ -f "$f" ]; then
1569
- size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1570
- rel="$(team_panel_detail_rel "$f")"
1571
- refused=0; [ -L "$f" ] && refused=1
1572
- printf '%s\t%s\t%s\t%s\n' "$rel" "review" "${size:-0}" "$refused"
1673
+ if [ -f "$f" ] || [ -e "$f" ] || [ -L "$f" ]; then
1674
+ team_panel_detail_record_path "$TEAM_DOCS_ABS" "$f" "review"
1573
1675
  fi
1574
1676
  for f in "$TEAM_DOCS_ABS/reviews/$id"-*.md; do
1575
- [ -f "$f" ] || continue
1576
1677
  name="${f##*/}"; suffix="${name#"$id"-}"; suffix="${suffix%.md}"
1577
- size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1578
- rel="$(team_panel_detail_rel "$f")"
1579
- refused=0; [ -L "$f" ] && refused=1
1580
- printf '%s\t%s\t%s\t%s\n' "$rel" "review:$suffix" "${size:-0}" "$refused"
1678
+ team_panel_detail_record_path "$TEAM_DOCS_ABS" "$f" "review:$suffix"
1581
1679
  done
1582
1680
  return 0
1583
1681
  }
1584
1682
 
1585
1683
  # source spec:`<spec_dir>/specs/<capability>/spec.md`(唯一的那个文件,tab `spec`)。
1586
1684
  team_panel_detail_records_spec() { # <capability>
1587
- local id="$1" f size rel refused=0 root hit
1685
+ local id="$1" f size note rc root
1588
1686
  root="$(team_spec_dir_abs)/specs"
1589
1687
  f="$root/$id/spec.md"
1590
- # 目录段软链先判(`-f` 会跟随它):目标在不在都拒绝并点名,不拿软链之外的正文充数。
1591
- if hit="$(team_panel_detail_symlink_hit "$root" "$f")"; then
1592
- printf '%s\t%s\t%s\t%s\n' "$hit" "spec" "0" "1"
1593
- return 0
1688
+ # 目录段(`specs/<cap>` 是软链)按落点判(`-f`/`-d` 都会跟随它):项目内照常读,根外整条拒绝并点名。
1689
+ if [ -e "$root/$id" ] || [ -L "$root/$id" ]; then
1690
+ rc=0
1691
+ note="$(team_panel_detail_landing_reason "$root" "$root/$id")" || rc=$?
1692
+ if [ "$rc" != 0 ]; then
1693
+ [ "$rc" = 5 ] && note="落点解析不出(目标不存在或链成环)"
1694
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$root/$id")" "spec" "0" "1" "$note"
1695
+ return 0
1696
+ fi
1594
1697
  fi
1595
- [ -f "$f" ] || return 0
1596
- size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1597
- rel="$(team_panel_detail_rel "$f")"
1598
- [ -L "$f" ] && refused=1
1599
- printf '%s\t%s\t%s\t%s\n' "$rel" "spec" "${size:-0}" "$refused"
1698
+ if [ ! -f "$f" ] && [ ! -e "$f" ] && [ ! -L "$f" ]; then return 0; fi
1699
+ team_panel_detail_record_path "$root" "$f" "spec"
1600
1700
  }
1601
1701
 
1602
1702
  # source change:该 change 自己的 proposal/design/tasks(按此序,缺的不补;archive 到不了)。
1603
1703
  team_panel_detail_records_change() { # <change id>
1604
- local id="$1" dir f name size rel refused=0 root hit
1704
+ local id="$1" dir f name size note rc root
1605
1705
  root="$(team_spec_dir_abs)/changes"
1606
1706
  dir="$root/$id"
1607
- # 同上:`changes/<id>` 是软链(指根外、指别的 change、指 archive/)时整条拒绝并点名那一段。
1608
- if hit="$(team_panel_detail_symlink_hit "$root" "$dir")"; then
1609
- printf '%s\t%s\t%s\t%s\n' "$hit" "change" "0" "1"
1610
- return 0
1707
+ # 同上:`changes/<id>` 是软链时按落点判 —— 项目内(例如整棵 openspec 搬到项目里)照常读,根外拒绝。
1708
+ if [ -e "$dir" ] || [ -L "$dir" ]; then
1709
+ rc=0
1710
+ note="$(team_panel_detail_landing_reason "$root" "$dir")" || rc=$?
1711
+ if [ "$rc" != 0 ]; then
1712
+ [ "$rc" = 5 ] && note="落点解析不出(目标不存在或链成环)"
1713
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$dir")" "change" "0" "1" "$note"
1714
+ return 0
1715
+ fi
1611
1716
  fi
1612
1717
  [ -d "$dir" ] || return 0
1613
1718
  for name in proposal design tasks; do
1614
1719
  f="$dir/$name.md"
1615
- [ -f "$f" ] || continue
1616
- size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1617
- rel="$(team_panel_detail_rel "$f")"
1618
- refused=0; [ -L "$f" ] && refused=1
1619
- printf '%s\t%s\t%s\t%s\n' "$rel" "$name" "${size:-0}" "$refused"
1720
+ team_panel_detail_record_path "$root" "$f" "$name"
1620
1721
  done
1621
1722
  }
1622
1723
 
@@ -1649,21 +1750,25 @@ team_panel_detail_decision_slice() { # <D编号> [文件](缺省账本;`-` =
1649
1750
 
1650
1751
  # source decision:只服务所请求条目的切片(不提供整文件出口)。
1651
1752
  team_panel_detail_records_decision() { # <D编号>
1652
- local id="$1" f="$TEAM_DOCS_ABS/DECISIONS.md" slice size rel refused=0 hit
1653
- # F3:`docs`(或它到项目根之间的段)是软链时,账本条目整条拒绝并点名那一段(正文更是一个字节不读)。
1654
- if hit="$(team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$f")"; then
1655
- printf '%s\t%s\t%s\t%s\n' "$hit" "$id" "0" "1"
1656
- return 0
1753
+ local id="$1" f="$TEAM_DOCS_ABS/DECISIONS.md" slice size note rc
1754
+ # 账本本身是软链时按落点判:项目内照常读,根外整条拒绝并点名(正文一个字节都不读)。
1755
+ if [ -e "$f" ] || [ -L "$f" ]; then
1756
+ rc=0
1757
+ note="$(team_panel_detail_landing_reason "$TEAM_DOCS_ABS" "$f")" || rc=$?
1758
+ if [ "$rc" != 0 ]; then
1759
+ [ "$rc" = 5 ] && note="落点解析不出(目标不存在或链成环)"
1760
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$f")" "$id" "0" "1" "$note"
1761
+ return 0
1762
+ fi
1657
1763
  fi
1658
1764
  [ -f "$f" ] || return 0
1659
1765
  slice="$(team_panel_detail_decision_slice "$id")"
1660
1766
  [ -n "$slice" ] || return 0
1661
1767
  size="$(printf '%s\n' "$slice" | wc -c | tr -d ' ')"
1662
- rel="$(team_panel_detail_rel "$f")"
1663
- [ -L "$f" ] && refused=1
1664
- printf '%s\t%s\t%s\t%s\n' "$rel" "$id" "${size:-0}" "$refused"
1768
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(team_panel_detail_rel "$f")" "$id" "${size:-0}" "0" "$(team_panel_detail_link_segs "$f")"
1665
1769
  }
1666
1770
 
1771
+
1667
1772
  team_panel_detail_records() { # <id> [source]
1668
1773
  case "${2:-entry}" in
1669
1774
  entry) team_panel_detail_records_entry "$1" ;;
@@ -1699,12 +1804,21 @@ team_panel_detail_json() { # <id> [file] [source]
1699
1804
  esac
1700
1805
  fi
1701
1806
  local -a paths=() tabs=() sizes=()
1702
- local path tab size flag refused=""
1703
- while IFS=$'\t' read -r path tab size flag; do
1807
+ local path tab size flag note refused="" refused_type="" links=""
1808
+ while IFS=$'\t' read -r path tab size flag note; do
1704
1809
  [ -n "$path" ] || continue
1705
- # 软链不进发现集(`--file` 选不到、正文永不读穿),但在 reason 里点名。
1706
- if [ "${flag:-0}" = 1 ]; then refused="${refused:+$refused · }$path"; continue; fi
1810
+ # 被拒的路径不进发现集(`--file` 选不到、正文不读),原因里点名它 + 真实落点与边界。
1811
+ if [ "${flag:-0}" = 1 ]; then
1812
+ refused="${refused:+$refused · }$path${note:+($note)}"
1813
+ continue
1814
+ fi
1815
+ # 不是普通文件(FIFO / 设备 / 目录 / 坏链):同样不进发现集,但拒绝原因要说清它是什么。
1816
+ if [ "${flag:-0}" = 2 ]; then
1817
+ refused_type="${refused_type:+$refused_type · }$path${note:+($note)}"
1818
+ continue
1819
+ fi
1707
1820
  paths+=("$path"); tabs+=("$tab"); sizes+=("${size:-0}")
1821
+ [ -z "${note:-}" ] || links="${links:+$links|}$note"
1708
1822
  done < <(team_panel_detail_records "$id" "$source")
1709
1823
  local n="${#paths[@]}" i pick=0
1710
1824
  if [ -n "$want" ]; then
@@ -1726,27 +1840,27 @@ team_panel_detail_json() { # <id> [file] [source]
1726
1840
  out="$out{\"tab\": $(team_panel_json_str "${tabs[$i]}"), \"name\": $(team_panel_json_str "${paths[$i]##*/}"), \"path\": $(team_panel_json_str "${paths[$i]}"), \"size\": $(team_panel_num "${sizes[$i]}"), \"truncated\": $t}"
1727
1841
  done
1728
1842
  out="$out]"
1729
- local file="" text="" truncated=false abs read_hit="" read_unchecked="" read_root="-" read_rc=0 decision_rel="" decision_body=""
1843
+ local file="" text="" truncated=false abs read_hit="" read_unchecked="" read_root="-" read_rc=0 read_note="" decision_rel="" decision_body=""
1730
1844
  if [ "$n" -gt 0 ]; then
1731
1845
  file="${paths[$pick]}"
1732
1846
  case "$file" in /*) abs="$file" ;; *) abs="$TEAM_MAIN_ROOT/$file" ;; esac
1733
- # 路径级复判(发现与读取两处都判):发现之后、读之前路径被换成软链也不读 —— 这里顺手点名命中的那一段。
1734
- # F3:entry/decision 两类也判(锚点是项目根:`docs` 本身是软链时点名 `docs`)。
1735
1847
  case "$source" in
1736
- spec|change)
1737
- if read_hit="$(team_panel_detail_symlink_hit "$(team_panel_detail_source_root "$source")" "$abs")"; then
1738
- file=""
1739
- fi ;;
1740
- entry|decision)
1741
- if read_hit="$(team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$abs")"; then
1742
- file=""
1743
- fi ;;
1848
+ spec|change) read_root="$(team_panel_detail_source_root "$source")" ;;
1849
+ entry|decision) read_root="$TEAM_DOCS_ABS" ;;
1744
1850
  esac
1851
+ # 读前再判一次落点(发现之后、读之前路径被换成指向根外的软链):判据与发现面同源;
1852
+ # 原因里同时点名真实落点与边界,越界的路径一个字节都不读。
1853
+ read_rc=0
1854
+ read_note="$(team_panel_detail_landing_reason "$read_root" "$abs")" || read_rc=$?
1855
+ if [ "$read_rc" = 1 ]; then
1856
+ read_hit="$file($read_note)"; file=""
1857
+ fi
1745
1858
  if [ -n "$read_hit" ]; then
1746
- : # 命中软链:正文一个字节都不读(下面 reason 里点名)
1859
+ : # 越界:正文一个字节都不读(下面 reason 里点名)
1747
1860
  elif [ "$source" = decision ]; then
1748
- # 决策源也是「发现到的路径」(合同把三类 source 的软链都点名了):先原子读账本,再从**读到的那份正文**
1749
- # 切片 —— 账本在发现之后被换成软链,切出来的一样不是树外内容。
1861
+ # 决策源也是「发现到的路径」:先原子读账本,再从**读到的那份正文**切片 —— 账本在发现之后被换掉,
1862
+ # 切出来的一样不是树外内容。
1863
+ read_rc=0
1750
1864
  decision_rel="$(team_panel_detail_rel "$TEAM_DOCS_ABS/DECISIONS.md")"
1751
1865
  decision_body="$(team_panel_detail_read_nofollow "$TEAM_DOCS_ABS" "$TEAM_DOCS_ABS/DECISIONS.md" -)" || read_rc=$?
1752
1866
  case "$read_rc" in
@@ -1755,11 +1869,8 @@ team_panel_detail_json() { # <id> [file] [source]
1755
1869
  *) text="$(printf '%s\n' "$decision_body" | team_panel_detail_decision_slice "$id" - | head -c "$cap" | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true)" ;;
1756
1870
  esac
1757
1871
  else
1758
- # 读面原子化(F2):判据与读取作用于同一个 inode(open 一次 + fd 身份 + 逐段现查)。
1759
- case "$source" in
1760
- spec|change) read_root="$(team_panel_detail_source_root "$source")" ;;
1761
- entry) read_root="$TEAM_DOCS_ABS" ;;
1762
- esac
1872
+ # 读面原子化:判据与读取作用于同一个 inode(open 一次 + fd 身份 + 落点现查)。
1873
+ read_rc=0
1763
1874
  text="$(team_panel_detail_read_nofollow "$read_root" "$abs" "$cap")" || read_rc=$?
1764
1875
  case "$read_rc" in
1765
1876
  3) read_hit="$file"; file="" ;;
@@ -1768,14 +1879,17 @@ team_panel_detail_json() { # <id> [file] [source]
1768
1879
  fi
1769
1880
  [ "${sizes[$pick]}" -gt "$cap" ] && truncated=true
1770
1881
  fi
1771
- # 被拒的软链点名;目标根本不存在时给可读原因(不是错误帧,也不拿邻居的正文充数)。
1882
+
1883
+ # 被拒的路径点名(越界软链 / 不是普通文件);目标根本不存在时给可读原因(不是错误帧,
1884
+ # 也不拿邻居的正文充数)。
1772
1885
  local reason=""
1773
1886
  if [ -n "$read_hit" ]; then
1774
1887
  reason="软链拒绝:$read_hit"
1775
1888
  elif [ -n "$read_unchecked" ]; then
1776
1889
  reason="读取身份无法确认(没有 /proc/self/fd 也没有 /dev/fd):$read_unchecked"
1777
- elif [ -n "$refused" ]; then
1778
- reason="软链拒绝:$refused"
1890
+ elif [ -n "$refused" ] || [ -n "$refused_type" ]; then
1891
+ [ -z "$refused" ] || reason="软链拒绝:$refused"
1892
+ [ -z "$refused_type" ] || reason="${reason:+$reason · }不是普通文件,不打开:$refused_type"
1779
1893
  elif [ "$n" -eq 0 ]; then
1780
1894
  case "$source" in
1781
1895
  spec) reason="${TEAM_SPEC_DIR:-openspec}/specs/$id/spec.md 不存在" ;;
@@ -1783,11 +1897,23 @@ team_panel_detail_json() { # <id> [file] [source]
1783
1897
  decision) reason="DECISIONS.md 里没有 $id" ;;
1784
1898
  esac
1785
1899
  fi
1900
+ # P424:项目内的软链照常读,但把经过的软链段如实报出来(`links`,排错线索,不是错误、不再挡读)。
1901
+ local links_json="" seg seen=" "
1902
+ if [ -n "$links" ]; then
1903
+ while IFS= read -r seg; do
1904
+ [ -n "$seg" ] || continue
1905
+ case "$seen" in *" $seg "*) continue ;; esac
1906
+ seen="$seen$seg "
1907
+ links_json="$links_json${links_json:+, }$(team_panel_json_str "$seg")"
1908
+ done < <(printf '%s\n' "$links" | tr '|' '\n')
1909
+ fi
1910
+ local links_json_field=""
1911
+ [ -n "$links_json" ] && links_json_field=", \"links\": [$links_json]"
1786
1912
  local reason_json=""
1787
1913
  [ -n "$reason" ] && reason_json=", \"reason\": $(team_panel_json_str "$reason")"
1788
- printf '{"id": %s, "count": %s, "file": %s, "text": %s, "truncated": %s, "files": %s%s}\n' \
1914
+ printf '{"id": %s, "count": %s, "file": %s, "text": %s, "truncated": %s, "files": %s%s%s}\n' \
1789
1915
  "$(team_panel_json_str "$id")" "$(team_panel_num "$n")" "$(team_panel_json_str "$file")" \
1790
- "$(team_panel_json_str_ml "$text")" "$truncated" "$out" "$reason_json"
1916
+ "$(team_panel_json_str_ml "$text")" "$truncated" "$out" "$links_json_field" "$reason_json"
1791
1917
  }
1792
1918
 
1793
1919
  # ---- 关键回复块(change: pulse-key-replies):三个 console-only 只读块,直接进 helper。
@@ -2238,7 +2364,7 @@ team_cmd_standby() {
2238
2364
  local action="status" reason="-"
2239
2365
  while [ $# -gt 0 ]; do
2240
2366
  case "$1" in
2241
- on|off|status) action="$1"; shift ;;
2367
+ on|off|status|migrate) action="$1"; shift ;;
2242
2368
  --reason) reason="${2:?}"; shift 2 ;;
2243
2369
  -*) team_usage_die "standby: 未知参数 $1" ;;
2244
2370
  *) team_usage_die "standby: 多余参数 $1" ;;
@@ -2246,23 +2372,23 @@ team_cmd_standby() {
2246
2372
  done
2247
2373
  case "$action" in
2248
2374
  on)
2249
- team_standby_on "$reason"
2375
+ # 写失败就停住:一个报错的 `standby on` 之后团队到底是不是待命,不能靠猜。
2376
+ team_standby_on "$reason" || team_die "待命没有写进去(上面是权威层的原因);状态未变,修好后重跑"
2250
2377
  team_wlog "standby on(原因:$reason)"
2251
2378
  team_ok "已进入待命:pulse 不会再叫醒 PM(原因:$reason)"
2252
2379
  team_dim " 待办不会丢:积压会记进 ${TEAM_STATE_DIR#"$TEAM_MAIN_ROOT"/}/watchdog.log;恢复用 $TEAM_CLI standby off"
2253
2380
  ;;
2254
2381
  off)
2255
- team_standby_off
2382
+ team_standby_off || team_die "待命没有关掉(上面是权威层的原因);状态未变,修好后重跑"
2256
2383
  team_wlog "standby off"
2257
2384
  team_ok "已退出待命:下个巡检周期起,有待办就会叫醒/拉起 PM"
2258
2385
  ;;
2386
+ migrate)
2387
+ # 旧 state/standby 一次性并入统一状态(保留原因/时间,不加代次);重复跑不变。
2388
+ team_standby_migrate || team_die "待命迁移失败(上面是权威层的原因);统一状态未有改动"
2389
+ ;;
2259
2390
  *)
2260
- if team_in_standby; then
2261
- local since; since="$(awk '{print $1}' "$(team_standby_file)" 2>/dev/null)"
2262
- printf 'standby: on(自 %s,原因:%s)\n' "${since:--}" "$(team_standby_reason || echo -)"
2263
- else
2264
- printf 'standby: off\n'
2265
- fi
2391
+ team_standby_status || team_die "读不到待命状态(上面是权威层的原因)"
2266
2392
  local pend; pend="$(team_pending_text "$(team_panel_pending_counts_fast || true)")"
2267
2393
  printf '待办:%s\n' "${pend:-无}"
2268
2394
  ;;