teamsmith 0.3.2 → 0.3.4
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 +5 -4
- package/package.json +2 -6
- package/skills/handover/SKILL.md +117 -0
- package/skills/teamsmith/CHANGELOG.md +65 -0
- package/skills/teamsmith/SKILL.md +2 -1
- package/skills/teamsmith/extension/team-inbox-watch.ts +30 -1
- package/skills/teamsmith/extension/team-notify.ts +161 -20
- package/skills/teamsmith/references/agent-adapters.md +3 -1
- package/skills/teamsmith/references/config.md +1 -1
- package/skills/teamsmith/references/protocol.md +21 -0
- package/skills/teamsmith/references/troubleshooting.md +7 -3
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +213 -19
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1 -1
- package/skills/teamsmith/scripts/lib/cmd-init.sh +85 -9
- package/skills/teamsmith/scripts/lib/cmd-status.sh +177 -21
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +11 -1
- package/skills/teamsmith/scripts/lib/common.sh +7 -3
- package/skills/teamsmith/scripts/lib/outbox.sh +31 -3
- 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/strings/help.en.tsv +1 -1
- package/skills/teamsmith/scripts/strings/help.zh.tsv +1 -1
- package/skills/teamsmith/scripts/team +1 -0
- package/skills/teamsmith/templates/config.sh.tmpl +2 -1
- 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 +10 -2
- package/skills/teamsmith/tests/help-surface.sh +1 -1
- package/skills/teamsmith/tests/install-shape.sh +234 -46
- package/skills/teamsmith/tests/panel-choices.sh +11 -7
- package/skills/teamsmith/tests/section-paths.tsv +2 -2
- package/skills/teamsmith/tests/skill-load.mjs +6 -2
- package/skills/teamsmith/tests/smoke.sh +643 -27
- 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/tmux-lint.pl +12 -2
- package/skills/teamsmith-init/SKILL.md +1 -1
|
@@ -78,6 +78,27 @@ Guards and limitations:
|
|
|
78
78
|
records in `state/notify.log`, bounded by `TEAM_NOTIFY_DETAIL_MAX` and rotated once). A different key, a manual
|
|
79
79
|
notice in between, or a record write that failed starts a new line; a byte-identical briefing inside
|
|
80
80
|
`TEAM_NOTIFY_DEDUP_SEC` is still suppressed outright.
|
|
81
|
+
- **A notice also lands where the PM reads it** (change `turn-notice-in-pm-inbox`): when the resolved sender is not
|
|
82
|
+
the PM, the same settle writes a second, **independent** line — a pointer — into `docs/team/inbox/pm.md`:
|
|
83
|
+
`<ISO> [<tag>] agent:<seat> · <ID> · knock=enqueued|skipped:<class> · see=docs/team/inbox/<seat>.md`, plus
|
|
84
|
+
`task=<ID> tip=<hex>` when the record carries the revision stamp and `awaiting=<ids>` for a suspension. It is
|
|
85
|
+
derived by the writing side from the record line (same merge key, same merger, no second "what is the same run"
|
|
86
|
+
implementation) and it does **not** append to the detail file, so a run's `×N` still equals its record count. It
|
|
87
|
+
carries no last-message summary, no `branch=`/`uncommitted=`/`unpushed=` and no `⚠ 未提交` prefix: it says where to
|
|
88
|
+
look, and the PM's line count is the PM's pending count. `knock=` is a **run-scoped** field like `×N` and
|
|
89
|
+
`first=`: extending a run keeps the value its first event wrote, because only that event could have woken the PM.
|
|
90
|
+
`enqueued` means "handed to the delivery guard", never "delivered" (`state/outbox/delivered.log` says that). A
|
|
91
|
+
failed pointer write is logged by the extension and changes nothing else: it does not delay, suppress or duplicate
|
|
92
|
+
the knock, and the record line is already on disk. The record line itself stays byte-identical — the pointer is a
|
|
93
|
+
second, independent write, not a rewrite.
|
|
94
|
+
- **One notice is counted once**: an auto-class line whose `agent:` names the inbox file's own seat is that seat's
|
|
95
|
+
record, not its unread traffic (`team_inbox_new` and `team_inbox_since` share the one predicate), so one delivery
|
|
96
|
+
adds exactly one to the PM's pending count — the pointer line — and a seat no longer sees its own `[auto]` lines as
|
|
97
|
+
new mail. Historical `[auto]` lines are not counted after the upgrade and are **not** backfilled with pointers: a
|
|
98
|
+
pointer records where a notice landed and what the knock did, and neither is observable for a notice written before
|
|
99
|
+
the pointer existed. `team inbox <seat> --all` still shows them. `--detail` reconciles a merged line's `×N`
|
|
100
|
+
against the records of **that line's own key** (its first component is the sender), so a `×N` pointer line in
|
|
101
|
+
`pm.md` is not reported as a gap.
|
|
81
102
|
- **A notice names the revision it describes** (R2/P139; width and branch proof fixed by P160): the durable inbox
|
|
82
103
|
line and the knock payload carry `task=<ID> tip=<12-hex>` — the **first twelve hex characters of the branch tip,
|
|
83
104
|
truncated by the sender itself** (`git rev-parse HEAD | cut -c1-12`; the extension's `TIP_WIDTH`), never a Git
|
|
@@ -299,9 +299,13 @@ Honest edges (documented, not hidden):
|
|
|
299
299
|
captures a pane, advances a drain observation or retries a delivery.
|
|
300
300
|
|
|
301
301
|
If a notification really did get glued (e.g. the whitespace-only case), the mitigations from before still apply:
|
|
302
|
-
answer with a short sentence right after reading it,
|
|
303
|
-
|
|
304
|
-
|
|
302
|
+
answer with a short sentence right after reading it, set `TEAM_NOTIFY_TMUX=0` and read `team digest` yourself — or
|
|
303
|
+
run that session on a built-in Pi launch path, where the box is not part of the delivery channel at all.
|
|
304
|
+
|
|
305
|
+
`TEAM_INBOX_MAX_CHARS` is **not** one of them: it only shortens the preview a knock quotes. The record line in
|
|
306
|
+
`docs/team/inbox/<seat>.md` and the detail in `state/notify.log` keep the whole message, so lowering it removes no
|
|
307
|
+
text from the inbox and no text from the disk — read what is already there and `team inbox <seat> --ack` it away,
|
|
308
|
+
and the volume that matters (events per day) is bounded by `TEAM_NOTIFY_DETAIL_MAX`, not by this key.
|
|
305
309
|
|
|
306
310
|
## 4. `team dispatch` refuses to dispatch
|
|
307
311
|
|
|
@@ -1800,15 +1800,38 @@ team_notify_line_events() {
|
|
|
1800
1800
|
printf '%s\n' "$n"
|
|
1801
1801
|
}
|
|
1802
1802
|
|
|
1803
|
+
# 行里的 `knock=`(指针行的 run 级字段;记录行从不带它 → 空)。
|
|
1804
|
+
team_notify_knock_of() { # <行> → knock= 的值(没有 → 空)
|
|
1805
|
+
local head="${1#- }"
|
|
1806
|
+
head="${head%% :: *}"
|
|
1807
|
+
case "$head" in
|
|
1808
|
+
*'knock='*) head="${head#*knock=}"; printf '%s\n' "${head%% *}" ;;
|
|
1809
|
+
*) printf '\n' ;;
|
|
1810
|
+
esac
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1803
1813
|
# 汇总行 = **最后一条事件的行** + 首事件时间戳 + 字段区 `×N first= last=`(branch/tip/uncommitted 自动是最后一条的值)。
|
|
1804
|
-
|
|
1805
|
-
|
|
1814
|
+
# 第 5 参 <已存在的行> 只服务一条 run 级字段规则:两边都有 `knock=` 时取**已存在那一行**的值 ——
|
|
1815
|
+
# 叫醒只发生在 run 的第一个事件上(state=new 才入队,扩展一律不入队),让扩展事件把 knock 改写会
|
|
1816
|
+
# 让这一行说谎。记录行从不带 knock=,所以对记录行的输出逐字节无影响。
|
|
1817
|
+
team_notify_line_merge() { # <新事件行> <首时间戳> <n> <末时间戳> [<已存在的行>]
|
|
1818
|
+
local c="$1" first="$2" n="$3" last="$4" prev="${5:-}" head tail rest pk pre post cur
|
|
1806
1819
|
case "$c" in
|
|
1807
1820
|
*' :: '*) head="${c%% :: *}"; tail="${c#* :: }" ;;
|
|
1808
1821
|
*) head="$c"; tail='' ;;
|
|
1809
1822
|
esac
|
|
1810
1823
|
rest="${head#* }"
|
|
1811
1824
|
head="${first} ${rest} · ×${n} first=${first} last=${last}"
|
|
1825
|
+
if [ -n "$prev" ]; then
|
|
1826
|
+
pk="$(team_notify_knock_of "$prev")"
|
|
1827
|
+
case "$head" in
|
|
1828
|
+
*'knock='*)
|
|
1829
|
+
if [ -n "$pk" ]; then
|
|
1830
|
+
pre="${head%%knock=*}"; post="${head#*knock=}"; cur="${post%% *}"
|
|
1831
|
+
head="${pre}knock=${pk}${post#"$cur"}"
|
|
1832
|
+
fi ;;
|
|
1833
|
+
esac
|
|
1834
|
+
fi
|
|
1812
1835
|
if [ "${c%% :: *}" != "$c" ]; then printf '%s :: %s\n' "$head" "$tail"; else printf '%s\n' "$head"; fi
|
|
1813
1836
|
}
|
|
1814
1837
|
|
|
@@ -1840,8 +1863,10 @@ team_notify_detail_events() { # <明细文件> → 事件行数(轮转头不
|
|
|
1840
1863
|
}
|
|
1841
1864
|
|
|
1842
1865
|
# 先明细:一行一事件(内容 = 该事件单发形状的收件箱行)。越界 → 轮转一代到 <file>.1 + 新代轮转头。
|
|
1843
|
-
|
|
1844
|
-
|
|
1866
|
+
# 第 3 参只影响轮转在扩展日志里的名字:结果账(notify-knock.log)与明细共用这一个轮转器与同一个上界,
|
|
1867
|
+
# 但两件东西不是一回事,日志里点错名字会让下一次查现场的人找错文件。
|
|
1868
|
+
team_notify_detail_append() { # <事件行> <文件> [轮转日志里的名字=detail] → 0 = 已落盘;1 = 失败(调用方写 detail=unavailable)
|
|
1869
|
+
local content="$1" file="$2" label="${3:-detail}" dir max count
|
|
1845
1870
|
dir="$(dirname "$file")"
|
|
1846
1871
|
mkdir -p "$dir" || return 1
|
|
1847
1872
|
max="$(team_notify_detail_max)"
|
|
@@ -1849,7 +1874,7 @@ team_notify_detail_append() { # <事件行> <明细文件> → 0 = 已落盘;1
|
|
|
1849
1874
|
if [ "$count" -ge "$max" ]; then
|
|
1850
1875
|
mv -f "$file" "$file.1" || return 1
|
|
1851
1876
|
printf '%s\n' "# rotation $(team_timestamp) moved=${count} path=${file}.1" > "$file" || return 1
|
|
1852
|
-
team_notify_log_line "notify
|
|
1877
|
+
team_notify_log_line "notify ${label} rotated: moved=${count} to=${file}.1"
|
|
1853
1878
|
fi
|
|
1854
1879
|
printf -- '- %s\n' "$content" >> "$file" 2>/dev/null || return 1
|
|
1855
1880
|
return 0
|
|
@@ -1869,12 +1894,95 @@ team_inbox_rewrite_last() { # <收件箱文件> <新尾行> → 0 = 已重写;
|
|
|
1869
1894
|
return 0
|
|
1870
1895
|
}
|
|
1871
1896
|
|
|
1872
|
-
#
|
|
1873
|
-
|
|
1897
|
+
# 指针行派生(turn-notice-in-pm-inbox · design §2):记录行 → PM 收件箱里的那一行。
|
|
1898
|
+
# 由**写入侧**从记录行派生,而不是在扩展里另拼一份 —— 「什么算同一个 run」只有 team_notify_line_key
|
|
1899
|
+
# 一份实现,两边才不可能在缺字段/awaiting 顺序/⚠ 前缀上分叉。四处变换,字段顺序写死:
|
|
1900
|
+
# ① 删 `⚠ 未提交 N 个文件 · ` 前缀(告警框是事件级的告警,指针不复制它);
|
|
1901
|
+
# ② 只留 run 级字段 `task=<ID> tip=<hex>`、`awaiting=<ids>`、`detail=unavailable`:
|
|
1902
|
+
# branch=/uncommitted=/unpushed= 是「last= 那一刻」的事件级快照,抄进 run 级摘要只会显示一个
|
|
1903
|
+
# 过期瞬间(PM 要判断这些时读的是 see= 指的那份记录);
|
|
1904
|
+
# ③ 插入 `knock=<outcome> · see=docs/team/inbox/<seat>.md`;
|
|
1905
|
+
# ④ 删 ` :: <末消息>` 尾巴(摘要在记录行与敲门载荷里各有一份;pm.md 的行数是 PM 的待办数)。
|
|
1906
|
+
# 记录行的状态类(design §6 的 class= 字段):[auto] → delivered、[auto·suspended] → suspended、
|
|
1907
|
+
# [auto·interrupted] → interrupted;其余(没有记录行 / 非 auto 行)是 `-`。
|
|
1908
|
+
# 与 team_inbox_line_is_record / 合并键共用同一套 tag 拼写,不另立一份。
|
|
1909
|
+
team_notify_line_class() { # <记录行> → delivered|suspended|interrupted|-
|
|
1910
|
+
local body tag
|
|
1911
|
+
body="${1#- }"
|
|
1912
|
+
case "$body" in *'['*) ;; *) printf '%s\n' '-' ; return 0 ;; esac
|
|
1913
|
+
tag="${body#*\[}"; tag="${tag%%\]*}"
|
|
1914
|
+
case "$tag" in
|
|
1915
|
+
auto) printf '%s\n' delivered ;;
|
|
1916
|
+
'auto·suspended') printf '%s\n' suspended ;;
|
|
1917
|
+
'auto·interrupted') printf '%s\n' interrupted ;;
|
|
1918
|
+
*) printf '%s\n' '-' ;;
|
|
1919
|
+
esac
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
# 结果账(turn-notice-in-pm-inbox · A2):一行一次 settle —— 项目内那个跨 ack、跨轮转之后还能回答
|
|
1923
|
+
# 「今天 skipped 了几次、为什么」的地方。与 state/notify.log 同一个轮转器与同一个上界(不新增配置键)。
|
|
1924
|
+
team_notify_knock_ledger_path() { printf '%s/notify-knock.log\n' "$(team_state_dir)"; }
|
|
1925
|
+
|
|
1926
|
+
team_notify_knock_ledger_append() { # <seat> <task> <class> <outcome> <pointer> <identity> → 0 = 已落盘
|
|
1927
|
+
local line
|
|
1928
|
+
line="$(team_timestamp) seat=$1 · task=$2 · class=$3 · outcome=$4 · pointer=$5 · identity=$6"
|
|
1929
|
+
team_notify_detail_append "$line" "$(team_notify_knock_ledger_path)" knock
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
team_notify_pointer_line() { # <记录行> <outcome> → 指针行(解析不成立 → rc 1)
|
|
1933
|
+
local body="$1" outcome="$2"
|
|
1934
|
+
local iso rest tag seat tok head f task_f='' aw_f='' ask_f='' det_f=''
|
|
1935
|
+
iso="${body%% *}"
|
|
1936
|
+
case "$iso" in ''|*[!0-9TZ:.-]*) return 1 ;; esac
|
|
1937
|
+
rest="${body#"$iso" }"
|
|
1938
|
+
[ "$rest" != "$body" ] || return 1
|
|
1939
|
+
case "$rest" in '⚠'*) rest="${rest#*· }" ;; esac
|
|
1940
|
+
case "$rest" in '['*) ;; *) return 1 ;; esac
|
|
1941
|
+
tag="${rest%%\]*}"; tag="${tag#\[}"
|
|
1942
|
+
rest="${rest#*\] }"
|
|
1943
|
+
case "$rest" in agent:*) ;; *) return 1 ;; esac
|
|
1944
|
+
seat="${rest#agent:}"; seat="${seat%% *}"
|
|
1945
|
+
[ -n "$seat" ] || return 1
|
|
1946
|
+
rest="${rest#"agent:$seat"}"
|
|
1947
|
+
case "$rest" in ' '*|'') ;; *) return 1 ;; esac
|
|
1948
|
+
rest="${rest# }"
|
|
1949
|
+
case "$rest" in '· '*) rest="${rest#· }" ;; *) return 1 ;; esac
|
|
1950
|
+
head="${rest%% :: *}"
|
|
1951
|
+
tok="${head%% · *}"
|
|
1952
|
+
[ -n "$tok" ] || return 1
|
|
1953
|
+
rest="${head#"$tok"}"
|
|
1954
|
+
case "$rest" in ' · '*) rest="${rest# · }" ;; *) rest='' ;; esac
|
|
1955
|
+
while [ -n "$rest" ]; do
|
|
1956
|
+
f="${rest%% · *}"
|
|
1957
|
+
if [ "$f" = "$rest" ]; then rest=''; else rest="${rest#* · }"; fi
|
|
1958
|
+
case "$f" in
|
|
1959
|
+
task=*) task_f="$f" ;;
|
|
1960
|
+
awaiting=*) aw_f="$f" ;;
|
|
1961
|
+
# notice-fulltext-and-asks:`asks=` 是**事件级**字段(跟 branch=/tip= 同类),但它是 PM 唯一可行动
|
|
1962
|
+
# 的信号,所以在这里被有意复制 —— PM 读的是 pm.md,不是 worker 的收件箱。branch=/uncommitted=/unpushed=
|
|
1963
|
+
# 仍然不复制(它们只描述 last= 那一刻的快照)。
|
|
1964
|
+
asks=*) ask_f="$f" ;;
|
|
1965
|
+
'detail=unavailable') det_f="$f" ;;
|
|
1966
|
+
*) : ;; # branch=/uncommitted=/unpushed= 与未识别字段:事件级,不属于指针
|
|
1967
|
+
esac
|
|
1968
|
+
done
|
|
1969
|
+
printf '%s [%s] agent:%s · %s · knock=%s · see=%s/inbox/%s.md' \
|
|
1970
|
+
"$iso" "$tag" "$seat" "$tok" "$outcome" "$TEAM_DOCS_DIR" "$seat"
|
|
1971
|
+
[ -n "$task_f" ] && printf ' · %s' "$task_f"
|
|
1972
|
+
[ -n "$ask_f" ] && printf ' · %s' "$ask_f"
|
|
1973
|
+
[ -n "$aw_f" ] && printf ' · %s' "$aw_f"
|
|
1974
|
+
[ -n "$det_f" ] && printf ' · %s' "$det_f"
|
|
1975
|
+
printf '\n'
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
# 临界区(调用方持锁):明细(detail=- → 不写)→ 尾行锚判定 → 截尾重写或追加 → 打印写入结果。
|
|
1979
|
+
# turn-notice-in-pm-inbox:记录行与指针行走**同一段**合并逻辑,唯一区别是明细写不写 —— 指针行不进
|
|
1980
|
+
# 明细,所以一个 run 的 ×N 仍然等于它的记录数(把指针也记进明细会让两边分家)。
|
|
1981
|
+
team_inbox_merge_or_append() { # <recipient> <行> <文件> <明细|-> → state=new|extended first=<ISO> key=<键>
|
|
1874
1982
|
local recipient="$1" content="$2" file="$3" detail="$4"
|
|
1875
1983
|
local key='' detail_failed=0 newcontent="$content" state=new first='' tail_line merged n
|
|
1876
1984
|
key="$(team_notify_line_key "$content" || true)"
|
|
1877
|
-
if [ -n "$key" ]; then
|
|
1985
|
+
if [ -n "$key" ] && [ "$detail" != '-' ]; then
|
|
1878
1986
|
if ! team_notify_detail_append "$content" "$detail"; then
|
|
1879
1987
|
detail_failed=1
|
|
1880
1988
|
newcontent="$(team_notify_line_mark_detail "$content")"
|
|
@@ -1887,7 +1995,7 @@ team_inbox_write_locked() { # <recipient> <行> <文件> <明细> → state=new|
|
|
|
1887
1995
|
if [ -n "$tail_line" ] && team_notify_line_anchor_ok "$tail_line" \
|
|
1888
1996
|
&& [ "$(team_notify_line_key "$tail_line" 2>/dev/null || true)" = "$key" ]; then
|
|
1889
1997
|
n=$(( $(team_notify_line_events "$tail_line") + 1 ))
|
|
1890
|
-
merged="$(team_notify_line_merge "$newcontent" "$(team_notify_line_iso "$tail_line")" "$n" "$first")"
|
|
1998
|
+
merged="$(team_notify_line_merge "$newcontent" "$(team_notify_line_iso "$tail_line")" "$n" "$first" "$tail_line")"
|
|
1891
1999
|
if team_inbox_rewrite_last "$file" "$merged"; then
|
|
1892
2000
|
state=extended
|
|
1893
2001
|
first="$(team_notify_line_iso "$tail_line")"
|
|
@@ -1897,25 +2005,36 @@ team_inbox_write_locked() { # <recipient> <行> <文件> <明细> → state=new|
|
|
|
1897
2005
|
if [ "$state" = new ]; then
|
|
1898
2006
|
printf -- '- %s\n' "$newcontent" >> "$file" || return 1
|
|
1899
2007
|
fi
|
|
1900
|
-
# 写入结果协议(单行一段,扩展用 ^first=/^key= 解析):state=new|extended
|
|
1901
|
-
|
|
2008
|
+
# 写入结果协议(单行一段,扩展用 ^state=/^first=/^key=/^lineno= 解析):state=new|extended
|
|
2009
|
+
# notice-fulltext-and-asks:`lineno=` = 这次写入之后那条记录在文件里的**1 基行号**(追加与截尾重写两条腿
|
|
2010
|
+
# 都是「文件的最后一行」)。为什么由写入侧给:敲门载荷的 `full=<文件>:<行>` 必须resolveable,
|
|
2011
|
+
# 而行号只有持锁的临界区里数才不会与并发追加错位(扩展自己算的数会错位 → 假定位)。
|
|
2012
|
+
local lineno
|
|
2013
|
+
lineno="$(LC_ALL=C wc -l < "$file" 2>/dev/null | tr -d ' ' || true)"
|
|
2014
|
+
case "$lineno" in ''|*[!0-9]*) lineno=0 ;; esac
|
|
2015
|
+
printf 'state=%s\nfirst=%s\nkey=%s\nlineno=%s\n' "$state" "$first" "${key:--}" "$lineno"
|
|
1902
2016
|
return 0
|
|
1903
2017
|
}
|
|
1904
2018
|
|
|
2019
|
+
# 记录行那条腿:参数与行为逐字节不变(明细 + 收件人自己的收件箱)。
|
|
2020
|
+
team_inbox_write_locked() { # <recipient> <行> <文件> <明细>
|
|
2021
|
+
team_inbox_merge_or_append "$1" "$2" "$3" "$4"
|
|
2022
|
+
}
|
|
2023
|
+
|
|
1905
2024
|
# 每收件人一把锁的写入口(team_inbox_append 与扩展的 __inbox-write 共用)。
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
local
|
|
1909
|
-
dir
|
|
2025
|
+
# 第 4 参 = 明细文件或 `-`(指针行走的是同一个临界区,只是不写明细)。
|
|
2026
|
+
team_inbox_write_with_lock() { # <recipient> <行> <文件> <明细|->
|
|
2027
|
+
local recipient="$1" content="$2" file="$3" detail="$4"
|
|
2028
|
+
local dir lockfd rc=0
|
|
1910
2029
|
local state; state="$(team_state_dir)"
|
|
1911
|
-
|
|
2030
|
+
dir="$(dirname "$file")"
|
|
1912
2031
|
mkdir -p "$dir" || return 1
|
|
1913
2032
|
if command -v flock >/dev/null 2>&1; then
|
|
1914
2033
|
# exec 加**不带命令**的重定向会永久改变当前 shell:`exec {fd}>&- 2>/dev/null` 会把 stderr 永久接到
|
|
1915
2034
|
# /dev/null(P251 实测:say 的 team_warn 从此消失)。这里只关 fd,不带任何 stderr 重定向。
|
|
1916
2035
|
if ! exec {lockfd}>"$state/inbox-$recipient.lock"; then return 1; fi
|
|
1917
2036
|
if flock -w 10 "$lockfd"; then
|
|
1918
|
-
|
|
2037
|
+
team_inbox_merge_or_append "$recipient" "$content" "$file" "$detail" || rc=$?
|
|
1919
2038
|
else
|
|
1920
2039
|
team_notify_log_line "inbox lock timeout: $state/inbox-$recipient.lock"
|
|
1921
2040
|
rc=1
|
|
@@ -1923,7 +2042,24 @@ team_inbox_write_line() { # <recipient> <行> → 打印写入结果(同 team_
|
|
|
1923
2042
|
exec {lockfd}>&-
|
|
1924
2043
|
return $rc
|
|
1925
2044
|
fi
|
|
1926
|
-
|
|
2045
|
+
team_inbox_merge_or_append "$recipient" "$content" "$file" "$detail"
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
team_inbox_write_line() { # <recipient> <行> → 打印写入结果(同 team_inbox_write_locked)
|
|
2049
|
+
local recipient="$1" content="$2" dir
|
|
2050
|
+
dir="$(team_inbox_dir)"
|
|
2051
|
+
team_inbox_write_with_lock "$recipient" "$content" "$dir/$recipient.md" "$(team_state_dir)/notify.log"
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
# 指针行写进 PM 的收件箱(同一把 pm 锁;不写明细)。
|
|
2055
|
+
team_inbox_write_pointer_line() { # <指针行> → 0 = 已落盘;1 = 没写成
|
|
2056
|
+
local content="$1" file
|
|
2057
|
+
file="$(team_inbox_dir)/pm.md"
|
|
2058
|
+
# 存在却不可写 → 直接判失败:截尾重写是「mktemp + mv」,它会把一次被禁止的写入伪装成成功
|
|
2059
|
+
# (只读文件所在的目录可写)。指针写不进去这件事必须让调用方看得见(pointer=failed)。
|
|
2060
|
+
if [ -e "$file" ]; then [ -w "$file" ] || return 1; fi
|
|
2061
|
+
# 内层的 state=/first=/key= 是给 __inbox-write 的协议,指针腿不消费它(调用方只看 pointer=)。
|
|
2062
|
+
team_inbox_write_with_lock pm "$content" "$file" '-' >/dev/null
|
|
1927
2063
|
}
|
|
1928
2064
|
|
|
1929
2065
|
# 内部命令(扩展消费写入结果;不进 help):--agent <席位> --from-file <单行文件>
|
|
@@ -1942,10 +2078,68 @@ team_cmd_inbox_write() {
|
|
|
1942
2078
|
[ -n "$agent" ] || team_usage_die "__inbox-write: 需要 --agent <席位>"
|
|
1943
2079
|
if [ -z "$src" ] || [ ! -f "$src" ]; then team_usage_die "__inbox-write: 需要 --from-file <行文件>"; fi
|
|
1944
2080
|
local content; content="$(head -n 1 "$src")"
|
|
1945
|
-
if [ -z "$content" ]; then printf 'state=failed\nfirst=-\nkey=-\n'; return 1; fi
|
|
2081
|
+
if [ -z "$content" ]; then printf 'state=failed\nfirst=-\nkey=-\nlineno=0\n'; return 1; fi
|
|
1946
2082
|
team_inbox_write_line "$agent" "$content"
|
|
1947
2083
|
}
|
|
1948
2084
|
|
|
2085
|
+
# 内部命令(扩展消费;不进 help):一次 settle 的旁路记账入口。
|
|
2086
|
+
# --agent <seat> --outcome <enqueued|skipped:<类>> [--record-from-file <行文件>] [--identity <id>] [--task <ID>]
|
|
2087
|
+
# 两步,顺序写死(design §4):
|
|
2088
|
+
# (a) 指针腿:有记录行 → 从它派生指针行并写进 PM 的收件箱(持 pm 的收件箱锁);没有记录行 →
|
|
2089
|
+
# 什么都写(没有东西可以指)。
|
|
2090
|
+
# (b) 结果账:每一次 settle 一行 → state/notify-knock.log(与明细同一个轮转器与上界)。它必须在
|
|
2091
|
+
# 指针尝试**之后**写,才带得上 pointer=failed —— 反过来只能记一个假值或二次改写。
|
|
2092
|
+
# 两次写都是旁路:无论成败都退出 0,把结果打印成 pointer=ok|failed|none 与 ledger=ok|failed。
|
|
2093
|
+
team_cmd_notify_settle() {
|
|
2094
|
+
local agent='' outcome='' src='' identity='-' task='-'
|
|
2095
|
+
while [ $# -gt 0 ]; do
|
|
2096
|
+
case "$1" in
|
|
2097
|
+
--agent) agent="${2:?--agent 需要值}"; shift 2 ;;
|
|
2098
|
+
--agent=*) agent="${1#*=}"; shift ;;
|
|
2099
|
+
--outcome) outcome="${2:?--outcome 需要值}"; shift 2 ;;
|
|
2100
|
+
--outcome=*) outcome="${1#*=}"; shift ;;
|
|
2101
|
+
--record-from-file) src="${2:?--record-from-file 需要文件}"; shift 2 ;;
|
|
2102
|
+
--record-from-file=*) src="${1#*=}"; shift ;;
|
|
2103
|
+
--identity) identity="${2:?--identity 需要值}"; shift 2 ;;
|
|
2104
|
+
--identity=*) identity="${1#*=}"; shift ;;
|
|
2105
|
+
--task) task="${2:?--task 需要值}"; shift 2 ;;
|
|
2106
|
+
--task=*) task="${1#*=}"; shift ;;
|
|
2107
|
+
-*) team_usage_die "__notify-settle: 未知参数 $1" ;;
|
|
2108
|
+
*) team_usage_die "__notify-settle: 多余参数 $1" ;;
|
|
2109
|
+
esac
|
|
2110
|
+
done
|
|
2111
|
+
[ -n "$agent" ] || team_usage_die "__notify-settle: 需要 --agent <席位>"
|
|
2112
|
+
case "$outcome" in
|
|
2113
|
+
''|-) team_usage_die "__notify-settle: 需要 --outcome <enqueued|skipped:<类>>" ;;
|
|
2114
|
+
enqueued) ;;
|
|
2115
|
+
skipped:?*) ;;
|
|
2116
|
+
*) team_usage_die "__notify-settle: --outcome 只有 enqueued 与 skipped:<类> 两种形状(收到 $outcome)" ;;
|
|
2117
|
+
esac
|
|
2118
|
+
local record pointer='none' cls='-'
|
|
2119
|
+
# 发送者是 PM 自己时没有「指针」:PM 的收件箱就是记录的落点(账照样记,它是一个 settle)。
|
|
2120
|
+
if [ "$agent" != pm ] && [ -n "$src" ] && [ -f "$src" ]; then
|
|
2121
|
+
record="$(head -n 1 "$src")"
|
|
2122
|
+
cls="$(team_notify_line_class "$record")"
|
|
2123
|
+
local pointer_line
|
|
2124
|
+
if ! pointer_line="$(team_notify_pointer_line "$record" "$outcome")" || [ -z "$pointer_line" ]; then
|
|
2125
|
+
team_notify_log_line "notify pointer derivation failed: seat=$agent outcome=$outcome"
|
|
2126
|
+
pointer=failed
|
|
2127
|
+
elif team_inbox_write_pointer_line "$pointer_line"; then
|
|
2128
|
+
pointer=ok
|
|
2129
|
+
else
|
|
2130
|
+
team_notify_log_line "notify pointer write failed: seat=$agent outcome=$outcome task=$task identity=$identity"
|
|
2131
|
+
pointer=failed
|
|
2132
|
+
fi
|
|
2133
|
+
fi
|
|
2134
|
+
if team_notify_knock_ledger_append "$agent" "$task" "$cls" "$outcome" "$pointer" "$identity"; then
|
|
2135
|
+
printf 'pointer=%s\nledger=ok\n' "$pointer"
|
|
2136
|
+
else
|
|
2137
|
+
team_notify_log_line "notify knock ledger write failed: seat=$agent outcome=$outcome pointer=$pointer"
|
|
2138
|
+
printf 'pointer=%s\nledger=failed\n' "$pointer"
|
|
2139
|
+
fi
|
|
2140
|
+
return 0
|
|
2141
|
+
}
|
|
2142
|
+
|
|
1949
2143
|
# notify 的去重键:内容 + 长度(同一份通知在 TEAM_NOTIFY_DEDUP_SEC 内只入队/投递一次)。
|
|
1950
2144
|
# 扩展走的是它自己的键(<agent>|<tag>|<summary>|<len>:<hash>),两边都进同一个队列条目。
|
|
1951
2145
|
team_notify_dedup_key() { # <agent> <msg>
|
|
@@ -126,7 +126,7 @@ TEAM_ZRAM_WARN_PCT|apply|pct|0,100|plain|85|-||70,80,85,90|delivery
|
|
|
126
126
|
TEAM_AGENT_MEM_MB|apply|mb|1,|plain|6144|-||2048,4096,6144|delivery
|
|
127
127
|
TEAM_NOTIFY_TMUX|apply|bool||plain|1|-|||delivery
|
|
128
128
|
TEAM_NOTIFY_DEDUP_SEC|apply|seconds|0,|plain|20|-|||delivery
|
|
129
|
-
TEAM_INBOX_MAX_CHARS|apply|int|1,|plain|150
|
|
129
|
+
TEAM_INBOX_MAX_CHARS|apply|int|1,|plain|150|预览字数:敲门载荷里引用末消息的字数上限;收件箱行与 state/notify.log 存全文||100,150,300|delivery
|
|
130
130
|
TEAM_NOTIFY_DETAIL_MAX|apply|int|1,|plain|2048|state/notify.log 的事件上界:越界轮转到 state/notify.log.1(只留一代)||512,2048,8192|delivery
|
|
131
131
|
TEAM_NOTIFY_LOG|apply|path|file,opt|plain|/tmp/teamsmith-notify.log|-|||delivery
|
|
132
132
|
TEAM_DEFER_TTL|apply|seconds|0,|plain|300|0 = 投递队列入队即过期||60,300,900|delivery
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
# 调用点:`team init` 的最后一步,以及 `team bootstrap`(同一实现,两个调用点;bootstrap 在
|
|
5
5
|
# config.sh 已存在时也要跑它 —— 这就是老项目的升级路径)。
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
7
|
+
# 源按**名字**解析到 `$TEAM_SKILL_DIR` 的兄弟目录(绝不扫描全局 skill 目录):teamsmith = 正在运行的 CLI
|
|
8
|
+
# 自己的 skill 目录,teamsmith-init / handover = 它的兄弟目录。复制布局里只带一部分就只装一部分,并**说出来**
|
|
9
|
+
# (P361:`missing` / `unregistered` / `broken` 三种可见性,见下面 team_skill_inventory 的注释)。
|
|
9
10
|
#
|
|
10
11
|
# 冲突表(与 openspec/changes/npm-cli-and-project-init/design.md §3 逐格一致;tests/install-shape.sh 走):
|
|
11
12
|
# dest 状态 默认(link) --force
|
|
@@ -32,10 +33,74 @@ team_project_extension_target() {
|
|
|
32
33
|
return 0
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
# ---------------------------------------------------------------- P361 · 技能源:解析 + 发现 + 声明面
|
|
37
|
+
# **谁是源**由发现回答:`$TEAM_SKILL_DIR` 的兄弟目录里,只有「真实目录(不是软链)+ 有 SKILL.md +
|
|
38
|
+
# frontmatter 的 name 与目录名一致」才算一个可安装的技能 —— 以后再加一个技能不用改代码。
|
|
39
|
+
# **少了谁**只能由声明回答:一个目录整个消失时,树上没有任何痕迹可供推导。所以另有一份声明面
|
|
40
|
+
# (team_skill_declared),只承担发现做不到的两件事,两个方向都由 tests/install-shape.sh 钉住(含红侧):
|
|
41
|
+
# ① 声明了、源不在 → 明说 `miss`(不是静默少装一个);
|
|
42
|
+
# ② 源在、没声明 → 明说 `note`(照装,但喊出来;声明面因此不会悄悄漂移)。
|
|
43
|
+
# 三处布局都要对:包内 skills/(检出 / npm 包)、~/.agents/skills(全局软链)、项目本地 .pi/skills(副本)。
|
|
44
|
+
# 软链布局下兄弟目录也是软链(install.sh 建的),所以「真实目录」只约束**发现**那一条,不约束名字解析。
|
|
45
|
+
team_skill_declared() { printf '%s\n' teamsmith teamsmith-init handover; return 0; }
|
|
46
|
+
|
|
47
|
+
team_skill_parent() { dirname "$TEAM_SKILL_DIR"; }
|
|
48
|
+
|
|
49
|
+
team_skill_real_parent() { # 运行目录可能是软链:技能源的真树在链接背后,兄弟目录要在那里对得上
|
|
50
|
+
dirname "$(readlink -f "$TEAM_SKILL_DIR" 2>/dev/null || printf '%s' "$TEAM_SKILL_DIR")"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# 只有「包自己的 skills/」里,兄弟目录才全是我们的技能:全局 ~/.agents/skills 下还躺着别的产品的 skill
|
|
54
|
+
# (archify、kimi-webbridge…),按兄弟目录发现会把它们一起装进别人的项目。判据 = 包根有 teamsmith 的 package.json。
|
|
55
|
+
team_skill_own_tree() {
|
|
56
|
+
local root; root="$(dirname "$(team_skill_parent)")"
|
|
57
|
+
[ -f "$root/package.json" ] || return 1
|
|
58
|
+
grep -qE '"name"[[:space:]]*:[[:space:]]*"teamsmith"' "$root/package.json"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
team_skill_src_for() { # <name> → 该技能的源目录(不存在就空):先看运行目录的兄弟,再看软链背后的真树
|
|
62
|
+
local name="$1" c
|
|
63
|
+
for c in "$(team_skill_parent)/$name" "$(team_skill_real_parent)/$name"; do
|
|
64
|
+
if [ -d "$c" ]; then printf '%s\n' "$c"; return 0; fi
|
|
65
|
+
done
|
|
66
|
+
return 0
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
team_skill_inventory() { # → 每行 "<kind>\t<name>\t<detail>";kind = ok | missing | broken | unregistered
|
|
70
|
+
local declared name src found d
|
|
71
|
+
declared="$(team_skill_declared)"
|
|
72
|
+
while IFS= read -r name; do
|
|
73
|
+
[ -n "$name" ] || continue
|
|
74
|
+
src="$(team_skill_src_for "$name")"
|
|
75
|
+
if [ -z "$src" ]; then printf 'missing\t%s\t%s\n' "$name" "$(team_skill_parent)/$name"; continue; fi
|
|
76
|
+
if [ ! -f "$src/SKILL.md" ]; then printf 'broken\t%s\t%s\n' "$name" "$src 没有 SKILL.md"; continue; fi
|
|
77
|
+
found="$(team_skill_md_name "$src")"
|
|
78
|
+
if [ "$found" != "$name" ]; then
|
|
79
|
+
printf 'broken\t%s\t%s\n' "$name" "$src 的 SKILL.md 里 name: 是 [${found:-<空>}]"
|
|
80
|
+
continue
|
|
81
|
+
fi
|
|
82
|
+
printf 'ok\t%s\t%s\n' "$name" "$src"
|
|
83
|
+
done <<< "$declared"
|
|
84
|
+
team_skill_own_tree || return 0
|
|
85
|
+
for d in "$(team_skill_parent)"/*/; do
|
|
86
|
+
[ -d "$d" ] || continue
|
|
87
|
+
[ -L "${d%/}" ] && continue # install.sh 的 M7.3:skills/ 下的软链是兼容别名,不是技能
|
|
88
|
+
name="$(basename "$d")"
|
|
89
|
+
printf '%s\n' "$declared" | grep -qxF -- "$name" && continue
|
|
90
|
+
if [ ! -f "$d/SKILL.md" ]; then printf 'broken\t%s\t%s\n' "$name" "${d%/} 没有 SKILL.md"; continue; fi
|
|
91
|
+
found="$(team_skill_md_name "$d")"
|
|
92
|
+
if [ "$found" != "$name" ]; then
|
|
93
|
+
printf 'broken\t%s\t%s\n' "$name" "${d%/} 的 SKILL.md 里 name: 是 [${found:-<空>}]"
|
|
94
|
+
continue
|
|
95
|
+
fi
|
|
96
|
+
printf 'ok\t%s\t%s\n' "$name" "${d%/}"
|
|
97
|
+
printf 'unregistered\t%s\t%s\n' "$name" "${d%/}"
|
|
98
|
+
done
|
|
99
|
+
return 0
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
team_skill_sources() { # → 每行 "<name>\t<src>",只列真实存在且合法的源
|
|
103
|
+
team_skill_inventory | awk -F'\t' '$1 == "ok" { printf "%s\t%s\n", $2, $3 }'
|
|
39
104
|
return 0
|
|
40
105
|
}
|
|
41
106
|
|
|
@@ -232,14 +297,25 @@ team_init_install_skills() { # [--copy|--link] [--no-skills] [--force] → 0 全
|
|
|
232
297
|
return 0
|
|
233
298
|
fi
|
|
234
299
|
|
|
235
|
-
|
|
300
|
+
# P361:三件发现做不到的事先说出来(都不静默):少了谁 / 谁是未登记的新技能 / 谁的源不合法。
|
|
301
|
+
local inventory kind vname detail bad=0
|
|
302
|
+
inventory="$(team_skill_inventory)"
|
|
303
|
+
while IFS=$'\t' read -r kind vname detail; do
|
|
304
|
+
case "$kind" in
|
|
305
|
+
missing) printf ' miss %s(源 %s 不在:随包发布的技能少装了一个)\n' "$vname" "$detail" ;;
|
|
306
|
+
unregistered) printf ' note %s 是 skills/ 下未登记的技能(%s):照装\n' "$vname" "$detail" ;;
|
|
307
|
+
broken) team_err "技能源不合法:$detail —— 目录名与 frontmatter 的 name 必须一致"; bad=1 ;;
|
|
308
|
+
esac
|
|
309
|
+
done <<< "$inventory"
|
|
310
|
+
|
|
311
|
+
local sources; sources="$(printf '%s\n' "$inventory" | awk -F'\t' '$1 == "ok" { printf "%s\t%s\n", $2, $3 }')"
|
|
236
312
|
if [ -z "$sources" ]; then
|
|
237
|
-
team_err "找不到可安装的 skill 源($TEAM_SKILL_DIR
|
|
313
|
+
team_err "找不到可安装的 skill 源($TEAM_SKILL_DIR 与它软链背后的 skills/ 里没有合格的技能目录)"
|
|
238
314
|
return 1
|
|
239
315
|
fi
|
|
240
316
|
|
|
241
317
|
mkdir -p "$target" || { team_err "建不了 $target"; return 1; }
|
|
242
|
-
local rc
|
|
318
|
+
local rc=$bad name src dest cur src_real found
|
|
243
319
|
while IFS=$'\t' read -r name src; do
|
|
244
320
|
[ -n "$name" ] || continue
|
|
245
321
|
dest="$target/$name"
|