teamsmith 0.0.0-stage → 0.1.2

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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/bin/team.mjs +59 -0
  4. package/install.sh +94 -0
  5. package/package.json +37 -4
  6. package/skills/teamsmith/CHANGELOG.md +763 -0
  7. package/skills/teamsmith/SKILL.md +312 -0
  8. package/skills/teamsmith/extension/team-bg.ts +435 -0
  9. package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
  10. package/skills/teamsmith/extension/team-notify.ts +663 -0
  11. package/skills/teamsmith/references/agent-adapters.md +643 -0
  12. package/skills/teamsmith/references/config.md +477 -0
  13. package/skills/teamsmith/references/meeting.md +124 -0
  14. package/skills/teamsmith/references/memory.md +133 -0
  15. package/skills/teamsmith/references/migration.md +227 -0
  16. package/skills/teamsmith/references/openspec.md +222 -0
  17. package/skills/teamsmith/references/philosophy.md +95 -0
  18. package/skills/teamsmith/references/protocol.md +712 -0
  19. package/skills/teamsmith/references/troubleshooting.md +1384 -0
  20. package/skills/teamsmith/references/workflows.md +448 -0
  21. package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
  22. package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
  23. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
  24. package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
  25. package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
  26. package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
  27. package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
  28. package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
  29. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
  30. package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
  31. package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
  32. package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
  33. package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
  34. package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
  35. package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
  36. package/skills/teamsmith/scripts/lib/common.sh +4964 -0
  37. package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
  38. package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
  39. package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
  40. package/skills/teamsmith/scripts/monitor.mjs +616 -0
  41. package/skills/teamsmith/scripts/panel/README.md +192 -0
  42. package/skills/teamsmith/scripts/panel/build.sh +47 -0
  43. package/skills/teamsmith/scripts/panel/bun.lock +109 -0
  44. package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
  45. package/skills/teamsmith/scripts/panel/package.json +24 -0
  46. package/skills/teamsmith/scripts/panel/panel.js +388 -0
  47. package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
  48. package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
  49. package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
  50. package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
  51. package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
  52. package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
  53. package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
  54. package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
  55. package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
  56. package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
  57. package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
  58. package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
  59. package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
  60. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
  61. package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
  62. package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
  63. package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
  64. package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
  65. package/skills/teamsmith/scripts/shim/signal-gate +156 -0
  66. package/skills/teamsmith/scripts/shim/tmux +403 -0
  67. package/skills/teamsmith/scripts/team +143 -0
  68. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
  69. package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
  70. package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
  71. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
  72. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
  73. package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
  74. package/skills/teamsmith/templates/config.sh.tmpl +106 -0
  75. package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
  76. package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
  77. package/skills/teamsmith/templates/report.md.tmpl +36 -0
  78. package/skills/teamsmith/templates/task.md.tmpl +65 -0
  79. package/skills/teamsmith/templates/threads-README.md +17 -0
  80. package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
  81. package/skills/teamsmith/tests/bg-ledger.sh +307 -0
  82. package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
  83. package/skills/teamsmith/tests/config-cli.sh +1562 -0
  84. package/skills/teamsmith/tests/container-tmux.sh +493 -0
  85. package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
  86. package/skills/teamsmith/tests/death-cause.sh +564 -0
  87. package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
  88. package/skills/teamsmith/tests/fake-tui.py +450 -0
  89. package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
  90. package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
  91. package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
  92. package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
  93. package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
  94. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
  95. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
  96. package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
  97. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
  98. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
  99. package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
  100. package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
  101. package/skills/teamsmith/tests/flip-glue.sh +162 -0
  102. package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
  103. package/skills/teamsmith/tests/flip-m12.sh +185 -0
  104. package/skills/teamsmith/tests/flip-m16.sh +166 -0
  105. package/skills/teamsmith/tests/flip-m17.sh +204 -0
  106. package/skills/teamsmith/tests/flip-m33.sh +284 -0
  107. package/skills/teamsmith/tests/flip-m34.sh +96 -0
  108. package/skills/teamsmith/tests/flip-m37.sh +185 -0
  109. package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
  110. package/skills/teamsmith/tests/flip-m43.sh +128 -0
  111. package/skills/teamsmith/tests/flip-m44.sh +262 -0
  112. package/skills/teamsmith/tests/flip-m45.sh +244 -0
  113. package/skills/teamsmith/tests/flip-m46.sh +238 -0
  114. package/skills/teamsmith/tests/flip-m48.sh +304 -0
  115. package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
  116. package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
  117. package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
  118. package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
  119. package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
  120. package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
  121. package/skills/teamsmith/tests/flip-p144.sh +112 -0
  122. package/skills/teamsmith/tests/flip-p156.sh +133 -0
  123. package/skills/teamsmith/tests/flip-p158.sh +301 -0
  124. package/skills/teamsmith/tests/flip-p160.sh +182 -0
  125. package/skills/teamsmith/tests/flip-p171.sh +249 -0
  126. package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
  127. package/skills/teamsmith/tests/flip-p20.sh +286 -0
  128. package/skills/teamsmith/tests/flip-p201.sh +249 -0
  129. package/skills/teamsmith/tests/flip-p210.sh +239 -0
  130. package/skills/teamsmith/tests/flip-p211.sh +152 -0
  131. package/skills/teamsmith/tests/flip-p217.sh +288 -0
  132. package/skills/teamsmith/tests/flip-p22.sh +123 -0
  133. package/skills/teamsmith/tests/flip-p23.sh +239 -0
  134. package/skills/teamsmith/tests/flip-p25.sh +165 -0
  135. package/skills/teamsmith/tests/flip-p71.sh +184 -0
  136. package/skills/teamsmith/tests/flip-p72.sh +202 -0
  137. package/skills/teamsmith/tests/frames/README.md +176 -0
  138. package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
  139. package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
  140. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
  141. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
  142. package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
  143. package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
  144. package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
  145. package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
  146. package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
  147. package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
  148. package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
  149. package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
  150. package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
  151. package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
  152. package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
  153. package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
  154. package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
  155. package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
  156. package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
  157. package/skills/teamsmith/tests/gate-guard.sh +112 -0
  158. package/skills/teamsmith/tests/guard-matrix.sh +233 -0
  159. package/skills/teamsmith/tests/install-shape.sh +731 -0
  160. package/skills/teamsmith/tests/ledger-ban.sh +612 -0
  161. package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
  162. package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
  163. package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
  164. package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
  165. package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
  166. package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
  167. package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
  168. package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
  169. package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
  170. package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
  171. package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
  172. package/skills/teamsmith/tests/load-experiment.sh +290 -0
  173. package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
  174. package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
  175. package/skills/teamsmith/tests/panel-b2.sh +1183 -0
  176. package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
  177. package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
  178. package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
  179. package/skills/teamsmith/tests/panel-b3.sh +1301 -0
  180. package/skills/teamsmith/tests/panel-choices.sh +572 -0
  181. package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
  182. package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
  183. package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
  184. package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
  185. package/skills/teamsmith/tests/panel-cpu.sh +391 -0
  186. package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
  187. package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
  188. package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
  189. package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
  190. package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
  191. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
  192. package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
  193. package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
  194. package/skills/teamsmith/tests/panel-knobs.sh +83 -0
  195. package/skills/teamsmith/tests/panel-p21.sh +2181 -0
  196. package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
  197. package/skills/teamsmith/tests/panel-strings.mjs +195 -0
  198. package/skills/teamsmith/tests/perf.sh +740 -0
  199. package/skills/teamsmith/tests/pm-box-real.sh +350 -0
  200. package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
  201. package/skills/teamsmith/tests/routes.sh +1652 -0
  202. package/skills/teamsmith/tests/section-budgets.tsv +150 -0
  203. package/skills/teamsmith/tests/section-guard.sh +231 -0
  204. package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
  205. package/skills/teamsmith/tests/section-paths.tsv +142 -0
  206. package/skills/teamsmith/tests/section-select.sh +655 -0
  207. package/skills/teamsmith/tests/signal-gate.sh +366 -0
  208. package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
  209. package/skills/teamsmith/tests/signal-lint.pl +416 -0
  210. package/skills/teamsmith/tests/skill-load.mjs +65 -0
  211. package/skills/teamsmith/tests/smoke.sh +19711 -0
  212. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
  213. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
  214. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
  215. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
  216. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
  217. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
  218. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
  219. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
  220. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
  221. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
  222. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
  223. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
  224. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
  225. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
  226. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
  227. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
  228. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
  229. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
  230. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
  231. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
  232. package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
  233. package/skills/teamsmith/tests/spec-refs.sh +826 -0
  234. package/skills/teamsmith/tests/task-header-model.sh +267 -0
  235. package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
  236. package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
  237. package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
  238. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
  239. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
  240. package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
  241. package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
  242. package/skills/teamsmith/tests/tmux-lint.pl +604 -0
  243. package/skills/teamsmith-init/SKILL.md +100 -0
  244. package/skills/teamsmith-init/references/bootstrap.md +74 -0
  245. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
@@ -0,0 +1,1183 @@
1
+ #!/usr/bin/env bash
2
+ # Compose-entry fixtures (pulse-console B2, P13): the pty/tmux proofs for tasks.md items 2.1–2.6
3
+ # and 3.1–3.2.
4
+ #
5
+ # bash skills/teamsmith/tests/panel-b2.sh # every scenario
6
+ # bash skills/teamsmith/tests/panel-b2.sh cjk draft # selected scenarios
7
+ # TEAM_B2_KEEP=1 bash skills/teamsmith/tests/panel-b2.sh # keep the fixture directory
8
+ #
9
+ # Every scenario runs in a **private tmux server** (`-L p13b2-$$`) and a fresh fixture project, so
10
+ # the real team session is never touched. The private server's panes inherit the server
11
+ # environment, which is why the identity isolation below is the first thing the script does.
12
+ #
13
+ # Scenarios
14
+ # cursor P20/B1 insertion-point cursor: codepoint steps, wide glyphs, line breaks, the window
15
+ # keys P20/B2 pi's key map: word/line/forward-delete, kill ring, Kitty encodings, undo
16
+ # multiline P20/B3 ctrl+j inserts a break, enter submits, Kitty shift+enter, single-line reason
17
+ # clipboard P20/B4 C-v: the image probe order, text fallback, the bounds, the temp file
18
+ # cjk 2.1 CJK-wide cursor column + codepoint backspace (`tmux display -p '#{cursor_x}'`)
19
+ # draft 2.2 Esc keeps the draft across a relaunch; `\r` is normalized on intake
20
+ # editor B3 `C-o` relays to $EDITOR (C-e is the line-end key); the relay is lossless
21
+ # receipt 2.4 the three honest receipts: busy → queued, empty → delivered, eaten Enter → held
22
+ # pause 2.5 a refresh completes mid-compose: the draft survives, the frame advanced
23
+ # paste 2.6 plain and bracketed three-line pastes are one message each
24
+ # actions 3.1 `f` runs `team outbox flush`; `s` toggles standby with a reason line
25
+ # readonly 3.2 the write sweep: only the console's own files may change
26
+ #
27
+ # Exit: 0 every selected scenario green, 1 at least one assertion failed, 3 setup failure.
28
+ set -uo pipefail
29
+
30
+ # ── identity isolation (must be first): never inherit the caller's team identity ────────────────
31
+ unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_ROOT_SOURCE TEAM_ROOT_WAS TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM \
32
+ TEAM_PM_WINDOW TEAM_AGENTS TEAM_DOCS_DIR TEAM_WORKTREES_DIR TEAM_GATES TEAM_VCS TEAM_CONFIG_FILE \
33
+ TEAM_ALLOW_FOREIGN_SESSION TEAM_PULSE_WINDOW TEAM_WATCH_WINDOW TEAM_STATE_DIR TEAM_JS_BIN \
34
+ TEAM_MONITOR_REFRESH TEAM_MONITOR_UI TEAM_MONITOR_ACTIVITY TEAM_AGENT_LOG_GLOB 2>/dev/null || true
35
+
36
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
38
+ . "$here/lib/tmp-root.sh"
39
+ # P162:破坏性调用(kill-server/kill-session/kill-window)动手前先证明私有 socket 生效
40
+ . "$here/lib/tmux-iso.sh"
41
+ tree="${TEAM_B2_TREE:-$(cd -P "$here/../../.." && pwd)}"
42
+ skill="$tree/skills/teamsmith"
43
+ panel="${TEAM_B2_PANEL:-$skill/scripts/panel/panel.js}"
44
+ fake_tui="$here/fake-tui.py"
45
+
46
+ js="${TEAM_B2_JS:-$(command -v node || true)}"
47
+ [ -n "$js" ] || js="$(command -v bun || true)"
48
+ sock="p13b2-$$"
49
+ sess="p13b2-$$"
50
+ keep="${TEAM_B2_KEEP:-0}"
51
+ [ "$keep" = "1" ] && export TEAM_TMP_KEEP=1
52
+ tmp="$(tmp_root_create panel-b2)" || exit 3
53
+ PASS=0
54
+ FAIL=0
55
+ ROOT=""
56
+ current=""
57
+
58
+ # TEAM_B2_PANEL=<bundle>:翻转夹具用。启动器只会跑 $TEAM_SKILL_DIR/scripts/panel/panel.js,
59
+ # 所以把 skill 目录硬链成一份、换掉那个 bundle,再把 TEAM_SKILL_DIR 指过去。
60
+ if [ -n "${TEAM_B2_PANEL:-}" ]; then
61
+ mkdir -p "$tmp/skill-flip"
62
+ cp -al "$skill/." "$tmp/skill-flip/" 2>/dev/null || cp -r "$skill/." "$tmp/skill-flip/"
63
+ rm -f "$tmp/skill-flip/scripts/panel/panel.js"
64
+ cp "$TEAM_B2_PANEL" "$tmp/skill-flip/scripts/panel/panel.js"
65
+ skill="$tmp/skill-flip"
66
+ panel="$skill/scripts/panel/panel.js"
67
+ skill_env="TEAM_SKILL_DIR=$(printf '%q' "$skill") "
68
+ fi
69
+
70
+ cleanup() {
71
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
72
+ # P162:收尾先证明私有 socket 生效(不成立就拒绝;cleanup 里不许 exit)
73
+ tmux_iso_guard_soft "panel-b2" "收尾:私有 server" --tmpdir "${TMUX_TMPDIR:-}" --sock-name "$sock" \
74
+ && tmux -L "$sock" kill-server 2>/dev/null || true
75
+ rm -f "${TMUX_TMPDIR:-/tmp}/tmux-$(id -u)/$sock" 2>/dev/null || true
76
+ if [ "$keep" = "1" ]; then
77
+ printf '\n保留夹具目录:%s\n' "$tmp"
78
+ else
79
+ tmp_root_reap_all
80
+ fi
81
+ }
82
+ trap cleanup EXIT
83
+
84
+ section() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
85
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
86
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
87
+ assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
88
+ assert_has() { grep -qF -- "$2" "$1" 2>/dev/null && ok "$3" || bad "$3($1 里找不到 [$2])"; }
89
+ cond_skip() { printf ' \033[33mSKIP(条件不满足)\033[0m %s\n' "$1${2:+ —— $2}"; }
90
+ assert_match() { grep -qE -- "$2" "$1" 2>/dev/null && ok "$3" || bad "$3($1 里没有匹配 [$2])"; }
91
+ assert_not_has() { grep -qF -- "$2" "$1" 2>/dev/null && bad "$3(不该出现 [$2])" || ok "$3"; }
92
+
93
+ if ! command -v tmux >/dev/null 2>&1; then
94
+ printf 'panel-b2: tmux is required (the fixtures drive real panes)\n' >&2
95
+ exit 3
96
+ fi
97
+ if ! command -v python3 >/dev/null 2>&1; then
98
+ printf 'panel-b2: python3 is required (the fake PM pane)\n' >&2
99
+ exit 3
100
+ fi
101
+ if [ -z "$js" ]; then
102
+ printf 'panel-b2: no node/bun runtime for the console bundle\n' >&2
103
+ exit 3
104
+ fi
105
+ [ -f "$panel" ] || { printf 'panel-b2: no bundle at %s\n' "$panel" >&2; exit 3; }
106
+ [ -f "$fake_tui" ] || { printf 'panel-b2: no fake TUI at %s\n' "$fake_tui" >&2; exit 3; }
107
+
108
+ # ---------------------------------------------------------------- fixture plumbing
109
+ server_up() { # <name> → fresh project + private tmux session
110
+ current="$1"
111
+ ROOT="$tmp/$1/root"
112
+ mkdir -p "$ROOT"
113
+ ( cd "$ROOT" && git init -q -b main && git config user.email b2@teamsmith && git config user.name b2 \
114
+ && echo "# $1" > README.md && git add -A && git commit -qm init ) >/dev/null 2>&1
115
+ mkdir -p "$ROOT/docs/team" "$ROOT/.pi/team/state"
116
+ tmux -L "$sock" kill-server 2>/dev/null || true
117
+ rm -f "${TMUX_TMPDIR:-/tmp}/tmux-$(id -u)/$sock" 2>/dev/null || true
118
+ ( cd "$ROOT" && bash "$skill/scripts/team" init --session "$sess" --agents "dev verify" --vcs local \
119
+ --gates "true" --docs docs/team ) >"$tmp/$1/init.log" 2>&1 \
120
+ || { printf 'panel-b2: team init failed\n' >&2; tail -3 "$tmp/$1/init.log" >&2; exit 3; }
121
+ mkdir -p "$ROOT/.pi/team/state" "$ROOT/docs/team"
122
+ # The private server: the panes inherit its environment, and its `TMUX` routes every `team`
123
+ # subprocess the console spawns back to this server (never the real session).
124
+ tmux -L "$sock" new-session -d -s "$sess" -x 120 -y 30 -n bootstrap -c "$ROOT" 'sleep 600'
125
+ # P20: the cursor/window scenarios resize their window; a manual window size keeps the resize
126
+ # (no client is attached, so tmux would otherwise re-fit the session's default).
127
+ tmux -L "$sock" set -g window-size manual 2>/dev/null || true
128
+ }
129
+
130
+ start_pm() { # <draft> [extra env string]
131
+ local draft="$1" extra="${2:-}"
132
+ tmux -L "$sock" kill-window -t "$sess:pm" 2>/dev/null || true
133
+ tmux -L "$sock" new-window -d -t "$sess" -n pm -c "$ROOT" \
134
+ "FAKE_TUI_DRAFT=$(printf '%q' "$draft") FAKE_TUI_COLS=100 FAKE_TUI_SUBMIT_LOG=$(printf '%q' "$tmp/$current/submit.log") $extra python3 '$fake_tui'"
135
+ sleep 1
136
+ }
137
+
138
+ start_panel() { # [extra env string] [panel args...]
139
+ local extra="${1:-}"
140
+ [ $# -gt 0 ] && shift
141
+ tmux -L "$sock" kill-window -t "$sess:panel" 2>/dev/null || true
142
+ tmux -L "$sock" new-window -d -t "$sess" -n panel -c "$ROOT" \
143
+ "TEAM_JS_BIN=$(printf '%q' "$js") ${skill_env:-}$extra exec bash '$skill/scripts/team' monitor --no-pulse --interval 1 ${*:-}"
144
+ wait_panel
145
+ }
146
+
147
+ wait_panel() { # the first frame is on screen
148
+ local i
149
+ for i in $(seq 1 40); do
150
+ if tmux -L "$sock" capture-pane -p -t "$sess:panel" 2>/dev/null | grep -qF 'teamsmith pulse'; then
151
+ sleep 0.4
152
+ return 0
153
+ fi
154
+ sleep 0.25
155
+ done
156
+ printf 'panel-b2: the console pane never rendered (%s)\n' "$current" >&2
157
+ tmux -L "$sock" capture-pane -p -t "$sess:panel" 2>/dev/null | tail -5 >&2
158
+ return 1
159
+ }
160
+
161
+ cap() { tmux -L "$sock" capture-pane -p -t "$sess:panel" -S -400 2>/dev/null; }
162
+ cap_to() { cap > "$tmp/$current/${1:-cap}.txt"; }
163
+ cap_has() { local f="$tmp/$current/${2:-cap}.txt"; cap >"$f"; assert_has "$f" "$1" "捕获里有 [$1]"; }
164
+ cap_not_has() { local f="$tmp/$current/${2:-cap}.txt"; cap >"$f"; assert_not_has "$f" "$1" "捕获里没有 [$1]"; }
165
+ pm_cap() { tmux -L "$sock" capture-pane -p -t "$sess:pm" -S -1000 2>/dev/null; }
166
+ keys() { tmux -L "$sock" send-keys -t "$sess:panel" "$@" 2>/dev/null; }
167
+ type_text() { tmux -L "$sock" send-keys -l -t "$sess:panel" "$1" 2>/dev/null; }
168
+ cursor_x() { tmux -L "$sock" display -p -t "$sess:panel" '#{cursor_x}' 2>/dev/null | tr -d ' '; }
169
+ cursor_y() { tmux -L "$sock" display -p -t "$sess:panel" '#{cursor_y}' 2>/dev/null | tr -d ' '; }
170
+ # The visible pane only (no scrollback): tmux's `#{cursor_y}` is 0-based over exactly these rows.
171
+ cap_visible() { tmux -L "$sock" capture-pane -p -t "$sess:panel" 2>/dev/null; }
172
+ # The 0-based visible row of the first line matching <pattern> (-1 when absent).
173
+ vis_row() { cap_visible | grep -nF -- "$1" | head -1 | cut -d: -f1 | awk '{print ($1 == "" ? -1 : $1 - 1)}'; }
174
+ # Draft rows as drawn in the boxed tray (`│ > …` / `│ …`; the hidden-rows marker has neither).
175
+ draft_rows() { cap_visible | grep -cE '^│ (>| )'; }
176
+ # The number the hidden-rows marker counts, or 0 when the window hides nothing above.
177
+ marker_n() { cap_visible | sed -n 's/.*↑\([0-9][0-9]*\) 行.*/\1/p' | head -1; }
178
+ resize_pane() { tmux -L "$sock" resize-window -t "$sess:panel" -x "$1" -y "$2" 2>/dev/null || true; sleep 1.4; }
179
+ draft_lines_count() { grep -c '' "$(draft_file)" 2>/dev/null || printf '0'; }
180
+ stamp() { cap | grep -oE '[0-9]{2}:[0-9]{2}:[0-9]{2}' | head -1; }
181
+ draft_file() { printf '%s\n' "$ROOT/.pi/team/state/draft.md"; }
182
+ draft() { cat "$(draft_file)" 2>/dev/null || true; }
183
+ entries() { find "$ROOT/.pi/team/state/outbox" -maxdepth 1 -name '*.msg' -type f 2>/dev/null | LC_ALL=C sort; }
184
+ held_entries() { find "$ROOT/.pi/team/state/outbox/held" -maxdepth 1 -name '*.msg' -type f 2>/dev/null | LC_ALL=C sort; }
185
+ payload_of() { awk 'seen{print} $0=="---"{seen=1}' "$1" 2>/dev/null | sed -e '$ { /^$/d }'; }
186
+ submits() {
187
+ local log="$tmp/$current/submit.log"
188
+ if [ -f "$log" ]; then grep -c '^SUBMIT:' "$log" 2>/dev/null; else printf '0'; fi
189
+ }
190
+ last_submit() { sed -n 's/^SUBMIT://p' "$tmp/$current/submit.log" 2>/dev/null | tail -1; }
191
+ snapshot() { ( cd "$ROOT" && find .pi/team/state docs/team -type f 2>/dev/null | sort \
192
+ | while IFS= read -r f; do printf '%s ' "$f"; md5sum "$f" | cut -d' ' -f1; done ) 2>/dev/null; }
193
+
194
+ # ---------------------------------------------------------------- 2.1 CJK cursor and backspace
195
+ scenario_cjk() {
196
+ section "2.1 · m 打开输入行,中文宽字符光标与按码点退格"
197
+ server_up cjk
198
+ start_pm '' ''
199
+ start_panel
200
+ keys m
201
+ sleep 0.8
202
+ cap_to after-m
203
+ assert_match "$tmp/cjk/after-m.txt" '│ >' "2.1 'm' 打开底部输入行(带框托盘)"
204
+ type_text '中文ab'
205
+ sleep 0.8
206
+ cap_to after-cjk
207
+ assert_eq "2.1 中文ab 之后 cursor_x=10(托盘 │ + 空格 =2 列,> =2 列 + 中文 4 列 + ab 2 列)" "$(cursor_x)" "10"
208
+ assert_has "$tmp/cjk/after-cjk.txt" "> 中文ab" "2.1 输入行显示 > 中文ab"
209
+ keys BSpace
210
+ sleep 0.5
211
+ assert_eq "2.1 退格删掉一个半角码点:cursor_x=9" "$(cursor_x)" "9"
212
+ keys BSpace
213
+ sleep 0.5
214
+ cap_to after-bs
215
+ assert_eq "2.1 退格删掉整个宽字符(不是半个):cursor_x=8" "$(cursor_x)" "8"
216
+ assert_has "$tmp/cjk/after-bs.txt" "> 中文" "2.1 宽字符被整字删除"
217
+ keys BSpace
218
+ sleep 0.5
219
+ assert_eq "2.1 宽字符退格:中文 → 中,cursor_x=6" "$(cursor_x)" "6"
220
+ # astral plane: one codepoint, two UTF-16 units — a code-unit backspace would leave half
221
+ type_text '🙂'
222
+ sleep 0.6
223
+ assert_eq "2.1 星平面字符(emoji)按两个显示列计:cursor_x=8" "$(cursor_x)" "8"
224
+ keys BSpace
225
+ sleep 0.5
226
+ cap_to after-emoji-bs
227
+ assert_eq "2.1 emoji 退格整个码点删掉:cursor_x=6" "$(cursor_x)" "6"
228
+ assert_has "$tmp/cjk/after-emoji-bs.txt" "> 中" "2.1 emoji 被整字删除(没有半个代理对)"
229
+ assert_eq "2.1 草稿文件同步(state/draft.md)" "$(draft)" "中"
230
+ }
231
+
232
+ # ---------------------------------------------------------------- P20/B1 the insertion-point cursor
233
+ # The model's headless sibling first: the pure cases exit non-zero and name the failing case, so a
234
+ # pty-green bundle with a broken model cannot pass this scenario.
235
+ scenario_cursor() {
236
+ section "B1 · 插入点:码点移动 / 宽字形 / 换行与软换行 / 草稿窗口"
237
+ local bunbin=""
238
+ bunbin="$(command -v bun 2>/dev/null || true)"
239
+ [ -n "$bunbin" ] || { [ -x "$HOME/.bun/bin/bun" ] && bunbin="$HOME/.bun/bin/bun"; }
240
+ if [ -n "$bunbin" ]; then
241
+ if ( cd "$here" && "$bunbin" build panel-compose-model.ts --target=node --format=esm --outfile "$tmp/panel-compose-model.js" ) >"$tmp/cursor/model-build.log" 2>&1; then
242
+ ok "B1 模型夹具:bun 构建成功"
243
+ else
244
+ bad "B1 模型夹具:bun 构建失败"; tail -3 "$tmp/cursor/model-build.log"
245
+ fi
246
+ if "$js" "$tmp/panel-compose-model.js" >"$tmp/cursor/model.log" 2>&1; then
247
+ ok "B1 模型夹具:$(tail -1 "$tmp/cursor/model.log")"
248
+ else
249
+ bad "B1 模型夹具:纯模型用例失败"; grep -A1 '^FAIL' "$tmp/cursor/model.log" | head -6
250
+ fi
251
+ else
252
+ cond_skip "B1 模型夹具" "本机没有 bun(模型夹具要构建 .ts)"
253
+ fi
254
+
255
+ server_up cursor
256
+ start_pm '' ''
257
+ start_panel
258
+ # ① `ad` → ← → 中文 → ← → Backspace:编辑发生在插入点,宽字形是一步、整字删除
259
+ keys m; sleep 0.8
260
+ type_text 'ad'; sleep 0.5
261
+ keys Left; sleep 0.4
262
+ type_text '中文'; sleep 0.5
263
+ keys Left; sleep 0.4
264
+ keys BSpace; sleep 0.6
265
+ cap_to after-bs
266
+ assert_has "$tmp/cursor/after-bs.txt" '> a文d' "B1 插入点 Backspace:草稿 a文d"
267
+ assert_eq "B1 草稿文件 a文d" "$(draft)" "a文d"
268
+ assert_eq "B1 cursor_x=5(托盘 2 + 提示 2 + a)" "$(cursor_x)" "5"
269
+ keys Right; sleep 0.5
270
+ assert_eq "B1 跨宽字形一步 → cursor_x=7" "$(cursor_x)" "7"
271
+ keys BSpace; sleep 0.6
272
+ cap_to after-wide-bs
273
+ assert_has "$tmp/cursor/after-wide-bs.txt" '> ad' "B1 宽字形整字删除(不剩半个)"
274
+ assert_eq "B1 草稿回到 ad" "$(draft)" "ad"
275
+
276
+ # ② 40 列 pane:40 个 x 的草稿,插入点在软换行的第二行;Home + Z 落回第一行
277
+ keys Escape; sleep 0.4
278
+ python3 -c 'import sys; sys.stdout.write("x"*40)' > "$(draft_file)"
279
+ resize_pane 40 30
280
+ keys m; sleep 0.9
281
+ assert_eq "B1 软换行:插入点在第二绘制行 cursor_x=8" "$(cursor_x)" "8"
282
+ keys Home; sleep 0.5
283
+ type_text 'Z'; sleep 0.6
284
+ cap_to wrap
285
+ assert_eq "B1 Home 到逻辑行首:cursor_x=5" "$(cursor_x)" "5"
286
+ assert_eq "B1 cursor_y 指向绘制 Z 的软换行第一行" "$(cursor_y)" "$(vis_row '> Zxxxx')"
287
+ assert_eq "B1 草稿 = Z + 40 个 x(插入在插入点,不在末尾)" "$(draft)" "Z$(python3 -c 'import sys; sys.stdout.write("x"*40)')"
288
+
289
+ # ③ 同一 40 列 pane:ab\nXXXXXXXX,↑ 钳到较短行
290
+ keys Escape; sleep 0.4
291
+ printf 'ab\nXXXXXXXX' > "$(draft_file)"
292
+ keys m; sleep 0.9
293
+ assert_eq "B1 换行草稿:插入点在第二行 cursor_x=12" "$(cursor_x)" "12"
294
+ keys Up; sleep 0.6
295
+ cap_to clamp
296
+ assert_eq "B1 ↑ 钳到较短行 cursor_x=6" "$(cursor_x)" "6"
297
+ assert_eq "B1 cursor_y 指向 ab 行" "$(cursor_y)" "$(vis_row '> ab')"
298
+ assert_has "$tmp/cursor/clamp.txt" 'XXXXXXXX' "B1 另一行原样还在"
299
+
300
+ # ④ 120x30:alpha\nbeta,Home/End/↑/X
301
+ keys Escape; sleep 0.4
302
+ resize_pane 120 30
303
+ printf 'alpha\nbeta' > "$(draft_file)"
304
+ keys m; sleep 0.9
305
+ keys Home; sleep 0.4
306
+ keys End; sleep 0.4
307
+ keys Up; sleep 0.5
308
+ type_text 'X'; sleep 0.6
309
+ cap_to rows
310
+ assert_eq "B1 Home+End+↑+X → alphXa\\nbeta" "$(draft)" "$(printf 'alphXa\nbeta')"
311
+ assert_eq "B1 cursor_x=9(托盘+提示+alphX)" "$(cursor_x)" "9"
312
+ assert_eq "B1 cursor_y 指向 alpha 行" "$(cursor_y)" "$(vis_row '> alphXa')"
313
+
314
+ # ⑤ 120x20 + 30 行草稿:窗口 ≤ 10 行、含插入点行、顶沿计数隐藏行
315
+ keys Escape; sleep 0.4
316
+ resize_pane 120 20
317
+ python3 -c 'import sys; sys.stdout.write("\n".join("L%02d" % i for i in range(1, 31)))' > "$(draft_file)"
318
+ keys m; sleep 0.9
319
+ cap_to window
320
+ local rows_n marker1
321
+ rows_n="$(draft_rows)"
322
+ if [ "$rows_n" -le 10 ] && [ "$rows_n" -ge 1 ]; then
323
+ ok "B1 窗口:草稿行 $rows_n ≤ 10(半屏)"
324
+ else
325
+ bad "B1 窗口:草稿行 $rows_n 不在 1..10"
326
+ fi
327
+ assert_has "$tmp/cursor/window.txt" 'L30' "B1 窗口:插入点所在行 L30 在画面里"
328
+ marker1="$(marker_n)"
329
+ if [ -n "$marker1" ] && [ "$marker1" -gt 0 ]; then
330
+ ok "B1 窗口:顶沿标记隐藏行数(↑$marker1 行)"
331
+ else
332
+ bad "B1 窗口:没有隐藏行标记($(head -1 "$tmp/cursor/window.txt" | cut -c1-40))"
333
+ fi
334
+ assert_eq "B1 窗口:文件里仍是 30 行" "$(draft_lines_count)" "30"
335
+
336
+ # ⑥ 窗口跟随插入点:↑ 12 次到 L18,标记计数变小
337
+ local i
338
+ for i in $(seq 1 12); do keys Up; sleep 0.15; done
339
+ sleep 0.6
340
+ cap_to window-follow
341
+ local marker2
342
+ assert_has "$tmp/cursor/window-follow.txt" 'L18' "B1 窗口跟随:插入点行 L18 可见"
343
+ marker2="$(marker_n)"
344
+ if [ -n "$marker2" ] && [ "$marker1" -gt "$marker2" ] && [ "$marker2" -gt 0 ]; then
345
+ ok "B1 窗口跟随:上方隐藏行减少(↑$marker1 → ↑$marker2)"
346
+ else
347
+ bad "B1 窗口跟随:标记没有变小(↑$marker1 → ↑${marker2:-无})"
348
+ fi
349
+ }
350
+
351
+ # ---------------------------------------------------------------- P20/B2 the pi key map
352
+ scenario_keys() {
353
+ section "B2 · pi 键位:词/行/前向删除、kill ring、Kitty 编码、undo"
354
+ server_up keys
355
+ start_pm '' ''
356
+ start_panel
357
+ # ① 词/行/前向删除:alpha beta gamma → ctrl+w alt+b ctrl+d ctrl+k ctrl+a Z
358
+ keys m; sleep 0.8
359
+ type_text 'alpha beta gamma'; sleep 0.5
360
+ keys C-w; sleep 0.4 # 切 ` gamma`
361
+ keys M-b; sleep 0.4 # 词左移到 beta 开头
362
+ keys C-d; sleep 0.4 # 删前向一个码点(b)
363
+ keys C-k; sleep 0.4 # 删到逻辑行尾
364
+ keys C-a; sleep 0.4 # 逻辑行首
365
+ type_text 'Z'; sleep 0.6
366
+ cap_to words
367
+ assert_eq "B2 词/行/前向删除 → Zalpha " "$(draft)" "Zalpha "
368
+ assert_eq "B2 cursor_x=5(托盘+提示+Z)" "$(cursor_x)" "5"
369
+ assert_eq "B2 没按过 Enter(未提交)" "$(submits)" "0"
370
+
371
+ # ② 逻辑行边界:45 字符行 + second,↑ ctrl+a ctrl+k → \nsecond
372
+ keys Escape; sleep 0.4
373
+ resize_pane 40 30
374
+ python3 -c 'import sys; sys.stdout.write("x"*45 + "\nsecond")' > "$(draft_file)"
375
+ keys m; sleep 0.9
376
+ keys Up; sleep 0.4
377
+ keys C-a; sleep 0.4
378
+ keys C-k; sleep 0.5
379
+ cap_to line
380
+ assert_eq "B2 ctrl+k 删的是逻辑行(整行 45 字符),不是绘制行" "$(draft)" "$(printf '\nsecond')"
381
+ assert_eq "B2 cursor_x=4(托盘+提示,在已空的第一绘制行)" "$(cursor_x)" "4"
382
+
383
+ # ③ Kitty 编码:ctrl+b ×3 + alt+b 与 legacy 字节落在同一插入点
384
+ # (spec 原写 cursor_x 12;实测/算术都是 10 —— alpha beta 末尾 3×← 到 index 7、再一词到 6,
385
+ # `│ > alpha ` 共 10 列。两种编码必须一致,这条断言是硬约束,数值随实测修正。)
386
+ keys Escape; sleep 0.4
387
+ resize_pane 120 30
388
+ printf 'alpha beta' > "$(draft_file)"
389
+ keys m; sleep 0.9
390
+ type_text $'\x1b[98;5u\x1b[98;5u\x1b[98;5u'; sleep 0.5
391
+ type_text $'\x1b[98;3u'; sleep 0.6
392
+ local kitty_x
393
+ kitty_x="$(cursor_x)"
394
+ assert_eq "B2 Kitty ctrl+b×3 + alt+b 后 cursor_x=10(alpha |beta)" "$kitty_x" "10"
395
+ assert_eq "B2 Kitty 编码移动不改草稿" "$(draft)" "alpha beta"
396
+ # 同一条序列的 legacy 字节(ctrl+b = 0x02 单独发;alt+b = ESC b)必须落在同一处。
397
+ keys Escape; sleep 0.4
398
+ printf 'alpha beta' > "$(draft_file)"
399
+ keys m; sleep 0.9
400
+ keys C-b; sleep 0.25; keys C-b; sleep 0.25; keys C-b; sleep 0.25
401
+ keys M-b; sleep 0.5
402
+ assert_eq "B2 legacy 字节复跑同一条序列落点与 Kitty 相同" "$(cursor_x)" "$kitty_x"
403
+
404
+ # ④ kill ring:ctrl+w ctrl+a ctrl+k ctrl+y alt+y → ` gamma`
405
+ keys Escape; sleep 0.4
406
+ printf 'alpha beta gamma' > "$(draft_file)"
407
+ keys m; sleep 0.9
408
+ keys C-w; sleep 0.4
409
+ keys C-a; sleep 0.4
410
+ keys C-k; sleep 0.4
411
+ keys C-y; sleep 0.4
412
+ keys M-y; sleep 0.6
413
+ cap_to ring
414
+ assert_eq "B2 ring:ctrl+y 放回新的,alt+y 换成旧的 → 空格+gamma" "$(draft)" " gamma"
415
+
416
+ # ⑦ 词边界用平台的 word segmenter(标点在 pi 里是停点):alt+b/alt+d 不能把 alpha-beta 当一个词
417
+ keys Escape; sleep 0.4
418
+ printf 'alpha-beta gamma' > "$(draft_file)"
419
+ keys m; sleep 0.9
420
+ keys C-w; sleep 0.4 # 切 ` gamma`
421
+ keys M-b; sleep 0.4 # 词左移:pi 停在 beta 开头(不是 alpha-beta 的开头)
422
+ keys M-d; sleep 0.5 # 删 beta(alpha- 后停,不跨过标点)
423
+ cap_to punctuation
424
+ assert_eq "B2 标点是词停点:alpha-beta gamma → alpha-" "$(draft)" "alpha-"
425
+ assert_eq "B2 标点停点后 cursor_x=10" "$(cursor_x)" "10"
426
+
427
+ # ⑦半 word segmenter 对 CJK 真的分词(pi 用 Intl.Segmenter;「白空格规则」会把整串当一个词)
428
+ keys Escape; sleep 0.4
429
+ printf '中文中文' > "$(draft_file)"
430
+ keys m; sleep 0.9
431
+ keys M-b; sleep 0.4 # 词左移:pi 切出两个「中文」,回到后一个的开头
432
+ type_text 'X'; sleep 0.5
433
+ cap_to cjk-word
434
+ assert_eq "B2 CJK 词边界:alt+b 只回上一个词(中文X中文)" "$(draft)" "中文X中文"
435
+ assert_eq "B2 CJK 词边界后 cursor_x=9" "$(cursor_x)" "9"
436
+
437
+ # ⑧ kill ring 累积:同方向连续切合并成一条(ctrl+w ×2 → ` beta gamma`)
438
+ keys Escape; sleep 0.4
439
+ printf 'alpha beta gamma' > "$(draft_file)"
440
+ keys m; sleep 0.9
441
+ keys C-w; sleep 0.3; keys C-w; sleep 0.4
442
+ assert_eq "B2 两次 ctrl+w 后只剩 alpha" "$(draft)" "alpha"
443
+ keys C-a; sleep 0.3
444
+ keys C-k; sleep 0.4
445
+ keys C-y; sleep 0.4
446
+ keys M-y; sleep 0.6
447
+ cap_to ring-accum
448
+ assert_eq "B2 ring 累积:alt+y 换回合并的一条(空格+beta+空格+gamma)" "$(draft)" " beta gamma"
449
+
450
+ # ⑤ undo:Z 之后 Kitty ctrl+- 恢复草稿与插入点,再按一次不变
451
+ keys Escape; sleep 0.4
452
+ printf 'ad' > "$(draft_file)"
453
+ keys m; sleep 0.9
454
+ keys Left; sleep 0.4
455
+ type_text 'Z'; sleep 0.5
456
+ type_text $'\x1b[45;5u'; sleep 0.6
457
+ cap_to undo
458
+ assert_eq "B2 ctrl+- 恢复草稿 ad" "$(draft)" "ad"
459
+ assert_eq "B2 ctrl+- 同时恢复插入点 cursor_x=5" "$(cursor_x)" "5"
460
+ type_text $'\x1b[45;5u'; sleep 0.6
461
+ cap_to undo-empty
462
+ assert_eq "B2 历史空了再按 ctrl+- 不变" "$(draft)" "ad"
463
+ assert_has "$tmp/keys/undo-empty.txt" '> ad' "B2 undo 后帧仍完好"
464
+
465
+ # ⑥ 未绑定的修饰键不插字母、不收控制台(P20 新断言:ctrl+c)
466
+ keys C-c; sleep 0.6
467
+ cap_to ctrlc
468
+ assert_eq "B2 ctrl+c 不把 c 插进草稿" "$(draft)" "ad"
469
+ assert_has "$tmp/keys/ctrlc.txt" 'teamsmith pulse' "B2 ctrl+c 没有收起控制台"
470
+ local pane_pid args
471
+ pane_pid="$(tmux -L "$sock" list-panes -t "$sess:panel" -F '#{pane_pid}' | head -1)"
472
+ args="$(ps -o args= -p "$pane_pid" 2>/dev/null || true)"
473
+ if printf '%s' "$args" | grep -q 'panel.js' && ! printf '%s' "$args" | grep -q -- '--headless'; then
474
+ ok "B2 ctrl+c 之后窗口仍是渲染器(没被收起)"
475
+ else
476
+ bad "B2 ctrl+c 之后窗口进程不是渲染器:$args"
477
+ fi
478
+ }
479
+
480
+ # ---------------------------------------------------------------- P20/B3 multi-line editing
481
+ scenario_multiline() {
482
+ section "B3 · 多行编辑:C-j 插换行、Enter 仍提交、shift+enter、standby 理由单行化"
483
+ server_up multiline
484
+ start_pm 'PM draft' ''
485
+ start_panel
486
+
487
+ # ① legacy `\n`(= ctrl+j)插换行;Enter 仍提交,一条两行的消息
488
+ keys m; sleep 0.7
489
+ type_text 'ad'; sleep 0.4
490
+ type_text $'\n'; sleep 0.5
491
+ cap_to after-lf
492
+ assert_eq "B3 legacy \\n 插入换行而不是提交(草稿 ad+LF)" "$(draft)" "$(printf 'ad\n')"
493
+ assert_has "$tmp/multiline/after-lf.txt" '> ad' "B3 换行后第一行还在"
494
+ type_text 'b'; sleep 0.5
495
+ cap_to two-lines
496
+ assert_has "$tmp/multiline/two-lines.txt" ' b' "B3 第二行带续行前缀渲染(同一草稿)"
497
+ keys Enter; sleep 3
498
+ assert_eq "B3 Enter 仍提交:恰好一条条目" "$(entries | wc -l | tr -d ' ')" "1"
499
+ assert_eq "B3 条目保住两行" "$(payload_of "$(entries | head -1)")" $'ad\nb'
500
+ assert_eq "B3 换行键没有直接提交(忙框下一次都没到 PM 框)" "$(submits)" "0"
501
+
502
+ # ② Kitty ctrl+j(CSI 106;5u)与 shift+enter(CSI 13;2u)都插换行、都不提交
503
+ printf 'ad' > "$(draft_file)"
504
+ keys m; sleep 0.7
505
+ type_text $'\x1b[106;5u'; sleep 0.4
506
+ type_text 'b'; sleep 0.3
507
+ type_text $'\x1b[13;2u'; sleep 0.4
508
+ type_text 'c'; sleep 0.5
509
+ cap_to kitty
510
+ assert_eq "B3 Kitty ctrl+j + shift+enter → ad\\nb\\nc" "$(draft)" "$(printf 'ad\nb\nc')"
511
+ assert_eq "B3 Kitty 两个换行键都没有提交" "$(submits)" "0"
512
+
513
+ # ③ 粘贴三行仍是"一条草稿、一条消息"
514
+ keys Escape; sleep 0.4
515
+ printf '' > "$(draft_file)"
516
+ keys m; sleep 0.7
517
+ type_text $'p-one\np-two\np-three'; sleep 0.6
518
+ keys Enter; sleep 3
519
+ assert_eq "B3 粘贴三行 → 新增恰好一条条目" "$(entries | wc -l | tr -d ' ')" "2"
520
+ assert_eq "B3 粘贴条目保住三行" "$(payload_of "$(entries | tail -1)")" $'p-one\np-two\np-three'
521
+
522
+ # ④ standby 理由单行化:三行粘贴 → 一个空格分隔的参数;消息草稿不被动
523
+ keys Escape; sleep 0.4
524
+ printf 'half a thought' > "$(draft_file)"
525
+ local wrapper="$tmp/multiline/team-wrap.sh"
526
+ cat > "$wrapper" <<EOS
527
+ #!/usr/bin/env bash
528
+ printf 'INVOKE %s\n' "\$(printf '%q ' "\$@")" >> "$tmp/multiline/team.log"
529
+ exec "$skill/scripts/team" "\$@"
530
+ EOS
531
+ chmod +x "$wrapper"
532
+ rm -f "$tmp/multiline/team.log"
533
+ tmux -L "$sock" kill-window -t "$sess:panel" 2>/dev/null || true
534
+ tmux -L "$sock" new-window -d -t "$sess" -n panel -c "$ROOT" \
535
+ "TEAM_JS_BIN=$(printf '%q' "$js") exec '$js' '$panel' --root '$ROOT' --team-cli '$wrapper' --state-dir '$ROOT/.pi/team/state' --no-pulse --interval 1"
536
+ wait_panel
537
+ keys s; sleep 0.9
538
+ cap_to reason-open
539
+ assert_has "$tmp/multiline/reason-open.txt" '待命原因' "B3 s 打开理由输入行"
540
+ type_text $'one\ntwo\nthree'; sleep 0.6
541
+ cap_to reason-typed
542
+ assert_has "$tmp/multiline/reason-typed.txt" 'one two three' "B3 三行粘贴在理由里变成一行(空格分隔)"
543
+ assert_not_has "$tmp/multiline/reason-typed.txt" ' two' "B3 理由区没有出现第二绘制行"
544
+ keys Enter; sleep 3
545
+ cap_to reason-sent
546
+ assert_has "$tmp/multiline/reason-sent.txt" '待命 on' "B3 理由提交后显示待命 on"
547
+ if grep -qF -- '--reason one\ two\ three' "$tmp/multiline/team.log"; then
548
+ ok "B3 CLI 拿到一个参数 one two three(%q 里没有换行转义)"
549
+ else
550
+ bad "B3 CLI 没有拿到单行理由"; grep -m2 'reason' "$tmp/multiline/team.log" | head -2
551
+ fi
552
+ if grep -qF "\$'\\n'" "$tmp/multiline/team.log"; then
553
+ bad "B3 理由参数里出现了换行转义"
554
+ else
555
+ ok "B3 理由参数里没有换行转义"
556
+ fi
557
+ assert_eq "B3 理由没有覆盖消息草稿" "$(draft)" "half a thought"
558
+ ( cd "$ROOT" && bash "$skill/scripts/team" standby status ) > "$tmp/multiline/status.txt" 2>&1 || true
559
+ assert_has "$tmp/multiline/status.txt" 'one two three' "B3 待命状态里也是单行理由"
560
+ }
561
+
562
+ # ---------------------------------------------------------------- P20/B4 the clipboard paste
563
+ scenario_clipboard() {
564
+ section "B4 · 剪贴板图片:C-v → 临时文件、Wayland→X11、文本回退、无工具/挂死、理由、只读"
565
+ server_up clipboard
566
+ local fx="$tmp/clipboard"
567
+ mkdir -p "$fx/fakebin" "$fx/tmpdir"
568
+
569
+ # The probe's headless sibling first (the pure order/MIME/bounds).
570
+ local bunbin=""
571
+ bunbin="$(command -v bun 2>/dev/null || true)"
572
+ [ -n "$bunbin" ] || { [ -x "$HOME/.bun/bin/bun" ] && bunbin="$HOME/.bun/bin/bun"; }
573
+ if [ -n "$bunbin" ]; then
574
+ if ( cd "$here" && "$bunbin" build panel-clipboard-model.ts --target=node --format=esm --outfile "$tmp/panel-clipboard-model.js" ) >"$fx/model-build.log" 2>&1; then
575
+ ok "B4 模型夹具:bun 构建成功"
576
+ else
577
+ bad "B4 模型夹具:bun 构建失败"; tail -3 "$fx/model-build.log"
578
+ fi
579
+ if "$js" "$tmp/panel-clipboard-model.js" >"$fx/model.log" 2>&1; then
580
+ ok "B4 模型夹具:$(tail -1 "$fx/model.log")"
581
+ else
582
+ bad "B4 模型夹具:纯模型用例失败"; grep -A1 '^FAIL' "$fx/model.log" | head -6
583
+ fi
584
+ else
585
+ cond_skip "B4 模型夹具" "本机没有 bun"
586
+ fi
587
+
588
+ # The fake tools: each call is logged; the mode comes from the panel's environment.
589
+ cat > "$fx/fakebin/wl-paste" <<'EOWS'
590
+ #!/usr/bin/env bash
591
+ printf 'wl-paste %s\n' "$*" >> "$P20_CLIP_LOG"
592
+ case "${P20_WL_MODE:-image}" in
593
+ image)
594
+ case "$1" in
595
+ --list-types) printf 'text/plain;charset=utf-8\nimage/png\n' ;;
596
+ --type) if [ "${2:-}" = "image/png" ]; then printf 'PNGDATA8'; else exit 1; fi ;;
597
+ *) exit 1 ;;
598
+ esac ;;
599
+ text)
600
+ case "$1" in
601
+ --list-types) printf 'text/plain;charset=utf-8\n' ;;
602
+ --no-newline) printf 'from the clipboard' ;;
603
+ *) exit 1 ;;
604
+ esac ;;
605
+ hang) exec /bin/sleep 60 ;;
606
+ *) exit 1 ;;
607
+ esac
608
+ EOWS
609
+ cat > "$fx/fakebin/xclip" <<'EOXC'
610
+ #!/usr/bin/env bash
611
+ printf 'xclip %s\n' "$*" >> "$P20_CLIP_LOG"
612
+ case "${P20_X_MODE:-image}" in
613
+ image) case "$*" in *TARGETS*) printf 'image/png\n' ;; *) printf 'XCLIPDATA' ;; esac ;;
614
+ *) exit 1 ;;
615
+ esac
616
+ EOXC
617
+ chmod +x "$fx/fakebin/wl-paste" "$fx/fakebin/xclip"
618
+
619
+ clip_env() { # <wl mode> <x mode> [extra]
620
+ printf 'PATH=%s:%s TMPDIR=%s P20_CLIP_LOG=%s P20_WL_MODE=%s P20_X_MODE=%s %s' \
621
+ "$fx/fakebin" "$PATH" "$fx/tmpdir" "$fx/calls.log" "$1" "$2" "${3:-}"
622
+ }
623
+ pasted_file() { ls "$fx/tmpdir"/teamsmith-paste-* 2>/dev/null | head -1; }
624
+ paste_count() { ls "$fx/tmpdir" 2>/dev/null | grep -c 'teamsmith-paste-' || true; }
625
+ reset_clip() { rm -f "$fx/tmpdir"/teamsmith-paste-*; : > "$fx/calls.log"; }
626
+
627
+ # ① 图片 → 临时文件路径,插在插入点;Wayland 优先且 xclip 不被调用
628
+ printf 'ad' > "$(draft_file)"
629
+ reset_clip
630
+ start_pm '' ''
631
+ start_panel "$(clip_env image image)"
632
+ keys m; sleep 0.8
633
+ keys Left; sleep 0.4
634
+ keys C-v; sleep 1.5
635
+ cap_to image
636
+ local file
637
+ file="$(pasted_file)"
638
+ assert_eq "B4 TMPDIR 里恰好一个 teamsmith-paste-*.png" "$(paste_count)" "1"
639
+ if [ -n "$file" ]; then
640
+ ok "B4 文件名形状:$(basename "$file")"
641
+ else
642
+ bad "B4 没有写出 teamsmith-paste-*.png"
643
+ fi
644
+ assert_eq "B4 文件内容就是剪贴板的 8 字节" "$(cat "$file" 2>/dev/null)" "PNGDATA8"
645
+ assert_eq "B4 路径插在插入点(a<path>d)" "$(draft)" "a${file}d"
646
+ assert_has "$tmp/clipboard/image.txt" "$file" "B4 画面里也有这条路径"
647
+ assert_match "$fx/calls.log" '^wl-paste --list-types$' "B4 探测先问 wl-paste"
648
+ if grep -q '^xclip' "$fx/calls.log"; then bad "B4 Wayland 命中时不该调用 xclip"; else ok "B4 Wayland 命中时 xclip 没有被调用"; fi
649
+ type_text 'Z'; sleep 0.5
650
+ assert_eq "B4 粘贴后继续打字落到草稿(插入点之后)" "$(draft)" "a${file}Zd"
651
+
652
+ # ② Wayland 失败 → X11:仍成图,调用日志里 wl-paste 在 xclip 之前
653
+ keys Escape; sleep 0.4
654
+ printf 'ad' > "$(draft_file)"
655
+ reset_clip
656
+ start_panel "$(clip_env fail image)"
657
+ keys m; sleep 0.8
658
+ keys Left; sleep 0.4
659
+ keys C-v; sleep 1.5
660
+ cap_to x11
661
+ file="$(pasted_file)"
662
+ assert_eq "B4 X11 回退:文件内容 XCLIPDATA" "$(cat "$file" 2>/dev/null)" "XCLIPDATA"
663
+ assert_eq "B4 X11 回退:路径进草稿" "$(draft)" "a${file}d"
664
+ local wl_line x_line
665
+ wl_line="$(grep -n '^wl-paste' "$fx/calls.log" | head -1 | cut -d: -f1)"
666
+ x_line="$(grep -n '^xclip' "$fx/calls.log" | head -1 | cut -d: -f1)"
667
+ if [ -n "$wl_line" ] && [ -n "$x_line" ] && [ "$wl_line" -lt "$x_line" ]; then
668
+ ok "B4 调用顺序:wl-paste($wl_line) 先于 xclip($x_line)"
669
+ else
670
+ bad "B4 调用顺序不对(wl=$wl_line x=$x_line)"; head -4 "$fx/calls.log"
671
+ fi
672
+
673
+ # ③ 无图片 → 文本回退,且不调用 xclip
674
+ keys Escape; sleep 0.4
675
+ printf 'ad' > "$(draft_file)"
676
+ reset_clip
677
+ start_panel "$(clip_env text image)"
678
+ keys m; sleep 0.8
679
+ keys Left; sleep 0.4
680
+ keys C-v; sleep 1.5
681
+ cap_to text-fallback
682
+ assert_eq "B4 文本回退:afrom the clipboardd" "$(draft)" "afrom the clipboardd"
683
+ assert_eq "B4 文本回退不写临时文件" "$(paste_count)" "0"
684
+ if grep -q '^xclip' "$fx/calls.log"; then bad "B4 文本回退不该调用 xclip"; else ok "B4 文本回退不调用 xclip"; fi
685
+
686
+ # ④ 两个工具都不给东西:什么都不变;挂死的工具在界内被放弃
687
+ keys Escape; sleep 0.4
688
+ printf 'half a thought' > "$(draft_file)"
689
+ reset_clip
690
+ start_panel "$(clip_env fail fail)"
691
+ keys m; sleep 0.8
692
+ keys C-v; sleep 1.5
693
+ cap_to no-tool
694
+ assert_eq "B4 无工具:草稿不变" "$(draft)" "half a thought"
695
+ assert_eq "B4 无工具:没有文件" "$(paste_count)" "0"
696
+ assert_has "$tmp/clipboard/no-tool.txt" '> half a thought' "B4 无工具:帧照常、没有错误行"
697
+ type_text 'Z'; sleep 0.5
698
+ assert_eq "B4 无工具后仍能打字" "$(draft)" "half a thoughtZ"
699
+
700
+ keys Escape; sleep 0.4
701
+ printf 'half a thought' > "$(draft_file)"
702
+ reset_clip
703
+ start_panel "$(clip_env hang fail)"
704
+ keys m; sleep 0.8
705
+ keys C-v; sleep 5
706
+ cap_to hang
707
+ assert_eq "B4 挂死工具 5s 内:草稿不变" "$(draft)" "half a thought"
708
+ assert_eq "B4 挂死工具:没有文件" "$(paste_count)" "0"
709
+ type_text 'Z'; sleep 0.5
710
+ assert_eq "B4 挂死工具期间仍能打字" "$(draft)" "half a thoughtZ"
711
+ keys Escape; sleep 0.5
712
+ assert_eq "B4 Esc 仍关掉输入行并保留草稿" "$(draft)" "half a thoughtZ"
713
+
714
+ # ⑤ 理由模式:路径进理由行,消息草稿不动
715
+ printf 'half a thought' > "$(draft_file)"
716
+ reset_clip
717
+ start_panel "$(clip_env image image)"
718
+ keys s; sleep 0.9
719
+ type_text 'why'; sleep 0.4
720
+ keys C-v; sleep 1.5
721
+ cap_to reason
722
+ file="$(pasted_file)"
723
+ assert_has "$tmp/clipboard/reason.txt" "$file" "B4 理由行里有图片路径"
724
+ assert_eq "B4 理由模式仍不写 state/draft.md" "$(draft)" "half a thought"
725
+
726
+ # ⑥ 只读扫描:C-v 不调用任何 team 动作(数据读者不算动作)
727
+ cat > "$fx/teamwrap.sh" <<EOS
728
+ #!/usr/bin/env bash
729
+ for a in "\$@"; do [ "\$a" = "__panel-data" ] && exit 0; done
730
+ printf '%s\n' "\$*" >> "$fx/team.log"
731
+ exec "$skill/scripts/team" "\$@"
732
+ EOS
733
+ chmod +x "$fx/teamwrap.sh"
734
+ keys Escape; sleep 0.4
735
+ printf 'ad' > "$(draft_file)"
736
+ reset_clip
737
+ : > "$fx/team.log"
738
+ tmux -L "$sock" kill-window -t "$sess:panel" 2>/dev/null || true
739
+ tmux -L "$sock" new-window -d -t "$sess" -n panel -c "$ROOT" \
740
+ "TEAM_JS_BIN=$(printf '%q' "$js") $(clip_env image image) exec '$js' '$panel' --root '$ROOT' --team-cli '$fx/teamwrap.sh' --state-dir '$ROOT/.pi/team/state' --no-pulse --interval 1"
741
+ wait_panel
742
+ keys m; sleep 0.8
743
+ keys Left; sleep 0.4
744
+ : > "$fx/team.log"
745
+ keys C-v; sleep 1.5
746
+ assert_eq "B4 只读:C-v 没有触发任何 team 动作" "$(wc -l < "$fx/team.log" 2>/dev/null | tr -d ' ')" "0"
747
+ assert_eq "B4 只读:临时文件仍写在 TMPDIR 里" "$(paste_count)" "1"
748
+
749
+ # ⑦ 不按 C-v 就绝不起剪贴板工具:5s 空闲(写信关着、开着各一段)调用日志为空
750
+ reset_clip
751
+ : > "$fx/calls.log"
752
+ start_panel "$(clip_env image image)"
753
+ sleep 5
754
+ assert_eq "B4 空闲 5s(未写信号)没有调用剪贴板工具" "$(wc -l < "$fx/calls.log" | tr -d ' ')" "0"
755
+ keys m; sleep 5
756
+ assert_eq "B4 空闲 5s(写信中)没有调用剪贴板工具" "$(wc -l < "$fx/calls.log" | tr -d ' ')" "0"
757
+ }
758
+
759
+ # ---------------------------------------------------------------- 2.2 draft persistence / \r
760
+ scenario_draft() {
761
+ section "2.2 · Esc 保留草稿、重开带出、\\r 归一"
762
+ server_up draft
763
+ start_pm '' ''
764
+ start_panel
765
+ keys m
766
+ sleep 0.6
767
+ type_text 'half a thought'
768
+ sleep 0.5
769
+ keys Escape
770
+ sleep 0.6
771
+ assert_eq "2.2 Esc 后 state/draft.md 保留草稿" "$(draft)" "half a thought"
772
+ keys q
773
+ sleep 1.2
774
+ start_panel
775
+ keys m
776
+ sleep 0.8
777
+ cap_to restored
778
+ assert_has "$tmp/draft/restored.txt" "> half a thought" "2.2 重启后 m 带出草稿"
779
+ # \r 归一:用带 CR 的粘贴进草稿(bracketed paste 里的 CR 是换行,不是提交)
780
+ keys Escape
781
+ sleep 0.4
782
+ keys q
783
+ sleep 1.2
784
+ rm -f "$(draft_file)"
785
+ start_panel
786
+ keys m
787
+ sleep 0.6
788
+ type_text $'\x1b[200~cr-one\rcr-two\rcr-three\x1b[201~'
789
+ sleep 0.8
790
+ cap_to cr
791
+ assert_eq "2.2 CR 归一为换行(三行草稿)" "$(draft)" $'cr-one\ncr-two\ncr-three'
792
+ if printf '%s' "$(draft)" | grep -q $'\r'; then
793
+ bad "2.2 草稿里不该留下 CR"
794
+ else
795
+ ok "2.2 草稿里没有 CR 字节"
796
+ fi
797
+ assert_has "$tmp/draft/cr.txt" " cr-three" "2.2 三行都渲染在输入区"
798
+ }
799
+
800
+ # ---------------------------------------------------------------- 2.3 the editor relay
801
+ scenario_editor() {
802
+ section "B3 · C-o 编辑器接力(C-e 迁到行尾;挂起期间渲染回调门控)"
803
+ server_up editor
804
+
805
+ # ── 迁移(spec scenario):草稿 ad、插入点在两字之间;C-e 到行尾,绝不启动编辑器。
806
+ cat > "$tmp/editor.sh" <<'EOS'
807
+ #!/usr/bin/env bash
808
+ printf 'EDITOR-ACTIVE\n'
809
+ printf 'ran\n' >> "${TEAM_B2_EDITOR_MARKER:?}"
810
+ printf '\nsecond line\n' >> "$1"
811
+ sleep "${TEAM_B2_EDITOR_HOLD:-2}"
812
+ printf 'EDITOR-DONE\n'
813
+ EOS
814
+ chmod +x "$tmp/editor.sh"
815
+ rm -f "$tmp/editor/marker"
816
+ printf 'ad' > "$(draft_file)"
817
+ start_pm 'PM draft' ''
818
+ start_panel "EDITOR=$tmp/editor.sh TEAM_B2_EDITOR_HOLD=4 TEAM_B2_EDITOR_MARKER=$tmp/editor/marker"
819
+ keys m
820
+ sleep 0.7
821
+ keys Left
822
+ sleep 0.4
823
+ assert_eq "B3 夹具:插入点在 ad 中间(cursor_x=5)" "$(cursor_x)" "5"
824
+ keys C-e
825
+ sleep 0.7
826
+ assert_eq "B3 C-e 到行尾(cursor_x=6),不是编辑器" "$(cursor_x)" "6"
827
+ assert_eq "B3 C-e 后草稿仍是 ad" "$(draft)" "ad"
828
+ if [ -f "$tmp/editor/marker" ]; then
829
+ bad "B3 C-e 竟然启动了编辑器(marker 存在)"
830
+ else
831
+ ok "B3 C-e 没有启动编辑器(marker 不存在)"
832
+ fi
833
+ cap_to c-e-line-end
834
+ assert_not_has "$tmp/editor/c-e-line-end.txt" 'EDITOR-ACTIVE' "B3 C-e 没有把终端交给编辑器"
835
+ keys Escape
836
+ sleep 0.4
837
+
838
+ # The handoff's raw bytes (design §6): `tmux pipe-pane` records everything the pane writes.
839
+ rm -f "$tmp/editor/pane-bytes.log"
840
+ tmux -L "$sock" pipe-pane -t "$sess:panel" -o "cat >> '$tmp/editor/pane-bytes.log'" 2>/dev/null || true
841
+
842
+ # ── 接力本体:C-o 跑一次脚本,挂起期间不重绘,回来无损。
843
+ printf '' > "$(draft_file)"
844
+ keys m
845
+ sleep 0.6
846
+ type_text 'raw1'
847
+ sleep 0.5
848
+ keys C-o
849
+ local saw_editor=1 i
850
+ for i in $(seq 1 25); do
851
+ if { cap || true; } | grep -q 'EDITOR-ACTIVE'; then saw_editor=0; break; fi
852
+ sleep 0.2
853
+ done
854
+ cap_to during-editor
855
+ assert_eq "B3 C-o 把终端交给了编辑器" "$saw_editor" "0"
856
+ local c1 c2
857
+ c1="$(cap)"
858
+ sleep 1.3
859
+ c2="$(cap)"
860
+ if [ -n "$c1" ] && [ "$c2" = "$c1" ]; then
861
+ ok "B3 挂起期间屏幕静止(渲染回调门控生效,没有重绘)"
862
+ else
863
+ bad "B3 挂起期间仍在重绘(挂起门控没生效)"
864
+ fi
865
+ assert_not_has "$tmp/editor/during-editor.txt" 'EDITOR-DONE' "B3 编辑器还在跑"
866
+ for i in $(seq 1 25); do
867
+ { cap || true; } | grep -q 'EDITOR-DONE' && break
868
+ sleep 0.4
869
+ done
870
+ sleep 1
871
+ cap_to after-editor
872
+ assert_has "$tmp/editor/after-editor.txt" 'teamsmith pulse' "B3 接力回来后面板帧完好"
873
+ assert_has "$tmp/editor/after-editor.txt" '> raw1' "B3 输入行保留 raw1"
874
+ assert_has "$tmp/editor/after-editor.txt" 'second line' "B3 编辑器加的第二行无损带回"
875
+ assert_eq "B3 C-o 只跑了恰好一次编辑器(marker 一行)" "$(grep -c '^ran$' "$tmp/editor/marker" 2>/dev/null || printf 0)" "1"
876
+ # Kitty 协议的关/开字节(design §6):handoff 前 `CSI < u`,编辑器退出后 `CSI > 1 u`。
877
+ if [ -s "$tmp/editor/pane-bytes.log" ] \
878
+ && LC_ALL=C grep -qF $'\x1b[<u' "$tmp/editor/pane-bytes.log" \
879
+ && LC_ALL=C grep -qF $'\x1b[>1u' "$tmp/editor/pane-bytes.log"; then
880
+ ok "B3 handoff 前写入 CSI < u、回来后 CSI > 1 u(pane 原始字节)"
881
+ else
882
+ bad "B3 Kitty 关/开字节缺失(pane-bytes.log $(wc -c < "$tmp/editor/pane-bytes.log" 2>/dev/null | tr -d ' ') 字节)"
883
+ fi
884
+ keys Enter
885
+ sleep 3
886
+ cap_to after-send
887
+ assert_has "$tmp/editor/after-send.txt" 'queued' "B3 忙框回执 queued"
888
+ local n e payload
889
+ n="$(entries | wc -l | tr -d ' ')"
890
+ assert_eq "B3 恰好一条队列条目" "$n" "1"
891
+ e="$(entries | head -1)"
892
+ payload="$(payload_of "$e")"
893
+ assert_eq "B3 条目保住两行(无损)" "$payload" $'raw1\nsecond line'
894
+ assert_eq "B3 发送成功后草稿文件清空" "$(wc -c < "$(draft_file)" | tr -d ' ')" "0"
895
+
896
+ # 真 vi(E6 drive2 T5 的形状):在 pane 里发 G/o/文本/Esc/:wq,接力回来仍然无损。
897
+ # 夹具用 `vi -n`(无 swap 文件),只在 vi 存在时跑。
898
+ if command -v vi >/dev/null 2>&1; then
899
+ start_panel "EDITOR='vi -n'"
900
+ keys m
901
+ sleep 0.6
902
+ type_text 'vi draft'
903
+ sleep 0.4
904
+ keys C-o
905
+ sleep 1.6
906
+ cap_to vi-open
907
+ assert_has "$tmp/editor/vi-open.txt" 'vi draft' "B3 真 vi:草稿真的进了编辑器"
908
+ keys G
909
+ sleep 0.3
910
+ keys o
911
+ sleep 0.3
912
+ type_text 'vi second line'
913
+ sleep 0.3
914
+ keys Escape
915
+ sleep 0.3
916
+ type_text ':wq'
917
+ sleep 0.2
918
+ keys Enter
919
+ sleep 2.5
920
+ cap_to vi-back
921
+ assert_has "$tmp/editor/vi-back.txt" 'teamsmith pulse' "B3 真 vi:退出后面板帧正常"
922
+ assert_has "$tmp/editor/vi-back.txt" '> vi draft' "B3 真 vi:第一行无损"
923
+ assert_has "$tmp/editor/vi-back.txt" 'vi second line' "B3 真 vi:新增的第二行无损带回"
924
+ keys Enter
925
+ sleep 3
926
+ cap_to vi-sent
927
+ assert_has "$tmp/editor/vi-sent.txt" 'queued' "B3 真 vi:忙框回执 queued"
928
+ local newest
929
+ newest="$(entries | tail -1)"
930
+ assert_eq "B3 真 vi:条目保住两行" "$(payload_of "$newest")" $'vi draft\nvi second line'
931
+ else
932
+ cond_skip "B3 真 vi 接力" "本机没有 vi"
933
+ fi
934
+ }
935
+
936
+ # ---------------------------------------------------------------- 2.4 the three receipts
937
+ scenario_receipt() {
938
+ section "2.4 · Enter 走守卫发送,回执三态"
939
+ server_up receipt
940
+ # ① busy box → queued;PM 草稿逐字节不变;渲染器一个键都没打
941
+ start_pm '半句草稿 half a sentence' ''
942
+ start_panel
943
+ local before after
944
+ before="$(pm_cap)"
945
+ keys m
946
+ sleep 0.6
947
+ type_text 'hello'
948
+ sleep 0.4
949
+ keys Enter
950
+ sleep 3
951
+ cap_to busy
952
+ assert_has "$tmp/receipt/busy.txt" 'queued' "2.4 忙框回执 queued"
953
+ assert_eq "2.4 忙框:恰好一条队列条目" "$(entries | wc -l | tr -d ' ')" "1"
954
+ assert_eq "2.4 忙框:条目 payload 是 hello" "$(payload_of "$(entries | head -1)")" "hello"
955
+ after="$(pm_cap)"
956
+ if [ "$before" = "$after" ]; then ok "2.4 忙框:PM 输入框逐字节不变(渲染器没打字)"; else bad "2.4 忙框:PM 输入框变了"; fi
957
+ assert_eq "2.4 忙框:没有发生提交" "$(submits)" "0"
958
+
959
+ # ② empty box → delivered
960
+ tmux -L "$sock" kill-window -t "$sess:pm" 2>/dev/null || true
961
+ rm -rf "$ROOT/.pi/team/state/outbox"
962
+ start_pm '' ''
963
+ keys m
964
+ sleep 0.6
965
+ type_text 'hello2'
966
+ sleep 0.4
967
+ keys Enter
968
+ sleep 3
969
+ cap_to delivered
970
+ assert_has "$tmp/receipt/delivered.txt" 'delivered' "2.4 空框回执 delivered"
971
+ assert_eq "2.4 空框:恰好一次提交" "$(submits)" "1"
972
+ assert_eq "2.4 空框:提交内容是 hello2" "$(last_submit)" "hello2"
973
+ assert_eq "2.4 空框:没有留下队列条目" "$(entries | wc -l | tr -d ' ')" "0"
974
+
975
+ # ③ eaten Enter → held(payload 进过框一次:进 held/,绝不重贴)
976
+ tmux -L "$sock" kill-window -t "$sess:pm" 2>/dev/null || true
977
+ rm -rf "$ROOT/.pi/team/state/outbox"
978
+ start_pm '' 'FAKE_TUI_EAT_ENTER=1 FAKE_TUI_STATIC_FOOTER=1'
979
+ keys m
980
+ sleep 0.6
981
+ type_text 'held candidate'
982
+ sleep 0.4
983
+ keys Enter
984
+ sleep 9
985
+ cap_to held
986
+ assert_has "$tmp/receipt/held.txt" 'held' "2.4 未确认投递回执 held"
987
+ assert_eq "2.4 held:条目进了 outbox/held/" "$(held_entries | wc -l | tr -d ' ')" "1"
988
+ assert_has "$ROOT/.pi/team/state/outbox/HOLDING.log" 'reason=unconfirmed' "2.4 held:HOLDING.log 记下 unconfirmed"
989
+ assert_eq "2.4 held:活动队列为空" "$(entries | wc -l | tr -d ' ')" "0"
990
+ }
991
+
992
+ # ---------------------------------------------------------------- 2.5 compose pause
993
+ scenario_pause() {
994
+ section "2.5 · 写信期间输入区暂停刷新、其余区照刷(慢读者)"
995
+ server_up pause
996
+ start_pm 'PM draft' ''
997
+ local stub="$here/panel-b2-slow-stub.sh"
998
+ tmux -L "$sock" kill-window -t "$sess:panel" 2>/dev/null || true
999
+ tmux -L "$sock" new-window -d -t "$sess" -n panel -c "$ROOT" \
1000
+ "TEAM_JS_BIN=$(printf '%q' "$js") TEAM_B2_REAL_CLI=$(printf '%q' "$skill/scripts/team") TEAM_B2_SLOW_SLEEP=4 exec '$js' '$panel' --root '$ROOT' --team-cli '$stub' --state-dir '$ROOT/.pi/team/state' --no-pulse --refresh 1"
1001
+ wait_panel || return 1
1002
+ keys m
1003
+ sleep 0.6
1004
+ type_text 'before'
1005
+ sleep 0.6
1006
+ local ts1 ts2
1007
+ ts1="$(stamp)"
1008
+ sleep 6
1009
+ ts2="$(stamp)"
1010
+ if [ -n "$ts1" ] && [ "$ts2" != "$ts1" ]; then
1011
+ ok "2.5 写信期间别的区块刷新了(时间戳 $ts1 → $ts2)"
1012
+ else
1013
+ bad "2.5 写信期间没有刷新($ts1 → $ts2)"
1014
+ fi
1015
+ type_text 'after'
1016
+ sleep 0.6
1017
+ cap_to pause
1018
+ assert_has "$tmp/pause/pause.txt" '> beforeafter' "2.5 草稿跨刷新存活(beforeafter)"
1019
+ assert_eq "2.5 草稿文件也是 beforeafter" "$(draft)" "beforeafter"
1020
+ keys Enter
1021
+ sleep 3
1022
+ assert_eq "2.5 跨刷新后的草稿仍作为一条消息入队" "$(payload_of "$(entries | head -1)")" "beforeafter"
1023
+ }
1024
+
1025
+ # ---------------------------------------------------------------- 2.6 paste is one message
1026
+ scenario_paste() {
1027
+ section "2.6 · 粘贴(plain / bracketed)三行 = 一条消息"
1028
+ server_up paste
1029
+ start_pm 'PM draft' ''
1030
+ start_panel
1031
+ # ① plain paste:一行 write 里带 LF
1032
+ keys m
1033
+ sleep 0.6
1034
+ type_text $'line one\nline two\nline three'
1035
+ sleep 0.6
1036
+ cap_to plain
1037
+ assert_has "$tmp/paste/plain.txt" ' line three' "2.6 plain 粘贴三行都在草稿里"
1038
+ keys Enter
1039
+ sleep 3
1040
+ assert_eq "2.6 plain:恰好一条条目" "$(entries | wc -l | tr -d ' ')" "1"
1041
+ assert_eq "2.6 plain:条目保住三行" "$(payload_of "$(entries | head -1)")" $'line one\nline two\nline three'
1042
+ # ② bracketed paste:DECSET 标记包裹,里面是 CR
1043
+ keys m
1044
+ sleep 0.6
1045
+ type_text $'\x1b[200~b-one\rb-two\rb-three\x1b[201~'
1046
+ sleep 0.6
1047
+ cap_to bracket
1048
+ assert_has "$tmp/paste/bracket.txt" ' b-three' "2.6 bracketed 粘贴三行都在草稿里"
1049
+ keys Enter
1050
+ sleep 3
1051
+ assert_eq "2.6 bracketed:两条条目(每次粘贴一条)" "$(entries | wc -l | tr -d ' ')" "2"
1052
+ assert_eq "2.6 bracketed:条目保住三行" "$(payload_of "$(entries | tail -1)")" $'b-one\nb-two\nb-three'
1053
+ assert_eq "2.6 两次粘贴都没有产生提交(忙框守卫)" "$(submits)" "0"
1054
+ }
1055
+
1056
+ # ---------------------------------------------------------------- 3.1 the action layer
1057
+ scenario_actions() {
1058
+ section "3.1 · f 冲刷走 CLI、s 待命开关(开时要一行理由)"
1059
+ server_up actions
1060
+ start_pm '' ''
1061
+ start_panel
1062
+ # 先留一份消息草稿,证明「理由」不会覆盖它
1063
+ keys m
1064
+ sleep 0.6
1065
+ type_text 'draft kept'
1066
+ sleep 0.4
1067
+ keys Escape
1068
+ sleep 0.5
1069
+ # 队列里放两条(目标窗口就是 fixture 的 PM,空框 → flush 可投)
1070
+ ( cd "$ROOT" && bash "$skill/scripts/team" outbox enqueue --kind say --target "$sess:pm" --from pm --payload 'q one' >/dev/null 2>&1
1071
+ bash "$skill/scripts/team" outbox enqueue --kind say --target "$sess:pm" --from pm --payload 'q two' >/dev/null 2>&1 )
1072
+ assert_eq "3.1 夹具:队列里两条" "$(entries | wc -l | tr -d ' ')" "2"
1073
+ keys f
1074
+ sleep 5
1075
+ cap_to flush
1076
+ assert_has "$tmp/actions/flush.txt" 'outbox' "3.1 f 的回执带 flush 自己的日志行"
1077
+ assert_eq "3.1 f 之后队列空了(flush 真跑了)" "$(entries | wc -l | tr -d ' ')" "0"
1078
+ assert_eq "3.1 flush 投了两条" "$(submits)" "2"
1079
+ # s:关 → 开(要理由)
1080
+ keys s
1081
+ sleep 0.8
1082
+ cap_to reason-input
1083
+ assert_has "$tmp/actions/reason-input.txt" '>' "3.1 s 打开理由输入行"
1084
+ type_text 'lunch'
1085
+ sleep 0.4
1086
+ keys Enter
1087
+ sleep 3
1088
+ cap_to standby-on
1089
+ assert_has "$tmp/actions/standby-on.txt" '待命 on' "3.1 s 之后回执显示待命 on"
1090
+ ( cd "$ROOT" && bash "$skill/scripts/team" standby status ) > "$tmp/actions/status-on.txt" 2>&1 || true
1091
+ assert_has "$tmp/actions/status-on.txt" 'standby: on' "3.1 CLI 报告 standby on"
1092
+ assert_has "$tmp/actions/status-on.txt" 'lunch' "3.1 CLI 记下理由 lunch"
1093
+ assert_eq "3.1 理由没有覆盖消息草稿" "$(draft)" "draft kept"
1094
+ keys s
1095
+ sleep 3
1096
+ cap_to standby-off
1097
+ assert_has "$tmp/actions/standby-off.txt" '待命 off' "3.1 再按 s 回执显示待命 off"
1098
+ ( cd "$ROOT" && bash "$skill/scripts/team" standby status ) > "$tmp/actions/status-off.txt" 2>&1 || true
1099
+ assert_has "$tmp/actions/status-off.txt" 'standby: off' "3.1 CLI 报告 standby off"
1100
+ }
1101
+
1102
+ # ---------------------------------------------------------------- 3.2 the write sweep
1103
+ scenario_readonly() {
1104
+ section "3.2 · 只读扫描:只有面板自己的文件会变"
1105
+ server_up readonly
1106
+ start_pm '' ''
1107
+ start_panel
1108
+ local before after
1109
+ before="$(snapshot)"
1110
+ printf '%s\n' "$before" > "$tmp/readonly/before.txt"
1111
+ keys r
1112
+ keys Up
1113
+ keys Down
1114
+ keys Tab
1115
+ type_text '1'
1116
+ type_text '2'
1117
+ type_text '3'
1118
+ for k in x z '?' '!' '~' 'w' '%' '&'; do type_text "$k"; done
1119
+ sleep 0.5
1120
+ keys m
1121
+ sleep 0.5
1122
+ type_text 'sweep draft'
1123
+ sleep 0.4
1124
+ keys Escape
1125
+ sleep 0.6
1126
+ keys q
1127
+ sleep 1
1128
+ after="$(snapshot)"
1129
+ printf '%s\n' "$after" > "$tmp/readonly/after.txt"
1130
+ local changed
1131
+ changed="$(diff <(printf '%s\n' "$before") <(printf '%s\n' "$after") | sed -n 's/^[<>] //p' | awk '{print $1}' | sort -u | tr '\n' ' ')"
1132
+ printf ' 变化过的路径:%s\n' "${changed:-(无)}" >> "$tmp/readonly/after.txt"
1133
+ local off=""
1134
+ local p
1135
+ for p in $changed; do
1136
+ case "$p" in
1137
+ .pi/team/state/draft.md|.pi/team/state/panel.conf|.pi/team/state/panel-page) ;;
1138
+ *) off="$off $p" ;;
1139
+ esac
1140
+ done
1141
+ if [ -z "$off" ]; then
1142
+ ok "3.2 只读扫描:只变了面板自己的文件(${changed:-无})"
1143
+ else
1144
+ bad "3.2 只读扫描:面板动了别人的文件:$off"
1145
+ fi
1146
+ assert_has "$(draft_file)" 'sweep draft' "3.2 草稿(允许写的文件之一)确实写了"
1147
+ assert_eq "3.2 文档/收件箱零改动" "$(printf '%s\n' "$after" | grep -c '^docs/team')" "$(printf '%s\n' "$before" | grep -c '^docs/team')"
1148
+ }
1149
+
1150
+ # ---------------------------------------------------------------- runner
1151
+ if [ "${BASH_SOURCE[0]}" != "$0" ]; then
1152
+ return 0 2>/dev/null || exit 0
1153
+ fi
1154
+ ALL="cursor keys multiline clipboard cjk draft editor receipt pause paste actions readonly"
1155
+ selected="${*:-$ALL}"
1156
+ mkdir -p "$tmp"
1157
+ rc=0
1158
+ for name in $selected; do
1159
+ mkdir -p "$tmp/$name"
1160
+ case "$name" in
1161
+ cursor) scenario_cursor ;;
1162
+ keys) scenario_keys ;;
1163
+ multiline) scenario_multiline ;;
1164
+ clipboard) scenario_clipboard ;;
1165
+ cjk) scenario_cjk ;;
1166
+ draft) scenario_draft ;;
1167
+ editor) scenario_editor ;;
1168
+ receipt) scenario_receipt ;;
1169
+ pause) scenario_pause ;;
1170
+ paste) scenario_paste ;;
1171
+ actions) scenario_actions ;;
1172
+ readonly) scenario_readonly ;;
1173
+ *) printf 'panel-b2: unknown scenario %s(known: %s)\n' "$name" "$ALL" >&2; rs=3 ;;
1174
+ esac || rc=$?
1175
+ done
1176
+
1177
+ printf '\n\033[1m== 结果 ==\033[0m ✓ %d ✗ %d\n' "$PASS" "$FAIL"
1178
+ if [ "$FAIL" -ne 0 ]; then
1179
+ printf '\033[31mpanel-b2 有失败项\033[0m\n'
1180
+ exit 1
1181
+ fi
1182
+ printf '\033[32mpanel-b2 全绿\033[0m\n'
1183
+ exit "$rc"