@markus-global/cli 0.12.3 → 0.12.5-rc.0

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 (159) hide show
  1. package/dist/background-maintenance.d.ts +25 -0
  2. package/dist/background-maintenance.d.ts.map +1 -1
  3. package/dist/background-maintenance.js +61 -0
  4. package/dist/background-maintenance.js.map +1 -1
  5. package/dist/commands/im-inbound-origin.d.ts +38 -0
  6. package/dist/commands/im-inbound-origin.d.ts.map +1 -0
  7. package/dist/commands/im-inbound-origin.js +48 -0
  8. package/dist/commands/im-inbound-origin.js.map +1 -0
  9. package/dist/commands/start.d.ts.map +1 -1
  10. package/dist/commands/start.js +211 -46
  11. package/dist/commands/start.js.map +1 -1
  12. package/dist/markus.mjs +18523 -9866
  13. package/dist/web-ui/assets/{AsyncState-_UC7xcxJ.js → AsyncState-ByYn1wrM.js} +1 -1
  14. package/dist/web-ui/assets/ChatComponents-Bwh8SlUV.js +14 -0
  15. package/dist/web-ui/assets/{ContentRenderer-C-V5k_3K.js → ContentRenderer-GLgoGp2a.js} +6 -6
  16. package/dist/web-ui/assets/DeliverableShareModal-CRfnRuR3.js +1 -0
  17. package/dist/web-ui/assets/{Deliverables-CQnWqbTb.js → Deliverables-EFsnf6kU.js} +2 -2
  18. package/dist/web-ui/assets/MarkdownMessage-CaLBeMto.js +4 -0
  19. package/dist/web-ui/assets/{Search-CVYQIy_D.js → Search-COiaXUNr.js} +1 -1
  20. package/dist/web-ui/assets/{SendToChat-IOAvuta-.js → SendToChat-DleryIlc.js} +1 -1
  21. package/dist/web-ui/assets/Settings-CzY8z2Yh.js +8 -0
  22. package/dist/web-ui/assets/{Store-BEsLd_RN.js → Store-C4VpQCM_.js} +1 -1
  23. package/dist/web-ui/assets/Switch-ByogYoGH.js +1 -0
  24. package/dist/web-ui/assets/Team-Cutq2J24.js +93 -0
  25. package/dist/web-ui/assets/Work-BO-mz-na.js +142 -0
  26. package/dist/web-ui/assets/{arc-DP1Vf7Sx.js → arc-mYv67jdD.js} +1 -1
  27. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Buq8JYN8.js → architectureDiagram-3BPJPVTR-Bzpz_1r6.js} +1 -1
  28. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-BCa2p2_X.js → blockDiagram-GPEHLZMM-BBrLiivl.js} +1 -1
  29. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BxsgggQY.js → c4Diagram-AAUBKEIU-BwDUoXA_.js} +1 -1
  30. package/dist/web-ui/assets/channel-Bx09lbhA.js +1 -0
  31. package/dist/web-ui/assets/{chunk-2J33WTMH-BJZZ60c9.js → chunk-2J33WTMH-DCSfJ-S9.js} +1 -1
  32. package/dist/web-ui/assets/{chunk-4BX2VUAB-C5hc4E6J.js → chunk-4BX2VUAB-CI0n1b2H.js} +1 -1
  33. package/dist/web-ui/assets/{chunk-55IACEB6-CbyvZ6Mk.js → chunk-55IACEB6-DqlSWLrm.js} +1 -1
  34. package/dist/web-ui/assets/{chunk-727SXJPM-JmNt9TVA.js → chunk-727SXJPM-BtmAfGYV.js} +1 -1
  35. package/dist/web-ui/assets/{chunk-AQP2D5EJ-BTk0v5ba.js → chunk-AQP2D5EJ-BgkA4lpQ.js} +1 -1
  36. package/dist/web-ui/assets/{chunk-FMBD7UC4-BO-dhB1U.js → chunk-FMBD7UC4-DCSr1JH4.js} +1 -1
  37. package/dist/web-ui/assets/{chunk-ND2GUHAM-BdjCcLdb.js → chunk-ND2GUHAM-CETYBRRm.js} +1 -1
  38. package/dist/web-ui/assets/{chunk-QZHKN3VN-BAzRC82n.js → chunk-QZHKN3VN-C58yD7lH.js} +1 -1
  39. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DGZqU3iA.js +1 -0
  40. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DGZqU3iA.js +1 -0
  41. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-CVffmErT.js → cose-bilkent-S5V4N54A-BpvdK03m.js} +1 -1
  42. package/dist/web-ui/assets/{dagre-BM42HDAG-Dd9pB2fX.js → dagre-BM42HDAG-CZ1K-KD5.js} +1 -1
  43. package/dist/web-ui/assets/{diagram-2AECGRRQ-BG_AUqzM.js → diagram-2AECGRRQ-D136Ok1V.js} +1 -1
  44. package/dist/web-ui/assets/{diagram-5GNKFQAL-D5qFMRFf.js → diagram-5GNKFQAL-Ji6qPYYV.js} +1 -1
  45. package/dist/web-ui/assets/{diagram-KO2AKTUF-B3qTxSWl.js → diagram-KO2AKTUF-B-s2RC-f.js} +1 -1
  46. package/dist/web-ui/assets/{diagram-LMA3HP47-BrxC1636.js → diagram-LMA3HP47-COWaps70.js} +1 -1
  47. package/dist/web-ui/assets/{diagram-OG6HWLK6-BvXyEQ9-.js → diagram-OG6HWLK6-bh6MvwWn.js} +1 -1
  48. package/dist/web-ui/assets/{docx-preview-DBAZFeEb.js → docx-preview-BRynUqJd.js} +1 -1
  49. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CMap9oy_.js → erDiagram-TEJ5UH35-DOPh2LlL.js} +1 -1
  50. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-BZerJtvk.js → flowDiagram-I6XJVG4X-B_kxDHIp.js} +1 -1
  51. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CagPMHMO.js → ganttDiagram-6RSMTGT7-DYBKHOkK.js} +1 -1
  52. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-DZ5dDKRu.js → gitGraphDiagram-PVQCEYII-D8_0BxLC.js} +1 -1
  53. package/dist/web-ui/assets/index-9SXWNIl0.css +1 -0
  54. package/dist/web-ui/assets/index-TAHyKznL.js +867 -0
  55. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-CHLdsDUZ.js → infoDiagram-5YYISTIA-DayJP7Ws.js} +1 -1
  56. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-SdeinQaS.js → ishikawaDiagram-YF4QCWOH-vzxCYVSq.js} +1 -1
  57. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-BtlL2fi0.js → journeyDiagram-JHISSGLW-B-Fud82o.js} +1 -1
  58. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-BKPQYXkB.js → kanban-definition-UN3LZRKU-DzuKdB65.js} +1 -1
  59. package/dist/web-ui/assets/{mermaid.core-MkJR6w4B.js → mermaid.core-D4ql87kI.js} +5 -5
  60. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-CbOmHX_u.js → mindmap-definition-RKZ34NQL-DosvXt2g.js} +1 -1
  61. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CypGjJP1.js → pieDiagram-4H26LBE5-DhXtMWhr.js} +1 -1
  62. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CGtemfUz.js → quadrantDiagram-W4KKPZXB-D33pLLOq.js} +1 -1
  63. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-N7YfpCvE.js → requirementDiagram-4Y6WPE33-B-iIz-XM.js} +1 -1
  64. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CYnSrei-.js → sankeyDiagram-5OEKKPKP-BMd9AFEW.js} +1 -1
  65. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-CsB7dCPF.js → sequenceDiagram-3UESZ5HK-CI1MIdwo.js} +1 -1
  66. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DTDFUXFP.js → stateDiagram-AJRCARHV-Bq6FKPW2.js} +1 -1
  67. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-8nMhmWY5.js +1 -0
  68. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-C_bWAN9B.js → timeline-definition-PNZ67QCA-BDdmmSRo.js} +1 -1
  69. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-CX_qAuUT.js → vennDiagram-CIIHVFJN-DP2q5vY2.js} +1 -1
  70. package/dist/web-ui/assets/{wardley-L42UT6IY-q53jQ293.js → wardley-L42UT6IY-Bw3fjszD.js} +1 -1
  71. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-D34dKCJU.js → wardleyDiagram-YWT4CUSO-37bQUocJ.js} +1 -1
  72. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-BFAngp66.js → xychartDiagram-2RQKCTM6-DnLDZyNC.js} +1 -1
  73. package/dist/web-ui/index.html +2 -2
  74. package/docs/README.md +50 -16
  75. package/docs/api/guides/websocket.md +43 -0
  76. package/docs/api/reference.md +657 -0
  77. package/docs/architecture/a2a-communication.md +303 -0
  78. package/docs/architecture/agent-runtime.md +145 -28
  79. package/docs/architecture/architecture.md +30 -11
  80. package/docs/architecture/cognitive-architecture.md +189 -15
  81. package/docs/architecture/concurrent-processing.md +190 -31
  82. package/docs/architecture/context-assembly.md +264 -0
  83. package/docs/architecture/derived-views.md +463 -0
  84. package/docs/architecture/desktop-auto-update.md +185 -0
  85. package/docs/architecture/facts.md +406 -0
  86. package/docs/architecture/learning-loop.md +11 -0
  87. package/docs/architecture/limits.md +79 -0
  88. package/docs/architecture/mailbox-system.md +786 -668
  89. package/docs/architecture/memory-system.md +1 -1
  90. package/docs/architecture/messaging-gateway.md +7 -0
  91. package/docs/architecture/notification-delivery.md +221 -0
  92. package/docs/architecture/notification-sounds.md +177 -0
  93. package/docs/architecture/prompt-engineering.md +171 -700
  94. package/docs/{design/remote-access-contract.md → architecture/remote-access.md} +4 -0
  95. package/docs/architecture/state-machines.md +288 -5
  96. package/docs/architecture/tool-loop-harness.md +362 -0
  97. package/docs/architecture/tool-system.md +40 -16
  98. package/docs/design/background-callback-in-turn-delivery-2026-11-22.md +95 -0
  99. package/docs/design/c10-0b-pick-identity-leak-2026-11-22.md +233 -0
  100. package/docs/design/c10-a-identity-columns-2026-11-22.md +182 -0
  101. package/docs/design/c10-c-trust-boundary-2026-11-23.md +222 -0
  102. package/docs/design/c10-external-adapters-plan-2026-11-19.md +448 -0
  103. package/docs/design/c8-residual-mechanisms-2026-11-15.md +984 -0
  104. package/docs/design/external-signal-decision-loop-2026-11-25.md +579 -0
  105. package/docs/guides/development.md +1 -1
  106. package/docs/{architecture → guides}/mailbox-audit-checklist.md +7 -0
  107. package/docs/guides/remote-access.md +1 -1
  108. package/docs/{design/agent-stop-intent-audit.md → records/agent-stop-intent-audit-2026-11-08.md} +4 -0
  109. package/docs/records/c10-l5-gate-verification-2026-11-26.md +72 -0
  110. package/docs/records/c10-l5-live-verification-2026-11-25.md +117 -0
  111. package/docs/records/cut6-c4-verification-2026-11-12.md +268 -0
  112. package/docs/records/cut6-mailbox-address-envelope-design-2026-11-12.md +871 -0
  113. package/docs/records/cut7-c7a-red-green-evidence-2026-11-13.md +105 -0
  114. package/docs/records/cut7-c7a-workunit-implementation-2026-11-13.md +116 -0
  115. package/docs/records/cut7-c7b-verification-2026-11-14.md +90 -0
  116. package/docs/records/cut7-live-verification-2026-11-14.md +33 -0
  117. package/docs/records/cut7-wiring-negative-cache-2026-11-14.md +64 -0
  118. package/docs/records/cut7-workunit-execution-plan-2026-11-13.md +206 -0
  119. package/docs/records/cut8-a-entity-keys-design-2026-11-14.md +377 -0
  120. package/docs/records/cut8-b-turn-delta-injection-2026-11-14.md +362 -0
  121. package/docs/records/cut8-c-single-clock-2026-11-14.md +119 -0
  122. package/docs/records/cut8-c-single-clock-design-2026-11-14.md +150 -0
  123. package/docs/records/cut8-d-2026-11-14.md +231 -0
  124. package/docs/records/cut8-live-verification-2026-11-14.md +1018 -0
  125. package/docs/records/cut9-adjacent-identity-paths-2026-11-15.md +200 -0
  126. package/docs/records/cut9-identity-declaration-2026-11-15.md +163 -0
  127. package/docs/records/cut9-inbox-dual-run-diff-2026-11-15.md +117 -0
  128. package/docs/records/cut9-live-verification-2026-11-15.md +222 -0
  129. package/docs/records/cut9-runtime-probe-2026-11-19.md +520 -0
  130. package/docs/{design/deliverable-sharing.md → records/deliverable-sharing-2026-08-12.md} +10 -3
  131. package/docs/records/identity-backlog-disposition-2026-11-22.md +143 -0
  132. package/docs/records/marketplace-orphan-freeze-2026-11-22.md +239 -0
  133. package/docs/{architecture/notify-user-context-truth.md → records/notify-user-context-truth-2026-10-28.md} +6 -0
  134. package/docs/{handoff → records}/remote-access-handoff.md +1 -1
  135. package/package.json +1 -1
  136. package/templates/roles/HANDBOOK.md +1 -1
  137. package/templates/skills/agent-building/SKILL.md +1 -1
  138. package/dist/web-ui/assets/ChatComponents-Ca9tWI9W.js +0 -12
  139. package/dist/web-ui/assets/DeliverableShareModal-BvpyowYJ.js +0 -1
  140. package/dist/web-ui/assets/MarkdownMessage-DedA8Zob.js +0 -4
  141. package/dist/web-ui/assets/Settings-BQDqf4q5.js +0 -8
  142. package/dist/web-ui/assets/Switch-C6InTNUi.js +0 -1
  143. package/dist/web-ui/assets/Team-nfNyWj-s.js +0 -85
  144. package/dist/web-ui/assets/Work-BQvgkynj.js +0 -142
  145. package/dist/web-ui/assets/channel-BTSrOo6c.js +0 -1
  146. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BSYlcnF9.js +0 -1
  147. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BSYlcnF9.js +0 -1
  148. package/dist/web-ui/assets/index-CKPQYzzR.js +0 -867
  149. package/dist/web-ui/assets/index-CzHSs0Vd.css +0 -1
  150. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-AVnDjlzF.js +0 -1
  151. package/docs/api/api.md +0 -353
  152. package/docs/architecture/llm-provider-timeouts.md +0 -60
  153. package/docs/architecture/state-ownership.md +0 -83
  154. /package/docs/architecture/{frontend/team-chat.md → team-chat.md} +0 -0
  155. /package/docs/{analysis → records}/2026-10-29-a2a-cache-hit-rate.md +0 -0
  156. /package/docs/{fixes → records}/2026-11-12-session-expiry-and-mention-thinking.md +0 -0
  157. /package/docs/{handoff → records}/approval-tri-state-handoff.md +0 -0
  158. /package/docs/{design → records}/overview-attention-redesign.md +0 -0
  159. /package/docs/{remote-access/fast-path-plan.md → records/remote-access-fast-path-plan-2026-10-17.md} +0 -0
@@ -420,7 +420,7 @@ writes are dropped when the observation pool is read.
420
420
 
421
421
  Before the working context fills up, the agent is prompted to persist anything important so
422
422
  lossy compaction never silently discards decisions or learned facts. The prompt-side
423
- mechanics live in [prompt-engineering.md §5.7](./prompt-engineering.md); this is the
423
+ mechanics live in [tool-loop-harness.md §5.7](./tool-loop-harness.md); this is the
424
424
  authoritative behavior spec.
425
425
 
426
426
  - **Behavior**: a **turn-level preflight** runs `memoryFlush` once per session when the
@@ -1,6 +1,13 @@
1
1
  # Messaging Gateway
2
2
 
3
3
  **Status:** implemented.
4
+
5
+ > **Reading note.** The body of this document was written *before* the gateway shipped, so its
6
+ > section names still say "Target model" and "Data model & migration". Read §4–§6 as **as-built**:
7
+ > the four entities exist, and the migration in §5 has been executed. §11 (known limitations) is the
8
+ > only part that still describes open work. Trimmed to as-built wording on 2026-11-15; the wording
9
+ > below is kept so the decision trail (why these four entities) survives.
10
+
4
11
  **Related:** `packages/comms/docs/platform-manifest.md` (type contract + "how to add a
5
12
  platform"), issue #340.
6
13
 
@@ -11,6 +11,27 @@ The path is **platform-generic**. Feishu was merely the first platform where a
11
11
  user configured a destination and noticed; the same structural holes existed for
12
12
  every IM.
13
13
 
14
+ ## Merge record
15
+
16
+ > **合并于 2026-11-15** — §12 (in-app user notifications) and §13 (agent→user tools:
17
+ > `notify_user` vs `request_user_input`) were merged **verbatim** from
18
+ > [`mailbox-system.md`](./mailbox-system.md) §12/§13, which now carry pointers only. The
19
+ > pre-existing structure (§1–§11, the outbound-to-IM path) is unchanged; the merged chapters
20
+ > keep their source numbering, so `mailbox-system.md §12.x / §13.x` references map one-to-one
21
+ > onto this file.
22
+ >
23
+ > Layering, so the two halves cannot contradict each other: §1–§11 describe **outbound to a
24
+ > person's IM** (destination resolution, send fidelity, approval cards, one-message-per-
25
+ > notification); §12 describes the **in-app** store + WebSocket fan-out; §13 describes the
26
+ > **agent-side tools** that feed both. They meet at `HITLService.notify()`, and the mechanism
27
+ > description is taken from `mailbox-system.md` as authoritative: `notify()` fans out
28
+ > **per person** for the in-app bell/WS and emits **exactly once** on the channel stream the
29
+ > IM dispatcher subscribes to (§12.5 here, §9 above).
30
+ >
31
+ > What stays in [`mailbox-system.md`](./mailbox-system.md): enqueue, priority, merging,
32
+ > leasing and retry of the mailbox items these paths produce. The mailbox only owns
33
+ > *enqueueing and priority*; the delivery contract is this document.
34
+
14
35
  ## 1. The model — a destination is a concrete, sendable address
15
36
 
16
37
  First principle: **a notification destination is an address**
@@ -271,3 +292,203 @@ moves bytes.*
271
292
  - A desktop install with no group configured for a bot is correctly
272
293
  **unconfigured** — that is the designed state, not a defect.
273
294
 
295
+ ---
296
+
297
+ ## 12. User Notifications (Human Mailbox)
298
+
299
+ > Merged 2026-11-15 from `mailbox-system.md` §12 (verbatim below). This is the **in-app**
300
+ > layer — a DB row plus a WebSocket fan-out — i.e. the user-facing counterpart of the agent
301
+ > mailbox. Outbound-to-IM delivery of the same notification is §1–§11 above; both are fed by
302
+ > `HITLService.notify()`.
303
+
304
+ Just as agents have a mailbox for incoming stimuli, users have a **persistent notification system** for events that require their attention. This is the user-facing counterpart to the agent mailbox.
305
+
306
+ ### 12.1 Storage
307
+
308
+ ```sql
309
+ CREATE TABLE user_notifications (
310
+ id TEXT PRIMARY KEY,
311
+ user_id TEXT NOT NULL,
312
+ type TEXT NOT NULL, -- UserNotificationType
313
+ title TEXT NOT NULL,
314
+ body TEXT DEFAULT '',
315
+ priority TEXT DEFAULT 'normal', -- 'low' | 'normal' | 'high' | 'urgent'
316
+ read INTEGER DEFAULT 0,
317
+ action_type TEXT, -- 'navigate' | 'open_chat' | null
318
+ action_target TEXT, -- JSON: { path } or { agentId, sessionId }
319
+ metadata TEXT DEFAULT '{}',
320
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
321
+ );
322
+ ```
323
+
324
+ ### 12.2 Notification Type Registry
325
+
326
+ Analogous to `MAILBOX_TYPE_REGISTRY`, user notification types are defined in `USER_NOTIFICATION_TYPE_REGISTRY` in `@markus/shared`:
327
+
328
+ | Type | Label | Icon | Default Priority | Action | Category |
329
+ |------|-------|------|-----------------|--------|----------|
330
+ | `approval_request` | Approval Request | 🔐 | high | navigate | approval |
331
+ | `task_created` | Task Created | 📋 | normal | navigate | task |
332
+ | `task_completed` | Task Completed | ✅ | normal | navigate | task |
333
+ | `task_review` | Task Review | 👁️ | normal | navigate | task |
334
+ | `task_failed` | Task Failed | ❌ | high | navigate | task |
335
+ | `requirement_created` | Requirement Proposed | 📝 | high | navigate | task |
336
+ | `requirement_decision` | Requirement Decision | ⚖️ | normal | navigate | task |
337
+ | `agent_report` | Agent Report | 📊 | normal | none | agent |
338
+ | `system` | System | ⚙️ | normal | none | system |
339
+
340
+ ### 12.3 Action Types
341
+
342
+ Notifications can be **actionable** — clicking them navigates the user to the relevant context:
343
+
344
+ | `action_type` | `action_target` format | Behaviour |
345
+ |---------------|----------------------|-----------|
346
+ | `navigate` | `{ "path": "/work?task=T123" }` | Navigate to the specified route |
347
+ | `open_chat` | `{ "agentId": "...", "sessionId": "..." }` | Open chat with agent, resume session |
348
+ | `none` | — | Notification only, no navigation |
349
+
350
+ ### 12.4 REST API
351
+
352
+ | Method | Path | Description |
353
+ |--------|------|-------------|
354
+ | GET | `/api/notifications?type=...&limit=...&offset=...` | List notifications with filtering, returns `totalCount` and `unreadCount` |
355
+ | POST | `/api/notifications/:id/read` | Mark single notification as read |
356
+ | POST | `/api/notifications/mark-all-read` | Mark all notifications as read |
357
+
358
+ ### 12.5 Real-Time Delivery
359
+
360
+ When a notification is created (via `HITLService.notify()`), a WebSocket `notification` event is broadcast. The frontend `App.tsx` listens for this and dispatches a `markus:notifications-changed` custom DOM event, which triggers the `NotificationBell` component to refresh.
361
+
362
+ ---
363
+
364
+ ## 13. Agent-to-User Communication
365
+
366
+ > Merged 2026-11-15 from `mailbox-system.md` §13 (verbatim below). The distinction is a
367
+ > contract, not guidance: `notify_user` informs (one-way), `request_user_input` asks
368
+ > (blocking, returns the answer). Mailbox-side, the resulting items are ordinary mailbox
369
+ > items — see [mailbox-system.md](./mailbox-system.md) §5 for enqueue and §4 for the
370
+ > approval-wait backstop (`APPROVAL_WAIT_TIMEOUT_MS`, 24 h).
371
+
372
+ Agents have two distinct modes for communicating with users. **They are not
373
+ interchangeable** — the choice is decided by one question: *do I need an answer
374
+ before I can continue?*
375
+
376
+ | I need… | Tool | Semantics |
377
+ |---|---|---|
378
+ | to inform (status, report, alert, finding) | `notify_user` | **one-way**; do NOT expect a reply; must not wait for it |
379
+ | an answer / authorization / a decision | `request_user_input` | **blocks** until the human responds; returns the answer |
380
+
381
+ A question asked through `notify_user` does not block, brings no answer back, and
382
+ leaves the agent permanently blocked — which in practice produces repeated
383
+ notifications of the same ask (2026-10-25: 12 identical sends in 3 minutes). A
384
+ notification sent through `request_user_input` would hold a turn open for an
385
+ answer nobody needs to give. Each tool's own description states this boundary;
386
+ it is enforced by the tools' contracts, not by caller discipline.
387
+
388
+ ### 13.1 `notify_user` — Proactive Chat Message + Notification
389
+
390
+ Proactive messages that appear in the agent's chat **and** the user's notification bell. The user can reply in chat, and the agent has full context of what it sent.
391
+
392
+ ```typescript
393
+ // Tool schema
394
+ {
395
+ name: 'notify_user',
396
+ parameters: {
397
+ title: string, // Short headline (1 line)
398
+ body: string, // Full message content (visible in chat)
399
+ priority: 'low' | 'normal' | 'high' | 'urgent', // optional, default 'normal'
400
+ related_task_id?: string, // deep-link to task if applicable
401
+ target_user_id?: string // target specific user (defaults to currentInteractingUserId)
402
+ }
403
+ }
404
+ ```
405
+
406
+ **When to use**: Status updates, task completion notices, FYI messages, findings, alerts — any proactive communication where the user may want to reply.
407
+
408
+ **Flow**: `agent.executeTool('notify_user')` → builds formatted message with embedded context → `memory.appendMessage()` (in-memory session) → `eventBus.emit('agent:notify-user')` → `start.ts` handler: `chatSessionRepo.appendMessage()` (with `notifyUser` metadata) + `ws.broadcastProactiveMessage()` (with metadata) + `hitlService.notify()`
409
+
410
+ **Notification routing**: With `related_task_id` → `actionType: 'navigate'` to Work page. Without task → `actionType: 'open_chat'` with `sessionId` to agent's chat.
411
+
412
+ #### Message Metadata & Context Embedding
413
+
414
+ Every `notify_user` message is persisted with **two layers of context**:
415
+
416
+ 1. **DB metadata** (`metadata` column): `{ notifyUser: true, priority, taskId?, requirementId? }` — used by the frontend to display context links and badges.
417
+
418
+ 2. **Embedded context comment** (appended to message content): `<!-- notify_context: task_id=xxx, requirement_id=yyy -->` — survives through `restoreSessionFromHistory()` (which only reads `role` + `content`), ensuring the agent retains context about what it notified the user about when the user replies.
419
+
420
+ The agent's `chat` scenario system prompt instructs it to parse these `notify_context` references and use tools like `recall_activity` or `search_tasks` to retrieve full context before responding to user follow-ups.
421
+
422
+ > **Referencing resources in the body**: `notify_user` bodies (and any chat/comment/report markdown) should reference Markus resources using the conventions in [prompt-engineering.md §2.2 "Referencing Markus Resources"](./prompt-engineering.md#referencing-markus-resources) — bare IDs (`tsk_…`, `dlv_…`, …), titled links `[Title](task:tsk_…)`, or a reference alone on its own line to render a card. This is separate from the `related_task_id` metadata (which drives the notification's deep-link badge).
423
+
424
+ #### Real-time Visibility
425
+
426
+ All `notify_user` messages are buffered in the frontend for every agent conversation immediately upon WebSocket receipt — regardless of whether the user is currently viewing that agent's chat. This ensures messages are visible as soon as the user navigates to the agent, without requiring a page reload.
427
+
428
+ ### 13.2 `request_user_input` — Blocking Decision Request
429
+
430
+ Requests input or a decision from the user. The tool **blocks** until the user
431
+ responds — no timeout. Supports multiple questions, default Approve/Reject
432
+ options, custom options, and optional freeform text input.
433
+ `request_user_approval` is a deprecated alias with identical behaviour, kept only
434
+ so older prompts keep working.
435
+
436
+ **Use it whenever you cannot continue without an answer** — an authorization, a
437
+ scope call, an ambiguous choice, a fact only the human has ("I am blocked, I need
438
+ one line of approval"). Asking through `notify_user` instead leaves the turn
439
+ unblocked, brings no answer back, and produces repeated notifications of the same
440
+ ask; the blocking tool is the only correct choice for a question that needs an
441
+ answer.
442
+
443
+ ```typescript
444
+ // Tool schema
445
+ {
446
+ name: 'request_user_input',
447
+ parameters: {
448
+ title: string, // Short headline
449
+ description: string, // Detailed context
450
+ options?: Array<{ // Custom options (defaults to Approve/Reject)
451
+ id: string,
452
+ label: string,
453
+ description?: string
454
+ }>,
455
+ allow_freeform?: boolean, // Allow user to type custom text
456
+ related_task_id?: string,
457
+ priority?: 'normal' | 'high' | 'urgent'
458
+ }
459
+ }
460
+ // Returns: { status: 'ok', approved: boolean, selected_option: string, comment: string }
461
+ ```
462
+
463
+ **When to use**: Approval requests, design decisions, choosing between approaches, anything requiring user input or decision.
464
+
465
+ **Flow**: `agent.executeTool('request_user_input')` → `attentionController.setWaitingForApproval(true)` → `HITLService.requestApprovalAndWait(options)` → notification + WebSocket → NotificationBell renders options → user responds → `HITLService.respondToApproval(selectedOption)` → promise resolves → agent receives result
466
+
467
+ The attention controller uses `APPROVAL_WAIT_TIMEOUT_MS` (24h) instead of the normal 45-minute backstop (`MAILBOX_PROCESSING_TIMEOUT_MS`) while waiting for approval, preventing the mailbox item from being requeued prematurely.
468
+
469
+ ### 13.3 Prompt Guidance
470
+
471
+ The system prompt includes scenario-specific guidance on which tool to use:
472
+
473
+ | Situation | Tool |
474
+ |-----------|------|
475
+ | Status report, progress update, FYI alert | `notify_user` — one-way; the user may reply, but do not wait |
476
+ | Task completed notification | `notify_user` with `related_task_id` |
477
+ | **Blocked: needs an authorization / decision to continue** | **`request_user_input`** (blocks, returns the answer) |
478
+ | Need user to approve/reject something | `request_user_input` (default options) |
479
+ | Need user to choose between approaches | `request_user_input` with custom `options` |
480
+ | Need user freeform input | `request_user_input` with `allow_freeform: true` |
481
+ | Want to discuss interactively | Mention user via task/requirement comment |
482
+ | Need to review past execution details | `recall_activity` (list activities or get logs) |
483
+
484
+ ---
485
+
486
+ ## 14. What this document does *not* own
487
+
488
+ - **Enqueueing, priority, merging, leasing, retry** of the notification / approval /
489
+ `a2a_message` items these paths produce — [`mailbox-system.md`](./mailbox-system.md) §4-§6,
490
+ §14, §17-§18.
491
+ - **Which agent gets an inter-agent message and how** —
492
+ [`a2a-communication.md`](./a2a-communication.md) §11.
493
+ - **Addresses, envelopes and bounces** (`refOrigin`, delivery facts, `bounced`) —
494
+ [`mailbox-system.md`](./mailbox-system.md) §28.
@@ -0,0 +1,177 @@
1
+ # Notification sounds (web UI)
2
+
3
+ Short auditory cues for events the user must notice while not looking at the screen.
4
+ This document is the human-readable mirror of the single source of truth in
5
+ `packages/web-ui/src/lib/notificationSounds.ts` — if the two disagree, the code wins
6
+ and this file is the bug.
7
+
8
+ ## Why synthesized cues, not audio files
9
+
10
+ Every cue is a small group of oscillator notes (frequency / start / duration / waveform /
11
+ gain). No binary assets means no packaging path, no codec differences between browsers and
12
+ Electron, and the note table is plain data that unit tests can assert on. Total audible
13
+ length per cue stays under 0.6 s: a cue is a hint, not an interruption.
14
+
15
+ ## Event catalogue
16
+
17
+ | Event id | Label (zh) | Trigger (authoritative source) | Cue |
18
+ |---|---|---|---|
19
+ | `agent-reply-complete` | Agent 回复完成 | `session:stream_state` WS event: the server-confirmed turn for a session goes `streaming: true → false` with status `done` | `chime` (rising two-note) |
20
+ | `input-requested` | Agent 在问你 | WS `notification` with `type = approval_request` **and** `metadata.askKind = "input"` (the agent called `request_user_input`) | `ask` (soft rising two-note) |
21
+ | `approval-requested` | 有审批待处理 | WS `notification` with `type = approval_request` and no `askKind: "input"` (a gate that needs a decision) | `attention` (triple ping) |
22
+ | `review-requested` | 任务待验收 | WS `task:update` whose `status` is `review`; or a notification typed `review_request` / `task_review` | `ding` (single ding) |
23
+ | `notification` | 收到通知 | Any other WS `notification` (`notify_user` and friends) | `pop` (soft pop) |
24
+ | `agent-reply-error` | Agent 回复出错 | Same stream transition as above, but the turn ends with status `error` | `alert` (falling two-note) |
25
+ | `task-failed` | 任务失败 | WS `task:update` whose `status` is `failed` | `alert` |
26
+
27
+ `cancelled` / `stopped` turns are deliberately silent: the user pressed stop, they already
28
+ know. Task transitions to `completed` / `pending` / `in_progress` are silent too — an agent
29
+ finishing everyday work must not create a soundtrack.
30
+
31
+ ## Cue table
32
+
33
+ | Cue id | Notes | Peak | Length | Used by |
34
+ |---|---|---|---|---|
35
+ | `chime` | 698.46 Hz → 880 Hz, sine (+octave) | 0.30 | 0.44 s | `agent-reply-complete` |
36
+ | `attention` | 196 Hz bed + three rising bells (784 / 988 / 1175 Hz, +2× and +2.76× partials) | 0.67 | 0.82 s | `approval-requested` |
37
+ | `ding` | 262 Hz + 523 Hz beds + 1046.5 Hz bell (+2×, +2.76×, +4× partials) + 1568 Hz sparkle | 0.47 | 0.76 s | `review-requested` |
38
+ | `pop` | 523.25 Hz → 659.25 Hz, sine (+octave) | 0.30 | 0.27 s | `notification` |
39
+ | `alert` | 392 Hz → 311.13 Hz, triangle (+octave) | 0.32 | 0.60 s | `agent-reply-error`, `task-failed` |
40
+ | `ask` | 587.33 Hz → 783.99 Hz, sine (+octave) | 0.28 | 0.47 s | `input-requested` |
41
+
42
+ Peak is `cuePeakGain(cue)` — the summed gain of all voices *overlapping in time* (not a single
43
+ note's gain), which is what the limiter actually sees.
44
+
45
+ ### Why some cues sounded "thin" and what makes them sound solid
46
+
47
+ The first pass at `attention` / `ding` was all energy above 800 Hz with a single octave partial
48
+ and a steep envelope — that is the recipe for a piezo buzzer, and the Owner reported exactly
49
+ that ("单薄", 2026-11-27). Physical thickness needs three things, all of them now in the table:
50
+
51
+ 1. **A low bed** (196 Hz for `attention`, 262 + 523 Hz for `ding`). Mid/high content alone has no
52
+ weight on a laptop speaker.
53
+ 2. **Inharmonic partials** — 2.76× is the bell's tierce (a non-integer ratio). Integer-only
54
+ partials read as "electronic"; the inharmonic one is what makes metal sound like metal.
55
+ 3. **Overlapping strikes with long decay** — `attention` is three bells 150 ms apart that ring
56
+ into each other; `ding` is one strike with a 650 ms tail. Single short blips cannot be thick.
57
+
58
+ Two cues may not share a semantic either: `ding` is one strike (a task finished its turn),
59
+ `attention` is a rising triple (several things are waiting for your decision).
60
+
61
+ ### Loudness and duration — the numbers that listenable
62
+
63
+ Reference points (industry IM / system sounds): peak level around **−10 … −6 dBFS** (linear
64
+ 0.30–0.50), daily-event cues **0.25–0.45 s**, "you must act" cues **0.5–0.7 s**. The first
65
+ revision of this feature shipped 0.11–0.16 peak with 0.2–0.3 s spans and was audibly too quiet
66
+ and too clipped (Owner, 2026-11-27).
67
+
68
+ What the current cue table follows:
69
+
70
+ - **Volume lives on a master bus with a limiter**, not per note. Per-note clamping cannot bound
71
+ the *sum* of overlapping voices, which is exactly how a thick cue clips. `loud` (×1.7) is
72
+ therefore genuinely louder: the `DynamicsCompressor` (threshold −6 dB, ratio 12:1) catches the
73
+ peaks instead of the gain stage flattening them.
74
+ - **Overtones instead of a louder fundamental** — a pure sine at a given level sounds markedly
75
+ weaker than a triangle; each note may carry `overtones: [{ mult, gain }]` which adds body
76
+ without the harshness of pushing the fundamental up.
77
+ - **Duration is a semantic signal** — recurring daily events stay short (`pop` 0.27 s), events
78
+ that need a decision run long (`attention` 0.82 s, `alert` 0.60 s). A busy queue therefore
79
+ produces short ticks, while "you owe me an approval" gets attention.
80
+ - Frequencies stay in ~190–1600 Hz (plus quiet octaves) so cues do not sit on top of speech.
81
+
82
+ Tests pin the floors so a later "make it subtle" edit cannot regress into inaudibility:
83
+ `cuePeakGain ≥ 0.24` and `≤ 0.9` (below the limiter), long cues `≥ 550 ms`, daily cues
84
+ `≥ 250 ms`. `attention` and `ding` additionally must keep a low bed (`≤ 300 Hz`) and an
85
+ inharmonic partial — reverting either to a single high blip turns the suite red.
86
+
87
+ ### How `input-requested` is told apart from an approval gate
88
+
89
+ Both a human question (`request_user_input`) and a decision gate arrive as the same
90
+ notification type (`approval_request`), so the distinction must be carried by the producer,
91
+ not guessed by the consumer. `HITLService.requestApproval({ askKind })` accepts
92
+ `'input' | 'approval'` and copies it into `notification.metadata.askKind`; the CLI's
93
+ `userApprovalRequester`装配点 — reached **only** from the agent's `request_user_input` tool —
94
+ passes `askKind: 'input'`.
95
+
96
+ The tempting shape-based proxy is wrong: `metadata.formOnly` / `questions` answer "can one
97
+ tap finish it", not "is this a question or a gate" — a multi-question real approval has
98
+ exactly the same shape as a question. A notification without `askKind` is therefore treated
99
+ as a gate (conservative: better to over-alert on a decision than to whisper a gate).
100
+
101
+ Cue names are localized (`settings:sounds.cues.*`) and shown next to each event row in
102
+ Settings → General → Notification sounds, together with a **Preview** button that plays the
103
+ cue while bypassing the switches (the user clicked it on purpose).
104
+
105
+ ## Where the sound is triggered
106
+
107
+ `packages/web-ui/src/hooks/useNotificationSounds.ts` is mounted once in `App.tsx` (next to
108
+ `useAttentionBadge`) and is the only wiring point:
109
+
110
+ 1. **Turn end** — subscribes to `sessionStreamState` (the client-side authority for
111
+ "is this session generating", fed by server `session:stream_state` pushes plus batch
112
+ reconciliation). It compares consecutive snapshots and fires only when a previous
113
+ snapshot said *this session was streaming* and the new one says the server confirmed it
114
+ ended. Consequences:
115
+ - reattaching mid-stream on app start does not replay a cue later for a turn that never
116
+ started while the app was running; the first snapshot is treated as a baseline;
117
+ - switching tabs, reconnecting the socket, or a reconciliation poll cannot fire a cue
118
+ for a session that was already finished;
119
+ - a local optimistic `false` (the moment the user presses stop) never fires — only the
120
+ server's verdict does.
121
+ 2. **Approvals / notifications** — WS `notification`.
122
+ 3. **Task review / failure** — WS `task:update`.
123
+
124
+ No second judgement lives in the hook: classification is `soundEventFor*` and suppression
125
+ is `SoundGate`, both pure.
126
+
127
+ ## Switching and throttling
128
+
129
+ Preferences live in `localStorage` under `markus-notification-sounds` as
130
+ `{ enabled: boolean, disabledEvents: string[], volume: 'quiet' | 'normal' | 'loud' }`. They are
131
+ deliberately device-scoped (like the theme): "should this machine make noise" is not an
132
+ account-level trait.
133
+
134
+ `volume` multiplies every note's gain (`quiet` 0.6, `normal` 1, `loud` 1.7) and is clamped per
135
+ voice, so the loud step cannot clip. Settings → General → Notification sounds shows the three
136
+ steps and plays the selected level on click — a volume control the user cannot hear while
137
+ adjusting is a guess, not a setting. The Preview button for each event also uses the current
138
+ level, so what you audition is what you will hear.
139
+
140
+ The gate applies three rules in order, short-circuiting:
141
+
142
+ 1. master switch off → nothing plays;
143
+ 2. the event is individually disabled → that event does not play;
144
+ 3. `EVENT_COOLDOWN_MS` (4 s) per event and `GLOBAL_GAP_MS` (0.7 s) between any two cues —
145
+ ten sessions finishing at once yields one chime, not a chord.
146
+
147
+ Changing the preference broadcasts `markus:notification-sounds-changed` (and `storage`
148
+ events cover other tabs), so an open Settings page and the running app never disagree.
149
+
150
+ ## Adding a new sound
151
+
152
+ 1. Add the event id to `NotificationSoundEvent` **and** to `NOTIFICATION_SOUND_EVENTS`
153
+ with an existing cue (or add a new cue to `SOUND_CUES`).
154
+ 2. Add `settings:sounds.events.<event>.label` / `.desc` in `en`, `zh-CN` and `es`.
155
+ 3. Add a `soundEventFor*` classifier branch (or extend an existing one) and wire it in
156
+ `useNotificationSounds.ts` if it comes from a new signal.
157
+ 4. Extend `packages/web-ui/test/notificationSounds.test.ts`; the existing tests fail on a
158
+ missing cue or a missing translation, by design.
159
+
160
+ ## Known limitations
161
+
162
+ - **`attention` currently has no reachable production trigger.** The only producer of
163
+ `approval_request` notifications today is `request_user_input`, and every one of those is
164
+ tagged `askKind: 'input'` — which routes to `input-requested`, by design. The owner
165
+ reviewed this on 2026-11-27 and chose to keep the cue for preview only, rather than add a
166
+ gate entry point or delete it. Recorded here so nobody later assumes the approval cue is
167
+ firing in production when it is not.
168
+ - Browser autoplay policy: audio needs one user gesture before the first cue. The player
169
+ resumes the `AudioContext` opportunistically and silently skips a cue if the context is
170
+ still suspended — the next event after any click works.
171
+ - Cues fire for every agent, including background sessions and other tabs' conversations.
172
+ That is intentional (the point is "something finished while you were elsewhere"), but it
173
+ means a busy team can produce a cue every few seconds; per-event switches exist for that.
174
+ - The user's own actions (approving, submitting for review, stopping a turn) are not
175
+ suppressed by identity yet — if the UI later emits the same WS event for a self-service
176
+ action, a cue would fire. `soundEventForTaskUpdate` only reacts to `review` / `failed`,
177
+ which are agent-driven transitions today.