teamsmith 0.4.6 → 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 (91) hide show
  1. package/README.md +6 -6
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +35 -0
  4. package/skills/teamsmith/SKILL.md +43 -30
  5. package/skills/teamsmith/extension/team-bg.ts +5 -3
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +14 -3
  7. package/skills/teamsmith/extension/team-notify.ts +20 -13
  8. package/skills/teamsmith/extension/team-remind.ts +189 -0
  9. package/skills/teamsmith/extension/team-reply.ts +4 -7
  10. package/skills/teamsmith/references/config.md +11 -12
  11. package/skills/teamsmith/references/migration.md +101 -0
  12. package/skills/teamsmith/references/openspec.md +43 -27
  13. package/skills/teamsmith/references/protocol.md +26 -15
  14. package/skills/teamsmith/references/reminders.md +153 -161
  15. package/skills/teamsmith/references/troubleshooting.md +12 -7
  16. package/skills/teamsmith/references/workflows.md +84 -31
  17. package/skills/teamsmith/scripts/lib/cmd-agents.sh +10 -4
  18. package/skills/teamsmith/scripts/lib/cmd-project.sh +88 -6
  19. package/skills/teamsmith/scripts/lib/cmd-remind.sh +88 -2
  20. package/skills/teamsmith/scripts/lib/cmd-review.sh +61 -35
  21. package/skills/teamsmith/scripts/lib/cmd-watch.sh +48 -11
  22. package/skills/teamsmith/scripts/lib/common.sh +83 -13
  23. package/skills/teamsmith/scripts/panel/README.md +35 -33
  24. package/skills/teamsmith/scripts/panel/panel.js +217 -199
  25. package/skills/teamsmith/scripts/panel/src/App.tsx +221 -66
  26. package/skills/teamsmith/scripts/panel/src/data.ts +71 -15
  27. package/skills/teamsmith/scripts/panel/src/layout.ts +159 -310
  28. package/skills/teamsmith/scripts/panel/src/main.tsx +83 -21
  29. package/skills/teamsmith/scripts/panel/src/project-settings.ts +46 -0
  30. package/skills/teamsmith/scripts/panel/src/strings/en.ts +71 -205
  31. package/skills/teamsmith/scripts/panel/src/strings/index.ts +3 -5
  32. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +72 -204
  33. package/skills/teamsmith/scripts/panel/src/types.ts +23 -4
  34. package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
  35. package/skills/teamsmith/scripts/remind-store.mjs +55 -24
  36. package/skills/teamsmith/scripts/remind-tick.mjs +5 -2
  37. package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
  38. package/skills/teamsmith/scripts/state-authority.mjs +72 -6
  39. package/skills/teamsmith/scripts/strings/commands.tsv +1 -1
  40. package/skills/teamsmith/scripts/team +1 -0
  41. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +18 -8
  42. package/skills/teamsmith/templates/DECISIONS.md.tmpl +2 -2
  43. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +3 -3
  44. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +19 -14
  45. package/skills/teamsmith/templates/memory-seed.md.tmpl +2 -2
  46. package/skills/teamsmith/templates/pm-prompt.md.tmpl +41 -25
  47. package/skills/teamsmith/templates/report.md.tmpl +33 -0
  48. package/skills/teamsmith/tests/bg-ledger-harness.mjs +217 -33
  49. package/skills/teamsmith/tests/bg-ledger.sh +24 -10
  50. package/skills/teamsmith/tests/checkout-shape-probe.sh +7 -6
  51. package/skills/teamsmith/tests/fixtures/remind-adversarial-delay.ts +27 -0
  52. package/skills/teamsmith/tests/fixtures/remind-tool-provider.ts +65 -0
  53. package/skills/teamsmith/tests/help-surface.sh +78 -12
  54. package/skills/teamsmith/tests/install-shape.sh +7 -7
  55. package/skills/teamsmith/tests/isolation-ledger.sh +6 -2
  56. package/skills/teamsmith/tests/key-replies-ui.sh +64 -5
  57. package/skills/teamsmith/tests/key-replies.sh +307 -106
  58. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +2 -0
  59. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +255 -90
  60. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +181 -61
  61. package/skills/teamsmith/tests/lib/model-routing-roles.sh +125 -67
  62. package/skills/teamsmith/tests/lib/reply-fixture.sh +14 -9
  63. package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
  64. package/skills/teamsmith/tests/lib/tmp-root.sh +1 -1
  65. package/skills/teamsmith/tests/loop-inventory.tsv +3 -0
  66. package/skills/teamsmith/tests/panel-b2.sh +91 -31
  67. package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
  68. package/skills/teamsmith/tests/panel-p21.sh +607 -1162
  69. package/skills/teamsmith/tests/panel-strings.mjs +21 -113
  70. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +190 -0
  71. package/skills/teamsmith/tests/remind-adversarial-faults.sh +78 -0
  72. package/skills/teamsmith/tests/remind-adversarial-real.sh +28 -0
  73. package/skills/teamsmith/tests/remind-cli.sh +108 -3
  74. package/skills/teamsmith/tests/remind-delivery-node.mjs +13 -0
  75. package/skills/teamsmith/tests/remind-delivery.sh +123 -35
  76. package/skills/teamsmith/tests/remind-lifecycle.sh +197 -0
  77. package/skills/teamsmith/tests/remind-pulse.sh +199 -0
  78. package/skills/teamsmith/tests/remind-recovery-real.sh +5 -0
  79. package/skills/teamsmith/tests/remind-recovery-unit.sh +118 -0
  80. package/skills/teamsmith/tests/remind-tool-node.mjs +159 -0
  81. package/skills/teamsmith/tests/remind-tool-real.mjs +801 -0
  82. package/skills/teamsmith/tests/remind-tool-real.sh +180 -0
  83. package/skills/teamsmith/tests/reply-capture-real.mjs +93 -2
  84. package/skills/teamsmith/tests/routes.sh +213 -293
  85. package/skills/teamsmith/tests/section-paths.tsv +19 -17
  86. package/skills/teamsmith/tests/smoke.sh +583 -133
  87. package/skills/teamsmith/tests/state-authority.sh +152 -8
  88. package/skills/teamsmith/tests/task-model-routing.sh +57 -26
  89. package/skills/teamsmith/tests/tmp-hygiene.sh +1 -1
  90. package/skills/teamsmith-init/SKILL.md +5 -5
  91. package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env bash
2
+ # P442: private real Pi/tmux and controlled loopback model only; never the live team or credentials.
3
+ TESTS="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
+
5
+ # Read only the scenes the driver actually sent to its private pane. The launch receipt
6
+ # is written immediately before exec, so it names Pi itself, not launch.sh or tmux.
7
+ remind_tool_real_pi_writers() {
8
+ [[ -n "$remind_root" && -f "$remind_root/.pi-scenes" ]] || return 0
9
+ local scene root relative_receipt receipt pid started cwd uncertain=0
10
+ while IFS=$'\t' read -r scene relative_receipt; do
11
+ root="$(realpath -e -- "$remind_work/$scene")" || { uncertain=1; continue; }
12
+ receipt="$root/$relative_receipt"
13
+ if [[ ! -f "$receipt" ]] || ! IFS= read -r pid < "$receipt" || [[ ! "$pid" =~ ^[1-9][0-9]*$ || "$pid" == 1 ]]; then
14
+ printf 'remind-tool-real: no Pi launch identity for %s\n' "$scene" >&2
15
+ uncertain=1
16
+ continue
17
+ fi
18
+ if [[ ! -d "/proc/$pid" ]]; then continue; fi
19
+ if started="$(_tmp_root_proc_start "$pid")"; then
20
+ if ! _tmp_root_proc_alive "$pid" "$started"; then continue; fi
21
+ if cwd="$(team_proc_cwd "$pid")" && [[ "$cwd" == "$root" || "$cwd" == "$root/"* ]]; then
22
+ printf '%s:%s\n' "$pid" "$started"
23
+ continue
24
+ fi
25
+ fi
26
+ # The process may have exited while we were reading its identity.
27
+ if [[ -d "/proc/$pid" ]]; then
28
+ printf 'remind-tool-real: cannot identify private Pi %s for %s\n' "$pid" "$scene" >&2
29
+ uncertain=1
30
+ fi
31
+ done < "$remind_root/.pi-scenes"
32
+ return "$uncertain"
33
+ }
34
+
35
+ remind_tool_real_wait_pi() {
36
+ local pid started current deadline=$((SECONDS + 10))
37
+ while IFS=: read -r pid started; do
38
+ [[ -n "$pid" ]] || continue
39
+ while [[ -d "/proc/$pid" ]]; do
40
+ if ! current="$(_tmp_root_proc_start "$pid")"; then
41
+ [[ ! -d "/proc/$pid" ]] && break
42
+ printf 'remind-tool-real: cannot read exit identity of Pi %s\n' "$pid" >&2
43
+ return 1
44
+ fi
45
+ [[ "$current" == "$started" ]] || break
46
+ _tmp_root_proc_alive "$pid" "$started" || break
47
+ if (( SECONDS >= deadline )); then
48
+ printf 'remind-tool-real: private Pi %s has not exited\n' "$pid" >&2
49
+ return 1
50
+ fi
51
+ sleep 0.05
52
+ done
53
+ done <<< "$1"
54
+ return 0
55
+ }
56
+
57
+ remind_tool_real_cleanup() {
58
+ local rc=$? failure writers uncertain=0
59
+ trap '' INT TERM
60
+ if [[ -n "$remind_driver" ]]; then
61
+ # TERM works even if the background child has not installed its INT handler yet.
62
+ if [[ "$remind_driver_start" != unknown ]] && _tmp_root_proc_alive "$remind_driver" "$remind_driver_start"; then
63
+ kill -TERM "$remind_driver"
64
+ fi
65
+ # An interrupted driver returns nonzero; keep the owner's original result.
66
+ wait "$remind_driver" || :
67
+ fi
68
+
69
+ # Snapshot the original Pi identities while the private pane is still addressable.
70
+ writers="$(remind_tool_real_pi_writers)" || uncertain=1
71
+ if [[ -S "$remind_socket" ]]; then
72
+ if ! failure="$(env -i PATH="$remind_path" LC_ALL=C HOME="$remind_work/driver-home" TMPDIR="$remind_work" \
73
+ tmux -S "$remind_socket" -f /dev/null kill-server 2>&1)"; then
74
+ case "$failure" in
75
+ 'no server running on '*|'error connecting to '*' (No such file or directory)'|'error connecting to '*' (Connection refused)')
76
+ # The last session may already have shut down the private server.
77
+ ;;
78
+ *)
79
+ printf 'remind-tool-real: cannot stop private tmux at %s: %s; work=%s\n' \
80
+ "$remind_socket" "$failure" "$remind_work" >&2
81
+ exit "$((rc == 0 ? 1 : rc))" ;;
82
+ esac
83
+ fi
84
+ fi
85
+ # Closing the terminal starts Pi shutdown; its hooks can still write after tmux returns.
86
+ remind_tool_real_wait_pi "$writers" || uncertain=1
87
+ if [[ -n "$remind_socket_dir" ]]; then
88
+ rm -rf -- "$remind_socket_dir" || rc=$((rc == 0 ? 1 : rc))
89
+ fi
90
+ if (( uncertain )); then
91
+ printf 'remind-tool-real: Pi exit not proved; leaving work=%s\n' "$remind_work" >&2
92
+ exit "$((rc == 0 ? 1 : rc))"
93
+ fi
94
+ if [[ -n "$remind_root" ]]; then
95
+ if [[ -n "$remind_work" && ( "$TEAM_TMP_KEEP" == 1 || "$remind_work" != "$remind_root" ) ]]; then
96
+ printf 'kept private fixture root=%s\n' "$remind_work"
97
+ fi
98
+ # The driver is already reaped, so the helper must not signal that recorded PID.
99
+ rm -f -- "$TMP_ROOT_PIDFILE" || exit "$((rc == 0 ? 3 : rc))"
100
+ tmp_root_reap_all
101
+ fi
102
+ exit "$rc"
103
+ }
104
+
105
+ remind_tool_real_prepare() {
106
+ # shellcheck source=lib/tmp-root.sh
107
+ . "$TESTS/lib/tmp-root.sh"
108
+ remind_driver= remind_driver_start=unknown remind_stop= remind_socket= remind_socket_dir= remind_root= remind_work=
109
+ trap remind_tool_real_cleanup EXIT
110
+ # Defer an early signal until the owner knows whether a child has been started.
111
+ trap 'remind_stop=${remind_stop:-130}' INT
112
+ trap 'remind_stop=${remind_stop:-143}' TERM
113
+
114
+ TEAM_TMP_KEEP=0
115
+ if [[ -z "${P442_EVIDENCE:-}" && -n "${P442_KEEP:-}" ]]; then TEAM_TMP_KEEP=1; fi
116
+ remind_root="$(tmp_root_create remind-real)" || return 3
117
+ printf 'remind-tool-real: work=%s %s\n' "$remind_root" "$(team_tmp_root_note)"
118
+ TMP_ROOT_PIDFILE="$remind_root/.driver.pid"
119
+ remind_work="$remind_root"
120
+ if [[ -n "${P442_EVIDENCE:-}" ]]; then
121
+ # Match Node's lexical path.resolve, including relative caller paths.
122
+ remind_evidence="$(realpath -ms -- "$P442_EVIDENCE")" || return 3
123
+ mkdir -p -m 700 -- "$remind_evidence" || return 3
124
+ if [[ -n "${P442_KEEP:-}" ]]; then
125
+ remind_work="$(mktemp -d "$remind_evidence/run-XXXXXX")" || return 3
126
+ fi
127
+ else
128
+ remind_evidence="$remind_root/evidence"
129
+ mkdir -m 700 -- "$remind_evidence" || return 3
130
+ fi
131
+ }
132
+
133
+ remind_tool_real_run() {
134
+ local rc=0 pi bunbin runner="${_P442_NODE:-node}"
135
+ unset _P442_NODE
136
+ pi="${P442_PI:-$(command -v pi)}"
137
+ if [[ -z "$pi" ]]; then
138
+ printf 'remind-tool-real: Pi not found on caller PATH (or set P442_PI)\n' >&2
139
+ return 1
140
+ fi
141
+ bunbin="$(dirname -- "$pi")" || return 3
142
+ remind_path="$bunbin:/usr/local/bin:/usr/bin:/bin"
143
+ if ! PATH="$remind_path" type -P tmux >/dev/null; then
144
+ printf 'remind-tool-real: tmux not found on private Pi PATH\n' >&2
145
+ return 1
146
+ fi
147
+ remind_socket="$remind_work/socket"
148
+ if ! (LC_ALL=C; [[ ${#remind_socket} -le 107 ]]); then
149
+ if ! remind_socket_dir="$(LC_ALL=C TMP_ROOT_SOCKET_FALLBACK=/var/tmp tmp_root_socket_dir tmux s)"; then
150
+ printf 'remind-tool-real: cannot allocate a private tmux socket for %s\n' "$remind_work" >&2
151
+ return 3
152
+ fi
153
+ remind_socket="$remind_socket_dir/s"
154
+ fi
155
+
156
+ [[ -z "$remind_stop" ]] || exit "$remind_stop"
157
+ _P442_WORK="$remind_work" _P442_EVIDENCE="$remind_evidence" _P442_SOCKET="$remind_socket" \
158
+ _P442_PATH="$remind_path" _P442_PI="$pi" _P442_SCENES="$remind_root/.pi-scenes" \
159
+ "$runner" "$TESTS/remind-tool-real.mjs" "$@" <&0 &
160
+ remind_driver=$!
161
+ if ! remind_driver_start="$(_tmp_root_proc_start "$remind_driver")"; then
162
+ # A child that has already exited has no live identity to record.
163
+ remind_driver_start=unknown
164
+ else
165
+ tmp_root_track_pid "$remind_driver" remind-real-driver || return 3
166
+ fi
167
+ trap 'exit 130' INT
168
+ trap 'exit 143' TERM
169
+ [[ -z "$remind_stop" ]] || exit "$remind_stop"
170
+ wait "$remind_driver" || rc=$?
171
+ remind_driver=
172
+ return "$rc"
173
+ }
174
+
175
+ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
176
+ set -uo pipefail
177
+ remind_tool_real_prepare || exit $?
178
+ remind_tool_real_run "$@"
179
+ exit $?
180
+ fi
@@ -2,13 +2,13 @@
2
2
  import assert from 'node:assert/strict'
3
3
  import { createServer } from 'node:http'
4
4
  import { spawnSync } from 'node:child_process'
5
- import { appendFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
5
+ import { appendFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs'
6
6
  import { dirname, join, resolve } from 'node:path'
7
7
  import { fileURLToPath } from 'node:url'
8
8
  import { setTimeout as delay } from 'node:timers/promises'
9
9
  import { CaptureJournal, captureDiskFingerprint, inspectRuntime } from '../scripts/reply-capture.mjs'
10
10
  const tests = dirname(fileURLToPath(import.meta.url)), skill = dirname(tests)
11
- const selection = (process.argv.find(a => a.startsWith('--select='))?.slice(9) ?? (process.argv.includes('--select') ? process.argv[process.argv.indexOf('--select') + 1] : undefined) ?? 'print,tui,terminal,identity,lifecycle,owner-mutations').split(',')
11
+ const selection = (process.argv.find(a => a.startsWith('--select='))?.slice(9) ?? (process.argv.includes('--select') ? process.argv[process.argv.indexOf('--select') + 1] : undefined) ?? 'print,tui,terminal,identity,lifecycle,owner-mutations,diagnostic-mutations,config-mutations').split(',')
12
12
  const evidence = resolve(process.env.P396_EVIDENCE ?? `${process.env.HOME}/.cache/P396/pi-${Date.now()}`)
13
13
  mkdirSync(evidence, { recursive: true, mode: 0o700 })
14
14
  const temporary = mkdtempSync('/var/tmp/p396-real-'), socket = join(temporary, 'socket')
@@ -62,6 +62,7 @@ server = createServer(async (req, res) => {
62
62
  })
63
63
  await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
64
64
  const port = server.address().port
65
+ const invalidateIdentity = info => tmux('rename-window', '-t', info.pane, 'not-pm')
65
66
  async function run(name, kind = 'print', opts = {}) {
66
67
  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')
67
68
  for (const path of [dir, home, state, join(root, 'docs/team/tasks'), join(root, 'docs/team/inbox'), join(root, 'docs/team/outbox'), join(home, '.pi/agent')]) mkdirSync(path, { recursive: true })
@@ -71,6 +72,23 @@ async function run(name, kind = 'print', opts = {}) {
71
72
  const path = join(runSkill, 'extension/team-reply.ts'), bytes = readFileSync(path, 'utf8'), anchor = 'if (owners.has(key)) return'
72
73
  assert.equal(bytes.split(anchor).length, 2); writeFileSync(path, bytes.replace(anchor, 'if (false) return'))
73
74
  }
75
+ if (opts.diagnosticFlip) {
76
+ const path = join(runSkill, 'extension/team-reply.ts'), bytes = readFileSync(path, 'utf8')
77
+ const anchor = ' const line = `[team-reply] ${d.reason}; source=${d.entryId || \'unbound\'}; evidence=${d.path}\\n`\n'
78
+ assert.equal(bytes.split(anchor).length, 2)
79
+ writeFileSync(path, bytes.replace(anchor, `${anchor} process.stderr.write(line)\n`))
80
+ }
81
+ if (opts.configFlip) {
82
+ const path = join(runSkill, 'scripts/reply-capture.mjs'); let bytes = readFileSync(path, 'utf8')
83
+ const read = ' readRegular(config) // The path, type and owner remain capture boundaries; its contents do not.\n'
84
+ const identify = ' return { root, state, config, sessionId: context.sessionId, sessionFile, pid: process.pid, starttime: life.starttime, cwd, tmux }\n'
85
+ const inspect = " readRegular(config) // Keep the doctor's symlink and ownership checks without comparing configuration contents.\n"
86
+ for (const anchor of [read, identify, inspect]) assert.equal(bytes.split(anchor).length, 2, `config flip anchor: ${anchor.trim()}`)
87
+ bytes = bytes.replace(read, ' const configBytes = readRegular(config), configStat = lstatSync(config)\n')
88
+ bytes = bytes.replace(identify, ' return { root, state, config, configHash: digest(configBytes), configIno: configStat.ino, sessionId: context.sessionId, sessionFile, pid: process.pid, starttime: life.starttime, cwd, tmux }\n')
89
+ bytes = bytes.replace(inspect, " if (runtime.configHash !== digest(readRegular(config))) throw new Error('identity/config changed')\n")
90
+ writeFileSync(path, bytes)
91
+ }
74
92
  writeFileSync(join(home, '.pi/agent/settings.json'), JSON.stringify({ retry: { enabled: kind === 'retry', maxRetries: 1, baseDelayMs: 1 }, compaction: { enabled: false } }))
75
93
  writeFileSync(join(root, 'docs/team/BOARD.md'), '# untouched\n')
76
94
  command('git', ['init', '-q', '-b', 'main'], { cwd: root })
@@ -192,6 +210,10 @@ async function run(name, kind = 'print', opts = {}) {
192
210
  assert(!JSON.stringify(history).includes('[[team-reply'), 'next provider history is clean')
193
211
  }
194
212
  if (kind === 'print') assert.equal(readFileSync(join(dir, 'stdout'), 'utf8'), text(ends.at(-1).message) + '\n', 'exact final print stdout')
213
+ for (const file of ['stdout', 'stderr']) {
214
+ const path = join(dir, file)
215
+ if (existsSync(path)) assert(!readFileSync(path, 'utf8').includes('[team-reply]'), `terminal ${file} must not contain internal diagnostics`)
216
+ }
195
217
  if (kind === 'tui') {
196
218
  await delay(100)
197
219
  const raw = readFileSync(join(dir, 'raw.pty'), 'utf8')
@@ -200,6 +222,8 @@ async function run(name, kind = 'print', opts = {}) {
200
222
  writeFileSync(join(dir, 'final-screen.txt'), screen)
201
223
  assert(screen.includes(`决定 ${name} 保留。`), 'final frame matching body positive')
202
224
  assert(!screen.includes('[[team-reply'), 'final frame has no complete control')
225
+ assert(!screen.includes('[team-reply]'), 'final frame must not contain internal diagnostics')
226
+ assert(!raw.includes('[team-reply]'), 'raw PTY must not contain internal diagnostics')
203
227
  // Scrollback may retain transient frames: validate finalized authoritative message separately, never claim zero flash.
204
228
  assert(raw.includes(`决定 ${name} 保留。`), 'raw PTY actual body positive')
205
229
  }
@@ -239,6 +263,38 @@ async function test(name, body) {
239
263
  try { await body(); console.log(`PASS real Pi ${name}`); passed++ }
240
264
  catch (e) { failed++; console.error(`FAIL real Pi ${name}: ${e.stack}`) }
241
265
  }
266
+ async function configChange(name) {
267
+ const flip = process.env.P438_CONFIG_FLIP === '1'
268
+ await run(name, 'print', {
269
+ skillCopy: flip, configFlip: flip,
270
+ onReady: async info => {
271
+ const runtimePath = join(info.state, 'reply-capture/runtime.json')
272
+ await until(() => existsSync(runtimePath) && json(runtimePath).status === 'ready', 'capture ready before config edit')
273
+ const before = readFileSync(info.config, 'utf8'), beforeIno = statSync(info.config).ino
274
+ const output = command('bash', [join(info.skill, 'scripts/team'), '--root', info.root, 'config', 'set-task-model', 'routine', 'p396/after-config', '--yes'], { cwd: info.root, env: info.env })
275
+ writeFileSync(join(info.dir, 'config-change.txt'), output)
276
+ assert.notEqual(readFileSync(info.config, 'utf8'), before, 'the product CLI really changed task-model configuration')
277
+ assert.notEqual(statSync(info.config).ino, beforeIno, 'the atomic CLI write really changed the config inode')
278
+ assert.match(readFileSync(info.config, 'utf8'), /routine=p396\/after-config/)
279
+ const { inspectRuntime: inspect } = await import(join(info.skill, 'scripts/reply-capture.mjs'))
280
+ assert.equal(inspect({ ...info, window: 'pm' }).state, 'ready', 'task-model edit leaves runtime ready')
281
+ },
282
+ interactive: async info => {
283
+ await until(() => storeCount(info.state) === 1 && confirmedCount(info.state) === 1, 'marked reply saved after task-model edit')
284
+ const runtime = json(join(info.state, 'reply-capture/runtime.json'))
285
+ assert.equal(runtime.status, 'ready', 'capture does not degrade after the changed configuration is re-proved')
286
+ const { inspectRuntime: inspect } = await import(join(info.skill, 'scripts/reply-capture.mjs'))
287
+ assert.equal(inspect({ ...info, window: 'pm' }).state, 'ready', 'doctor runtime remains ready after capture')
288
+ const doctor = spawnSync('bash', [join(info.skill, 'scripts/team'), '--root', info.root, 'doctor'], { cwd: info.root, env: info.env, encoding: 'utf8' })
289
+ writeFileSync(join(info.dir, 'doctor.txt'), doctor.stdout + doctor.stderr)
290
+ assert.match(doctor.stdout, /关键回复运行/)
291
+ assert.match(doctor.stdout, /ready disk=/)
292
+ const events = jsonl(join(info.dir, 'events.jsonl'))
293
+ assert(events.filter(e => e.type === 'message_end').every(e => !text(e.message).includes('[[team-reply')), 'the post-edit reply is cleaned')
294
+ await control(info, 'stop')
295
+ },
296
+ })
297
+ }
242
298
  try {
243
299
  if (selection.includes('print')) await test('builtin print/end/append/entry/settled/raw store/transcript', () => run('print'))
244
300
  if (selection.includes('tui')) await test('interactive actual-marker raw PTY and authoritative final cleanup', () => run('tui', 'tui'))
@@ -253,6 +309,41 @@ try {
253
309
  },
254
310
  }))
255
311
  }
312
+ if (selection.includes('config-change')) await test('task-model CLI edit keeps live capture and doctor ready', () => configChange('config-change'))
313
+ if (selection.includes('config-mutations')) await test('restoring config hash/inode identity makes the real edit red; restoration is green', async () => {
314
+ for (const [group, code] of [['config-flip', 1], ['config-control', 0]]) {
315
+ const result = spawnSync(process.execPath, [fileURLToPath(import.meta.url), '--select=config-change'], {
316
+ env: { ...process.env, P396_EVIDENCE: join(evidence, group), P438_CONFIG_FLIP: code ? '1' : '0' }, encoding: 'utf8',
317
+ })
318
+ const output = result.stdout + result.stderr
319
+ writeFileSync(join(evidence, `${group}.log`), output)
320
+ assert.equal(result.status, code, output)
321
+ assert(output.includes(code ? 'task-model edit leaves runtime ready' : 'passed=1 failed=0'), output)
322
+ }
323
+ })
324
+ if (selection.includes('diagnostics')) await test('recover-skip:ineligible is file-only and never appears in the Pi terminal', async () => {
325
+ const info = await run('diagnostics', 'tui', {
326
+ noPublish: true, onReady: invalidateIdentity,
327
+ skillCopy: process.env.P437_DIAGNOSTIC_FLIP === '1', diagnosticFlip: process.env.P437_DIAGNOSTIC_FLIP === '1',
328
+ })
329
+ const path = join(info.state, 'reply-capture/diagnostics.log')
330
+ assert(existsSync(path), 'recover refusal leaves a local diagnostic file')
331
+ const diagnostic = readFileSync(path, 'utf8')
332
+ assert(diagnostic.includes('[team-reply] recover-skip:ineligible; source=unbound; evidence='), diagnostic)
333
+ assert(diagnostic.includes(join(info.state, 'reply-capture')), 'diagnostic retains its evidence path')
334
+ })
335
+ if (selection.includes('diagnostic-mutations')) await test('restoring diagnostic stderr makes the real Pi terminal assertion red; restoration is green', async () => {
336
+ for (const [group, code] of [['diagnostics-flip', 1], ['diagnostics-control', 0]]) {
337
+ const result = spawnSync(process.execPath, [fileURLToPath(import.meta.url), '--select=diagnostics'], {
338
+ env: { ...process.env, P396_EVIDENCE: join(evidence, group), P437_DIAGNOSTIC_FLIP: code ? '1' : '0' }, encoding: 'utf8',
339
+ })
340
+ const output = result.stdout + result.stderr
341
+ writeFileSync(join(evidence, `${group}.log`), output)
342
+ assert.equal(result.status, code, output)
343
+ if (code) assert(output.includes('raw PTY must not contain internal diagnostics'), output)
344
+ else assert(output.includes('passed=1 failed=0'), output)
345
+ }
346
+ })
256
347
  if (selection.includes('owner-flip')) await test('first path keeps owner/runtime', () => run('owner-flip', 'print', { skillCopy: true, duplicate: true, ownerFlip: true }))
257
348
  if (selection.includes('owner-control')) await test('first path keeps owner/runtime', () => run('owner-control', 'print', { skillCopy: true, duplicate: true }))
258
349
  if (selection.includes('owner-mutations')) await test('owner mutation named red and restoration green in private Pi', async () => {