@markus-global/cli 0.11.3 → 0.12.0-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 (114) hide show
  1. package/dist/backend.d.ts.map +1 -1
  2. package/dist/backend.js +5 -1
  3. package/dist/backend.js.map +1 -1
  4. package/dist/commands/approval-card.d.ts +53 -0
  5. package/dist/commands/approval-card.d.ts.map +1 -0
  6. package/dist/commands/approval-card.js +43 -0
  7. package/dist/commands/approval-card.js.map +1 -0
  8. package/dist/commands/auth.d.ts.map +1 -1
  9. package/dist/commands/auth.js +11 -5
  10. package/dist/commands/auth.js.map +1 -1
  11. package/dist/commands/init.d.ts.map +1 -1
  12. package/dist/commands/init.js +7 -5
  13. package/dist/commands/init.js.map +1 -1
  14. package/dist/commands/model.d.ts.map +1 -1
  15. package/dist/commands/model.js +6 -4
  16. package/dist/commands/model.js.map +1 -1
  17. package/dist/commands/outbound.d.ts +76 -0
  18. package/dist/commands/outbound.d.ts.map +1 -0
  19. package/dist/commands/outbound.js +80 -0
  20. package/dist/commands/outbound.js.map +1 -0
  21. package/dist/commands/start.d.ts +124 -2
  22. package/dist/commands/start.d.ts.map +1 -1
  23. package/dist/commands/start.js +718 -82
  24. package/dist/commands/start.js.map +1 -1
  25. package/dist/index.js +5 -20
  26. package/dist/index.js.map +1 -1
  27. package/dist/markus.mjs +112615 -103125
  28. package/dist/web-ui/assets/AsyncState-BebkDWbq.js +1 -0
  29. package/dist/web-ui/assets/{CommentInput-DN3Cichs.js → CommentInput-BRZWIC3U.js} +1 -1
  30. package/dist/web-ui/assets/{ContentRenderer-CjHOyYgJ.js → ContentRenderer-PGP8H_Zz.js} +2 -2
  31. package/dist/web-ui/assets/DeliverableShareModal-CcigVYGz.js +1 -0
  32. package/dist/web-ui/assets/Deliverables-CQwXaCA4.js +3 -0
  33. package/dist/web-ui/assets/{Notifications-CCsdBfdg.js → Notifications-BvHJCIRG.js} +1 -1
  34. package/dist/web-ui/assets/Search-BA-aXh7i.js +1 -0
  35. package/dist/web-ui/assets/SendToChat-CAfyKhpq.js +1 -0
  36. package/dist/web-ui/assets/Settings-icFp6tNI.js +8 -0
  37. package/dist/web-ui/assets/{Store-BWi97VP9.js → Store-DKwOcmMu.js} +1 -1
  38. package/dist/web-ui/assets/Switch-C7lFnHA7.js +1 -0
  39. package/dist/web-ui/assets/Team-DyqXLZ-X.js +84 -0
  40. package/dist/web-ui/assets/Work-BXGrda4S.js +12 -0
  41. package/dist/web-ui/assets/{arc-Cg0-C295.js → arc-Dnk6N-Zc.js} +1 -1
  42. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-BctEHNLp.js → architectureDiagram-3BPJPVTR-CV8JIXXD.js} +1 -1
  43. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-hxr2ZwOV.js → blockDiagram-GPEHLZMM-D9pKmrXH.js} +1 -1
  44. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-CfIRo1GE.js → c4Diagram-AAUBKEIU-Q26HvIpY.js} +1 -1
  45. package/dist/web-ui/assets/channel-BZs6ereM.js +1 -0
  46. package/dist/web-ui/assets/{chunk-2J33WTMH-T0bENsqX.js → chunk-2J33WTMH-BSjFVwnx.js} +1 -1
  47. package/dist/web-ui/assets/{chunk-4BX2VUAB-ChLLkyYx.js → chunk-4BX2VUAB-BZXv4MQp.js} +1 -1
  48. package/dist/web-ui/assets/{chunk-55IACEB6-BD3ENYp9.js → chunk-55IACEB6-CeKd3oeJ.js} +1 -1
  49. package/dist/web-ui/assets/{chunk-727SXJPM-BAes4atE.js → chunk-727SXJPM-DP1tSQo5.js} +1 -1
  50. package/dist/web-ui/assets/{chunk-AQP2D5EJ-FymM7gfT.js → chunk-AQP2D5EJ-DqEncn7j.js} +1 -1
  51. package/dist/web-ui/assets/{chunk-FMBD7UC4-N5sRT0m9.js → chunk-FMBD7UC4-tuDUJ9Xx.js} +1 -1
  52. package/dist/web-ui/assets/{chunk-ND2GUHAM-BSjS3JyS.js → chunk-ND2GUHAM-DoC8aLWB.js} +1 -1
  53. package/dist/web-ui/assets/{chunk-QZHKN3VN-Dkwitdbr.js → chunk-QZHKN3VN-74zpvcgs.js} +1 -1
  54. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C9JIxJeJ.js +1 -0
  55. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C9JIxJeJ.js +1 -0
  56. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-BLuYATCK.js → cose-bilkent-S5V4N54A-DjYUalC1.js} +1 -1
  57. package/dist/web-ui/assets/{dagre-BM42HDAG-DGLiqiH2.js → dagre-BM42HDAG-oSewacE8.js} +1 -1
  58. package/dist/web-ui/assets/{diagram-2AECGRRQ-Cq_GnNKs.js → diagram-2AECGRRQ-C1fiWe46.js} +1 -1
  59. package/dist/web-ui/assets/{diagram-5GNKFQAL-CHNz-2dA.js → diagram-5GNKFQAL-9G_q6hCa.js} +1 -1
  60. package/dist/web-ui/assets/{diagram-KO2AKTUF-D8eKa7jh.js → diagram-KO2AKTUF-CSm-lJp-.js} +1 -1
  61. package/dist/web-ui/assets/{diagram-LMA3HP47-RkDgQcLr.js → diagram-LMA3HP47-BTAORcHx.js} +1 -1
  62. package/dist/web-ui/assets/{diagram-OG6HWLK6-LqxQrIwa.js → diagram-OG6HWLK6-DbcCkDfo.js} +1 -1
  63. package/dist/web-ui/assets/{docx-preview-Be-Qo_ag.js → docx-preview-DjqdA44x.js} +1 -1
  64. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-BX0zZgYQ.js → erDiagram-TEJ5UH35-DFa-B8-u.js} +1 -1
  65. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-DKnfIFA4.js → flowDiagram-I6XJVG4X-WCTnaK9M.js} +1 -1
  66. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-DjBURmY-.js → ganttDiagram-6RSMTGT7-DbW1CoJJ.js} +1 -1
  67. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-BvSi7SvS.js → gitGraphDiagram-PVQCEYII-1faDfO29.js} +1 -1
  68. package/dist/web-ui/assets/index-B8h1PPzP.js +883 -0
  69. package/dist/web-ui/assets/index-DD3NMntN.css +1 -0
  70. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-CwtIgim2.js → infoDiagram-5YYISTIA-DfXKP4tQ.js} +1 -1
  71. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-CWhXJfSa.js → ishikawaDiagram-YF4QCWOH-D6FOsFQ5.js} +1 -1
  72. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-DN9rorlL.js → journeyDiagram-JHISSGLW-DXpxntIF.js} +1 -1
  73. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Burf5FE8.js → kanban-definition-UN3LZRKU-Dt7FBCF3.js} +1 -1
  74. package/dist/web-ui/assets/{mermaid.core-Dx4rzlyC.js → mermaid.core-sTcSUoRD.js} +5 -5
  75. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-DqZ21Siw.js → mindmap-definition-RKZ34NQL-CvOU23ga.js} +1 -1
  76. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-C_4ksu-T.js → pieDiagram-4H26LBE5-DUedtXVj.js} +1 -1
  77. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-Dl6Rjg1X.js → quadrantDiagram-W4KKPZXB-CqpHHRca.js} +1 -1
  78. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-CzmWi02d.js → requirementDiagram-4Y6WPE33-CKZYvVDJ.js} +1 -1
  79. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-D8K7e8we.js → sankeyDiagram-5OEKKPKP-gZ0nzDfs.js} +1 -1
  80. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-1z9rqtVx.js → sequenceDiagram-3UESZ5HK-DN3XdBkW.js} +1 -1
  81. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-nneYkkHa.js → stateDiagram-AJRCARHV-BvtafGxO.js} +1 -1
  82. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-B2nWDV5R.js +1 -0
  83. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-D6GmLlRi.js → timeline-definition-PNZ67QCA-BrR919lp.js} +1 -1
  84. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-TVefhiCa.js → vennDiagram-CIIHVFJN-B7CTm4yM.js} +1 -1
  85. package/dist/web-ui/assets/{wardley-L42UT6IY-BgUuAeiM.js → wardley-L42UT6IY-CyqFngx_.js} +1 -1
  86. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-CyJ_l94o.js → wardleyDiagram-YWT4CUSO-BCqEPBJ5.js} +1 -1
  87. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-kajbbx7a.js → xychartDiagram-2RQKCTM6-BmT6Cmz-.js} +1 -1
  88. package/dist/web-ui/index.html +2 -2
  89. package/docs/README.md +1 -0
  90. package/docs/architecture/architecture.md +1 -1
  91. package/docs/architecture/configuration-model.md +156 -0
  92. package/docs/architecture/messaging-gateway.md +1043 -0
  93. package/docs/architecture/notification-delivery.md +273 -0
  94. package/docs/design/remote-access-contract.md +445 -0
  95. package/docs/guides/development.md +1 -1
  96. package/docs/guides/guide.md +4 -2
  97. package/docs/guides/remote-access.md +147 -214
  98. package/docs/handoff/approval-tri-state-handoff.md +69 -0
  99. package/docs/handoff/remote-access-handoff.md +160 -0
  100. package/docs/records/agent-platform-friction-2026-10.md +102 -2
  101. package/package.json +1 -1
  102. package/dist/web-ui/assets/DeliverableShareModal-CBSvxB-X.js +0 -1
  103. package/dist/web-ui/assets/Deliverables-BaAF4-w0.js +0 -3
  104. package/dist/web-ui/assets/Search-BiBdevAU.js +0 -1
  105. package/dist/web-ui/assets/Settings-CawBnWuy.js +0 -8
  106. package/dist/web-ui/assets/Team-CfUDkdc3.js +0 -84
  107. package/dist/web-ui/assets/Work-DrIXOW-P.js +0 -12
  108. package/dist/web-ui/assets/channel-DAQ2Rbxq.js +0 -1
  109. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BZyCVtJb.js +0 -1
  110. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BZyCVtJb.js +0 -1
  111. package/dist/web-ui/assets/index-D8vskks7.js +0 -882
  112. package/dist/web-ui/assets/index-DEN_qReg.css +0 -1
  113. package/dist/web-ui/assets/modelCapabilities-DDtCBZ6o.js +0 -1
  114. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C-hpzcms.js +0 -1
@@ -0,0 +1,273 @@
1
+ # Notification & approval delivery
2
+
3
+ Status: **implemented** (2026-10). This is the design of the **outbound
4
+ notification path** — how a notification or an approval produced inside Markus
5
+ reaches a person's IM, and the invariants it holds. It supersedes the "honest
6
+ residual" notes formerly in `messaging-gateway.md` §7.4 / §11: on a live install
7
+ those residuals *were* the bug (a "connected" integration where every
8
+ notification was silently dropped).
9
+
10
+ The path is **platform-generic**. Feishu was merely the first platform where a
11
+ user configured a destination and noticed; the same structural holes existed for
12
+ every IM.
13
+
14
+ ## 1. The model — a destination is a concrete, sendable address
15
+
16
+ First principle: **a notification destination is an address**
17
+ `(platform, instanceId, nativeId, receiveIdType?)` that the transport can actually
18
+ send to. It is obtained two ways, both first-class:
19
+
20
+ - **derived** — from a binding conversation (a chat the agent already lives in);
21
+ - **declared** — an explicit destination on the *instance* (a chat id), independent
22
+ of any binding.
23
+
24
+ The lookup port (`NotifyTargetLookup`, production impl `RepoNotifyTargetLookup`)
25
+ exposes three readers — `agentTarget` / `instanceTarget` / `globalTarget` — and
26
+ `resolveNotifyTarget(orgId, origin, lookup)` walks them **first-hit-wins**. The walk
27
+ ends **loudly** (`{ delivered: false, reason: 'no-notify-target' }`), never with a
28
+ silent drop.
29
+
30
+ ## 2. The resolution walk
31
+
32
+ The walk **enumerates candidates, most specific first, and returns the first one
33
+ that may actually be sent through**:
34
+
35
+ 1. **agent** — the producing agent's own conversation binding (if any).
36
+ 2. **instance** — the **declared notification destination** on the instance,
37
+ read from `platform_instances.config` via the generic annotation (§3). This is
38
+ the reliable terminus: it does not depend on any binding existing.
39
+ 3. **instance** — an explicit `kind = 'notification'` binding sink on one of those
40
+ instances.
41
+ 4. **instance fallback** — the instance's `notifyAgentId` → that agent's
42
+ conversation (best-effort).
43
+ 5. **global** — the Secretary's conversation, else any global-scope binding with a
44
+ native id.
45
+ 6. **no candidates at all** → a visible **undelivered** state (surfaced in Settings
46
+ and in one log line), once per message, not once per platform.
47
+ 7. **candidates existed, every one ineligible** → an explicit **suppressed** state
48
+ carrying *each* skipped candidate and why it was passed over — distinct from
49
+ `undelivered`, so "deliberately switched off" can never again stand in for
50
+ "mis-routed".
51
+
52
+ Level 2 is what makes delivery predictable on a fresh install: a destination set in
53
+ Settings is honoured even when no chat has ever bound to an agent.
54
+
55
+ ### 2.1 Where-could-it-go and may-it-go-there are separate questions
56
+
57
+ `lookup.candidates()` answers only the first (it is a pure enumeration, ordered by
58
+ the rules below). Whether a candidate is **eligible** is a single predicate supplied
59
+ by the dispatcher — the notification preferences for *this* message (§6). The walk
60
+ applies it as a **filter**, moving on to the next candidate rather than stopping.
61
+
62
+ Collapsing the two into "pick one, then check it" is what silently dropped every
63
+ notification for an org on 2026-10-16: the walk landed on a bot whose notification
64
+ master switch was off and the drop was logged as `notify-disabled`, which reads like
65
+ an intentional setting. An ineligible candidate is now just skipped.
66
+
67
+ ### 2.2 Candidate ordering is stated, never inherited from `ORDER BY label`
68
+
69
+ `platform_instances` is stored ordered by `(platform, label)`. Letting that *be* the
70
+ routing priority is how a bot labelled `CTO` silently outranked one labelled
71
+ `default`. The order is now declared in the lookup:
72
+
73
+ 1. the instances the producing agent already works in (its own bindings);
74
+ 2. the instance named by the org's declared global sink (`scope = 'global'`);
75
+ 3. the Secretary's instances;
76
+ 4. the rest, by creation time then id — a deterministic *tie-break*, never a
77
+ semantic preference.
78
+
79
+ When more than one instance-scoped destination is available and one of them wins,
80
+ the dispatcher logs which bot was chosen and what else was on offer — so "why did
81
+ this land in *that* chat?" has an answer that is not "list order".
82
+
83
+ ### 2.3 A switched-off bot is not a candidate at all
84
+
85
+ `platform_instances.enabled` is the bot's master switch (the toggle beside its
86
+ connection status). A disabled instance is not connected (`start.ts` skips it), so
87
+ it cannot deliver; it is excluded during enumeration — structurally, not via a
88
+ policy the resolver has to know about.
89
+
90
+ ## 3. Generic destination declaration (`notifyTarget`)
91
+
92
+ A manifest field may carry `notifyTarget: 'chat' | 'user'`. The resolver scans a
93
+ platform's annotated fields (in manifest order) and needs **no platform branch** —
94
+ a new platform becomes a notification target by declaring a field rather than
95
+ adding an `if (platform === …)`. Field reference and the per-platform table live in
96
+ `packages/comms/docs/platform-manifest.md`.
97
+
98
+ The kind maps onto a wire receive-id type (`receiveIdTypeForDestination`:
99
+ `chat → chat_id`, `user → open_id`); an adapter whose user token differs translates
100
+ at the edge. Destination fields are always **optional** — a required field would
101
+ silently disable the platform.
102
+
103
+ ## 4. A destination is a group, never a person
104
+
105
+ Approvals and notifications are posted into a **chat the bot has been added to**. A
106
+ bot that holds only a personal address is not a notification channel — and an
107
+ individual address made a bot with no group count as "configured" while nothing
108
+ reached the group, which is the failure this removes. Every platform with group
109
+ semantics therefore declares exactly one `chat` destination; a bot with no group is
110
+ honestly **unconfigured**.
111
+
112
+ The single exception is **WhatsApp**, whose Cloud API has no groups: its only
113
+ addressable recipient is a `wa_id`, so it declares a `user` destination.
114
+
115
+ ## 5. Send fidelity — the render decision reaches the adapter
116
+
117
+ `renderOutbound()` picks `format = 'card' | 'markdown' | 'text'` by capability, but
118
+ the decision is only real if the transport honours it. `RouterOutboundSink.send()`
119
+ forwards the renderer's `format` **and** `NotifyTarget.receiveIdType` to the
120
+ adapter: `card → the adapter's interactive-card call` (Feishu
121
+ `sendInteractiveMessage`, Slack blocks, …), `markdown`/`text → text`. This is what
122
+ makes an approval **tappable** wherever the platform supports cards, instead of
123
+ degrading every notification to text with a literal `[label] ref`.
124
+
125
+ Capability degradation is a total function: `cards|buttons → 'card'`,
126
+ `markdown → 'markdown'`, otherwise `'text'`. The plain-text projection always exists
127
+ and always carries the action labels **and their refs** — a platform without buttons
128
+ shows the same content as text, it never drops it.
129
+
130
+ Notification bodies are Markdown; the adapter renders them as the platform's rich
131
+ form (Feishu `lark_md`). **Attribution is envelope, not payload** (§5.1): at the
132
+ single delivery point the dispatcher stamps the message's `origin` with the
133
+ producing agent's name and, when it has one, its **team** — and each renderer
134
+ places that fact once, in its own way.
135
+
136
+ ### 5.1 Origin attribution — structure, not a body prefix
137
+
138
+ Who sent a message is *structure* (`origin.agentName` / `origin.teamName`), never a
139
+ line spliced into the body for a later stage to parse back out:
140
+
141
+ - **Text / markdown platforms** get a plain-text line from the one renderer,
142
+ `originLine()` — `来自:{agent}(团队:{team})`, or `来自:{agent}` with no team. It
143
+ is deliberately markdown-free: the old in-band `**来自**:…` prefix leaked its `**`
144
+ straight into text-only platforms, and left no room for the team.
145
+ - **Card platforms** keep `body` clean and receive `origin` as a field, which each
146
+ adapter renders in its own extension slot — a Feishu `note` footnote, a Slack
147
+ `context` block. Names are escaped per dialect (Slack mrkdwn) so an agent name
148
+ cannot inject a mention or link.
149
+
150
+ The line is idempotent and best-effort: if the agent name cannot be resolved the
151
+ message is delivered anyway, unchanged; a missing team never withholds the agent
152
+ line nor the delivery. `RouterOutboundSink` forwards `origin` into the card
153
+ options; resolution happens once, in the dispatcher, from `agentId`.
154
+
155
+ ## 6. One enforcement point for preferences
156
+
157
+ `notifyOnApproval` / `notifyOnNotification` / `notifyPriority` and the **master
158
+ switch** `notifyEnabled` are enforced in exactly one place — the dispatcher's
159
+ **eligibility predicate**, applied *inside* the walk (see §2.1) — reading the **same**
160
+ instance config as the destination (`RepoNotifyPreferenceSource`,
161
+ `suppressionReasonFor`). A preference is not a decorative field: toggling it changes
162
+ what is sent. Turning the master switch off removes exactly that bot from
163
+ consideration, at the same single point, not by greying out a button.
164
+
165
+ ## 7. Single source of truth — the DB, never `markus.json`
166
+
167
+ The outbound wiring reads `platform_instances.config` (what Settings writes) and
168
+ **only** that. The legacy `markus.json` → `config.integrations.<platform>` read is
169
+ removed: a value the UI never wrote can no longer win. This is the "one fact, one
170
+ source" rule applied to the whole notification surface — the configured fact and the
171
+ consumed fact are the same row.
172
+
173
+ ## 8. Approval round-trip (tap → record → visible, and the in-app banner)
174
+
175
+ An approval is a **one-shot card**: the platform never edits it for us. The
176
+ round-trip therefore has four observable steps, each with one owner:
177
+
178
+ 1. **Outbound** — the card carries an action `ref`. Both the signing side and the
179
+ verifying side call the *same* resolver, `resolveActionSecret()`
180
+ (`@markus/shared`): an explicit `MARKUS_ACTION_SECRET` wins, otherwise a random
181
+ secret is generated once and persisted at `~/.markus/action-secret` (0600),
182
+ exactly like `resolveJwtSecret` / `resolveGatewaySecret`. **The operator never
183
+ configures it** — signing is a defence-in-depth backstop, not the trust boundary
184
+ (the inbound webhook / long-connection is authenticated by the platform itself).
185
+ Unset is still accepted: `resolveCardActionValue(value, secret)` returns the
186
+ `{approvalId, command}` from a *signed* token when a secret exists, and from a
187
+ bare id (flagged `unverified`) when it does not — a tap is never silently
188
+ discarded because a key was missing.
189
+ 2. **Record** — the resolved action is handed to `hitlService.respondToApproval`;
190
+ the decision is persisted, and the recorded actor is preserved (a second tap does
191
+ not overwrite the first decision's actor).
192
+ 3. **Rewrite the card** — after the decision is recorded, the wiring calls
193
+ `router.updateResolvedCard(platform, instanceId, messageId, resolution)`: the
194
+ adapter re-renders the same card with its action row replaced by a status line
195
+ (`✅ 已批准` / `❌ 已驳回`, actor, time) and the header recoloured. The message id
196
+ comes from the action (`InboundAction.messageId`, Feishu
197
+ `context.open_message_id`); title/body are re-read from the approval record —
198
+ never scraped back out of the card. Two contract rules make this safe: the
199
+ capability is **optional** on `CommAdapter` (a platform that cannot edit messages
200
+ omits it, and `updateResolvedCard` returns `false` rather than throwing), and it
201
+ is **best-effort** (a failed rewrite is logged, never rolls back a recorded
202
+ decision). The PATCH is **scheduled after the callback ack**
203
+ (`scheduleCardRewrite`, `CARD_REWRITE_DELAY_MS = 1000`, `unref`) so it is the
204
+ last write the tapper's client sees — an in-ack PATCH is visually overwritten by
205
+ the client's re-render of the card as it was at tap time. A repeated tap
206
+ re-reads the approval and rewrites again, so an old-looking card self-heals.
207
+ 4. **Dismiss the in-app banner** — the decision must invalidate every derived view,
208
+ whoever triggered it. Terminal transitions (approve / reject / cancel / timeout)
209
+ emit through one hook, `HITLService.onApprovalChanged`; api-server **broadcasts**
210
+ `approval:resolved`; the Team banner and the notification bell subscribe and
211
+ refresh. The event fires at the **transition itself**, not at each call site, so a
212
+ decision made from an external IM (a different process path than the HTTP route)
213
+ dismisses the in-app banner just the same. Invariant: *any terminal approval
214
+ transition invalidates all derived views, regardless of who caused it.*
215
+
216
+ ## 9. One logical notification ⇒ one message
217
+
218
+ The dispatcher subscribes to **one** notification stream, and the sources are split
219
+ by semantics at a single point:
220
+
221
+ - `HITLService.notify()` fans out **per person** (app bell / WS) **N** times, and
222
+ emits on the **channel** stream (`onChannelNotification`) **exactly once**. The
223
+ dispatcher subscribes to the channel stream (`attachNotifications`), so one
224
+ logical notification yields **one** IM message — decoupled from the number of
225
+ human users. Subscribing to the per-person stream (the pre-fix wiring) multiplied
226
+ every message by the human count; that is the duplicate-delivery bug.
227
+ - The EventBus path (`attachEventBus`: `task:completed` / `task:failed`) is a
228
+ **separate** notification — the agent's *execution* terminus, not a copy of the
229
+ status-transition notice. The task state machine emits no `task:*` events, so a
230
+ single transition cannot fire both paths. There is no "second source" to
231
+ de-duplicate; de-duplicating would be a guard for a writer that does not exist.
232
+
233
+ **Inbound duplicates** are a distinct layer, fixed structurally: an adapter's
234
+ on-message **handler is wired at registration, not at connect**. Registration
235
+ dedupes by adapter identity and `connect` only establishes transport, so repeated
236
+ reconnects (a settings save, a "verify connection", a platform reconnect) cannot
237
+ stack handlers. Invariant: *subscribing is a registration-time act; connecting only
238
+ moves bytes.*
239
+
240
+ ## 10. Invariants
241
+
242
+ - A destination is a sendable address; if none is **eligible** the result is a
243
+ **visible** state — `undelivered` when nothing was configured, `suppressed` (with
244
+ every skipped candidate and its reason) when candidates existed and all were
245
+ switched off. Never a silent drop.
246
+ - An ineligible candidate is a **filter**, never a dead end: the walk continues to
247
+ the next destination. One switched-off bot cannot swallow a notification another
248
+ bot could deliver.
249
+ - Destination, send fidelity, preference enforcement and attribution all read the
250
+ **same** instance config (the DB) — one fact, one source.
251
+ - Attribution is **structure** (`origin.{agentName,teamName}`), placed exactly once per
252
+ rendering: an inline, markdown-free line for text platforms, a native extension slot
253
+ for card platforms — never both, never a body prefix a later stage must parse.
254
+ - A notification platform with buttons renders a tappable card; capability
255
+ degradation is total and never loses content.
256
+ - **Exactly one** IM message per logical notification, independent of user count.
257
+ - A notification **names its subject**. An event that carries no human-readable
258
+ title/summary is an internal signal, not a notification, and is not sent — the
259
+ dispatcher never falls back to the raw event name as a title (2026-10-16: an
260
+ agent-execution `task:completed`, payload `{ taskId, agentId }`, was pushed to
261
+ Feishu as the literal string `"task:completed"`). The user-facing task facts
262
+ belong to the status machine → HITL, which always carries the title.
263
+ - A tap always produces visible evidence; the card rewrite is post-ack, optional and
264
+ best-effort.
265
+ - Any terminal approval transition invalidates all derived UI, from any trigger.
266
+
267
+ ## 11. Not claimed
268
+
269
+ - Real-service connectivity for Slack / Telegram / Discord is unverifiable on a
270
+ desktop install (no public URL); Feishu long-connection is the proven path.
271
+ - A desktop install with no group configured for a bot is correctly
272
+ **unconfigured** — that is the designed state, not a defect.
273
+