teamsmith 0.1.2 → 0.2.0

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 (97) hide show
  1. package/README.md +13 -7
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +39 -0
  4. package/skills/teamsmith/SKILL.md +18 -7
  5. package/skills/teamsmith/references/agent-adapters.md +7 -7
  6. package/skills/teamsmith/references/config.md +29 -15
  7. package/skills/teamsmith/references/migration.md +38 -2
  8. package/skills/teamsmith/references/protocol.md +81 -13
  9. package/skills/teamsmith/references/workflows.md +31 -19
  10. package/skills/teamsmith/scripts/lib/cmd-agents.sh +210 -70
  11. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +70 -9
  12. package/skills/teamsmith/scripts/lib/cmd-config.sh +222 -70
  13. package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
  14. package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
  15. package/skills/teamsmith/scripts/lib/cmd-project.sh +134 -17
  16. package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
  17. package/skills/teamsmith/scripts/lib/cmd-review.sh +13 -10
  18. package/skills/teamsmith/scripts/lib/cmd-status.sh +42 -13
  19. package/skills/teamsmith/scripts/lib/cmd-watch.sh +75 -13
  20. package/skills/teamsmith/scripts/lib/common.sh +797 -71
  21. package/skills/teamsmith/scripts/monitor.mjs +34 -3
  22. package/skills/teamsmith/scripts/panel/README.md +22 -11
  23. package/skills/teamsmith/scripts/panel/panel.js +217 -215
  24. package/skills/teamsmith/scripts/panel/src/App.tsx +421 -164
  25. package/skills/teamsmith/scripts/panel/src/data.ts +84 -4
  26. package/skills/teamsmith/scripts/panel/src/layout.ts +502 -91
  27. package/skills/teamsmith/scripts/panel/src/main.tsx +97 -12
  28. package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
  29. package/skills/teamsmith/scripts/panel/src/strings/en.ts +56 -21
  30. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +56 -21
  31. package/skills/teamsmith/scripts/panel/src/types.ts +178 -16
  32. package/skills/teamsmith/scripts/replies.mjs +893 -0
  33. package/skills/teamsmith/scripts/team +1 -0
  34. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +15 -2
  35. package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
  36. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
  37. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
  38. package/skills/teamsmith/templates/config.sh.tmpl +10 -5
  39. package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
  40. package/skills/teamsmith/templates/pm-prompt.md.tmpl +20 -1
  41. package/skills/teamsmith/templates/report.md.tmpl +12 -0
  42. package/skills/teamsmith/templates/task.md.tmpl +4 -0
  43. package/skills/teamsmith/tests/config-cli.sh +162 -288
  44. package/skills/teamsmith/tests/death-cause.sh +5 -2
  45. package/skills/teamsmith/tests/install-shape.sh +4 -2
  46. package/skills/teamsmith/tests/key-replies-pty.sh +375 -0
  47. package/skills/teamsmith/tests/key-replies-ui.sh +332 -0
  48. package/skills/teamsmith/tests/key-replies.sh +1075 -0
  49. package/skills/teamsmith/tests/ledger-ban.sh +4 -4
  50. package/skills/teamsmith/tests/ledger-claim.sh +247 -0
  51. package/skills/teamsmith/tests/lib/model-policy.sh +26 -0
  52. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
  53. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
  54. package/skills/teamsmith/tests/lib/model-routing-flips.py +136 -0
  55. package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
  56. package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
  57. package/skills/teamsmith/tests/lib/reply-fixture.sh +372 -0
  58. package/skills/teamsmith/tests/lib/tmux-iso.sh +8 -0
  59. package/skills/teamsmith/tests/panel-b2.sh +1 -1
  60. package/skills/teamsmith/tests/panel-b3-stub.sh +27 -0
  61. package/skills/teamsmith/tests/panel-b3.sh +14 -10
  62. package/skills/teamsmith/tests/panel-choices.sh +74 -61
  63. package/skills/teamsmith/tests/panel-cpu.sh +1 -1
  64. package/skills/teamsmith/tests/panel-p21.sh +311 -190
  65. package/skills/teamsmith/tests/perf.sh +1 -1
  66. package/skills/teamsmith/tests/pm-box-real.sh +1 -1
  67. package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
  68. package/skills/teamsmith/tests/routes.sh +43 -22
  69. package/skills/teamsmith/tests/section-budgets.tsv +8 -4
  70. package/skills/teamsmith/tests/section-paths.tsv +26 -16
  71. package/skills/teamsmith/tests/section-select.sh +82 -6
  72. package/skills/teamsmith/tests/smoke.sh +782 -180
  73. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
  74. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
  75. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
  76. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
  77. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
  78. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
  79. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
  80. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
  81. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
  82. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
  83. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
  84. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
  85. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
  86. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
  87. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
  88. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
  89. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
  90. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
  91. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
  92. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
  93. package/skills/teamsmith/tests/task-header-model.sh +2 -1
  94. package/skills/teamsmith/tests/task-model-routing.sh +1014 -0
  95. package/skills/teamsmith-init/SKILL.md +38 -38
  96. package/skills/teamsmith-init/references/bootstrap.md +6 -4
  97. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
@@ -142,6 +142,7 @@ team_cmd_up() {
142
142
  [ "$pm_fresh" = "1" ] && export TEAM_PM_FRESH_LAUNCH=1
143
143
 
144
144
  if [ "$show_prompt" = "1" ]; then
145
+ team_pm_identity_guard || return 1
145
146
  team_pm_prompt
146
147
  # P36(A):--print 是「看清这一次启动」的地方 —— 会话判定(fresh:/continued:/lost:)与渲染出的
147
148
  # 完整命令都要看得见、能断言(有没有 -c 一眼可见)。不写任何状态、不动 tmux。
@@ -156,6 +157,8 @@ team_cmd_up() {
156
157
  team_assert_own_session "team up" || team_die "team up 拒绝在「不属于本项目的 session」上动手(见上)"
157
158
  team_hdr "teamsmith up · $TEAM_PROJECT(只负责 PM)"
158
159
 
160
+ # Running/starting PM is never restarted by a policy edit. Otherwise guard BEFORE windows.
161
+ case "$(team_pm_state)" in running:*|starting:*) ;; *) team_pm_identity_guard || return 1 ;; esac
159
162
  # 1) tmux 场地:人跑 up 就是明确要求“把工地建起来”,所以这里允许建 session/窗口
160
163
  if ! team_tmux_has_session "$TEAM_SESSION"; then
161
164
  team_warn "tmux session '$TEAM_SESSION' 不存在:重建"
@@ -179,7 +182,7 @@ team_cmd_up() {
179
182
  idle:*) team_warn "PM 没在跑(空提示符):启动 $(team_pm_cli_name)"
180
183
  team_pm_same_dir_warn
181
184
  if team_pm_start; then
182
- team_ok "PM 已启动(cli=$(team_pm_cli_name),proof=$(team_pm_proof || echo '?'),model=${TEAM_PM_MODEL:-$TEAM_DEFAULT_MODEL})"
185
+ team_ok "PM 已启动(cli=$(team_pm_cli_name),proof=$(team_pm_proof || echo '?'),$(team_pm_identity_claim))"
183
186
  else
184
187
  pm_fail=1
185
188
  team_err "PM 启动失败:请手动到 $TEAM_SESSION:$TEAM_PM_WINDOW 里跑 $(team_pm_bin_path);诊断见 $(team_pm_launch_failed_log)"
@@ -191,7 +194,7 @@ team_cmd_up() {
191
194
  team_warn "PM 窗口里有非 PM 进程(${pm_state#unknown:},cwd=$_ucwd):不算存活"
192
195
  team_pm_same_dir_warn
193
196
  if team_pm_start; then
194
- team_ok "PM 已启动(替换了非 PM 进程;cli=$(team_pm_cli_name),proof=$(team_pm_proof || echo '?'),model=${TEAM_PM_MODEL:-$TEAM_DEFAULT_MODEL})"
197
+ team_ok "PM 已启动(替换了非 PM 进程;cli=$(team_pm_cli_name),proof=$(team_pm_proof || echo '?'),$(team_pm_identity_claim))"
195
198
  else
196
199
  pm_fail=1
197
200
  team_err "PM 启动失败:请手动到 $TEAM_SESSION:$TEAM_PM_WINDOW 里跑 $(team_pm_bin_path);诊断见 $(team_pm_launch_failed_log)"
@@ -237,7 +240,7 @@ team_cmd_up() {
237
240
  # ---------------------------------------------------------------- team resume(PM 的工具)
238
241
  # 注意:watchdog 不调用这个。agent 的启停由 PM 决定(PM 开场会 --dry-run 看一眼)。
239
242
  team_cmd_resume() {
240
- local only="" all=1 dry=0 quiet=0
243
+ local only="" all=1 dry=0 quiet=0 failed=0
241
244
  while [ $# -gt 0 ]; do
242
245
  case "$1" in
243
246
  --agent) only="${2:?}"; all=0; shift 2 ;;
@@ -245,7 +248,7 @@ team_cmd_resume() {
245
248
  --dry-run) dry=1; shift ;;
246
249
  --quiet) quiet=1; shift ;;
247
250
  -*) team_usage_die "resume: 未知参数 $1" ;;
248
- # 位置参数也当 agent 名(erp 反馈:team resume dev 应该能用)
251
+ # 位置参数也当 agent 名(外部项目反馈:team resume dev 应该能用)
249
252
  *) if [ -z "$only" ]; then only="$1"; all=0; shift; else team_usage_die "resume: 多余参数 $1"; fi ;;
250
253
  esac
251
254
  done
@@ -257,18 +260,30 @@ team_cmd_resume() {
257
260
  for a in $(team_agents); do
258
261
  [ -n "$only" ] && [ "$a" != "$only" ] && continue
259
262
  task="$(team_state_get "$a" task '')"
260
- [ -n "$task" ] || continue
263
+ if [ -z "$task" ]; then
264
+ if [ -n "$only" ]; then
265
+ team_err "$a: no recorded assignment to resume;保留磁盘交接后显式 dispatch <task> <brief> --fresh"
266
+ failed=1
267
+ fi
268
+ continue
269
+ fi
261
270
  if team_agent_live "$a"; then live=$((live + 1)); continue; fi
262
271
  taskfile="$(team_state_get "$a" taskfile '')"
263
272
  if [ ! -f "$taskfile" ]; then
264
- team_warn "$a:任务 $task 的任务书不见了($taskfile)→ 写 thread,跳过"
273
+ team_warn "$a:任务 $task 的任务书不见了($taskfile)→ 跳过"
274
+ failed=1
275
+ [ "$dry" != 1 ] || continue
265
276
  team_cmd_thread "$a" --re "$task" "pulse 想续跑 $task,但任务书 $taskfile 不存在。请 PM 重新生成或改用 --task 指定。" >/dev/null 2>&1 || true
266
277
  team_inbox_append "$a" blocked "pulse: 任务书丢失,无法续跑 $task"
267
278
  continue
268
279
  fi
269
280
  n=$((n + 1))
270
281
  if [ "$dry" = "1" ]; then
282
+ # P240:dry-run 是 PM「一眼看清哪些席位有活可续」的清单入口(workflows.md:the PM looks for itself)。
283
+ # P228 的合同要求 dry-run 解析与真派单同一套预检/计划(退非 0、不写盘),那条走下面的 --print;
284
+ # 但清单行本身是既有输出契约(--select 11c / 6k⑥ / M9.3-③ 都钉它),两个都要在:先列清单,再看计划。
271
285
  printf ' %s 可续跑:%s → %s\n' "$a" "$task" "$taskfile"
286
+ team_cmd_dispatch "$a" "$task" "$taskfile" --print || failed=1
272
287
  else
273
288
  team_info " 续跑 $a · $task"
274
289
  # M9.3:resume / `up --agents` 与 dispatch 共用同一扇门,而它们派的**永远是这个 agent 自己
@@ -278,6 +293,7 @@ team_cmd_resume() {
278
293
  team_wlog "resume agent=$a task=$task"
279
294
  else
280
295
  # 常见两类:容量/并发排队(正常),或工作树状态不允许(需要 PM 处理)
296
+ failed=1
281
297
  team_warn "$a 续跑没成功:看上面一行原因(容量/并发属正常排队;工作树脏/分支不对要 PM 处理)"
282
298
  fi
283
299
  fi
@@ -285,7 +301,7 @@ team_cmd_resume() {
285
301
  if [ "$n" -eq 0 ]; then
286
302
  [ "$quiet" != "1" ] && team_dim " 没有需要续跑的 agent(在跑 $live 个)"
287
303
  fi
288
- return 0
304
+ return "$failed"
289
305
  }
290
306
 
291
307
  # ---------------------------------------------------------------- team watch
@@ -396,6 +412,10 @@ team_watch_once() {
396
412
  return 0
397
413
  fi
398
414
 
415
+ if ! team_pm_identity_guard; then
416
+ team_wlog "PM continuity blocked;人工 $TEAM_CLI up --fresh-pm;不计 attempt/restart,不建窗"
417
+ return 0
418
+ fi
399
419
  # ③c 有待办但 PM 没在跑 → 把它拉起来(除非 tmux 场地不在且不允许重建)
400
420
  # idle(空提示符)与 unknown(本项目里的非 PM 占用者)都算「没有 PM」;foreign 不碰。
401
421
  case "$st" in
@@ -823,7 +843,7 @@ team_panel_activity_json() { # <1|0> <events>
823
843
  # 本 session 里没有任何窗口 → 不翻别人的会话(也不给 monitor.mjs 传空 --only,那等于「全都要」)
824
844
  [ -n "$only" ] || { printf '[]'; return 0; }
825
845
  [ -n "${TEAM_AGENT_LOG_GLOB:-}" ] && g=(--log-glob "$TEAM_AGENT_LOG_GLOB")
826
- out="$("$runner" "$js" --root "$TEAM_MAIN_ROOT" --only "$only" --events "$events" \
846
+ out="$("$runner" "$js" --root "$TEAM_MAIN_ROOT" --state-dir "$TEAM_STATE_DIR" --only "$only" --events "$events" \
827
847
  ${g[@]+"${g[@]}"} --json 2>/dev/null || true)"
828
848
  case "${out:-}" in
829
849
  \[*) printf '%s' "$out" ;;
@@ -1243,9 +1263,42 @@ team_panel_detail_json() { # <id> [file]
1243
1263
  "$(team_panel_json_str_ml "$text")" "$truncated" "$out"
1244
1264
  }
1245
1265
 
1266
+ # ---- 关键回复块(change: pulse-key-replies):三个 console-only 只读块,直接进 helper。
1267
+ # 这三块**不参与** team_scan_warm:回复读路径的 IO 边界必须在自己的 helper 里被证明,
1268
+ # 不能被既有 board/report 的全量扫描掩盖(design §4)。helper 自己不 mkdir、不写盘、不等 writer 锁。
1269
+ team_panel_reply_helper() { # <helper 子命令> [args...]
1270
+ local helper="$TEAM_SKILL_DIR/scripts/replies.mjs"
1271
+ if [ ! -f "$helper" ]; then
1272
+ printf 'team: __panel-data: 缺存储 helper(%s)\n' "$helper" >&2
1273
+ return 4
1274
+ fi
1275
+ local runner; runner="$(team_js_runner)"
1276
+ if [ -z "$runner" ]; then
1277
+ printf 'team: __panel-data: 缺 JS 运行时(node/bun/tsx)\n' >&2
1278
+ return 4
1279
+ fi
1280
+ local state_dir="${TEAM_STATE_DIR:-$TEAM_MAIN_ROOT/.pi/team/state}"
1281
+ "$runner" "$helper" "$@" --main-root "$TEAM_MAIN_ROOT" --state-dir "$state_dir"
1282
+ }
1283
+
1284
+ team_panel_reply_summary_json() { team_panel_reply_helper summary; }
1285
+
1286
+ team_panel_reply_list_json() { # [--before <no>]
1287
+ if [ -n "${1:-}" ] && [ "${1:-}" != "-" ]; then
1288
+ team_panel_reply_helper list --before "$1" --format json
1289
+ else
1290
+ team_panel_reply_helper list --format json
1291
+ fi
1292
+ }
1293
+
1294
+ team_panel_reply_body_json() { # <no>
1295
+ [ -n "${1:-}" ] || { printf 'team: __panel-data --block reply_body 需要 --no <编号>\n' >&2; return 2; }
1296
+ team_panel_reply_helper show --no "$1" --format json
1297
+ }
1298
+
1246
1299
  # 块分发:一个块一个子进程(panel.js 用 --block 起一片),源坏时打印尽力而为的片段并返回非 0,
1247
1300
  # 由渲染层把那一块画成 `—`,其余块照常渲染。
1248
- team_panel_block() { # <块名> <activity 1|0> <events> [id] [file]
1301
+ team_panel_block() { # <块名> <activity 1|0> <events> [id] [file] [before] [no]
1249
1302
  case "$1" in
1250
1303
  frame) team_panel_frame_json ;;
1251
1304
  pm) team_panel_pm_json ;;
@@ -1264,6 +1317,9 @@ team_panel_block() { # <块名> <activity 1|0> <events> [id] [file]
1264
1317
  health) team_panel_health_json ;;
1265
1318
  detail) team_panel_detail_json "${4:-}" "${5:-}" ;;
1266
1319
  settings) team_panel_settings_json ;;
1320
+ reply_summary) team_panel_reply_summary_json ;;
1321
+ reply_list) team_panel_reply_list_json "${6:-}" ;;
1322
+ reply_body) team_panel_reply_body_json "${7:-}" ;;
1267
1323
  activity) team_panel_activity_json "${2:-1}" "${3:-4}" ;;
1268
1324
  *) team_usage_die "__panel-data: 未知块名 $1" ;;
1269
1325
  esac
@@ -1272,7 +1328,7 @@ team_panel_block() { # <块名> <activity 1|0> <events> [id] [file]
1272
1328
  # 内部命令:给 panel.js 一个 JSON({panel, activity})或一个块(--block <名>)。
1273
1329
  # 名字带 __ 前缀 = 不是给人用的命令面。
1274
1330
  team_cmd_panel_data() {
1275
- local activity=1 events="${TEAM_MONITOR_EVENTS:-4}" block="" did="" dfile=""
1331
+ local activity=1 events="${TEAM_MONITOR_EVENTS:-4}" block="" did="" dfile="" rbefore="" rno=""
1276
1332
  while [ $# -gt 0 ]; do
1277
1333
  case "$1" in
1278
1334
  --no-activity) activity=0; shift ;;
@@ -1281,6 +1337,8 @@ team_cmd_panel_data() {
1281
1337
  --block) block="${2:?__panel-data: --block 需要块名}"; shift 2 ;;
1282
1338
  --id) did="${2:?__panel-data: --id 需要入口 id}"; shift 2 ;;
1283
1339
  --file) dfile="${2:?__panel-data: --file 需要路径}"; shift 2 ;;
1340
+ --before) rbefore="${2:?__panel-data: --before 需要编号}"; shift 2 ;;
1341
+ --no) rno="${2:?__panel-data: --no 需要编号}"; shift 2 ;;
1284
1342
  -*) team_usage_die "__panel-data: 未知参数 $1" ;;
1285
1343
  *) team_usage_die "__panel-data: 多余参数 $1" ;;
1286
1344
  esac
@@ -1290,9 +1348,13 @@ team_cmd_panel_data() {
1290
1348
  # 进程替换起一个后台产者,末尾再收;输出键序与字节与串行完全一致。
1291
1349
  local _act_fd _act_out='[]'
1292
1350
  if [ -n "$block" ]; then
1293
- # M50:pending 块逐份迭代报告 → 全量档;其余块(pm/frame/capacity/agents/…)不碰 candidates → 宽度档
1294
- case "$block" in pending) team_scan_warm --reports ;; *) team_scan_warm ;; esac
1295
- team_panel_block "$block" "$activity" "$events" "$did" "$dfile"
1351
+ # 关键回复三块直接进只读 helper(不预热扫描);其余块照旧共享扫描缓存。
1352
+ case "$block" in
1353
+ reply_summary|reply_list|reply_body) ;;
1354
+ pending) team_scan_warm --reports ;;
1355
+ *) team_scan_warm ;;
1356
+ esac
1357
+ team_panel_block "$block" "$activity" "$events" "$did" "$dfile" "$rbefore" "$rno"
1296
1358
  return $?
1297
1359
  fi
1298
1360
  if [ "$activity" = "1" ]; then