teamsmith 0.3.3 → 0.4.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.
- package/README.md +8 -8
- package/package.json +2 -6
- package/skills/teamsmith/CHANGELOG.md +77 -0
- package/skills/teamsmith/SKILL.md +83 -163
- package/skills/teamsmith/extension/team-inbox-watch.ts +30 -1
- package/skills/teamsmith/extension/team-notify.ts +162 -21
- package/skills/teamsmith/extension/team-reply.ts +105 -0
- package/skills/teamsmith/references/agent-adapters.md +4 -2
- package/skills/teamsmith/references/config.md +21 -12
- package/skills/teamsmith/references/migration.md +47 -3
- package/skills/teamsmith/references/protocol.md +85 -31
- package/skills/teamsmith/references/reminders.md +131 -0
- package/skills/teamsmith/references/troubleshooting.md +26 -8
- package/skills/teamsmith/references/workflows.md +18 -16
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +290 -68
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1 -1
- package/skills/teamsmith/scripts/lib/cmd-project.sh +193 -21
- package/skills/teamsmith/scripts/lib/cmd-remind.sh +103 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +177 -21
- package/skills/teamsmith/scripts/lib/cmd-update.sh +7 -4
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +11 -1
- package/skills/teamsmith/scripts/lib/common.sh +50 -6
- package/skills/teamsmith/scripts/lib/outbox.sh +103 -21
- package/skills/teamsmith/scripts/panel/panel.js +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +1 -1
- package/skills/teamsmith/scripts/remind-store.mjs +529 -0
- package/skills/teamsmith/scripts/replies.mjs +9 -3
- package/skills/teamsmith/scripts/reply-capture.mjs +596 -0
- package/skills/teamsmith/scripts/state-authority.mjs +500 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +2 -1
- package/skills/teamsmith/scripts/strings/help.en.tsv +16 -2
- package/skills/teamsmith/scripts/strings/help.zh.tsv +16 -2
- package/skills/teamsmith/scripts/team +2 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +68 -123
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +48 -55
- package/skills/teamsmith/templates/config.sh.tmpl +2 -1
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +126 -119
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +17 -6
- package/skills/teamsmith/tests/bg-ledger.sh +16 -5
- package/skills/teamsmith/tests/checkout-shape-probe.sh +6 -5
- package/skills/teamsmith/tests/delivery-truth.sh +82 -47
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +71 -23
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-dirty-ab.py +143 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +26 -9
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +92 -20
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +47 -3
- package/skills/teamsmith/tests/fixtures/reply-capture-provider.ts +76 -0
- package/skills/teamsmith/tests/flip-p410-order2.sh +205 -0
- package/skills/teamsmith/tests/frames/README.md +3 -1
- package/skills/teamsmith/tests/gate-guard.sh +20 -4
- package/skills/teamsmith/tests/help-surface.sh +61 -3
- package/skills/teamsmith/tests/install-shape.sh +400 -38
- package/skills/teamsmith/tests/key-replies-pty.sh +197 -21
- package/skills/teamsmith/tests/key-replies.sh +187 -68
- package/skills/teamsmith/tests/ledger-claim.sh +8 -6
- package/skills/teamsmith/tests/lib/box-judge.sh +2 -1
- package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +104 -0
- package/skills/teamsmith/tests/lib/pm-window.sh +127 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +7 -19
- package/skills/teamsmith/tests/lib/reply-guard.sh +188 -0
- package/skills/teamsmith/tests/lib/section-calls.pl +171 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +7 -5
- package/skills/teamsmith/tests/meta-suite.sh +215 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +154 -17
- package/skills/teamsmith/tests/panel-b3.sh +33 -4
- package/skills/teamsmith/tests/panel-choices.sh +11 -7
- package/skills/teamsmith/tests/remind-cli.sh +574 -0
- package/skills/teamsmith/tests/reply-capture-real.mjs +360 -0
- package/skills/teamsmith/tests/reply-capture-real.sh +5 -0
- package/skills/teamsmith/tests/reply-capture.mjs +622 -0
- package/skills/teamsmith/tests/section-paths.tsv +41 -10
- package/skills/teamsmith/tests/section-select.sh +180 -26
- package/skills/teamsmith/tests/smoke.sh +1829 -249
- package/skills/teamsmith/tests/state-authority-node.mjs +42 -0
- package/skills/teamsmith/tests/state-authority.sh +629 -0
- package/skills/teamsmith/tests/task-model-routing.sh +10 -1
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +33 -0
- package/skills/teamsmith/tests/team-notify-knock-marker.mjs +91 -0
- package/skills/teamsmith/tests/workflow-entry.sh +123 -3
- package/skills/teamsmith-init/SKILL.md +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
# teamsmith · 更新与版本自检:mark-loaded / version [--check] / changelog
|
|
3
3
|
#
|
|
4
4
|
# 三种更新粒度(实测自 Pi 的 reload 实现):
|
|
5
|
-
# scripts/**
|
|
5
|
+
# 普通 scripts/** 每次调用现读盘 → 零操作;reply-capture/replies 是扩展的已加载依赖,须 reload
|
|
6
6
|
# SKILL.md / references / templates → /reload(或 team reload)刷新描述与清单;正文本来就每次读盘
|
|
7
|
-
# extension/*.ts
|
|
7
|
+
# 已有 extension/*.ts 重新 import → /reload;PM 原启动未注入 reply 入口时须获权重启
|
|
8
8
|
#
|
|
9
9
|
# 本模块提供:把"本会话启动时的版本"记下来,之后任何时刻都能判断"我是不是旧的"。
|
|
10
10
|
|
|
@@ -13,7 +13,10 @@ team_skill_changelog() { printf '%s/CHANGELOG.md\n' "$TEAM_SKILL_DIR"; }
|
|
|
13
13
|
# M27:扩展面从一个变成两个(notify + bg);指纹必须覆盖**两个**,否则改了 team-bg.ts
|
|
14
14
|
# 而 `team version --check` 还说「没变」,PM 不会想起 /reload。team_skill_ext 保留
|
|
15
15
|
# 单数形态(老调用方要的是 notify 扩展那一个路径)。
|
|
16
|
-
team_skill_exts() {
|
|
16
|
+
team_skill_exts() {
|
|
17
|
+
printf '%s\n' "$TEAM_SKILL_DIR/extension/team-notify.ts" "$TEAM_SKILL_DIR/extension/team-bg.ts" \
|
|
18
|
+
"$TEAM_SKILL_DIR/extension/team-reply.ts" "$TEAM_SKILL_DIR/scripts/reply-capture.mjs" "$TEAM_SKILL_DIR/scripts/replies.mjs"
|
|
19
|
+
}
|
|
17
20
|
team_skill_ext() { printf '%s\n' "$TEAM_SKILL_DIR/extension/team-notify.ts"; }
|
|
18
21
|
|
|
19
22
|
team_skill_doc_version() { # SKILL.md frontmatter 里的 version
|
|
@@ -28,7 +31,7 @@ team_skill_changelog_version() { # CHANGELOG 顶部版本
|
|
|
28
31
|
sed -n 's/^##[[:space:]]*\[*v\?\([0-9][0-9.]*\)\]*.*/\1/p' "$f" | head -1
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
team_skill_hash() { # SKILL.md +
|
|
34
|
+
team_skill_hash() { # SKILL.md + 扩展入口/实际捕获依赖指纹(不代表 live runtime 已装载)
|
|
32
35
|
local a f
|
|
33
36
|
a="$(team_skill_file)"
|
|
34
37
|
{
|
|
@@ -380,7 +380,17 @@ team_cmd_up() {
|
|
|
380
380
|
team_tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
|
|
381
381
|
fi
|
|
382
382
|
if ! team_pm_window_exists; then
|
|
383
|
-
|
|
383
|
+
# V60 R2:这里曾经是 `|| true` + 无条件的成功行 —— 窗口没建出来(tmux 起不来 / 路径不可用)时
|
|
384
|
+
# 用户看到的是「✓ 创建 PM 窗口」,接着 up 按「窗口存在」的样子往下走。失败就用 rc 说话:
|
|
385
|
+
# 点名目标、保留 tmux 自己的诊断(不重定向),不打印成功行、也不继续。
|
|
386
|
+
local pm_win_rc=0
|
|
387
|
+
team_tmux_new_window "$TEAM_SESSION" "$TEAM_PM_WINDOW" || pm_win_rc=$?
|
|
388
|
+
if [ "$pm_win_rc" != "0" ]; then
|
|
389
|
+
team_err "创建 PM 窗口失败($TEAM_SESSION:$TEAM_PM_WINDOW,tmux new-window rc=$pm_win_rc;上面是 tmux 的诊断):窗口不存在,PM 没有起来"
|
|
390
|
+
team_dim " 修法:确认 tmux server 可用(tmux ls)后重跑 $TEAM_CLI up;窗口在、里面是空的:up 会重启 PM" >&2
|
|
391
|
+
team_up_backup_note
|
|
392
|
+
return 1
|
|
393
|
+
fi
|
|
384
394
|
team_ok "创建 PM 窗口 $TEAM_SESSION:$TEAM_PM_WINDOW"
|
|
385
395
|
fi
|
|
386
396
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# 由 scripts/team 与各 cmd-*.sh source;不要直接执行。
|
|
4
4
|
# 约定:所有函数名以 team_ 前缀;不依赖 jq / python / node。
|
|
5
5
|
|
|
6
|
-
TEAM_VERSION="0.
|
|
6
|
+
TEAM_VERSION="0.4.0"
|
|
7
7
|
|
|
8
8
|
# ---------------------------------------------------------------- 输出
|
|
9
9
|
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
|
|
@@ -1122,7 +1122,6 @@ team_load_config() {
|
|
|
1122
1122
|
# 明细文件(state/notify.log)的事件上界:越界轮转到 state/notify.log.1(只留一代)。
|
|
1123
1123
|
TEAM_NOTIFY_DETAIL_MAX="${TEAM_NOTIFY_DETAIL_MAX:-2048}"
|
|
1124
1124
|
TEAM_INBOX_IN_MAIN="${TEAM_INBOX_IN_MAIN:-1}"
|
|
1125
|
-
TEAM_INBOX_MAX_CHARS="${TEAM_INBOX_MAX_CHARS:-150}"
|
|
1126
1125
|
TEAM_CONFIRM_WRITES="${TEAM_CONFIRM_WRITES:-1}"
|
|
1127
1126
|
TEAM_AGENTS="${TEAM_AGENTS:-}"
|
|
1128
1127
|
TEAM_EXTRA_PI_ARGS="${TEAM_EXTRA_PI_ARGS:-}"
|
|
@@ -1643,6 +1642,43 @@ team_with_lock() ( # <resource> <command> [args...]
|
|
|
1643
1642
|
"$@"
|
|
1644
1643
|
)
|
|
1645
1644
|
|
|
1645
|
+
# ---------------------------------------------------------------- 项目状态权威(P406 · agent-self-reminder 1.1/1.2)
|
|
1646
|
+
# 一个状态根、一份版本化快照、一把 flock 事务锁:CLI / Pulse(Bash)与 Pi(Node)共用
|
|
1647
|
+
# scripts/state-authority.mjs 这一份实现。这里只做身份与入口 —— 锁、原子写、快照校验、错误语义
|
|
1648
|
+
# 全在助手里。**没有**不持锁的落回路径:缺 flock / 等锁超时 / 快照读不懂都是显式失败。
|
|
1649
|
+
#
|
|
1650
|
+
# 身份只认目录:继承的 TEAM_MAIN_ROOT 只有在与当前目录所属项目一致时才接受;不一致 → 拒绝
|
|
1651
|
+
# (不挑一个状态权威、也不把提醒/Standby 写进另一个项目)。状态根本身由项目自己的定位器钉住:
|
|
1652
|
+
# 首次使用写 <main>/.pi/team/reminder-locator.json,之后每次比对 —— 改 override 需要显式迁移。
|
|
1653
|
+
team_authority_main_root() { # → 本项目的物理主工作树(继承值必须与目录一致)
|
|
1654
|
+
local inherited="${TEAM_MAIN_ROOT:-}" dir_main main
|
|
1655
|
+
dir_main="$(team_main_root)" || dir_main="" # 留:不在 git 仓库里 = 空答案,下一行具名拒绝
|
|
1656
|
+
[ -n "$dir_main" ] || { team_err "state-authority:当前目录不在 git 工作树里,定不出项目主工作树"; return 1; }
|
|
1657
|
+
main="${inherited:-$dir_main}"
|
|
1658
|
+
if [ -n "$inherited" ] && [ "$(team_identity_norm_dir "$inherited")" != "$(team_identity_norm_dir "$dir_main")" ]; then
|
|
1659
|
+
team_err "state-authority:继承的 TEAM_MAIN_ROOT=$inherited 与当前目录所属项目($dir_main)不一致 —— 不挑一个状态权威;清掉继承值或 cd 到目标项目"
|
|
1660
|
+
return 1
|
|
1661
|
+
fi
|
|
1662
|
+
printf '%s\n' "$main"
|
|
1663
|
+
}
|
|
1664
|
+
team_authority_cli() { # <resolve|init|read|allocate> [参数];助手自己取 flock,这里只解析运行时
|
|
1665
|
+
local runner main state
|
|
1666
|
+
runner="$(team_js_runner)"
|
|
1667
|
+
[ -n "$runner" ] || { team_err "state-authority:缺 JS 运行时(node/bun/tsx 都解析不到)—— 装一个或设 TEAM_JS_BIN 指向绝对路径"; return 1; }
|
|
1668
|
+
main="$(team_authority_main_root)" || return 1
|
|
1669
|
+
state="${TEAM_STATE_DIR:-}"
|
|
1670
|
+
[ -n "$state" ] || { team_err "state-authority:TEAM_STATE_DIR 未解析(先 team_load_config)"; return 1; }
|
|
1671
|
+
"$runner" "${TEAM_SKILL_DIR:-$(team_skill_dir)}/scripts/state-authority.mjs" --cli "$main" "$state" "$@"
|
|
1672
|
+
}
|
|
1673
|
+
team_authority_state_root() { team_authority_cli resolve --print stateRoot; }
|
|
1674
|
+
team_authority_init() { team_authority_cli init; }
|
|
1675
|
+
team_authority_read() { team_authority_cli read; }
|
|
1676
|
+
team_authority_allocate() { # <reminder|batch|queue> → 分配到的序号(持久 high-water,不重用)
|
|
1677
|
+
local kind="${1:-}"
|
|
1678
|
+
[ -n "$kind" ] || { team_err "state-authority:allocate 需要序号类别(reminder|batch|queue)"; return 1; }
|
|
1679
|
+
team_authority_cli allocate "$kind" --print value
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1646
1682
|
team_identity_snapshot() { # One bounded DATA snapshot, for worker and PM records.
|
|
1647
1683
|
local f="$1" data='' bytes
|
|
1648
1684
|
TEAM_IDENTITY_DATA=''; TEAM_IDENTITY_DIAGNOSTIC='missing identity record'
|
|
@@ -2844,7 +2880,12 @@ team_orphan_read_environ() { # <pid> → 环境文本;读不到 → 非 0
|
|
|
2844
2880
|
local f
|
|
2845
2881
|
f="$(team_orphan_proc_dir "${1:-}")/environ"
|
|
2846
2882
|
[ -r "$f" ] || return 1
|
|
2847
|
-
|
|
2883
|
+
# P366:`[ -r ]`(access(2))与真正的读**不是同一道门**。容器 `--pid=host` 下两者差得很远(实测一次全扫:
|
|
2884
|
+
# access 答「可读」600 条,其中 599 条真读被拒),宿主上也有同形状的进程(非 dumpable 的同 uid 进程)。
|
|
2885
|
+
# 读放在子 shell 里、把内核/shell 的报错收进**这条判定本身**:读不到 → rc≠0(身份未知,调用方跳过、
|
|
2886
|
+
# 不猜身份),stdout/stderr 一个字节都不多;读得到时 stdout 与改动前逐字节相同(子 shell 只透传,
|
|
2887
|
+
# 不缓冲、不改写)。诊断由**返回值**承担,不许让 shell 的报错顶替读数。
|
|
2888
|
+
( tr '\0' '\n' < "$f" ) 2>/dev/null || return 1
|
|
2848
2889
|
return 0
|
|
2849
2890
|
}
|
|
2850
2891
|
|
|
@@ -3233,7 +3274,7 @@ team_pm_abort_uncommitted() { # only the window started by this attempt
|
|
|
3233
3274
|
team_tmux_kill_window "$target" || { team_err "uncommitted PM stop failed: $target;检查保存的诊断"; return 1; }
|
|
3234
3275
|
}
|
|
3235
3276
|
|
|
3236
|
-
team_pm_pi_args() { # PM
|
|
3277
|
+
team_pm_pi_args() { # PM 定向加载 bg/inbox-watch/reply,不加载 notify;默认 -c 延续本目录上一个会话
|
|
3237
3278
|
team_pm_identity_guard || return 1
|
|
3238
3279
|
local model="$(team_pm_model_resolve)" args=()
|
|
3239
3280
|
args=(--provider "${model%%/*}" --model "${model#*/}")
|
|
@@ -3241,6 +3282,7 @@ team_pm_pi_args() { # PM 不加载 notify 扩展(它就是收件人),但
|
|
|
3241
3282
|
[ -d "$TEAM_SKILL_DIR" ] && args+=(-e "$TEAM_SKILL_DIR/extension/team-bg.ts")
|
|
3242
3283
|
# M30:PM 的收件箱监视唤醒(投递换道:pi 通道不再往输入框粘贴)
|
|
3243
3284
|
[ -d "$TEAM_SKILL_DIR" ] && args+=(-e "$TEAM_SKILL_DIR/extension/team-inbox-watch.ts")
|
|
3285
|
+
[ -d "$TEAM_SKILL_DIR" ] && args+=(-e "$TEAM_SKILL_DIR/extension/team-reply.ts")
|
|
3244
3286
|
[ -d "$TEAM_SKILL_DIR" ] && args+=(--skill "$TEAM_SKILL_DIR")
|
|
3245
3287
|
# 续跑参数(M8.1):TEAM_PM_SESSION_ID > 显式 TEAM_PM_RESUME_ARGS > 历史的 -c。
|
|
3246
3288
|
# 默认三个都空 = 与历史逐字节一致;显式配了 resume 参数就换掉默认的 -c(同一套键也服务于自定义 CLI)。
|
|
@@ -3529,8 +3571,10 @@ team_pm_launch_cmd() { # <prompt_file> <spawn_file> → respawn-pane 的 shell-c
|
|
|
3529
3571
|
if [ -z "$(team_trim "${TEAM_PM_CMD:-}")" ]; then
|
|
3530
3572
|
pi_bin="$(team_pm_bin_path)"
|
|
3531
3573
|
# M40:启动前先清洗身份 env(继承的 TEAM_* 一律清掉,只写本命令推导出的身份)
|
|
3532
|
-
printf '%s%
|
|
3533
|
-
"$(team_identity_env_prefix "$TEAM_MAIN_ROOT")" "$(team_tmux_shim_exports)"
|
|
3574
|
+
printf '%s%sexport TEAM_STATE_DIR=%q TEAM_CONFIG_FILE=%q TEAM_PM_WINDOW=%q; cd %q && printf "%%s\\n" $$ > %q && exec %q %s @%q' \
|
|
3575
|
+
"$(team_identity_env_prefix "$TEAM_MAIN_ROOT")" "$(team_tmux_shim_exports)" \
|
|
3576
|
+
"$TEAM_STATE_DIR" "${TEAM_CONFIG:-${TEAM_CONFIG_FILE:-}}" "$TEAM_PM_WINDOW" \
|
|
3577
|
+
"$TEAM_MAIN_ROOT" "$spawnfile" "$pi_bin" "$(team_pm_pi_args)" "$pf"
|
|
3534
3578
|
return 0
|
|
3535
3579
|
fi
|
|
3536
3580
|
expanded="$(team_agent_expand pm "$TEAM_PM_CMD" pm "${TEAM_PM_SESSION_ID:-}" \
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
# 投递 = 写 durable 收件箱 + 往 `state/inbox-watch/<key>.wake` 追加一行指针;会话里的扩展读到
|
|
15
15
|
# 就 `sendMessage(triggerTurn)` 唤醒 —— **一个键都不碰**。五次 draft-race 事故(D20/M17/M24/…)
|
|
16
16
|
# 的结论:框检测判不准「人的草稿 vs 我们刚贴进去的 payload」,所以 pi 通道换道而不是继续修。
|
|
17
|
-
# 粘贴路径(守卫 + 收回)保留给非 pi target
|
|
17
|
+
# 粘贴路径(守卫 + 收回)保留给非 pi target、没有可用 watcher 的默认 `say` 直投尝试,以及人的显式
|
|
18
|
+
# 逃生门(`outbox flush --now` / `draft send --now`)。
|
|
18
19
|
#
|
|
19
20
|
# 已知的诚实边界(写进 references/troubleshooting.md §3,不许静默):
|
|
20
21
|
# - 只有空白的草稿会被判成 EMPTY(光标相对检测法的实测盲区);
|
|
@@ -1259,6 +1260,31 @@ team_inbox_watch_clip() { # <text> [<max-bytes=700>] → stdout
|
|
|
1259
1260
|
printf '%s' "$cut" | LC_ALL=C sed 's/[^ -~]*$//'
|
|
1260
1261
|
}
|
|
1261
1262
|
|
|
1263
|
+
# notice-fulltext-and-asks · 预览被剪时**每一层自己说出「剪了、剪了多少、原文在哪」**(design §4)。
|
|
1264
|
+
# 标记是 spool 行的**第 7 个 Tab 字段**,不塞进 preview 字段:后者必须仍然是「≤ 界的最长整字符
|
|
1265
|
+
# 前缀」(既有契约),把标记塞进去两边都不成立。老读者只看前 5–6 个字段(team-inbox-watch.ts
|
|
1266
|
+
# 按 f[4]/f[5] 取)—— 多一个字段不炸,且**没有第 7 字段的旧行不得被当成「被剪了」**。
|
|
1267
|
+
# `full=` 的取值顺序:durable 指向的收件箱文件(条目头部就是真相)→ 载荷里自带的 `full=`
|
|
1268
|
+
# (knock 的载荷在扩展那一层被剪时就写了自己那个定位,它指向 worker 收件箱的那一行)。
|
|
1269
|
+
# 两者都没有的形状是「durable=- 且载荷没带定位」(nudge、或短到扩展都没剪的敲门):此时只写
|
|
1270
|
+
# `<shown>/<total>`,不编造一个不存在的文件 —— 那份正文在发送方自己的日志里(唤醒文本的尾句点名了它)。
|
|
1271
|
+
team_inbox_watch_cut_marker() { # <原载荷(已扁平)> <剪后的预览> <durable> → stdout(没剪 → 空)
|
|
1272
|
+
local payload="$1" preview="$2" durable="$3" total shown locator
|
|
1273
|
+
[ "$preview" != "$payload" ] || return 0
|
|
1274
|
+
total="$(printf '%s' "$payload" | LC_ALL=C wc -c | tr -d ' ')"
|
|
1275
|
+
shown="$(printf '%s' "$preview" | LC_ALL=C wc -c | tr -d ' ')"
|
|
1276
|
+
case "$total$shown" in *[!0-9]*|'') return 0 ;; esac
|
|
1277
|
+
locator=''
|
|
1278
|
+
if [ -n "$durable" ] && [ "$durable" != '-' ]; then
|
|
1279
|
+
locator="full=${TEAM_DOCS_DIR}/inbox/${durable}.md"
|
|
1280
|
+
else
|
|
1281
|
+
locator="$(printf '%s' "$payload" | tr ' ' '\n' | LC_ALL=C awk '/^full=/ { print; exit }')"
|
|
1282
|
+
fi
|
|
1283
|
+
printf 'truncated=preview:%s/%sB' "$shown" "$total"
|
|
1284
|
+
[ -n "$locator" ] && printf ' %s' "$locator"
|
|
1285
|
+
return 0
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1262
1288
|
# 顺序不能反:spool 行存在 ⟹ 收件箱里已经有这条(唤醒不会指向空气)。
|
|
1263
1289
|
# durable 的判定(条目头部是契约,不靠正文逐字匹配 —— 重复的相同消息不会被误吞):
|
|
1264
1290
|
# inbox + inbox-written=1 → 发送方已经写过了(名字可能是 `-` :它的记录在自家日志里,如 nudges.log)
|
|
@@ -1268,7 +1294,7 @@ team_inbox_watch_clip() { # <text> [<max-bytes=700>] → stdout
|
|
|
1268
1294
|
# 返回 0 = 已投递;1 = 投不出去(条目留在队列里重试,绝不假装投过)。
|
|
1269
1295
|
team_inbox_watch_deliver() { # <entry> <kind> <from> <key> <route-inbox> <payload> → 0 已投递 / 1 投不出去
|
|
1270
1296
|
local e="$1" kind="$2" from="$3" key="$4" route_inbox="$5" payload="$6"
|
|
1271
|
-
local dir req_ib="" durable="-" preview
|
|
1297
|
+
local dir req_ib="" durable="-" preview clipped marker
|
|
1272
1298
|
dir="$(team_inbox_watch_dir)"
|
|
1273
1299
|
mkdir -p "$dir" || return 1
|
|
1274
1300
|
req_ib="$(team_outbox_header "$e" inbox)"
|
|
@@ -1287,10 +1313,13 @@ team_inbox_watch_deliver() { # <entry> <kind> <from> <key> <route-inbox> <payloa
|
|
|
1287
1313
|
# 预览有界(700 字节):spool 行保持小(并发 `>>` 的自追加写尽量落在一次 write 里;扩展侧还会按
|
|
1288
1314
|
# TEAM_INBOX_WATCH_PREVIEW 再截一次字符数)。正文全文在收件箱/发送方日志里,不在这里。
|
|
1289
1315
|
# P28/B6:按**字符**边界裁(`cut -c` 在任何 locale 下都按字节,会把多字节字符截半)。
|
|
1290
|
-
|
|
1316
|
+
clipped="$(team_inbox_watch_clip "$preview" 700)"
|
|
1317
|
+
marker="$(team_inbox_watch_cut_marker "$preview" "$clipped" "$durable")"
|
|
1318
|
+
preview="$clipped"
|
|
1291
1319
|
# P81:第 6 字段 = 发送方自己的 durable 记录名(outbox 条目名,与 state/outbox/delivered.log 的 name
|
|
1292
1320
|
# 列同一个串)—— 接收方的唤醒文本与投递日志用它点名「这是哪一条」;老读者按 5 字段照读。
|
|
1293
|
-
|
|
1321
|
+
# 第 7 字段 = 本层自己的截断标记(见 team_inbox_watch_cut_marker);没剪就是空字段。
|
|
1322
|
+
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$(team_epoch_ms)" "$kind" "${from:--}" "$durable" "$preview" "$(basename "$e")" "$marker" >> "$dir/$key.wake" || return 1
|
|
1294
1323
|
return 0
|
|
1295
1324
|
}
|
|
1296
1325
|
|
|
@@ -1633,13 +1662,16 @@ team_outbox_note() { # <ok|warn|plain> <文本>:--quiet 时整段静音(警
|
|
|
1633
1662
|
esac
|
|
1634
1663
|
}
|
|
1635
1664
|
|
|
1636
|
-
team_outbox_process_entry() { # <entry> [--now] [--no-verify]
|
|
1665
|
+
team_outbox_process_entry() { # <entry> [--now] [--no-verify] [--watch-only]
|
|
1637
1666
|
local e="$1"; shift
|
|
1638
|
-
local now=0 noverify=0
|
|
1667
|
+
local now=0 noverify=0 watch_only=0
|
|
1639
1668
|
while [ $# -gt 0 ]; do
|
|
1640
1669
|
case "$1" in
|
|
1641
1670
|
--now) now=1; shift ;;
|
|
1642
1671
|
--no-verify) noverify=1; shift ;;
|
|
1672
|
+
# P393 · 私有的一次性模式(只有「已选中监视通道的默认 say」会传):本次只走监视通道;
|
|
1673
|
+
# 路由消失/持久化失败就留下条目,绝不换道去打字。不进队头、不持久化、不影响后续普通排水。
|
|
1674
|
+
--watch-only) watch_only=1; shift ;;
|
|
1643
1675
|
*) shift ;;
|
|
1644
1676
|
esac
|
|
1645
1677
|
done
|
|
@@ -1703,6 +1735,17 @@ team_outbox_process_entry() { # <entry> [--now] [--no-verify]
|
|
|
1703
1735
|
fi
|
|
1704
1736
|
team_outbox_note warn "outbox:$(basename "$e") pi 通道投递失败(收件箱写不进去)→ 留在队列重试"
|
|
1705
1737
|
team_outbox_release "$e"
|
|
1738
|
+
TEAM_OUTBOX_CHANNEL="watch-pending"
|
|
1739
|
+
TEAM_OUTBOX_RESULT="queued"
|
|
1740
|
+
return 0
|
|
1741
|
+
fi
|
|
1742
|
+
|
|
1743
|
+
# P393:已选中的监视通道本次不可用(路由已消失)—— 条目留在队列、零按键;
|
|
1744
|
+
# 不落到下面的 EMPTY/BUSY 守卫,也不走 forced。后续普通排水仍是原来的受守卫排水。
|
|
1745
|
+
if [ "$watch_only" = "1" ]; then
|
|
1746
|
+
team_outbox_note warn "outbox:$(basename "$e") 已选中的监视通道路由已消失 → 留在队列(本次不打字)"
|
|
1747
|
+
team_outbox_release "$e"
|
|
1748
|
+
TEAM_OUTBOX_CHANNEL="watch-pending"
|
|
1706
1749
|
TEAM_OUTBOX_RESULT="queued"
|
|
1707
1750
|
return 0
|
|
1708
1751
|
fi
|
|
@@ -1918,7 +1961,10 @@ team_outbox_drain() { # [--now] [--quiet] [--max N] [--retry-impeded]
|
|
|
1918
1961
|
# 所有「往 TUI 输入框打字」的发送方都走这里。设置 TEAM_SEND_OUTCOME:
|
|
1919
1962
|
# delivered(已确认送达)|watched(pi 监视通道:已写收件箱 + 唤醒指针,输入框零按键)|queued(进队列了)
|
|
1920
1963
|
# |held(阻碍 hold:geometry-untrusted / queue-stalled,返回非 0)
|
|
1921
|
-
# |forced(--now
|
|
1964
|
+
# |forced(--now 或 kind=say 的默认直投:一次尝试,不是回执)
|
|
1965
|
+
# |offline-handled(say 的直投前检查已把消息落收件箱并解释原因)
|
|
1966
|
+
# |persist-failed(已选监视通道但队列条目写不进去:非零持久化错误)
|
|
1967
|
+
# |unknown-sent|unknown-failed|offline|duplicate
|
|
1922
1968
|
team_send_guarded() { # <target> <payload> <kind> [--from F] [--dedup K] [--inbox A] [--inbox-written A] [--now] [--no-verify] [--meeting-ledger V]
|
|
1923
1969
|
local target="$1" payload="$2" kind="$3"; shift 3
|
|
1924
1970
|
local from="-" dedup="" inbox="" inbox_written="" now=0 noverify=0 queue_offline=0 meeting_ledger=""
|
|
@@ -1938,11 +1984,40 @@ team_send_guarded() { # <target> <payload> <kind> [--from F] [--dedup K] [--inbo
|
|
|
1938
1984
|
TEAM_SEND_OUTCOME=""
|
|
1939
1985
|
TEAM_SEND_ENTRY=""
|
|
1940
1986
|
TEAM_SEND_REASON=""
|
|
1941
|
-
local entry="" rc=0 v=""
|
|
1987
|
+
local entry="" rc=0 v="" watch_route="" default_direct=0 watch_only=0
|
|
1942
1988
|
|
|
1943
|
-
|
|
1989
|
+
# M30 · pi 通道:目标装了 inbox-watch 扩展(活的注册)→ 不查输入框、不判 SHELL/NOPANE
|
|
1990
|
+
# (那些问题问的是「能不能打字」;pi 通道根本不打字),直接入队,投递由 process_entry 走收件箱 + spool。
|
|
1991
|
+
# P393:这一次查询同时就是 fresh `kind=say` 的路由选择(watch 优先)。
|
|
1992
|
+
[ "$now" = "1" ] || watch_route="$(team_inbox_watch_route "$target" 2>/dev/null || true)"
|
|
1993
|
+
|
|
1994
|
+
# P393 · 默认 say = 先 watch、没有可用 watcher 才走旧 forced 动作。
|
|
1995
|
+
# 意图只由**这次发送**的 kind=say 解释(不是新的 flag,也不进入队头/排水):
|
|
1996
|
+
# team_outbox_process_entry 不按 kind 强制,所以后续普通排水仍是受守卫的排水。
|
|
1997
|
+
# 目标资格检查(窗口/死 pane/空提示符)在决定直投的这一刻、按键之前做(team_say_prepare_direct)。
|
|
1998
|
+
if [ "$kind" = "say" ] && [ "$now" != "1" ] && [ -n "$inbox" ]; then
|
|
1999
|
+
if [ -z "$watch_route" ]; then
|
|
2000
|
+
local prep=0
|
|
2001
|
+
team_say_prepare_direct "$inbox" "$target" "$payload" || prep=$?
|
|
2002
|
+
case "$prep" in
|
|
2003
|
+
0) default_direct=1 ;;
|
|
2004
|
+
*) # 已经离线处理完(收件箱已写、原因已打印):不重复追加、不打字
|
|
2005
|
+
TEAM_SEND_OUTCOME="offline-handled"
|
|
2006
|
+
return 0 ;;
|
|
2007
|
+
esac
|
|
2008
|
+
else
|
|
2009
|
+
watch_only=1 # 已选中监视通道:这次即时处理只走监视通道,路由/持久化失败不换道
|
|
2010
|
+
fi
|
|
2011
|
+
fi
|
|
2012
|
+
|
|
2013
|
+
if [ "$now" = "1" ] || [ "$default_direct" = "1" ]; then
|
|
1944
2014
|
team_outbox_force_log "$target" "$kind" "$from"
|
|
1945
|
-
|
|
2015
|
+
if [ "$now" = "1" ]; then
|
|
2016
|
+
team_warn "--now:跳过守卫,直接往 $target 打字(今天的旧行为,已记入 outbox/forced.log)"
|
|
2017
|
+
else
|
|
2018
|
+
# 只由 kind=say 的默认直投走到这里:决不展示已退休的 flag,也不声称已确认送达。
|
|
2019
|
+
team_warn "say:没有可用的监视通道,直接往 $target 打字(立即尝试,未确认模型接收;已记入 outbox/forced.log)"
|
|
2020
|
+
fi
|
|
1946
2021
|
local before="" i after="" text
|
|
1947
2022
|
text="$(team_deliver_text "$target" "$payload")"
|
|
1948
2023
|
[ "$noverify" = "1" ] || before="$(team_pane_snapshot "$target")"
|
|
@@ -1969,10 +2044,7 @@ team_send_guarded() { # <target> <payload> <kind> [--from F] [--dedup K] [--inbo
|
|
|
1969
2044
|
elif [ -n "$inbox" ]; then enq+=(--inbox "$inbox"); fi
|
|
1970
2045
|
enq+=(--payload "$payload")
|
|
1971
2046
|
|
|
1972
|
-
# M30 · pi
|
|
1973
|
-
# (那些问题问的是「能不能打字」;pi 通道根本不打字),直接入队,投递由 process_entry 走收件箱 + spool。
|
|
1974
|
-
local watch_route=""
|
|
1975
|
-
[ "$now" = "1" ] || watch_route="$(team_inbox_watch_route "$target" 2>/dev/null || true)"
|
|
2047
|
+
# M30 · pi 通道:见上面的路由选择(watch_route 已在进入时查询过;显式 --now 不查)
|
|
1976
2048
|
if [ -n "$watch_route" ]; then
|
|
1977
2049
|
v="" # pi 通道:不打字,就不需要判 SHELL/NOPANE/BUSY
|
|
1978
2050
|
else
|
|
@@ -2016,13 +2088,19 @@ team_send_guarded() { # <target> <payload> <kind> [--from F] [--dedup K] [--inbo
|
|
|
2016
2088
|
TEAM_SEND_OUTCOME="duplicate"
|
|
2017
2089
|
return 0
|
|
2018
2090
|
fi
|
|
2019
|
-
[ -n "$entry" ] && [ -f "$entry" ] || {
|
|
2091
|
+
[ -n "$entry" ] && [ -f "$entry" ] || {
|
|
2092
|
+
# P393:已选中监视通道却连队列条目都建不起来 = 真实持久化失败。不许报 offline(那不是离线)、
|
|
2093
|
+
# 不许报 queued/收件箱成功,也不许因此改成盲直投 —— 调用方保持这个非零错误。
|
|
2094
|
+
if [ -n "$watch_route" ]; then
|
|
2095
|
+
TEAM_SEND_OUTCOME="persist-failed"
|
|
2096
|
+
return 1
|
|
2097
|
+
fi
|
|
2098
|
+
TEAM_SEND_OUTCOME="offline"; return 1; }
|
|
2020
2099
|
TEAM_SEND_ENTRY="$entry"
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
fi
|
|
2100
|
+
local pa=()
|
|
2101
|
+
[ "$watch_only" = "1" ] && pa+=(--watch-only)
|
|
2102
|
+
[ "$noverify" = "1" ] && pa+=(--no-verify)
|
|
2103
|
+
team_outbox_process_entry "$entry" ${pa[@]+"${pa[@]}"}
|
|
2026
2104
|
case "$TEAM_OUTBOX_RESULT" in
|
|
2027
2105
|
delivered)
|
|
2028
2106
|
if [ "$TEAM_OUTBOX_CHANNEL" = "watch" ]; then TEAM_SEND_OUTCOME="watched"
|
|
@@ -2036,7 +2114,11 @@ team_send_guarded() { # <target> <payload> <kind> [--from F] [--dedup K] [--inbo
|
|
|
2036
2114
|
return 1
|
|
2037
2115
|
fi
|
|
2038
2116
|
TEAM_SEND_OUTCOME="queued" ;;
|
|
2039
|
-
*)
|
|
2117
|
+
*)
|
|
2118
|
+
TEAM_SEND_OUTCOME="queued"
|
|
2119
|
+
# P393:监视通道在这次即时处理里没走完(路由消失/收件箱写不进去):条目留在队列,
|
|
2120
|
+
# 本次零按键;调用方的输出不能说成「目标有草稿」。
|
|
2121
|
+
[ "$TEAM_OUTBOX_CHANNEL" = "watch-pending" ] && TEAM_SEND_REASON="watch-pending" ;;
|
|
2040
2122
|
esac
|
|
2041
2123
|
return 0
|
|
2042
2124
|
}
|