teamsmith 0.4.7 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +11 -0
  4. package/skills/teamsmith/SKILL.md +12 -8
  5. package/skills/teamsmith/references/config.md +11 -12
  6. package/skills/teamsmith/scripts/lib/cmd-review.sh +21 -33
  7. package/skills/teamsmith/scripts/lib/common.sh +1 -1
  8. package/skills/teamsmith/scripts/panel/README.md +35 -33
  9. package/skills/teamsmith/scripts/panel/panel.js +217 -199
  10. package/skills/teamsmith/scripts/panel/src/App.tsx +221 -66
  11. package/skills/teamsmith/scripts/panel/src/layout.ts +139 -302
  12. package/skills/teamsmith/scripts/panel/src/project-settings.ts +46 -0
  13. package/skills/teamsmith/scripts/panel/src/strings/en.ts +71 -205
  14. package/skills/teamsmith/scripts/panel/src/strings/index.ts +3 -5
  15. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +72 -204
  16. package/skills/teamsmith/scripts/panel/src/types.ts +23 -4
  17. package/skills/teamsmith/scripts/strings/commands.tsv +1 -1
  18. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +7 -0
  19. package/skills/teamsmith/templates/pm-prompt.md.tmpl +10 -6
  20. package/skills/teamsmith/tests/help-surface.sh +75 -7
  21. package/skills/teamsmith/tests/install-shape.sh +7 -7
  22. package/skills/teamsmith/tests/key-replies-ui.sh +11 -5
  23. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +2 -0
  24. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +255 -90
  25. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +181 -61
  26. package/skills/teamsmith/tests/lib/model-routing-roles.sh +125 -67
  27. package/skills/teamsmith/tests/lib/reply-fixture.sh +14 -9
  28. package/skills/teamsmith/tests/lib/tmp-root.sh +1 -1
  29. package/skills/teamsmith/tests/loop-inventory.tsv +2 -0
  30. package/skills/teamsmith/tests/panel-b2.sh +91 -31
  31. package/skills/teamsmith/tests/panel-p21.sh +607 -1162
  32. package/skills/teamsmith/tests/panel-strings.mjs +21 -113
  33. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +65 -38
  34. package/skills/teamsmith/tests/remind-adversarial-faults.sh +64 -12
  35. package/skills/teamsmith/tests/remind-adversarial-real.sh +13 -12
  36. package/skills/teamsmith/tests/remind-tool-real.mjs +159 -112
  37. package/skills/teamsmith/tests/remind-tool-real.sh +178 -3
  38. package/skills/teamsmith/tests/section-paths.tsv +10 -10
  39. package/skills/teamsmith/tests/smoke.sh +108 -114
  40. package/skills/teamsmith/tests/task-model-routing.sh +57 -26
  41. package/skills/teamsmith/tests/tmp-hygiene.sh +1 -1
  42. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -2,24 +2,52 @@
2
2
  // P442 private real Pi + private tmux + controlled loopback provider. No live team, credentials or model.
3
3
  import assert from 'node:assert/strict'
4
4
  import { createServer } from 'node:http'
5
- import { spawnSync } from 'node:child_process'
6
- import { appendFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
7
- import { dirname, join, resolve } from 'node:path'
5
+ import { spawn, spawnSync } from 'node:child_process'
6
+ import { once } from 'node:events'
7
+ import { appendFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
8
+ import { constants } from 'node:os'
9
+ import { dirname, join } from 'node:path'
8
10
  import { fileURLToPath } from 'node:url'
9
- import { setTimeout as delay } from 'node:timers/promises'
11
+ import { setImmediate as immediate, setTimeout as delay } from 'node:timers/promises'
10
12
 
11
13
  const tests = dirname(fileURLToPath(import.meta.url)), skill = dirname(tests)
14
+ // Direct Node calls (including the recovery entry) use the same owner as the shell.
15
+ if (!process.env._P442_WORK) {
16
+ const owner = spawn('bash', [join(tests, 'remind-tool-real.sh'), ...process.argv.slice(2)], {
17
+ env: { ...process.env, _P442_NODE: process.execPath }, stdio: 'inherit',
18
+ })
19
+ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => owner.kill(signal))
20
+ const [code, signal] = await once(owner, 'exit')
21
+ process.exit(code ?? 128 + constants.signals[signal])
22
+ }
23
+
24
+ let stopSignal
25
+ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { stopSignal ??= signal })
26
+ function checkStop() {
27
+ if (stopSignal) process.exit(128 + constants.signals[stopSignal])
28
+ }
29
+ async function stopPoint() {
30
+ // Cross a poll turn even if the command returned in an I/O callback before this turn's check phase.
31
+ await immediate()
32
+ await immediate()
33
+ checkStop()
34
+ }
35
+ async function runSync(bin, args, options) {
36
+ checkStop()
37
+ try { return spawnSync(bin, args, options) }
38
+ finally { await stopPoint() }
39
+ }
40
+
12
41
  const selection = (process.argv.find(a => a.startsWith('--select='))?.slice(9) ?? 'pm,large,identity,doctor').split(',')
13
- const evidence = resolve(process.env.P442_EVIDENCE ?? `/var/tmp/p442-real-evidence-${Date.now()}`)
14
- mkdirSync(evidence, { recursive: true, mode: 0o700 })
15
- const temporary = mkdtempSync('/var/tmp/p442-real-'), socket = join(temporary, 'socket')
16
- const pi = process.env.P442_PI ?? `${process.env.HOME}/.bun/bin/pi`, bunbin = dirname(pi)
42
+ const { _P442_WORK: temporary, _P442_EVIDENCE: evidence, _P442_SOCKET: socket, _P442_PATH: privatePath,
43
+ _P442_PI: pi, _P442_SCENES: launchedScenes } = process.env
44
+ console.log(`remind-tool-real: pi=${pi}`)
17
45
  mkdirSync(join(temporary, 'driver-home'))
18
- const base = { HOME: join(temporary, 'driver-home'), PATH: `${bunbin}:/usr/local/bin:/usr/bin:/bin`, LANG: 'C.UTF-8',
46
+ const base = { HOME: join(temporary, 'driver-home'), PATH: privatePath, LANG: 'C.UTF-8',
19
47
  TERM: 'xterm-256color', USER: process.env.USER ?? 'fixture', LOGNAME: process.env.LOGNAME ?? 'fixture', TMPDIR: temporary }
20
48
  const sh = value => `'${value.replaceAll("'", "'\\''")}'`
21
- function command(bin, args, options = {}) {
22
- const result = spawnSync(bin, args, { encoding: 'utf8', env: base, ...options })
49
+ async function command(bin, args, options = {}) {
50
+ const result = await runSync(bin, args, { encoding: 'utf8', env: base, ...options })
23
51
  assert.equal(result.error, undefined, `${bin}: ${result.error}`)
24
52
  assert.equal(result.status, 0, `${bin} ${args.join(' ')}: ${result.stderr}\n${result.stdout}`)
25
53
  return result.stdout
@@ -36,6 +64,7 @@ async function until(test, label) {
36
64
  const end = Date.now() + 90000 // Fixture watchdog, not a product latency claim.
37
65
  let last
38
66
  for (;;) {
67
+ checkStop()
39
68
  try { if (test()) return } catch (e) { last = e } // A snapshot/process may not exist on the first poll.
40
69
  if (Date.now() > end) throw new Error(`watchdog: ${label}: ${last?.message ?? 'condition stayed false'}`)
41
70
  await delay(50)
@@ -57,35 +86,39 @@ server = createServer(async (req, res) => {
57
86
  let raw = ''; for await (const chunk of req) raw += chunk
58
87
  const body = JSON.parse(raw), name = req.url.split('/')[1], plan = plans.get(name)
59
88
  if (!plan) { res.writeHead(404); res.end(); return }
89
+ checkStop()
60
90
  const n = plan.requests++
61
91
  appendFileSync(join(plan.dir, 'requests.jsonl'), JSON.stringify(body) + '\n')
62
92
  if (n === (plan.gateN ?? 0) && plan.gate) await plan.gate
93
+ checkStop()
63
94
  await plan.respond({ body, n, res, plan })
64
95
  })
65
96
  await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
97
+ checkStop()
66
98
  const port = server.address().port
67
- function publishLaunch(info) {
99
+ async function publishLaunch(info) {
68
100
  const source = `source ${sh(join(info.skill, 'scripts/lib/common.sh'))}; source ${sh(join(info.skill, 'scripts/lib/cmd-config.sh'))}; team_load_config; team_pm_metadata_publish p442-${info.name}`
69
- command('bash', ['-c', source], { cwd: info.root, env: info.env })
101
+ await command('bash', ['-c', source], { cwd: info.root, env: info.env })
70
102
  }
71
- function doctor(info) {
72
- const result = spawnSync('bash', [join(info.skill, 'scripts/team'), '--root', info.root, 'doctor'],
103
+ async function doctor(info) {
104
+ const result = await runSync('bash', [join(info.skill, 'scripts/team'), '--root', info.root, 'doctor'],
73
105
  { cwd: info.root, env: { ...info.env, TMUX: `${socket},${info.serverPid},0`, TMUX_PANE: info.pane }, encoding: 'utf8' })
74
106
  const output = result.stdout + result.stderr
75
107
  writeFileSync(join(info.dir, `doctor-${Date.now()}.txt`), output)
76
108
  return output
77
109
  }
78
110
  async function start(name, respond, opts = {}) {
111
+ checkStop()
79
112
  const dir = join(evidence, name), root = join(temporary, name), home = join(root, 'home'), state = join(root, '.pi/team/state'), config = join(root, '.pi/team/config.sh')
80
113
  for (const path of [dir, home, join(home, '.pi/agent')]) mkdirSync(path, { recursive: true })
81
114
  const runSkill = opts.skillCopy ? join(root, 'skill') : skill
82
115
  if (opts.skillCopy) cpSync(skill, runSkill, { recursive: true })
83
116
  if (opts.mutate) opts.mutate(runSkill)
84
117
  writeFileSync(join(home, '.pi/agent/settings.json'), JSON.stringify({ retry: { enabled: false }, compaction: { enabled: false } }))
85
- command('git', ['init', '-q', '-b', 'main'], { cwd: root })
118
+ await command('git', ['init', '-q', '-b', 'main'], { cwd: root })
86
119
  const session = `p442-${name}`, fixture = join(tests, 'fixtures/remind-tool-provider.ts')
87
120
  const extra = `--offline --no-extensions --no-skills --no-context-files -e ${sh(fixture)}`
88
- command('bash', [join(skill, 'scripts/team'), 'init', '--no-skills', '--session', session,
121
+ await command('bash', [join(skill, 'scripts/team'), 'init', '--no-skills', '--session', session,
89
122
  '--agents', 'dev', '--vcs', 'local', '--gates', 'true', '--pm-model', 'p442/controlled',
90
123
  '--task-models', 'routine=p442/controlled analysis=p442/controlled verify=p442/controlled code=p442/controlled'], { cwd: root, env: base })
91
124
  writeFileSync(join(dir, 'config.generated.sh'), readFileSync(config))
@@ -94,19 +127,23 @@ async function start(name, respond, opts = {}) {
94
127
  const env = { ...base, HOME: home, PI_CODING_AGENT_DIR: join(home, '.pi/agent'), P442_EVIDENCE: dir,
95
128
  P442_ENDPOINT: `http://127.0.0.1:${port}/${name}/v1`, TEAM_REMIND_POLL_MS: '200',
96
129
  TEAM_PI_BIN: pi, TEAM_PM_EXTRA_PI_ARGS: extra, ...(opts.env ?? {}) }
97
- const info = { name, dir, root, home, state, config, session, env, skill: runSkill, pane: '', done: join(dir, 'done') }
130
+ const manualLaunch = ['ordinary', 'worker'].includes(opts.invalid)
131
+ const receiptPath = manualLaunch ? 'home/.fixture-pi.pid' : '.pi/team/state/pm.pid.spawn'
132
+ const spawnReceipt = join(root, receiptPath)
133
+ const info = { name, dir, root, home, state, config, session, env, skill: runSkill, pane: '', spawnReceipt, done: join(dir, 'done') }
98
134
  let launch
99
- if (['ordinary', 'worker'].includes(opts.invalid)) {
135
+ if (manualLaunch) {
100
136
  let cwd = root
101
137
  if (opts.invalid === 'worker') {
102
- cwd = join(root, 'worker'); writeFileSync(join(root, 'README'), 'fixture'); command('git', ['add', 'README'], { cwd: root })
103
- command('git', ['-c', 'user.name=fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture'], { cwd: root })
104
- command('git', ['worktree', 'add', '-q', '--detach', cwd, 'HEAD'], { cwd: root })
138
+ cwd = join(root, 'worker'); writeFileSync(join(root, 'README'), 'fixture'); await command('git', ['add', 'README'], { cwd: root })
139
+ await command('git', ['-c', 'user.name=fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture'], { cwd: root })
140
+ await command('git', ['worktree', 'add', '-q', '--detach', cwd, 'HEAD'], { cwd: root })
105
141
  }
106
- launch = `cd ${sh(cwd)} && exec ${sh(pi)} --provider p442 --model controlled -e ${sh(join(runSkill, 'extension/team-remind.ts'))} ${extra} @${sh(prompt)}`
142
+ // These two cases bypass team_pm_launch_cmd; record the same pre-exec PID for cleanup.
143
+ launch = `cd ${sh(cwd)} && printf '%s\\n' "$$" > ${sh(spawnReceipt)} && exec ${sh(pi)} --provider p442 --model controlled -e ${sh(join(runSkill, 'extension/team-remind.ts'))} ${extra} @${sh(prompt)}`
107
144
  } else {
108
- const sourceScript = `source ${sh(join(runSkill, 'scripts/lib/common.sh'))}; source ${sh(join(runSkill, 'scripts/lib/cmd-config.sh'))}; team_load_config; team_pm_launch_cmd ${sh(prompt)} ${sh(join(state, 'pm.pid.spawn'))}`
109
- launch = command('bash', ['-c', sourceScript], { cwd: root, env })
145
+ const sourceScript = `source ${sh(join(runSkill, 'scripts/lib/common.sh'))}; source ${sh(join(runSkill, 'scripts/lib/cmd-config.sh'))}; team_load_config; team_pm_launch_cmd ${sh(prompt)} ${sh(spawnReceipt)}`
146
+ launch = await command('bash', ['-c', sourceScript], { cwd: root, env })
110
147
  if (opts.invalid === 'no-entry') launch = launch.replace(` -e ${join(runSkill, 'extension/team-remind.ts')}`, '')
111
148
  }
112
149
  // Mutate after computing the directed launch so its environment still belongs to the real pane.
@@ -124,21 +161,30 @@ async function start(name, respond, opts = {}) {
124
161
  const gate = opts.deferFirstResponse ? new Promise(resolve => { release = resolve }) : null
125
162
  plans.set(name, { requests: 0, dir, state, respond, gate })
126
163
  const window = opts.invalid === 'forged' ? 'not-pm' : 'pm'
127
- tmux('new-session', '-d', '-s', session, '-n', window, '-c', root, 'sleep 600')
128
- tmux('set-option', '-t', session, 'remain-on-exit', 'on')
129
- const pane = tmux('display-message', '-p', '-t', `${session}:${window}`, '#{pane_id}').trim(); info.pane = pane
130
- info.serverPid = tmux('display-message', '-p', '-t', pane, '#{pid}').trim()
164
+ await tmux('new-session', '-d', '-s', session, '-n', window, '-c', root, 'sleep 600')
165
+ await tmux('set-option', '-t', session, 'remain-on-exit', 'on')
166
+ const pane = (await tmux('display-message', '-p', '-t', `${session}:${window}`, '#{pane_id}')).trim(); info.pane = pane
167
+ info.serverPid = (await tmux('display-message', '-p', '-t', pane, '#{pid}')).trim()
131
168
  const script = join(root, 'launch.sh')
132
169
  const assignments = Object.entries(env).map(([key, value]) => `export ${key}=${sh(value)};`).join('\n')
133
- writeFileSync(script, `#!/usr/bin/env bash\n${assignments}\nunset TEAM_ROOT TEAM_MAIN_ROOT TEAM_CONFIG_FILE TEAM_STATE_DIR\nbash -c ${sh(launch)}\nrc=$?; printf '%s\\n' "$rc" >${sh(info.done)}\nsleep 600\n`)
134
- tmux('respawn-pane', '-k', '-t', pane, `bash ${sh(script)}`)
170
+ const launchError = join(dir, 'launch-stderr.txt')
171
+ writeFileSync(script, `#!/usr/bin/env bash\n${assignments}\nunset TEAM_ROOT TEAM_MAIN_ROOT TEAM_CONFIG_FILE TEAM_STATE_DIR\nbash -c ${sh(launch)} 2>${sh(launchError)}\nrc=$?; printf '%s\\n' "$rc" >${sh(info.done)}\nsleep 600\n`)
172
+ // Tell the owner before requesting the launch, even if interrupted before Pi can log session_start.
173
+ appendFileSync(launchedScenes, `${name}\t${receiptPath}\n`)
174
+ await tmux('respawn-pane', '-k', '-t', pane, `bash ${sh(script)}`)
135
175
  await until(() => existsSync(join(dir, 'session-start')) || existsSync(info.done), `${name} session_start`)
136
- if (!['ordinary', 'worker', 'forged', 'no-entry'].includes(opts.invalid)) publishLaunch(info)
176
+ if (existsSync(info.done) && !existsSync(join(dir, 'session-start'))) {
177
+ const output = await tmux('capture-pane', '-p', '-t', pane, '-S', '-')
178
+ writeFileSync(join(dir, 'launch-output.txt'), output)
179
+ throw new Error(`${name} Pi exited before session_start: rc=${readFileSync(info.done, 'utf8').trim()}\n${readFileSync(launchError, 'utf8')}${output}`)
180
+ }
181
+ if (!['ordinary', 'worker', 'forged', 'no-entry'].includes(opts.invalid)) await publishLaunch(info)
137
182
  if (release) release()
138
183
  if (opts.invalid === 'no-entry' && release) release()
139
- const tick = () => {
184
+ const tick = async () => {
140
185
  if (['ordinary', 'worker', 'forged', 'no-entry'].includes(opts.invalid)) return
141
- spawnSync(process.execPath, [join(runSkill, 'scripts/remind-tick.mjs'), '--root', root, '--state-dir', state,
186
+ await stopPoint()
187
+ await runSync(process.execPath, [join(runSkill, 'scripts/remind-tick.mjs'), '--root', root, '--state-dir', state,
142
188
  '--pulse-started', new Date().toISOString(), '--json'], { cwd: root, env, stdio: 'ignore' })
143
189
  }
144
190
  const armTicker = () => setInterval(tick, 250)
@@ -151,10 +197,13 @@ async function stopPi(info) {
151
197
  if (!existsSync(info.done)) {
152
198
  const pid = Number(readFileSync(join(info.dir, 'session-start'), 'utf8').trim())
153
199
  const alive = () => { try { process.kill(pid, 0); return true } catch { return false } }
154
- tmux('send-keys', '-t', info.pane, '-l', '/p442-control stop'); tmux('send-keys', '-t', info.pane, 'Enter')
200
+ await tmux('send-keys', '-t', info.pane, '-l', '/p442-control stop'); await tmux('send-keys', '-t', info.pane, 'Enter')
155
201
  // team_pm_start restarts do not use launch.sh, so they have no `done` receipt. Wait for either
156
202
  // that receipt or the actual process exit; a stuck private fixture is killed by its recorded pid.
157
- for (let n = 0; n < 200 && !existsSync(info.done) && alive(); n++) await delay(50)
203
+ for (let n = 0; n < 200 && !existsSync(info.done) && alive(); n++) {
204
+ await delay(50)
205
+ checkStop()
206
+ }
158
207
  if (!existsSync(info.done) && alive()) {
159
208
  console.error(`CLEANUP ${info.name}: graceful shutdown did not exit; killing private Pi pid ${pid}`)
160
209
  process.kill(pid, 'SIGKILL')
@@ -163,31 +212,31 @@ async function stopPi(info) {
163
212
  }
164
213
  }
165
214
  async function stop(info) {
166
- const alive = spawnSync('tmux', ['-S', socket, '-f', '/dev/null', 'has-session', '-t', info.session], { env: base, encoding: 'utf8' })
215
+ const alive = await runSync('tmux', ['-S', socket, '-f', '/dev/null', 'has-session', '-t', info.session], { env: base, encoding: 'utf8' })
167
216
  if (alive.status === 0) {
168
217
  await stopPi(info)
169
- tmux('kill-session', '-t', info.session)
218
+ await tmux('kill-session', '-t', info.session)
170
219
  } else clearInterval(info.ticker)
171
220
  }
172
- function team(info, args, label = 'team') {
173
- const result = spawnSync('bash', [join(info.skill, 'scripts/team'), '--root', info.root, ...args], {
221
+ async function team(info, args, label = 'team') {
222
+ const result = await runSync('bash', [join(info.skill, 'scripts/team'), '--root', info.root, ...args], {
174
223
  cwd: info.root, env: { ...info.env, TMUX: `${socket},${info.serverPid},0`, TMUX_PANE: info.pane }, encoding: 'utf8' })
175
224
  writeFileSync(join(info.dir, `${label}.txt`), (result.stdout ?? '') + (result.stderr ?? ''))
176
225
  return result
177
226
  }
178
- function recover(info) {
227
+ async function recover(info) {
179
228
  // tmux respawn inherits the private server's environment, not spawnSync's. Publish the same
180
229
  // controlled fixture environment the initial launch.sh supplied explicitly.
181
- for (const [key, value] of Object.entries(info.env)) tmux('set-environment', '-t', info.session, key, String(value))
230
+ for (const [key, value] of Object.entries(info.env)) await tmux('set-environment', '-t', info.session, key, String(value))
182
231
  const source = `source ${sh(join(info.skill, 'scripts/lib/common.sh'))}; source ${sh(join(info.skill, 'scripts/lib/cmd-config.sh'))}; source ${sh(join(info.skill, 'scripts/lib/cmd-remind.sh'))}; team_load_config; team_remind_recovery`
183
- const result = spawnSync('bash', ['-c', source], { cwd: info.root,
232
+ const result = await runSync('bash', ['-c', source], { cwd: info.root,
184
233
  env: { ...info.env, TMUX: `${socket},${info.serverPid},0`, TMUX_PANE: info.pane }, encoding: 'utf8' })
185
234
  writeFileSync(join(info.dir, `recovery-${Date.now()}.txt`), (result.stdout ?? '') + (result.stderr ?? ''))
186
235
  return result
187
236
  }
188
- function control(info, action) {
189
- tmux('send-keys', '-t', info.pane, '-l', `/p442-control ${action}`)
190
- tmux('send-keys', '-t', info.pane, 'Enter')
237
+ async function control(info, action) {
238
+ await tmux('send-keys', '-t', info.pane, '-l', `/p442-control ${action}`)
239
+ await tmux('send-keys', '-t', info.pane, 'Enter')
191
240
  }
192
241
  async function hardStop(info) {
193
242
  const pid = Number(readFileSync(join(info.dir, 'session-start'), 'utf8').trim())
@@ -200,12 +249,12 @@ async function restartDirect(info) {
200
249
  // resends). Restart the same stopped PM through the production prompt-free start primitive instead.
201
250
  rmSync(info.done, { force: true })
202
251
  delete info.env.P444_KILL_AT
203
- for (const [key, value] of Object.entries(info.env)) tmux('set-environment', '-t', info.session, key, String(value))
252
+ for (const [key, value] of Object.entries(info.env)) await tmux('set-environment', '-t', info.session, key, String(value))
204
253
  const script = join(info.root, 'launch.sh')
205
254
  writeFileSync(script, readFileSync(script, 'utf8').replace(/^export P444_KILL_AT=.*;$/m, 'unset P444_KILL_AT;'))
206
255
  const before = events(info).filter(e => e.type === 'session_start').length
207
256
  const source = `source ${sh(join(info.skill, 'scripts/lib/common.sh'))}; source ${sh(join(info.skill, 'scripts/lib/cmd-config.sh'))}; team_load_config; TEAM_REMINDER_ONLY_RECOVERY=1 team_pm_start`
208
- const result = spawnSync('bash', ['-c', source], { cwd: info.root,
257
+ const result = await runSync('bash', ['-c', source], { cwd: info.root,
209
258
  env: { ...info.env, TMUX: `${socket},${info.serverPid},0`, TMUX_PANE: info.pane }, encoding: 'utf8' })
210
259
  writeFileSync(join(info.dir, `restart-${Date.now()}.txt`), (result.stdout ?? '') + (result.stderr ?? ''))
211
260
  assert.equal(result.status, 0, `prompt-free restart after death: ${result.stdout}${result.stderr}`)
@@ -221,15 +270,17 @@ async function restartForeign(info) {
221
270
  .replace(' -c --offline', ' --offline').replace(/ @\S*pm-prompt\.md\s*$/, '')
222
271
  const script = join(info.root, 'launch-foreign.sh')
223
272
  const assignments = Object.entries(info.env).map(([key, value]) => `export ${key}=${sh(value)};`).join('\n')
224
- writeFileSync(script, `#!/usr/bin/env bash\n${assignments}\nunset TEAM_ROOT TEAM_MAIN_ROOT TEAM_CONFIG_FILE TEAM_STATE_DIR\nbash -c ${sh(launch)}\nrc=$?; printf '%s\\n' "$rc" >${sh(info.done)}\nsleep 600\n`)
225
- tmux('respawn-pane', '-k', '-t', info.pane, `bash ${sh(script)}`)
273
+ writeFileSync(script, `#!/usr/bin/env bash\n${assignments}\nunset TEAM_ROOT TEAM_MAIN_ROOT TEAM_CONFIG_FILE TEAM_STATE_DIR\nbash -c ${sh(launch)} 2>${sh(join(info.dir, 'launch-stderr.txt'))}\nrc=$?; printf '%s\\n' "$rc" >${sh(info.done)}\nsleep 600\n`)
274
+ // The old Pi has exited. Do not let its receipt stand in for a replacement still starting.
275
+ rmSync(info.spawnReceipt, { force: true })
276
+ await tmux('respawn-pane', '-k', '-t', info.pane, `bash ${sh(script)}`)
226
277
  await until(() => events(info).filter(e => e.type === 'session_start').length > before &&
227
278
  events(info).filter(e => e.type === 'session_start').at(-1).sessionId !== oldSession, 'actual foreign process/session')
228
279
  }
229
- function addReal(info, message, key, label = 'add-adversarial') {
280
+ async function addReal(info, message, key, label = 'add-adversarial') {
230
281
  const args = ['remind', 'add', '--after', '1s', '--message', message]
231
282
  if (key) args.push('--key', key)
232
- const result = team(info, args, label)
283
+ const result = await team(info, args, label)
233
284
  assert.equal(result.status, 0, `${label}: ${result.stdout}${result.stderr}`)
234
285
  }
235
286
  function lastBatch(info) { return snapshot(info.state).batches.at(-1) }
@@ -242,12 +293,12 @@ function replayPayload(info, name = 'replay') {
242
293
  }
243
294
  async function replay(info, file, label) {
244
295
  const sends = events(info).filter(e => e.type === 'fixture_send').length
245
- control(info, `send ${file}`)
296
+ await control(info, `send ${file}`)
246
297
  await until(() => events(info).filter(e => e.type === 'fixture_send').length > sends, `${label} actual Pi send`)
247
298
  }
248
299
  async function test(name, body) {
249
- try { await body(); console.log(`PASS real Pi ${name}`); passed++ }
250
- catch (e) { failed++; console.error(`FAIL real Pi ${name}: ${e.stack}`) }
300
+ try { await body(); await stopPoint(); console.log(`PASS real Pi ${name}`); passed++ }
301
+ catch (e) { await stopPoint(); failed++; console.error(`FAIL real Pi ${name}: ${e.stack}`) }
251
302
  }
252
303
  const add = (after, message, key) => ({ action: 'add', after, message, ...(key ? { key } : {}) })
253
304
  const final = text => ({ text })
@@ -260,7 +311,7 @@ const mismatchGeneratedSession = config => {
260
311
  assert.notEqual(changed, source, 'change only the generated TEAM_SESSION line')
261
312
  writeFileSync(config, changed)
262
313
  }
263
- function assertConfigMismatch(info) {
314
+ async function assertConfigMismatch(info) {
264
315
  const evidence = join(info.state, 'remind-tool/current.json')
265
316
  assert(existsSync(evidence), 'mismatched config leaves visible error evidence')
266
317
  const record = json(evidence)
@@ -270,7 +321,7 @@ function assertConfigMismatch(info) {
270
321
  const started = events(info).filter(e => e.type === 'session_start').at(-1)
271
322
  assert.equal(started.reminderTools[0]?.exposure, 'hidden', 'real Pi registers only the hidden tool')
272
323
  assert(!started.activeTools.includes('team_remind'), 'real Pi active tools exclude team_remind')
273
- assert.match(doctor(info), /PM 提醒工具\s+.*error PM config TEAM_SESSION does not match the directed launch/,
324
+ assert.match(await doctor(info), /PM 提醒工具\s+.*error PM config TEAM_SESSION does not match the directed launch/,
274
325
  'doctor reports the configuration error instead of unknown or ready')
275
326
  assert(!existsSync(join(info.state, 'reminders/state.json')), 'rejected config touches no Reminder state')
276
327
  }
@@ -315,13 +366,13 @@ try {
315
366
  assert.equal(snap.reminders[2].message, 'identical no key'); assert.equal(snap.reminders[3].message, 'identical no key')
316
367
  assert.notEqual(snap.reminders[2].id, snap.reminders[3].id)
317
368
  assert(snap.reminders.every(record => record.source === 'pm-tool'))
318
- const output = doctor(info); assert.match(output, /PM 提醒工具\s+.*ready extension reported registered\/active/)
369
+ const output = await doctor(info); assert.match(output, /PM 提醒工具\s+.*ready extension reported registered\/active/)
319
370
  const capability = json(join(info.state, 'remind-tool/current.json'))
320
371
  assert(capability.launchNonce && capability.sessionId && capability.starttime && capability.extensionVersion)
321
372
  writeFileSync(join(info.dir, 'receipt.json'), JSON.stringify({ firstId, firstDue, final: snap, capability }, null, 2))
322
373
  } finally { await stop(info) }
323
374
  assert(!existsSync(join(info.state, 'remind-tool/current.json')), 'shutdown removes only its own capability evidence')
324
- assert.match(doctor(info), /PM 提醒工具\s+.*not-running/)
375
+ assert.match(await doctor(info), /PM 提醒工具\s+.*not-running/)
325
376
  })
326
377
 
327
378
  if (selection.includes('large')) await test('64 KiB plus final newline through real PM tool add/show/list/cancel', async () => {
@@ -364,13 +415,13 @@ try {
364
415
  try {
365
416
  await until(() => snapshot(info.state).reminders.length === 1 && events(info).some(e => e.type === 'agent_settled'), 'pre-reload add')
366
417
  const before = readFileSync(join(info.state, 'reminders/state.json'), 'utf8')
367
- tmux('rename-window', '-t', info.pane, 'not-pm')
368
- tmux('send-keys', '-t', info.pane, '-l', '/p442-control reload'); tmux('send-keys', '-t', info.pane, 'Enter')
418
+ await tmux('rename-window', '-t', info.pane, 'not-pm')
419
+ await tmux('send-keys', '-t', info.pane, '-l', '/p442-control reload'); await tmux('send-keys', '-t', info.pane, 'Enter')
369
420
  await until(() => events(info).filter(e => e.type === 'session_start').length >= 2 && requests(info).length >= 2, 'invalid reload response')
370
421
  const current = events(info).filter(e => e.type === 'session_start').at(-1)
371
422
  assert.equal(current.reminderTools[0]?.exposure, 'hidden'); assert.equal(current.activeTools.length, 0)
372
423
  assert.equal(readFileSync(join(info.state, 'reminders/state.json'), 'utf8'), before)
373
- assert.match(doctor(info), /PM 提醒工具\s+.*not-running/) // configured PM pane is gone; no ready claim follows the stale evidence
424
+ assert.match(await doctor(info), /PM 提醒工具\s+.*not-running/) // configured PM pane is gone; no ready claim follows the stale evidence
374
425
  } finally { await stop(info) }
375
426
  })
376
427
  }
@@ -385,22 +436,22 @@ try {
385
436
  const promptBefore = readFileSync(join(info.state, 'pm-prompt.md'), 'utf8')
386
437
  const wrapper = join(info.dir, 'pi-argv-wrapper.sh'), argvBytes = join(info.dir, 'argv.bin')
387
438
  writeFileSync(wrapper, `#!/usr/bin/env bash\nprintf '%s\\0' "$@" >${sh(argvBytes)}\nexec ${sh(pi)} "$@"\n`)
388
- command('chmod', ['+x', wrapper])
439
+ await command('chmod', ['+x', wrapper])
389
440
  writeFileSync(info.config, readFileSync(info.config, 'utf8').replace(/^TEAM_PI_BIN=.*$/m, `TEAM_PI_BIN=${sh(wrapper)}`))
390
441
  // team_load_config gives environment overrides precedence; recover() also publishes info.env to tmux.
391
442
  info.env.TEAM_PI_BIN = wrapper
392
- let result = team(info, ['notify', 'pm', 'P443_ORDINARY_BACKLOG'], 'ordinary-backlog')
443
+ let result = await team(info, ['notify', 'pm', 'P443_ORDINARY_BACKLOG'], 'ordinary-backlog')
393
444
  assert.equal(result.status, 0, 'ordinary backlog is pending before recovery')
394
- result = team(info, ['standby', 'on', '--reason', 'P443 stopped recovery'], 'standby-on')
445
+ result = await team(info, ['standby', 'on', '--reason', 'P443 stopped recovery'], 'standby-on')
395
446
  assert.equal(result.status, 0, 'Standby on succeeds')
396
- result = team(info, ['remind', 'add', '--after', '1s', '--message', 'P443_RECOVERY_ONLY', '--key', 'recovery'], 'add-recovery')
447
+ result = await team(info, ['remind', 'add', '--after', '1s', '--message', 'P443_RECOVERY_ONLY', '--key', 'recovery'], 'add-recovery')
397
448
  assert.equal(result.status, 0, 'recovery Reminder is created')
398
449
  await delay(1200)
399
- result = recover(info)
450
+ result = await recover(info)
400
451
  assert.equal(result.status, 0, `prompt-free recovery: ${result.stdout}${result.stderr}`)
401
452
  assert.match(result.stdout, /result=started/)
402
453
  await delay(500)
403
- const pane = spawnSync('tmux', ['-S', socket, '-f', '/dev/null', 'capture-pane', '-p', '-t', `${info.session}:pm`, '-S', '-100'], { env: base, encoding: 'utf8' })
454
+ const pane = await runSync('tmux', ['-S', socket, '-f', '/dev/null', 'capture-pane', '-p', '-t', `${info.session}:pm`, '-S', '-100'], { env: base, encoding: 'utf8' })
404
455
  writeFileSync(join(info.dir, 'recovery-pane.txt'), (pane.stdout ?? '') + (pane.stderr ?? ''))
405
456
  const pid = readFileSync(join(info.state, 'pm.pid'), 'utf8').trim()
406
457
  const argv = readFileSync(argvBytes).toString('utf8').split('\0').filter(Boolean)
@@ -424,15 +475,15 @@ try {
424
475
  plan.gateN = plan.requests
425
476
  let releaseBusy
426
477
  plan.gate = new Promise(resolve => { releaseBusy = resolve; info.releaseBusy = resolve })
427
- result = team(info, ['remind', 'add', '--after', '1s', '--message', 'P443_BUSY_FOLLOW_UP'], 'add-busy')
478
+ result = await team(info, ['remind', 'add', '--after', '1s', '--message', 'P443_BUSY_FOLLOW_UP'], 'add-busy')
428
479
  assert.equal(result.status, 0)
429
480
  await delay(1200)
430
- result = recover(info)
481
+ result = await recover(info)
431
482
  assert.equal(result.status, 0)
432
483
  assert.match(result.stdout, /result=running/)
433
484
  await until(() => requests(info).length === plan.gateN + 1, 'busy controlled response is pending')
434
485
  const restartsBeforeBusyCheck = readFileSync(join(info.state, 'pm-restarts.log'), 'utf8')
435
- result = recover(info)
486
+ result = await recover(info)
436
487
  assert.equal(result.status, 0)
437
488
  assert.doesNotMatch(result.stdout, /result=started/, 'an in-flight Reminder never causes another PM start')
438
489
  assert.equal(readFileSync(join(info.state, 'pm-restarts.log'), 'utf8'), restartsBeforeBusyCheck)
@@ -451,9 +502,9 @@ try {
451
502
  { deferFirstResponse: true, earlierHandler: true, pauseTicker: true, env: { P444_DELAY: '1' } })
452
503
  try {
453
504
  await until(() => requests(info).length === 1 && events(info).some(e => e.type === 'agent_settled'), 'batch initial response')
454
- assert.equal(team(info, ['standby', 'on', '--reason', 'P444 G1'], 'batch-g1').status, 0)
455
- addReal(info, 'P444_A first line\nsecond line\n', 'batch-a', 'add-a')
456
- addReal(info, 'P444_B full text', 'batch-b', 'add-b')
505
+ assert.equal((await team(info, ['standby', 'on', '--reason', 'P444 G1'], 'batch-g1')).status, 0)
506
+ await addReal(info, 'P444_A first line\nsecond line\n', 'batch-a', 'add-a')
507
+ await addReal(info, 'P444_B full text', 'batch-b', 'add-b')
457
508
  await delay(1100) // Both one-second Reminders are actually due before admission is allowed to run.
458
509
  info.armTicker()
459
510
  await until(() => lastBatch(info)?.phase === 'intent' && events(info).some(e => e.type === 'delay_enter'), 'A+B real event paused in earlier handler')
@@ -476,7 +527,7 @@ try {
476
527
  'the frozen A+B batch caused one controlled model request')
477
528
  assert.equal(requests(info).filter(r => JSON.stringify(r).includes('P444_A') && JSON.stringify(r).includes('P444_B')).length, 1)
478
529
 
479
- assert.equal(team(info, ['standby', 'on', '--reason', 'P444 fresh G2'], 'batch-g2').status, 0)
530
+ assert.equal((await team(info, ['standby', 'on', '--reason', 'P444 fresh G2'], 'batch-g2')).status, 0)
480
531
  const malformed = join(info.dir, 'wrong-members.json')
481
532
  writeFileSync(malformed, JSON.stringify({ ...delayed.message, details: { ...delayed.message.details, members: [] } }))
482
533
  await replay(info, malformed, 'wrong members')
@@ -506,11 +557,11 @@ try {
506
557
  { deferFirstResponse: true, earlierHandler: true, env: { P444_DELAY: '1' } })
507
558
  try {
508
559
  await until(() => events(info).some(e => e.type === 'agent_settled'), 'event-first initial response')
509
- team(info, ['standby', 'on', '--reason', 'G1'], 'event-first-g1')
510
- addReal(info, 'P444_EVENT_BEFORE_G2', 'event-first')
560
+ await team(info, ['standby', 'on', '--reason', 'G1'], 'event-first-g1')
561
+ await addReal(info, 'P444_EVENT_BEFORE_G2', 'event-first')
511
562
  await until(() => events(info).some(e => e.type === 'delay_enter') && lastBatch(info)?.phase === 'intent', 'real event arrived before G2')
512
- assert.equal(team(info, ['standby', 'off'], 'event-first-off').status, 0)
513
- assert.equal(team(info, ['standby', 'on', '--reason', 'G2'], 'event-first-g2').status, 0)
563
+ assert.equal((await team(info, ['standby', 'off'], 'event-first-off')).status, 0)
564
+ assert.equal((await team(info, ['standby', 'on', '--reason', 'G2'], 'event-first-g2')).status, 0)
514
565
  assert.equal(snapshot(info.state).standby.generation, 2)
515
566
  assert.equal(lastBatch(info).phase, 'intent', 'paused earlier handler has not committed observation')
516
567
  assert(!events(info).some(e => e.type === 'delay_exit'), 'both Standby commands completed while Pi handler was paused')
@@ -532,19 +583,19 @@ try {
532
583
  plan.gateN = plan.requests
533
584
  let releaseBusy
534
585
  plan.gate = new Promise(resolve => { releaseBusy = resolve; info.releaseBusy = resolve })
535
- control(info, 'busy')
586
+ await control(info, 'busy')
536
587
  await until(() => requests(info).length === plan.gateN + 1, 'unrelated controlled turn is busy')
537
- team(info, ['standby', 'on', '--reason', 'G1'], 'event-after-g1')
538
- addReal(info, 'P444_EVENT_AFTER_G2', 'event-after')
588
+ await team(info, ['standby', 'on', '--reason', 'G1'], 'event-after-g1')
589
+ await addReal(info, 'P444_EVENT_AFTER_G2', 'event-after')
539
590
  await until(() => lastBatch(info)?.phase === 'intent' && readFileSync(join(info.state, 'inbox-watch.log'), 'utf8').includes('intent-sent'),
540
591
  'busy follow-up call returned with durable intent')
541
592
  assert(!events(info).some(e => e.type === 'custom_start' && e.customType === 'team-reminder'), 'no message event before the busy turn ends')
542
593
  assert.equal(lastBatch(info).phase, 'intent', 'sendMessage returning is not a wake')
543
- assert.equal(team(info, ['standby', 'off'], 'event-after-off').status, 0)
544
- assert.equal(team(info, ['standby', 'on', '--reason', 'G2'], 'event-after-g2').status, 0)
594
+ assert.equal((await team(info, ['standby', 'off'], 'event-after-off')).status, 0)
595
+ assert.equal((await team(info, ['standby', 'on', '--reason', 'G2'], 'event-after-g2')).status, 0)
545
596
  releaseBusy()
546
597
  await until(() => lastBatch(info)?.phase === 'observed', 'busy follow-up observed after G2')
547
- assert(events(info).some(e => e.type === 'custom_start' && e.customType === 'team-reminder'))
598
+ await until(() => events(info).some(e => e.type === 'custom_start' && e.customType === 'team-reminder'), 'busy follow-up event recorded after G2')
548
599
  assert.equal(lastBatch(info).outcome.standby, 'generation-ambiguous')
549
600
  assert.equal(snapshot(info.state).standby.on, true); assert.equal(snapshot(info.state).standby.generation, 2)
550
601
  writeFileSync(join(info.dir, 'receipt.json'), JSON.stringify({ final: snapshot(info.state),
@@ -557,10 +608,10 @@ try {
557
608
  const bound = await start('adversarial-g2-bound', async ({ n, res }) => sse(res, { name: 'adversarial-g2-bound', ...final(`G2 bound ${n}`) }), { deferFirstResponse: true })
558
609
  try {
559
610
  await until(() => events(bound).some(e => e.type === 'agent_settled'), 'G2-bound initial response')
560
- team(bound, ['standby', 'on', '--reason', 'G1'], 'bound-g1')
561
- team(bound, ['standby', 'off'], 'bound-off1')
562
- team(bound, ['standby', 'on', '--reason', 'G2'], 'bound-g2')
563
- addReal(bound, 'P444_G2_BOUND', 'g2-bound')
611
+ await team(bound, ['standby', 'on', '--reason', 'G1'], 'bound-g1')
612
+ await team(bound, ['standby', 'off'], 'bound-off1')
613
+ await team(bound, ['standby', 'on', '--reason', 'G2'], 'bound-g2')
614
+ await addReal(bound, 'P444_G2_BOUND', 'g2-bound')
564
615
  await until(() => lastBatch(bound)?.phase === 'observed', 'G2-bound observation')
565
616
  assert.equal(lastBatch(bound).generation, 2); assert.equal(lastBatch(bound).outcome.standby, 'auto-off')
566
617
  assert.equal(snapshot(bound.state).standby.on, false)
@@ -571,10 +622,10 @@ try {
571
622
  { deferFirstResponse: true, earlierHandler: true, env: { P444_DELAY: '1' } })
572
623
  try {
573
624
  await until(() => events(manual).some(e => e.type === 'agent_settled'), 'manual-off initial response')
574
- team(manual, ['standby', 'on', '--reason', 'G1'], 'manual-g1')
575
- addReal(manual, 'P444_MANUAL_OFF', 'manual-off')
625
+ await team(manual, ['standby', 'on', '--reason', 'G1'], 'manual-g1')
626
+ await addReal(manual, 'P444_MANUAL_OFF', 'manual-off')
576
627
  await until(() => events(manual).some(e => e.type === 'delay_enter'), 'manual-off real event paused')
577
- assert.equal(team(manual, ['standby', 'off'], 'manual-off-command').status, 0)
628
+ assert.equal((await team(manual, ['standby', 'off'], 'manual-off-command')).status, 0)
578
629
  writeFileSync(join(manual.dir, 'release-event'), 'release')
579
630
  await until(() => lastBatch(manual)?.phase === 'observed', 'manual-off observation')
580
631
  assert.equal(lastBatch(manual).outcome.standby, 'already-off')
@@ -588,8 +639,8 @@ try {
588
639
  { deferFirstResponse: true, earlierHandler: true, env: { P444_KILL_AT: 'event' } })
589
640
  try {
590
641
  await until(() => events(info).some(e => e.type === 'agent_settled'), 'death-event initial response')
591
- team(info, ['standby', 'on', '--reason', 'G1'], 'death-event-g1')
592
- addReal(info, 'P444_DEATH_AFTER_EVENT', 'death-event')
642
+ await team(info, ['standby', 'on', '--reason', 'G1'], 'death-event-g1')
643
+ await addReal(info, 'P444_DEATH_AFTER_EVENT', 'death-event')
593
644
  await until(() => existsSync(info.done) && events(info).some(e => e.type === 'delay_enter'), 'death inside earlier real event handler')
594
645
  const original = replayPayload(info, 'late-original-event')
595
646
  assert.equal(lastBatch(info).phase, 'intent'); assert.equal(snapshot(info.state).standby.on, true)
@@ -599,8 +650,8 @@ try {
599
650
  assert.equal((ledger().match(/reminder intent-sent/g) ?? []).length, 1, 'restart did not resend the old intent')
600
651
  await until(() => lastBatch(info)?.phase === 'unknown', 'actual sixty-second deadline marks the old intent unknown')
601
652
  assert.equal(snapshot(info.state).standby.on, true)
602
- team(info, ['standby', 'off'], 'death-event-off1')
603
- team(info, ['standby', 'on', '--reason', 'fresh G2 after restart'], 'death-event-g2')
653
+ await team(info, ['standby', 'off'], 'death-event-off1')
654
+ await team(info, ['standby', 'on', '--reason', 'fresh G2 after restart'], 'death-event-g2')
604
655
  await replay(info, original, 'late original event')
605
656
  await until(() => lastBatch(info)?.phase === 'observed', 'late real event observes unknown batch')
606
657
  assert.equal(lastBatch(info).outcome.standby, 'generation-ambiguous')
@@ -635,11 +686,11 @@ try {
635
686
  if (point === 'after-call') {
636
687
  plan.gateN = plan.requests
637
688
  plan.gate = new Promise(resolve => { info.releaseBusy = resolve })
638
- control(info, 'busy')
689
+ await control(info, 'busy')
639
690
  await until(() => requests(info).length === plan.gateN + 1, 'after-call busy turn')
640
691
  }
641
- team(info, ['standby', 'on', '--reason', point], `${point}-g1`)
642
- addReal(info, `P444_DEATH_${point}`, point)
692
+ await team(info, ['standby', 'on', '--reason', point], `${point}-g1`)
693
+ await addReal(info, `P444_DEATH_${point}`, point)
643
694
  await until(() => existsSync(info.done), `${point} process death`)
644
695
  assert.equal(lastBatch(info).phase, 'intent'); assert.equal(snapshot(info.state).standby.on, true)
645
696
  assert(!events(info).some(e => e.type === 'custom_start' && e.customType === 'team-reminder'), 'no observation was manufactured')
@@ -669,18 +720,18 @@ try {
669
720
  const info = await start(name, async ({ n, res }) => sse(res, { name, ...final(`${action} response ${n}`) }), { deferFirstResponse: true })
670
721
  try {
671
722
  await until(() => requests(info).length === 1 && events(info).some(e => e.type === 'agent_settled'), `${action} initial response`)
672
- const added = team(info, ['remind', 'add', '--after', '1h', '--message', `before ${action}`], `add-before-${action}`)
723
+ const added = await team(info, ['remind', 'add', '--after', '1h', '--message', `before ${action}`], `add-before-${action}`)
673
724
  assert.equal(added.status, 0)
674
725
  const before = readFileSync(join(info.state, 'reminders/state.json'), 'utf8')
675
- tmux('rename-window', '-t', info.pane, 'not-pm')
676
- tmux('send-keys', '-t', info.pane, '-l', `/p442-control ${action}`); tmux('send-keys', '-t', info.pane, 'Enter')
726
+ await tmux('rename-window', '-t', info.pane, 'not-pm')
727
+ await tmux('send-keys', '-t', info.pane, '-l', `/p442-control ${action}`); await tmux('send-keys', '-t', info.pane, 'Enter')
677
728
  await until(() => events(info).filter(e => e.type === 'session_start').length >= 2, `${action} replacement session`)
678
729
  const current = events(info).filter(e => e.type === 'session_start').at(-1)
679
730
  assert.equal(current.reminderTools[0]?.exposure, 'hidden')
680
731
  assert.equal(current.activeTools.length, 0)
681
732
  const evidencePath = join(info.state, 'remind-tool/current.json')
682
733
  if (existsSync(evidencePath)) assert.equal(json(evidencePath).status, 'hidden')
683
- assert(!/PM 提醒工具\s+.*ready/.test(doctor(info)), 'doctor is not ready in the same replacement, without a 20s wait')
734
+ assert(!/PM 提醒工具\s+.*ready/.test(await doctor(info)), 'doctor is not ready in the same replacement, without a 20s wait')
684
735
  assert.equal(readFileSync(join(info.state, 'reminders/state.json'), 'utf8'), before)
685
736
  } finally { await stop(info) }
686
737
  })
@@ -691,7 +742,7 @@ try {
691
742
  const info = await start('noentry', async ({ n, res }) => sse(res, { name: 'noentry', ...final('no entry') }), { invalid: 'no-entry', deferFirstResponse: true })
692
743
  try {
693
744
  await until(() => events(info).some(e => e.type === 'agent_settled'), 'no-entry response')
694
- assert.match(doctor(info), /PM 提醒工具\s+.*unknown evidence:ENOENT/)
745
+ assert.match(await doctor(info), /PM 提醒工具\s+.*unknown evidence:ENOENT/)
695
746
  assert(!existsSync(join(info.state, 'reminders/state.json')))
696
747
  } finally { await stop(info) }
697
748
  })
@@ -701,7 +752,7 @@ try {
701
752
  })
702
753
  try {
703
754
  await until(() => existsSync(join(info.state, 'remind-tool/current.json')) && events(info).some(e => e.type === 'agent_settled'), 'config mismatch settles')
704
- assertConfigMismatch(info)
755
+ await assertConfigMismatch(info)
705
756
  } finally { await stop(info) }
706
757
  })
707
758
  await test('flip: deleting config-error evidence turns the named visibility assertion red', async () => {
@@ -717,7 +768,7 @@ try {
717
768
  try {
718
769
  await until(() => events(info).some(e => e.type === 'agent_settled'), 'config error flip settles')
719
770
  let failure
720
- try { assertConfigMismatch(info) } catch (e) { failure = e }
771
+ try { await assertConfigMismatch(info) } catch (e) { failure = e }
721
772
  assert.match(failure?.message ?? '', /mismatched config leaves visible error evidence/,
722
773
  'removing the write must fail the named error-evidence assertion')
723
774
  console.log(`EXPECTED RED config-error evidence: ${failure.message.split('\n')[0]}`)
@@ -737,18 +788,14 @@ try {
737
788
  await until(() => existsSync(join(info.state, 'remind-tool/current.json')), 'bootstrap error evidence')
738
789
  const record = json(join(info.state, 'remind-tool/current.json'))
739
790
  assert.equal(record.status, 'error'); assert.equal(record.exposure, 'hidden')
740
- assert.match(doctor(info), /PM 提醒工具\s+.*error controlled direct registration failure/)
791
+ assert.match(await doctor(info), /PM 提醒工具\s+.*error controlled direct registration failure/)
741
792
  assert(!existsSync(join(info.state, 'reminders/state.json')))
742
793
  } finally { await stop(info) }
743
794
  })
744
795
  }
745
796
  } finally {
746
797
  server.closeAllConnections(); await new Promise(resolve => server.close(resolve))
747
- const remaining = spawnSync('tmux', ['-S', socket, 'list-sessions'], { env: base, encoding: 'utf8' })
748
- if (remaining.status === 0) tmux('kill-server')
749
- else assert.match(remaining.stderr, /no server running|error connecting/, 'only the private server may already be gone')
750
- if (!process.env.P442_KEEP) rmSync(temporary, { recursive: true, force: true })
751
- else console.log(`kept private fixture root=${temporary}`)
752
798
  }
799
+ await stopPoint()
753
800
  console.log(`remind-tool-real: passed=${passed} failed=${failed} evidence=${evidence}`)
754
801
  if (failed) process.exitCode = 1