teamsmith 0.4.5 → 0.4.6

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 (43) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +13 -1
  4. package/skills/teamsmith/SKILL.md +1 -1
  5. package/skills/teamsmith/extension/team-bg.ts +7 -8
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +136 -3
  7. package/skills/teamsmith/references/protocol.md +2 -3
  8. package/skills/teamsmith/references/reminders.md +55 -12
  9. package/skills/teamsmith/references/workflows.md +1 -3
  10. package/skills/teamsmith/scripts/lib/cmd-agents.sh +18 -1
  11. package/skills/teamsmith/scripts/lib/cmd-project.sh +12 -9
  12. package/skills/teamsmith/scripts/lib/cmd-remind.sh +49 -10
  13. package/skills/teamsmith/scripts/lib/cmd-update.sh +90 -88
  14. package/skills/teamsmith/scripts/lib/cmd-watch.sh +281 -155
  15. package/skills/teamsmith/scripts/lib/common.sh +74 -14
  16. package/skills/teamsmith/scripts/panel/panel.js +134 -134
  17. package/skills/teamsmith/scripts/panel/src/data.ts +51 -0
  18. package/skills/teamsmith/scripts/panel/src/layout.ts +10 -0
  19. package/skills/teamsmith/scripts/panel/src/main.tsx +27 -0
  20. package/skills/teamsmith/scripts/remind-store.mjs +362 -6
  21. package/skills/teamsmith/scripts/remind-tick.mjs +102 -0
  22. package/skills/teamsmith/scripts/reminder-delivery.mjs +76 -0
  23. package/skills/teamsmith/scripts/state-authority.mjs +265 -17
  24. package/skills/teamsmith/scripts/strings/commands.tsv +3 -3
  25. package/skills/teamsmith/scripts/strings/help.en.tsv +12 -12
  26. package/skills/teamsmith/scripts/strings/help.zh.tsv +12 -12
  27. package/skills/teamsmith/scripts/team +3 -3
  28. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +2 -3
  29. package/skills/teamsmith/templates/pm-prompt.md.tmpl +11 -5
  30. package/skills/teamsmith/tests/death-cause.sh +5 -0
  31. package/skills/teamsmith/tests/help-surface.sh +15 -150
  32. package/skills/teamsmith/tests/isolation-ledger.sh +85 -0
  33. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +17 -1
  34. package/skills/teamsmith/tests/live-capture-probe.sh +12 -2
  35. package/skills/teamsmith/tests/pulse-nudge-key.sh +5 -0
  36. package/skills/teamsmith/tests/remind-delivery-node.mjs +176 -0
  37. package/skills/teamsmith/tests/remind-delivery.sh +611 -0
  38. package/skills/teamsmith/tests/section-paths.tsv +6 -6
  39. package/skills/teamsmith/tests/smoke.sh +397 -107
  40. package/skills/teamsmith/tests/state-authority.sh +246 -26
  41. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +58 -8
  42. package/skills/teamsmith/tests/tmux-identity-leak.sh +12 -16
  43. package/skills/teamsmith-init/SKILL.md +1 -1
package/README.md CHANGED
@@ -57,14 +57,14 @@ than replaced (`--force` replaces only an entry recognised as this skill).
57
57
  ### As a Pi package (no global CLI)
58
58
 
59
59
  ```bash
60
- pi install git:git@github.com:Track07-cda/teamsmith@v0.4.0 # user level: every project
61
- pi install -l git:git@github.com:Track07-cda/teamsmith@v0.4.0 # project level: recorded in .pi/settings.json
60
+ pi install git:git@github.com:Track07-cda/teamsmith@v0.4.6 # user level: every project
61
+ pi install -l git:git@github.com:Track07-cda/teamsmith@v0.4.6 # project level: recorded in .pi/settings.json
62
62
  ```
63
63
 
64
64
  - **Pin a released tag**: `@v<version>`, the version `team version` prints. Latest tag:
65
65
  `git tag --sort=-v:refname | head -1`.
66
- - The `git@github.com:` form (or `ssh://git@github.com/Track07-cda/teamsmith@v0.4.0`) uses your SSH key and works
67
- whether or not you have a token; the shorthand `git:github.com/Track07-cda/teamsmith@v0.4.0` takes the HTTPS
66
+ - The `git@github.com:` form (or `ssh://git@github.com/Track07-cda/teamsmith@v0.4.6`) uses your SSH key and works
67
+ whether or not you have a token; the shorthand `git:github.com/Track07-cda/teamsmith@v0.4.6` takes the HTTPS
68
68
  route, so it works anonymously on the public repository and asks for credentials if your access is private.
69
69
  - The clone lands in `~/.pi/agent/git/<host>/<path>` (user level) or `.pi/git/<host>/<path>` (project level); the
70
70
  skill directory — the `<skill>` used in every command below — is `<clone>/skills/teamsmith`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamsmith",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Turn one agent session into a project owner: self-contained task briefs dispatched to worker agents in their own git worktrees, independent verification on a separate checkout, and an auditable ledger (BOARD / reviews / threads / DECISIONS). Runs on Pi today.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -3,7 +3,19 @@
3
3
  > 版本号单一来源:`scripts/lib/common.sh` 的 `TEAM_VERSION`(`SKILL.md` 的 `metadata.version` 必须一致,
4
4
  > `team version --check` 会检查)。**更新怎么拿到**:`scripts/**` 每次调用现读盘(零操作);
5
5
  > `SKILL.md`/`references/**`/`templates/**`/`extension/**` 在 Pi 里输入 `/reload`(或 `/pi-team-reload`)即生效;
6
- > 判断自己是不是旧的:`team mark-loaded`(开局记一次)→ `team version --check`。
6
+ > 判断自己是不是旧的:`team version --check`(按 PM 启动时刻与 skill 文件时间推导)。
7
+
8
+ ## v0.4.6(2026-11-06)
9
+
10
+ 提醒到点会真的叫醒 PM;`team say` 插在对方下一次调用模型之前;详情页不再拒绝项目内的软链。
11
+
12
+ - **提醒**:`team remind add 20m "…"` 到点后由巡检送入 PM 会话。待命期间照样叫;只有确认消息进了会话才退出待命,且一次只退一次。送达失败不自动重发,记成「未知」由人确认(`team remind resolve <批次> --ack-unknown`)。PM 正忙时消息会等它这一轮结束,可能超过 60 秒确认窗而先记成「未知」,迟到的回执会补正。
13
+ - **待命开关**:不再单独一个文件,读写与提醒同一份状态、同一把锁;旧标记用 `team standby migrate` 一次性并入,原因与时间保留,重复执行不再写。
14
+ - **指令投递**:`team say` 改用 `steer`,插在对方下一次调用模型之前;通知与巡检唤醒保持原节奏。只能在两次工具调用之间落地,对方正卡在长工具调用里仍要等它返回。
15
+ - **详情页**:按落点判软链——项目根内正常打开(含跨 change、指向 archive 的别名),项目根外、FIFO、设备仍拒绝并点名。
16
+ - 提示词统一为「长命令后台跑,不要在回合内等」;状态目录按项目解析,显式指定别的项目的状态根会被拒绝。
17
+
18
+ 升级方式:`npm i -g teamsmith@0.4.6`,重启 PM。
7
19
 
8
20
  ## v0.4.5(2026-11-05)
9
21
 
@@ -3,7 +3,7 @@ name: teamsmith
3
3
  description: teamsmith gives one agent real ownership of a project — it plans, writes self-contained task briefs, dispatches worker agents into their own tmux windows and git worktrees, verifies their work on an independent checkout, merges, and keeps an auditable ledger (BOARD/reviews/threads/DECISIONS). A pulse window (the periodic patrol) wakes the owner only when there is pending work, and the owner can deliberately stand down. Works with Pi; the launch/notify seam is an internal seam (frozen) reserved for a possible future non-Pi adapter, with no compatibility promise. Use when the user wants an agent to own a project end to end, dispatch tasks to worker agents, run agents in parallel in tmux with git worktree isolation, act as a PM/orchestrator over other agents, review an agent's work independently, run the patrol (`pulse`) as a tmux window, wake the PM only when there is pending work, or resume and coordinate a multi-agent project. To start a new project, use the teamsmith-init skill.
4
4
  license: MIT
5
5
  metadata:
6
- version: "0.4.5"
6
+ version: "0.4.6"
7
7
  ---
8
8
 
9
9
  # teamsmith · one agent that actually owns the project
@@ -54,11 +54,10 @@ const CMD_ELLIPSIS = '…'
54
54
  * ③ **原地等是有界例外**:预算(约 2 分钟)+ 结果卡住下一步 + 没有别的任务可推进,三条**同时**成立。
55
55
  * 任何面都不得再出现「回合结束前必须收割」的措辞,也不得把叫醒写成惩罚/损失。
56
56
  */
57
- const INLINE_WAIT_BUDGET = '~2 minutes'
58
57
  const SUSPEND_DEFAULT =
59
58
  'End your turn after starting; the completion wake-up (several completions merge into one message) is the normal harvest point.'
60
- const INLINE_WAIT_EXCEPTION =
61
- `Wait inline only in the bounded exception: all three must hold -- the job should finish within the inline-wait budget (${INLINE_WAIT_BUDGET}), its result blocks your immediate next step, and no other task work can advance meanwhile.`
59
+ const NO_INLINE_WAIT =
60
+ 'Do not wait inside the turn (`sleep`, `team wait`, a blocking harvest): end the turn instead.'
62
61
 
63
62
  /**
64
63
  * 定位**本会话自己的根**:team-bg 的产物(作业日志、账本、合并窗口)都是会话本地的,
@@ -274,12 +273,12 @@ export default function (pi: ExtensionAPI) {
274
273
  description:
275
274
  'Start a long command (a gate, a build) as a detached background job and return immediately with a job id. ' +
276
275
  `Output goes to state/bg/<id>.log (bounded). ${SUSPEND_DEFAULT} Then run team_bg_wait <id> there to harvest it. ` +
277
- INLINE_WAIT_EXCEPTION,
276
+ NO_INLINE_WAIT,
278
277
  promptSnippet:
279
278
  'team_bg_run: start a long command in the background and end your turn ' +
280
279
  '(returns a job id immediately; the completion wake-up is the normal harvest point)',
281
280
  promptGuidelines: [
282
- `Use team_bg_run for long gates or builds. ${SUSPEND_DEFAULT} ${INLINE_WAIT_EXCEPTION}`,
281
+ `Use team_bg_run for long gates or builds. ${SUSPEND_DEFAULT} ${NO_INLINE_WAIT}`,
283
282
  ],
284
283
  parameters: {
285
284
  type: 'object',
@@ -331,7 +330,7 @@ export default function (pi: ExtensionAPI) {
331
330
  trimTimer = setInterval(() => { for (const j of jobs.values()) if (!j.done) trimLog(j.log) }, TRIM_EVERY_MS)
332
331
  }
333
332
  return {
334
- content: [{ type: 'text', text: `job ${id} started (pid ${job.pid}); log: ${log}\n cmd: ${displayCmd(command)}\n${SUSPEND_DEFAULT} Harvest job ${id} with team_bg_wait when that wake-up arrives (the result comes back inline). ${INLINE_WAIT_EXCEPTION}` }],
333
+ content: [{ type: 'text', text: `job ${id} started (pid ${job.pid}); log: ${log}\n cmd: ${displayCmd(command)}\n${SUSPEND_DEFAULT} Harvest job ${id} with team_bg_wait when that wake-up arrives (the result comes back inline). ${NO_INLINE_WAIT}` }],
335
334
  details: { id, pid: job.pid, log, cwd, cmd: command },
336
335
  }
337
336
  },
@@ -342,9 +341,9 @@ export default function (pi: ExtensionAPI) {
342
341
  label: 'Team background job wait',
343
342
  description:
344
343
  'Wait for a job started by team_bg_run, harvest it and return its exit code plus the log tail inline. ' +
345
- `${SUSPEND_DEFAULT} ${INLINE_WAIT_EXCEPTION}`,
344
+ `${SUSPEND_DEFAULT} ${NO_INLINE_WAIT}`,
346
345
  promptSnippet:
347
- 'team_bg_wait: harvest a team_bg_run job (waits if it is still running; the completion wake-up is the normal harvest point)',
346
+ 'team_bg_wait: harvest a finished team_bg_run job (after its completion wake-up; never as a poll)',
348
347
  parameters: {
349
348
  type: 'object',
350
349
  properties: {
@@ -9,8 +9,11 @@
9
9
  * 1. 发送方(outbox.sh)把消息写进 **durable 收件箱** `docs/team/inbox/<name>.md`(唯一真相);
10
10
  * 2. 再往本项目 `state/inbox-watch/<key>.wake` 追加**一行指针**(kind / from / inbox / 截断预览);
11
11
  * 3. 本扩展 `fs.watch` 那个目录,读到新行就
12
- * `pi.sendMessage({customType:'team-inbox'}, …, {triggerTurn:true, deliverAs:'followUp'})`
12
+ * `pi.sendMessage({customType:'team-inbox'}, …, {triggerTurn:true, deliverAs:<按类别>})`
13
13
  * —— 消息进会话队列(agent 空闲时立刻触发一轮),输入框一个键都不碰。
14
+ * `deliverAs` 由**消息类别**决定(P419,不看批量大小):批里只要有一条 `kind=say`(PM 发给席位的
15
+ * 指令)→ `steer`(本次工具调用结束后、下一次模型请求之前落地,插得进正在跑的那一轮);其余
16
+ * (notify / nudge / knock / draft 回执…)→ `followUp`(等这一轮没有更多工具调用)。
14
17
  *
15
18
  * 就绪注册(发送方据此判定「目标是 pi 且有监视」):`state/inbox-watch/<key>.reg` 里写
16
19
  * target / inbox / pid / cwd / started / heartbeat;心跳每 HEARTBEAT_MS 刷新。`team_inbox_watch_route`
@@ -74,6 +77,7 @@ import { execFileSync } from 'node:child_process'
74
77
  import { createHash } from 'node:crypto'
75
78
  import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, watch, writeFileSync } from 'node:fs'
76
79
  import { basename, dirname, join, resolve } from 'node:path'
80
+ import { fileURLToPath, pathToFileURL } from 'node:url'
77
81
 
78
82
  const DEFAULT_PREVIEW = 160 // 预览截断(字符):唤醒消息只带一行指针,不带全文
79
83
  const DEFAULT_MAX_BYTES = 128 * 1024 // spool 上限
@@ -853,6 +857,7 @@ export default function (pi: ExtensionAPI) {
853
857
  let pollTimer: ReturnType<typeof setInterval> | null = null
854
858
  let beatTimer: ReturnType<typeof setInterval> | null = null
855
859
  let mergeTimer: ReturnType<typeof setTimeout> | null = null
860
+ let remindTimer: ReturnType<typeof setInterval> | null = null
856
861
 
857
862
  const stopAll = (): void => {
858
863
  try { watcher?.close?.() } catch { /* ignore */ }
@@ -862,6 +867,7 @@ export default function (pi: ExtensionAPI) {
862
867
  if (pollTimer) { clearInterval(pollTimer); pollTimer = null }
863
868
  if (beatTimer) { clearInterval(beatTimer); beatTimer = null }
864
869
  if (mergeTimer) { clearTimeout(mergeTimer); mergeTimer = null }
870
+ if (remindTimer) { clearInterval(remindTimer); remindTimer = null }
865
871
  }
866
872
 
867
873
  let headBytes: Buffer | null = null // 上次建立 offset 时的头部前缀(B2 的回退证据)
@@ -1081,11 +1087,19 @@ export default function (pi: ExtensionAPI) {
1081
1087
 
1082
1088
  const shortError = (error: unknown): string => oneLine(String((error as Error)?.message ?? error ?? 'unknown'), 160)
1083
1089
 
1090
+ /** P419 · 投递模式按**消息类别**选,不看批量大小:批里只要有一条 `kind=say`(PM 发给席位的指令),
1091
+ * 整批用 `steer` —— 本次工具调用结束后、下一次模型请求之前落地,插得进正在跑的那一轮;
1092
+ * 其余(notify / nudge / knock / draft 回执…)保持 `followUp`(等这一轮没有更多工具调用)。
1093
+ * 已知极限:`steer` 也只能落在两次工具调用之间 —— 席位卡在一个长工具调用里时,仍要等那次返回。 */
1094
+ const deliverModeOf = (lines: SpoolLine[]): 'steer' | 'followUp' =>
1095
+ lines.some(l => l.kind === 'say') ? 'steer' : 'followUp'
1096
+
1084
1097
  /** P81 · 唯一的发送出口:写前记录(read → intent)→ 发送 → sent/failed。
1085
1098
  * `intent` 没写成**绝不发送**(fail-closed);API 拒了记 `failed`,下一拍重试。 */
1086
1099
  const sendWake = (lines: SpoolLine[], meta: WakeMeta = {}): 'ok' | 'failed' | 'blocked' => {
1087
1100
  if (!lines.length) return 'ok'
1088
1101
  const seq = seqCounter++
1102
+ const deliverAs = deliverModeOf(lines)
1089
1103
  const off = meta.off ?? offset
1090
1104
  const size = meta.size ?? fileSize(spool)
1091
1105
  const head = meta.head ?? headStamp(readHead(spool, size))
@@ -1104,7 +1118,7 @@ export default function (pi: ExtensionAPI) {
1104
1118
  if (abortAt === 'intent') fixtureAbort()
1105
1119
  try {
1106
1120
  pi.sendMessage({ customType: 'team-inbox', content: wakeText(seq, lines, meta), display: true },
1107
- { triggerTurn: true, deliverAs: 'followUp' })
1121
+ { triggerTurn: true, deliverAs })
1108
1122
  } catch (error) {
1109
1123
  journalAppend(`failed seq=${seq} reason=${jesc(shortError(error))}`)
1110
1124
  appendLedger(root,
@@ -1123,7 +1137,7 @@ export default function (pi: ExtensionAPI) {
1123
1137
  recoveryQueue.delete(l.identity)
1124
1138
  }
1125
1139
  appendLedger(root,
1126
- `wake n=${lines.length} total=${seen} inbox=${inbox} kinds=${lines.map(l => l.kind).join(',')} seq=${seq} ids=${lines.map(l => l.identity).join('|')}` +
1140
+ `wake n=${lines.length} total=${seen} inbox=${inbox} kinds=${lines.map(l => l.kind).join(',')} seq=${seq} ids=${lines.map(l => l.identity).join('|')} deliver=${deliverAs}` +
1127
1141
  (meta.recovery ? ` recovery n=${lines.length}` : '') +
1128
1142
  (meta.retry ? ' retry=1' : '') +
1129
1143
  (meta.dup !== undefined ? ` rescan[dup=${meta.dup} skipped=${meta.skipped ?? 0}]` : ''))
@@ -1307,6 +1321,121 @@ export default function (pi: ExtensionAPI) {
1307
1321
  }
1308
1322
  }
1309
1323
 
1324
+ // ---------------------------------------------------------------- Reminder wake (P423 · 3.1/3.2)
1325
+ // The PM's self-Reminders are delivered here and only here. The authority freezes one batch as an intent
1326
+ // (full text + the Standby generation bound before the call); this watcher submits it as ONE
1327
+ // non-interrupting custom message, and the public message_start of that very message -- matched by batch
1328
+ // id, nonce and member set -- is what records the wake and may switch Standby off once. Nothing is typed
1329
+ // into the editor, and nothing is resent because a call returned, threw or was deferred.
1330
+ let remindRoot = ''
1331
+ let remindState = ''
1332
+ let remindSession = ''
1333
+ let remindAuthority: any = null
1334
+ let remindModule: any = null
1335
+ let remindBusy = false
1336
+ let remindWarned = ''
1337
+
1338
+ const reminderPollMs = (): number => {
1339
+ const n = Number(process.env.TEAM_REMIND_POLL_MS ?? NaN)
1340
+ return Number.isFinite(n) && n >= 200 ? n : 2000
1341
+ }
1342
+
1343
+ const defaultStateRoot = (): string => join(remindRoot, '.pi/team/state')
1344
+
1345
+ const reminderPoll = async (): Promise<void> => {
1346
+ if (remindBusy || !remindRoot || !remindAuthority || !remindModule) return
1347
+ remindBusy = true
1348
+ try {
1349
+ const seen = await remindAuthority.peek({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: defaultStateRoot() })
1350
+ if (!seen.pinned) return
1351
+ remindState = String(seen.stateRoot ?? '')
1352
+ const pending = seen.reminders ?? { due: [], queued: [], staleIntent: [] }
1353
+ // Nothing to freeze: no queued item and no intent past its observation deadline. A batch in flight is
1354
+ // closed by the observation handler, not by polling the authority every couple of seconds.
1355
+ if (!pending.queued.length && !pending.staleIntent.length) return
1356
+ const res = await remindAuthority.request({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: remindState }, {
1357
+ op: 'remind-intent', session: remindSession, pid: process.pid,
1358
+ })
1359
+ if (!res || res.action !== 'send') {
1360
+ // An unknown batch (or one still in flight) blocks the next freeze. Say it once per batch, not per tick.
1361
+ if (res?.action === 'wait' && res.batch && remindWarned !== res.batch) {
1362
+ remindWarned = res.batch
1363
+ appendLedger(root, `reminder waiting batch=${res.batch} phase=${res.phase ?? 'intent'}(${oneLine(String(res.reason ?? ''), 160)})`)
1364
+ }
1365
+ return
1366
+ }
1367
+ const batch = res.batch
1368
+ const mod = remindModule
1369
+ try {
1370
+ pi.sendMessage({
1371
+ customType: mod.REMINDER_CUSTOM_TYPE, content: mod.reminderContent(batch), display: true,
1372
+ details: mod.reminderDetails(batch),
1373
+ }, { triggerTurn: true, deliverAs: 'followUp' })
1374
+ appendLedger(root, mod.deliveryLogLine(batch, 'intent-sent'))
1375
+ } catch (error) {
1376
+ // A throw is not a receipt: the batch becomes unknown (visible, no automatic resend).
1377
+ try {
1378
+ await remindAuthority.request({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: remindState }, {
1379
+ op: 'remind-fail', id: batch.id, nonce: batch.nonce, reason: oneLine(shortError(error), 300),
1380
+ })
1381
+ } catch (second) {
1382
+ appendLedger(root, `reminder fail-record blocked batch=${batch.id}(${oneLine(shortError(second), 160)})`)
1383
+ }
1384
+ appendLedger(root, `reminder send-failed batch=${batch.id}(会话 API 拒绝;批次保持 unknown,不自动重发)`)
1385
+ }
1386
+ } catch (error) {
1387
+ appendLedger(root, `reminder tick failed: ${oneLine(shortError(error), 200)}`)
1388
+ } finally {
1389
+ remindBusy = false
1390
+ }
1391
+ }
1392
+
1393
+ const startReminderWatch = async (ctx: any): Promise<void> => {
1394
+ try {
1395
+ const skill = dirname(dirname(fileURLToPath(import.meta.url)))
1396
+ remindAuthority = await import(pathToFileURL(join(skill, 'scripts/state-authority.mjs')).href)
1397
+ remindModule = await import(pathToFileURL(join(skill, 'scripts/reminder-delivery.mjs')).href)
1398
+ if (typeof remindAuthority.peek !== 'function' || typeof remindAuthority.request !== 'function' ||
1399
+ typeof remindModule.reminderContent !== 'function' || typeof remindModule.matchesObservation !== 'function') {
1400
+ throw new Error('the reminder modules did not export the expected entry points')
1401
+ }
1402
+ remindRoot = root
1403
+ remindSession = String(ctx?.sessionManager?.getSessionId?.() ?? '')
1404
+ if (!remindSession) throw new Error('this session has no id: a batch intent must bind the session that may observe it')
1405
+ remindTimer = setInterval(() => { void reminderPoll() }, reminderPollMs())
1406
+ appendLedger(root, `reminder watch on session=${remindSession} poll=${reminderPollMs()}ms`)
1407
+ void reminderPoll() // restart recovery: a queued item from before this process is delivered now
1408
+ } catch (error) {
1409
+ remindAuthority = null
1410
+ remindModule = null
1411
+ if (remindTimer) { clearInterval(remindTimer); remindTimer = null }
1412
+ appendLedger(root, `reminder watch disabled: ${oneLine(shortError(error), 200)}`)
1413
+ }
1414
+ }
1415
+
1416
+ // The observation. `sendMessage` returning, a thrown error or a deferred action never reach this path;
1417
+ // only Pi's own message_start for our custom message, with the frozen batch's identity, does.
1418
+ pi.on('message_start', async (event: any) => {
1419
+ if (!remindAuthority || !remindRoot) return
1420
+ const message = event?.message
1421
+ const details = message?.details
1422
+ if (message?.role !== 'custom' || message?.customType !== 'team-reminder' || !details?.batchId) return
1423
+ try {
1424
+ const res = await remindAuthority.request({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: remindState || defaultStateRoot() }, {
1425
+ op: 'remind-observe', id: String(details.batchId), nonce: String(details.nonce ?? ''), session: remindSession,
1426
+ })
1427
+ if (!res?.ok) {
1428
+ appendLedger(root, `reminder observation refused (${res?.refusal ?? 'unknown'}): ${oneLine(String(res?.reason ?? ''), 200)}`)
1429
+ } else if (res.outcome === 'duplicate') {
1430
+ appendLedger(root, `reminder duplicate event batch=${res.batch}(right 已花掉;未再退待命)`)
1431
+ } else {
1432
+ appendLedger(root, `reminder observed batch=${res.batch} standby=${res.standby} generation=${res.generation} ids=${(res.ids ?? []).join('|')}`)
1433
+ }
1434
+ } catch (error) {
1435
+ appendLedger(root, `reminder observation failed: ${oneLine(shortError(error), 200)}`)
1436
+ }
1437
+ })
1438
+
1310
1439
  pi.on('session_start', async (_event: any, ctx: any) => {
1311
1440
  stopAll()
1312
1441
  root = findRoot(String(ctx?.cwd ?? process.cwd()))
@@ -1425,6 +1554,8 @@ export default function (pi: ExtensionAPI) {
1425
1554
  armFileWatcher() // spool 可能早已存在(上一任会话留下的):文件级 watcher 现在就 arm 上
1426
1555
  pollTimer = setInterval(() => { try { flush() } catch { /* ignore */ } }, pollMs())
1427
1556
  beatTimer = setInterval(() => { try { writeReg('ready') } catch { /* ignore */ } }, heartbeatMs())
1557
+ // Reminder delivery is the PM's path: a worker window never binds a batch or observes a wake.
1558
+ if (inbox === 'pm') await startReminderWatch(ctx)
1428
1559
  })
1429
1560
 
1430
1561
  pi.on('session_shutdown', async () => {
@@ -1439,5 +1570,7 @@ export default function (pi: ExtensionAPI) {
1439
1570
  headBytes = null; lastShrink = null
1440
1571
  journalPath = ''; journalEntries = new Map(); retryQueue = new Map(); recoveryQueue = new Map()
1441
1572
  delivered = new Set(); floorTs = null; floorId = ''; journalRecords = 0; abortAt = ''
1573
+ remindRoot = ''; remindState = ''; remindSession = ''; remindAuthority = null; remindModule = null
1574
+ remindBusy = false; remindWarned = ''
1442
1575
  })
1443
1576
  }
@@ -121,9 +121,8 @@ Guards and limitations:
121
121
  `awaiting=` too when its jobs are alive). A suspension omits the `⚠ 未提交` prefix — it is not a delivery claim —
122
122
  while `uncommitted=<n>` stays. The three states are **delivered**, **hard-blocked** and
123
123
  **suspended on background jobs**, and the lane rule is the suspend default: `team_bg_run` starts a long job and
124
- the turn ends; the completion wake-up is the normal harvest point; in-turn waiting is the bounded exception,
125
- only inside the inline-wait budget (about 2 minutes), when the result blocks the next step and nothing else can
126
- advance. A seat that suspended and then died needs no new patrol clause: an unfinished task with no live window
124
+ the turn ends; the completion wake-up is the normal harvest point. Do not wait inline: the user cannot type while
125
+ the PM waits. A seat that suspended and then died needs no new patrol clause: an unfinished task with no live window
127
126
  is already pending work (§8).
128
127
  - The **other** injected extension is `extension/team-bg.ts` (M27) — not notification, but the team's own
129
128
  background lane: `team_bg_run` starts a detached job (bounded `state/bg/<id>.log`), `team_bg_wait <id>` harvests
@@ -4,18 +4,26 @@ A reminder is a durable one-shot note the project PM leaves for itself: "come ba
4
4
  time". It is stored in the same versioned project state as the rest of teamsmith, so it survives a
5
5
  restart, a lost session and a new checkout, and it is the only copy of that decision.
6
6
 
7
- This page is the operator's manual for the part that exists today: recording, reading and cancelling
8
- a reminder. It does not describe delivery, because this build does not deliver.
7
+ This page is the operator's manual: recording, reading, cancelling, and what happens when a reminder
8
+ comes due.
9
9
 
10
10
  ## What this build does and does not do
11
11
 
12
12
  - Records a reminder with its full text, its due instant, its source and an optional key and task.
13
13
  - Lists what is waiting, when it is due, and whether it is due *now*; shows one record in full;
14
- cancels a reminder that has not been frozen for delivery.
15
- - Does **not** wake the PM, does not queue anything for delivery, and does not touch Standby. A due
16
- reminder is shown as `derived-due` and stays there until the delivery part of the change reads it.
14
+ cancels a reminder that has not been frozen into a batch.
15
+ - Queues a reminder when it comes due (the pulse's own ten-second due check) and delivers it — as one
16
+ complete message, one batch at a time — into the verified PM session through the inbox watcher. The
17
+ message is a Pi custom message: nothing is typed into the editor and a draft is never touched.
18
+ - Leaves Standby once, and only after the wake is actually observed. Being due, queued, frozen or
19
+ refused does **not** leave Standby, and a newer Standby generation is never cleared by an older
20
+ batch.
21
+ - Does **not** resend a batch whose delivery cannot be proven: it becomes `unknown` and waits for an
22
+ operator (`team remind resolve <batch> --ack-unknown`).
17
23
  - Does **not** accept a project, an owner or a recipient from the caller: those come from the
18
24
  checkout the command runs in and from the authority itself.
25
+ - Does **not** start a stopped PM for a reminder, and does not expose a PM model tool: the CLI is the
26
+ way this build creates reminders, and a queued reminder waits for the session that comes back.
19
27
 
20
28
  ## Where the state lives
21
29
 
@@ -98,10 +106,44 @@ and the clock:
98
106
  | `cancelled` | withdrawn before delivery was frozen |
99
107
  | `resolved` | an operator acknowledged an unknown batch |
100
108
 
101
- `due` is not `queued`: a reminder can be overdue for a long time and still never have been sent. This
102
- build produces only `scheduled`, `cancelled` and, from the clock, `derived-due`; the other phases are
103
- written by the delivery and Pulse tasks of the same change, and this reader already shows them
104
- because it derives from the snapshot rather than from a second copy.
109
+ `due` is not `queued`: a reminder can be overdue for a long time and still never have been sent.
110
+ All of these phases are produced by this build; the reader derives the view from the snapshot rather
111
+ than from a second copy, so a record written by any process shows up the same way in every reader.
112
+
113
+ ## Delivery
114
+
115
+ The delivery path has four separate facts, and each one is durable before the next step:
116
+
117
+ 1. **Due admission.** Both pulse shapes (the console and the headless tick loop) run a lightweight
118
+ check about every ten seconds, apart from the full patrol. A due reminder is committed as `queued`
119
+ with a queue order and its enqueue time; a repeated scan never creates a second queue entry. An
120
+ item is marked `overdue` when its due instant predates the pulse instance that admitted it (a
121
+ catch-up after a restart) or when admission lagged due by more than 30 seconds — an ordinary
122
+ polling delay is not labelled overdue. A reminder still arriving 5 seconds late is normal; one
123
+ that arrives 5 minutes late says so.
124
+ 2. **One frozen batch.** The PM session's inbox watcher freezes at most eight queued reminders into
125
+ one batch, records the intent — every member, the full text, the correlation nonce and the current
126
+ Standby generation — and only then calls Pi. One batch is outstanding at a time; at most one
127
+ submission per five seconds. Nothing is written into the editor and the input draft is untouched.
128
+ 3. **Observation.** Pi's own `message_start` for that custom message, carrying the batch id and the
129
+ nonce, is the only thing that counts as a wake. A return value, a thrown error, a deferred action
130
+ or an unrelated run is not. The observation, the consumed right and the Standby exit commit in one
131
+ atomic snapshot with an audit line naming the batch and every reminder id and source.
132
+ 4. **Standby.** A reminder may wake a PM that is on standby (this is the one wake that Standby does
133
+ not suppress). If the generation bound at intent is still the current one, the same observation
134
+ transaction switches standby off — once per batch, never twice. If a newer generation exists, it
135
+ is preserved and the outcome is reported as `generation-ambiguous`. If standby was already
136
+ manually off, the audit says `already-off` rather than inventing an automatic exit.
137
+
138
+ If the session API refuses the message, the batch becomes `unknown` (visible in `team remind list`),
139
+ its members stop being independently sendable and nothing resends automatically: a call returning or
140
+ throwing is not a receipt. `team remind resolve <batch-id> --ack-unknown` is the operator's explicit
141
+ acknowledgment — it closes every member of that batch, burns its remaining right and reports the ids
142
+ without claiming delivery.
143
+
144
+ After a restart, `queued` reminders are still queued and are delivered by the next watcher; an intent
145
+ that never saw an observation past its 60-second deadline becomes `unknown` instead of being resent;
146
+ `observed` and `resolved` reminders are never queued again.
105
147
 
106
148
  ## Retention and the issued high-water
107
149
 
@@ -126,6 +168,7 @@ revived or sent.
126
168
 
127
169
  ## Not in this build
128
170
 
129
- Pulse admission, the PM wake-up and its message, Standby interaction, the configurable limits (active
130
- count, message bytes, create rate) and the PM-only tool are later tasks of the same change. Until
131
- they land, a reminder is a durable note that a person reads — it does not summon anyone.
171
+ The PM-only model tool, starting a stopped PM for a reminder (the prompt-free handoff), and the
172
+ configurable limits (active count, message bytes, create rate) are later tasks of the same change.
173
+ Until they land, the CLI is how a reminder is created and a queued reminder waits for a PM session
174
+ that is running.
@@ -194,9 +194,7 @@ The four rules that make it safe (they are the extension's code, not a conventio
194
194
  1. **End the turn after starting; the completion wake-up is the normal harvest point.** The tool returns at once,
195
195
  so the turn is free: end it, and when the job finishes and you are idle you are woken once (several jobs
196
196
  finishing together arrive as one message) to run `team_bg_wait <id>`; a harvested job stays silent (its result
197
- came back inline). In-turn waiting is the bounded exception: use it only when all three hold -- the job is
198
- expected to finish within the inline-wait budget (about 2 minutes), its result blocks your immediate next step,
199
- and no other task work can advance meanwhile. A turn that ends with this session's jobs still running is
197
+ came back inline). Do not wait inside the turn: it blocks the user's input. A turn that ends with this session's jobs still running is
200
198
  **suspended on background jobs** -- a third legal ending beside **delivered** and **hard-blocked**, not a
201
199
  delivery and not a blockage, and its last line names every awaited job id.
202
200
  2. **The ledger is on disk**: `team_bg_run` appends `<ISO timestamp> start id=<id> pid=<pid>` before it returns the
@@ -128,7 +128,7 @@ team_build_prompt() { # <agent> <ID> <taskfile-abs> <worktree> <model> [<session
128
128
  # 其它 adapter 不提:工具不存在,教了只会让 worker 白找。
129
129
  case "${TEAM_AGENT_CMD:-}" in
130
130
  ''|*'{bg_ext}'*)
131
- bg_block="$(printf '\n**Long jobs (a gate, a build)**: start them with `team_bg_run` (it returns a job id immediately and keeps\nworking while you go on), then **end your turn** -- the completion wake-up is the normal harvest point: when the\njob finishes you are woken once (several jobs finishing together arrive as one message) and harvest it with\n`team_bg_wait <id>` (the exit code and the log tail come back inline). **In-turn waiting is the bounded\nexception**: use it only when all three hold -- the job is expected to finish within the inline-wait budget (about 2 minutes),\nits result blocks your immediate next step, and no other task work can advance meanwhile.\n')" ;;
131
+ bg_block="$(printf '\n**Long jobs (a gate, a build)**: start them with `team_bg_run` (it returns a job id immediately and keeps\nworking while you go on), then **end your turn** -- the completion wake-up is the normal harvest point: when the\njob finishes you are woken once (several jobs finishing together arrive as one message) and harvest it with\n`team_bg_wait <id>` (the exit code and the log tail come back inline). Do not wait inside the turn (`sleep`, `team wait`, a blocking harvest).\n')" ;;
132
132
  esac
133
133
 
134
134
  cat <<PROMPT
@@ -675,11 +675,24 @@ team_df_raw_err() { _TEAM_DF_ERR="${_TEAM_DF_ERR}${1:-}"$'\n'; }
675
675
  team_df_lines_raw_err() { local t="${1:-}" line; [ -n "$t" ] || return 0; while IFS= read -r line; do team_df_raw_err "$line"; done <<< "$t"; }
676
676
  team_df_lines_err() { local t="${1:-}" line; [ -n "$t" ] || return 0; while IFS= read -r line; do team_df_err "$line"; done <<< "$t"; }
677
677
  team_df_lines_dim() { local t="${1:-}" line; [ -n "$t" ] || return 0; while IFS= read -r line; do team_df_dim "$line"; done <<< "$t"; }
678
+ team_df_has_block() { # <一段输出> → 0 = 里面已经有 ✗ 行(阻塞项有具体原因)
679
+ case "${1:-}" in *✗*) return 0 ;; esac
680
+ return 1
681
+ }
682
+ # P420 · 判不了就是阻塞,但不许无声:守卫 rc≠0 却一行 ✗ 都没写时,补一条点名它的阻塞行。
683
+ # 现场:某个守卫只 warn(`!`)后 return 1,report 只重放那条警告,末行却是「共 1 个阻塞项」——
684
+ # 人看得见计数、看不见是哪一项,于是只能猜。守卫名 = 传进来的第一个词(函数名)。
685
+ team_df_block_reason() { # <守卫名> <rc> → 一行 ✗(结尾有换行;由调用方写进自己的缓冲)
686
+ printf '%s✗%s %s:判不了(rc=%s),没有任何具体原因\n' "$C_RED" "$C_RESET" "${1:-?}" "${2:-?}"
687
+ }
678
688
  # 一个守卫跑一趟:_TEAM_DF_RUN_RC = 这次守卫的 rc(driver 据此判「前提缺失 → 判不了」,不冒充查过)。
679
689
  team_df_run() { # <守卫函数> [参数…]
680
690
  _TEAM_DF_ERR=""; _TEAM_DF_OUT=""
681
691
  local rc=0; "$@" || rc=$?
682
692
  _TEAM_DF_RUN_RC="$rc"
693
+ if [ "$rc" -ne 0 ] && ! team_df_has_block "$_TEAM_DF_ERR"; then
694
+ _TEAM_DF_ERR="${_TEAM_DF_ERR}$(team_df_block_reason "${1:-?}" "$rc")"$'\n'
695
+ fi
683
696
  if [ "$rc" -eq 0 ]; then _TEAM_DF_NOTES+=("$_TEAM_DF_ERR"$'\x1f'"$_TEAM_DF_OUT")
684
697
  else _TEAM_DF_BLOCKS+=("$_TEAM_DF_ERR"$'\x1f'"$_TEAM_DF_OUT"); _TEAM_DF_N=$((_TEAM_DF_N + 1)); fi
685
698
  return 0
@@ -691,6 +704,10 @@ team_df_run_lib() { # <函数> [参数…]
691
704
  local rc=0 out=""
692
705
  out="$("$@" 2>&1)" || rc=$?
693
706
  _TEAM_DF_RUN_RC="$rc"
707
+ # P420 · 同上:库守卫非 0 却没有 ✗ 行时补一条,report 里必须点得出是哪一项。
708
+ if [ "$rc" -ne 0 ] && ! team_df_has_block "$out"; then
709
+ out="${out}$(team_df_block_reason "${1:-?}" "$rc")"$'\n'
710
+ fi
694
711
  [ -n "$out" ] && out="$out"$'\n'
695
712
  if [ "$rc" -eq 0 ]; then _TEAM_DF_NOTES+=("$out"$'\x1f'"")
696
713
  else _TEAM_DF_BLOCKS+=("$out"$'\x1f'""); _TEAM_DF_N=$((_TEAM_DF_N + 1)); fi
@@ -452,23 +452,19 @@ team_cmd_init() {
452
452
  }
453
453
 
454
454
  # ---------------------------------------------------------------- doctor
455
- # M7.1:这个项目要不要读迁移指南?两个判据都来自可查的真实状态,不猜:
455
+ # M7.1:这个项目要不要读迁移指南?判据来自可查的真实状态,不猜:
456
456
  # ① AGENTS.md 里还有围栏外的旧名标记 <!-- pi-team:begin -->(init 会就地改写;改写后不再触发)——
457
457
  # 判据是「可迁移的候选行」,所以正文里引用、缩进或围栏里的旧名示例不会让这条提示永不消失。
458
- # ② 本会话加载的 skill 比磁盘旧(mark-loaded 记的版本/指纹与磁盘不一致)—— 与 version --check 同口径
459
458
  # 干净项目上保持静默(doctor 不该多刷一行);返回原因字符串,没有原因则返回空。
459
+ # P417:以前这里还有第二条判据「本会话加载的 skill 比磁盘旧」——它读 `state/pm-loaded.env` 这份
460
+ # 由人记得写的记录,没人写就永远停在上一版。记录删掉了,会话新旧改由推导给出(见下面的「skill 新鲜度」)。
460
461
  team_migration_reasons() {
461
- local reasons="" f="$TEAM_MAIN_ROOT/AGENTS.md" loaded
462
+ local reasons="" f="$TEAM_MAIN_ROOT/AGENTS.md"
462
463
  # 只看「init 真会改的那两行」:围栏外、独占整行、逐字节等于旧名标记。正文引用、缩进
463
464
  # 或围栏里的旧名示例都不会被 init 改写,所以它们也不该让这条提示永不消失。
464
465
  if [ -f "$f" ] && [ "$(team_legacy_marker_candidates "$f" '<!-- pi-team:begin -->' '<!-- pi-team:end -->')" -gt 0 ]; then
465
466
  reasons="AGENTS.md 还是旧名标记"
466
467
  fi
467
- loaded="$(team_loaded_version 2>/dev/null || true)"
468
- if [ -n "$loaded" ] \
469
- && { [ "$loaded" != "$TEAM_VERSION" ] || [ "$(team_loaded_hash 2>/dev/null || true)" != "$(team_skill_hash 2>/dev/null || true)" ]; }; then
470
- reasons="${reasons:+$reasons;}本会话加载 $loaded、磁盘 $TEAM_VERSION"
471
- fi
472
468
  [ -n "$reasons" ] && printf '%s' "$reasons"
473
469
  return 0
474
470
  }
@@ -768,7 +764,7 @@ team_cmd_doctor() {
768
764
  fi
769
765
  fi
770
766
 
771
- # Disk, directed launch and actual process registration are separate evidence; mark-loaded is not runtime proof.
767
+ # Disk, directed launch and actual process registration are separate evidence; disk mtimes are not runtime proof.
772
768
  check "关键回复磁盘"
773
769
  if [ -f "$TEAM_SKILL_DIR/extension/team-reply.ts" ] && [ -f "$TEAM_SKILL_DIR/scripts/reply-capture.mjs" ]; then
774
770
  pass "捕获源码存在(不代表当前 PM 已加载)"
@@ -850,6 +846,13 @@ team_cmd_doctor() {
850
846
  check "迁移指引"; warn "$mig:读 $TEAM_SKILL_DIR/references/migration.md(重命名 / 已删命令 / 必需依赖 / 行为变更 / 升级配方 / 回滚)"
851
847
  fi
852
848
 
849
+ # P417:skill 比这台 PM 新吗?由「PM 进程启动时刻 vs skill 文件最近 mtime」推导,不维护任何记录。
850
+ # 磁盘比进程新才说话(给出那个时间与 /reload);没有 PM 在跑时不谈会话;都没问题就整行不出现。
851
+ local skill_stale; skill_stale="$(team_skill_stale_line)"
852
+ if [ -n "$skill_stale" ]; then
853
+ check "skill 新鲜度"; warn "$skill_stale"
854
+ fi
855
+
853
856
 
854
857
  printf '\n'
855
858
  if [ "$fails" -gt 0 ]; then team_err "doctor: $fails 项失败 / $warns 项警告"; return 1; fi