teamsmith 0.1.2 → 0.3.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 +13 -7
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +67 -0
- package/skills/teamsmith/SKILL.md +26 -8
- package/skills/teamsmith/extension/team-notify.ts +37 -6
- package/skills/teamsmith/extension/team.ts +438 -0
- package/skills/teamsmith/references/agent-adapters.md +7 -7
- package/skills/teamsmith/references/config.md +65 -18
- package/skills/teamsmith/references/migration.md +220 -34
- package/skills/teamsmith/references/protocol.md +250 -25
- package/skills/teamsmith/references/troubleshooting.md +124 -7
- package/skills/teamsmith/references/workflows.md +66 -20
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +525 -90
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +71 -10
- package/skills/teamsmith/scripts/lib/cmd-config.sh +562 -128
- package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
- package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
- package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
- package/skills/teamsmith/scripts/lib/cmd-project.sh +149 -105
- package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +188 -40
- package/skills/teamsmith/scripts/lib/cmd-status.sh +268 -30
- package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +634 -54
- package/skills/teamsmith/scripts/lib/common.sh +1560 -109
- package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
- package/skills/teamsmith/scripts/monitor.mjs +34 -3
- package/skills/teamsmith/scripts/panel/README.md +22 -11
- package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
- package/skills/teamsmith/scripts/panel/panel.js +226 -224
- package/skills/teamsmith/scripts/panel/src/App.tsx +478 -184
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
- package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
- package/skills/teamsmith/scripts/panel/src/data.ts +95 -7
- package/skills/teamsmith/scripts/panel/src/layout.ts +703 -152
- package/skills/teamsmith/scripts/panel/src/main.tsx +129 -19
- package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +76 -31
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +78 -33
- package/skills/teamsmith/scripts/panel/src/types.ts +204 -17
- package/skills/teamsmith/scripts/replies.mjs +896 -0
- package/skills/teamsmith/scripts/shim/tmux +18 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
- package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
- package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
- package/skills/teamsmith/scripts/team +20 -6
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +23 -3
- package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
- package/skills/teamsmith/templates/config.sh.tmpl +29 -5
- package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +41 -1
- package/skills/teamsmith/templates/report.md.tmpl +12 -0
- package/skills/teamsmith/templates/task.md.tmpl +4 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
- package/skills/teamsmith/tests/bg-ledger.sh +168 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
- package/skills/teamsmith/tests/config-cli.sh +320 -300
- package/skills/teamsmith/tests/death-cause.sh +5 -2
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
- package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
- package/skills/teamsmith/tests/flip-m33.sh +5 -3
- package/skills/teamsmith/tests/flip-m37.sh +4 -1
- package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
- package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
- package/skills/teamsmith/tests/flip-p158.sh +2 -1
- package/skills/teamsmith/tests/flip-p210.sh +4 -1
- package/skills/teamsmith/tests/flip-p217.sh +4 -1
- package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
- package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
- package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
- package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
- package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
- package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
- package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
- package/skills/teamsmith/tests/help-surface.sh +1664 -0
- package/skills/teamsmith/tests/install-shape.sh +283 -22
- package/skills/teamsmith/tests/key-replies-pty.sh +374 -0
- package/skills/teamsmith/tests/key-replies-ui.sh +325 -0
- package/skills/teamsmith/tests/key-replies.sh +1314 -0
- package/skills/teamsmith/tests/ledger-ban.sh +9 -8
- package/skills/teamsmith/tests/ledger-claim.sh +248 -0
- package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
- package/skills/teamsmith/tests/lib/model-policy.sh +30 -0
- package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
- package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +187 -0
- package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
- package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +367 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
- package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
- package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
- package/skills/teamsmith/tests/lib/tmux-iso.sh +39 -13
- package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
- package/skills/teamsmith/tests/panel-b2.sh +107 -4
- package/skills/teamsmith/tests/panel-b3-stub.sh +139 -4
- package/skills/teamsmith/tests/panel-b3.sh +189 -29
- package/skills/teamsmith/tests/panel-choices.sh +81 -63
- package/skills/teamsmith/tests/panel-cpu.sh +3 -2
- package/skills/teamsmith/tests/panel-knobs.sh +7 -1
- package/skills/teamsmith/tests/panel-p21.sh +445 -241
- package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
- package/skills/teamsmith/tests/panel-strings.mjs +33 -18
- package/skills/teamsmith/tests/perf.sh +122 -31
- package/skills/teamsmith/tests/pm-box-real.sh +1 -1
- package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
- package/skills/teamsmith/tests/routes.sh +364 -109
- package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
- package/skills/teamsmith/tests/seat-visibility.sh +675 -0
- package/skills/teamsmith/tests/section-budgets.tsv +26 -12
- package/skills/teamsmith/tests/section-guard.sh +6 -1
- package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
- package/skills/teamsmith/tests/section-paths.tsv +42 -26
- package/skills/teamsmith/tests/section-select.sh +90 -7
- package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
- package/skills/teamsmith/tests/slash-team.sh +617 -0
- package/skills/teamsmith/tests/smoke.sh +3762 -628
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
- package/skills/teamsmith/tests/task-header-model.sh +2 -1
- package/skills/teamsmith/tests/task-model-routing.sh +1511 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
- package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
- package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
- package/skills/teamsmith-init/SKILL.md +43 -43
- package/skills/teamsmith-init/references/bootstrap.md +8 -6
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* 输出:每个用例一行 `BG-CASE PASS|FAIL <name> [:: detail]`;任一 FAIL → 退出码 1。
|
|
18
18
|
*/
|
|
19
19
|
import { execFileSync, spawn } from 'node:child_process'
|
|
20
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
20
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
21
21
|
import { dirname, join, resolve } from 'node:path'
|
|
22
22
|
|
|
23
23
|
// ── 参数与身份隔离 ─────────────────────────────────────────────────────────────
|
|
@@ -39,8 +39,8 @@ if (!ROOT || !existsSync(join(ROOT, '.pi/team/config.sh'))) {
|
|
|
39
39
|
console.error('bg-ledger-harness: --root <夹具仓库> 是必需的(它必须带 .pi/team/config.sh)')
|
|
40
40
|
process.exit(2)
|
|
41
41
|
}
|
|
42
|
-
if ((GROUPS.has('suspend-shape') || GROUPS.has('owner-scope')) && NOTIFY === '-') {
|
|
43
|
-
console.error('bg-ledger-harness: suspend-shape / owner-scope 需要 --notify <extension/team-notify.ts>')
|
|
42
|
+
if ((GROUPS.has('suspend-shape') || GROUPS.has('owner-scope') || GROUPS.has('merge') || GROUPS.has('detail') || GROUPS.has('wake')) && NOTIFY === '-') {
|
|
43
|
+
console.error('bg-ledger-harness: suspend-shape / owner-scope / merge / detail / wake 需要 --notify <extension/team-notify.ts>')
|
|
44
44
|
process.exit(2)
|
|
45
45
|
}
|
|
46
46
|
for (const key of Object.keys(process.env)) {
|
|
@@ -130,7 +130,7 @@ const makeBase = (name, { ownConfigInWorktree = false, seats = ['dev'] } = {}) =
|
|
|
130
130
|
mkdirSync(join(base, 'docs/team/inbox'), { recursive: true })
|
|
131
131
|
writeFileSync(join(base, '.pi/team/config.sh'),
|
|
132
132
|
`TEAM_PROJECT="bg-ledger-${name}"\nTEAM_AGENTS="${seats.join(' ')}"\nTEAM_WORKTREES_DIR=".worktrees"\n` +
|
|
133
|
-
`TEAM_NOTIFY_LOG="${base}/.pi/team/state/notify.log"\n`)
|
|
133
|
+
`TEAM_NOTIFY_LOG="${base}/.pi/team/state/notify-ext.log"\n`)
|
|
134
134
|
writeFileSync(join(base, 'README.md'), `# bg-ledger fixture ${name}\n`)
|
|
135
135
|
git(['init', '-q', '-b', 'main'], base)
|
|
136
136
|
git(['add', 'README.md'], base)
|
|
@@ -221,42 +221,8 @@ const groupWording = async () => {
|
|
|
221
221
|
'team_bg_run.start-result': receipt.text,
|
|
222
222
|
'team_bg_wait.description': String(host.tools.team_bg_wait?.description ?? ''),
|
|
223
223
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const hasBlocked = t => /blocks your immediate next step/i.test(t)
|
|
227
|
-
const hasExclusive = t => /no other task work/i.test(t)
|
|
228
|
-
const hasException = t => /bounded exception/i.test(t) && hasBudget(t) && hasBlocked(t) && hasExclusive(t)
|
|
229
|
-
|
|
230
|
-
check('wording: team_bg_run description presents the suspend default',
|
|
231
|
-
hasDefault(texts['team_bg_run.description']), texts['team_bg_run.description'].slice(0, 90))
|
|
232
|
-
check('wording: team_bg_run prompt snippet presents the suspend default',
|
|
233
|
-
hasDefault(texts['team_bg_run.promptSnippet']), texts['team_bg_run.promptSnippet'].slice(0, 90))
|
|
234
|
-
check('wording: team_bg_run guidelines present the suspend default and the bounded exception',
|
|
235
|
-
hasDefault(texts['team_bg_run.promptGuidelines']) && hasException(texts['team_bg_run.promptGuidelines']),
|
|
236
|
-
texts['team_bg_run.promptGuidelines'].slice(0, 120))
|
|
237
|
-
check('wording: the start result presents the suspend default and the bounded exception',
|
|
238
|
-
hasDefault(texts['team_bg_run.start-result']) && hasException(texts['team_bg_run.start-result']),
|
|
239
|
-
texts['team_bg_run.start-result'].split('\n').at(-1)?.slice(0, 120) ?? '')
|
|
240
|
-
check('wording: team_bg_wait description names the three exception conditions and the budget',
|
|
241
|
-
hasDefault(texts['team_bg_wait.description']) && hasException(texts['team_bg_wait.description']),
|
|
242
|
-
texts['team_bg_wait.description'].slice(0, 120))
|
|
243
|
-
|
|
244
|
-
// 旧措辞零命中:两个被点名的退休句 + 更宽的「回合结束前必须收割」与「叫醒=损失」形状。
|
|
245
|
-
const retired = [
|
|
246
|
-
'Harvest it with team_bg_wait before you end your turn',
|
|
247
|
-
'harvest every job with team_bg_wait before ending your turn',
|
|
248
|
-
'before you end your turn',
|
|
249
|
-
'before ending your turn',
|
|
250
|
-
'must not end with unharvested',
|
|
251
|
-
'costs a turn',
|
|
252
|
-
]
|
|
253
|
-
const offenders = []
|
|
254
|
-
for (const [name, text] of Object.entries(texts)) {
|
|
255
|
-
for (const phrase of retired) if (text.includes(phrase)) offenders.push(`${name} :: ${phrase}`)
|
|
256
|
-
if (/\b(cost|penalt|loss|waste)/i.test(text)) offenders.push(`${name} :: loss framing`)
|
|
257
|
-
}
|
|
258
|
-
check('wording: the retired duty wording is gone from every registered text',
|
|
259
|
-
offenders.length === 0, offenders.join(' | ') || 'clean')
|
|
224
|
+
|
|
225
|
+
|
|
260
226
|
|
|
261
227
|
// 完成叫醒:多条合并成一条、点名每个 id、指 team_bg_wait(既有行为,钉住)。
|
|
262
228
|
// 先把回执作业收割掉(否则它会带着自己的叫醒混进下面那条合并消息的窗口)。
|
|
@@ -668,6 +634,461 @@ const groupOwnerScope = async () => {
|
|
|
668
634
|
await bgHost.emit('session_shutdown', { reason: 'fixture' }, { cwd: ROOT })
|
|
669
635
|
}
|
|
670
636
|
|
|
637
|
+
// ── turn-notice-merge(merge / detail / wake):写入侧合并 + 明细 + 叫醒 ──────────────
|
|
638
|
+
// 夹具驱动**真扩展 + 真 CLI**:扩展调 CLI 的 __inbox-write(per-recipient 锁 + 先明细后合并),
|
|
639
|
+
// harness 读收件箱 / state/notify.log / outbox 断言合同。CLI 路径从 --notify 派生:
|
|
640
|
+
// <notify 的父目录>/../scripts/team —— 所以变异树($MUT/<tag>/{extension,scripts})能同时破坏扩展
|
|
641
|
+
// 与 CLI,而不会因为 skillDir() 找不到 CLI 变成假红。
|
|
642
|
+
const CLI = () => {
|
|
643
|
+
const explicit = opt('cli')
|
|
644
|
+
return explicit ? resolve(explicit) : resolve(dirname(NOTIFY), '..', 'scripts', 'team')
|
|
645
|
+
}
|
|
646
|
+
const runCliRaw = (base, args) => execFileSync('bash', [CLI(), '--root', base, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
|
|
647
|
+
const runCliRc = (base, args) => {
|
|
648
|
+
try { return { rc: 0, out: runCliRaw(base, args) } }
|
|
649
|
+
catch (error) { return { rc: typeof error?.status === 'number' ? error.status : 1, out: `${error?.stdout ?? ''}${error?.stderr ?? ''}` } }
|
|
650
|
+
}
|
|
651
|
+
const inboxAll = (base, agent = 'dev') => {
|
|
652
|
+
const f = join(base, 'docs/team/inbox', `${agent}.md`)
|
|
653
|
+
return existsSync(f) && !lstatSync(f).isDirectory() ? readFileSync(f, 'utf8').split('\n').filter(Boolean) : []
|
|
654
|
+
}
|
|
655
|
+
const detailFileOf = base => join(base, '.pi/team/state/notify.log')
|
|
656
|
+
const detailRaw = base => {
|
|
657
|
+
const f = detailFileOf(base)
|
|
658
|
+
return existsSync(f) && !lstatSync(f).isDirectory() ? readFileSync(f, 'utf8') : ''
|
|
659
|
+
}
|
|
660
|
+
const detailEventCount = text => text.split('\n').filter(l => l.startsWith('- ')).length
|
|
661
|
+
const detailRecs = base => detailRaw(base).split('\n').filter(l => l.startsWith('- '))
|
|
662
|
+
const configAdd = (base, line) => writeFileSync(join(base, '.pi/team/config.sh'), `${line}\n`, { flag: 'a' })
|
|
663
|
+
const extLogOf = base => {
|
|
664
|
+
const f = join(base, '.pi/team/state/notify-ext.log')
|
|
665
|
+
return existsSync(f) && !lstatSync(f).isDirectory() ? readFileSync(f, 'utf8') : ''
|
|
666
|
+
}
|
|
667
|
+
const taskProof = (base, agent, id) => writeFileSync(join(base, '.pi/team/state', `${agent}.env`), `task=${id}\n`)
|
|
668
|
+
const liveRecord = (base, id, cwd) => {
|
|
669
|
+
const child = spawnSleep(30)
|
|
670
|
+
writeRecord(join(base, '.pi/team/state', 'bg'), id, { pid: child.pid, pgid: child.pid, start: procStartTime(child.pid), cwd })
|
|
671
|
+
return child.pid
|
|
672
|
+
}
|
|
673
|
+
const dropRecord = (base, id) => rmSync(join(base, '.pi/team/state', 'bg', `${id}.job`), { force: true })
|
|
674
|
+
const killPid = pid => { try { process.kill(pid, 'SIGKILL') } catch { /* 已经不在了 */ } }
|
|
675
|
+
const tipOfLine = text => /tip=([0-9a-f]+)/.exec(text)?.[1] ?? ''
|
|
676
|
+
const isoOfLine = text => /^- (\S+) /.exec(text)?.[1] ?? ''
|
|
677
|
+
// 敲门的可观察面:① 还在 outbox 里的条目(含 held/);② delivered.log(投递成功后会移出目录)。
|
|
678
|
+
// 只数 knock 的**行身份**(dedup 以 `line|` 开头)的条目 —— 旧键(摘要指纹)在这里则不会被数到。
|
|
679
|
+
const knockEntries = base => {
|
|
680
|
+
const dir = join(base, '.pi/team/state/outbox')
|
|
681
|
+
let n = 0
|
|
682
|
+
const log = join(dir, 'delivered.log')
|
|
683
|
+
if (existsSync(log)) for (const line of readFileSync(log, 'utf8').split('\n')) {
|
|
684
|
+
const f = line.split('\t')
|
|
685
|
+
if ((f[1] ?? '').startsWith('line|')) n++
|
|
686
|
+
}
|
|
687
|
+
const scan = d => {
|
|
688
|
+
if (!existsSync(d)) return
|
|
689
|
+
for (const f of readdirSync(d)) {
|
|
690
|
+
const p = join(d, f)
|
|
691
|
+
let st
|
|
692
|
+
try { st = lstatSync(p) } catch { continue }
|
|
693
|
+
if (st.isDirectory()) { if (f !== 'diagnostics') scan(p); continue }
|
|
694
|
+
if (!f.endsWith('.msg')) continue
|
|
695
|
+
try { if (/^dedup: line\|/m.test(readFileSync(p, 'utf8'))) n++ } catch { /* ignore */ }
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
scan(dir)
|
|
699
|
+
return n
|
|
700
|
+
}
|
|
701
|
+
const inboxNewCount = (base, agent = 'dev') => Number(/新 (\d+) 条/.exec(runCliRaw(base, ['inbox', agent]))?.[1] ?? 0)
|
|
702
|
+
|
|
703
|
+
// ── merge:合并键 / 合并行形状 / 尾行锚 / 既有读者 ─────────────────────────────
|
|
704
|
+
const groupMerge = async () => {
|
|
705
|
+
const notify = await newNotify()
|
|
706
|
+
|
|
707
|
+
// ① 首条事件的行逐字节形状不变;同 run 三条 → 一行 ×3 + 明细三条(首末时间点名首末事件)
|
|
708
|
+
{
|
|
709
|
+
const b = makeBase('merge-run')
|
|
710
|
+
taskProof(b.base, 'dev', 'P230')
|
|
711
|
+
resetNotify(b.base)
|
|
712
|
+
await notify.settle(b.wt, 'stop', 'MERGE-RUN first summary')
|
|
713
|
+
const l1 = inboxAll(b.base)[0] ?? ''
|
|
714
|
+
const shape = new RegExp('^- \\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z (⚠ 未提交 \\d+ 个文件 · )?\\[auto\\] agent:dev · P230 · branch=task/P230-merge-run · uncommitted=\\d+ · unpushed=\\d+(\\(no-upstream\\))? · task=P230 tip=[0-9a-f]{12} :: MERGE-RUN first summary$')
|
|
715
|
+
check('merge: a single-event line keeps today’s shape',
|
|
716
|
+
shape.test(l1) && !l1.includes('×') && !l1.includes('first=') && !l1.includes('last='), l1 || '(no inbox line)')
|
|
717
|
+
await notify.settle(b.wt, 'stop', 'MERGE-RUN second summary')
|
|
718
|
+
await notify.settle(b.wt, 'stop', 'MERGE-RUN third summary')
|
|
719
|
+
const ls = inboxAll(b.base)
|
|
720
|
+
const dl = detailRecs(b.base)
|
|
721
|
+
const line = ls[0] ?? ''
|
|
722
|
+
check('merge: a run of same-key notifications is one line with its window',
|
|
723
|
+
ls.length === 1 && /×3 first=\S+ last=\S+/.test(line) && dl.length === 3 &&
|
|
724
|
+
isoOfLine(line) === isoOfLine(dl[0]) && /last=(\S+)/.exec(line)?.[1] === isoOfLine(dl[2]),
|
|
725
|
+
`lines=${ls.length} detail=${dl.length} :: ${line}`)
|
|
726
|
+
check('merge: the run’s summaries stay readable in the detail file',
|
|
727
|
+
dl.some(r => r.includes('first summary')) && dl.some(r => r.includes('third summary')) && dl.every(r => !r.includes('×') && r.startsWith('- ')),
|
|
728
|
+
dl.join(' | ').slice(0, 200))
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// ② 汇总行取**最后一条**的值(uncommitted/tip/last);取最大值、平均或第一条的值都在这里变红
|
|
732
|
+
{
|
|
733
|
+
const b = makeBase('merge-last')
|
|
734
|
+
taskProof(b.base, 'dev', 'P230')
|
|
735
|
+
resetNotify(b.base)
|
|
736
|
+
for (const f of ['w2.txt', 'w3.txt', 'w4.txt']) writeFileSync(join(b.wt, f), 'x\n')
|
|
737
|
+
await notify.settle(b.wt, 'stop', 'MERGE-LAST one')
|
|
738
|
+
const rec1 = detailRecs(b.base).at(-1) ?? ''
|
|
739
|
+
git(['add', '-A'], b.wt)
|
|
740
|
+
git(['-c', 'user.email=fixture@teamsmith', '-c', 'user.name=fixture', 'commit', '-qm', 'merge-last one'], b.wt)
|
|
741
|
+
writeFileSync(join(b.wt, 'w5.txt'), 'x\n')
|
|
742
|
+
await notify.settle(b.wt, 'stop', 'MERGE-LAST two')
|
|
743
|
+
rmSync(join(b.wt, 'w5.txt'), { force: true })
|
|
744
|
+
await notify.settle(b.wt, 'stop', 'MERGE-LAST three')
|
|
745
|
+
const rec3 = detailRecs(b.base).at(-1) ?? ''
|
|
746
|
+
const line = inboxAll(b.base)[0] ?? ''
|
|
747
|
+
const tip1 = tipOfLine(rec1); const tip3 = tipOfLine(rec3)
|
|
748
|
+
check('merge: the merged line carries the last event’s values',
|
|
749
|
+
tip1 !== '' && tip3 !== '' && tip1 !== tip3 && /uncommitted=0( |·)/.test(line) && line.includes(`tip=${tip3}`) &&
|
|
750
|
+
!line.includes(`tip=${tip1}`) && /last=(\S+)/.exec(line)?.[1] === isoOfLine(rec3) && line.includes('×3'),
|
|
751
|
+
`tip1=${tip1} tip3=${tip3} :: ${line}`)
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// ③ 状态类变化必然新起一行(两个同 awaiting 的 suspended 不跨过 delivered 合并)
|
|
755
|
+
{
|
|
756
|
+
const b = makeBase('merge-class')
|
|
757
|
+
resetNotify(b.base)
|
|
758
|
+
const pA = liveRecord(b.base, 'J1', b.wt)
|
|
759
|
+
await notify.settle(b.wt, 'stop', 'MERGE-CLASS suspended one')
|
|
760
|
+
dropRecord(b.base, 'J1'); killPid(pA)
|
|
761
|
+
await notify.settle(b.wt, 'stop', 'MERGE-CLASS delivered')
|
|
762
|
+
const pB = liveRecord(b.base, 'J1', b.wt)
|
|
763
|
+
await notify.settle(b.wt, 'stop', 'MERGE-CLASS suspended two')
|
|
764
|
+
const ls = inboxAll(b.base)
|
|
765
|
+
check('merge: a state-class change starts a new line',
|
|
766
|
+
ls.length === 3 && ls[0].includes('[auto·suspended]') && ls[0].includes('awaiting=J1') && !ls[0].includes('×') &&
|
|
767
|
+
ls[1].includes('[auto] ') && !ls[1].includes('awaiting=') && !ls[1].includes('×') &&
|
|
768
|
+
ls[2].includes('[auto·suspended]') && ls[2].includes('awaiting=J1') && !ls[2].includes('×'),
|
|
769
|
+
ls.join(' || ').slice(0, 240))
|
|
770
|
+
// 只有类变、awaiting 集合不变:suspended → interrupted 也必须新起一行(键里的类分量单独可观测)
|
|
771
|
+
await notify.settle(b.wt, 'aborted', 'MERGE-CLASS interrupted same job')
|
|
772
|
+
const ls2 = inboxAll(b.base)
|
|
773
|
+
check('merge: a class change with the same awaiting set starts a new line',
|
|
774
|
+
ls2.length === 4 && ls2[3].includes('[auto·interrupted]') && ls2[3].includes('awaiting=J1') && !ls2[3].includes('×'),
|
|
775
|
+
ls2.join(' || ').slice(0, 260))
|
|
776
|
+
killPid(pB); dropRecord(b.base, 'J1')
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// ④ 任务 / awaiting 集合任一变化都新起一行
|
|
780
|
+
{
|
|
781
|
+
const b = makeBase('merge-key')
|
|
782
|
+
taskProof(b.base, 'dev', 'P230')
|
|
783
|
+
resetNotify(b.base)
|
|
784
|
+
const p1 = liveRecord(b.base, 'X1', b.wt)
|
|
785
|
+
await notify.settle(b.wt, 'stop', 'MERGE-KEY awaiting one')
|
|
786
|
+
dropRecord(b.base, 'X1'); killPid(p1)
|
|
787
|
+
const p2 = liveRecord(b.base, 'X2', b.wt)
|
|
788
|
+
await notify.settle(b.wt, 'stop', 'MERGE-KEY awaiting two')
|
|
789
|
+
dropRecord(b.base, 'X2'); killPid(p2)
|
|
790
|
+
const p3 = liveRecord(b.base, 'X3', b.wt)
|
|
791
|
+
git(['checkout', '-q', '-b', 'task/P231-other'], b.wt)
|
|
792
|
+
await notify.settle(b.wt, 'stop', 'MERGE-KEY other task')
|
|
793
|
+
const ls = inboxAll(b.base)
|
|
794
|
+
check('merge: a different task or awaiting set starts a new line',
|
|
795
|
+
ls.length === 3 && ls[0].includes('awaiting=X1') && ls[1].includes('awaiting=X2') && ls[2].includes('awaiting=X3') &&
|
|
796
|
+
ls.every(l => !l.includes('×')), `lines=${ls.length} :: ${ls.join(' || ').slice(0, 200)}`)
|
|
797
|
+
killPid(p3); dropRecord(b.base, 'X3')
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ⑤ 跨席位:各写各的文件
|
|
801
|
+
{
|
|
802
|
+
const b = makeBase('merge-seats', { seats: ['dev', 'dev2'] })
|
|
803
|
+
resetNotify(b.base, 'dev'); resetNotify(b.base, 'dev2')
|
|
804
|
+
await notify.settle(b.wt, 'stop', 'MERGE-SEATS dev')
|
|
805
|
+
await notify.settle(b.wts.dev2, 'stop', 'MERGE-SEATS dev2')
|
|
806
|
+
const ld = inboxAll(b.base, 'dev'); const l2 = inboxAll(b.base, 'dev2')
|
|
807
|
+
check('merge: a different seat’s run stays in its own file',
|
|
808
|
+
ld.length === 1 && l2.length === 1 && ld[0].includes('agent:dev ') && !ld[0].includes('agent:dev2') && l2[0].includes('agent:dev2'),
|
|
809
|
+
`dev=[${ld.join('||')}] dev2=[${l2.join('||')}]`)
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// ⑥ awaiting 是集合:夹具预置的反序锚行与扩展的排序结果必须合并
|
|
813
|
+
{
|
|
814
|
+
const b = makeBase('merge-order')
|
|
815
|
+
resetNotify(b.base)
|
|
816
|
+
const pa = liveRecord(b.base, 'aaa', b.wt); const pz = liveRecord(b.base, 'zzz', b.wt)
|
|
817
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD'], b.wt)
|
|
818
|
+
writeFileSync(join(b.base, 'docs/team/inbox/dev.md'),
|
|
819
|
+
`- 2026-10-14T00:00:00Z [auto·suspended] agent:dev · P230 · branch=${branch} · uncommitted=1 · awaiting=zzz,aaa · unpushed=0\n`)
|
|
820
|
+
await notify.settle(b.wt, 'stop', 'MERGE-ORDER second settle')
|
|
821
|
+
const ls = inboxAll(b.base)
|
|
822
|
+
const line = ls[0] ?? ''
|
|
823
|
+
check('merge: the awaiting set’s order does not split a run',
|
|
824
|
+
ls.length === 1 && line.includes('×2') && line.includes('awaiting=aaa,zzz'), line)
|
|
825
|
+
killPid(pa); killPid(pz); dropRecord(b.base, 'aaa'); dropRecord(b.base, 'zzz')
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// ⑦ 中间插入的手工通知结束 run,且本人逐字节不变
|
|
829
|
+
{
|
|
830
|
+
const b = makeBase('merge-break')
|
|
831
|
+
resetNotify(b.base)
|
|
832
|
+
await notify.settle(b.wt, 'stop', 'MERGE-BREAK one')
|
|
833
|
+
const before = inboxAll(b.base)[0] ?? ''
|
|
834
|
+
runCliRc(b.base, ['notify', 'dev', 'MERGE-BREAK manual notice'])
|
|
835
|
+
const manual = inboxAll(b.base).at(-1) ?? ''
|
|
836
|
+
await notify.settle(b.wt, 'stop', 'MERGE-BREAK two')
|
|
837
|
+
const ls = inboxAll(b.base)
|
|
838
|
+
check('merge: a notice appended between two events ends the run untouched',
|
|
839
|
+
ls.length === 3 && ls[0] === before && ls[1] === manual && ls[1].includes('[manual]') &&
|
|
840
|
+
ls[1].includes('MERGE-BREAK manual notice') && ls[2].includes('MERGE-BREAK two') && !ls[2].includes('×'),
|
|
841
|
+
ls.join(' || ').slice(0, 240))
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// ⑧ 去重窗口内的重复 settle 既不进明细也不推 ×N
|
|
845
|
+
{
|
|
846
|
+
const b = makeBase('merge-dedup')
|
|
847
|
+
resetNotify(b.base)
|
|
848
|
+
await notify.settle(b.wt, 'stop', 'MERGE-DEDUP same text')
|
|
849
|
+
await notify.settle(b.wt, 'stop', 'MERGE-DEDUP same text')
|
|
850
|
+
const ls = inboxAll(b.base); const dl = detailRecs(b.base)
|
|
851
|
+
check('merge: a settle inside the dedup window neither counts nor records',
|
|
852
|
+
ls.length === 1 && !ls[0].includes('×') && dl.length === 1, `lines=${ls.length} detail=${dl.length}`)
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// ⑨ 行计数读者:合并行算一行;被后续事件扩展后仍是已读
|
|
856
|
+
{
|
|
857
|
+
const b = makeBase('merge-readers')
|
|
858
|
+
resetNotify(b.base)
|
|
859
|
+
for (const t of ['one', 'two', 'three']) await notify.settle(b.wt, 'stop', `MERGE-READERS ${t}`)
|
|
860
|
+
const before = inboxNewCount(b.base)
|
|
861
|
+
runCliRc(b.base, ['inbox', 'dev', '--ack'])
|
|
862
|
+
await notify.settle(b.wt, 'stop', 'MERGE-READERS four')
|
|
863
|
+
const after = inboxNewCount(b.base)
|
|
864
|
+
check('merge: line-counting readers count a merged line once',
|
|
865
|
+
before === 1 && after === 0 && /×4/.test(inboxAll(b.base)[0] ?? ''),
|
|
866
|
+
`before=${before} after=${after} :: ${inboxAll(b.base)[0] ?? ''}`)
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// ⑩ 陈旧判据在合并行上读最后一条的 tip(更早的事件从明细里判)
|
|
870
|
+
{
|
|
871
|
+
const b = makeBase('merge-stale')
|
|
872
|
+
taskProof(b.base, 'dev', 'P230')
|
|
873
|
+
resetNotify(b.base)
|
|
874
|
+
await notify.settle(b.wt, 'stop', 'MERGE-STALE one')
|
|
875
|
+
const tip1 = tipOfLine(detailRecs(b.base).at(-1) ?? '')
|
|
876
|
+
git(['add', '-A'], b.wt)
|
|
877
|
+
git(['-c', 'user.email=fixture@teamsmith', '-c', 'user.name=fixture', 'commit', '-qm', 'merge-stale one'], b.wt)
|
|
878
|
+
await notify.settle(b.wt, 'stop', 'MERGE-STALE two')
|
|
879
|
+
const tip2 = tipOfLine(detailRecs(b.base).at(-1) ?? '')
|
|
880
|
+
const line = inboxAll(b.base)[0] ?? ''
|
|
881
|
+
mkdirSync(join(b.base, 'docs/team/reviews'), { recursive: true })
|
|
882
|
+
writeFileSync(join(b.base, 'docs/team/reviews/P230.md'), `# P230\n\n- HEAD ${tip1}\n`)
|
|
883
|
+
const reviewed = new RegExp(tip1).test(readFileSync(join(b.base, 'docs/team/reviews/P230.md'), 'utf8'))
|
|
884
|
+
const judged = t => tip1.startsWith(t) || t.startsWith(tip1)
|
|
885
|
+
check('merge: a merged line is judged by its last event, not as current state',
|
|
886
|
+
/×2/.test(line) && tip1 !== tip2 && line.includes(`tip=${tip2}`) && !judged(tip2) && judged(tip1) && reviewed,
|
|
887
|
+
`tip1=${tip1} tip2=${tip2} :: ${line}`)
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// ── detail:明细文件 / 轮转 / 读面缺口 ────────────────────────────────────────
|
|
892
|
+
const groupDetail = async () => {
|
|
893
|
+
const notify = await newNotify()
|
|
894
|
+
|
|
895
|
+
// ① 计数与记录一致;② 明细不是流量(记录不写收件箱行、不入队 knock)
|
|
896
|
+
{
|
|
897
|
+
const b = makeBase('detail-agree')
|
|
898
|
+
resetNotify(b.base)
|
|
899
|
+
await notify.settle(b.wt, 'stop', 'DETAIL one')
|
|
900
|
+
await notify.settle(b.wt, 'stop', 'DETAIL two')
|
|
901
|
+
await notify.settle(b.wt, 'stop', 'DETAIL three')
|
|
902
|
+
const dl = detailRecs(b.base)
|
|
903
|
+
const out = runCliRc(b.base, ['inbox', 'dev', '--detail']).out
|
|
904
|
+
check('detail: a run’s count and its records agree',
|
|
905
|
+
/×3/.test(inboxAll(b.base)[0] ?? '') && dl.length === 3 && /记录 3\/3 OK/.test(out),
|
|
906
|
+
`recs=${dl.length} out=${out.split('\n').slice(0, 3).join(' / ')}`)
|
|
907
|
+
check('detail: the detail file is not traffic',
|
|
908
|
+
inboxAll(b.base).length === 1 && knockEntries(b.base) === 0,
|
|
909
|
+
`lines=${inboxAll(b.base).length} knocks=${knockEntries(b.base)}`)
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// ③ 轮转:搬走一代 + 新代轮转头(时间 / state/notify.log.1 / 事件数)+ 扩展日志点名
|
|
913
|
+
{
|
|
914
|
+
const b = makeBase('detail-rotate')
|
|
915
|
+
configAdd(b.base, 'TEAM_NOTIFY_DETAIL_MAX=2')
|
|
916
|
+
resetNotify(b.base)
|
|
917
|
+
for (const t of ['one', 'two', 'three']) await notify.settle(b.wt, 'stop', `ROTATE ${t}`)
|
|
918
|
+
const cur = detailRaw(b.base)
|
|
919
|
+
const rotated = existsSync(`${detailFileOf(b.base)}.1`) ? readFileSync(`${detailFileOf(b.base)}.1`, 'utf8') : ''
|
|
920
|
+
const log = existsSync(join(b.base, '.pi/team/state/notify-ext.log')) ? readFileSync(join(b.base, '.pi/team/state/notify-ext.log'), 'utf8') : ''
|
|
921
|
+
check('detail: a rotated generation names where the older events went',
|
|
922
|
+
/^# rotation \S+ moved=2 /.test(cur) && cur.includes('state/notify.log.1') && detailEventCount(cur) <= 2 && detailEventCount(rotated) === 2 && /rotated/.test(log),
|
|
923
|
+
`head=${cur.split('\n')[0] ?? ''} curEvents=${detailEventCount(cur)} rotEvents=${detailEventCount(rotated)}`)
|
|
924
|
+
for (const t of ['four', 'five', 'six', 'seven']) await notify.settle(b.wt, 'stop', `ROTATE ${t}`)
|
|
925
|
+
const cur2 = detailRaw(b.base)
|
|
926
|
+
check('detail: the bound holds as the file grows',
|
|
927
|
+
detailEventCount(cur2) <= 2 && !existsSync(`${detailFileOf(b.base)}.2`),
|
|
928
|
+
`curEvents=${detailEventCount(cur2)} generations=${existsSync(`${detailFileOf(b.base)}.1`) ? 1 : 0}`)
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// ④ 缺文件:点名 state/notify.log 与 .1,非零退出,不假装完整
|
|
932
|
+
{
|
|
933
|
+
const b = makeBase('detail-missing')
|
|
934
|
+
resetNotify(b.base)
|
|
935
|
+
await notify.settle(b.wt, 'stop', 'GAP one')
|
|
936
|
+
await notify.settle(b.wt, 'stop', 'GAP two')
|
|
937
|
+
rmSync(detailFileOf(b.base), { force: true })
|
|
938
|
+
const r = runCliRc(b.base, ['inbox', 'dev', '--detail'])
|
|
939
|
+
check('detail: a missing record is named, not silent',
|
|
940
|
+
r.rc !== 0 && r.out.includes('state/notify.log') && r.out.includes('state/notify.log.1') && !/记录 2\/2 OK/.test(r.out),
|
|
941
|
+
`rc=${r.rc} :: ${r.out.replace(/\n/g, ' | ').slice(0, 220)}`)
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// ⑤ 轮转后当前代缺记录:点名缺口与 .1,非零退出
|
|
945
|
+
{
|
|
946
|
+
const b = makeBase('detail-rotgap')
|
|
947
|
+
configAdd(b.base, 'TEAM_NOTIFY_DETAIL_MAX=2')
|
|
948
|
+
resetNotify(b.base)
|
|
949
|
+
for (const t of ['one', 'two', 'three']) await notify.settle(b.wt, 'stop', `ROTGAP ${t}`)
|
|
950
|
+
const r = runCliRc(b.base, ['inbox', 'dev', '--detail'])
|
|
951
|
+
check('detail: a rotated run’s gap is named with the older generation',
|
|
952
|
+
r.rc !== 0 && /缺口/.test(r.out) && r.out.includes('state/notify.log.1') && /×3/.test(r.out) && /记录 1\/3/.test(r.out),
|
|
953
|
+
`rc=${r.rc} :: ${r.out.replace(/\n/g, ' | ').slice(0, 240)}`)
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// ⑥ 只读:不 ack、未读数不变
|
|
957
|
+
{
|
|
958
|
+
const b = makeBase('detail-readonly')
|
|
959
|
+
resetNotify(b.base)
|
|
960
|
+
await notify.settle(b.wt, 'stop', 'READONLY one')
|
|
961
|
+
await notify.settle(b.wt, 'stop', 'READONLY two')
|
|
962
|
+
const before = inboxNewCount(b.base)
|
|
963
|
+
// --detail 在有缺口时**按契约非零退出**:夹具用 rc 宽容的调用(否则破坏树会把 harness 自身搞崩)
|
|
964
|
+
runCliRc(b.base, ['inbox', 'dev', '--detail'])
|
|
965
|
+
const after = inboxNewCount(b.base)
|
|
966
|
+
check('detail: detail reading does not acknowledge', before === 1 && after === 1, `before=${before} after=${after}`)
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// ── wake:只有写新行才入队 knock(合并的 settle 不叫醒)──────────────────────
|
|
971
|
+
const groupWake = async () => {
|
|
972
|
+
const notify = await newNotify()
|
|
973
|
+
const prevPane = process.env.TMUX_PANE
|
|
974
|
+
// 敲门要「有 PM 窗口」的形状:TMUX_PANE 在进程内设就够(子进程继承);假 tmux 由 bg-ledger.sh 在
|
|
975
|
+
// **启动 runner 之前**放进 PATH —— bun 在启动时缓存 PATH,运行中改 process.env.PATH 对子进程查找无效。
|
|
976
|
+
process.env.TMUX_PANE = 'p251-fixture-pane'
|
|
977
|
+
try {
|
|
978
|
+
// ① 交付:每个新行恰好一条 knock,同键合并的 settle 零条目
|
|
979
|
+
{
|
|
980
|
+
const b = makeBase('wake-once')
|
|
981
|
+
configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
|
|
982
|
+
resetNotify(b.base)
|
|
983
|
+
await notify.settle(b.wt, 'stop', 'WAKE-ONCE one')
|
|
984
|
+
const k1 = knockEntries(b.base)
|
|
985
|
+
await notify.settle(b.wt, 'stop', 'WAKE-ONCE two')
|
|
986
|
+
const k2 = knockEntries(b.base)
|
|
987
|
+
await notify.settle(b.wt, 'stop', 'WAKE-ONCE three')
|
|
988
|
+
const k3 = knockEntries(b.base)
|
|
989
|
+
check('wake: each new line wakes exactly once', k1 === 1 && k2 === 1 && k3 === 1, `k=${k1},${k2},${k3}`)
|
|
990
|
+
// 合并的 settle 不敲:既不能新增条目(会被 outbox 自己的去重挡住,所以还要看扩展自己的账本)
|
|
991
|
+
// 也不能走「入队」那条路径 —— 扩展日志里必须是 no knock(state=extended),零次 knock queued。
|
|
992
|
+
const log3 = extLogOf(b.base)
|
|
993
|
+
check('wake: a merged settle does not wake again',
|
|
994
|
+
k3 === 1 && /×3/.test(inboxAll(b.base)[0] ?? '') && /no knock \(inbox write state=extended\)/.test(log3),
|
|
995
|
+
`k=${k3} log=${log3.split('\n').filter(Boolean).slice(-3).join(' | ')}`)
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// ② 挂起只记录、不叫醒(用户裁定 2026-10-14):行与明细都在、queue 为空;同键合并也不叫醒
|
|
999
|
+
{
|
|
1000
|
+
const b = makeBase('wake-suspended')
|
|
1001
|
+
configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
|
|
1002
|
+
resetNotify(b.base)
|
|
1003
|
+
const pid = liveRecord(b.base, 'W2', b.wt)
|
|
1004
|
+
await notify.settle(b.wt, 'stop', 'WAKE-SUSPENDED one')
|
|
1005
|
+
const k1 = knockEntries(b.base)
|
|
1006
|
+
const line1 = inboxAll(b.base)[0] ?? ''
|
|
1007
|
+
const rec1 = detailRecs(b.base).length
|
|
1008
|
+
await notify.settle(b.wt, 'stop', 'WAKE-SUSPENDED two')
|
|
1009
|
+
const k2 = knockEntries(b.base)
|
|
1010
|
+
const line2 = inboxAll(b.base)[0] ?? ''
|
|
1011
|
+
const rec2 = detailRecs(b.base).length
|
|
1012
|
+
check('wake: a suspended line never wakes',
|
|
1013
|
+
k1 === 0 && line1.includes('[auto·suspended]') && line1.includes('awaiting=W2') && rec1 === 1,
|
|
1014
|
+
`k=${k1} recs=${rec1} :: ${line1}`)
|
|
1015
|
+
check('wake: a merged suspended run never wakes',
|
|
1016
|
+
k2 === 0 && /×2/.test(line2) && line2.includes('awaiting=W2') && rec2 === 2,
|
|
1017
|
+
`k=${k2} recs=${rec2} :: ${line2}`)
|
|
1018
|
+
killPid(pid); dropRecord(b.base, 'W2')
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// ③ 状态类变化:挂起不叫醒,随后交付 / 中断各叫醒一次
|
|
1022
|
+
{
|
|
1023
|
+
const b = makeBase('wake-class')
|
|
1024
|
+
configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
|
|
1025
|
+
resetNotify(b.base)
|
|
1026
|
+
const pid = liveRecord(b.base, 'W3', b.wt)
|
|
1027
|
+
await notify.settle(b.wt, 'stop', 'WAKE-CLASS suspended')
|
|
1028
|
+
const k0 = knockEntries(b.base)
|
|
1029
|
+
dropRecord(b.base, 'W3'); killPid(pid)
|
|
1030
|
+
await notify.settle(b.wt, 'stop', 'WAKE-CLASS delivered')
|
|
1031
|
+
const k1 = knockEntries(b.base)
|
|
1032
|
+
const pid2 = liveRecord(b.base, 'W3', b.wt)
|
|
1033
|
+
await notify.settle(b.wt, 'aborted', 'WAKE-CLASS interrupted')
|
|
1034
|
+
const k2 = knockEntries(b.base)
|
|
1035
|
+
check('wake: a class change away from suspended wakes once',
|
|
1036
|
+
k0 === 0 && k1 === 1 && k2 === 2,
|
|
1037
|
+
`k=${k0},${k1},${k2} :: ${inboxAll(b.base).map(l => l.slice(0, 60)).join(' || ')}`)
|
|
1038
|
+
killPid(pid2); dropRecord(b.base, 'W3')
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
// ④ 计数抖动不叫醒:先显式清掉上一条 knock(否则 outbox 自己的去重会替实现挡住这条断言)
|
|
1042
|
+
{
|
|
1043
|
+
const b = makeBase('wake-churn')
|
|
1044
|
+
configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
|
|
1045
|
+
resetNotify(b.base)
|
|
1046
|
+
await notify.settle(b.wt, 'stop', 'WAKE-CHURN one')
|
|
1047
|
+
const k1 = knockEntries(b.base)
|
|
1048
|
+
runCliRc(b.base, ['outbox', 'drop', 'all'])
|
|
1049
|
+
const k0 = knockEntries(b.base)
|
|
1050
|
+
await notify.settle(b.wt, 'stop', 'WAKE-CHURN two')
|
|
1051
|
+
await notify.settle(b.wt, 'stop', 'WAKE-CHURN three')
|
|
1052
|
+
const k2 = knockEntries(b.base)
|
|
1053
|
+
check('wake: count churn does not wake',
|
|
1054
|
+
k1 >= 1 && k2 === k0 && /×3/.test(inboxAll(b.base)[0] ?? ''),
|
|
1055
|
+
`afterFirst=${k1} afterDrop=${k0} afterChurn=${k2} lines=${inboxAll(b.base).length}`)
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// ⑤ 两条文本逐字相同的不同行(手工通知打断 + 夹具去掉 settle 去重簿):行身份不互吞。
|
|
1059
|
+
// 不去掉 outbox 的去重窗口(默认 20s):用摘要当键的破坏实现会被它摕下(这正是要红的地方)。
|
|
1060
|
+
// 不去掉 outbox 的去重窗口(默认 20s):用摘要当键的破坏实现会被它摕下(这正是要红的地方)。
|
|
1061
|
+
{
|
|
1062
|
+
const b = makeBase('wake-identity')
|
|
1063
|
+
resetNotify(b.base)
|
|
1064
|
+
await notify.settle(b.wt, 'stop', 'WAKE-IDENTICAL text')
|
|
1065
|
+
runCliRc(b.base, ['notify', 'dev', 'WAKE-IDENTICAL break'])
|
|
1066
|
+
rmSync(join(b.base, '.pi/team/state/notify-dedup'), { force: true })
|
|
1067
|
+
await notify.settle(b.wt, 'stop', 'WAKE-IDENTICAL text')
|
|
1068
|
+
const ls = inboxAll(b.base)
|
|
1069
|
+
const stripped = l => l.replace(/^- \S+ /, '')
|
|
1070
|
+
check('wake: two text-identical lines are not conflated',
|
|
1071
|
+
ls.length === 3 && knockEntries(b.base) === 2 && ls[0] !== ls[2] && stripped(ls[0]) === stripped(ls[2]),
|
|
1072
|
+
`lines=${ls.length} knocks=${knockEntries(b.base)} :: ${ls.join(' || ').slice(0, 200)}`)
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// ⑥ 写盘失败不叫醒(收件箱路径是个目录 → 追加必败)
|
|
1076
|
+
{
|
|
1077
|
+
const b = makeBase('wake-writefail')
|
|
1078
|
+
resetNotify(b.base)
|
|
1079
|
+
rmSync(join(b.base, 'docs/team/inbox/dev.md'), { force: true })
|
|
1080
|
+
mkdirSync(join(b.base, 'docs/team/inbox/dev.md'), { recursive: true })
|
|
1081
|
+
await notify.settle(b.wt, 'stop', 'WAKE-WRITEFAIL must not wake')
|
|
1082
|
+
const k = knockEntries(b.base)
|
|
1083
|
+
rmSync(join(b.base, 'docs/team/inbox/dev.md'), { recursive: true, force: true })
|
|
1084
|
+
check('wake: a failed inbox write does not wake', k === 0, `knocks=${k}`)
|
|
1085
|
+
}
|
|
1086
|
+
} finally {
|
|
1087
|
+
if (prevPane === undefined) delete process.env.TMUX_PANE
|
|
1088
|
+
else process.env.TMUX_PANE = prevPane
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
671
1092
|
// ── 主流程 ────────────────────────────────────────────────────────────────────
|
|
672
1093
|
console.log(`bg-ledger-harness · root=${ROOT} · groups=${[...GROUPS].join(',')} · bg=${BG} · notify=${NOTIFY}`)
|
|
673
1094
|
try {
|
|
@@ -675,6 +1096,9 @@ try {
|
|
|
675
1096
|
if (GROUPS.has('ledger')) await groupLedger()
|
|
676
1097
|
if (GROUPS.has('suspend-shape')) await groupSuspendShape()
|
|
677
1098
|
if (GROUPS.has('owner-scope')) await groupOwnerScope()
|
|
1099
|
+
if (GROUPS.has('merge')) await groupMerge()
|
|
1100
|
+
if (GROUPS.has('detail')) await groupDetail()
|
|
1101
|
+
if (GROUPS.has('wake')) await groupWake()
|
|
678
1102
|
} catch (error) {
|
|
679
1103
|
check('harness: no unexpected exception', false, String(error?.stack ?? error).split('\n').slice(0, 3).join(' / '))
|
|
680
1104
|
}
|