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
@@ -97,11 +97,17 @@ exists (`{{SKILL_DIR}}/references/openspec.md`).
97
97
 
98
98
  **Background jobs and turn endings.** A turn ends in one of three states: **delivered**, **hard-blocked** (blocked on
99
99
  a human: record it and stand down), or **suspended on background jobs** with every awaited id named on its last line.
100
- The lane default is the suspension: `team_bg_run` starts a long job (a gate, a build) and you **let the turn end**;
101
- the completion wake-up is the normal harvest point, and `team_bg_wait <id>` then brings back the exit code and the log
102
- tail. In-turn waiting is the bounded exception, only when all three hold: the job is expected to finish within the
103
- inline-wait budget (about 2 minutes), its result blocks your immediate next step, and no other task work can advance
104
- meanwhile (`{{SKILL_DIR}}/references/workflows.md` §E2).
100
+ Do not run long work in your own session — not a full gate, not a long test matrix, not a bulk refactor. A seat
101
+ does that work, or `team_bg_run` does it in the background; your session does routing, judgement and acceptance.
102
+ Guidance, not a limit: nothing stops you, but a busy PM cannot answer the user and cannot be steered.
103
+
104
+ Long commands run in the background -- the full gate, a container gate, a mutation matrix, a project build, a long
105
+ test suite. Do not wait inline (`sleep`, `team wait`, a blocking harvest): end the turn and come back on the
106
+ completion wake-up or a reminder.
107
+
108
+ `team_bg_run` starts a long job (a gate, a build) and you **let the turn end**; the completion wake-up is the normal
109
+ harvest point, and `team_bg_wait <id>` then brings back the exit code and the log tail. Harvest after the wake rather
110
+ than polling it.
105
111
 
106
112
  The pulse is a metronome that wakes you only when there is work, not a daemon. If there is genuinely nothing to push,
107
113
  or you are blocked on a human (authorization, a decision, external information), write the conclusion into
@@ -61,8 +61,13 @@ td_not_has() { # <名字> <文本> <子串>
61
61
  }
62
62
 
63
63
  # ---------------------------------------------------------------- 夹具仓库(只写 $TMP 里)
64
+ # 夹具的“主工作树”必须是个**真 git 仓库**,而且脚本要在它里面跑:待命自 1.3 起住在项目状态
65
+ # 权威的快照里,权威按“当前目录所属项目”钉住状态根(继承的 TEAM_MAIN_ROOT 与目录不一致会被拒)。
64
66
  T="$TMP/repo"
65
67
  mkdir -p "$T/state" "$T/worktrees/dev" "$T/worktrees/dev2" "$T/docs/team" "$T/pi"
68
+ git -C "$T" init -q -b main &&
69
+ git -C "$T" -c user.email=td@fixture -c user.name=td commit -q --allow-empty -m init || exit 3
70
+ cd "$T" || exit 3
66
71
  for _a in dev dev2; do
67
72
  git -C "$T/worktrees/$_a" init -q -b "task/TD-$_a" 2>/dev/null || true
68
73
  git -C "$T/worktrees/$_a" -c user.email=td@fixture -c user.name=td commit -q --allow-empty -m init 2>/dev/null || true
@@ -16,10 +16,9 @@
16
16
  # surface wraps to (the fixture's own locale-independent counter, not the renderer's)
17
17
  # claims the declared effect / authorization / reversibility values: closed vocabularies,
18
18
  # one probe per value, and each probe run against a real fixture asserting the effect.
19
- # For `idempotent` the probe turns a *named* recorded-time field into a canary
20
- # (IDEMPOTENT_TIME_FIELDS) so its verdict cannot depend on the wall clock (P290),
21
- # requires the second run's exit code to equal the first run's, and exercises the
22
- # record-without-that-field shape: a missing timestamp is not an error (V46 F1)
19
+ # For `idempotent` the probe runs the command twice with a wall-clock gap between
20
+ # the runs (so a same-second clock rewrite cannot hide) and requires every byte,
21
+ # and the second run's exit code, to be unchanged (P290, V46 F1)
23
22
  # invariants command names, flag names and the literals other specs name: unchanged; the
24
23
  # pre-change (command, flag) set is still printed; the retired --model is not
25
24
  # route the three levels, byte-identical entries, unknown tokens exit 2 and are named, the
@@ -352,59 +351,6 @@ fp_all() { # <dir> → every face's fingerprint
352
351
  for f in state docs config worktree skills meetings; do printf '%s %s\n' "$f" "$(fp_face "$1" "$f")"; done
353
352
  }
354
353
 
355
- # ---------------------------------------------------------------- recorded-time fields (P290)
356
- # A command whose manifest row declares `idempotent` must leave the state byte-identical after a
357
- # second identical run. One field shape is legitimately *about* time: the record of when the command
358
- # ran (`AT=` in `.pi/team/state/pm-loaded.env`). It is not exempt from the assertion — it is *named* here, and
359
- # the probe turns it into a canary: after the first run the fixture overwrites the named field with a
360
- # sentinel value no clock produces, runs the command again, and requires every byte (sentinel
361
- # included) to survive. Without the sentinel the verdict would depend on the wall clock — a rewrite
362
- # inside the same second is invisible — and that is the host-green/container-red flake this table
363
- # exists to remove (P290). A second run that rewrites a clock field is a defect for *every* command
364
- # that declares `idempotent`, so a field must be named here rather than silently excused; a line
365
- # naming a field the first run did not write is itself a finding, so a stale entry cannot sit here.
366
- # An exclusion-only comparison was rejected on purpose: it would make this probe blind to exactly
367
- # the rewrite the declaration forbids.
368
- declare -A IDEMPOTENT_TIME_FIELDS=(
369
- [mark-loaded]=".pi/team/state/pm-loaded.env:AT"
370
- )
371
- IDEMPOTENT_SENTINEL="sentinel-not-a-clock"
372
-
373
- idem_fields() { # <cmd> → one `relpath:field` per line (nothing when the command declares none)
374
- case "${IDEMPOTENT_TIME_FIELDS[$1]+x}" in x) printf '%s\n' ${IDEMPOTENT_TIME_FIELDS[$1]} ;; esac
375
- return 0
376
- }
377
-
378
- idem_stamp() { # <cmd> <dir> <outfile> — overwrite each declared recorded-time field with the sentinel
379
- local cmd="$1" d="$2" out="$3" spec rel field f
380
- while IFS= read -r spec; do
381
- [ -n "$spec" ] || continue
382
- rel="${spec%%:*}"; field="${spec#*:}"
383
- f="$d/$rel"
384
- if [ ! -f "$f" ] || ! grep -q "^$field=" "$f" 2>/dev/null; then
385
- finding "claims: $cmd 声明的记录时间字段 $field 不在 $rel 里(声明过期:不静默通过,见 IDEMPOTENT_TIME_FIELDS)"
386
- continue
387
- fi
388
- if awk -v k="$field" -v v="$IDEMPOTENT_SENTINEL" 'index($0, k"=") == 1 { print k"="v; next } { print }' "$f" > "$f.p290"; then
389
- mv "$f.p290" "$f"
390
- printf '%s\n' "$spec" >> "$out"
391
- else
392
- rm -f "$f.p290"
393
- finding "claims: $cmd 声明的记录时间字段 $field 没盖上哨兵(夹具写入失败)"
394
- fi
395
- done < <(idem_fields "$cmd")
396
- return 0
397
- }
398
-
399
- idem_names() { # <stamped-file> → ` AT(.pi/team/state/pm-loaded.env)` — names the fields in the result line
400
- local s out=""
401
- while IFS= read -r s; do
402
- [ -n "$s" ] || continue
403
- out="$out ${s#*:}(${s%%:*})"
404
- done < "$1"
405
- printf '%s' "$out"
406
- }
407
-
408
354
  new_repo() { # <name> → a fresh git repository
409
355
  local d="$tmp/fx/$1"
410
356
  rm -rf "$d"; mkdir -p "$d"
@@ -528,7 +474,7 @@ probe_recipe() {
528
474
  pr) printf 'proj|pr\n' ;;
529
475
  gh) printf 'proj|gh\n' ;;
530
476
  gl) printf 'proj|gl\n' ;;
531
- mark-loaded) printf 'proj|mark-loaded --version 0.0.0\n' ;;
477
+ mark-loaded) printf 'proj|mark-loaded\n' ;;
532
478
  version) printf 'proj|version\n' ;;
533
479
  changelog) printf 'proj|changelog\n' ;;
534
480
  reload) printf 'proj|reload\n' ;;
@@ -1182,26 +1128,16 @@ run_probe() { # <cmd> → ok/finding
1182
1128
  # undo
1183
1129
  case "${MG_UNDO[$cmd]}" in
1184
1130
  idempotent)
1185
- # the declared recorded-time fields (IDEMPOTENT_TIME_FIELDS) get the sentinel before the second
1186
- # run: the field is named, not excused, and the verdict cannot depend on the wall clock
1187
- local base again stamped n_stamped lost="" s rc2 rc_missing wrote f field
1188
- stamped="$tmp/logs/p-$cmd.stamped"; : > "$stamped"; n_stamped=0
1189
- if [ -n "$(idem_fields "$cmd")" ]; then
1190
- idem_stamp "$cmd" "$d" "$stamped"
1191
- n_stamped="$(grep -c . "$stamped" 2>/dev/null || true)"
1192
- fi
1131
+ # P417:`mark-loaded`(唯一「会合法改写记录时间字段」的命令)删掉了,所以幂等的判据不再需要
1132
+ # 哨兵:第二次跑必须逐字节不变。中间隔 1.1s 仍然要睡 —— 同一秒内的改写会写出同样的字节,
1133
+ # 那条 P290 的时钟缺陷正是躲在这个缝里(宿主绿、慢一档的容器红)。
1134
+ local base again rc2
1193
1135
  base="$(fp_all "$d")"
1194
- # The sentinel above covers the fields somebody *declared*. A clock-derived value nobody declared
1195
- # is still invisible inside one second: run 1 and run 2 write the same bytes. Sleeping past a
1196
- # second boundary makes the probe judge "a later run changed nothing" instead of "a run inside
1197
- # the same second changed nothing" — the verdict stops depending on how fast the machine is,
1198
- # which is exactly the clock the P290 flake hid behind (host green, container red). Cost: ~1.1s
1199
- # per idempotent command, and only in the full gate (FAST does not run `claims`).
1200
1136
  sleep 1.1
1201
1137
  env_run "$d" $argv >/dev/null 2>&1
1202
1138
  rc2="$HS_RC"
1203
1139
  again="$(fp_all "$d")"
1204
- # O1(V46):第二次跑的退出码也要判——「第二次失败、不写盘」若只看字节会被当成幂等(假绿)。
1140
+ # O1(V46):第二次跑的退出码也要判 ——「第二次失败、不写盘」若只看字节会被当成幂等(假绿)。
1205
1141
  # 判据是「与第一次一致」而不是「必须为 0」:夹具里 gh/gl/pr 这类命令在没有远端时本来就以非零
1206
1142
  # 退出(只读拒绝),要求全部为 0 会把它们判红。rc 打进输出,红时点名两次的数。
1207
1143
  printf ' \033[2m·\033[0m 幂等 %-11s rc=%s → %s\n' "$cmd" "$rc" "$rc2"
@@ -1211,40 +1147,9 @@ run_probe() { # <cmd> → ok/finding
1211
1147
  finding "claims: $cmd 声明幂等,但两次跑的退出码不同(rc $rc → $rc2):第二次跑失败不算「什么都没变」"
1212
1148
  fi
1213
1149
  if [ "$base" = "$again" ]; then
1214
- if [ "$n_stamped" = "0" ]; then
1215
- ok "claims: $cmd 幂等(第二次跑逐字节不变)"
1216
- else
1217
- ok "claims: $cmd 幂等(第二次跑逐字节不变;指名的记录时间字段$(idem_names "$stamped") 经哨兵验证未被重写)"
1218
- fi
1150
+ ok "claims: $cmd 幂等(第二次跑逐字节不变)"
1219
1151
  else
1220
- while IFS= read -r s; do
1221
- [ -n "$s" ] || continue
1222
- grep -q "^${s#*:}=$IDEMPOTENT_SENTINEL$" "$d/${s%%:*}" 2>/dev/null || lost="$lost ${s#*:}(${s%%:*})"
1223
- done < "$stamped"
1224
- if [ -n "$lost" ]; then
1225
- finding "claims: $cmd 声明幂等,但第二次跑重写了指名的记录时间字段$lost:哨兵值被覆盖"
1226
- else
1227
- finding "claims: $cmd 声明幂等,但第二次跑改了状态"
1228
- fi
1229
- fi
1230
- # F1(V46 返修轮次 1):记录在、但没有指名的记录时间字段时,「没有可保留的时间」等于
1231
- # 「没有记录」——命令必须照旧把字段补全并 rc=0。守卫若用裸赋值接一个没命中的 grep,在
1232
- # set -e 下会把整个 CLI 带走(rc=1、一字不写):既有的 smoke §17 用的就是这个形状。
1233
- if [ "$n_stamped" != "0" ]; then
1234
- while IFS= read -r s; do
1235
- [ -n "$s" ] || continue
1236
- f="$d/${s%%:*}"; field="${s#*:}"
1237
- grep -v "^$field=" "$f" > "$f.p290m" 2>/dev/null || true
1238
- mv "$f.p290m" "$f"
1239
- env_run "$d" $argv >/dev/null 2>&1
1240
- rc_missing="$HS_RC"; wrote=no
1241
- grep -q "^$field=" "$f" 2>/dev/null && wrote=yes
1242
- if [ "$rc_missing" = "0" ] && [ "$wrote" = "yes" ]; then
1243
- ok "claims: $cmd 记录里缺指名的记录时间字段 $field 时补全并 rc=0(缺时间戳不是错误)"
1244
- else
1245
- finding "claims: $cmd 记录里缺指名的记录时间字段 $field 时 rc=$rc_missing、字段写回=$wrote(静默失败与不补全都算缺陷)"
1246
- fi
1247
- done < "$stamped"
1152
+ finding "claims: $cmd 声明幂等,但第二次跑改了状态"
1248
1153
  fi ;;
1249
1154
  undo-by-*)
1250
1155
  local undo_cmd="${MG_UNDO[$cmd]#undo-by-}"
@@ -1338,7 +1243,6 @@ changelog --since
1338
1243
  change --json
1339
1244
  dispatch --allow-overflow --branch --fresh --model --print
1340
1245
  draft --now
1341
- mark-loaded --version
1342
1246
  meeting --all --intent --knock --note --peek --since --topic --ttl --with --yes
1343
1247
  monitor --events --height --interval --json --no-pulse --once --print --width
1344
1248
  notify --from
@@ -1608,8 +1512,11 @@ if [ "$_TEAM_HELP_REQ" = "1" ]; then""", 1)' \
1608
1512
  coverage "__probe-x"
1609
1513
 
1610
1514
  # O2b: the declared internal set names one entry that is no longer a dispatcher label
1515
+ # P417: 这里的字面量以前跟丢了声明本身(声明是三个名字 `__inbox-write __notify-settle __panel-data`,
1516
+ # 而变异找的是中间没有 `__notify-settle` 的两词子串)——替换静默空转,⑪ 于是长期「没有红」:
1517
+ # 一条自己什么都没测的红侧。字面量改成声明的原三词串;改完这条翻转必须变红。
1611
1518
  flip_case "internal-list-short" "⑪声明清单里删一个内部名" "tests/help-surface.sh" \
1612
- 's = s.replace("__inbox-write __panel-data", "__panel-data", 1)' \
1519
+ 's = s.replace("__inbox-write __notify-settle __panel-data", "__notify-settle __panel-data", 1)' \
1613
1520
  coverage "__inbox-write"
1614
1521
 
1615
1522
  # O6a: a declared group disappears from the manifest while its commands still name it
@@ -1634,48 +1541,6 @@ if [ "$_TEAM_HELP_REQ" = "1" ]; then""", 1)' \
1634
1541
  's = s.replace("""team_cmd_status() {\n team_require_docs""", """team_cmd_status() {\n team_require_docs\n mkdir -p \"$TEAM_STATE_DIR\"; printf \x27%s\\n\x27 \"$(wc -l < \"$TEAM_STATE_DIR/probe-idem.txt\" 2>/dev/null || true)\" >> \"$TEAM_STATE_DIR/probe-idem.txt\"""", 1)' \
1635
1542
  claims "声明幂等,但第二次跑改了状态" status
1636
1543
 
1637
- # ②the recorded-time field is rewritten on every run again — the P290 flake's exact shape; the
1638
- # sentinel makes this red no matter how fast the two runs are (no clock, no sleep)
1639
- flip_case "mark-loaded-rewrites" "⑯去掉「无变化不重写」的守卫(P290 的时钟缺陷回退)" "scripts/lib/cmd-update.sh" \
1640
- 's = s.replace(""" if [ -n "$stored_at" ] && [ "$stored_core" = "$core" ]; then""", " if false; then", 1)' \
1641
- claims "重写了指名的记录时间字段" mark-loaded
1642
-
1643
- # ③the declared field is no longer written at all: the table's entry must be a finding, not a
1644
- # silently passing no-op
1645
- flip_case "time-field-gone" "⑰声明的记录时间字段不再被写(声明过期必红)" "scripts/lib/cmd-update.sh" \
1646
- 's = s.replace(""" printf \x27AT=%s\\n\x27 \"$(team_timestamp)\"\n""", "", 1)' \
1647
- claims "声明过期" mark-loaded
1648
-
1649
- # ⑱ a clock field nobody declared, with the declaration table emptied for mark-loaded: the sentinel
1650
- # cannot see that pair, so the only thing that makes the rewrite visible is the 1.1s gap — this is
1651
- # the red side that shows the gap is load-bearing rather than decoration, and it is the exact shape
1652
- # of the P290 defect (an undeclared clock field, invisible on a fast same-second host)
1653
- if flip_wanted "clock-undeclared"; then
1654
- local c18
1655
- c18="$(flip_copy "flip-clock-undeclared")"
1656
- if flip_edit "$c18/skills/teamsmith/scripts/lib/cmd-update.sh" \
1657
- 's = s.replace(""" if [ -n "$stored_at" ] && [ "$stored_core" = "$core" ]; then""", " if false; then", 1)' 2>"$tmp/flip-18a.err" \
1658
- && flip_edit "$c18/skills/teamsmith/tests/help-surface.sh" \
1659
- 's = s.replace(" [mark-loaded]=\".pi/team/state/pm-loaded.env:AT\"\n", "", 1)' 2>"$tmp/flip-18b.err"; then
1660
- flip_run "⑱未指名的时钟字段(只有 1.1s 间隔抓得住)" "$c18" claims "第二次跑改了状态" mark-loaded
1661
- else
1662
- finding "翻转 ⑱:变异没落地(夹具缺陷)—— $(head -1 "$tmp/flip-18b.err" 2>/dev/null || head -1 "$tmp/flip-18a.err")"
1663
- rm -rf "$c18"
1664
- fi
1665
- fi
1666
-
1667
- # ── P290 · 返修轮次 1(V46 的 F1 与 O1)─────────────────────────────────────
1668
- # ⑲ F1 的形状回退:守卫改回裸赋值接一个没命中的 grep,set -e 把 CLI 带走。记录里没有指名的
1669
- # 时间字段时必须补全并 rc=0——这条红侧证明夹具里那条新臂是承重的(V46 F1 的真实形状)。
1670
- flip_case "missing-time-field" "⑲记录缺 AT= 行时静默失败(V46 F1 的回退)" "scripts/lib/cmd-update.sh" \
1671
- 's = s.replace(""" stored_at="$(grep -s -m1 \x27^AT=\x27 "$f" 2>/dev/null || true)"\n fi""", """ stored_at="$(grep -s \x27^AT=\x27 "$f" | head -1)"\n fi""", 1)' \
1672
- claims "记录里缺指名的记录时间字段 AT" mark-loaded
1673
-
1674
- # ⑳ O1:第二次跑以非零退出、且不写盘(V46 的 m3)——只看字节会判绿,退出码断言是唯一抓手。
1675
- flip_case "second-run-fails" "⑳第二次跑失败但不写盘(退出码盲区)" "scripts/lib/cmd-update.sh" \
1676
- 's = s.replace(""" team_ok "本会话 skill 版本未变化:$ver(指纹 $hash;保留 $(basename "$f") 里记录的时间)"\n return 0""", """ team_ok "本会话 skill 版本未变化:$ver(指纹 $hash;保留 $(basename "$f") 里记录的时间)"\n return 1""", 1)' \
1677
- claims "两次跑的退出码不同" mark-loaded
1678
-
1679
1544
  # ── P292 · 返修轮次 1(V52 的 F1)────────────────────────────────────────────────────────────
1680
1545
  # ㉑ 少声明:interrupt 的 `faces` 删掉 docs。旧探针只判「声明的面都动了」,这一改照样全绿(V52 §2.5);
1681
1546
  # 反向判据必须红并点名那个没被声明的面。
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env bash
2
+ # P426: exercise the actual isolation predicates without starting tmux or writing to a live team.
3
+ # --ref <commit> runs the same expectations against the old predicates (expected red).
4
+ set -euo pipefail
5
+ SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ ROOT="$(cd "$SELF_DIR/../../.." && pwd)"
7
+ REF=""
8
+ if [ "${1:-}" = --ref ] && [ "$#" = 2 ]; then REF="$2"
9
+ elif [ "$#" != 0 ]; then printf 'usage: isolation-ledger.sh [--ref <commit>]\n' >&2; exit 2; fi
10
+ TMP="$(mktemp -d -p /var/tmp p426-isolation.XXXXXX)"
11
+ trap 'rm -rf "$TMP"' EXIT
12
+ for file in smoke.sh tmux-identity-leak.sh; do
13
+ if [ -n "$REF" ]; then git -C "$ROOT" show "$REF:skills/teamsmith/tests/$file" > "$TMP/$file"
14
+ else cp "$SELF_DIR/$file" "$TMP/$file"; fi
15
+ done
16
+ # Extract the checked-in functions and the actual closing verdict, not a second implementation.
17
+ python3 - "$TMP" <<'PY'
18
+ import pathlib, re, sys
19
+ root = pathlib.Path(sys.argv[1])
20
+ for file, name in [('smoke.sh', 'real_ledger_hits'), ('tmux-identity-leak.sh', 'ledger_manifest')]:
21
+ text = (root / file).read_text()
22
+ body = re.search(r'^' + name + r'\(\).*?^}', text, re.M | re.S)
23
+ if not body:
24
+ raise SystemExit('missing predicate: ' + name)
25
+ (root / (name + '.sh')).write_text(body[0] + '\n')
26
+ text = (root / 'tmux-identity-leak.sh').read_text()
27
+ start = text.index('LEDGER_AFTER=')
28
+ end = text.index('ROOTS_AFTER=', start)
29
+ (root / 'verdict.sh').write_text(text[start:end])
30
+ PY
31
+ . "$SELF_DIR/lib/main-team-fingerprint.sh"
32
+ . "$TMP/real_ledger_hits.sh"
33
+ . "$TMP/ledger_manifest.sh"
34
+ PASS=0; FAIL=0
35
+ ok() { printf 'ok: %s\n' "$1"; PASS=$((PASS + 1)); }
36
+ bad() { printf 'bad: %s\n' "$1"; FAIL=$((FAIL + 1)); }
37
+ expect() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (expected=$3 actual=$2)"; fi; }
38
+
39
+ SCAN="$TMP/scan"
40
+ mkdir -p "$SCAN/docs/team/inbox" "$SCAN/.pi/team/state"
41
+ # Reports may quote old sessions, old temp roots, family prefixes and fixture aliases in any file.
42
+ printf '%s\n' 'Old incident: teamsmith-smoke-758714; teamsmith-smoke-p10-1; teamsmith-smoke-m16-2; teamsmith-smoke-m98-3; teamsmith-smoke-pm_skills-deb708fe.OLDROOT' \
43
+ 'P10 夹具阻塞行 / P10Z / $P10SESS / M16A / M98G / never lands / held body / OB-EXT-KNOCK' \
44
+ > "$SCAN/docs/team/inbox/history.md"
45
+ cp "$SCAN/docs/team/inbox/history.md" "$SCAN/.pi/team/state/notify.log"
46
+ cp "$SCAN/docs/team/inbox/history.md" "$SCAN/.pi/team/state/history.env"
47
+ for session in "teamsmith-smoke-$$" "teamsmith-smoke-p10-$$" "teamsmith-smoke-m16-$$" "teamsmith-smoke-m98-$$"; do
48
+ pats="$(printf '%s\n' "$session" "${TMP##*/}")"
49
+ expect "scanner [$session]: historical messages and old aliases are not this run's leakage" \
50
+ "$(real_ledger_hits "$pats" "$SCAN" | wc -l | tr -d ' ')" 0
51
+ printf 'fixture session: %s:dev\n' "$session" > "$SCAN/docs/team/inbox/current.md"
52
+ current_hits="$(real_ledger_hits "$pats" "$SCAN")"
53
+ printf 'current-session hits: %s\n' "$current_hits"
54
+ expect "scanner [$session]: this run's session written into inbox must be caught" \
55
+ "$(printf '%s\n' "$current_hits" | grep -c 'inbox/current.md$')" 1
56
+ rm "$SCAN/docs/team/inbox/current.md"
57
+ printf 'fixture root: %s/fixture\n' "$TMP" > "$SCAN/.pi/team/state/current.env"
58
+ cp "$SCAN/.pi/team/state/current.env" "$SCAN/.pi/team/state/notify-current.log"
59
+ expect "scanner [$session]: this run's temp root in state and notify must be caught" \
60
+ "$(real_ledger_hits "$pats" "$SCAN" | wc -l | tr -d ' ')" 2
61
+ rm "$SCAN/.pi/team/state/current.env" "$SCAN/.pi/team/state/notify-current.log"
62
+ done
63
+
64
+ # Same before/after manifest and closing branch used by the identity fixture, on a nonempty live shape.
65
+ for mode in telemetry inbox unknown-state; do
66
+ REPO_ROOT="$TMP/$mode"
67
+ REAL_INBOX="$REPO_ROOT/docs/team/inbox"; REAL_STATE="$REPO_ROOT/.pi/team/state"
68
+ mkdir -p "$REAL_INBOX" "$REAL_STATE"
69
+ printf 'original\n' > "$REAL_INBOX/dev.md"
70
+ printf 'tick\n' > "$REAL_STATE/watchdog.log"
71
+ printf 'delivery\n' > "$REAL_STATE/notify.log"
72
+ LEDGER_BEFORE="$(ledger_manifest "$REAL_INBOX" "$REAL_STATE")"
73
+ LEDGER_N="$(printf '%s\n' "$LEDGER_BEFORE" | wc -l)"
74
+ case "$mode" in
75
+ telemetry) printf 'next tick\n' >> "$REAL_STATE/watchdog.log"; printf 'next delivery\n' >> "$REAL_STATE/notify.log"; expected=0 ;;
76
+ inbox) printf 'unintended write\n' >> "$REAL_INBOX/dev.md"; expected=1 ;;
77
+ unknown-state) mkdir "$REAL_STATE/unregistered"; printf 'unintended write\n' > "$REAL_STATE/unregistered/new.log"; expected=1 ;;
78
+ esac
79
+ # The verdict functions print their real lines, while this subshell's result counts rejected writes.
80
+ actual="$(FAIL=0; . "$TMP/verdict.sh"; printf '\nrejected=%s\n' "$FAIL")"
81
+ printf '%s\n' "$actual"
82
+ expect "identity ledger: $mode" "${actual##*rejected=}" "$expected"
83
+ done
84
+ printf 'isolation-ledger: pass=%s fail=%s\n' "$PASS" "$FAIL"
85
+ [ "$FAIL" = 0 ]
@@ -16,6 +16,10 @@
16
16
  # main_team_volatile <./relpath> → 0 = the shape is allowed to move
17
17
  # main_team_violations <before> <after> → one path per non-whitelisted change
18
18
  # main_team_volatile_changes <b> <a> → count of whitelisted changes (proves the check sees motion)
19
+ # main_team_touched <b> <a> <./prefix> → one path per file under the prefix that appeared, vanished
20
+ # or changed (the accident-shape probe: "this run must not
21
+ # have written it", which stays true when the path is a
22
+ # legitimate runtime file the real team owns)
19
23
  #
20
24
  # MAIN_TEAM_BREAK=skip-state is the fixtures' own red side: it restores the old "skip state/" shape so
21
25
  # a stray file there stops being reported. Product code never reads it.
@@ -59,7 +63,7 @@ main_team_volatile() { # <relative path, starting with ./ >
59
63
  inbox-*|pm-*|pm.*|dispatch-*|draft-*|held) return 0 ;;
60
64
  notify*|nudge*|watchdog*|capacity*|digest-*|deaths.*|bg.log|panel*) return 0 ;;
61
65
  changes.json|refs|pane|_watch.*|reload-requested|interrupt.*|update-check.*|config.*) return 0 ;;
62
- summary-*|prompt-*|pm-loaded.*|pm-launch*) return 0 ;;
66
+ summary-*|prompt-*|pm-launch*) return 0 ;;
63
67
  esac
64
68
  return 1 ;;
65
69
  esac
@@ -94,6 +98,18 @@ main_team_volatile_changes() { # <before> <after> → number of whitelisted path
94
98
  printf '%s\n' "$n"
95
99
  }
96
100
 
101
+ # The accident-shape probe. "This path must not exist" is the wrong judgement for a live project: the
102
+ # team legitimately owns e.g. state/standby until it migrates. The judgement that stays true is "this
103
+ # run did not create, change or remove it", which covers a file that was never there and one that was.
104
+ main_team_touched() { # <before> <after> <./prefix> → one path per file under the prefix that moved
105
+ local before="$1" after="$2" prefix="$3" path b a
106
+ join -t "$(printf '\t')" -a1 -a2 -e MISSING -o '0,1.2,2.2' "$before" "$after" |
107
+ while IFS="$(printf '\t')" read -r path b a; do
108
+ [ "$b" = "$a" ] && continue
109
+ case "$path" in "$prefix"|"$prefix"/*) printf '%s\n' "$path" ;; esac
110
+ done
111
+ }
112
+
97
113
  # The proof target is this project's **main checkout**, never this worktree: the fixture runs from a
98
114
  # worktree while the authority must never land in the main checkout.
99
115
  main_team_project_root() { # <skill-dir> → the main checkout (empty when this checkout has none)
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env bash
2
+ # Live probe for marker capture, run against THIS working tree (not an installed release).
3
+ #
4
+ # Cost: it starts one real PM session and asks the model for one reply, so it is not part of any
5
+ # gate. Use it before cutting a release that touches scripts/reply-capture.mjs or extension/team-reply.ts.
6
+ #
7
+ # bash skills/teamsmith/tests/live-capture-probe.sh [scratch-dir]
8
+ #
9
+ # Success is three facts, printed at the end: the marker is gone from the persisted reply, the
10
+ # journal's newest source is `saved` with a number, and the reply store grew.
11
+ set -euo pipefail
12
+
13
+ repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)
14
+ probe=${1:-/var/tmp/teamsmith-live-probe}
15
+ model=${PROBE_PM_MODEL:-deepseek/deepseek-flash}
16
+ team="$repo_root/skills/teamsmith/scripts/team"
17
+ unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_STATE_DIR TEAM_CONFIG_FILE TEAM_PM_WINDOW
18
+
19
+ rm -rf "$probe"; mkdir -p "$probe"
20
+ git -C "$probe" init -q .
21
+ git -C "$probe" -c user.email=probe@local -c user.name=probe commit -q --allow-empty -m init
22
+
23
+ cd "$probe"
24
+ bash "$team" init --no-skills --session probe --agents dev --pm-model "$model" \
25
+ --task-models "code=$model verify=$model analysis=$model" >/dev/null
26
+ bash "$team" up >/dev/null
27
+ sleep 35
28
+ # team up creates the session on the caller's tmux server; point the probe at that same server
29
+ # (the PM session lives there), while every probe-issued call goes through its own socket below.
30
+
31
+ session=probe
32
+ # The probe owns a private tmux server: every call goes through tmux_probe (isolated socket),
33
+ # so it never disturbs a caller's session and the tmux isolation lint can verify that.
34
+ probe_socket="$probe/tmux-private"
35
+ mkdir -p "$probe_socket"
36
+ tmux_probe() { env -u TMUX TMUX_TMPDIR="$probe_socket" tmux -S "$probe_socket/tmux.sock" "$@"; }
37
+ # The probe owns a private tmux server: all mutating calls go through tmux_probe (isolated socket),
38
+ # and the caller's server is never touched. team up uses its own session; send the model prompt the
39
+ # same way the probe owns, via that private socket.
40
+ tmux_probe send-keys -t "$session:pm" '正文一句。最后一行单独写 [[team-reply]]' Enter
41
+ sleep 55
42
+
43
+ journal=$(ls .pi/team/state/reply-capture/*.json | grep -v runtime | head -1)
44
+ store=.pi/team/state/key-replies/index.v1
45
+
46
+ python3 - "$journal" "$store" <<'PY'
47
+ import json, sys
48
+ journal, store, os = sys.argv[1], sys.argv[2], __import__('os')
49
+ data = json.load(open(journal))
50
+ records = list(data['sources'].values())
51
+ saved = [r for r in records if r.get('status') == 'saved' and isinstance(r.get('no'), int)]
52
+ bodies = [json.dumps(r.get('message', {}), ensure_ascii=False) for r in saved]
53
+ marker_left = any('[[team-reply' in b for b in bodies)
54
+ size = os.path.getsize(store) if os.path.exists(store) else 0
55
+ print(f'journal sources: {len(records)} | saved: {len(saved)}')
56
+ print(f'marker in published body: {marker_left}')
57
+ print(f'store bytes: {size}')
58
+ sys.exit(0 if saved and not marker_left and size > 0 else 1)
59
+ PY
60
+
61
+ status=$?
62
+ tmux_probe kill-server 2>/dev/null || true
63
+ exit $status
@@ -63,6 +63,11 @@ PK_COUNTS_MODE='stub' # stub | real(policy 档用真读者)
63
63
  PK_PM_STATE='running:fixture'
64
64
  PK_NOW=100000
65
65
  mkdir -p "$PK_STATE" "$PK_PROJ/docs/team" "$PK_PROJ/worktrees"
66
+ # 夹具的“项目主工作树”得是真 git 仓库,而且脚本要在它里面跑:待命自 1.3 起住在项目状态权威的
67
+ # 快照里,权威按“当前目录所属项目”钉住状态根(继承的 TEAM_MAIN_ROOT 与目录不一致会被拒)。
68
+ git -C "$PK_PROJ" init -q -b main &&
69
+ git -C "$PK_PROJ" -c user.email=pk@fixture -c user.name=pk commit -q --allow-empty -m init || exit 3
70
+ cd "$PK_PROJ" || exit 3
66
71
 
67
72
  export TEAM_ROOT="$PK_PURE" TEAM_MAIN_ROOT="$PK_PROJ" TEAM_STATE_DIR="$PK_STATE" \
68
73
  TEAM_DOCS_ABS="$PK_PROJ/docs/team" TEAM_DOCS_DIR="docs/team" TEAM_SESSION="pk-fixture-session" \