teamsmith 0.4.5 → 0.4.7

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 (81) hide show
  1. package/README.md +6 -6
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +37 -1
  4. package/skills/teamsmith/SKILL.md +32 -23
  5. package/skills/teamsmith/extension/team-bg.ts +12 -11
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +149 -5
  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/migration.md +101 -0
  11. package/skills/teamsmith/references/openspec.md +43 -27
  12. package/skills/teamsmith/references/protocol.md +28 -18
  13. package/skills/teamsmith/references/reminders.md +133 -98
  14. package/skills/teamsmith/references/troubleshooting.md +12 -7
  15. package/skills/teamsmith/references/workflows.md +85 -34
  16. package/skills/teamsmith/scripts/lib/cmd-agents.sh +28 -5
  17. package/skills/teamsmith/scripts/lib/cmd-project.sh +100 -15
  18. package/skills/teamsmith/scripts/lib/cmd-remind.sh +135 -10
  19. package/skills/teamsmith/scripts/lib/cmd-review.sh +42 -4
  20. package/skills/teamsmith/scripts/lib/cmd-update.sh +90 -88
  21. package/skills/teamsmith/scripts/lib/cmd-watch.sh +322 -159
  22. package/skills/teamsmith/scripts/lib/common.sh +156 -26
  23. package/skills/teamsmith/scripts/panel/panel.js +182 -182
  24. package/skills/teamsmith/scripts/panel/src/data.ts +113 -6
  25. package/skills/teamsmith/scripts/panel/src/layout.ts +26 -4
  26. package/skills/teamsmith/scripts/panel/src/main.tsx +103 -14
  27. package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
  28. package/skills/teamsmith/scripts/remind-store.mjs +404 -17
  29. package/skills/teamsmith/scripts/remind-tick.mjs +105 -0
  30. package/skills/teamsmith/scripts/reminder-delivery.mjs +76 -0
  31. package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
  32. package/skills/teamsmith/scripts/state-authority.mjs +334 -20
  33. package/skills/teamsmith/scripts/strings/commands.tsv +3 -3
  34. package/skills/teamsmith/scripts/strings/help.en.tsv +12 -12
  35. package/skills/teamsmith/scripts/strings/help.zh.tsv +12 -12
  36. package/skills/teamsmith/scripts/team +4 -3
  37. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +13 -11
  38. package/skills/teamsmith/templates/DECISIONS.md.tmpl +2 -2
  39. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +3 -3
  40. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +19 -14
  41. package/skills/teamsmith/templates/memory-seed.md.tmpl +2 -2
  42. package/skills/teamsmith/templates/pm-prompt.md.tmpl +36 -18
  43. package/skills/teamsmith/templates/report.md.tmpl +33 -0
  44. package/skills/teamsmith/tests/bg-ledger-harness.mjs +217 -33
  45. package/skills/teamsmith/tests/bg-ledger.sh +24 -10
  46. package/skills/teamsmith/tests/checkout-shape-probe.sh +7 -6
  47. package/skills/teamsmith/tests/death-cause.sh +5 -0
  48. package/skills/teamsmith/tests/fixtures/remind-adversarial-delay.ts +27 -0
  49. package/skills/teamsmith/tests/fixtures/remind-tool-provider.ts +65 -0
  50. package/skills/teamsmith/tests/help-surface.sh +14 -151
  51. package/skills/teamsmith/tests/isolation-ledger.sh +89 -0
  52. package/skills/teamsmith/tests/key-replies-ui.sh +53 -0
  53. package/skills/teamsmith/tests/key-replies.sh +307 -106
  54. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +17 -1
  55. package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
  56. package/skills/teamsmith/tests/live-capture-probe.sh +12 -2
  57. package/skills/teamsmith/tests/loop-inventory.tsv +1 -0
  58. package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
  59. package/skills/teamsmith/tests/pulse-nudge-key.sh +5 -0
  60. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +163 -0
  61. package/skills/teamsmith/tests/remind-adversarial-faults.sh +26 -0
  62. package/skills/teamsmith/tests/remind-adversarial-real.sh +27 -0
  63. package/skills/teamsmith/tests/remind-cli.sh +108 -3
  64. package/skills/teamsmith/tests/remind-delivery-node.mjs +189 -0
  65. package/skills/teamsmith/tests/remind-delivery.sh +699 -0
  66. package/skills/teamsmith/tests/remind-lifecycle.sh +197 -0
  67. package/skills/teamsmith/tests/remind-pulse.sh +199 -0
  68. package/skills/teamsmith/tests/remind-recovery-real.sh +5 -0
  69. package/skills/teamsmith/tests/remind-recovery-unit.sh +118 -0
  70. package/skills/teamsmith/tests/remind-tool-node.mjs +159 -0
  71. package/skills/teamsmith/tests/remind-tool-real.mjs +754 -0
  72. package/skills/teamsmith/tests/remind-tool-real.sh +5 -0
  73. package/skills/teamsmith/tests/reply-capture-real.mjs +93 -2
  74. package/skills/teamsmith/tests/routes.sh +213 -293
  75. package/skills/teamsmith/tests/section-paths.tsv +14 -12
  76. package/skills/teamsmith/tests/smoke.sh +876 -130
  77. package/skills/teamsmith/tests/state-authority.sh +392 -28
  78. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +58 -8
  79. package/skills/teamsmith/tests/tmux-identity-leak.sh +12 -16
  80. package/skills/teamsmith-init/SKILL.md +5 -5
  81. package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # teamsmith
2
2
 
3
- **Give one agent real ownership of a project**: it plans, dispatches, verifies independently, merges and keeps the ledger.
3
+ **Give one agent real ownership of a project**: it plans, dispatches, accepts independent verification, merges and keeps the ledger.
4
4
 
5
5
  Runs on Pi; the launch/notify seam is an **internal seam (frozen)** — reserved for a possible future non-Pi adapter, with no compatibility promise (ROADMAP M3.0).
6
6
 
@@ -12,7 +12,7 @@ not "more agents chatting with each other".
12
12
  | Capability | Mechanism |
13
13
  |---|---|
14
14
  | Dispatch | Task briefs are self-contained (context / deliverables / boundaries / copy-pasteable acceptance commands); `team dispatch` puts a worker agent into its own tmux window and git worktree |
15
- | **Independent verification** | The agent's report is a **claim**; the PM runs the gates on an **independent checkout** (`team review <ID> --dir …`) and that becomes the evidence |
15
+ | **Independent verification** | The agent's report is a **claim**; a non-implementer verifier runs `team review <ID> --dir …` on the PM-prepared independent checkout, and the PM accepts that evidence without running the gates |
16
16
  | Ledger | `BOARD.md` (state), `reviews/` (verification evidence), `threads/` (decision trail), `DECISIONS.md` (the "why") |
17
17
  | Not rigid | The watchdog only wakes the owner when there is pending work; the PM can `standby` deliberately; when capacity is tight, work queues instead of thrashing |
18
18
  | Boundaries | Cross-project interaction is discussion only (`team meeting`) — never command; git/forge work stays with the PM's own tools |
@@ -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.7 # user level: every project
61
+ pi install -l git:git@github.com:Track07-cda/teamsmith@v0.4.7 # 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.7`) uses your SSH key and works
67
+ whether or not you have a token; the shorthand `git:github.com/Track07-cda/teamsmith@v0.4.7` 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.7",
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,43 @@
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.7(2026-11-13)
9
+
10
+ PM 可以用自然语言创建提醒,到点后继续处理;通知、关键回复与只读诊断完成一轮修复。
11
+
12
+ ### 提醒
13
+
14
+ - PM 可通过 `team_remind` 创建、查看和取消提醒;到点后由巡检送入会话并触发新的模型回合。
15
+ - 周期检查由 PM 在醒后自行续排;同一 key 在前一条确认后释放,新提醒使用新的 ID。停止指令会取消尚未到点的提醒。
16
+ - PM 或巡检停止后,到点未处理的提醒会恢复投递。待命期间仍允许提醒叫醒;确认进入会话后才退出待命,失败或结果未知不会提前退出。
17
+ - `team init` 生成的配置可直接加载提醒工具;配置不匹配会在 `team doctor` 显示具体原因。`team paths` 显示 `flock_runner`,缺失、不可执行或文件系统不支持锁时明确失败,不无锁写入。
18
+
19
+ ### 通知与关键回复
20
+
21
+ - 后台作业按发起会话归属,即使在独立检出执行也不会丢失;新的最终交付提交会再次叫醒 PM,同一提交的重复通知仍合并。
22
+ - PM 收不到新通知时,按看板、报告和提交记录核对实际状态,不把旧提交或合并通知当成未完成。
23
+ - 关键回复时间统一按本地时区显示;修改模型配置不再停止捕获;内部诊断只写日志,不再出现在 Pi 会话中。
24
+
25
+ ### 流程与诊断
26
+
27
+ - OpenSpec 验证与归档由非实现者席位执行,PM 负责审阅、合并与关闭;合并后由同一验证者复核最终提交。
28
+ - `team doctor` 只读检查不再创建调用方指定的临时目录。
29
+
30
+ 升级方式:`npm i -g teamsmith@0.4.7`,重启 PM。
31
+
32
+ ## v0.4.6(2026-11-06)
33
+
34
+ 提醒到点会真的叫醒 PM;`team say` 插在对方下一次调用模型之前;详情页不再拒绝项目内的软链。
35
+
36
+ - **提醒**:`team remind add 20m "…"` 到点后由巡检送入 PM 会话。待命期间照样叫;只有确认消息进了会话才退出待命,且一次只退一次。送达失败不自动重发,记成「未知」由人确认(`team remind resolve <批次> --ack-unknown`)。PM 正忙时消息会等它这一轮结束,可能超过 60 秒确认窗而先记成「未知」,迟到的回执会补正。
37
+ - **待命开关**:不再单独一个文件,读写与提醒同一份状态、同一把锁;旧标记用 `team standby migrate` 一次性并入,原因与时间保留,重复执行不再写。
38
+ - **指令投递**:`team say` 改用 `steer`,插在对方下一次调用模型之前;通知与巡检唤醒保持原节奏。只能在两次工具调用之间落地,对方正卡在长工具调用里仍要等它返回。
39
+ - **详情页**:按落点判软链——项目根内正常打开(含跨 change、指向 archive 的别名),项目根外、FIFO、设备仍拒绝并点名。
40
+ - 提示词统一为「长命令后台跑,不要在回合内等」;状态目录按项目解析,显式指定别的项目的状态根会被拒绝。
41
+
42
+ 升级方式:`npm i -g teamsmith@0.4.6`,重启 PM。
7
43
 
8
44
  ## v0.4.5(2026-11-05)
9
45
 
@@ -1,16 +1,16 @@
1
1
  ---
2
2
  name: teamsmith
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.
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, accepts non-implementer verification 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.7"
7
7
  ---
8
8
 
9
9
  # teamsmith · one agent that actually owns the project
10
10
 
11
11
  teamsmith turns "one PM session + several worker agents" into a one-command setup: the PM writes task briefs and
12
- dispatches them, workers implement in parallel inside their own worktrees, the PM verifies on an independent
13
- checkout, then merges. **You usually are that PM**: when the user asks to "set up a team / dispatch tasks /
12
+ dispatches them, workers implement in parallel inside their own worktrees, a non-implementer verifier executes the
13
+ gates on the PM-prepared independent checkout, then the PM accepts the evidence and merges. **You usually are that PM**: when the user asks to "set up a team / dispatch tasks /
14
14
  run agents in parallel", follow the PM loop below.
15
15
 
16
16
  ```
@@ -18,8 +18,8 @@ PM(this session, tmux <session>:pm) worker agents(each in .worktrees/<agent>
18
18
  task / dispatch ──────────────────▶ pi --session-id <s>-<a> (interactive, watchable)
19
19
  digest / inbox ◀── auto-notify on turn end ── extension/team-notify.ts → inbox + tmux wake-up
20
20
  long gate: team_bg_run → turn ends → woken once → team_bg_wait (extension/team-bg.ts, both sides)
21
- review(independent checkout, run gates) ──▶ reports/<ID>-<a>.md (local branch; remote on the PM's route)
22
- merge / close ──────────────────▶ BOARD → done
21
+ prepare checkout ──▶ verifier: team review (run gates + central record/log)
22
+ accept evidence / merge ──▶ same verifier checks merged SHA ──▶ BOARD → done / close
23
23
  ```
24
24
 
25
25
  ## Starting a new project: use the `teamsmith-init` skill
@@ -49,7 +49,7 @@ the upgrade recipe: [references/migration.md](references/migration.md) §§1b–
49
49
  | Collaborate | `team say <a> "<one-line message>" [--no-verify]` (prefers a live inbox watcher: durable inbox + wake spool, zero keys; with no usable watcher it makes one audited immediate attempt typed straight into the window, even over a draft — an attempt, not a model receipt — and falls back to the inbox when the agent is not running), `team notify <a> "<one line>" [--from <sender>]` (agent → PM; the sender comes from the runtime directory — an unresolved sender is refused, never recorded as `pm`) |
50
50
  | Draft / deferred delivery | `team draft [pm]` opens an editor window on `state/draft-pm.md` (nothing automated ever types into it; save+quit enqueues through the guarded path and prints the ack there), `team draft send [<file>] [--now]` (headless form), `team outbox [list]` (what is waiting, with `held` reasons), `team outbox flush [--now]`, `team outbox drop <n\|all>`. Protected senders (notify knocks, wake lines, meeting knocks, ordinary `draft send`, ordinary queued pane delivery) refuse to type into an input box that already holds a draft: the message is queued in `state/outbox/` and reported as `queued`. Default `team say` is the named exception: watch first, otherwise one audited immediate attempt even over a draft (`state/outbox/forced.log`), never a receipt; a `geometry-untrusted` read (the supported Pi layout cannot be established) or three trusted-empty drains with no progress (`queue-stalled`) hold the entry durably with its reason and **exit non-zero**, never promising an automatic delivery. `draft send --now` / `outbox flush --now` remain the audited human overrides that type anyway (`state/outbox/forced.log`). See `references/troubleshooting.md` §3 |
51
51
  | Long gate (background job) | **tool calls in the session** (not `team` subcommands): `team_bg_run` starts a detached job (id + pid at once, `state/bg/<id>.log`), `team_bg_wait <id>` harvests it (exit code + log tail inline). One merged wake-up per finished batch, silence once harvested, one `settled-with-unharvested=<n>` line per turn end in `state/bg.log`. Injected on both built-in Pi paths; a custom template opts in with `{bg_ext}`. The lane's records are readable and stoppable from the CLI: `team bg list` (one row per record, signals nothing), `team bg stop <id>` (signals only the recorded job — the `(pid, start-time)` pair is the identity, a reused pid is refused). Inside a window `pkill`/`killall` are the signal gate and refuse every name/pattern selection with exit 64. See `references/workflows.md` §E2 |
52
- | Verify | `team review <ID> --dir <PM-prepared independent checkout> [--no-gates] [--strong] [--allow-unresolved-branch]` → `reviews/<ID>.md` (runs gates + writes evidence; refuses a dirty or `.gitignore`d checkout / an unresolvable `--branch` unless the matching `TEAM_REVIEW_ALLOW_*` override is used and recorded; `--strong` structurally checks flip evidence + a path to an independent package) |
52
+ | Verify | The PM prepares a clean detached checkout; the assigned non-implementer verifier invokes `team review <ID> --dir <checkout> [--branch <sha>] [--no-gates] [--strong] [--allow-unresolved-branch]` from its own worktree → the tool writes only the brief-named main-checkout `reviews/<ID>.md` + `<ID>-verify.log` ledger exception, with the actual executor and reviewed SHA (the verifier's report stays on its branch; refuses a dirty or `.gitignore`d checkout / an unresolvable `--branch` unless the matching `TEAM_REVIEW_ALLOW_*` override is used and recorded; `--strong` structurally checks flip evidence + a path to an independent package) |
53
53
  | Wrap up | `team close <ID> [--keep-window]` (BOARD/state/window only, never git), `team teardown --agent a [--purge] [--register]` (explicit cleanup; `--register` removes the seat from the roster through the audited writer first) |
54
54
  | Bootstrap | `team bootstrap [--agents "dev verify"] --task-models '<map>' --pm-model '<model>' [--print]` (recommended; both model inputs are required on a fresh project, a valid policy is kept on re-entry, a legacy config is refused before any side effect and points at `team config upgrade-models`), `team init`, `team doctor` |
55
55
  | Patrol (pulse) | `team pulse up\|down\|restart\|status\|logs` (a `pulse` window in the same session runs the monitor + periodic patrol; single backend). Renamed from `watchdog` in v1.36.0: `team watchdog …`, `watchdog-status`, `install-watchdog`, `uninstall-watchdog` still work as aliases until v2.0.0 (they print a one-line deprecation notice first). `team watch [--once]` (foreground patrol) |
@@ -89,16 +89,24 @@ when they conflict, the creed wins and the process gets fixed.
89
89
  `category:` picks a new dispatch's model; dispatching again to the same agent resumes its session, and `--fresh` is
90
90
  the explicit new-session route. The `change:`/`specs:`/`anchor:`/`deltas:` header is checked **before the window
91
91
  opens**, and a refusal names the offending line, the sibling and the fix.
92
- 3. **Wait for notifications**: when a worker's turn ends it appends to `inbox/<agent>.md` and knocks on your window.
93
- Do not poll agent screens; read `team inbox --ack` and `team digest`.
94
- 4. **Verify (never skip)**: `team review <ID> --dir <checkout>` runs the gates on a clean, independent checkout and
95
- writes `reviews/<ID>.md`. **A report is a claim; your verification is the evidence.** Re-read the diff against the
96
- brief, and read each finding for what it changed.
97
- 5. **Land the records, then merge**: `team review <ID> --pre-merge` first — it lists every `docs/team/**` file the
98
- task's worktree has **not committed**, and a squash carries only committed content (an untracked report dies with
99
- the reused worktree). Commit them yourself with the `Agent: <agent>` trailer, then run git yourself: squash-merge
100
- (with a PR: merge it, then `fetch && merge --ff-only`) → `team board set <ID> done` → `team close <ID>`. A late
101
- delivery after the merge goes through `team review <ID> --post-merge` before you take anything.
92
+ 3. **Wait with notifications first and files as the authority**: when a worker's turn ends it appends to
93
+ `inbox/<agent>.md` and knocks on your window; read `team inbox --ack` and `team digest`. Before repeating an
94
+ unchanged waiting report, reconcile the digest, BOARD, task-branch report and task-worktree `git log`/`status`.
95
+ Use `git show <task-branch>:docs/team/reports/<ID>-<agent>.md` without switching branches; an uncommitted report
96
+ is a draft. An old tip, no new notice or a merged line does not prove unfinished work. Recognize a committed
97
+ final report through the existing acceptance route, keep a live job without one on wait/harvest, do not poll
98
+ agent screens, and do not rerun the assigned non-implementer verifier's acceptance tests yourself.
99
+ 4. **Delegate verification (never skip)**: prepare a clean, independent checkout; a non-implementer verifier runs
100
+ `team review <ID> --dir <checkout>` and the tool writes the named central record/log. **A report is a claim; the
101
+ verifier's execution is the evidence; your evidence/diff review is acceptance, not a gate run.** Re-read the diff
102
+ against the brief, and read each finding for what it changed.
103
+ 5. **Land the records, merge, then verify the merge**: `team review <ID> --pre-merge` first — it lists every
104
+ `docs/team/**` file the task's worktree has **not committed**, and a squash carries only committed content (an
105
+ untracked report dies with the reused worktree). Commit them yourself with the `Agent: <agent>` trailer, then run
106
+ git yourself: squash-merge (with a PR: merge it, then `fetch && merge --ff-only`). Resume the same verifier on a
107
+ clean checkout pinned to the merged SHA; accept its passing gates and OpenSpec assessment before `team board set
108
+ <ID> done` → `team close <ID>`. `team review <ID> --post-merge` remains an inspection of late delivery, never the
109
+ merged-revision verification run.
102
110
  6. **Wrap up / report**: update `BOARD.md`, record decisions in `DECISIONS.md` with rationale and impact, and report to
103
111
  the user as "delivered + where the evidence is + next step".
104
112
 
@@ -114,10 +122,11 @@ scenarios; teamsmith keeps the **evidence** (briefs, reports, reviews, decisions
114
122
  spec system: a product promise goes into a spec, reasoning or guidance into `references/`.
115
123
 
116
124
  A change runs as **five phases, one brief each, one owner each**: `opsx-explore` (an explorer) → `opsx-propose` (the
117
- same explorer, planning only) → `opsx-apply` (a dev) → `opsx-verify` (a **different** agent) → `opsx-archive` (the
118
- PM). Two hard rules: **an `apply` brief starts only after the PM's proposal review is ACCEPTED**
119
- (`docs/team/reviews/<change>-proposal.md`), and **the PM never archives without independent verification and the
120
- user's confirmation**. **One change : N tasks** — the change is the dispatch unit and the brief's header maps the task
125
+ same explorer, planning only) → `opsx-apply` (a dev) → `opsx-verify` (a **different** agent) → `opsx-archive` (a
126
+ non-implementer worker, possibly that verifier). Two hard rules: **an `apply` brief starts only after the PM's
127
+ proposal review is ACCEPTED** (`docs/team/reviews/<change>-proposal.md`), and **the PM never authorizes archive without
128
+ the same verifier's accepted merged-revision evidence and valid confirmation**. The user confirms, or the PM records a
129
+ narrowly qualified proxy confirmation (small, reversible and already covered by the approved approach). **One change : N tasks** — the change is the dispatch unit and the brief's header maps the task
121
130
  to it (`team dispatch` refuses more than one `change:` id, a change-less brief without a resolvable anchor, two
122
131
  unfinished tasks writing one delta file, and a verifier who authored the change; `team change status <id>` reports
123
132
  readiness). `openspec validate --all --strict` is part of `TEAM_GATES`. Phase table, gates and the PM's ten-point review
@@ -180,8 +189,8 @@ about them). They stay writable so the seam can be maintained and diagnosed; to
180
189
  - Details: [references/meeting.md](references/meeting.md).
181
190
 
182
191
  ## Non-negotiable rules (verified during review)
183
- - **Never claim something passed without having run it.** Reports carry the real commands and output tails; the PM
184
- re-runs independently.
192
+ - **Never claim something passed without having run it.** Reports carry the real commands and output tails; the
193
+ assigned non-implementer verifier re-runs independently, and the PM reviews that evidence without executing it.
185
194
  - **Mark the reply — publication is a standing duty.** Whenever the answer is written for the user — an answer, a status
186
195
  or progress report, a conclusion or a ruling, a delivery or verification summary, a decision you ask the user for,
187
196
  however short — write the complete reply as the normal answer and end it with the final control line `[[team-reply]]`
@@ -27,6 +27,7 @@ type Job = {
27
27
  root: string // 起作业时解析到的车道根 —— 账本/记录/wait 行都落它下面(会话中途换 cwd 也不漂)
28
28
  pid: number
29
29
  command: string
30
+ sessionCwd: string // 发起会话的目录;cwd 可以是独立执行检出,不能顶替发起身份
30
31
  cwd: string
31
32
  log: string
32
33
  startedAt: number
@@ -54,11 +55,10 @@ const CMD_ELLIPSIS = '…'
54
55
  * ③ **原地等是有界例外**:预算(约 2 分钟)+ 结果卡住下一步 + 没有别的任务可推进,三条**同时**成立。
55
56
  * 任何面都不得再出现「回合结束前必须收割」的措辞,也不得把叫醒写成惩罚/损失。
56
57
  */
57
- const INLINE_WAIT_BUDGET = '~2 minutes'
58
58
  const SUSPEND_DEFAULT =
59
59
  '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.`
60
+ const NO_INLINE_WAIT =
61
+ 'Do not wait inside the turn (`sleep`, `team wait`, a blocking harvest): end the turn instead.'
62
62
 
63
63
  /**
64
64
  * 定位**本会话自己的根**:team-bg 的产物(作业日志、账本、合并窗口)都是会话本地的,
@@ -196,7 +196,7 @@ function writeJobRecord(root: string, job: Job): void {
196
196
  const { pgid, start } = procStat(job.pid)
197
197
  const one = job.command.replace(/[\r\n]+/g, ' ')
198
198
  writeFileSync(join(dir, `${job.id}.job`),
199
- `id=${job.id}\npid=${job.pid}\npgid=${pgid}\nstart=${start}\ncwd=${job.cwd}\nlog=${job.log}\ncmd=${one}\n`)
199
+ `id=${job.id}\npid=${job.pid}\npgid=${pgid}\nstart=${start}\nsession_cwd=${job.sessionCwd}\ncwd=${job.cwd}\nlog=${job.log}\ncmd=${one}\n`)
200
200
  } catch {
201
201
  /* 记录写不进去 = 这个作业停不了(fail-closed,且 team bg list 里可见);作业本身照常跑 */
202
202
  }
@@ -274,12 +274,12 @@ export default function (pi: ExtensionAPI) {
274
274
  description:
275
275
  'Start a long command (a gate, a build) as a detached background job and return immediately with a job id. ' +
276
276
  `Output goes to state/bg/<id>.log (bounded). ${SUSPEND_DEFAULT} Then run team_bg_wait <id> there to harvest it. ` +
277
- INLINE_WAIT_EXCEPTION,
277
+ NO_INLINE_WAIT,
278
278
  promptSnippet:
279
279
  'team_bg_run: start a long command in the background and end your turn ' +
280
280
  '(returns a job id immediately; the completion wake-up is the normal harvest point)',
281
281
  promptGuidelines: [
282
- `Use team_bg_run for long gates or builds. ${SUSPEND_DEFAULT} ${INLINE_WAIT_EXCEPTION}`,
282
+ `Use team_bg_run for long gates or builds. ${SUSPEND_DEFAULT} ${NO_INLINE_WAIT}`,
283
283
  ],
284
284
  parameters: {
285
285
  type: 'object',
@@ -292,7 +292,8 @@ export default function (pi: ExtensionAPI) {
292
292
  additionalProperties: false,
293
293
  } as any,
294
294
  async execute(_toolCallId: string, params: any, _signal: any, _onUpdate: any, ctx: any) {
295
- const root = findRoot(String(ctx?.cwd ?? process.cwd()))
295
+ const sessionCwd = resolve(String(ctx?.cwd ?? process.cwd()))
296
+ const root = findRoot(sessionCwd)
296
297
  if (!root) throw new Error('team_bg_run: not a teamsmith project (no .pi/team/config.sh found)')
297
298
  const command = String(params?.command ?? '')
298
299
  if (!command.trim()) throw new Error('team_bg_run: empty command')
@@ -311,7 +312,7 @@ export default function (pi: ExtensionAPI) {
311
312
  closeSync(fd)
312
313
  }
313
314
  const job: Job = {
314
- id, root, pid: child.pid ?? 0, command, cwd, log, startedAt: Date.now(),
315
+ id, root, pid: child.pid ?? 0, command, sessionCwd, cwd, log, startedAt: Date.now(),
315
316
  done: false, exitCode: null, harvested: false, notified: false, waiters: [],
316
317
  }
317
318
  jobs.set(id, job)
@@ -331,7 +332,7 @@ export default function (pi: ExtensionAPI) {
331
332
  trimTimer = setInterval(() => { for (const j of jobs.values()) if (!j.done) trimLog(j.log) }, TRIM_EVERY_MS)
332
333
  }
333
334
  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}` }],
335
+ 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
336
  details: { id, pid: job.pid, log, cwd, cmd: command },
336
337
  }
337
338
  },
@@ -342,9 +343,9 @@ export default function (pi: ExtensionAPI) {
342
343
  label: 'Team background job wait',
343
344
  description:
344
345
  '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}`,
346
+ `${SUSPEND_DEFAULT} ${NO_INLINE_WAIT}`,
346
347
  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)',
348
+ 'team_bg_wait: harvest a finished team_bg_run job (after its completion wake-up; never as a poll)',
348
349
  parameters: {
349
350
  type: 'object',
350
351
  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}]` : ''))
@@ -1241,7 +1255,7 @@ export default function (pi: ExtensionAPI) {
1241
1255
  /** 读 spool 的新行并合并成一条唤醒(同一拍收到的多行只叫一次)。
1242
1256
  * 日志写不进去时 `deliverNormal` 返回 blocked:offset 不动,行保持未读(下一拍重读)。 */
1243
1257
  const flush = (): void => {
1244
- if (!spool) return
1258
+ if (!spool || (reminderOnly && !reminderReleased)) return
1245
1259
  try { runRetryTick() } catch { /* ignore */ }
1246
1260
  try { runRecoveryTick() } catch { /* ignore */ }
1247
1261
  const res = readNewLines(spool, offset)
@@ -1307,8 +1321,133 @@ 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
+ let reminderOnly = false
1338
+ let reminderReleased = false
1339
+
1340
+ const reminderPollMs = (): number => {
1341
+ const n = Number(process.env.TEAM_REMIND_POLL_MS ?? NaN)
1342
+ return Number.isFinite(n) && n >= 200 ? n : 2000
1343
+ }
1344
+
1345
+ const defaultStateRoot = (): string => join(remindRoot, '.pi/team/state')
1346
+
1347
+ const reminderPoll = async (): Promise<void> => {
1348
+ if (remindBusy || !remindRoot || !remindAuthority || !remindModule) return
1349
+ remindBusy = true
1350
+ try {
1351
+ const seen = await remindAuthority.peek({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: defaultStateRoot() })
1352
+ if (!seen.pinned) return
1353
+ remindState = String(seen.stateRoot ?? '')
1354
+ const pending = seen.reminders ?? { due: [], queued: [], staleIntent: [] }
1355
+ // Nothing to freeze: no queued item and no intent past its observation deadline. A batch in flight is
1356
+ // closed by the observation handler, not by polling the authority every couple of seconds.
1357
+ if (!pending.queued.length && !pending.staleIntent.length) return
1358
+ const res = await remindAuthority.request({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: remindState }, {
1359
+ op: 'remind-intent', session: remindSession, pid: process.pid,
1360
+ })
1361
+ if (!res || res.action !== 'send') {
1362
+ // An unknown batch (or one still in flight) blocks the next freeze. Say it once per batch, not per tick.
1363
+ if (res?.action === 'wait' && res.batch && remindWarned !== res.batch) {
1364
+ remindWarned = res.batch
1365
+ appendLedger(root, `reminder waiting batch=${res.batch} phase=${res.phase ?? 'intent'}(${oneLine(String(res.reason ?? ''), 160)})`)
1366
+ }
1367
+ return
1368
+ }
1369
+ const batch = res.batch
1370
+ const mod = remindModule
1371
+ try {
1372
+ pi.sendMessage({
1373
+ customType: mod.REMINDER_CUSTOM_TYPE, content: mod.reminderContent(batch), display: true,
1374
+ details: mod.reminderDetails(batch),
1375
+ }, { triggerTurn: true, deliverAs: 'followUp' })
1376
+ appendLedger(root, mod.deliveryLogLine(batch, 'intent-sent'))
1377
+ } catch (error) {
1378
+ // A throw is not a receipt: the batch becomes unknown (visible, no automatic resend).
1379
+ try {
1380
+ await remindAuthority.request({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: remindState }, {
1381
+ op: 'remind-fail', id: batch.id, nonce: batch.nonce, reason: oneLine(shortError(error), 300),
1382
+ })
1383
+ } catch (second) {
1384
+ appendLedger(root, `reminder fail-record blocked batch=${batch.id}(${oneLine(shortError(second), 160)})`)
1385
+ }
1386
+ appendLedger(root, `reminder send-failed batch=${batch.id}(会话 API 拒绝;批次保持 unknown,不自动重发)`)
1387
+ }
1388
+ } catch (error) {
1389
+ appendLedger(root, `reminder tick failed: ${oneLine(shortError(error), 200)}`)
1390
+ } finally {
1391
+ remindBusy = false
1392
+ }
1393
+ }
1394
+
1395
+ const startReminderWatch = async (ctx: any): Promise<void> => {
1396
+ try {
1397
+ const skill = dirname(dirname(fileURLToPath(import.meta.url)))
1398
+ remindAuthority = await import(pathToFileURL(join(skill, 'scripts/state-authority.mjs')).href)
1399
+ remindModule = await import(pathToFileURL(join(skill, 'scripts/reminder-delivery.mjs')).href)
1400
+ if (typeof remindAuthority.peek !== 'function' || typeof remindAuthority.request !== 'function' ||
1401
+ typeof remindModule.reminderContent !== 'function' || typeof remindModule.matchesObservation !== 'function') {
1402
+ throw new Error('the reminder modules did not export the expected entry points')
1403
+ }
1404
+ remindRoot = root
1405
+ remindSession = String(ctx?.sessionManager?.getSessionId?.() ?? '')
1406
+ if (!remindSession) throw new Error('this session has no id: a batch intent must bind the session that may observe it')
1407
+ remindTimer = setInterval(() => { void reminderPoll() }, reminderPollMs())
1408
+ appendLedger(root, `reminder watch on session=${remindSession} poll=${reminderPollMs()}ms`)
1409
+ void reminderPoll() // restart recovery: a queued item from before this process is delivered now
1410
+ } catch (error) {
1411
+ remindAuthority = null
1412
+ remindModule = null
1413
+ if (remindTimer) { clearInterval(remindTimer); remindTimer = null }
1414
+ appendLedger(root, `reminder watch disabled: ${oneLine(shortError(error), 200)}`)
1415
+ }
1416
+ }
1417
+
1418
+ // The observation. `sendMessage` returning, a thrown error or a deferred action never reach this path;
1419
+ // only Pi's own message_start for our custom message, with the frozen batch's identity, does.
1420
+ pi.on('message_start', async (event: any) => {
1421
+ if (!remindAuthority || !remindRoot) return
1422
+ const message = event?.message
1423
+ const details = message?.details
1424
+ if (message?.role !== 'custom' || message?.customType !== 'team-reminder' || !details?.batchId) return
1425
+ try {
1426
+ const res = await remindAuthority.request({ cwd: remindRoot, mainRoot: remindRoot, stateRoot: remindState || defaultStateRoot() }, {
1427
+ op: 'remind-observe', id: String(details.batchId), nonce: String(details.nonce ?? ''), session: remindSession,
1428
+ members: Array.isArray(details.members) ? details.members.map((id: unknown) => String(id)) : null,
1429
+ })
1430
+ if (!res?.ok) {
1431
+ appendLedger(root, `reminder observation refused (${res?.refusal ?? 'unknown'}): ${oneLine(String(res?.reason ?? ''), 200)}`)
1432
+ } else if (res.outcome === 'duplicate') {
1433
+ appendLedger(root, `reminder duplicate event batch=${res.batch}(right 已花掉;未再退待命)`)
1434
+ } else {
1435
+ appendLedger(root, `reminder observed batch=${res.batch} standby=${res.standby} generation=${res.generation} ids=${(res.ids ?? []).join('|')}`)
1436
+ if (reminderOnly && !reminderReleased && res.outcome === 'observed' && (res.standby === 'auto-off' || res.standby === 'already-off')) {
1437
+ reminderReleased = true
1438
+ appendLedger(root, `reminder-only released batch=${res.batch} standby=${res.standby}(普通 watcher 恢复;启动前 backlog 仍按基线处理)`)
1439
+ flush()
1440
+ }
1441
+ }
1442
+ } catch (error) {
1443
+ appendLedger(root, `reminder observation failed: ${oneLine(shortError(error), 200)}`)
1444
+ }
1445
+ })
1446
+
1310
1447
  pi.on('session_start', async (_event: any, ctx: any) => {
1311
1448
  stopAll()
1449
+ reminderOnly = process.env.TEAM_REMINDER_ONLY_RECOVERY === '1'
1450
+ reminderReleased = !reminderOnly
1312
1451
  root = findRoot(String(ctx?.cwd ?? process.cwd()))
1313
1452
  if (!root) return
1314
1453
  noteIdentityFileConflicts(root)
@@ -1406,7 +1545,8 @@ export default function (pi: ExtensionAPI) {
1406
1545
  }
1407
1546
  maybeCompact()
1408
1547
  baselineSwallowed()
1409
- runRecoveryTick()
1548
+ if (!reminderOnly) runRecoveryTick()
1549
+ else appendLedger(root, 'reminder-only ordinary delivery held(等待匹配的 Reminder 观察;不重放普通 recovery/backlog)')
1410
1550
  // M53 · 失败不再静默:errno + 额度观察 + 轮询间隔进账本,并写一条耐久降级记录(读的人看 pid+cwd)。
1411
1551
  // 夹具旋钮强制失败时同样走这条路径(evidence 里带 forced=1,免得测试事故被当成真事故)。
1412
1552
  const forced = forcedWatchErrno()
@@ -1425,6 +1565,8 @@ export default function (pi: ExtensionAPI) {
1425
1565
  armFileWatcher() // spool 可能早已存在(上一任会话留下的):文件级 watcher 现在就 arm 上
1426
1566
  pollTimer = setInterval(() => { try { flush() } catch { /* ignore */ } }, pollMs())
1427
1567
  beatTimer = setInterval(() => { try { writeReg('ready') } catch { /* ignore */ } }, heartbeatMs())
1568
+ // Reminder delivery is the PM's path: a worker window never binds a batch or observes a wake.
1569
+ if (inbox === 'pm') await startReminderWatch(ctx)
1428
1570
  })
1429
1571
 
1430
1572
  pi.on('session_shutdown', async () => {
@@ -1439,5 +1581,7 @@ export default function (pi: ExtensionAPI) {
1439
1581
  headBytes = null; lastShrink = null
1440
1582
  journalPath = ''; journalEntries = new Map(); retryQueue = new Map(); recoveryQueue = new Map()
1441
1583
  delivered = new Set(); floorTs = null; floorId = ''; journalRecords = 0; abortAt = ''
1584
+ remindRoot = ''; remindState = ''; remindSession = ''; remindAuthority = null; remindModule = null
1585
+ remindBusy = false; remindWarned = ''; reminderOnly = false; reminderReleased = false
1442
1586
  })
1443
1587
  }
@@ -205,20 +205,26 @@ function ownedSessionPaths(cwd: string, worktree: string): Set<string> {
205
205
  return owned
206
206
  }
207
207
 
208
- /** P236 · 归属判据:作业记录里的 `cwd`(作业启动时的工作目录,也就是拥有它的那个席位的工作树)
209
- * 解析到本会话自己的工作树/cwd(真实路径相等)才算「我的作业」。缺 `cwd`、相对路径、解析失败、
210
- * 或指向别人的工作树 → 都不算(fail-closed)。 */
208
+ /** 新记录只看发起会话的 `session_cwd`;执行目录可以是独立 clone,不能顶替发起身份。
209
+ * 旧记录没有该字段时才走有界兼容:`cwd` 必须恰好解析到席位工作树,不能是会话恰好所在的子目录。 */
211
210
  function isOwnedCwd(jobCwd: string, owned: Set<string>): boolean {
212
211
  const real = realPathOf(jobCwd)
213
212
  return real !== '' && owned.has(real)
214
213
  }
215
214
 
215
+ function isOwnedJob(fields: Record<string, string>, owned: Set<string>, legacyWorktree: string): boolean {
216
+ if (Object.prototype.hasOwnProperty.call(fields, 'session_cwd')) {
217
+ return isOwnedCwd(fields.session_cwd ?? '', owned)
218
+ }
219
+ const real = realPathOf(fields.cwd ?? '')
220
+ return real !== '' && real === legacyWorktree
221
+ }
222
+
216
223
  /** 在跑作业集合:读车道目录下的 `bg/*.job`,逐条做 (pid, start-time) 活体验证(与 `team bg list`
217
- * 同一条身份规则),再按 `cwd` 只留**本会话自己的**作业(P236 归属范围 —— 同一车道目录里的记录
218
- * 可能属于别的席位,把别人的长作业算成自己挂起会污染 `awaiting=`)。任何一条失败都**跳过**
219
- * (目录/记录读不了、软链-FIFO 记录、pid 非正整数、start 缺失、/proc 读不到、指纹不符、cwd 缺失
220
- * 或不属于本会话)—— fail-closed:判定的不确定方向永远是「不挂起」,绝不假造挂起(design 决策 4)。 */
221
- function runningLaneJobs(laneDir: string, owned: Set<string>): string[] {
224
+ * 同一条身份规则),再按发起身份只留**本会话自己的**作业(同一车道目录里的记录可能属于别的席位)。
225
+ * 任何一条失败都**跳过**(目录/记录读不了、软链-FIFO 记录、pid 非正整数、start 缺失、/proc 读不到、
226
+ * 指纹不符、发起目录缺失或不属于本会话)—— fail-closed:绝不假造挂起。 */
227
+ function runningLaneJobs(laneDir: string, owned: Set<string>, legacyWorktree: string): string[] {
222
228
  if (!laneDir || owned.size === 0) return []
223
229
  let names: string[]
224
230
  try {
@@ -243,7 +249,7 @@ function runningLaneJobs(laneDir: string, owned: Set<string>): string[] {
243
249
  const start = fields.start ?? ''
244
250
  if (!Number.isInteger(pid) || pid <= 0 || !start) continue
245
251
  if (procStartTime(pid) !== start) continue // 死进程 / pid 复用 / /proc 读不到:都不算在跑
246
- if (!isOwnedCwd(fields.cwd ?? '', owned)) continue // P236:别人的作业不算自己挂起
252
+ if (!isOwnedJob(fields, owned, legacyWorktree)) continue // 别人的作业不算自己挂起
247
253
  ids.push(id)
248
254
  } catch {
249
255
  continue // 读不了:不算在跑
@@ -561,15 +567,16 @@ export default function (pi: ExtensionAPI) {
561
567
  // 逐条 (pid, start-time) 验活、再按 cwd 只留**本会话自己的**作业;判定失败一律退回非挂起形状
562
568
  // (fail-closed)——既不假造挂起,也不拿 notify 自己的 root 顶替车道目录(两侧分歧时它只负责把
563
569
  // 这件事记进日志)。
564
- // P236(缺陷现场):同一车道目录里的记录可能属于**别的席位** —— 只看「项目里有活作业」会把别人的
565
- // 长作业算成自己挂起。归属判据 = 作业的 cwd 与本会话自己的工作树/cwd 解析到同一个真实路径。
570
+ // 同一车道目录里的记录可能属于**别的席位**。新记录按 session_cwd 认发起会话,执行 cwd 可指向
571
+ // 独立 clone;只有旧记录才按恰好等于席位工作树的 cwd 兼容,其它路径一律不收养。
566
572
  const laneDir = laneStateDir(cwd)
567
573
  const ownDir = notifyStateDir(root)
568
574
  if (laneDir && ownDir && laneDir !== ownDir) {
569
575
  log(`suspend check reads the lane's directory ${laneDir} (notify's own root would be ${ownDir})`, cfg)
570
576
  }
571
- const owned = ownedSessionPaths(cwd, join(wtPrefix, agent))
572
- const running = runningLaneJobs(laneDir, owned)
577
+ const worktree = join(wtPrefix, agent)
578
+ const owned = ownedSessionPaths(cwd, worktree)
579
+ const running = runningLaneJobs(laneDir, owned, realPathOf(worktree))
573
580
  const awaiting = running.length > 0 ? `awaiting=${running.join(',')}` : ''
574
581
  const suspended = completed && running.length > 0
575
582