feat: 收件端核對——A 的結果寫進 B 的票會被擋(inkstone/ISEP#132)
派工有票號、工人有名字(roster)、留言有【身份】三件都在派工/回覆那頭; 缺的是總管改票的那一刻,把「要改的票」跟「這個 session 派出去的那一批票」比一次 (leo 2026-09-05:「明明已經都憑 milestone 和票號了」——subagent 回報的東西被 總管當成另一件事更新)。 - hooks/dispatched-ticket-stamp.sh(PostToolUse Agent|Task):按 session 記 「哪張票派給了哪位工人」(subagent_type,剝掉 plugin 前綴)。回報(SendMessage)不記。 - hooks/report-ticket-match-guard.sh(PreToolUse Bash):總管 say/close/handback (+ Gitea API 側門)一張不在那批派工票裡的票 → 擋一次,印「X 被派的是 #A」。 判準是票號(唯一識別碼)往放行方向比對,不看措辭(leo 2026-08-17 已證偽文字層封路)。 沒派過工的 session 整支休眠;動被派出去的那張放行;讀取/別的動詞放行; 同一張只擋一次(重下就過);逃生口 report-match-ok。 - 測試 scripts/test-report-ticket-match-guard.sh 31/31(離線,戳記走 ISEP_STAMP_DIR)。 - 盤點:hooks 62→64、註冊 88→90、scripts 66→67(在這棵樹上實數); docs/hooks-inventory.md、docs/TESTING.md A43、plugin.json 描述一併更新。 版本號待總管定(未動 plugin.json version,避開 check-version-consistency)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TGxitYq49FzYC7EFkbhzF5
This commit is contained in:
Executable
+129
@@ -0,0 +1,129 @@
|
||||
#!/bin/bash
|
||||
# 收件端核對——這道閘+它的戳記的測試(inkstone/ISEP#132)
|
||||
# 判準:把「要改的票」跟「這個 session 派出去的那一批票」比一次。
|
||||
# 在那批裡 → 放行;不在 → 擋一次。全程離線(戳記走 ISEP_STAMP_DIR,不碰 /tmp 正式戳記)。
|
||||
#
|
||||
# 🔴 「不該擋」比「該擋」重要(誤攔比漏擋嚴重,ISEP mistakes 反覆記過):
|
||||
# 沒派過工的 session 一律放行、沒被派出去的票只擋一次、讀取/其他動詞全放行——這幾條各有一條測。
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
STAMP="hooks/dispatched-ticket-stamp.sh"
|
||||
GUARD="hooks/report-ticket-match-guard.sh"
|
||||
PASS=0; FAIL=0
|
||||
|
||||
WORK=$(mktemp -d)
|
||||
export ISEP_STAMP_DIR="$WORK"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
jq_cmd(){ python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$1"; }
|
||||
|
||||
# 派一張票給某工人(餵 Task payload 給戳記)
|
||||
dispatch(){ # $1=sid $2=worker $3=owner/repo#N
|
||||
printf '%s' "{\"session_id\":\"$1\",\"tool_name\":\"Task\",\"tool_input\":{\"subagent_type\":$(jq_cmd "$2"),\"prompt\":$(jq_cmd "【工單】$3")}}" \
|
||||
| bash "$STAMP" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# 跑一次守門(餵 Bash payload),比對離開碼
|
||||
run(){ # $1=want $2=sid $3=cmd $4=說明
|
||||
printf '%s' "{\"session_id\":\"$2\",\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(jq_cmd "$3")}}" \
|
||||
| bash "$GUARD" >/dev/null 2>&1
|
||||
got=$?
|
||||
if [ "$got" = "$1" ]; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
||||
printf 'want=%s got=%s %s\n' "$1" "$got" "$4"
|
||||
}
|
||||
|
||||
echo "═══ 戳記:把「哪張票派給哪位工人」記下來 ═══"
|
||||
S=stamp-$$
|
||||
dispatch "$S" "isep:isep-hand" "inkstone/ISEP#101" # 帶 plugin 前綴
|
||||
dispatch "$S" "arcrun-hand" "inkstone/arcrun-rag#88"
|
||||
dispatch "$S" "isep-hand" "inkstone/ISEP#101" # 同工人同票再派一次 → 不該多一行
|
||||
GOT=$(cat "$WORK/.dispatched-$S" 2>/dev/null)
|
||||
check(){ if printf '%s\n' "$GOT" | grep -qxF "$1"; then PASS=$((PASS+1)); echo " ✅ 記到:$1"; else FAIL=$((FAIL+1)); echo " ❌ 沒記到:$1"; fi; }
|
||||
check "$(printf 'isep-hand\tinkstone/ISEP#101')" # 前綴被剝掉
|
||||
check "$(printf 'arcrun-hand\tinkstone/arcrun-rag#88')"
|
||||
N=$(grep -c . "$WORK/.dispatched-$S")
|
||||
if [ "$N" = 2 ]; then PASS=$((PASS+1)); echo " ✅ 去重:兩行不是三行"; else FAIL=$((FAIL+1)); echo " ❌ 去重壞了:$N 行"; fi
|
||||
# 回報(SendMessage,不是新開 subagent)不該被當成派工記下來——工人名字在那條路上不存在
|
||||
printf '%s' "{\"session_id\":\"$S\",\"tool_name\":\"SendMessage\",\"tool_input\":{\"to\":\"main\",\"message\":\"【工單】inkstone/ISEP#999\"}}" | bash "$STAMP" >/dev/null 2>&1
|
||||
if grep -q '#999' "$WORK/.dispatched-$S"; then FAIL=$((FAIL+1)); echo " ❌ SendMessage 被誤記成派工"; else PASS=$((PASS+1)); echo " ✅ SendMessage(回報)不記"; fi
|
||||
|
||||
echo
|
||||
echo "═══ 該擋:派了 #A,卻去動不在那批裡的票 ═══"
|
||||
B=block-$$
|
||||
dispatch "$B" "isep-hand" "inkstone/ISEP#101"
|
||||
run 2 "$B" 'python3 scripts/ticket say inkstone/ISEP#202 -F /tmp/r.md' "say 一張沒派出去的票"
|
||||
rm -f "$WORK"/.report-match-warned-* # 每個 block 案例各自獨立(同張只擋一次)
|
||||
run 2 "$B" 'python3 scripts/ticket close inkstone/ISEP#202 --deliverable https://x/pr/1' "close 一張沒派出去的票"
|
||||
rm -f "$WORK"/.report-match-warned-*
|
||||
run 2 "$B" 'python3 scripts/ticket handback inkstone/ISEP#202 --to claude-code --next x' "handback 一張沒派出去的票"
|
||||
rm -f "$WORK"/.report-match-warned-*
|
||||
# 側門:直接打 API 貼留言到沒派出去的票
|
||||
run 2 "$B" 'curl -X POST "$API/repos/inkstone/ISEP/issues/202/comments" -d "{\"body\":\"x\"}"' "API 側門 POST 留言到沒派出去的票"
|
||||
rm -f "$WORK"/.report-match-warned-*
|
||||
# 側門:直接 PATCH 關掉沒派出去的票
|
||||
run 2 "$B" 'curl -X PATCH "$API/repos/inkstone/ISEP/issues/202" -d "{\"state\":\"closed\"}"' "API 側門 PATCH 關掉沒派出去的票"
|
||||
|
||||
echo
|
||||
echo "═══ 不該擋(比該擋更重要)═══"
|
||||
# ① 動的就是派出去的那張
|
||||
P=pass-$$
|
||||
dispatch "$P" "isep-hand" "inkstone/ISEP#101"
|
||||
run 0 "$P" 'python3 scripts/ticket say inkstone/ISEP#101 -F /tmp/r.md' "say 被派出去的那張 → 放行"
|
||||
run 0 "$P" 'python3 scripts/ticket close inkstone/ISEP#101 --deliverable https://x/pr/1' "close 被派出去的那張 → 放行"
|
||||
run 0 "$P" 'python3 scripts/ticket handback inkstone/ISEP#101 --to claude-code --next x' "handback 被派出去的那張 → 放行"
|
||||
|
||||
# ② 兩條線並行,各自回報,狀態各落各票(驗收條件第 2 條)
|
||||
T=two-$$
|
||||
dispatch "$T" "isep-hand" "inkstone/ISEP#101"
|
||||
dispatch "$T" "arcrun-hand" "inkstone/arcrun-rag#88"
|
||||
run 0 "$T" 'python3 scripts/ticket handback inkstone/ISEP#101 --to claude-code --next x' "並行:動 A 線的票 → 放行"
|
||||
run 0 "$T" 'python3 scripts/ticket handback inkstone/arcrun-rag#88 --to claude-code --next y' "並行:動 B 線的票 → 放行"
|
||||
|
||||
# ③ 這個 session 沒派過任何工 ⇒ 休眠,一律放行
|
||||
run 0 "idle-$$" 'python3 scripts/ticket say inkstone/ISEP#202 -F /tmp/r.md' "沒派過工的 session → 放行(休眠)"
|
||||
|
||||
# ④ 同一張沒派出去的票只擋一次:重下就過
|
||||
O=once-$$
|
||||
dispatch "$O" "isep-hand" "inkstone/ISEP#101"
|
||||
run 2 "$O" 'python3 scripts/ticket say inkstone/ISEP#202 -F /tmp/r.md' "第一次動 #202 → 擋"
|
||||
run 0 "$O" 'python3 scripts/ticket say inkstone/ISEP#202 -F /tmp/r.md' "重下同一個 → 放行(只擋一次)"
|
||||
|
||||
# ⑤ 逃生口
|
||||
E=esc-$$
|
||||
dispatch "$E" "isep-hand" "inkstone/ISEP#101"
|
||||
run 0 "$E" 'python3 scripts/ticket say inkstone/ISEP#202 -F /tmp/r.md report-match-ok' "report-match-ok 放行"
|
||||
|
||||
# ⑥ 純讀取(GET 撈留言)不管,就算那張沒派出去
|
||||
R=read-$$
|
||||
dispatch "$R" "isep-hand" "inkstone/ISEP#101"
|
||||
run 0 "$R" 'curl -s "$API/repos/inkstone/ISEP/issues/202/comments"' "GET 撈留言 → 放行"
|
||||
|
||||
# ⑦ 別的動詞(where/new/triage/decide/mine/subtask)全部不碰
|
||||
V=verb-$$
|
||||
dispatch "$V" "isep-hand" "inkstone/ISEP#101"
|
||||
run 0 "$V" 'python3 scripts/ticket where 卡片 佇列' "ticket where → 放行"
|
||||
run 0 "$V" 'python3 scripts/ticket new inkstone/ISEP -F /tmp/n.md --title "身為x,我要y,我才z"' "ticket new → 放行"
|
||||
run 0 "$V" 'python3 scripts/ticket triage inkstone/ISEP#202 --to s/backlog --why x' "ticket triage → 放行"
|
||||
run 0 "$V" 'python3 scripts/ticket decide inkstone/ISEP#202 -F /tmp/a.md' "ticket decide → 放行"
|
||||
run 0 "$V" 'python3 scripts/ticket mine' "ticket mine → 放行"
|
||||
run 0 "$V" 'python3 scripts/ticket subtask inkstone/ISEP#101 --title "身為x,我要y,我才z" -F /tmp/s.md' "ticket subtask → 放行"
|
||||
|
||||
# ⑧ fail-open:payload 壞掉、空指令 → 放行(PreToolUse fail-closed 會讓人做不了事)
|
||||
printf 'not json' | bash "$GUARD" >/dev/null 2>&1
|
||||
if [ $? = 0 ]; then PASS=$((PASS+1)); echo " ✅ payload 不是 JSON → 放行(fail-open)"; else FAIL=$((FAIL+1)); echo " ❌ payload 壞掉時擋住了"; fi
|
||||
run 0 "empty-$$" '' "空指令 → 放行"
|
||||
|
||||
echo
|
||||
echo "═══ 訊息內容:擋下來時說得出「X 被派的是 #A」+一條走得通的出路 ═══"
|
||||
M=msg-$$
|
||||
dispatch "$M" "isep-hand" "inkstone/ISEP#101"
|
||||
MSG=$(printf '%s' "{\"session_id\":\"$M\",\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(jq_cmd 'python3 scripts/ticket say inkstone/ISEP#202 -F /tmp/r.md')}}" | bash "$GUARD" 2>&1 1>/dev/null)
|
||||
chk_msg(){ if printf '%s' "$MSG" | grep -qF "$1"; then PASS=$((PASS+1)); echo " ✅ 訊息含:$1"; else FAIL=$((FAIL+1)); echo " ❌ 訊息缺:$1"; fi; }
|
||||
chk_msg "isep-hand 被派的是 inkstone/ISEP#101"
|
||||
chk_msg "inkstone/ISEP#202"
|
||||
chk_msg "重下一次一模一樣的指令就會過"
|
||||
chk_msg "report-match-ok"
|
||||
|
||||
echo
|
||||
echo "════════════════════════════════════════"
|
||||
echo "$PASS 通過 / $FAIL 失敗"
|
||||
[ "$FAIL" = 0 ]
|
||||
Reference in New Issue
Block a user