@cohortapp/agent-sdk 2.3.2 → 2.4.1

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 (148) hide show
  1. package/framework-features.json +30 -0
  2. package/lib/backlog.mjs +136 -0
  3. package/lib/cadences.mjs +63 -2
  4. package/lib/cadences.test.mjs +105 -0
  5. package/lib/capability/inventory.mjs +542 -0
  6. package/lib/capability/inventory.test.mjs +232 -0
  7. package/lib/capability/probe.mjs +255 -0
  8. package/lib/channels/contract.mjs +37 -1
  9. package/lib/channels/contract.test.mjs +25 -1
  10. package/lib/claude-bin.mjs +37 -3
  11. package/lib/claude-bin.test.mjs +42 -8
  12. package/lib/execution/disposition.mjs +501 -0
  13. package/lib/execution/disposition.test.mjs +482 -0
  14. package/lib/execution/drive.mjs +352 -0
  15. package/lib/execution/drive.test.mjs +270 -0
  16. package/lib/execution/effects.mjs +340 -0
  17. package/lib/execution/effects.test.mjs +193 -0
  18. package/lib/execution/index.mjs +152 -0
  19. package/lib/execution/intake.mjs +581 -0
  20. package/lib/execution/intake.test.mjs +343 -0
  21. package/lib/execution/journal.mjs +374 -0
  22. package/lib/execution/journal.test.mjs +261 -0
  23. package/lib/execution/match.mjs +331 -0
  24. package/lib/execution/match.test.mjs +235 -0
  25. package/lib/execution/pipeline.mjs +341 -0
  26. package/lib/execution/pipeline.test.mjs +389 -0
  27. package/lib/execution/route.mjs +332 -0
  28. package/lib/execution/route.test.mjs +186 -0
  29. package/lib/execution/surface-policy.mjs +446 -0
  30. package/lib/execution/surface-policy.test.mjs +162 -0
  31. package/lib/goals/admission.mjs +209 -0
  32. package/lib/goals/admission.test.mjs +139 -0
  33. package/lib/goals/classify.mjs +206 -0
  34. package/lib/goals/classify.test.mjs +109 -0
  35. package/lib/goals/collaborate.mjs +415 -0
  36. package/lib/goals/collaborate.test.mjs +324 -0
  37. package/lib/goals/gaps.mjs +111 -0
  38. package/lib/goals/gaps.test.mjs +284 -0
  39. package/lib/goals/loop.mjs +537 -0
  40. package/lib/goals/loop.test.mjs +719 -0
  41. package/lib/identity/persona.mjs +247 -0
  42. package/lib/identity/persona.test.mjs +117 -0
  43. package/lib/kpi.mjs +469 -0
  44. package/lib/kpi.test.mjs +244 -0
  45. package/lib/mandate/audit.mjs +168 -0
  46. package/lib/mandate/audit.test.mjs +195 -0
  47. package/lib/mandate/cache.mjs +162 -0
  48. package/lib/mandate/derive.mjs +317 -0
  49. package/lib/mandate/derive.test.mjs +224 -0
  50. package/lib/mandate/model.mjs +352 -0
  51. package/lib/mandate/model.test.mjs +145 -0
  52. package/lib/mandate/refresh.mjs +187 -0
  53. package/lib/mandate/refresh.test.mjs +293 -0
  54. package/lib/mcp/server.test.mjs +4 -4
  55. package/lib/org/approvals.mjs +14 -2
  56. package/lib/org/client.mjs +58 -22
  57. package/lib/org/client.test.mjs +3 -1
  58. package/lib/org/inbound/directedness.mjs +720 -0
  59. package/lib/org/inbound/directedness.test.mjs +543 -0
  60. package/lib/org/inbound/facts.mjs +501 -0
  61. package/lib/org/inbound/facts.test.mjs +375 -0
  62. package/lib/org/inbound/hydrate.mjs +535 -0
  63. package/lib/org/inbound/hydrate.test.mjs +326 -0
  64. package/lib/org/inbound/index.mjs +233 -0
  65. package/lib/org/inbound/index.test.mjs +324 -0
  66. package/lib/org/inbound/io.mjs +141 -0
  67. package/lib/org/inbound/project.mjs +201 -0
  68. package/lib/org/inbound/project.test.mjs +287 -0
  69. package/lib/org/inbound/surfaces.mjs +257 -0
  70. package/lib/org/knowledge.mjs +10 -1
  71. package/lib/org/knowledge.test.mjs +8 -1
  72. package/lib/org/leases.mjs +5 -0
  73. package/lib/org/mesh.mjs +17 -2
  74. package/lib/org/messaging.mjs +40 -4
  75. package/lib/org/messaging.test.mjs +40 -0
  76. package/lib/org/param-contract.mjs +694 -0
  77. package/lib/org/param-contract.test.mjs +451 -0
  78. package/lib/org/protocol.checksum +1 -1
  79. package/lib/org/protocol.mjs +8 -0
  80. package/lib/org/protocol.test.mjs +5 -1
  81. package/lib/org/push.mjs +1025 -0
  82. package/lib/org/push.test.mjs +690 -0
  83. package/lib/org/tool-surface.mjs +138 -38
  84. package/lib/org/tool-surface.test.mjs +13 -8
  85. package/lib/org/typing.mjs +341 -0
  86. package/lib/org/typing.test.mjs +291 -0
  87. package/lib/plan/compile.mjs +510 -0
  88. package/lib/plan/compile.test.mjs +286 -0
  89. package/lib/plan/emit.mjs +256 -0
  90. package/lib/plan/emit.test.mjs +246 -0
  91. package/lib/plan/explain.mjs +226 -0
  92. package/lib/plan/explain.test.mjs +188 -0
  93. package/lib/plan/schema.mjs +140 -0
  94. package/lib/resource-governor.mjs +47 -1
  95. package/lib/resource-governor.test.mjs +21 -1
  96. package/lib/setup/enroll-from-cohort.mjs +105 -17
  97. package/lib/setup/enroll-from-cohort.test.mjs +68 -1
  98. package/lib/setup/sections/identity.mjs +15 -4
  99. package/lib/setup/sections/identity.test.mjs +94 -0
  100. package/lib/setup/sections/inventory.mjs +178 -0
  101. package/lib/setup/sections/inventory.test.mjs +198 -0
  102. package/lib/setup/sections/mandate.mjs +392 -0
  103. package/lib/setup/sections/mandate.test.mjs +373 -0
  104. package/lib/setup/sections/subagents.mjs +427 -0
  105. package/lib/setup/sections/subagents.test.mjs +429 -0
  106. package/lib/setup/sections/verify.mjs +121 -0
  107. package/lib/setup/sections/verify.test.mjs +175 -0
  108. package/lib/setup/sot.mjs +2 -0
  109. package/lib/subagents/cli.mjs +463 -0
  110. package/lib/subagents/cli.test.mjs +389 -0
  111. package/lib/subagents/client.mjs +373 -0
  112. package/lib/subagents/client.test.mjs +309 -0
  113. package/lib/subagents/gap.mjs +268 -0
  114. package/lib/subagents/gap.test.mjs +234 -0
  115. package/lib/subagents/lock.mjs +296 -0
  116. package/lib/subagents/lock.test.mjs +248 -0
  117. package/lib/subagents/manifest.mjs +224 -0
  118. package/lib/subagents/manifest.test.mjs +175 -0
  119. package/lib/subagents/refs.mjs +274 -0
  120. package/lib/subagents/refs.test.mjs +204 -0
  121. package/lib/subagents/resolve.mjs +455 -0
  122. package/lib/subagents/resolve.test.mjs +422 -0
  123. package/lib/subagents/schema.mjs +467 -0
  124. package/lib/subagents/schema.test.mjs +306 -0
  125. package/package.json +8 -3
  126. package/plugins/maestro-skills/.claude-plugin/marketplace.json +16 -0
  127. package/policies/ai-disclosure.yaml +42 -2
  128. package/scaffold/CLAUDE.md +16 -2
  129. package/schedules/triggers/goal-steward.md +79 -0
  130. package/scripts/ci/conformance-org-api.mjs +792 -0
  131. package/scripts/ci/conformance-org-api.test.mjs +417 -0
  132. package/scripts/daemon/agent-daemon.mjs +36 -4
  133. package/scripts/daemon/cadence-handlers.mjs +145 -1
  134. package/scripts/daemon/goal-steward-cadence.test.mjs +243 -0
  135. package/scripts/daemon/inbox-deferral.mjs +45 -2
  136. package/scripts/daemon/inbox-deferral.test.mjs +56 -0
  137. package/scripts/daemon/inbox-wake.mjs +282 -0
  138. package/scripts/daemon/inbox-wake.test.mjs +199 -0
  139. package/scripts/daemon/prompt-builder.mjs +41 -1
  140. package/scripts/daemon/typing-registry.mjs +55 -2
  141. package/scripts/daemon/typing-registry.test.mjs +25 -0
  142. package/scripts/local-triggers/generate-plists.test.mjs +5 -5
  143. package/scripts/setup/gen-subagent-manifest.mjs +95 -0
  144. package/scripts/setup/gen-subagent-manifest.test.mjs +124 -0
  145. package/scripts/setup/generate-plan.mjs +108 -0
  146. package/scripts/setup/init-capability-manifest.mjs +70 -0
  147. package/scripts/setup/init-skill-marketplace.mjs +155 -0
  148. package/scripts/setup/init-skill-marketplace.test.mjs +193 -0
@@ -0,0 +1,343 @@
1
+ /**
2
+ * lib/execution/intake.test.mjs — every inbound shape, every surface, both signs.
3
+ *
4
+ * The negatives matter more than the positives here. `intake` is the only place
5
+ * that decides a Slack channel message nobody addressed is NOT this agent's
6
+ * problem, and the only place an `info` alert is stopped from becoming work. A
7
+ * regression in a positive case is a missed reply; a regression in a negative
8
+ * case is an agent that interrupts every conversation in the workspace.
9
+ */
10
+
11
+ import test from "node:test";
12
+ import assert from "node:assert/strict";
13
+
14
+ import {
15
+ intake,
16
+ fromInboxItem,
17
+ fromChannelEvent,
18
+ fromAlert,
19
+ fromRawEvent,
20
+ fromMessageEvent,
21
+ parseRawRef,
22
+ isKnownSurface,
23
+ KIND_SURFACE,
24
+ SURFACE_FAMILY,
25
+ SURFACE_TOPIC,
26
+ RECONSTRUCTED_REASON,
27
+ } from "./intake.mjs";
28
+ import { SURFACE_POLICY, EXTENDED_SURFACE_NAMES } from "./surface-policy.mjs";
29
+ import { SURFACE_NAMES } from "../org/inbound/surfaces.mjs";
30
+ import { decide } from "./disposition.mjs";
31
+ import { dedupeKey, threadKey } from "./journal.mjs";
32
+
33
+ const ME = "mem_self";
34
+ const NOW = "2026-08-11T09:00:00.000Z";
35
+
36
+ /** A cohort inbox item as it exists on disk (post-`eventToInboxItem` flattening). */
37
+ function orgItem(over = {}) {
38
+ return {
39
+ id: "cohort-mention-4821",
40
+ service: "cohort",
41
+ channel: "eng-space",
42
+ channel_id: "chan_1",
43
+ sender: "peer-one",
44
+ sender_id: "mem_peer",
45
+ timestamp: NOW,
46
+ subject: "Cohort @mention: eng-space",
47
+ content: "can you take a look at this",
48
+ thread_id: "msg_77",
49
+ is_reply: false,
50
+ priority_signals: { from_ceo: false, tagged_urgent: false, contains_deadline: false, mentions_agent: true },
51
+ raw_ref: "cohort:mention:msg_99:4821",
52
+ source: "cohort",
53
+ kind: "mention",
54
+ ...over,
55
+ };
56
+ }
57
+
58
+ // ---------------------------------------------------------------------------
59
+ // raw_ref
60
+ // ---------------------------------------------------------------------------
61
+
62
+ test("parseRawRef reads the projection's cohort ref, including ids containing colons", () => {
63
+ assert.deepEqual(parseRawRef("cohort:mention:msg_99:4821"), {
64
+ surface: "mention",
65
+ entityId: "msg_99",
66
+ seq: "4821",
67
+ });
68
+ assert.deepEqual(parseRawRef("cohort:task_comment:task:abc:def:12"), {
69
+ surface: "task_comment",
70
+ entityId: "task:abc:def",
71
+ seq: "12",
72
+ });
73
+ });
74
+
75
+ test("parseRawRef refuses a channel adapter's legacy ref and an unknown surface", () => {
76
+ assert.equal(parseRawRef("slack:C123:1699.1"), null, "legacy channel ref must not parse as cohort");
77
+ assert.equal(parseRawRef("cohort:teleport:x:1"), null, "unknown surface must not parse");
78
+ assert.equal(parseRawRef(""), null);
79
+ assert.equal(parseRawRef(null), null);
80
+ });
81
+
82
+ // ---------------------------------------------------------------------------
83
+ // coverage: every surface is reachable and decidable
84
+ // ---------------------------------------------------------------------------
85
+
86
+ test("every policy surface has a family, a topic and a reconstructable reason", () => {
87
+ for (const name of Object.keys(SURFACE_POLICY)) {
88
+ assert.ok(SURFACE_FAMILY[name], `${name} has no family`);
89
+ assert.ok(SURFACE_TOPIC[name], `${name} has no topic`);
90
+ assert.ok(RECONSTRUCTED_REASON[name], `${name} has no reconstructable reason`);
91
+ assert.ok(isKnownSurface(name), `${name} is not a known surface`);
92
+ }
93
+ });
94
+
95
+ test("every org surface can be reconstructed from an on-disk item and decided", () => {
96
+ for (const surface of SURFACE_NAMES) {
97
+ const item = orgItem({
98
+ raw_ref: `cohort:${surface}:ent_1:900`,
99
+ kind: surface === "dm" ? "message" : surface,
100
+ id: `cohort-${surface}-900`,
101
+ });
102
+ const norm = fromInboxItem(item, { me: ME, now: NOW });
103
+ assert.equal(norm.verdict.surface, surface, `${surface} did not round-trip`);
104
+ assert.equal(norm.verdict.directed, true, `${surface} lost its directedness`);
105
+ assert.equal(norm.candidate.family, SURFACE_FAMILY[surface]);
106
+
107
+ const d = decide({ candidate: norm.candidate, verdict: norm.verdict, me: ME, history: null });
108
+ assert.ok(d.disposition, `${surface} produced no disposition`);
109
+ assert.notEqual(d.policySurface, "default", `${surface} fell back to DEFAULT_POLICY`);
110
+ }
111
+ });
112
+
113
+ test("the three extended surfaces decide without falling back to the default row", () => {
114
+ for (const surface of EXTENDED_SURFACE_NAMES) {
115
+ const norm = fromInboxItem(orgItem({ raw_ref: `cohort:${surface}:ent_9:12`, kind: surface }), { me: ME });
116
+ assert.equal(norm.verdict.surface, surface);
117
+ const d = decide({ candidate: norm.candidate, verdict: norm.verdict, me: ME, history: null });
118
+ assert.equal(d.policySurface, surface, `${surface} has no policy row`);
119
+ }
120
+ });
121
+
122
+ // ---------------------------------------------------------------------------
123
+ // org inbox items
124
+ // ---------------------------------------------------------------------------
125
+
126
+ test("an org inbox item reconstructs directed:true and SAYS it reconstructed it", () => {
127
+ const norm = fromInboxItem(orgItem(), { me: ME });
128
+ assert.equal(norm.origin, "inbox_item");
129
+ assert.equal(norm.verdict.directed, true);
130
+ assert.equal(norm.verdict.surface, "mention");
131
+ assert.ok(
132
+ norm.degraded.some((d) => d.startsWith("verdict_reconstructed:")),
133
+ "a reconstructed verdict must be labelled as such, never presented as a resolved one",
134
+ );
135
+ });
136
+
137
+ test("mentions_agent upgrades a lane-tier reason to a structural one", () => {
138
+ const named = fromInboxItem(orgItem({ raw_ref: "cohort:thread_reply:msg_5:7", kind: "thread_reply" }), { me: ME });
139
+ assert.equal(named.verdict.reason, "named", "mentions_agent:true must read as T0");
140
+
141
+ const quiet = fromInboxItem(
142
+ orgItem({
143
+ raw_ref: "cohort:thread_reply:msg_5:7",
144
+ kind: "thread_reply",
145
+ priority_signals: { mentions_agent: false },
146
+ }),
147
+ { me: ME },
148
+ );
149
+ assert.equal(quiet.verdict.reason, "thread", "no mention must stay lane tier");
150
+ });
151
+
152
+ test("a lost raw_ref falls back to kind, and is_dm:false stops a channel item being read as a DM", () => {
153
+ const norm = fromInboxItem(orgItem({ raw_ref: "", kind: "message", is_dm: false }), { me: ME });
154
+ assert.equal(norm.verdict.surface, "mention");
155
+ assert.ok(norm.degraded.includes("surface_inferred_from_kind"));
156
+ });
157
+
158
+ test("an org item whose surface cannot be established is refused, not guessed", () => {
159
+ const norm = fromInboxItem(orgItem({ raw_ref: "", kind: "reaction" }), { me: ME });
160
+ assert.equal(norm.candidate, null);
161
+ assert.equal(norm.verdict.directed, false);
162
+ assert.equal(norm.verdict.reason, "unknown_surface");
163
+ });
164
+
165
+ test("two comments on the same task get different dedupe keys but share a thread", () => {
166
+ const a = fromInboxItem(orgItem({ raw_ref: "cohort:task_comment:task_7:101", kind: "task_comment" }), { me: ME });
167
+ const b = fromInboxItem(orgItem({ raw_ref: "cohort:task_comment:task_7:102", kind: "task_comment" }), { me: ME });
168
+ assert.notEqual(dedupeKey(a.candidate), dedupeKey(b.candidate), "distinct events must not collapse");
169
+ assert.equal(threadKey(a.candidate), threadKey(b.candidate), "one task is one conversation");
170
+ });
171
+
172
+ // ---------------------------------------------------------------------------
173
+ // channel adapters — the negatives
174
+ // ---------------------------------------------------------------------------
175
+
176
+ function slackItem(over = {}) {
177
+ return {
178
+ id: "1699000000.0001",
179
+ service: "slack",
180
+ channel: "general",
181
+ channel_id: "C123",
182
+ sender: "someone",
183
+ sender_id: "U9",
184
+ timestamp: NOW,
185
+ content: "shipping the thing today",
186
+ thread_id: "",
187
+ is_reply: false,
188
+ priority_signals: { mentions_agent: false },
189
+ raw_ref: "slack:C123:1699000000.0001",
190
+ source: "slack",
191
+ ...over,
192
+ };
193
+ }
194
+
195
+ test("NEGATIVE: an ambient Slack channel message is NOT directed", () => {
196
+ const norm = fromChannelEvent(slackItem(), { me: ME });
197
+ assert.equal(norm.verdict.directed, false);
198
+ assert.equal(norm.verdict.reason, "ambient_channel");
199
+ assert.ok(norm.why.join(" ").includes("not directed"));
200
+ });
201
+
202
+ test("NEGATIVE: an ambient channel message is parked, not dropped, because it could have been a mention", () => {
203
+ const norm = fromChannelEvent(slackItem(), { me: ME });
204
+ const d = decide({ candidate: norm.candidate, verdict: norm.verdict, me: ME, history: null });
205
+ assert.equal(d.disposition, "ignore");
206
+ assert.equal(d.ambient, true, "a message that might have been a mention deserves the ambient sweep");
207
+ });
208
+
209
+ test("a Slack DM is directed by construction", () => {
210
+ const norm = fromChannelEvent(slackItem({ is_dm: true, channel_type: "im" }), { me: ME });
211
+ assert.equal(norm.verdict.directed, true);
212
+ assert.equal(norm.verdict.surface, "dm");
213
+ });
214
+
215
+ test("a Slack channel message that names the agent is a mention", () => {
216
+ const norm = fromChannelEvent(slackItem({ priority_signals: { mentions_agent: true } }), { me: ME });
217
+ assert.equal(norm.verdict.surface, "mention");
218
+ assert.equal(norm.verdict.reason, "mention");
219
+ });
220
+
221
+ test("a thread reply on a channel is lane tier, and says membership is unverified", () => {
222
+ const norm = fromChannelEvent(slackItem({ is_reply: true, thread_id: "1699.0" }), { me: ME });
223
+ assert.equal(norm.verdict.surface, "thread_reply");
224
+ assert.ok(norm.degraded.includes("thread_membership_unverified"));
225
+ });
226
+
227
+ test("an org-mail item is email, directed, and keeps its service as the key space", () => {
228
+ const norm = fromChannelEvent(slackItem({ service: "orgmail", content: "quote attached" }), { me: ME });
229
+ assert.equal(norm.verdict.surface, "email");
230
+ assert.equal(norm.verdict.directed, true);
231
+ assert.equal(norm.candidate.family, "orgmail");
232
+ });
233
+
234
+ test("channel and org key spaces never collide", () => {
235
+ const org = fromInboxItem(orgItem({ raw_ref: "cohort:dm:m1:5" }), { me: ME });
236
+ const chan = fromChannelEvent(slackItem({ id: "m1", is_dm: true }), { me: ME });
237
+ assert.notEqual(dedupeKey(org.candidate), dedupeKey(chan.candidate));
238
+ assert.notEqual(threadKey(org.candidate), threadKey(chan.candidate));
239
+ });
240
+
241
+ // ---------------------------------------------------------------------------
242
+ // alerts
243
+ // ---------------------------------------------------------------------------
244
+
245
+ test("a critical alert is directed and decides to queued work", () => {
246
+ const norm = fromAlert({ id: "daemon_down", severity: "critical", detail: "no beat in 40m" }, { me: ME, now: NOW });
247
+ assert.equal(norm.verdict.directed, true);
248
+ assert.equal(norm.verdict.surface, "alert");
249
+ const d = decide({ candidate: norm.candidate, verdict: norm.verdict, me: ME, history: null });
250
+ assert.equal(d.disposition, "schedule", "an alert is work, not conversation");
251
+ });
252
+
253
+ test("NEGATIVE: an info alert never becomes work", () => {
254
+ const norm = fromAlert({ id: "cache_warm", severity: "info", detail: "warmed" }, { me: ME });
255
+ assert.equal(norm.verdict.directed, false);
256
+ assert.equal(norm.verdict.reason, "alert_below_threshold");
257
+ const d = decide({ candidate: norm.candidate, verdict: norm.verdict, me: ME, history: null });
258
+ assert.equal(d.disposition, "ignore");
259
+ });
260
+
261
+ test("repeated firings of one alert collapse onto one thread", () => {
262
+ const a = fromAlert({ id: "disk_low", severity: "warning" }, { me: ME, now: NOW });
263
+ const b = fromAlert({ id: "disk_low", severity: "warning" }, { me: ME, now: "2026-08-11T10:00:00.000Z" });
264
+ assert.equal(threadKey(a.candidate), threadKey(b.candidate), "a flapping check must not become a task storm");
265
+ });
266
+
267
+ // ---------------------------------------------------------------------------
268
+ // raw chain events
269
+ // ---------------------------------------------------------------------------
270
+
271
+ test("a raw chain row is classified and joined through the inbound layer, not a second copy of it", () => {
272
+ const norm = fromRawEvent(
273
+ { seq: 12, family: "escalation", kind: "raised", entity_id: "esc_1", payload: { actor: "mem_peer", waitingOnMemberId: ME } },
274
+ { me: ME },
275
+ );
276
+ assert.equal(norm.origin, "raw_event");
277
+ assert.ok(norm.candidate, "the classifier should have produced a candidate");
278
+ assert.ok(norm.degraded.includes("joined_without_facts"), "a factless join must be labelled");
279
+ });
280
+
281
+ test("NEGATIVE: a family an agent is not woken for produces no candidate and no throw", () => {
282
+ const norm = fromRawEvent({ seq: 1, family: "presence", kind: "beat", payload: {} }, { me: ME });
283
+ assert.equal(norm.candidate, null);
284
+ assert.equal(norm.verdict.directed, false);
285
+ assert.equal(norm.verdict.reason, "not_classified");
286
+ });
287
+
288
+ // ---------------------------------------------------------------------------
289
+ // projected MessageEvents
290
+ // ---------------------------------------------------------------------------
291
+
292
+ test("a projected MessageEvent is lossless — no reconstruction, no degradation", () => {
293
+ const norm = fromMessageEvent(
294
+ {
295
+ message_id: "msg_3",
296
+ channel_id: "chan_2",
297
+ thread_id: "msg_1",
298
+ from: { id: "mem_peer", name: "peer" },
299
+ timestamp: NOW,
300
+ kind: "mention",
301
+ cohort: { surface: "mention", topic: "message", reason: "mention", family: "messaging", event_kind: "send", entity_id: "msg_3", seq: 55, me: ME },
302
+ },
303
+ { me: ME },
304
+ );
305
+ assert.deepEqual(norm.degraded, [], "a full-provenance event needs no guessing");
306
+ assert.equal(norm.verdict.reason, "mention");
307
+ assert.equal(norm.candidate.seq, 55);
308
+ });
309
+
310
+ // ---------------------------------------------------------------------------
311
+ // intake() dispatch + totality
312
+ // ---------------------------------------------------------------------------
313
+
314
+ test("intake routes each shape to the right reader", () => {
315
+ assert.equal(intake({ candidate: { family: "x" }, verdict: { directed: true, surface: "dm" } }).origin, "pair");
316
+ assert.equal(intake({ cohort: { surface: "dm" }, from: {} }).origin, "message_event");
317
+ assert.equal(intake({ id: "a", severity: "critical" }).origin, "alert");
318
+ assert.equal(intake({ family: "board", kind: "assigned", payload: {} }).origin, "raw_event");
319
+ assert.equal(intake(orgItem()).origin, "inbox_item");
320
+ assert.equal(intake(slackItem()).origin, "channel_event");
321
+ });
322
+
323
+ test("intake is TOTAL: no input throws, returns undefined, or silently vanishes", () => {
324
+ for (const bad of [null, undefined, 7, "a string", [], {}, { kind: 5 }, { raw_ref: {} }]) {
325
+ const r = intake(bad, { me: ME });
326
+ assert.ok(r && typeof r === "object", `intake(${JSON.stringify(bad)}) returned nothing`);
327
+ assert.ok(r.verdict, "every result carries a verdict");
328
+ assert.ok(Array.isArray(r.why) && r.why.length > 0, "every result explains itself");
329
+ }
330
+ });
331
+
332
+ test("an unrecognised object is refused with a reason rather than guessed at", () => {
333
+ const r = intake({ some: "thing" }, { me: ME });
334
+ assert.equal(r.verdict.directed, false);
335
+ assert.equal(r.verdict.reason, "unrecognised_shape");
336
+ assert.ok(r.degraded.includes("unrecognised_shape"));
337
+ });
338
+
339
+ test("KIND_SURFACE covers every event kind the channel contract ships", async () => {
340
+ const { EVENT_KINDS } = await import("../channels/contract.mjs");
341
+ const missing = EVENT_KINDS.filter((k) => !["reaction", "channel_cc"].includes(k) && !KIND_SURFACE[k]);
342
+ assert.deepEqual(missing, [], "a shipped event kind with no surface would fall through to the default policy");
343
+ });