mercury-agent 0.24.4-beta.4 → 0.24.4-beta.5

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 (79) hide show
  1. package/docs/configuration.md +20 -1
  2. package/docs/extensions.md +23 -2
  3. package/docs/goals/rehearsal-bench/decisions.md +10 -0
  4. package/docs/goals/rehearsal-bench/goal.md +2 -2
  5. package/docs/goals/rehearsal-bench/roadmap.md +15 -7
  6. package/docs/goals/release-gate/goal.md +2 -2
  7. package/docs/goals/release-gate/roadmap.md +2 -2
  8. package/docs/live-testing.md +108 -15
  9. package/docs/pending-verification.md +64 -0
  10. package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/plan.md +2 -2
  11. package/docs/plans/archive/2026-10-21-tagula-client-1008/sessions/S4.md +108 -0
  12. package/docs/plans/archive/2026-10-21-tagula-client-1008/sessions/S8.md +86 -0
  13. package/docs/plans/archive/2026-10-21-tagula-client-1008/sessions/S9.md +50 -0
  14. package/docs/plans/watchdog-1011/sessions/S1.md +55 -0
  15. package/docs/release-gate.md +24 -10
  16. package/examples/extensions/archive/capability.ts +9 -0
  17. package/examples/extensions/archive/index.ts +2 -1
  18. package/examples/extensions/feed-watch/forget.ts +69 -0
  19. package/examples/extensions/feed-watch/index.ts +17 -1
  20. package/examples/extensions/longview/hook.ts +20 -2
  21. package/examples/extensions/longview/index.ts +45 -5
  22. package/examples/extensions/longview/targets/file.ts +101 -0
  23. package/examples/extensions/longview/targets/select.ts +63 -0
  24. package/examples/extensions/longview/targets/types.ts +6 -1
  25. package/examples/extensions/morning/index.ts +23 -18
  26. package/examples/extensions/morning/lib/morning.ts +18 -0
  27. package/examples/extensions/napkin/index.ts +28 -18
  28. package/examples/extensions/napkin/space-keys.ts +44 -0
  29. package/examples/extensions/office-365-mail/index.ts +13 -7
  30. package/examples/extensions/office-365-mail/lib/graph.ts +13 -0
  31. package/examples/extensions/overview/actions.ts +9 -0
  32. package/examples/extensions/overview/index.ts +2 -1
  33. package/examples/extensions/web-search/capability.ts +17 -1
  34. package/examples/extensions/web-search/index.ts +11 -0
  35. package/package.json +4 -3
  36. package/resources/skills/spaces/SKILL.md +3 -2
  37. package/src/agent/container-runner.ts +15 -0
  38. package/src/cli/mercury.ts +199 -4
  39. package/src/cli/shadow-say-cli.ts +296 -0
  40. package/src/core/git-env.ts +50 -0
  41. package/src/core/operator-alerts.ts +25 -12
  42. package/src/core/profiles.ts +2 -0
  43. package/src/core/routes/capability.ts +22 -0
  44. package/src/core/routes/tradestation.ts +19 -0
  45. package/src/core/runtime.ts +45 -11
  46. package/src/core/shadow-egress.ts +103 -0
  47. package/src/core/shadow-outbox.ts +45 -20
  48. package/src/core/space-delete.ts +5 -1
  49. package/src/core/system-messages.ts +10 -0
  50. package/src/extensions/api.ts +26 -2
  51. package/src/extensions/loader.ts +15 -5
  52. package/src/extensions/types.ts +28 -2
  53. package/src/main.ts +4 -0
  54. package/src/ops/shadow-rehearse-run.ts +22 -5
  55. package/src/ops/shadow-rehearse.ts +15 -1
  56. package/src/ops/shadow-say.ts +1540 -0
  57. package/src/ops/shadow-service.ts +275 -8
  58. package/src/ops/shadow-snapshot.ts +198 -0
  59. package/src/ops/shadow-transcript.ts +457 -0
  60. package/src/preflight/checks/roundtrip.ts +3 -0
  61. package/src/storage/pi-auth.ts +1 -1
  62. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S1.md +0 -0
  63. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S10.md +0 -0
  64. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S2.md +0 -0
  65. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S3.md +0 -0
  66. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S4.md +0 -0
  67. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S5.md +0 -0
  68. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S6.md +0 -0
  69. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S7.md +0 -0
  70. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S8.md +0 -0
  71. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/briefs/S9.md +0 -0
  72. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/decisions.md +0 -0
  73. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S1.md +0 -0
  74. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S10.md +0 -0
  75. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S2.md +0 -0
  76. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S3.md +0 -0
  77. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S5.md +0 -0
  78. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S6.md +0 -0
  79. /package/docs/plans/{tagula-client-1008 → archive/2026-10-21-tagula-client-1008}/sessions/S7.md +0 -0
@@ -505,6 +505,25 @@ only in the snapshot's `.env`; `shadow snapshot`, `shadow up`, `shadow
505
505
  status`, `/health` and the logs print key names, never the value. Rotation
506
506
  is a new snapshot.
507
507
 
508
+ **A shadow's model token is its own** (goal `rehearsal-bench` M1.3d). The
509
+ owner mints a long-lived token with `claude setup-token` (subscription, never
510
+ an API key) and writes it, one bare `sk-ant-oat01-…` line, to
511
+ `~/mercury-shadow/credentials/default/anthropic-oauth-token` (directory
512
+ `0700`, file `0600`). It lives outside every snapshot, and Mercury never
513
+ writes it. `shadow up` writes it into the snapshot `.env` as a marked
514
+ `MERCURY_ANTHROPIC_OAUTH_TOKEN` block at every start, and removes the block
515
+ when the file is gone. `up --dry-run` and `status` print the state
516
+ (`shadow-own`, `inherited non-rotating`, `shared chain`) with a 12-hex
517
+ fingerprint and the approximate expiry (file mtime + 365 days), never the
518
+ value. A file that is present but invalid (a blob, two lines, the wrong
519
+ prefix, readable or writable by group or other, or unreadable) refuses in every mode. Without the file the
520
+ shadow inherits the live `.env`'s key. **`up --beside-live`** (always used by
521
+ `shadow rehearse`) turns a live run and a due task into warnings and refuses
522
+ `credential-shared-chain` instead: that is, when the shadow would run on a
523
+ rotating credential it shares with the live bot (an env blob, or `auth.json`
524
+ OAuth). A shadow's unit runs at `CPUWeight=20`/`Nice=10`, and its containers
525
+ get `--cpu-shares 256 --memory 2g`. Live containers keep Docker's default CPU shares and are not memory-capped on runc (on runsc both arms already carry `--memory=2g`).
526
+
508
527
  **`POST /api/shadow/simulate`** (goal `rehearsal-bench` M2.2b) exists only on
509
528
  a shadow — on a live process the path is whatever `/api`'s guard says (401
510
529
  without the live secret, 404 with it). It is authenticated by
@@ -721,7 +740,7 @@ a detail on the page can be answered.
721
740
  |-----|---------|---------|
722
741
  | `longview.enabled` | `false` | Publish long replies from this space. |
723
742
  | `longview.threshold_chars` | `2000` | Publish when a reply exceeds this many characters. Minimum 500. |
724
- | `longview.target` | `telegraph` | Where pages are published. |
743
+ | `longview.target` | `telegraph` | Where pages are published: `telegraph`, or `file` (writes `<dataDir>/longview/pages/<stamp>-<hex>.md` and links its absolute path — a testing setting). A shadow always uses `file`, whatever this says. |
725
744
  | `longview.sources` | `both` | Which replies are published: `both` (any reply over the threshold, whoever asked), `scheduled` (task runs only — a member's long answer stays in chat), or `chat` (the reverse). A turn whose origin the host did not report is never published under `scheduled` or `chat`. |
726
745
  | `longview.summary_model` | *(empty)* | Model that writes the chat summary. Empty uses the space's configured model. |
727
746
 
@@ -179,6 +179,15 @@ delete's reply does not wait for it, and a handler cannot undo or fail the
179
179
  delete, so log what you did. The `mercury spaces delete` CLI loads no
180
180
  extensions and therefore emits nothing; it prints a note saying so.
181
181
 
182
+ `workspace` is always absolute, resolved once in `deleteSpaceEverywhere`. The
183
+ same event is where an extension deletes the `extension_state` rows it keyed by
184
+ the space id: `deleteSpace` cannot reach them, because a store key is the
185
+ extension's, not the space's. napkin, feed-watch, web-search and longview do
186
+ this; a new extension that keys rows by space id must too. Delete exact keys,
187
+ or match `<prefix>:<id>:<suffix>` with the suffix's own grammar. Never use
188
+ `startsWith("<prefix>:<id>")` alone: deleting space `a` would also take space
189
+ `a-b`'s rows.
190
+
182
191
  Both `workspace_init` and `before_container` events include:
183
192
  - `workspace` — absolute host path (for file operations on the host)
184
193
  - `containerWorkspace` — container-relative path, e.g. `/spaces/main` (for env vars passed into the container)
@@ -297,7 +306,7 @@ mercury.widget({
297
306
 
298
307
  Widgets render HTML fragments in the dashboard overview. Errors show a placeholder — never crash the dashboard.
299
308
 
300
- ### `mercury.capability(name, handler)`
309
+ ### `mercury.capability(name, handler, opts?)`
301
310
 
302
311
  Register a host-side handler the agent reaches from inside the container with
303
312
  `mrctl capability <name> <action> '<json>'` → `POST /api/capability/:name/:action`.
@@ -308,8 +317,9 @@ Credentials the handler uses stay on the host and never enter the container.
308
317
  mercury.permission({ defaultRoles: ["admin"] });
309
318
  mercury.capability("rooms", async (req, ctx) => {
310
319
  if (req.action === "book") return { data: await bookRoom(req.callerId, req.body) };
320
+ if (req.action === "list") return { data: await listRooms() };
311
321
  return { status: 400, data: { error: "unknown action" } };
312
- });
322
+ }, { readOnly: ["list"] });
313
323
  ```
314
324
 
315
325
  - **`name` must equal the extension's own name** — registering under any other
@@ -329,6 +339,17 @@ mercury.capability("rooms", async (req, ctx) => {
329
339
  - One capability per extension; branch on `req.action` for sub-verbs.
330
340
  - The name is resolved host-wide, so two extensions cannot own it — a
331
341
  collision is rejected at load time.
342
+ - **`opts.readOnly`** names the actions that change nothing outside this
343
+ host's own copy of its data (a search, a list, a read that does not mark
344
+ anything). A **shadow** (`MERCURY_SHADOW=1`, or any config whose `shadow`
345
+ is not the literal `false`) answers every other action with
346
+ `403 { error: "shadow_refused", detail, readOnly }` and a warn line, before
347
+ the body is parsed or the handler runs. Absence denies: an extension that
348
+ declares nothing has **every** action refused in a shadow. There is no
349
+ override. Each entry must match `/^[a-z0-9][a-z0-9-]*$/`, or registration
350
+ throws at load. A read that has a side effect elsewhere (an IMAP fetch that
351
+ sets `\Seen`, a preview that issues something) is not read-only — leave it
352
+ out. On a live process the declaration changes nothing.
332
353
 
333
354
  ### `mercury.store`
334
355
 
@@ -523,3 +523,13 @@
523
523
  - **Used by:** shadow-simulate-route (M2.2b), shadow-cli (M2.3), smoke-runner
524
524
  (release-gate R3.2), harness-on-shadow (M2.4)
525
525
 
526
+
527
+ ## D-017: A long-lived shadow token replaces the second OAuth login; the rehearsal waits for nothing but the restart
528
+
529
+ - **Category:** credential / rehearsal gate
530
+ - **Decided:** 2026-10-21 (owner; the item was filed 2026-10-20 as `shadow-rehearse-beside-live`)
531
+ - **Decision:** the shadow runs on its own owner-minted long-lived `sk-ant-oat01` token, kept outside every snapshot at `~/mercury-shadow/credentials/default/anthropic-oauth-token`, and written into the snapshot `.env` by `up` on every start. A token that never refreshes has no chain to race, so the cron and live-run window on `rehearse` goes; one guard, `credential-shared-chain`, refuses only when the shadow would share a *rotating* chain with live. M1.3c (a second `auth.json` login with its own refresh chain) is superseded on every box that runs on a long-lived token and stays deferred.
532
+ - **Alternatives considered:** (a) build M1.3c as specced — a second refresh chain, a `shadow login`, rotation tracking: more moving parts for a problem the long-lived token removes; (b) keep the 30m window — on 2026-10-20 it pushed a deploy to `--no-rehearse`, and a gate people skip protects nothing.
533
+ - **Reasoning:** both bots already moved to long-lived tokens after `docs/debug/moderate/2026-10-08-oauth-token-handed-to-container-can-expire-or-be-rotated-mid-run.md`; the shadow following them makes D-016's "a shadow answers to no live credential" hold for the model credential too.
534
+ - **Revisit if:** a box goes back to `auth.json` OAuth — then the guard refuses there and M1.3c comes back.
535
+ - **Used by:** shadow-rehearse-beside-live (M1.3d), release-gate R5.1
@@ -1,9 +1,9 @@
1
1
  # Rehearsal Bench — test the live bot without a phone and without reaching anyone
2
2
 
3
- **Status**: Active — M0.1, M0.2, M1.1, M1.2, M2.1 shipped (PRs #68–#71, live 2026-09-03); M1.3 `shadow-service` shipped 2026-09-07 (`871f93b`) and deployed 2026-09-08; re-scoped 2026-09-03 after the VPS cutover review; next M2.2 `simulate-ingress`, which is now the **function half** only — the route split off as M2.2b `shadow-simulate-route` on 2026-09-09
3
+ **Status**: Active — shipped: M0.1, M0.2, M1.1–M1.4, M1.3b, M1.7, M2.1, M2.2, M2.2b, M2.3, M3.1, M1.3d, M1.5 (the last three 2026-10-21, on local `dev`, not yet deployed; M1.4 `shadow-diff` 2026-10-01, M3.1 `shadow-from-worktree` 2026-10-19); the bench is on the deploy path since `release-gate` R5.1 `mercury shadow rehearse` (2026-10-20). Open: M2.4 (next), M1.3c (deferred 2026-10-02, superseded by M1.3d), M1.6, M3.2, M4.1, M4.2
4
4
  **Slug**: rehearsal-bench
5
5
  **Created**: 2026-09-02
6
- **Last updated**: 2026-09-07 (M1.3 `shadow-service` shipped; 2026-09-03 re-scope: the real host joins the invariant; the deploy gate moves to the sibling goal [`release-gate`](../release-gate/goal.md); see [`docs/notes/2026-09-03-release-gate-and-test-environment.md`](../../notes/2026-09-03-release-gate-and-test-environment.md))
6
+ **Last updated**: 2026-10-21 (M1.3d, M1.5, M2.3 landed on local `dev`; M1.3d added, M1.3c superseded by it, D-017; next M1.3d → M1.5 → M2.3 → M2.4). Earlier: 2026-09-07 (M1.3 `shadow-service` shipped; 2026-09-03 re-scope: the real host joins the invariant; the deploy gate moves to the sibling goal [`release-gate`](../release-gate/goal.md); see [`docs/notes/2026-09-03-release-gate-and-test-environment.md`](../../notes/2026-09-03-release-gate-and-test-environment.md))
7
7
 
8
8
  ---
9
9
 
@@ -1,13 +1,13 @@
1
1
  # Roadmap: Rehearsal Bench
2
2
 
3
3
  **Goal**: [rehearsal-bench](goal.md)
4
- **Last updated**: 2026-09-15 (§ *What the pending list says the bench still lacks* added after the beta.2 sweep — the 55 open manual checks sorted by what would take each one over, and two stories cut from it: M1.7 `shadow-feed-fixtures` and M1.3c `shadow-own-credential`. Earlier: 2026-09-09 M2.2 **split** into M2.2 `simulate-ingress`, the function half, and M2.2b `shadow-simulate-route`, the HTTP face — after an adversarial review of the M2.2 plan found three things the row asserted but the code does not support, and a route auth gap: the shadow inherits the **live** API secret, so M2.2b owns a new `MERCURY_SHADOW_API_SECRET`. M2.3 now depends on M2.2b; `release-gate` R3 still waits on M2.2 alone. Earlier: 2026-09-06 (M4.2 `test-bot-instance` added as an owner's-decision story after the "why not a test bot on a snapshot?" review — D-007 extended with the identity/egress/remap analysis; nothing else moved). Earlier: 2026-09-03 (re-scope after the VPS cutover review, [note](../../notes/2026-09-03-release-gate-and-test-environment.md):
4
+ **Last updated**: 2026-10-21 (M1.3d, M1.5 and M2.3 landed on local `dev`, not yet deployed; next M2.4. Earlier the same day: M1.3d `shadow-rehearse-beside-live` added from the owner's backlog item and M1.3c marked superseded by it, D-017; next order M1.3d → M1.5 → M2.3 → M2.4; specs for M1.5 and M2.3 planned. Earlier the same day (reconcile only: M2.2 marked done — it shipped 2026-09-10 and the row still read `backlog`; `release-gate` R5.1 `mercury shadow rehearse` added to the release-gate interface table as the bench's first deploy-path caller. No story, order or decision changed. Earlier: 2026-09-15 (§ *What the pending list says the bench still lacks* added after the beta.2 sweep — the 55 open manual checks sorted by what would take each one over, and two stories cut from it: M1.7 `shadow-feed-fixtures` and M1.3c `shadow-own-credential`. Earlier: 2026-09-09 M2.2 **split** into M2.2 `simulate-ingress`, the function half, and M2.2b `shadow-simulate-route`, the HTTP face — after an adversarial review of the M2.2 plan found three things the row asserted but the code does not support, and a route auth gap: the shadow inherits the **live** API secret, so M2.2b owns a new `MERCURY_SHADOW_API_SECRET`. M2.3 now depends on M2.2b; `release-gate` R3 still waits on M2.2 alone. Earlier: 2026-09-06 (M4.2 `test-bot-instance` added as an owner's-decision story after the "why not a test bot on a snapshot?" review — D-007 extended with the identity/egress/remap analysis; nothing else moved). Earlier: 2026-09-03 (re-scope after the VPS cutover review, [note](../../notes/2026-09-03-release-gate-and-test-environment.md):
5
5
  M1.3 gains the instance-label prerequisite and the fleet-box shape; M1.6
6
6
  `snapshot-across-hosts` added; M3.2 extended to tagula's space-sync path;
7
7
  M3.3 `sync-rehearse` **moved** to [`release-gate`](../release-gate/roadmap.md)
8
8
  as a caller of the gate; execution order rewritten. Earlier: 2026-09-02 M0.1
9
9
  drafted, the three day-one stories planned, the liveness milestone
10
- withdrawn on `c3d21cb`)
10
+ withdrawn on `c3d21cb`)))
11
11
 
12
12
  > Order chosen so that each milestone is useful on its own: M0 changes how
13
13
  > people work tomorrow with no code; M1 gives a no-phone, no-reach bot that
@@ -16,6 +16,11 @@ withdrawn on `c3d21cb`)
16
16
  > regression suite; M4 is the phone leg. Story slugs are `/f-feature-dev`
17
17
  > inputs and become `docs/backlog/<slug>.md` when planned.
18
18
 
19
+ > **Next, 2026-10-21** (owner): M1.3d → M1.5 → M2.3 → M2.4. M1.3d makes
20
+ > the deploy rehearsal usable at any hour; M1.5 closes the last two exits
21
+ > (Telegraph, broker); M2.3 turns the hand-written simulate event into one
22
+ > command, which M2.4 and unattended checks build on.
23
+
19
24
  > **Execution order since 2026-09-03** (by leverage, not by milestone
20
25
  > number): M1.3 → M2.2 → M2.2b → M2.3 → M1.4 → M1.5 → M3.1 →
21
26
  > M1.6 → M2.4 → M3.2 → M4.1. `release-gate` R1 (`mercury preflight`) runs
@@ -49,9 +54,10 @@ matrix in §2 or edits it; `ops-preflight` refuses the exact command of
49
54
  | M1.2 | `mercury shadow snapshot`: `VACUUM INTO` + copy of `spaces/ global/ extensions/ model-capabilities.yaml` into `~/mercury-shadow/<ts>/`, `SNAPSHOT.json` (source commit, live HEAD, time), `current` symlink, shadow `.env` derived by a script (copy + override lines, never printed) and a `mercury.yaml` with `runtime.data_dir` and `server.port` rewritten; the `.env` writer emits `MERCURY_SHADOW=1` (only `true`/`1` enable the mode) and the shadow **refuses to start** when `runtime.data_dir` is not under `~/mercury-shadow/` — the flag alone protects people, not the live DB (M1.1 review, 2026-09-02) | shadow-snapshot | M1.1 | **shipped** 2026-09-03 — [spec](../../archive/rehearsal/2026-09-03-shadow-snapshot.md), PR #71, deployed 2026-09-03. `mercury shadow snapshot\|prune`, `src/ops/shadow-root.ts` + `src/ops/shadow-snapshot.ts`; the data-dir refusal closes the M1.1 residual |
50
55
  | M1.3 | `mercury shadow up|down|status|logs`: transient user unit via `systemd-run --user --unit mercury-shadow`, `--src` defaults to `~/mercury-src`; `down` prints the run cost from the shadow's `token_usage`; refuses `up` when the live `mercury` unit is not the only thing on 8787 or when the snapshot is older than `--max-age`. **From M1.2's plan:** the unit must set `HOME` (the data-dir guard refuses on an empty home), and `up` must record its snapshot path so `shadow prune` skips the running one. **Added 2026-09-03 (D-011, D-012):** (a) *prerequisite, first commit of the story* — every container the runner creates (agent, probes) carries a `mercury.instance=<id>` label derived from the data dir, and `cleanupOrphans` **always** filters on it — no id, no sweep; negative test deletes the filter and watches a foreign container get listed; (b) `--src` also accepts an installed package (`mercury-agent` under npm, run as root with `XDG_RUNTIME_DIR=/run/user/0`), so the same command works on a fleet box; (c) `up` refuses below `--min-free-mem` / `--min-free-disk`, while `task_runs` has an unfinished row, or while a cron is due within the run window; never builds an image (missing derived image → refuse, name the tag); binds 8788 to loopback | shadow-service | M1.2 | **done** 2026-09-07 — [spec](../../archive/rehearsal/2026-09-07-shadow-service.md). **Three corrections found in the code while building it:** the roadmap's "refuse while `task_runs` has an unfinished row" could not be written as specified (`finished_at` is NOT NULL and rows are written at completion, so the table never shows a run in progress) — it is a *running container* carrying the live instance id instead; "binds 8788 to loopback" was **dropped**, because under `runc` agent containers reach the host API over TCP at `host.docker.internal:<port>` and a loopback bind would break agent runs in the shadow only (a bind-host option is B-2, live and shadow alike); and the label had to cover a fourth container site, `preflight/probe-container.ts` |
51
56
  | M1.4 | `mercury shadow diff [--space <id>]`: live snapshot vs shadow now — `space_config` / `space_preferences` / `tasks` / `space_roles` / `mutes` rows with `updated_by` before→after, `messages` added (count + first lines), workspace tree by hash (`MEMORY.md`, `knowledge/**`, `AGENTS.md`), `extension_state` keys. Output is the report a migration rehearsal is judged on | shadow-diff | M1.2 | **done 2026-10-01** ([archive](../../archive/rehearsal/2026-10-01-shadow-diff.md)) — `diffShadow` in `src/ops/shadow-diff.ts` is the library call M3.2 / M4.1 reuse |
52
- | M1.5 | `longview` gains a `file` target and shadow mode forces it; the transcript shows the page path. `capability` route refuses non-`readOnly` actions in shadow mode | longview-file-target | M1.1 | backlog |
57
+ | M1.5 | `longview` gains a `file` target and shadow mode forces it; the transcript shows the page path. `capability` route refuses non-`readOnly` actions in shadow mode | longview-file-target | M1.1 | done 2026-10-21 (`c3526705`, local `dev`) — [spec](../../archive/rehearsal/2026-10-21-longview-file-target.md) (also closes the TradeStation `confirm` host route; the container still holds the live TradeStation token — bug `shadow-container-receives-the-live-tradestation-access-token`); not yet deployed |
53
58
  | M1.3b | **Shadow admin list is chosen, never inherited** (added 2026-09-13, D-015, from bug `shadow-env-keys-does-not-override-mercury-admins`): `shadow snapshot --admins <id,…>` (default empty) is what `renderShadowEnv` writes as `MERCURY_ADMINS`; `SNAPSHOT.json.shadow.adminCount` records the count, `snapshot`/`up`/`status` print it (never the ids); `up` refuses a snapshot whose manifest records no count. Landed with the shadow-up hardening track (B1 of the 2026-09-12 bench-and-gate round), which also closed: the live project read from the unit's `WorkingDirectory` / `SNAPSHOT.json` (never cwd, disagreement refuses), the cron gate's third state (unknown denies, none allows), `mercury run` on `process.execPath` + the unit `PATH` composed from the live unit / `--path` (never the shell's), and the CLI tests' scoped user bus | shadow-admins | M1.3 | **done** 2026-09-13 — post-mortems under `docs/debug/{moderate,minor}/2026-09-1{2,3}-shadow-*` and `…-mercury-run-spawns-a-bare-bun-…` |
54
- | M1.3c | **Shadow-own model credential** (added 2026-09-15, from bug `shadow-snapshot-auth-json-goes-stale-when-the-live-bot-rotates-its-refresh-token`): the snapshot stops copying `global/auth.json`; `up` points `MERCURY_AUTH_PATH` at a shadow-only file the owner logs in to once (`mercury auth login` against the shadow root), so the shadow never holds the live refresh token — neither dies when the other rotates. D-016's principle ("a shadow answers to no live credential") extended from the API secrets to the model credential. The `Bun.serve` 10 s stream death on `/api/shadow/simulate` (bug `shadow-simulate-stream-dies-at-bun-serve-10s-idle-timeout`) — the other reason a bench run needs a person watching — is **not** this story's: it is fixed directly as plan `bugs-0915` S1 (corrected 2026-09-15), and the bug's shape (a) mitigation (`up` re-copies the live credential, `--dry-run` gates on it) ships as `bugs-0915` S4; this story owns shape (c) | shadow-own-credential | M1.3 | backlog |
59
+ | M1.3c | **Shadow-own model credential** (added 2026-09-15, from bug `shadow-snapshot-auth-json-goes-stale-when-the-live-bot-rotates-its-refresh-token`): the snapshot stops copying `global/auth.json`; `up` points `MERCURY_AUTH_PATH` at a shadow-only file the owner logs in to once (`mercury auth login` against the shadow root), so the shadow never holds the live refresh token — neither dies when the other rotates. D-016's principle ("a shadow answers to no live credential") extended from the API secrets to the model credential. The `Bun.serve` 10 s stream death on `/api/shadow/simulate` (bug `shadow-simulate-stream-dies-at-bun-serve-10s-idle-timeout`) — the other reason a bench run needs a person watching — is **not** this story's: it is fixed directly as plan `bugs-0915` S1 (corrected 2026-09-15), and the bug's shape (a) mitigation (`up` re-copies the live credential, `--dry-run` gates on it) ships as `bugs-0915` S4; this story owns shape (c) | shadow-own-credential | M1.3 | deferred by the owner 2026-10-02; **superseded by M1.3d** on every box that runs on a long-lived token (D-017) |
60
+ | M1.3d | **Rehearse beside the live bot** (added 2026-10-21, owner backlog item of 2026-10-20, D-017): `up --beside-live` (always passed by `rehearse`) reads the shadow's own long-lived `sk-ant-oat01` token from `~/mercury-shadow/credentials/default/anthropic-oauth-token` (owner-minted, 0600, never in a snapshot) and writes it as a marked block in the snapshot `.env`; one guard `credential-shared-chain` replaces the cron window, so `live-container-running` / `live-cron-due` become warnings; the shadow unit and its containers get lower CPU weight and a memory cap. Both shadow tokens (local, Tagula) were minted and the local one installed on 2026-10-20; until this lands the shadow inherits the live bot's non-rotating token, so it no longer expires. Tagula parallel rehearsal stays out of scope (3.8 GB box) | shadow-rehearse-beside-live | M1.3, M3.1, release-gate R5.1 | done 2026-10-21 (`be1f99ab`, local `dev`) — [spec](../../archive/rehearsal/2026-10-21-shadow-rehearse-beside-live.md); not yet deployed: three box checks in the spec's Retrospective, the decisive one a rehearsal started with task 1337 due inside 30 minutes |
55
61
  | M1.6 | **Snapshot across hosts** (added 2026-09-03, D-013): `mercury shadow snapshot --out <file>` packs a snapshot as one verified archive (the `VACUUM INTO` db, `spaces/ global/ extensions/`, `SNAPSHOT.json`; never `whatsapp-auth/`, never `.env` values); `mercury shadow restore <file>` unpacks it under `~/mercury-shadow/<ts>/` on another host with the shadow `.env` + `mercury.yaml` generated there, ownership normalised to the running user (the Windows uid 197609 trap), and `MERCURY_SHADOW=1` written — a restored copy **cannot** start live without `mercury shadow promote`, which refuses while any other host is known to hold the WhatsApp session. Replaces tagula's `pack.sh`/`pull.sh` (torn WAL, exit 0, 2026-09-01) | snapshot-across-hosts | M1.2, M1.3 | backlog |
56
62
  | M1.7 | **Synthetic feed input** (added 2026-09-15; **shipped 2026-09-24** as `759d04e`, `docs/archive/rehearsal/2026-09-24-shadow-feed-fixtures.md` — as built, fixtures live under the shadow's `<dataDir>/fixtures/feeds/<encoded target key>`, not `current/`; `--reset-feed-state` was dropped for a per-process `{{nonce}}` token, so no state is deleted; the original text follows): in shadow mode feed-watch's `fetchImpl` (`examples/extensions/feed-watch/index.ts:183`) serves `~/mercury-shadow/current/fixtures/feeds/<source-key>` when the file exists and falls through to the network otherwise — no `http://` sources, so `config.ts:252`'s https-only rule stays; and `shadow snapshot --reset-feed-state` drops feed-watch's `seen:`/`buffer:`/`pending:` rows for a space so the first poll treats the fixture as new (the copied `seen` state is why a shadow at debug level found 0 exclude-term drops on 2026-09-15). A fixture is a plain RSS/JSON/HTML file; a `dead` marker makes the source fail, for the failure-routing lines | shadow-feed-fixtures | M1.2 | done |
57
63
 
@@ -71,9 +77,9 @@ unchanged across the whole checkpoint.
71
77
  | ID | Story | Slug | Depends on | Status |
72
78
  |----|-------|------|------------|--------|
73
79
  | M2.1 | Extract the adapter's pre-handler derivations into `src/adapters/whatsapp-ingress.ts` as pure functions (`buildReplyContext`, `isSelfJid` over `{id, lid}`, mention detection, caller canonicalisation); the adapter calls them; tests pin the F5 adapter half that `docs/bugs/reply-to-member-triggers-bot.md` says is untestable | whatsapp-ingress-extraction | — | **done** 2026-09-02 — [spec](../../archive/ingress-hardening/2026-09-02-whatsapp-ingress-extraction.md), PR #69 |
74
- | M2.2 | **Function half** (split from the route on 2026-09-09, see M2.2b): `simulateIngress(event)` in `src/core/` — synthetic WhatsApp event → chat `Message` → the real `createMessageHandler` closure via a shadow bridge whose sends append to `shadow/outbox.jsonl` **as both the raw text the handler produced and the wire form `applyRtlDirection(normalizeChatMarkdown(text))` the adapter would have sent** — the shadow constructs no adapter (B1), so an outbox recording only the raw text would show what the model wrote, not what the group would have seen; response streams the outbox events for that thread until the run settles (heartbeat, edits, deletes, reply, files). Attachments arrive as supplied files and reach the *received* branch of `gateIncomingMedia`, not its `count === 0` "could not be downloaded" branch. **Three corrections found by the plan review of 2026-09-09, before any code:** (a) the handler's promise resolves *before the run starts* on the default WhatsApp path — `debouncer.submit` is the closure's last statement (`handler.ts:473`) and returns `void`, so "resolves when the run settles" is a thing this story **builds**, not a definition it inherits, and it must also quiesce the heartbeat's fire-and-forget `discardStatusMessage` continuation and bound the `SpaceQueue` wait; (b) `isBotMentioned` / `isReplyToBot` are **derived, never caller-supplied** — accepting them as flags is the `/chat` shortcut the goal forbids and makes the Milestone 2 checkpoint vacuous; (c) the wire form lives at **four** sites, two of them in the bridge (`bridges/whatsapp.ts:178` `editMessage`, `:237` `sendFiles` caption), so it is extracted once and shared rather than copied a fifth time | simulate-ingress | M1.3, M2.1 | backlog |
80
+ | M2.2 | **Function half** (split from the route on 2026-09-09, see M2.2b): `simulateIngress(event)` in `src/core/` — synthetic WhatsApp event → chat `Message` → the real `createMessageHandler` closure via a shadow bridge whose sends append to `shadow/outbox.jsonl` **as both the raw text the handler produced and the wire form `applyRtlDirection(normalizeChatMarkdown(text))` the adapter would have sent** — the shadow constructs no adapter (B1), so an outbox recording only the raw text would show what the model wrote, not what the group would have seen; response streams the outbox events for that thread until the run settles (heartbeat, edits, deletes, reply, files). Attachments arrive as supplied files and reach the *received* branch of `gateIncomingMedia`, not its `count === 0` "could not be downloaded" branch. **Three corrections found by the plan review of 2026-09-09, before any code:** (a) the handler's promise resolves *before the run starts* on the default WhatsApp path — `debouncer.submit` is the closure's last statement (`handler.ts:473`) and returns `void`, so "resolves when the run settles" is a thing this story **builds**, not a definition it inherits, and it must also quiesce the heartbeat's fire-and-forget `discardStatusMessage` continuation and bound the `SpaceQueue` wait; (b) `isBotMentioned` / `isReplyToBot` are **derived, never caller-supplied** — accepting them as flags is the `/chat` shortcut the goal forbids and makes the Milestone 2 checkpoint vacuous; (c) the wire form lives at **four** sites, two of them in the bridge (`bridges/whatsapp.ts:178` `editMessage`, `:237` `sendFiles` caption), so it is extracted once and shared rather than copied a fifth time | simulate-ingress | M1.3, M2.1 | **done** 2026-09-10 — [spec](../../archive/rehearsal/2026-09-10-simulate-ingress.md), `a24eb6da` + B2a hardening `34cea2b7` (every handler path bounded, non-finite `timeoutMs` refused, one inbox writer for all four legs); row reconciled 2026-10-21 |
75
81
  | M2.2b | **Route half** (split from M2.2 on 2026-09-09): `POST /api/shadow/simulate`, registered only under `MERCURY_SHADOW=1`, as a thin HTTP face over M2.2's function — multipart upload for attachments, and a response that streams that thread's outbox events until the run settles (heartbeat, edits, deletes, reply, files); `streamSSE` already exists (`routes/dashboard.ts`). **Owns a new secret**: `MERCURY_SHADOW_API_SECRET`, generated per snapshot and written by `renderShadowEnv`, absent ⇒ the route refuses. Today `SHADOW_ENV_KEYS` (`ops/shadow-snapshot.ts:100-108`) does **not** override `MERCURY_API_SECRET`, so a shadow authenticates with the **live** bot's secret, and M1.3 deliberately dropped the loopback bind — without its own secret the route lets anyone holding the live secret spend model credits on the shadow at the same auth cost as reading `/api/spaces` | shadow-simulate-route | M2.2 | **built** 2026-09-13 — [spec](../../archive/rehearsal/2026-09-13-shadow-simulate-route.md), B2b of the bench-and-gate round; the route, `MERCURY_SHADOW_API_SECRET` (D-016), `/health.simulateRoute`, `shadow status`; deploy-gated live checks in `pending-verification.md` |
76
- | M2.3 | `mercury shadow say --space <id> --as <jid\|name\|new> [--reply-to last-bot\|last-user\|<id>] [--mention] [--file …] "<text>"` and `mercury shadow transcript --space <id> [--since]` rendering both sides like a chat; `--as new` registers a fresh member (the "second phone" without a phone) | shadow-cli | M2.2b | backlog |
82
+ | M2.3 | `mercury shadow say --space <id> --as <jid\|name\|new> [--reply-to last-bot\|last-user\|<id>] [--mention] [--file …] "<text>"` and `mercury shadow transcript --space <id> [--since]` rendering both sides like a chat; `--as new` registers a fresh member (the "second phone" without a phone) | shadow-cli | M2.2b | done 2026-10-21 (`1196bf9c`, local `dev`) — [spec](../../archive/rehearsal/2026-10-21-shadow-cli.md); not yet deployed, three live checks in `pending-verification.md`. Adds `--chat`; the client (`simulateOverHttp`) is the library M2.4 imports |
77
83
  | M2.4 | `scripts/football-harness.ts --shadow`: live mode targets the shadow through `simulate` instead of `/chat`, in `football-friends` itself, so the group-trigger fixtures and the member-role fixtures the suite could never run become runnable | harness-on-shadow | M2.3 | backlog |
78
84
 
79
85
  **Checkpoint:** the F5 scenario — a member swipe-replies to another member
@@ -215,6 +221,7 @@ live spaces. The post-deploy functional smoke on live spaces is
215
221
  | a shadow from a candidate tree or package for `sync-rehearse` and the fleet updater | `shadow up --src <mirror \| package>` | M1.3, M3.1 |
216
222
  | a snapshot restorable on the destination box for migration rehearsal | `shadow snapshot --out` / `shadow restore` / `shadow promote` | M1.6 |
217
223
  | the data half of a rehearsal report next to the env half | `shadow diff` | M1.4 |
224
+ | one verdict per deploy candidate, before `~/sync-mercury.sh` restarts live (R5.1, landed 2026-10-20) | `shadow up --src` staging + `shadow diff`, composed by `mercury shadow rehearse`; refuses `image-drift` / `src-deps-differ` (idea `rehearse-what-the-shadow-refuses`) and, today, a live run or a due cron (backlog `shadow-rehearse-beside-live`) | M1.3, M1.4, M3.1 |
218
225
 
219
226
  The bench does **not** decide what a gate checks, when a deploy path must
220
227
  call it, or what dwell time a version needs before a customer box takes it.
@@ -225,7 +232,8 @@ call it, or what dwell time a version needs before a customer box takes it.
225
232
  M0.1 ─ M0.2
226
233
  M1.1 ─ M1.2 ─ M1.3 ─┬─ M3.1
227
234
  │ ├──── M1.6
228
- │ └──── M1.3c ─ (unattended shadow)
235
+ │ ├──── M1.3c (deferred; superseded by M1.3d)
236
+ │ └──── M1.3d ─ (rehearse at any hour) ◄─ release-gate R5.1
229
237
  └── M1.7 ─────────────────────► M2.4 (feed-shaped fixtures)
230
238
  └── M1.4 ───┬─ M3.2 ◄─ release-gate R3 (smoke)
231
239
  M1.1 ─ M1.5 │
@@ -1,9 +1,9 @@
1
1
  # Release Gate — the checks a deploy must pass, and the rules that say every deploy path must call them
2
2
 
3
- **Status**: Active — created 2026-09-03 from the VPS cutover review. **14/16 stories done** (R0–R4 complete; R3 landed on `dev` 2026-09-13). Remaining: **R5.1 `sync-rehearse`**, unblocked 2026-10-19 by bench M3.1, and **R5.2 `workflow-gate-step`**, after R5.1. Both are planned in `docs/backlog/` (G-012–G-014). Open owner checkpoints: R4 (read `docs/release-gate.md` and strike), and box evidence for R1–R3.
3
+ **Status**: Active — created 2026-09-03 from the VPS cutover review. **16/16 stories landed** (R5.1 2026-10-20, R5.2 Mercury half 2026-10-21). Open: the R5 checkpoint — no rehearsal has gone green yet (three box rehearsals since the bootstrap: `live-cron-due` twice bypassed, `src-deps-differ` once; M1.3d `--beside-live`, which turns the first into a warning, is on `dev` and not deployed). Owner checkpoints still open: R4 (read `docs/release-gate.md` and strike), box evidence for R1–R3.
4
4
  **Slug**: release-gate
5
5
  **Created**: 2026-09-03
6
- **Last updated**: 2026-10-19 (continue session: status reconciled, R5 planned)
6
+ **Last updated**: 2026-10-21 (checkpoint: all stories landed; R5 checkpoint open)
7
7
 
8
8
  ---
9
9
 
@@ -1,7 +1,7 @@
1
1
  # Roadmap: Release Gate
2
2
 
3
3
  **Goal**: [release-gate](goal.md)
4
- **Last updated**: 2026-10-20 (**push deferred by the owner, 2026-10-20**: the R5 planning commits `6e97bc4d` and `53056629` are on local `dev` only, and local `dev` is behind `origin/dev`. Push them, from a fresh worktree on `origin/dev`, only when the owner says so. R5 plan **approved by the owner** after a review that folded in five fixes: branch rehearsal as the doc's evidence and the deploy-doc filter (G-014 amended), a pre-restart gap check in the sync, `live-cron-due` / `credential-stale` passthrough and the shared-OAuth-token risk). Earlier, 2026-10-19 (continue session: R3.1 row reconciled — landed 2026-09-13; R5.1 unblocked by bench M3.1 `shadow up --src` (`1fe47951`) and planned as `mercury shadow rehearse` called by `~/sync-mercury.sh` before the mirror moves (G-012, G-013); R5.2 split into a Mercury evidence ratchet plus the boilerplate's workflow step (G-014). Both R5 specs in `docs/backlog/` with architecture. Earlier: 2026-09-09 R0.4 reconciled, R0.6 split out, R2.2 `env diff` landed)
4
+ **Last updated**: 2026-10-21 (**local only, owner 2026-10-21:** `ac9f43f0` (goal sync, deployed to the box), `0aa98095` (box-check results) and the commit adding this note are on local `dev`, not `origin/dev`; they ride a later push, not their own. Same day: `dev` @ `ac9f43f0` deployed `--no-rehearse` (baked `resources/skills/spaces/SKILL.md`), then two green rehearsals of the deployed commit, the first ever on the box. The R5 checkpoint still needs a rehearsal *before* a deploy: the next code-only change to `dev`. Checkpoint: 16/16 landed. Box rehearsals since the bootstrap: 2026-10-20 17:34 `b0f68910` refused `live-cron-due`; 17:39 `c5bc39f7` deployed `--no-rehearse` (hourly task 1337 leaves no 30m window); 2026-10-21 02:30 `1a4201fb` refused `src-deps-differ` (hono floor + version bump), deployed `--no-rehearse`. No green rehearsal yet, so the R5 checkpoint is open; M1.3d `be1f99ab` (`--beside-live`) is the fix for the first refusal and is undeployed. Earlier, 2026-10-20 (**push deferred by the owner, 2026-10-20**: the R5 planning commits `6e97bc4d` and `53056629` are on local `dev` only, and local `dev` is behind `origin/dev`. Push them, from a fresh worktree on `origin/dev`, only when the owner says so. R5 plan **approved by the owner** after a review that folded in five fixes: branch rehearsal as the doc's evidence and the deploy-doc filter (G-014 amended), a pre-restart gap check in the sync, `live-cron-due` / `credential-stale` passthrough and the shared-OAuth-token risk). Earlier, 2026-10-19 (continue session: R3.1 row reconciled — landed 2026-09-13; R5.1 unblocked by bench M3.1 `shadow up --src` (`1fe47951`) and planned as `mercury shadow rehearse` called by `~/sync-mercury.sh` before the mirror moves (G-012, G-013); R5.2 split into a Mercury evidence ratchet plus the boilerplate's workflow step (G-014). Both R5 specs in `docs/backlog/` with architecture. Earlier: 2026-09-09 R0.4 reconciled, R0.6 split out, R2.2 `env diff` landed)
5
5
 
6
6
  > Order is by leverage against the live risk, not by size: R1 protects the
7
7
  > customer box within a session or two and depends on nothing; R2 is the
@@ -124,7 +124,7 @@ command or strikes the rule; no rule survives without a command.
124
124
  | ID | Story | Slug | Depends on | Status |
125
125
  |----|-------|------|------------|--------|
126
126
  | R5.1 | `~/sync-mercury.sh --rehearse` (ex rehearsal-bench M3.3): after the mirror is reset and before the restart, `shadow up --src <mirror>`, `preflight`, `smoke` for the spaces that have fixtures, print cost and `shadow diff`, ask before restarting live; `--rehearse` becomes the default and `--no-rehearse` must name a reason that lands in the journal | sync-rehearse | R1.1, R3.2, rehearsal-bench M1.3 + M3.1 | **landed 2026-10-20 (code + docs); box checks wait for the bootstrap deploy.** `mercury shadow rehearse`, the `~/sync-mercury.sh` patch, and fixtures for `main`. Spec: [`docs/archive/2026-10-20-sync-rehearse.md`](../../archive/2026-10-20-sync-rehearse.md). The first box run refused `boot-report-missing`: the deployed `8407fdb6` predates M3.1, so nothing is rehearsable until the bootstrap deploy. Earlier: **backlog, unblocked 2026-10-19** (M3.1 landed as `1fe47951`; its six box checks are still open). Planned in [`docs/backlog/sync-rehearse.md`](../../backlog/sync-rehearse.md), with two corrections to this row: the sequence is a Mercury command, `mercury shadow rehearse --src <tree>` (G-012), and `~/sync-mercury.sh` rehearses a detached worktree of the target sha **before** the mirror moves, not after (G-013). `smoke` refuses while a shadow is up (`src/smoke/boot.ts`), so it runs after `down` from a second staging of the same tree hash. No live space has a `smoke.yaml` yet, so the owner's first fixtures are part of the story (absence denies → `no-fixtures`). Image-baked and dependency changes cannot be rehearsed yet → idea `rehearse-what-the-shadow-refuses` |
127
- | R5.2 | Workflow wiring: `/f-bug-fix` and `/f-feature-dev` gain a **Gate** step between the check gate and deploy that runs preflight + smoke in the shadow and attaches both reports to the doc; the post-mortem template gains a required `Gate check:` line; `pending-verification.md` entries must carry an owner and a date | workflow-gate-step | R4.1, R5.1 | **backlog — split 2026-10-19 (G-014).** Mercury half planned in [`docs/backlog/workflow-gate-step.md`](../../backlog/workflow-gate-step.md): `tests/release-gate-evidence.test.ts` fails any spec or post-mortem archived after the cutoff without the `release-gate.md` §4 block (class list read from §4, refusal ids from R5.1's `RehearseRefusal`). The `Gate check:` line is already enforced by R3.3. The Gate step, the template block and the owner field are workflow formats and go to the boilerplate idea `rehearse-step-in-fix-and-feature-dev` (local `555f5ad`, unpushed) |
127
+ | R5.2 | Workflow wiring: `/f-bug-fix` and `/f-feature-dev` gain a **Gate** step between the check gate and deploy that runs preflight + smoke in the shadow and attaches both reports to the doc; the post-mortem template gains a required `Gate check:` line; `pending-verification.md` entries must carry an owner and a date | workflow-gate-step | R4.1, R5.1 | **Mercury half landed 2026-10-21; checkpoint open.** `tests/release-gate-evidence.test.ts` + `tests/helpers/deploy-docs.ts`, cutoff 2026-10-22 (a post-mortem dated 2026-10-21 already sat on `dev` without the block). Spec: [`docs/archive/2026-10-21-workflow-gate-step.md`](../../archive/2026-10-21-workflow-gate-step.md). The R5 checkpoint (one real fix through check gate → `shadow rehearse` → deploy, its post-mortem passing this test) waits for the bootstrap deploy, since every rehearsal refuses `boot-report-missing` until then. Boilerplate idea extended with the template block and the `MANUAL-VERIFY` owner field (local `faa8050`, unpushed). Earlier: **backlog — split 2026-10-19 (G-014).** Mercury half planned in [`docs/backlog/workflow-gate-step.md`](../../backlog/workflow-gate-step.md): `tests/release-gate-evidence.test.ts` fails any spec or post-mortem archived after the cutoff without the `release-gate.md` §4 block (class list read from §4, refusal ids from R5.1's `RehearseRefusal`). The `Gate check:` line is already enforced by R3.3. The Gate step, the template block and the owner field are workflow formats and go to the boilerplate idea `rehearse-step-in-fix-and-feature-dev` (local `555f5ad`, unpushed) |
128
128
 
129
129
  **Checkpoint:** one real fix ships through the full path — check gate,
130
130
  shadow, preflight report, smoke report, deploy — and the corresponding
@@ -103,6 +103,48 @@ and prints which one and why.
103
103
  - **Schema:** an upgrade rehearsal that migrated the shadow shows the new
104
104
  table or column under *schema* and is `changed` — that is correct.
105
105
 
106
+ ### Talking to the shadow: `shadow say` and `shadow transcript` (M2.3)
107
+
108
+ These replace the hand-built event JSON, the `curl` with a secret copied out
109
+ of the snapshot's `.env`, the poll on `outbox.jsonl` and the DB read for a
110
+ message id to quote.
111
+
112
+ ```bash
113
+ mercury shadow say --space football-friends --as new --mention "who plays tonight?"
114
+ mercury shadow say --space football-friends --as Alice --reply-to last-bot --mention "and me?"
115
+ mercury shadow say --space football-friends --as Alice --reply-to last-bot "and me?" # quote-only: the F5 negative control
116
+ mercury shadow transcript --space football-friends # since the shadow started
117
+ mercury shadow transcript --space football-friends --since 30m --json
118
+ ```
119
+
120
+ - **The target is the run file**, never cwd: `say` refuses unless a
121
+ `SHADOW-RUN.json` exists under `~/mercury-shadow/`, the unit is active, the
122
+ port is 8788, and `/health` says `shadow:true`, a different instance from
123
+ the live bot, and `simulateRoute:true`. The secret is the last
124
+ `MERCURY_SHADOW_API_SECRET=` of the snapshot's `.env`, sent in one header
125
+ and printed nowhere.
126
+ - **`--as`**: a jid (verbatim), a member's name (roles first, then authors in
127
+ the chat; ambiguous names list the candidates), or `new` (a synthetic
128
+ `000…@s.whatsapp.net` member the shadow registers on first contact). In a
129
+ DM the sender is the chat's own member and `--as` may be omitted.
130
+ - **`--reply-to`**: `last-bot` (the newer of the outbox's last reply/file and
131
+ the DB's last stored bot message with an id; deleted ones skipped),
132
+ `last-user`, or a platform message id. The quote id is a stored or
133
+ journaled one, never invented. `--mention` tags the shadow's synthetic self
134
+ (`@0`). `--chat` picks a chat when the space has more than one.
135
+ - **Exit codes:** `0` settled or no-run (a negative control is a valid
136
+ rehearsal) · `1` error, timeout, or the client stopped listening · `2`
137
+ refused. The footer says which, with the `simId`.
138
+ - **Bounds:** `/health` 2 s; silence 12 s (three missed keepalives); overall
139
+ `--timeout` (default 6m) + 30 s. When one fires, `say` says which and
140
+ stops listening — the run continues, and `transcript` shows what it sent.
141
+ - **`transcript`** merges members (the shadow DB) with the bot (the outbox
142
+ journal; before the shadow started, the DB's history marked
143
+ `bot (live history)`). Member jids print as `…1234`. After `shadow down`
144
+ it reads `current` and says so. Known gaps, stated in its header:
145
+ scheduled and task sends never reach the outbox, and a message dropped
146
+ before storage (paused, empty) is only in `say`'s footer.
147
+
106
148
  ## 3. What can reach a person — the send-site inventory
107
149
 
108
150
  Every place a run's outcome leaves the process, as of `dev` @ `6a4cd60`.
@@ -127,6 +169,13 @@ named reason, or it needs a branch.
127
169
  | E13 | `runtime.ts:637` | broadcast to every `dm-*` space | global-admin gate | **B1** via E15 |
128
170
  | E14 | `src/core/operator-alerts.ts` | operator alerts to the adapter outbox | cooldown only | **B1** — there is no adapter outbox |
129
171
  | E15 | `src/main.ts:588-640` | `MessageSender` — resolves a space to all its conversations | drops with a warn when no bridge exists (`"Message dropped — no bridge for platform"`) | **B1** — `bridges` is `{}`, so every thread hits the existing drop |
172
+ | E17 | `src/core/routes/tradestation.ts` `POST /tradestation/orders` with `confirm: true` | places a real order, SIM or live | `tsAllowLiveOrders` (live accounts only) | **B6** — `config.shadow !== false` answers `403 shadow_refused` before the pending order is loaded; the propose leg (`orderconfirm`, places nothing) stays allowed |
173
+ | E18 | `src/core/routes/capability.ts` `POST /capability/:name/:action` | a host handler with host credentials: an issued invoice (`morning document-create`), a sent or moved mail (`office-365-mail send/move/…`), an erased archive file (`archive forget`) | the caller's `<name>` permission | **B5** — `config.shadow !== false` refuses every action the extension did not declare in `mercury.capability(…, { readOnly })`, with `403 shadow_refused`, before the body parse and the handler. No declaration = every action refused (yahoo-mail today) |
174
+
175
+ **B5** and **B6** are M1.5's host-side refusals (`longview-file-target`): B5 is
176
+ the capability route's read-only gate, B6 the TradeStation route's `confirm`
177
+ gate. Both pass only on a literal `config.shadow === false`, both refuse before
178
+ any handler or pending-order work, and both log a warn.
130
179
 
131
180
  E10–E15 close on **B1** — the single fact that no adapter is constructed. That
132
181
  is the point of D-001: one lever, not six checks. The `/health` `shadow` field
@@ -165,8 +214,13 @@ only if `consoleUrl` is set — it is not, here) — **B2**, `loadConfig` forces
165
214
  `consoleUrl` to `undefined` in shadow mode; task delivery to the console
166
215
  (`:667-691`) — **B3**, a separate guard, because that site reads
167
216
  `process.env.MERCURY_CONSOLE_URL` directly and never sees `config.consoleUrl`;
168
- **Telegraph page creation** (`examples/extensions/longview/targets/telegraph.ts:178-232`
169
- — public and undeletable) — *not yet closed*, M1.5 (`longview-file-target`);
217
+ **Telegraph page creation** (`examples/extensions/longview/targets/telegraph.ts`
218
+ — public and undeletable) — **closed by M1.5** (`longview-file-target`): longview
219
+ uses Telegraph only when `ctx.config.shadow === false`, and otherwise writes the
220
+ page to `<dataDir>/longview/pages/` and puts its absolute path in the reply
221
+ (`targets/select.ts`, `targets/file.ts`); a stale installed longview with no
222
+ such check is caught by the core backstop `src/core/shadow-egress.ts`, which in
223
+ a shadow makes `fetch` refuse `telegra.ph` and its subdomains;
170
224
  feed polling (every space, every interval) — real, but against the shadow's own
171
225
  copied DB; TTS — real, and accepted like any other outbound call.
172
226
 
@@ -177,9 +231,14 @@ permissions (`tasks create|run`, `config set`, `prefs set`, `roles grant`,
177
231
  handler with host credentials, e.g. a broker).
178
232
 
179
233
  **Irreversible from any ring:** a Telegraph page, a capability-broker action,
180
- an outbound web call. Shadow mode refuses the first two (`longview` writes
181
- the page to a file; the broker refuses non-read actions) and accepts the
182
- third as the price of fidelity.
234
+ a TradeStation order, an outbound web call. Since M1.5 shadow mode refuses the
235
+ first three on every **host** path (`longview` writes the page to a file, the
236
+ broker refuses every action not declared read-only — E18 — and the order route
237
+ refuses `confirm` — E17) and accepts the fourth as the price of fidelity. Not
238
+ by construction for the order: the container still receives the live
239
+ TradeStation access token (see §9), and container egress is real. A
240
+ read-only action is still a real outbound call: `web-search` spends real
241
+ provider budget, and `office-365-mail read` reads the real mailbox.
183
242
 
184
243
  ## 4. Where residue lands — the side-effect inventory
185
244
 
@@ -330,7 +389,12 @@ line above every destructive command (archived spec:
330
389
  only that), when anything but the live `mercury` unit holds 8787, when 8788
331
390
  is taken, when memory or disk is short, when the live bot has a container
332
391
  running, when a live task is due inside the window (`--window`, default 90m),
333
- or when the live bot's containers predate the `mercury.instance` label. It
392
+ or when the live bot's containers predate the `mercury.instance` label. Those
393
+ two live-busy refusals belong to **plain** `up`. With `--beside-live`, which
394
+ `shadow rehearse` always passes, they are printed under `Warnings:` instead.
395
+ It then refuses `credential-shared-chain`: the shadow would share a rotating
396
+ credential with live. The fix is the shadow's own token file
397
+ (`docs/configuration.md`, Shadow mode). It
334
398
  prints **every** refusal, not the first. `--dry-run` runs every check and
335
399
  prints the unit command without starting anything — run it first, always.
336
400
  `--src` defaults to `~/mercury-src` and takes any git working tree — a
@@ -390,7 +454,10 @@ and the report path (`~/mercury-shadow/rehearsal/<timestamp>.json`, plus
390
454
  `latest.json`; each child's report and log sit in the matching directory).
391
455
  Exit 0 green, 1 red, 2 refused, and the verdict is read from the report.
392
456
  `--no-smoke "<reason>"` skips smoke and records why; no fixtures and no reason
393
- is `no-fixtures`. `--window` (default 30m) is passed to `up`. `~/sync-mercury.sh`
457
+ is `no-fixtures`. `--window` (default 30m) is passed to `up`, together with
458
+ `--beside-live`: a rehearsal does not wait for a live run or a due task. They
459
+ are recorded as `warnings` on the report's `up` step. What it needs instead is
460
+ a shadow token, or an inherited credential that does not rotate. `~/sync-mercury.sh`
394
461
  runs exactly this before it moves the mirror (`docs/release-gate.md` Gate 4).
395
462
  Paste the report path into the item's doc as the §4 `Shadow (Gate 2)` line.
396
463
 
@@ -407,9 +474,9 @@ when one step needs a closer look):
407
474
  4. **Up**: `… shadow up --src <worktree>`. An `image-drift` refusal means the
408
475
  branch changes a file baked into the agent image (or the version): it
409
476
  cannot be rehearsed on the live image — stop here.
410
- 5. **Exercise it**: `mercury smoke`, the simulate route
411
- (`POST /api/shadow/simulate`), then `shadow diff` for what the rehearsal
412
- changed.
477
+ 5. **Exercise it**: `mercury smoke`, `shadow say` / `shadow transcript`
478
+ (§2, over `POST /api/shadow/simulate`), then `shadow diff` for what the
479
+ rehearsal changed.
413
480
  6. **Evidence**: `shadow status` (the `src:` and `tree:` lines), the smoke
414
481
  report, the diff verdict — pasted into the item's doc.
415
482
  7. **Down**: `… shadow down` — prints the cost, removes the staged copy.
@@ -438,11 +505,37 @@ owes the generic host-side probe harness that sends through the M2.2 seam
438
505
 
439
506
  ## 9. Known gaps (kept honest)
440
507
 
441
- **While a shadow is running (M1.3), these are still open and are the operator's
442
- care, not the bench's:** `longview` still publishes to its real target and the
443
- capability broker still accepts non-read-only actions — both are M1.5, and
444
- until it lands a rehearsal that publishes a page or places a broker order does
445
- so for real. A container's outbound web calls are real in every ring (D-005).
508
+ **While a shadow is running, these are still open and are the operator's
509
+ care, not the bench's** (the Telegraph page and the broker's write actions
510
+ were closed by M1.5):
511
+
512
+ - **yahoo-mail declares no read-only actions**, because it is baked into the
513
+ image; a shadow therefore refuses *every* yahoo-mail action until
514
+ `ideas/yahoo-mail-capability-readonly.md` lands (which must also confirm `read` uses
515
+ `BODY.PEEK`).
516
+ - **The container still holds the live TradeStation access token.**
517
+ `tradestation`'s `before_container` hook injects `TRADESTATION_ACCESS_TOKEN`
518
+ with no shadow check, so an agent that calls the API directly instead of the
519
+ host route skips E17
520
+ (`bugs/shadow-container-receives-the-live-tradestation-access-token.md`).
521
+ - **Extension jobs and hooks that call out on their own** — `tradestation`'s
522
+ `ts-token-refresh`, the Office 365 and gws OAuth refresh — still run in a
523
+ shadow and may rotate a credential the live bot holds; so do the
524
+ refresh-token exchanges behind `office-365-mail` and `morning`'s
525
+ read-only actions (`ideas/shadow-extension-token-refresh.md`).
526
+ - **The Telegraph backstop wraps only the global `fetch`.** A stale extension
527
+ that calls `node:https` or a `fetch` captured before boot is not caught; the
528
+ primary guard is longview's own target selection. Accepted.
529
+ - **`archive forget` cannot be rehearsed** — refused in a shadow; accepted.
530
+ - **The longview file target runs no image probes**, so a page whose images
531
+ would be dropped on Telegraph keeps them in the file; accepted.
532
+ - **Catalog extensions get their declarations only when reinstalled.** Until
533
+ the boot sync refreshes `morning`, `office-365-mail`, `overview`, `archive`
534
+ and `web-search`, a shadow refuses all of their actions — the safe side. A
535
+ shadow runs the installed copies its snapshot carried, and those refresh
536
+ only when that shadow itself boots and syncs.
537
+
538
+ A container's outbound web calls are real in every ring (D-005).
446
539
  A message goes *into* a shadow through `POST /api/shadow/simulate` (M2.2b,
447
540
  with the shadow's own secret); `mercury shadow say` (M2.3) is the CLI over it.
448
541
 
@@ -9,6 +9,64 @@ once every line under it is ticked.
9
9
 
10
10
  ---
11
11
 
12
+ ## Plan watchdog-1011 / S1
13
+
14
+ `scripts/ops/box-watchdog.sh`, one healthchecks.io check per box (spec
15
+ `docs/archive/2026-10-21-box-watchdog.md`, runbook `docs/runbooks/box-watchdog.md`).
16
+ Nothing is installed by the merge: each line is an owner step on a box. Never
17
+ write a ping URL value into this file or any other doc.
18
+
19
+ - [ ] First CI run after the push: the `check:shell` link reads PASS on
20
+ ubuntu-latest (shellcheck present on the runner).
21
+ - [ ] 1b home drill: the home healthchecks.io project has email and Telegram
22
+ integrations, `box-home-watchdog` exists (period 1 min, grace 3 min), and
23
+ `~/.config/box-watchdog.env` (0600) holds its UUID ping URL.
24
+ - [ ] 1b home drill: after `systemctl --user enable --now box-watchdog.timer`,
25
+ `box-home-watchdog` reads up within 2 minutes with `ok` bodies.
26
+ - [ ] 1b home drill: over 10 runs the journal's `Consumed … CPU time` averages
27
+ ≤ 60 ms per tick and no run peaks above 64 MB.
28
+ - [ ] 1b home drill: stopping `mercury` for 6 minutes in a proven gap brings an
29
+ email and a Telegram alert saying `no-answer` within 5 minutes, and a
30
+ recovery alert on both after the start.
31
+ - [ ] 1b home drill: `sha256sum ~/mercury-src/scripts/ops/box-watchdog.sh`
32
+ equals the file at the deployed commit, and `mercury preflight` exits 0.
33
+ - [ ] 1c Tagula, the same day: `sqlite3` installed (and
34
+ `sqlite3 -readonly -cmd '.timeout 5000' -- <dataDir>/state.db 'select 1;'`
35
+ prints 1 with that version), `box-tagula-assistant-watchdog`
36
+ exists in the Tagula project, `/etc/box-watchdog.env` (0600, root) holds
37
+ its UUID ping URL, and the timer is enabled beside `tagula-heartbeat.timer`.
38
+ - [ ] 1c Tagula: the same ping URL is mirrored into tagula-agents'
39
+ `.env.local`, after `git check-ignore -v .env.local` shows it ignored.
40
+ - [ ] 1c Tagula: `box-tagula-assistant-watchdog` reads up within 2 minutes with
41
+ `ok` bodies; the box copy's `sha256sum` equals the repo file at the
42
+ deployed commit; `mercury preflight` exits 0 on the box.
43
+ - [ ] 1c Tagula week: every `/fail` in the first 7 days is explained (the
44
+ heartbeat failed too, or a real disk / Docker / stuck-queue / unanswered
45
+ fault); an unexplained one restarts the 7 days.
46
+ - [ ] Step 10, after 7 clean days: `tagula-heartbeat.timer` disabled and the
47
+ script removed, `box-tagula-assistant` deleted in healthchecks.io, and
48
+ tagula-agents' interim `box-tagula-assistant-disk` check retired.
49
+
50
+ ---
51
+
52
+ ## shadow-cli (M2.3) — live checks (deploy-gated)
53
+
54
+ `mercury shadow say` / `shadow transcript` (spec `docs/in-progress/shadow-cli.md`,
55
+ branch `worktree-feature-shadow-cli`, 2026-10-21). Restart-only (no baked file).
56
+ Run against a shadow started with `mercury shadow up`, never the live bot.
57
+
58
+ - [ ] `mercury shadow say --space football-friends --as new --mention "…"` ends
59
+ `outcome: settled`, and `mercury shadow transcript --space football-friends`
60
+ shows the bot's reply under it.
61
+ - [ ] The F5 pair: a quote-only trigger (`--reply-to last-bot`, no trigger word,
62
+ no `--mention`) ends `outcome: no-run`; the same with the trigger in the body
63
+ ends `settled`. Paste both transcripts into the F5 debug doc — this is the
64
+ Milestone 2 checkpoint run.
65
+ - [ ] After using it, `grep -c MERCURY_SHADOW_API_SECRET ~/.bash_history` and a
66
+ grep for the snapshot's secret value both find nothing new from usage.
67
+
68
+ ---
69
+
12
70
  ## anchor task runs without a logon 2026-10-18 — reboot drill deferred
13
71
 
14
72
  `Start Mercury WSL` was switched to `LogonType: Password` with an at-startup
@@ -2549,3 +2607,9 @@ zap extractor reads one-store cards labelled `למפרט טכני` (restart-depl
2549
2607
 
2550
2608
  - [ ] MANUAL-VERIFY(2026-10-20): After the rebuild, `docker run --rm --entrypoint grep mercury-agent:<version> -c isThirdPartyAppRejection /app/src/agent/pi-failure-class.ts` should print a number above 0. Check this in the image itself, never the repo.
2551
2609
  - [ ] MANUAL-VERIFY(2026-10-20): On a shadow only (never the live bot), set `MERCURY_OVERRIDE_PI_SYSTEM_PROMPT=false` in the shadow's `.env` with an Anthropic OAuth leg first in the chain, and send one message. The Anthropic leg should be tried **once**, then the next leg should answer (or, with a single-leg chain, the reply should be "Something went wrong on my end. This has been logged for the operator.", never "try again"). The operator should get one 🚨 DM that says "third-party app (HTTP 400)" and names `agent.override_pi_system_prompt`, not `claude setup-token`.
2610
+
2611
+ ## Plan tagula-client-1008 / S9
2612
+
2613
+ `scheduled-run-over-cloud-quota-posts-the-quota-text-as-output`: host-only (`src/core/runtime.ts`, `operator-alerts.ts`, `system-messages.ts`; none baked). A restart deploys it. It only applies on a box in console mode (`consoleUrl` and `consoleUserId` set).
2614
+
2615
+ - [ ] MANUAL-VERIFY(2026-10-21): On a console-mode box, the first scheduled task to fire after a space's agent is over the daily message limit posts nothing in the group. The journal has `Scheduled task skipped: the console's daily message quota is used up`, the operator DM gets the "skipped, not failed … daily message limit" notice, and that task's `task_runs` row has `outcome` NULL, not `posted`.
@@ -1,7 +1,7 @@
1
1
  # Plan: tagula-client-1008
2
2
 
3
- **Status**: Active
4
- **Created**: 2026-10-08 **Last updated**: 2026-10-08
3
+ **Status**: Archived
4
+ **Created**: 2026-10-08 **Last updated**: 2026-10-21
5
5
  **Landing mode**: pr
6
6
  **Max width**: 5
7
7
  **Inputs**: build tagula-client-1008 — failures Tagula clients see, from the guy-pishkin outage of 2026-10-08 and the top of `/f-status`: shadow-rehearsal-archive-reconcile-deletes-live-drive-files reply-language-drifts-to-english-on-hebrew-input oauth-token-handed-to-container-can-expire-or-be-rotated-mid-run run-that-fails-after-its-deliverable-is-produced-discards-it operator-alert-dropped-when-admin-dm-is-not-linked-to-a-space mrctl-recall-is-gated-on-the-compact-permission, plus console-oauth-invalid-grant-reaches-no-operator third-party-apps-400-is-retried-and-shown-as-try-again scheduled-run-over-cloud-quota-posts-the-quota-text-as-output moved from monitoring-1005 (`--drop S10 S11 S13`) --width 5; `--rebuild --add chat-silence-sentinel-is-never-taught-so-the-model-explains-its-silence` (2026-10-08); `--rebuild` S10 to round 1, ahead of S2 and S8 on `container-entry.ts` (owner, 2026-10-08)