mercury-agent 0.24.4-beta.4 → 0.24.4

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
@@ -0,0 +1,108 @@
1
+ ## Launched — 2026-10-20T09:35Z
2
+ Branch: worktree-fix-run-that-fails-after-its-deliverable-is-produced-discards-it
3
+ Session: 5dc202f3-5f3e-4303-92a0-429a4f5ff919
4
+
5
+ ## Report — 2026-10-20T10:11Z
6
+ Outcome: delivered
7
+ Delivered: local
8
+ Blocked-on: —
9
+ Deploy needs: rebuild
10
+ Source: command
11
+ Files changed:
12
+ - docs/ARCHITECTURE.md
13
+ - docs/ROADMAP.md
14
+ - docs/archive/2026-10-19-shadow-from-worktree.md
15
+ - docs/backlog/sync-rehearse.md
16
+ - docs/backlog/workflow-gate-step.md
17
+ - docs/bugs/git-reading-tests-fail-in-the-check-mirror.md
18
+ - docs/bugs/run-that-fails-after-its-deliverable-is-produced-discards-it.md
19
+ - docs/bugs/scheduled-run-that-fails-after-its-tools-finish-drops-the-deliverable.md
20
+ - docs/bugs/tests-that-run-git-inherit-git-dir-and-commit-to-the-real-repo.md
21
+ - docs/bugs/third-party-apps-400-is-retried-and-shown-as-try-again.md
22
+ - docs/debug/minor/2026-10-20-third-party-apps-400-is-retried-and-shown-as-try-again.md
23
+ - docs/debug/moderate/2026-10-20-git-reading-tests-fail-in-the-check-mirror.md
24
+ - docs/debug/moderate/2026-10-20-run-that-fails-after-its-deliverable-is-produced-discards-it.md
25
+ - docs/goals/rehearsal-bench/roadmap.md
26
+ - docs/goals/release-gate/decisions.md
27
+ - docs/goals/release-gate/goal.md
28
+ - docs/goals/release-gate/roadmap.md
29
+ - docs/ideas/rehearse-what-the-shadow-refuses.md
30
+ - docs/ideas/shadow-up-cli-harness.md
31
+ - docs/live-testing.md
32
+ - docs/notes/critic-2026-10-12.md
33
+ - docs/pending-updates/shadow-from-worktree.md
34
+ - docs/pending-verification.md
35
+ - docs/release-gate.md
36
+ - src/agent/container-entry.ts
37
+ - src/agent/container-error.ts
38
+ - src/agent/container-runner.ts
39
+ - src/agent/image-content.ts
40
+ - src/agent/pi-failure-class.ts
41
+ - src/agent/pi-jsonl-parser.ts
42
+ - src/agent/provider-auth-rejection.ts
43
+ - src/agent/user-error-messages.ts
44
+ - src/cli/mercury.ts
45
+ - src/core/operator-alerts.ts
46
+ - src/core/runtime.ts
47
+ - src/core/system-messages.ts
48
+ - src/extensions/installer.ts
49
+ - src/main.ts
50
+ - src/ops/shadow-service.ts
51
+ - src/ops/shadow-src.ts
52
+ - src/preflight/checks/image-content.ts
53
+ - src/preflight/report.ts
54
+ - src/preflight/run.ts
55
+ - tests/connection-health.test.ts
56
+ - tests/fixtures/release-gate/regression-map.json
57
+ - tests/helpers/preflight-deps.ts
58
+ - tests/helpers/repo-git.ts
59
+ - tests/image-content.test.ts
60
+ - tests/installer-bundled-sync.test.ts
61
+ - tests/oauth-lifecycle.test.ts
62
+ - tests/pi-auth.test.ts
63
+ - tests/preflight-image-content.test.ts
64
+ - tests/preflight-run.test.ts
65
+ - tests/preflight-scope.test.ts
66
+ - tests/repo-no-real-phone-ids.test.ts
67
+ - tests/run-failed-after-work.test.ts
68
+ - tests/scheduler-missed-runs.test.ts
69
+ - tests/sensitive-guard-audience.test.ts
70
+ - tests/shadow-service-cli.test.ts
71
+ - tests/shadow-service.test.ts
72
+ - tests/shadow-src.test.ts
73
+ - tests/space-delete-coverage.test.ts
74
+ - tests/third-party-app-rejection.test.ts
75
+ Siblings must know:
76
+ - S9 (task-scheduler.ts): ContainerError now carries `completedTools` (and the runtime sets `completedNotice` on chat turns). The scheduler path ignores both; that gap is filed as docs/bugs/scheduled-run-that-fails-after-its-tools-finish-drops-the-deliverable.md, and S9's file is where it lands.
77
+ - CredentialAlertSink gained a required `runFailedAfterWork` method; any new test stub sink needs it.
78
+ - chainFailure(err, spent, kind, refused, completed) gained a trailing optional `completed` param.
79
+ - Local dev is red on tests/release-gate-map.test.ts for two post-mortems that are not S4's (minor/2026-10-20-third-party-apps-400-… and moderate/2026-10-20-git-reading-tests-…): their `Gate check:` lines name test paths, not check ids; each needs a regression-map entry or a `- Gate check:` bullet.
80
+ --- final report (verbatim) ---
81
+ ~~~
82
+ S4 — run-that-fails-after-its-deliverable-is-produced-discards-it: fixed, squash-committed on local dev as 62ee179f (not pushed).
83
+
84
+ What changed: the container's failure result.json now carries `completedTools` (the latest 3 finished tool results, bounded); the host re-bounds it onto ContainerError.completedTools; executePrompt closes the failed turn with a [System: …] stub holding the notice the user is sent; handleRawInput appends that notice to the error reply (the last step's output in a DM, its name only in a group, nothing on a content-filter block) and emits the new runFailedAfterWork operator alert (space, category, tool names and sizes; one per space per cooldown). Nothing is retried.
85
+
86
+ Scope grown with the owner's OK: src/agent/container-entry.ts (S8's, landed first; no overlap in the end), src/agent/pi-jsonl-parser.ts, src/agent/container-error.ts, src/agent/container-runner.ts, src/core/operator-alerts.ts.
87
+
88
+ Archive: docs/debug/moderate/2026-10-20-run-that-fails-after-its-deliverable-is-produced-discards-it.md. Spin-off filed and pushed: docs/bugs/scheduled-run-that-fails-after-its-tools-finish-drops-the-deliverable.md (d0c1cdf5).
89
+
90
+ Review: TIER deep (lines 309, files 8, hotspot 69, sensitive container-entry/runner). Fork + fresh-context reviewer; blocking content-filter leak fixed, all own-diff findings fixed or noted.
91
+
92
+ Gate on the rebased branch: 7641 pass / 1 skip / 2 fail. Both failures pre-exist on local dev (S8's and git-reading-tests post-mortems carry `Gate check: tests/…` lines the release-gate map refuses); not S4's files.
93
+
94
+ DELIVERED: local
95
+ Deploy: image rebuild (pi-jsonl-parser.ts and container-entry.ts are baked) + restart.
96
+ ~~~
97
+
98
+ ## Exit — 2026-10-20T10:14Z
99
+ Verdict: unattributed (2 files)
100
+ Source: session-end-hook
101
+ ~~~
102
+ EXIT-RECEIPT: unattributed (2 files)
103
+ SHARED: /home/guysaha/projects/mercury with live session 1272eede-8545-4815-b080-3114357f25b5 (since 2026-10-20T09:35:58Z)
104
+ SHARED: /home/guysaha/projects/mercury with live session 1993c399-f87c-4980-862e-3b79328b07e1 (since 2026-10-20T09:07:51Z)
105
+ UNATTRIBUTED: /home/guysaha/projects/mercury/docs/plans/tagula-client-1008/sessions/ — 2 files (S4.md, S8.md): changed during this session, but live session 1272eede-8545-4815-b080-3114357f25b5 1993c399-f87c-4980-862e-3b79328b07e1 shares this checkout -> nothing records whose this is: ask the owner; never discard it
106
+ DEFERRED: push 13 commit(s) on dev, which is also 2 behind origin/dev -> git pull --rebase first, then push (/f-status reports ahead=13)
107
+ NOTE: remote state as of the last fetch (--no-fetch)
108
+ ~~~
@@ -0,0 +1,86 @@
1
+ ## Launched — 2026-10-20T09:35Z
2
+ Branch: worktree-fix-third-party-apps-400-is-retried-and-shown-as-try-again
3
+ Session: 1bb5a5ee-e075-4e56-9bf4-680e4db501da
4
+
5
+ ## Report — 2026-10-20T09:45Z
6
+ Outcome: delivered
7
+ Delivered: local
8
+ Blocked-on: —
9
+ Deploy needs: rebuild
10
+ Source: command
11
+ Files changed:
12
+ - docs/ARCHITECTURE.md
13
+ - docs/ROADMAP.md
14
+ - docs/archive/2026-10-19-shadow-from-worktree.md
15
+ - docs/backlog/sync-rehearse.md
16
+ - docs/backlog/workflow-gate-step.md
17
+ - docs/bugs/git-reading-tests-fail-in-the-check-mirror.md
18
+ - docs/bugs/tests-that-run-git-inherit-git-dir-and-commit-to-the-real-repo.md
19
+ - docs/bugs/third-party-apps-400-is-retried-and-shown-as-try-again.md
20
+ - docs/debug/minor/2026-10-20-third-party-apps-400-is-retried-and-shown-as-try-again.md
21
+ - docs/debug/moderate/2026-10-20-git-reading-tests-fail-in-the-check-mirror.md
22
+ - docs/goals/rehearsal-bench/roadmap.md
23
+ - docs/goals/release-gate/decisions.md
24
+ - docs/goals/release-gate/goal.md
25
+ - docs/goals/release-gate/roadmap.md
26
+ - docs/ideas/rehearse-what-the-shadow-refuses.md
27
+ - docs/ideas/shadow-up-cli-harness.md
28
+ - docs/live-testing.md
29
+ - docs/notes/critic-2026-10-12.md
30
+ - docs/pending-updates/shadow-from-worktree.md
31
+ - docs/pending-verification.md
32
+ - docs/release-gate.md
33
+ - src/agent/image-content.ts
34
+ - src/agent/pi-failure-class.ts
35
+ - src/agent/provider-auth-rejection.ts
36
+ - src/agent/user-error-messages.ts
37
+ - src/cli/mercury.ts
38
+ - src/extensions/installer.ts
39
+ - src/main.ts
40
+ - src/ops/shadow-service.ts
41
+ - src/ops/shadow-src.ts
42
+ - src/preflight/checks/image-content.ts
43
+ - src/preflight/report.ts
44
+ - src/preflight/run.ts
45
+ - tests/helpers/preflight-deps.ts
46
+ - tests/helpers/repo-git.ts
47
+ - tests/image-content.test.ts
48
+ - tests/installer-bundled-sync.test.ts
49
+ - tests/preflight-image-content.test.ts
50
+ - tests/preflight-run.test.ts
51
+ - tests/preflight-scope.test.ts
52
+ - tests/repo-no-real-phone-ids.test.ts
53
+ - tests/shadow-service-cli.test.ts
54
+ - tests/shadow-service.test.ts
55
+ - tests/shadow-src.test.ts
56
+ - tests/space-delete-coverage.test.ts
57
+ - tests/third-party-app-rejection.test.ts
58
+ Siblings must know:
59
+ - S4: src/agent/user-error-messages.ts gained an import of isThirdPartyAppRejection and one arm in classifyUserError (before AUTH_RE). Rebase over it; do not drop it.
60
+ - S4: alert_provider_credential_rejected in src/core/system-messages.ts still says "until the credential is replaced"; for a third-party 400 that contradicts the detail/recovery. Left untouched (S4's file); a NOTE in the post-mortem.
61
+ --- final report (verbatim) ---
62
+ ~~~
63
+ Fixed: Anthropic's "Third-party apps now draw from your extra usage" 400 now behaves like an auth refusal.
64
+ - src/agent/pi-failure-class.ts: new isThirdPartyAppRejection; isPiAuthFailure counts it, so the leg falls back at once (no same-leg retries) and is tagged authRejected.
65
+ - src/agent/user-error-messages.ts: classifyUserError -> auth (err_auth_platform), not generic "try again" (owner-approved one-line arm in S4's file).
66
+ - src/agent/provider-auth-rejection.ts: the alert describes a third-party classification (HTTP 400) and recommends agent.override_pi_system_prompt, not a new token.
67
+ - tests/third-party-app-rejection.test.ts (Gate check), negative-tested.
68
+ - container-entry.ts unchanged: it reads the shared predicates.
69
+ Gate: 16/16 links, 7528 pass / 1 skip / 0 fail. Review: TIER standard, 3 notes, 0 blocking.
70
+ Post-mortem: docs/debug/minor/2026-10-20-third-party-apps-400-is-retried-and-shown-as-try-again.md
71
+ DELIVERED: local (squash 2f259130 on local dev; push not approved this session; local dev also carries 7 earlier unpushed commits)
72
+ Deploy: image rebuild (pi-failure-class.ts is baked) + restart.
73
+ ~~~
74
+
75
+ ## Exit — 2026-10-20T10:07Z
76
+ Verdict: unattributed (2 files)
77
+ Source: session-end-hook
78
+ ~~~
79
+ EXIT-RECEIPT: unattributed (2 files)
80
+ SHARED: /home/guysaha/projects/mercury with live session 1272eede-8545-4815-b080-3114357f25b5 (since 2026-10-20T09:35:58Z)
81
+ SHARED: /home/guysaha/projects/mercury with live session 1993c399-f87c-4980-862e-3b79328b07e1 (since 2026-10-20T09:07:51Z)
82
+ SHARED: /home/guysaha/projects/mercury with live session 5dc202f3-5f3e-4303-92a0-429a4f5ff919 (since 2026-10-20T09:34:50Z)
83
+ UNATTRIBUTED: /home/guysaha/projects/mercury/docs/plans/tagula-client-1008/sessions/ — 2 files (S4.md, S8.md): changed during this session, but live session 1272eede-8545-4815-b080-3114357f25b5 1993c399-f87c-4980-862e-3b79328b07e1 5dc202f3-5f3e-4303-92a0-429a4f5ff919 shares this checkout -> nothing records whose this is: ask the owner; never discard it
84
+ DEFERRED: push 12 commit(s) on dev, which is also 1 behind origin/dev -> git pull --rebase first, then push (/f-status reports ahead=12)
85
+ NOTE: remote state as of the last fetch (--no-fetch)
86
+ ~~~
@@ -0,0 +1,50 @@
1
+ ## Launched — 2026-10-21T08:10Z
2
+ Branch: worktree-fix-scheduled-run-over-cloud-quota-posts-the-quota-text-as-output
3
+ Session: 534bc519-9e83-4384-a87c-cd5720e7e10f
4
+
5
+ ## Report — 2026-10-21T08:23Z
6
+ Outcome: delivered
7
+ Delivered: local
8
+ Blocked-on: —
9
+ Deploy needs: restart
10
+ Source: command
11
+ Files changed:
12
+ - docs/bugs/scheduled-run-over-cloud-quota-posts-the-quota-text-as-output.md
13
+ - docs/debug/minor/2026-10-21-scheduled-run-over-cloud-quota-posts-the-quota-text-as-output.md
14
+ - docs/goals/rehearsal-bench/goal.md
15
+ - docs/goals/rehearsal-bench/roadmap.md
16
+ - docs/pending-verification.md
17
+ - src/core/operator-alerts.ts
18
+ - src/core/runtime.ts
19
+ - src/core/system-messages.ts
20
+ - tests/operator-alerts.test.ts
21
+ - tests/scheduled-run-quota.test.ts
22
+ - tests/sensitive-guard-audience.test.ts
23
+ Siblings must know:
24
+ - TaskBlockedAlert now has a required `reason: "sensitive" | "quota"`; any new emitter or test fake that builds one must set it.
25
+ - announceTaskBlocked(task, stage, reason) gained a third parameter.
26
+ --- final report (verbatim) ---
27
+ ~~~
28
+ Fixed: a scheduled run over the console daily message quota posted the platform_quota_exceeded text into the group, ledgered `posted`, and pinged the heartbeat (reproduced by test first: outcome posted, replyChars 103).
29
+ Fix: executePrompt returns a QuotaDenial shape (beside SensitiveDequeueDenial). The chat leg still replies with the text; the scheduler leg skips the run (outcome null, nothing posted, no heartbeat, no retry) and sends the operator notice alert_task_blocked_quota[_one_shot] (en + he) through the existing taskBlocked alert, which now carries a required `reason`.
30
+ Files: src/core/runtime.ts, src/core/operator-alerts.ts, src/core/system-messages.ts (the last two were outside the predicted surfaces; the owner approved, and S4/S5 had landed), tests/scheduled-run-quota.test.ts (new, 5 tests), tests/operator-alerts.test.ts, tests/sensitive-guard-audience.test.ts, docs/pending-verification.md (S9 section).
31
+ Archived: docs/debug/minor/2026-10-21-scheduled-run-over-cloud-quota-posts-the-quota-text-as-output.md
32
+ Gate: bun run check 7837 pass / 0 fail before the 5th test (then typecheck:tests + lint + that test re-run green).
33
+ Review: TIER standard; 3 notes (1 fixed inline, 2 in Review notes); no blocking.
34
+ Squash commit 22d195bd on local dev. NOT pushed: the owner chose to hold the push because local dev also carries two unpushed goal-doc commits (fe5f4fbd, 2d690e63) that are not S9's.
35
+ DELIVERED: local
36
+ ~~~
37
+
38
+ ## Exit — 2026-10-21T08:26Z
39
+ Verdict: unattributed (1 file)
40
+ Source: session-end-hook
41
+ ~~~
42
+ EXIT-RECEIPT: unattributed (1 file)
43
+ SHARED: /home/guysaha/projects/mercury with live session 346c997f-057c-43e0-aa29-ec4a68d180c9 (since 2026-10-21T08:06:49Z)
44
+ SHARED: /home/guysaha/projects/mercury with live session b275fd1a-30db-49b4-8eae-741abab2fadb (since 2026-10-21T08:07:23Z)
45
+ SHARED: /home/guysaha/projects/mercury with live session e7d59e03-c784-4e07-9aec-8ea013842a99 (since 2026-10-21T08:07:05Z)
46
+ UNATTRIBUTED: /home/guysaha/projects/mercury/docs/plans/tagula-client-1008/sessions/S9.md — changed during this session, but live session 346c997f-057c-43e0-aa29-ec4a68d180c9 b275fd1a-30db-49b4-8eae-741abab2fadb e7d59e03-c784-4e07-9aec-8ea013842a99 shares this checkout -> nothing records whose this is: ask the owner; never discard it
47
+ DEFERRED: push 4 commit(s) on dev -> git (/f-status reports ahead=4)
48
+ NOTE: remote state as of the last fetch (--no-fetch)
49
+ NOTE: /home/guysaha/projects/mercury/docs/plans/tagula-client-1008/sessions/ — 2 files (S4.md, S8.md): dirty before this session started
50
+ ~~~
@@ -0,0 +1,55 @@
1
+ ## Launched — 2026-10-21T11:54Z
2
+ Branch: worktree-feature-box-watchdog
3
+ Session: 5ea54b83-cda3-4aa2-b463-62fa4a3c785e
4
+
5
+ ## Report — 2026-10-21T15:02Z
6
+ Outcome: delivered
7
+ Delivered: local
8
+ Blocked-on: —
9
+ Deploy needs: none (owner installs the timer per docs/runbooks/box-watchdog.md)
10
+ Source: command
11
+ Files changed:
12
+ - docs/ARCHITECTURE.md
13
+ - docs/archive/2026-10-20-sync-rehearse.md
14
+ - docs/archive/2026-10-21-box-watchdog.md
15
+ - docs/archive/rehearsal/2026-10-21-longview-file-target.md
16
+ - docs/archive/rehearsal/2026-10-21-shadow-cli.md
17
+ - docs/archive/rehearsal/2026-10-21-shadow-rehearse-beside-live.md
18
+ - docs/debug/moderate/09-2026/2026-09-02-reply-to-member-triggers-bot.md
19
+ - docs/goals/release-gate/goal.md
20
+ - docs/goals/release-gate/roadmap.md
21
+ - docs/notes/2026-10-11-monitoring-rollout-order.md
22
+ - docs/pending-updates/box-watchdog.md
23
+ - docs/pending-verification.md
24
+ - docs/runbooks/box-watchdog.md
25
+ - package.json
26
+ - scripts/check-shell.ts
27
+ - scripts/check.ts
28
+ - scripts/kb-distill-cron.sh
29
+ - scripts/ops/box-watchdog.service
30
+ - scripts/ops/box-watchdog.sh
31
+ - scripts/ops/box-watchdog.timer
32
+ - scripts/shell-vendored-allowlist.json
33
+ - tests/box-watchdog-sql.test.ts
34
+ - tests/box-watchdog.test.ts
35
+ - tests/helpers/watchdog-app.ts
36
+ - tests/polled-routes-no-io.test.ts
37
+ Siblings must know:
38
+ - The watchdog polls exactly two Mercury routes: `/health` and `/auth/whatsapp` (Bearer). They are listed in `WATCHDOG_ROUTES` in scripts/ops/box-watchdog.sh.
39
+ - The no-I/O pin harness exists: tests/polled-routes-no-io.test.ts with helper tests/helpers/watchdog-app.ts. run-outcome-counters adds its `/health/runs` row there AND adds the route to `WATCHDOG_ROUTES` (a cross-check test fails if the two lists differ).
40
+ - The `runs` condition is not built; it waits on run-outcome-counters (see the archived spec's residuals).
41
+ - New gate link `check:shell`: any new tracked *.sh must pass shellcheck --severity=style; shellcheck must be installed where the gate runs.
42
+ --- final report (verbatim) ---
43
+ ~~~
44
+ box-watchdog built and squash-merged onto LOCAL dev as d4240eb5 (18 files, +2334/-32). Not pushed: CLAUDE.local.md gates every push on owner approval, and the owner chose "local only for now" (2026-10-21).
45
+ - scripts/ops/box-watchdog.sh + .service + .timer: one ping per tick to the box's own healthchecks.io check; conditions process, whatsapp, host, unanswered.
46
+ - check:shell gate (scripts/check-shell.ts, scripts/shell-vendored-allowlist.json); kb-distill-cron.sh SC2046 disable comment.
47
+ - No-I/O pin over the polled routes: tests/polled-routes-no-io.test.ts + tests/helpers/watchdog-app.ts.
48
+ - Tests: tests/box-watchdog.test.ts (41), tests/box-watchdog-sql.test.ts (5).
49
+ - Runbook docs/runbooks/box-watchdog.md; ARCHITECTURE invariant; pending-verification block "Plan watchdog-1011 / S1".
50
+ - Spec archived: docs/archive/2026-10-21-box-watchdog.md; docs/pending-updates/box-watchdog.md written; rollout-order step 1a ticked.
51
+ Gate: bun run check 17/17 links PASS, 8124 pass / 1 skip / 0 fail (before the archive-only doc edits; check:shell re-run clean after the rebase, which brought in docs only).
52
+ Review: deep tier, 3 reviewers, all findings notes, the real ones fixed. QA: 40/45 PASS, 5 DEFERRED (owner on-box steps, runs condition).
53
+ DELIVERED: local
54
+ Upstream: boilerplate bug vendored-shell-scripts-fail-shellcheck on pr-bug-vendored-shell-scripts-fail-shellcheck (69b1c7a), unpushed.
55
+ ~~~
@@ -91,7 +91,7 @@ or the pending-verification line it ticks.
91
91
  | | |
92
92
  |---|---|
93
93
  | **Rule** | The candidate runs as a shadow on the box being upgraded, on a fresh copy of the live data, and passes `preflight` and `smoke` there before the live process is touched. |
94
- | **Command that fails** | From the project directory on the box, one command: `mercury shadow rehearse --src <detached worktree of the candidate> [--space <id>]… [--json]` (R5.1). It runs the steps below in order, stops at the first that is not a pass, always runs `shadow down` after a successful `up`, and writes `~/mercury-shadow/rehearsal/<timestamp>.json` (+ `latest.json`). Exit 0 green, 1 red (a check ran and failed), 2 refused (could not rehearse: every `ShadowUpRefusalId` by name, plus `snapshot-failed`, `up-failed`, `no-fixtures`, `tree-changed-between-stages`, `step-timeout`, `report-missing`). The verdict is the report's `verdict`, never the exit code alone. The steps it runs, which is also the by-hand procedure: `mercury shadow snapshot --dry-run` then `mercury shadow snapshot`; `mercury shadow up --dry-run --src <mirror>` then without `--dry-run` — `up` exits 1 printing **every** `ShadowUpRefusalId` it found (`snapshot-stale`, `port-8787-foreign`, `low-mem`, `low-disk`, `live-container-running`, `live-cron-due`, `src-not-mercury`, …) and a refusal is a wait, never an override; then, in the shadow's project directory (`~/mercury-shadow/current`), `mercury preflight --json` — exit 1 on any `blocked` check; then `mercury smoke --fixtures <file> --space <id> --json` — a `fail` verdict on any fixture (*lands with R3.2*); then `mercury shadow down`. *Same commit*: `mercury shadow status` prints the source commit — it must equal `<candidate>`. *Same image*: the shadow never pulls or builds (`EnsureAgentImageDeps.refusePull`), so its image **is** the live image — which is why an image-class change takes the §1 path instead. |
94
+ | **Command that fails** | From the project directory on the box, one command: `mercury shadow rehearse --src <detached worktree of the candidate> [--space <id>]… [--json]` (R5.1). It runs the steps below in order, stops at the first that is not a pass, always runs `shadow down` after a successful `up`, and writes `~/mercury-shadow/rehearsal/<timestamp>.json` (+ `latest.json`). Exit 0 green, 1 red (a check ran and failed), 2 refused (could not rehearse: every `ShadowUpRefusalId` by name, plus `snapshot-failed`, `up-failed`, `no-fixtures`, `tree-changed-between-stages`, `step-timeout`, `report-missing`). The verdict is the report's `verdict`, never the exit code alone. The steps it runs, which is also the by-hand procedure: `mercury shadow snapshot --dry-run` then `mercury shadow snapshot`; `mercury shadow up --dry-run --src <mirror>` then without `--dry-run` — `up` exits 1 printing **every** `ShadowUpRefusalId` it found (`snapshot-stale`, `port-8787-foreign`, `low-mem`, `low-disk`, `live-container-running`, `live-cron-due`, `src-not-mercury`, …) and a refusal is a wait, never an override (`shadow rehearse` passes `--beside-live`, so for it `live-container-running` and `live-cron-due` are warnings recorded on the `up` step, and `credential-shared-chain` is the refusal: the shadow would share a rotating model credential with live); then, in the shadow's project directory (`~/mercury-shadow/current`), `mercury preflight --json` — exit 1 on any `blocked` check; then `mercury smoke --fixtures <file> --space <id> --json` — a `fail` verdict on any fixture (*lands with R3.2*); then `mercury shadow down`. *Same commit*: `mercury shadow status` prints the source commit — it must equal `<candidate>`. *Same image*: the shadow never pulls or builds (`EnsureAgentImageDeps.refusePull`), so its image **is** the live image — which is why an image-class change takes the §1 path instead. |
95
95
  | **Evidence** | The rehearsal report `~/mercury-shadow/rehearsal/<timestamp>.json`, which names the preflight report, each smoke report, the diff JSON and the cost. By hand: the shadow's `<dataDir>/preflight/latest.json`, the smoke report (R3.2), the `shadow status` line (snapshot, source commit), the `shadow down` cost line. |
96
96
  | **Where it goes** | The deploy doc's verification block, as file paths plus the one-line summary of each. |
97
97
  | **Status** | **in force**; one command since R5.1 (`shadow rehearse`). An image-class or dependency change cannot be rehearsed (`image-drift`, `src-deps-differ`) and takes the §1 path (`docs/ideas/rehearse-what-the-shadow-refuses.md`). |
@@ -111,10 +111,10 @@ or the pending-verification line it ticks.
111
111
  | | |
112
112
  |---|---|
113
113
  | **Rule** | The owner's sync script, `mercury upgrade`, the agent workflows and every fleet path call the same `preflight` / `smoke` binaries (G-001); a path that cannot call them may not restart a live bot. |
114
- | **Command that fails** | `~/sync-mercury.sh` running `mercury shadow rehearse` on a detached worktree of the target commit **before** the mirror moves, and refusing to reset or restart unless the report's verdict is `green`. Rehearsing is the default; `--no-rehearse "<reason>"` refuses an empty reason and writes `no-rehearse <sha>: <reason>` to the journal (`journalctl --user -t mercury-sync`). Every rehearsal writes `rehearsal <sha>: <verdict> <report path>` there. No TTY and no `--yes` stops after the rehearsal. Right before the reset it refuses `live-not-quiet` on a running agent container, a `pi` process, or a live task due within 5 minutes, and `--no-rehearse` does not skip that check (Gate 9) (**R5.1, landed**); the **Gate** step of `/f-bug-fix` and `/f-feature-dev` refusing to archive without the two reports attached (**lands with R5.2**); `mercury upgrade` pulling the matching image before touching the host and refusing when the tag does not exist (R0.5 — the image half of this gate for a package install; it prints `mercury preflight` as the next step and does not run it, because it runs outside any project directory); the fleet's `tagula-box-upgrade` and cloud-init calling `mercury preflight --json` before declaring success (`fleet-release-gate`). |
115
- | **Evidence** | The journal line the refusing path writes; the reports the Gate step attaches. |
114
+ | **Command that fails** | `~/sync-mercury.sh` running `mercury shadow rehearse` on a detached worktree of the target commit **before** the mirror moves, and refusing to reset or restart unless the report's verdict is `green`. Rehearsing is the default; `--no-rehearse "<reason>"` refuses an empty reason and writes `no-rehearse <sha>: <reason>` to the journal (`journalctl --user -t mercury-sync`). Every rehearsal writes `rehearsal <sha>: <verdict> <report path>` there. No TTY and no `--yes` stops after the rehearsal. Right before the reset it refuses `live-not-quiet` on a running agent container, a `pi` process, or a live task due within 5 minutes, and `--no-rehearse` does not skip that check (Gate 9) (**R5.1, landed**); `bun test` refusing any feature spec or post-mortem archived on or after 2026-10-22 without the §4 block's `Classes (Gate 1)` and `Shadow (Gate 2)` lines — `tests/release-gate-evidence.test.ts`, so a doc archived without the branch rehearsal turns `bun run check` red whoever wrote it (**R5.2, landed**; the `/f-bug-fix` / `/f-feature-dev` step that runs the rehearsal for you is the boilerplate's, idea `rehearse-step-in-fix-and-feature-dev`, G-014); `mercury upgrade` pulling the matching image before touching the host and refusing when the tag does not exist (R0.5 — the image half of this gate for a package install; it prints `mercury preflight` as the next step and does not run it, because it runs outside any project directory); the fleet's `tagula-box-upgrade` and cloud-init calling `mercury preflight --json` before declaring success (`fleet-release-gate`). |
115
+ | **Evidence** | The journal line the refusing path writes; the deploy doc's §4 `Shadow (Gate 2)` line naming the branch rehearsal's report. |
116
116
  | **Where it goes** | The deploy doc; for the fleet, the box's `<dataDir>/preflight/latest.json`. |
117
- | **Status** | **R5.1 in force** for the owner's sync script (the script lives outside the repo, and its patch is recorded in `docs/archive/*-sync-rehearse.md`); **R5.2 pending** (the workflow Gate step); **policy hook** (fleet side). Until R5.2 lands, the agent workflows attach Gates 2, 3 and 5 evidence by hand, and a deploy doc without it is the failure a reviewer reads. |
117
+ | **Status** | **in force** — R5.1 for the owner's sync script (the script lives outside the repo, and its patch is recorded in `docs/archive/*-sync-rehearse.md`) and R5.2 for the deploy doc (`tests/release-gate-evidence.test.ts`); **policy hook** (fleet side). The agent workflows still run the branch rehearsal and paste the block by hand until the boilerplate's Gate step ships; what is in force is that a doc without it does not pass the check. |
118
118
 
119
119
  ### Gate 5 — Health is not done
120
120
 
@@ -161,7 +161,7 @@ or the pending-verification line it ticks.
161
161
  | | |
162
162
  |---|---|
163
163
  | **Rule** | No restart while a run is in flight or a cron slot is near — a restart kills the running container and the scheduler's retry dies with the process, so the run is lost, not delayed — and never during a customer's working hours. |
164
- | **Command that fails** | `mercury shadow up --dry-run` exits 1 with `[live-container-running]` or `[live-cron-due]` (default window `--window 90m`) — the same two facts a live restart needs, computed by the command rather than by eye; read them even when no shadow is wanted. Beside it, because one-shot verify runs are `at`-style tasks the cron table does not show: `docker ps -q --filter label=mercury.managed=true` must print nothing and `pgrep -af 'bin/pi ' | grep -v 'bash -lc'` must print nothing (the `grep -v` excludes the invoking shell, which otherwise matches itself). *Working hours*: **policy hook** — which hours are a customer's is `fleet-release-gate`'s; for this box, the hour after a covered club's final whistle is the equivalent, and the round notes carry it. |
164
+ | **Command that fails** | `mercury shadow up --dry-run` (plain, **without** `--beside-live`, which would turn these into warnings) exits 1 with `[live-container-running]` or `[live-cron-due]` (default window `--window 90m`) — the same two facts a live restart needs, computed by the command rather than by eye; read them even when no shadow is wanted. Beside it, because one-shot verify runs are `at`-style tasks the cron table does not show: `docker ps -q --filter label=mercury.managed=true` must print nothing and `pgrep -af 'bin/pi ' | grep -v 'bash -lc'` must print nothing (the `grep -v` excludes the invoking shell, which otherwise matches itself). *Working hours*: **policy hook** — which hours are a customer's is `fleet-release-gate`'s; for this box, the hour after a covered club's final whistle is the equivalent, and the round notes carry it. |
165
165
  | **Evidence** | The `shadow up --dry-run` output; the two empty listings, with the wall-clock time. |
166
166
  | **Where it goes** | The deploy doc, beside the restart's timestamp. |
167
167
  | **Status** | **in force** (gap); **policy hook** (working hours) |
@@ -181,20 +181,20 @@ or the pending-verification line it ticks.
181
181
  | | |
182
182
  |---|---|
183
183
  | **Rule** | A post-mortem closes only when its regression check is in `preflight`, `smoke` or the env diff and has been negative-tested — the regression-map discipline of `football-regression-suite`. |
184
- | **Command that fails** | `tests/release-gate-map.test.ts` — every post-mortem under `docs/debug/**` dated 2026-09-01 or later names a `Gate check:` line pointing at a preflight `CheckId` (`src/preflight/report.ts`), a smoke fixture or an env-diff class, and the test is red for a post-mortem without one (**lands with R3.3**); the post-mortem template's required `Gate check:` line (**lands with R5.2**). Negative-tested means: delete the check's line, watch the suite go red — the `CLAUDE.md` rule for every guard. |
184
+ | **Command that fails** | `tests/release-gate-map.test.ts` — every post-mortem under `docs/debug/**` dated 2026-09-01 or later names a `Gate check:` line pointing at a preflight `CheckId` (`src/preflight/report.ts`), a smoke fixture or an env-diff class, and the test is red for a post-mortem without one (**R3.3, landed**); the post-mortem template's required `Gate check:` line is a workflow format and goes with the boilerplate idea `rehearse-step-in-fix-and-feature-dev` (G-014). Negative-tested means: delete the check's line, watch the suite go red — the `CLAUDE.md` rule for every guard. |
185
185
  | **Evidence** | The `Gate check:` line in the post-mortem; the red-then-green test run in the fix's check gate. |
186
186
  | **Where it goes** | The post-mortem. |
187
- | **Status** | **lands with R3.3 / R5.2** |
187
+ | **Status** | **in force** (`tests/release-gate-map.test.ts`); the template line **lands with the boilerplate idea** |
188
188
 
189
189
  ### Gate 12 — What no ring can test is written down, with a date and an owner
190
190
 
191
191
  | | |
192
192
  |---|---|
193
193
  | **Rule** | A check that no ring can settle — a phone screenshot, a page in a browser, the socket's behaviour — is one dated `MANUAL-VERIFY` line with an owner, short and visible; it blocks nothing and it is never lost. |
194
- | **Command that fails** | At archive time, `.claude/scripts/check-residual-risks.sh <spec>` exits 1 for a retrospective whose residual is neither tracked (`→ ideas/…`, `→ backlog/…`), accepted (`— accepted`) nor a dated `MANUAL-VERIFY(<YYYY-MM-DD>):` line — `/f-feature-dev` and `/f-bug-fix` hard-block on it. The lines land in `docs/pending-verification.md`, append-only under a heading per story. *The owner field*: **lands with R5.2**, which makes an entry without an owner and a date a refused entry. |
194
+ | **Command that fails** | At archive time, `.claude/scripts/check-residual-risks.sh <spec>` exits 1 for a retrospective whose residual is neither tracked (`→ ideas/…`, `→ backlog/…`), accepted (`— accepted`) nor a dated `MANUAL-VERIFY(<YYYY-MM-DD>):` line — `/f-feature-dev` and `/f-bug-fix` hard-block on it. The lines land in `docs/pending-verification.md`, append-only under a heading per story. *The owner field* is a workflow format (`MANUAL-VERIFY(<date>)` is written by the boilerplate's scripts), so it **lands with the boilerplate idea** `rehearse-step-in-fix-and-feature-dev` (G-014), which makes an entry without an owner and a date a refused entry. |
195
195
  | **Evidence** | The line itself, and its tick with the evidence that cleared it. |
196
196
  | **Where it goes** | `docs/pending-verification.md`. |
197
- | **Status** | **in force** (date, tracking); **lands with R5.2** (owner) |
197
+ | **Status** | **in force** (date, tracking); **lands with the boilerplate idea** (owner) |
198
198
 
199
199
  ---
200
200
 
@@ -239,6 +239,20 @@ Reader (Gate 10): host.heartbeat pass; last ping <time>
239
239
  Manual (Gate 12): <n> MANUAL-VERIFY lines under <heading> in docs/pending-verification.md
240
240
  ```
241
241
 
242
+ Two of these lines are checked, on every spec and post-mortem archived on or
243
+ after 2026-10-22, by `tests/release-gate-evidence.test.ts`. `Classes` must name
244
+ classes from the fence line above (the test reads them from here), and
245
+ `docs-only` only alone. `Shadow` is the **branch** rehearsal, run on the box
246
+ before archiving (`mercury shadow rehearse --src <worktree>`), in one of three
247
+ forms: `rehearsal <path> verdict <green|red|refused>`; `not run — docs-only`
248
+ (only when the class is exactly `docs-only`); or `not run — <id>` with the id
249
+ in `REHEARSE_REFUSALS` (`src/ops/shadow-rehearse.ts`). The by-hand form does
250
+ not pass. A `red` or `refused` verdict passes on purpose: the line is the
251
+ record a reviewer reads, and the sync's rehearsal of the merged commit is what
252
+ refuses to restart on anything but `green`. A deploy doc with no date in its
253
+ name and no `**Created**` header is checked, not exempt. The sync's own rehearsal of the merged commit is the gate and goes
254
+ to the journal, because a doc cannot carry a report made after its own merge.
255
+
242
256
  ---
243
257
 
244
258
  ## 5. Struck
@@ -250,7 +264,7 @@ re-proposed as a rule:
250
264
 
251
265
  | Draft wording | Why it is not a gate | What would make it one |
252
266
  |---|---|---|
253
- | "No evidence, no deploy" as a sentence a reviewer remembers | a sentence is not a command; the incident had thirteen of them | R5.2's Gate step: the archive refuses without the two reports — then Gate 4 is in force |
267
+ | "No evidence, no deploy" as a sentence a reviewer remembers | a sentence is not a command; the incident had thirteen of them | done 2026-10-21 (R5.2): `tests/release-gate-evidence.test.ts` fails `bun test` for any spec or post-mortem archived on or after 2026-10-22 without the §4 block — Gate 4 is in force |
254
268
  | "Reviewed by a person" (Gate 6) as the whole rule | a person's read cannot fail a script | kept only because `env diff` produces the lines and exits 1 on the blocking classes; the person reads the advisory rest — that is the whole of the human half |
255
269
  | "No restart during a customer's working hours" (Gate 9) as a Mercury rule | Mercury knows no customers (G-006) | the fleet's policy, with the box's local hours; on this box the round notes carry the football equivalent |
256
270
  | A functional probe schedule (Gate 10) | the fixtures do not exist yet and the scheduling is the fleet's | R3.2 for the fixtures, `space-probe-harness` for the timer |
@@ -59,6 +59,15 @@ function callerIsAdmin(
59
59
  return isGlobalAdmin(req.callerId, ctx.config);
60
60
  }
61
61
 
62
+ /**
63
+ * Actions that change nothing outside this host's own copy of its data. A
64
+ * shadow (goal rehearsal-bench M1.5) refuses every other action at the
65
+ * capability route before the handler runs.
66
+ *
67
+ * `forget` erases, so a shadow cannot rehearse it (accepted).
68
+ */
69
+ export const READ_ONLY_ACTIONS = ["list", "get"] as const;
70
+
62
71
  export async function runArchiveAction(
63
72
  req: CapabilityRequest,
64
73
  ctx: MercuryExtensionContext,
@@ -43,7 +43,7 @@ import type {
43
43
  import { DriveArchiveBackend } from "./backends/drive.js";
44
44
  import { LocalArchiveBackend } from "./backends/local.js";
45
45
  import type { ArchiveBackend } from "./backends/types.js";
46
- import { runArchiveAction } from "./capability.js";
46
+ import { READ_ONLY_ACTIONS, runArchiveAction } from "./capability.js";
47
47
  import { reconcileSpace } from "./gc.js";
48
48
  import { newId, readLines, writeArchiveMd } from "./manifest.js";
49
49
  import { drainSpace, hashFile, spacesWithPending, spool } from "./queue.js";
@@ -358,5 +358,6 @@ export default function (mercury: MercuryExtensionAPI) {
358
358
  }
359
359
  return result;
360
360
  },
361
+ { readOnly: READ_ONLY_ACTIONS },
361
362
  );
362
363
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Delete every store row feed-watch keeps for one space, on `space_deleted`.
3
+ *
4
+ * `deleteSpace` cannot reach these rows: `extension_state` keys belong to the
5
+ * extension, not to the space. Before this, a deleted space kept its watch
6
+ * buffer and seen-list (feed items and links collected for it), its cursors
7
+ * and its yield stats indefinitely (bug
8
+ * extension-cleanup-on-space-delete-leaves-keys-behind).
9
+ *
10
+ * Built from the same key builders the writers use, so a key cannot be spelled
11
+ * two ways. The two lane-suffixed shapes (`last_digest_at:<id>[:<lane>]`,
12
+ * `digest_until:<id>[:<lane>]`) can carry any lane a source ever named, so
13
+ * those are found by listing. A row is matched only by the exact
14
+ * `<base>:<lane>` grammar, never by prefix alone: space ids have no colon, so
15
+ * space `a`'s lane key can never be space `a-b`'s row.
16
+ */
17
+
18
+ import { SOURCE_LANE } from "./config.js";
19
+ import { laneDigestKey, pendingDigestKey } from "./digest.js";
20
+ import {
21
+ bufferKey,
22
+ hostCursorKey,
23
+ pendingKey,
24
+ runsKey,
25
+ seenKey,
26
+ sourceStatusKey,
27
+ } from "./watch.js";
28
+ import { sourceYieldKey } from "./yield.js";
29
+
30
+ export interface ForgetStore {
31
+ delete(key: string): boolean;
32
+ list(): Array<{ key: string; value: string }>;
33
+ }
34
+
35
+ /** The space's keys that have exactly one spelling. */
36
+ export function fixedSpaceKeys(spaceId: string): string[] {
37
+ return [
38
+ seenKey(spaceId),
39
+ bufferKey(spaceId),
40
+ pendingKey(spaceId),
41
+ runsKey(spaceId),
42
+ sourceStatusKey(spaceId),
43
+ hostCursorKey(spaceId),
44
+ sourceYieldKey(spaceId),
45
+ laneDigestKey(spaceId),
46
+ pendingDigestKey(spaceId),
47
+ ];
48
+ }
49
+
50
+ /** Delete the space's rows; returns how many existed. */
51
+ export function forgetSpace(store: ForgetStore, spaceId: string): number {
52
+ const keys = new Set(fixedSpaceKeys(spaceId));
53
+ const laneBases = [laneDigestKey(spaceId), pendingDigestKey(spaceId)];
54
+ for (const { key } of store.list()) {
55
+ for (const base of laneBases) {
56
+ if (
57
+ key.startsWith(`${base}:`) &&
58
+ SOURCE_LANE.test(key.slice(base.length + 1))
59
+ ) {
60
+ keys.add(key);
61
+ }
62
+ }
63
+ }
64
+ let removed = 0;
65
+ for (const key of keys) {
66
+ if (store.delete(key)) removed++;
67
+ }
68
+ return removed;
69
+ }
@@ -47,6 +47,7 @@ import {
47
47
  shadowFixtureDir,
48
48
  unknownFixtures,
49
49
  } from "./fixtures.js";
50
+ import { type ForgetStore, forgetSpace } from "./forget.js";
50
51
  import type { PostedReply } from "./posted.js";
51
52
  import {
52
53
  expandSources,
@@ -169,8 +170,15 @@ interface MercuryApi {
169
170
  ctx: ExtensionContext,
170
171
  ) => Promise<HookResult | undefined>,
171
172
  ): void;
173
+ on(
174
+ event: "space_deleted",
175
+ handler: (
176
+ event: { spaceId: string },
177
+ ctx: ExtensionContext,
178
+ ) => Promise<undefined>,
179
+ ): void;
172
180
  skill(relativePath: string): void;
173
- store: WatchStore;
181
+ store: WatchStore & ForgetStore;
174
182
  }
175
183
 
176
184
  // ---------------------------------------------------------------------------
@@ -643,6 +651,14 @@ export default function (mercury: MercuryApi) {
643
651
  return composeAppends(digest, recent);
644
652
  });
645
653
 
654
+ // The buffer, seen-list, cursors and yield stats are this extension's rows,
655
+ // which `deleteSpace` cannot reach; a deleted space must not keep them.
656
+ mercury.on("space_deleted", async ({ spaceId }, ctx) => {
657
+ const removed = forgetSpace(store, spaceId);
658
+ ctx.log.info("feed-watch: forgot a deleted space", { spaceId, removed });
659
+ return undefined;
660
+ });
661
+
646
662
  mercury.on("after_container", async (event, ctx) => {
647
663
  // First, and independent of the cursor bookkeeping below: a verify run
648
664
  // has no digest lane and would never reach `handleAfterContainer`.
@@ -33,8 +33,11 @@ export const DEFAULT_THRESHOLD = 2000;
33
33
  /** Below this a threshold is nonsense — normal replies would be published. */
34
34
  export const MIN_THRESHOLD = 500;
35
35
 
36
- /** Targets that `longview.target` may name. */
37
- export const TARGET_NAMES = ["telegraph"] as const;
36
+ /**
37
+ * Targets that `longview.target` may name. `file` writes the page under
38
+ * `<dataDir>/longview/pages/` and is what a shadow is always forced onto.
39
+ */
40
+ export const TARGET_NAMES = ["telegraph", "file"] as const;
38
41
 
39
42
  /**
40
43
  * Config default for `longview.summary_max_chars`.
@@ -476,6 +479,21 @@ export function recordRecent(store: TargetStore, entry: RecentEntry): void {
476
479
  store.set(RECENT_KEY, JSON.stringify(next));
477
480
  }
478
481
 
482
+ /**
483
+ * Drop a deleted space's entries from the recent list; returns how many went.
484
+ * The list is this extension's row, which `deleteSpace` cannot reach, and each
485
+ * entry names the space and the page it published for it (bug
486
+ * extension-cleanup-on-space-delete-leaves-keys-behind). The published pages
487
+ * themselves stay on the target: nothing here can unpublish them.
488
+ */
489
+ export function forgetSpace(store: TargetStore, spaceId: string): number {
490
+ const recent = readRecent(store);
491
+ const kept = recent.filter((e) => e.spaceId !== spaceId);
492
+ if (kept.length !== recent.length)
493
+ store.set(RECENT_KEY, JSON.stringify(kept));
494
+ return recent.length - kept.length;
495
+ }
496
+
479
497
  // ---------------------------------------------------------------------------
480
498
  // The hook
481
499
  // ---------------------------------------------------------------------------