@markus-global/cli 0.12.4 → 0.12.5-rc.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 (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 +18520 -9886
  13. package/dist/web-ui/assets/{AsyncState-BTLUPIr1.js → AsyncState-fJJNUOXK.js} +1 -1
  14. package/dist/web-ui/assets/ChatComponents-S7d2CAAU.js +14 -0
  15. package/dist/web-ui/assets/{ContentRenderer-BZXRiKE3.js → ContentRenderer-DWqhC0uq.js} +6 -6
  16. package/dist/web-ui/assets/DeliverableShareModal-B7DwzEnt.js +1 -0
  17. package/dist/web-ui/assets/{Deliverables-3Y3zjT_1.js → Deliverables-CueBYYpx.js} +2 -2
  18. package/dist/web-ui/assets/MarkdownMessage-D8BsJzvD.js +4 -0
  19. package/dist/web-ui/assets/{Search-BI3hk-5j.js → Search-CaYXz3u-.js} +1 -1
  20. package/dist/web-ui/assets/{SendToChat-D_5zHO-k.js → SendToChat-_9sm7UBY.js} +1 -1
  21. package/dist/web-ui/assets/Settings-DTL14pY8.js +8 -0
  22. package/dist/web-ui/assets/{Store-B8ksRjHF.js → Store-DpGqUMS2.js} +1 -1
  23. package/dist/web-ui/assets/Switch-NYQTn8wl.js +1 -0
  24. package/dist/web-ui/assets/Team-DB-JytPl.js +93 -0
  25. package/dist/web-ui/assets/Work-sQq-gy3S.js +142 -0
  26. package/dist/web-ui/assets/{arc-VmvI7TpW.js → arc-JtkmqkSR.js} +1 -1
  27. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-CTUtPasm.js → architectureDiagram-3BPJPVTR-B8zM5fky.js} +1 -1
  28. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-xeYAqtZJ.js → blockDiagram-GPEHLZMM-BQgjaOcE.js} +1 -1
  29. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BiFgoGY5.js → c4Diagram-AAUBKEIU-BnZvYRwj.js} +1 -1
  30. package/dist/web-ui/assets/channel-Zno2q8Ba.js +1 -0
  31. package/dist/web-ui/assets/{chunk-2J33WTMH-DueHBqOn.js → chunk-2J33WTMH-KONx1qvt.js} +1 -1
  32. package/dist/web-ui/assets/{chunk-4BX2VUAB-B8zgDfSV.js → chunk-4BX2VUAB-BqkxAkWs.js} +1 -1
  33. package/dist/web-ui/assets/{chunk-55IACEB6-DieD55CP.js → chunk-55IACEB6-DxLiTj85.js} +1 -1
  34. package/dist/web-ui/assets/{chunk-727SXJPM-Do4Z9LQ0.js → chunk-727SXJPM-Dhj-9NIs.js} +1 -1
  35. package/dist/web-ui/assets/{chunk-AQP2D5EJ-qrYsW5ml.js → chunk-AQP2D5EJ-M1vQ4YYc.js} +1 -1
  36. package/dist/web-ui/assets/{chunk-FMBD7UC4-BSz3QT1q.js → chunk-FMBD7UC4-DaXv58SH.js} +1 -1
  37. package/dist/web-ui/assets/{chunk-ND2GUHAM-utDWSydt.js → chunk-ND2GUHAM-Brkz9FCu.js} +1 -1
  38. package/dist/web-ui/assets/{chunk-QZHKN3VN-Cd86CYHV.js → chunk-QZHKN3VN-DIsEGiBf.js} +1 -1
  39. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-hI59DDUw.js +1 -0
  40. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-hI59DDUw.js +1 -0
  41. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-Dc6cP9WW.js → cose-bilkent-S5V4N54A-CSjC_YL5.js} +1 -1
  42. package/dist/web-ui/assets/{dagre-BM42HDAG-4b0Wf_6D.js → dagre-BM42HDAG-BevSxaQN.js} +1 -1
  43. package/dist/web-ui/assets/{diagram-2AECGRRQ-zS_j1Kf4.js → diagram-2AECGRRQ-CT3Hj8jy.js} +1 -1
  44. package/dist/web-ui/assets/{diagram-5GNKFQAL-CPo-_Ime.js → diagram-5GNKFQAL-CAebHy6q.js} +1 -1
  45. package/dist/web-ui/assets/{diagram-KO2AKTUF-CjHOA4_j.js → diagram-KO2AKTUF-BvRWS7BX.js} +1 -1
  46. package/dist/web-ui/assets/{diagram-LMA3HP47-CalZRF6K.js → diagram-LMA3HP47-gR9HBKc4.js} +1 -1
  47. package/dist/web-ui/assets/{diagram-OG6HWLK6-DnLAhsLX.js → diagram-OG6HWLK6-B5HGsfNo.js} +1 -1
  48. package/dist/web-ui/assets/{docx-preview-uRVPnxwM.js → docx-preview-pRjmDg6F.js} +1 -1
  49. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-L0nzlMSn.js → erDiagram-TEJ5UH35-mrPW01aQ.js} +1 -1
  50. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-Bdc3UwtW.js → flowDiagram-I6XJVG4X-BrZ1G-Tt.js} +1 -1
  51. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CFRmj_qc.js → ganttDiagram-6RSMTGT7-Dq_5mate.js} +1 -1
  52. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-B5hZwcoJ.js → gitGraphDiagram-PVQCEYII-Cb3yTWUy.js} +1 -1
  53. package/dist/web-ui/assets/index-9SXWNIl0.css +1 -0
  54. package/dist/web-ui/assets/index-Bco6UnT7.js +867 -0
  55. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DVT4RgPd.js → infoDiagram-5YYISTIA-CcnNlnvs.js} +1 -1
  56. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-Bf7pvUY_.js → ishikawaDiagram-YF4QCWOH-BqHTPtO1.js} +1 -1
  57. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-NVRjJlnd.js → journeyDiagram-JHISSGLW-DKBB9B-C.js} +1 -1
  58. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Co7BKMut.js → kanban-definition-UN3LZRKU-BVO5tbNl.js} +1 -1
  59. package/dist/web-ui/assets/{mermaid.core-CCf28Hq6.js → mermaid.core-bMoKRCj4.js} +5 -5
  60. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-DepMhVEb.js → mindmap-definition-RKZ34NQL-Bk0lFKmi.js} +1 -1
  61. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-Cq9ANaI0.js → pieDiagram-4H26LBE5-BRPnBLeL.js} +1 -1
  62. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CUY0BWhQ.js → quadrantDiagram-W4KKPZXB-CAqdqT5W.js} +1 -1
  63. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-D9fU5rCm.js → requirementDiagram-4Y6WPE33-Vv5YNzCu.js} +1 -1
  64. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CMHhuSQF.js → sankeyDiagram-5OEKKPKP-Ciq1EgmQ.js} +1 -1
  65. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-Bjx53SID.js → sequenceDiagram-3UESZ5HK-DVRqp161.js} +1 -1
  66. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DVvatKnO.js → stateDiagram-AJRCARHV-zbjDSKA3.js} +1 -1
  67. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C54VSYn7.js +1 -0
  68. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-9I80LG9m.js → timeline-definition-PNZ67QCA-D0hr0d1U.js} +1 -1
  69. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-B82Deutq.js → vennDiagram-CIIHVFJN-CtuZLcPo.js} +1 -1
  70. package/dist/web-ui/assets/{wardley-L42UT6IY-BKXtp57W.js → wardley-L42UT6IY-nP2-eCDJ.js} +1 -1
  71. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DzqTzfYa.js → wardleyDiagram-YWT4CUSO-Dxc7OveP.js} +1 -1
  72. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-TowyDWYu.js → xychartDiagram-2RQKCTM6-Bm2LvPhZ.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-DTB3H_n2.js +0 -12
  139. package/dist/web-ui/assets/DeliverableShareModal-BwZP39nd.js +0 -1
  140. package/dist/web-ui/assets/MarkdownMessage-DVfFMzM9.js +0 -4
  141. package/dist/web-ui/assets/Settings-DTUjLhJY.js +0 -8
  142. package/dist/web-ui/assets/Switch-RmZHA47D.js +0 -1
  143. package/dist/web-ui/assets/Team-BRgI1zM9.js +0 -85
  144. package/dist/web-ui/assets/Work-nah0UYFz.js +0 -142
  145. package/dist/web-ui/assets/channel-s7K3KXLr.js +0 -1
  146. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-B2mHhFY8.js +0 -1
  147. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-B2mHhFY8.js +0 -1
  148. package/dist/web-ui/assets/index-CzHSs0Vd.css +0 -1
  149. package/dist/web-ui/assets/index-TPf50ZeO.js +0 -867
  150. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-92MmE2MZ.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
@@ -0,0 +1,233 @@
1
+ # C10-0B — Pick identity leak: single identity constructor + fixed epoch + daily real-DB audit
2
+
3
+ > **Dated correction (2026-11-22, C10-0G).** Owner ruling: the daily real-DB audit
4
+ > mechanism (§3.5) and the fixed PRODUCT epoch (§3.4's constant + sentinel
5
+ > protocol) do not ship to users. C10-0G deleted the in-process mechanism,
6
+ > localized the epoch to an explicit `--epoch` deployment parameter, and replaced
7
+ > the daily clock with a retireable scheduled task on the Owner's instance
8
+ > (tsk_d4ed5b323793d738c746d719). The single constructor (§3.1–3.3) and the gate
9
+ > closed set remain the permanent net. See
10
+ > docs/records/identity-backlog-disposition-2026-11-22.md §0 and
11
+ > docs/design/c10-external-adapters-plan-2026-11-19.md §0G. Sections below are
12
+ > kept as history, not as instructions.
13
+
14
+ Status: built-pending (this document is the implementation SSOT for card tsk_fcd9cb0fabeeb39e3eaa496a)
15
+ Base: origin/feat/refactor-plan @ 5ea5efd4. Branch: task/c10-0b-pick-identity-leak.
16
+
17
+ ## 1. Phenomenon (measured, real DB, 2026-11-21T14:1xZ / 16:0xZ)
18
+
19
+ `node scripts/identity-audit.mjs` on ~/.markus/data.db: gate 11 = 1120. Post the proposed
20
+ epoch 2026-11-19T06:09:30Z there are 1100 rule `pick` decisions with `work_unit_ref IS NULL`
21
+ vs 71 with identity (~94% leak), still produced today. Breakdown of the 1106 post-epoch
22
+ null-ref picks by joined mailbox source_type: `system_event` 1093, `task_status_update` 12,
23
+ orphan 1. Gates 1/2/5 (25/5/3) are ALL historical rows (latest <= 2026-11-18T08:07Z, pre-0A) —
24
+ not a live leak.
25
+
26
+ Smoking gun: decision `dec_b32c39f9e57698b4efe8f9cf` (2026-11-21T15:59:24.515Z, the pick of
27
+ this card's own approval item) has `work_unit_ref = NULL` while its mailbox row carries
28
+ `task_tsk_fcd9cb0fabeeb39e3eaa496a_r1`.
29
+
30
+ ## 2. Root cause (R1: one fact, two construction points)
31
+
32
+ The ONLY decision writer is `AttentionController.recordDecision`
33
+ (packages/core/src/attention.ts:1796); identity is read at :1822 as
34
+ `workUnitRef: item.workUnitRef ?? null`. The ONLY pick call site is attention.ts:925 inside
35
+ `processFocusedItem` (both serial and concurrent loops pass through it). The decision
36
+ therefore reflects the **in-memory** mailbox item's ref at pick time.
37
+
38
+ Identity reaches the in-memory item by two paths:
39
+
40
+ - **P1 — at enqueue** (`options.workUnitRef`, mailbox.ts:1211/1234 writes memory + DB row
41
+ together): chat (api-server prepareChatTurnWorkUnit:2851), A2A (agent-delivery.ts:257
42
+ ensure BEFORE enqueue, ref passed at :305), task status notifications
43
+ (task-service.ts:3892), requirement/review notifications. These picks have identity.
44
+ - **P2 — post-enqueue, DB-only** (`linkMailboxItem`, sqlite-storage.ts:6053, UPDATE-only):
45
+ the task execution chain. `Agent.sendTaskExecution` (agent.ts:2195) enqueues with
46
+ `refOrigin: 'pending-link'` and NO ref; `onItemEnqueued` fires
47
+ `TaskService.linkExecutionEpoch` (task-service.ts:2760) which ensures the WU and calls
48
+ `units.linkMailboxItem` — writing ONLY the DB column. The in-memory item stays null
49
+ forever, so the pick (which reads memory) is null even though the row has a ref.
50
+ agent-delivery.ts:255 comment already documents this exact hazard ("linkMailboxItem 只写
51
+ DB 列") and solved it for A2A by moving ensure before enqueue. Task chain never got it.
52
+ - **P3 — no identity by design**: `PLATFORM_INTERNAL_SOURCES` (mailbox.ts:427 closed set:
53
+ heartbeat, system_event, session_reply, memory_consolidation, callback_result,
54
+ workflow_update). system_event wake turns (start wake agent.ts:1741, rest-expiry :8884,
55
+ callback mailbox delivery :8610, announcements agent-manager.ts:4426, distillation
56
+ task-service.ts:5786) are 1093/1106 of the leak. They are platform wake signals, not
57
+ decisions about work; no turn WU exists for them.
58
+
59
+ ## 3. Fix (structural — the second construction point must cease to exist)
60
+
61
+ ### 3.1 Task execution identity at enqueue (kills P2)
62
+
63
+ - `Agent.sendTaskExecution` (agent.ts:2150): replace the trailing
64
+ `onItemEnqueued: (item: { id: string }) => void` parameter with `workUnitRef: string`
65
+ (REQUIRED — fail closed; caller builds it with `WORK_UNIT_REF.task(taskId, round)`).
66
+ Enqueue with that ref and `refOrigin: 'entity'`. The C10-0A identityPort
67
+ (mailbox.ts:1242) ensures the WU exists at enqueue.
68
+ - `TaskService.linkExecutionEpoch(itemId, taskId, round)` (task-service.ts:2760) becomes
69
+ `ensureExecutionEpoch(taskId, round): string` — ensure + transition to running, RETURN
70
+ the ref, no link call. Both call sites (main execution ~:2309 with callback at :2554,
71
+ fresh retry ~:6409 with callback at :6499) call it BEFORE `sendTaskExecution` and pass
72
+ the ref as the new trailing argument. Same pattern as A2A (agent-delivery.ts:257).
73
+
74
+ ### 3.2 Delete `linkMailboxItem` and `pending-link` everywhere (grep must reach 0 in src)
75
+
76
+ - packages/storage/src/sqlite-storage.ts:6053 — delete method.
77
+ - packages/org-manager/src/work-unit-service.ts — port interface :43 + method :205.
78
+ - packages/org-manager/src/agent-delivery.ts — port :169 + redundant call :325 (the item
79
+ already carries the ref at enqueue).
80
+ - packages/org-manager/src/api-server.ts — wiring :492 + settle backfill :2804
81
+ (settleChatTurnWorkUnit; chat rows already carry the ref at enqueue — the backfill writes
82
+ the same value, it is redundant).
83
+ - packages/core/src/mailbox.ts:191 — remove `'pending-link'` from the refOrigin union
84
+ (keep 'entity' | 'turn' | 'platform-internal'); update guard message :1274;
85
+ `reEnqueueOnShutdown` :2015 becomes `refOrigin: item.workUnitRef ? 'entity' : undefined`
86
+ (non-internal null-ref requeue now fail-closed via the existing guard; internal sources
87
+ are exempt by the closed set).
88
+ - packages/core/src/agent.ts:2005 / :2055 / :2134 — `refOrigin: options?.workUnitRef ? 'turn' : undefined`
89
+ (a missing ref on a non-internal source is now a rejection, not a dead declaration).
90
+ - Update every test that asserts linking/pending-link behavior to assert the NEW invariant
91
+ (identity present at enqueue, in memory AND DB). No test may keep the old second-writer
92
+ semantics alive.
93
+
94
+ ### 3.3 Internal closed-set sources produce NO decision rows (kills P3, card-sanctioned)
95
+
96
+ Card authorizes the structural option "该 pick 不产生决策行". Platform wake signals are not
97
+ decisions about work and have no turn identity to hang a row on. Enforced at the SINGLE
98
+ writer, not at call sites:
99
+
100
+ - Export `PLATFORM_INTERNAL_SOURCES` from packages/core/src/mailbox.ts.
101
+ - `recordDecision` (attention.ts:1796): if `PLATFORM_INTERNAL_SOURCES.has(item.sourceType)`
102
+ return null — no ledger push, no persistence, no event. Return type becomes
103
+ `AttentionDecision | null`; all callers (attention.ts:374, :925-926, :1519-1522, :1727,
104
+ :1738, :1746) handle null (skip onDecisionMade / downstream use).
105
+ - Gate 11 is NOT relaxed: every persisted decision row must have identity. After 3.1+3.2
106
+ every non-internal item has identity at enqueue, and internal items produce no rows.
107
+
108
+ ### 3.4 Fixed product epoch + real-DB audit alerts only post-epoch (superseded by C10-0G — see the dated correction at the top)
109
+
110
+ - New single source: `packages/shared/src/identity-audit.ts` exporting
111
+ `IDENTITY_FIX_EPOCH` (fixed constant, identical on every instance; NEVER read from
112
+ instance restart time) and `makeIdentityGates({ epoch, predicates })` returning the gate
113
+ list (pure data + SQL strings, no sqlite import). Gates 1/2/5/11 are bounded by the
114
+ epoch (mailbox queued_at / decision created_at >= epoch); gates 3/6-10/12/13 unchanged
115
+ (current-state invariants). The rolling `MARKUS_AUDIT_SINCE` window is DELETED — a fixed
116
+ epoch is the only lower bound (two bounds = two measures of the same fact, R2).
117
+ - Predicate whitelist derives from `FACT_PREDICATES` (shared/src/facts/predicates.ts) —
118
+ the regex file-reader in the script is deleted (one source, not a copy).
119
+ - `scripts/identity-audit.mjs` imports the gates from shared **dist** (CI runs `tsc -b`
120
+ before the self-test step, so dist exists; document the build requirement in the header).
121
+ Self-test keeps seeding every violation and asserting bite + clean-to-zero, and ADDS the
122
+ two-way bite: a pre-epoch violation row must NOT be counted; a post-epoch one MUST be.
123
+ - Epoch VALUE (CTO ruling A, 2026-11-21): `IDENTITY_FIX_EPOCH: string | null = null`
124
+ is an explicit **sentinel** until the fix build goes live. The epoch is DEFINED as
125
+ the start time of the new process running the fix build; the single reading is
126
+ `ps -o lstart` (or the runtime log first line — exactly one, recorded with raw
127
+ output in the disposition record). No preset planned time, no `Date.now()`
128
+ fallback. During the sentinel period the audit reports an independent
129
+ `epoch-unset` state (script exit 2; daily record `state:"epoch-unset"` + alert) —
130
+ never silently green. The finalization commit sets the constant AND the
131
+ `FINAL_EPOCH` marker in `docs/records/identity-backlog-disposition-2026-11-22.md`
132
+ together; `packages/shared/test/identity-audit-epoch.test.ts` bites any divergence
133
+ (presetting a planned time into the constant goes red). Self-test uses an explicit
134
+ fixture epoch, so CI keeps biting regardless of the sentinel.
135
+
136
+ ### 3.5 Daily real-DB audit on the existing AgentClock (no new setInterval) (superseded by C10-0G — mechanism deleted, see the dated correction at the top)
137
+
138
+ - Core port `IdentityAuditPort { runDaily(): void | Promise<void> }` injected via
139
+ AgentOptions (same wiring pattern as workUnitPort, api-server.ts:482 → agent-manager).
140
+ Agent.start() registers a named clock source `identity-audit` (everyMs 24h, staggered
141
+ initial delay) ONLY when the port is wired; absent port = no source (assembly laziness is
142
+ proven by dependency absence).
143
+ - Org-manager implements the port: exclusive-create (flag 'wx') the dated record
144
+ `<markusHome>/records/identity-audit/YYYY-MM-DD.json` — first agent of the day wins,
145
+ others skip (single daily writer, no lock service). Run the gates read-only against the
146
+ real DB, write { date, ranAt, agentId, epoch, dbPath, gates:[{id,name,count}] }, and
147
+ log.error/alert ONLY when a gate count > 0 (all identity gates are epoch-bounded, so
148
+ historical rows cannot alert).
149
+ - Rationale kept: CI self-test proves the gates bite on fixtures; ONLY the real-DB audit
150
+ can catch a live leak like this one — it is the instrument that found it.
151
+
152
+ ## 4. Test plan (red first)
153
+
154
+ 1. core: task-execution-shaped enqueue (task_status_update + intent trigger_execution +
155
+ workUnitRef) → pick decision carries the ref (behavioral, real Mailbox +
156
+ AttentionController + capturing decisionPersistence). RED at base because the base
157
+ sendTaskExecution path enqueues without ref.
158
+ 2. core: internal source (system_event) pick → decisionPersistence.save NOT called, ledger
159
+ empty; non-internal pick → saved with ref. RED at base (base saves null-ref rows).
160
+ 3. core: non-internal enqueue without ref/refOrigin → throws (existing guard, stays).
161
+ 4. structural grep guard: `linkMailboxItem` and `pending-link` absent from packages/*/src
162
+ (0 matches). RED at base.
163
+ 5. org-manager: ensureExecutionEpoch returns the ref and the enqueued item carries it in
164
+ memory AND DB before any pick; no post-enqueue UPDATE of work_unit_ref happens.
165
+ 6. audit self-test: two-way epoch bite (pre-epoch silent, post-epoch alerts) + all gates
166
+ still bite and clean to zero.
167
+ 7. clock source: registered iff port wired; daily runner writes exactly one dated record
168
+ per day (second call same day skips), alerts on post-epoch violation only.
169
+ 8. Falsification: reverting the fix must turn the new tests red (run once, record).
170
+
171
+ ## 5. Boundaries
172
+
173
+ - No data migration, no DROP, no restart of the serving instance (human performs restart).
174
+ - Merge flow per Owner 2026-11-19: review → CTO merge --no-ff into build/c10-integration;
175
+ no per-card PR; exit PR #470.
176
+ - Historical rows (226,983 pre-epoch + the leak rows before the fix goes live) stay
177
+ untouched — the real DB IS the archive; disposition record carries counts + attribution,
178
+ never copied rows.
179
+
180
+ ## 6. Verification evidence (readings, not claims)
181
+
182
+ ### 6.1 Red at base (2026-11-21T16:31Z, base 5ea5efd4 + new tests, before implementation)
183
+
184
+ 7 new tests red across 6 files:
185
+ - guard: `linkMailboxItem` 0-hit FAIL; `pending-link` 0-hit FAIL (detector self-check green).
186
+ - attention-internal-no-decision: system_event pick persisted 1 row (expected 0).
187
+ - identity-audit-clock-source: `agent.setIdentityAuditPort is not a function`.
188
+ - task-execution-identity-at-enqueue: in-memory ref null (expected task_tsk_c10_0b_enqueue_r2).
189
+ - task-execution-epoch-identity (2): `svc.ensureExecutionEpoch is not a function`.
190
+ - identity-audit-runner: module absent (import failure).
191
+ Audit self-test two-way bite red at base: gates 1/2/5 counted pre-epoch history
192
+ (6 assertions failed) — the rolling window had no epoch lower bound.
193
+
194
+ ### 6.2 Green after implementation (2026-11-22T00:5x–01:0x local / 16:5x–17:0xZ)
195
+
196
+ | Check | Reading |
197
+ |---|---|
198
+ | npm run typecheck | exit 0 |
199
+ | npm run lint | exit 0 (0 errors; 1027 pre-existing warnings) |
200
+ | node scripts/architecture-guard.mjs | exit 0, contracts 27/27 |
201
+ | node scripts/security-guard.mjs | exit 0 |
202
+ | node scripts/identity-audit.mjs --self-test | exit 0 — 12 gates bite, silent on pre-epoch history, clean to zero |
203
+ | 7 new suites (epoch/runner/clock/guard/internal/enqueue/epoch-identity) | 19/19 passed |
204
+ | npm run test (full node, post-restore rerun) | 1 failed \| 9041 passed \| 14 skipped (9056) |
205
+ | npm run test:web-ui | 1581 passed \| 3 skipped (1584), exit 0 |
206
+ | grep linkMailboxItem / pending-link in packages/*/src | 0 matches |
207
+
208
+ The single remaining node failure is `packages/cli/test/commands-start-integration.test.ts
209
+ > auto-runs quickInit when config is missing` — **pre-existing environmental**, independently
210
+ confirmed on two cards: quickInit hard-codes port 8056 in nonInteractive mode and does not
211
+ inherit the test's getFreePort; the packaged desktop app holds 8056 on this host. Card
212
+ 0E+0C recorded the same failure on a clean base tree (three-stage evidence, commit 6337f9ac
213
+ delivery report §3); this card's isolated investigation found zero identity/mailbox code in
214
+ that test and an empty cli diff. Not a regression of this change; not silently waived.
215
+
216
+ ### 6.3 Falsification (guard proof, 2026-11-22T01:0xZ)
217
+
218
+ Two probes applied to the finished fix, then reverted:
219
+ - attention.ts recordDecision internal-source early return bypassed (`if (false && …)`);
220
+ - agent.ts sendTaskExecution enqueue `workUnitRef: null`.
221
+ Result: attention-internal-no-decision + task-execution-identity-at-enqueue both RED
222
+ (2 failed | 2 passed). Probes reverted; same files 4/4 GREEN; full-suite rerun above is
223
+ post-restore. No probe text remains in the tree.
224
+
225
+ ### 6.4 Real-DB probe (2026-11-21T17:01:06Z, read-only)
226
+
227
+ `node scripts/identity-audit.mjs` → **exit 2, state: epoch-unset** — the sentinel refuses
228
+ to claim green before the fix build is live (CTO ruling A). The old build is still serving
229
+ and still leaking, as expected until the Owner restart: 7 new null-ref picks since 16:00Z,
230
+ latest 2026-11-21T17:00:15.973Z; total null-ref decision rows 228,094. Post-epoch-zero and
231
+ the two consecutive daily readings are the post-restart closure steps (disposition record
232
+ §5) — they cannot be produced before the restart and were asked of CTO/Owner, never
233
+ self-restarted.
@@ -0,0 +1,182 @@
1
+ # C10-A — Identity columns, envelope slots, slug-ownership enforcement
2
+
3
+ Card: `tsk_80517bb773ae1f41145ba8f3`. SSOT for problem/fix/acceptance:
4
+ `docs/design/c10-external-adapters-plan-2026-11-19.md` §A (frozen field semantics:
5
+ master plan §4.9.6). This document records the implementation decisions and the
6
+ evidence plan; it does not restate the card.
7
+
8
+ Base: `origin/feat/refactor-plan` @ `708d9fa3` (re-read at card start).
9
+ Worktree: `/Users/liuqian/mycode/worktrees/c10-a`, branch `task/c10-a`.
10
+
11
+ ## 1. Measured starting point (2026-11-22 21:44 CST, read-only on `~/.markus/data.db`)
12
+
13
+ - `organizations`: 2 rows — `default` and `user_4941a0558946c8e1f58962cc`, both
14
+ named `My Organization` (the name collision is exactly why slugs must never be
15
+ derived from `name`).
16
+ - `agents`: 240. `channel_bindings`: 1 row, `address IS NULL` (zero live address
17
+ bindings). `status_transitions.entity_type` ∈ {task, requirement, work_unit}.
18
+ - `address_bindings` is a **view** over `channel_bindings` (C6); the base table
19
+ already has `kind TEXT` since its creation (`f91d064a`), but the view does not
20
+ expose it, and `bind()` writes `kind='mail'` — outside the frozen closed set
21
+ `kind ∈ {agent, role, platform}` (master plan §4.9.6).
22
+ - `EnvelopeAuth` (shared `mail.ts`) already exists as a reserved slot with three
23
+ non-null enum fields; §A freezes **four nullable fields** `{spf, dkim, dmarc,
24
+ verified}`. No consumer reads `auth` today (grep: only `mail.ts`).
25
+
26
+ ## 2. Decisions
27
+
28
+ ### D1 — `organizations.org_slug` (nullable column, real consumer)
29
+
30
+ - `ALTER TABLE organizations ADD COLUMN org_slug TEXT` (migrations array) + the
31
+ same column in `SCHEMA_SQL`; partial unique index
32
+ `uq_organizations_org_slug ON organizations(org_slug) WHERE org_slug IS NOT NULL`
33
+ created **after** migrations (never in `SCHEMA_SQL`).
34
+ - **Single derivation point** `registryOrgSlug(orgId) = 'org_' + orgId` (exported
35
+ from `sqlite-storage.ts`). Two callers, one rule: `createOrg` assigns it at
36
+ INSERT (new orgs are never slug-less — §4.9.6 "NOT NULL for new orgs" as a
37
+ write-path discipline, the column itself stays nullable), and a **one-time
38
+ explicit backfill** runs only when this upgrade adds the column
39
+ (`addedColumns.includes('organizations.org_slug')`, same pattern as
40
+ `tasks.status_changed_at`). The backfill is id-based, never name-based; it never
41
+ overwrites a declared value on re-open.
42
+ - **Slug ownership belongs to markus.global; the local DB only mirrors it**
43
+ (revised in C10-E, 2026-11-25). A slug is a *globally unique namespace* — that
44
+ property can only be adjudicated where a global unique index exists, i.e.
45
+ `hub_organizations.slug` on the Hub. The local `declareOrgSlug` write path was
46
+ therefore **removed** instead of being wired up: a local write cannot know whether
47
+ the name is already taken, and `syncHubOrgIdentity` would overwrite it on the next
48
+ login — a control that silently rolls back what the user just did. Local code keeps
49
+ exactly one slug validator (`checkOrgSlug`, shared with `formatAddress`/
50
+ `parseAddress` — no second rule set) and a **read-only** mirror endpoint for the UI.
51
+ `org_<id>` contains `_`, which is not a legal address segment, so the placeholder
52
+ still has to be replaced by a real slug before bind — that replacement now happens
53
+ on the Hub and the value is mirrored down here. Neither path ever reads `name`.
54
+ - `_mapOrg` exposes `orgSlug` (read side).
55
+
56
+ ### D2 — bind-time slug ownership (the consumer that bites)
57
+
58
+ In `SqliteAddressBindingRepo.bind`, after the existing format gate
59
+ (`rejectUnbindable`, unchanged and still shared with `revoke`):
60
+
61
+ 1. `parseAddress(address)` (the single parser) → `orgSlug` segment.
62
+ 2. Read `organizations.org_slug` for `input.orgId`.
63
+ 3. Org missing or slug NULL → `{status:'bounced', detail:'org_slug_unset'}`;
64
+ mismatch → `{status:'bounced', detail:'org_slug_mismatch'}` — both with an
65
+ actionable hint. `reason` stays `unresolved_address` (the existing
66
+ `BounceReason` closed set is **not** extended; precision lives in `detail`,
67
+ exactly like `platform_reserved` / `external_domain`).
68
+ 4. Match → INSERT; the global partial unique index still adjudicates collisions
69
+ (no check-then-insert for uniqueness).
70
+
71
+ `revoke` deliberately does **not** gain the ownership gate: releasing your own
72
+ historical binding must not be locked out by registry state. Two new members in
73
+ `AddressBindRejectDetail` (shared): `org_slug_unset`, `org_slug_mismatch`.
74
+
75
+ ### D3 — `agents.agent_alias` (reserved column, no writer this card)
76
+
77
+ Nullable column + partial unique index
78
+ `uq_agents_org_alias ON agents(org_id, agent_alias) WHERE agent_alias IS NOT NULL`.
79
+ No writer and no bind-time enforcement in this card: the issuance/revocation
80
+ lifecycle (unset = no mail address, change revokes old binding + isolation
81
+ period) needs an issuance tool that does not exist yet; enforcing it at `bind`
82
+ now would kill `bind_address` for all 240 agents before any alias could be
83
+ issued. §A lists the alias lifecycle as a later consumer; the column + constraint
84
+ are this card's seam. `role_slug`: name stays reserved, no table (per §A).
85
+
86
+ ### D4 — `envelope.auth` slot shape
87
+
88
+ `EnvelopeAuth` becomes `{spf, dkim, dmarc: 'pass'|'fail'|'none'|null; verified:
89
+ boolean|null}` — four nullable fields. `buildDeliveryEnvelope` still writes
90
+ `auth: null` (no values until an adapter actually verifies — C10-D);
91
+ `parseEnvelope` passes the slot through unchanged. `auth.verified` is the
92
+ adapter's authentication verdict; it is **not** `fromVerified` (the routing trust
93
+ bit, H1) — two different facts, commented as such.
94
+
95
+ ### D5 — `address_bindings.kind`
96
+
97
+ The view is recreated (`DROP VIEW IF EXISTS` + `CREATE VIEW`) in the
98
+ post-migration transaction so upgraded DBs expose `kind` too — a view holds zero
99
+ rows, so this is non-destructive (the card's no-DROP rule protects data, and no
100
+ table/column is dropped). `bind()` writes `kind='agent'` (frozen closed set;
101
+ zero live address rows, so no existing-row impact). `AddressBindingRow` + `mapRow` expose
102
+ `kind`.
103
+
104
+ ### D6 — `status_transitions.entity_type` gains `address`
105
+
106
+ No schema change (TEXT column). The `entityType` unions of
107
+ `SqliteStatusTransitionRepo.record` / `getByEntity` gain `'address'`; `bind`
108
+ (success, not the idempotent no-op) records `unbound|revoked → bound` and
109
+ `revoke` records `bound → revoked`, through the existing single execution point
110
+ (`record`), `changedByType:'agent'`, `changedById:agentId`.
111
+
112
+ ## 3. Migration discipline
113
+
114
+ DDL + migrations-array entry both; indexes/uniques after migrations; nullable
115
+ only; no observation-log backfill; the only data write is the explicit
116
+ `org_slug` backfill (D1). Fresh-init and upgraded DBs must end with identical
117
+ schema — tested by comparing `sqlite_master` (normalized) + `PRAGMA table_info`
118
+ for the touched tables between a fresh DB and a legacy DB upgraded through
119
+ `openSqlite`.
120
+
121
+ ## 4. Evidence plan (acceptance ↔ proof)
122
+
123
+ | Acceptance | Proof |
124
+ |---|---|
125
+ | fresh vs upgraded schema identical | `c10-a-identity-columns.test.ts` schema-consistency test + real-DB-copy probe readings |
126
+ | ownership check bites | org B binds `x.<orgA-slug>@` → bounced `org_slug_mismatch`; org A binds own slug → bound; **falsification**: delete the gate → tests red, restore → green |
127
+ | no slug derived from name | two same-name orgs get distinct `org_<id>` slugs; `createOrg('Acme Corp')` → `org_<id>`, never a slugified name |
128
+ | two historical orgs assigned | probe on a **copy** of `~/.markus/data.db` (serving DB untouched — the view recreation would break the old build's read path): SELECT readback with timestamp |
129
+ | tests not empty shells | new tests copied back to base commit `708d9fa3` → red at base, green at head |
130
+ | CI-equivalent regression | plan §3.1 layer-2 order: typecheck → lint → architecture-guard → identity-audit --self-test → test:json → test:web-ui → test:skipped-audit (+ security-guard as a labelled local extra). Windows storage matrix **not covered locally**. |
131
+
132
+ Existing `address-bindings.test.ts` fixtures insert orgs without slugs; they are
133
+ updated to declare `org_slug` explicitly (the fixture plays the registry) — the
134
+ ownership gate is a real behavior change and the fixtures must state the org's
135
+ slug, not bypass the gate.
136
+
137
+ ## 5. Boundaries
138
+
139
+ Files: `shared/src/{address,mail}.ts`, `storage/src/{sqlite-storage,types}.ts`,
140
+ their tests, docs. No intersection with C10-0G (audit mechanism files). No data
141
+ migration beyond the explicit backfill, no DROP of tables/columns, no restart of
142
+ the serving instance, no merge to main, no release.
143
+
144
+ ## 6. Evidence (measured 2026-11-22, all times CST)
145
+
146
+ - **Red first** (21:58, base implementation + new tests): 2 files, 23 red / 3 green
147
+ (the 3 green are invariant-behavior assertions: `auth` stays null, builder shape).
148
+ - **Green after implementation** (22:08): `c10-a-identity-columns.test.ts` (20) +
149
+ `c10-a-slots.test.ts` (6) + `address-bindings.test.ts` (26) = **52/52 green**;
150
+ `pnpm typecheck` exit 0.
151
+ - **Falsification A — the gate bites** (22:10): with both ownership branches
152
+ disabled, exactly 3 tests go red (squat → `org_slug_mismatch`, fail-closed →
153
+ `org_slug_unset`, cross-org rebind in the C6 file); gate restored → 52/52 green.
154
+ - **Falsification B — tests are not empty shells** (22:12): the new test files
155
+ copied into a clean base worktree at `708d9fa3` (`/tmp/c10a-base`, own
156
+ `pnpm install` + shared build): **23 red / 3 green** (`checkOrgSlug is not a
157
+ function`, `table organizations has no column named org_slug`) — identical to
158
+ the red-first reading; head is 52/52 green.
159
+ - **Real-data probe** (22:13:24–25, `sqlite3 .backup` copy of `~/.markus/data.db`,
160
+ 13.1 GB; serving DB opened read-only only):
161
+ - before: `org_slug` column absent; after upgrade through the new `openSqlite`:
162
+ `default → org_default`, `user_4941a0558946c8e1f58962cc →
163
+ org_user_4941a0558946c8e1f58962cc` (explicit, id-based; both orgs share the
164
+ display name `My Organization`, so name-derivation is provably not the source).
165
+ - non-destructive: agents 240, work_units 523, mailbox_items 243,322,
166
+ channel_bindings 1, status_transitions 9,550, facts 61, envelope non-empty
167
+ 1,723 — **all identical before/after**; `entity_type='address'` rows = 0
168
+ (migration fabricates no lifecycle history); the legacy routing row unchanged.
169
+ - serving DB after probe: still **no** `org_slug` column (never upgraded in
170
+ place — the view recreation would break the old build's read path).
171
+ - **Schema identity on real data** (22:14:58, probe #2): upgraded copy vs
172
+ fresh-init, logical column shape (name/type/notnull/default/pk, sorted) +
173
+ view/index SQL: **identical, diffs = []**. Probe #1's `false` was a comparison
174
+ artifact (JSON key order = cid order); see the cid note below.
175
+ - **cid-order note**: physical column order legitimately differs between
176
+ fresh-init and ALTER-upgrade for columns present in both `SCHEMA_SQL` and the
177
+ migrations array (pre-existing precedent: `mailbox_items.envelope`,
178
+ `channel_bindings.address`). All read paths are name-based, so the schema
179
+ contract is logical identity — the test and probe compare sorted column shapes,
180
+ never cid order.
181
+ - **CI-equivalent regression**: plan §3.1 layer-2 order, readings in the delivery
182
+ report. Windows storage matrix **not covered locally**.
@@ -0,0 +1,222 @@
1
+ # C10-C — Trust boundary: rebuild the autonomy axis + cross-org policy
2
+
3
+ Date: 2026-11-23 · Branch: `task/c10-c` · Base: `build/c10-adapters` @ 00358c88
4
+ (= 708d9fa3 + 0G cab08bc9 + A 9c91c9ee + B cdf9bca5) · Card: tsk_bcf3988a624bca685574aad8
5
+ SSOT for problem/fix/acceptance: `c10-external-adapters-plan-2026-11-19.md` §C.
6
+ This doc is the construction design + test plan; it does not restate the card.
7
+
8
+ ## 0. Measured preconditions (grep at 00358c88, not from memory)
9
+
10
+ - `maySelfInitiate` = 0 hits; `cross_org_policy`/`crossOrgPolicy` = 0 hits;
11
+ `autonomy-single-consumer.test.ts` absent. #464 (887e6a58) physically deleted the
12
+ predicate + its consumer + witness + test (introduced by #462 cc06f99e). This is a
13
+ REBUILD card, not reuse.
14
+ - `agents.autonomy` column: writers exist (sqlite-storage.ts:155 schema default 'act',
15
+ :974 migration, :1637/:1657 insert, :1719/:1728 updateConfig, :1744 row mapper) but
16
+ ZERO decision readers outside storage. shared `AgentConfig` (types/agent.ts:3) has no
17
+ autonomy field; agent-manager create (:1602) / restore (:2578) drop it. 240/240 live
18
+ agents = 'act' (plan §0.1) ⇒ no behavioral difference today; risk window Owner-accepted.
19
+ - Patrol machinery survives #464: `recordHeartbeatSkip` (agent.ts:10655, sole liveness
20
+ exit, no LLM), `runHeartbeatPatrol` (:10680, clock wrapper + inFlight guard),
21
+ `handleHeartbeat` (:10698). THREE entry paths converge on handleHeartbeat:
22
+ heartbeat:trigger listener (:1495→:1514), triggerHeartbeat api fallback (:8921),
23
+ mailbox 'heartbeat' item case (:3405). ⇒ handleHeartbeat top is the single admission.
24
+ - Settled seam (B, mail.ts:291-293 doc): signal-level ceiling
25
+ `mayExternalSignalDemandAction(fromVerified)` (sole consumer ExternalSourceService.ingest
26
+ :96) is a DIFFERENT fact from the agent-level axis. Two facts, two owners — do not merge,
27
+ do not rebuild B's predicate. C rebuilds the agent-level `maySelfInitiate`.
28
+ - Forged-From rule already structural (comms/external-source.ts:9-10): namespace decided by
29
+ ARRIVAL CHANNEL (webhook/RSS ⇒ external/unverified), never string similarity. ingest
30
+ fromVerified=false always (:94). address.ts:127/:193 dot-count decides bindability only.
31
+ - Global resolution already org-agnostic (storage :6487 comment, findActive :6628, H4).
32
+ ⇒ forged-From + cross-org resolution need PROBES + tests, not new enforcement code.
33
+
34
+ ## 1. Construction A — autonomy axis (one predicate, one consumer, witness)
35
+
36
+ ### A1. shared (packages/shared/src/types/agent.ts)
37
+ - Restore `export type AgentAutonomy = 'observe' | 'act';`
38
+ - Restore `AgentConfig.autonomy?: AgentAutonomy` (optional; storage default 'act' keeps
39
+ historical rows identical — compatible read, no data migration).
40
+ - Restore the ONE predicate, extended so the verified=false→observe ceiling hangs on it
41
+ (no second measure):
42
+ ```ts
43
+ export function maySelfInitiate(
44
+ autonomy: AgentAutonomy | string | undefined,
45
+ ceiling?: AgentAutonomy,
46
+ ): boolean {
47
+ const effective = ceiling === 'observe' ? 'observe' : autonomy;
48
+ return effective !== 'observe';
49
+ }
50
+ ```
51
+ Fail-open to old behavior by design: only 'observe' blocks; undefined/dirty ⇒ act
52
+ (a new field must not stall existing agents). `ceiling='observe'` is the trust cap
53
+ (cross-org unverified input, §2); it is an INPUT to the same predicate, not a second
54
+ permissibility function.
55
+ - Export from packages/shared/src/index.ts (incremental edit).
56
+
57
+ ### A2. declarations witness (packages/shared/src/declarations.ts)
58
+ - Re-register `'agent.autonomyLevel'` (kind 'param', declaredAt
59
+ 'packages/shared/src/types/agent.ts:AgentConfig', witness {type:'reader',
60
+ at:'maySelfInitiate'}, note: default 'act', one consumer). Restore the original entry.
61
+
62
+ ### A3. core single consumer (packages/core/src/agent.ts)
63
+ - At the TOP of `handleHeartbeat` (:10698), before any LLM/patrol work:
64
+ ```ts
65
+ if (!maySelfInitiate(this.config.autonomy, this.selfInitiationCeiling())) {
66
+ this.recordHeartbeatSkip('Heartbeat', 'autonomy=observe — self-initiated patrol disabled');
67
+ return;
68
+ }
69
+ ```
70
+ Must go through recordHeartbeatSkip (writes last_heartbeat + metrics), NOT a bare
71
+ return — an observe agent must still report liveness or it looks dead in the UI
72
+ (the deleted code's load-bearing comment).
73
+ - `selfInitiationCeiling()` derives the trust ceiling from cross-org policy (§2 consumer).
74
+ For platform-internal patrol with no unverified cross-org pending input ⇒ undefined
75
+ (no cap) ⇒ act agents patrol unchanged.
76
+ - This is the ONLY call site of maySelfInitiate in packages/*/src.
77
+
78
+ ### A4. autonomy threading (packages/core/src/agent-manager.ts)
79
+ - createAgent path (~:1602): `autonomy: request.autonomy ?? 'act'` into AgentConfig.
80
+ - restoreAgent path (~:2578): `autonomy: row.autonomy ?? 'act'` (storage row mapper
81
+ already returns it). Mirror the heartbeatIntervalMs threading exactly.
82
+ - Add autonomy to the create request type + restore row type as needed.
83
+
84
+ ## 2. Construction B — cross_org_policy + the verified=false ceiling
85
+
86
+ ### 2.0 Measured seam (decides the ceiling's scope)
87
+ - a2a delivery (org-manager/agent-delivery.ts:306) passes only `from: agentAddressRef(...)`;
88
+ mailbox.ts:1207 defaults `fromVerified ?? false`. So EVERY a2a item carries
89
+ fromVerified=false today. Per C10-A's frozen semantics (mail.ts:144) the bit is only
90
+ meaningful for kind='external'; for kind='agent' identity IS the platform-built id.
91
+ ⇒ A naive "any fromVerified=false caps patrol" rule would stop every agent with queued
92
+ a2a mail — a live-traffic regression, not a trust boundary. REJECTED.
93
+
94
+ - SUPERSEDED (A, Owner ruling 2026-11-25) — the earlier B/C division of labor said
95
+ "external_signal is demand-capped at ingest (intent→deliver), so it does NOT feed
96
+ C's ceiling". That lever was wrong: erasing the intent silenced the EVENT instead
97
+ of capping the SENDER, so an external signal could never reach a decision turn at
98
+ all. A splits the two facts:
99
+ · owing a turn is the PLATFORM's call — every external event gets
100
+ intent=action_required at the single ingest point, and routeMailboxItem
101
+ upgrades invokesLLM from it (upgrade-only, M0);
102
+ · sender authority is capped at the AGENT level — an unverified external origin
103
+ now DOES feed selfInitiationCeiling. It has no agent row and no org, so it
104
+ reaches the port as its own structural flag (`unverifiedExternal`), never
105
+ smuggled into senderAgentIds where a lookup would resolve it to nothing and
106
+ silently grant it more trust than a known cross-org peer.
107
+ A verified sender may still escalate to trigger_execution; an unverified one may
108
+ not (identity-audit criterion 14 now bites exactly that, and no longer bites
109
+ action_required — same field, different meaning under A).
110
+ Lesson worth keeping: when a ceiling is enforced by deleting the input, the
111
+ ceiling and the silencing become indistinguishable. Cap the actor, not the event.
112
+ - RULING (documented for CTO review — review is the adjudication point, as with B2):
113
+ the verified=false→observe ceiling at the AGENT level applies to **cross-org agent
114
+ mail**: queued item with envelope.from.kind='agent' AND fromVerified===false AND
115
+ sender's org ≠ receiver's org, while receiver org's cross_org_policy ≠ 'auto'.
116
+ Same-org a2a (platform-built identity) and IM human chat (B2 semantics) are untouched.
117
+ Today: single-org serving instance ⇒ zero behavioral change; the boundary becomes
118
+ real and probe-testable with two local orgs.
119
+
120
+ ### 2.1 Storage (packages/storage/src/sqlite-storage.ts)
121
+ - organizations: add `cross_org_policy TEXT NOT NULL DEFAULT 'observe'` to SCHEMA_SQL
122
+ (:112 block) AND the migration array (dual-write, fresh==upgraded logical shape;
123
+ mirror the autonomy-column migration at :974). No data migration, no DROP.
124
+ - `_mapOrg` (:1628): `crossOrgPolicy: (r['cross_org_policy'] as string|null) ?? 'observe'`.
125
+ - SqliteOrgRepo (:1524): single writer `setCrossOrgPolicy(orgId, policy)` (UPDATE only;
126
+ createOrg keeps the column default — 'observe' is never written by hand at creation).
127
+
128
+ ### 2.2 Human-approved elevation (org-manager)
129
+ - org-service: `setCrossOrgPolicy(orgId, policy, actorUserId)` — validates the actor is
130
+ a HUMAN user row (userRepo.findById), refuses otherwise (agent ids / missing actor
131
+ throw). On success writes the policy AND one audit row via SqliteAuditRepo
132
+ (audit_logs :594; event_type 'cross_org_policy_changed', user_id=actor,
133
+ details={orgId, from, to}). Elevation without a human approval row is structurally
134
+ refused at the service, not only at the HTTP edge.
135
+ - api-server: `POST /api/orgs/:orgId/cross-org-policy` behind requireAuth (human JWT;
136
+ agents have no JWT path) + role owner/admin. 401 unauthenticated, 403 non-human/
137
+ insufficient role, 200 + audit row on success. Mirror an existing org mutation route.
138
+
139
+ ### 2.3 Ceiling wiring (one port, one consumer, same predicate)
140
+ - shared: `type CrossOrgPolicy = 'observe' | 'auto'` (exported).
141
+ - core Agent: `setTrustBoundaryPort(port)` where port =
142
+ `{ selfInitiationCeiling(senderAgentIds: string[]): AgentAutonomy | undefined }`.
143
+ Agent-side derivation (INPUT, not a decision): collect from.kind='agent' &&
144
+ fromVerified===false senders of queued items → ask port. Port absent ⇒ undefined
145
+ (single-org/embedded deployments have no cross-org knowledge; documented fail-open
146
+ consistent with the axis's fail-open default — the axis itself still bites).
147
+ - org-manager/storage-bridge implements the port: sender org ≠ receiver org AND
148
+ receiver org crossOrgPolicy ≠ 'auto' ⇒ 'observe', else undefined.
149
+ - agent-manager: applyTrustBoundaryPort on BOTH creation paths (mirror
150
+ applyFactsCapability:3814); autonomy threaded per §A4.
151
+ - The ONLY place the ceiling can affect behavior is the maySelfInitiate call in §A3.
152
+ No per-adapter guard, no second permissibility function.
153
+
154
+ ## 3. Probes (second instance, HOME redirect; serving DB untouched)
155
+ - P1 observe/act behavior: disposable agent autonomy='observe' → heartbeat trigger →
156
+ skip activity + last_heartbeat refreshed, no LLM patrol; 'act' twin → patrol runs.
157
+ - P2 forged From: webhook POST from='cto.<slug>@markus.global' requesting
158
+ trigger_execution → stored envelope kind='external', fromVerified=false, intent
159
+ capped 'deliver' (B's ceiling) — string similarity never decides identity.
160
+ - P3 cross-org resolution + ceiling: two local orgs; org-B agent binds address; org-A
161
+ agent delivers → global resolution lands the item; while it is queued unverified,
162
+ org-B agent's self-initiated patrol is capped (skip); human elevates policy → audit
163
+ row → patrol resumes. Readings with timestamps.
164
+ - P4 elevation auth: no token → 401; non-owner → 403; owner → 200 + audit_logs row.
165
+ - L5 strengthened (B2/C gate): stranger resource self-binds in one conversation →
166
+ real webhook signal arrives → agent consumes and proposes next step while the
167
+ trust boundary holds (no autonomous action demanded by the unverified signal).
168
+
169
+ ## 4. Tests + falsification (red first, then implement)
170
+ - shared: predicate truth table (observe blocks; act/undefined/dirty pass; ceiling
171
+ 'observe' caps act); single-consumer guard (a second call site in packages/*/src →
172
+ red); witness registry entry present (declarations-witness greps maySelfInitiate).
173
+ - core behavior: observe agent heartbeat → recordHeartbeatSkip path, no patrol LLM;
174
+ act agent → patrol; cross-org unverified queued item + policy observe → capped;
175
+ policy auto → not capped; same-org a2a / external_signal / im items → NOT capped.
176
+ - storage: fresh + upgraded DB both default 'observe'; setCrossOrgPolicy round-trip.
177
+ - org-manager: elevation without human actor refused; with human → policy + audit row;
178
+ API 401/403/200 matrix.
179
+ - Falsification trio (each: seed → RED observed → revert → GREEN):
180
+ F1 seed a second maySelfInitiate call site → guard red;
181
+ F2 remove the admission consumer (bare return) → behavior test red;
182
+ F3 bypass the human check in setCrossOrgPolicy → elevation test red.
183
+ - Non-empty-shell: new tests copied onto clean base 00358c88 → red; this tree → green.
184
+
185
+ ## 5. Boundaries
186
+ - No data migration, no DROP, no serving-instance restart, no merge to main, no publish.
187
+ - Do NOT touch Feishu inbound dispatch files (B2 territory, already landed a25cd735).
188
+ - Do NOT rebuild or modify B's signal-level predicate (two facts, two owners).
189
+ - Envelope shape (C10-A frozen) unchanged; no new envelope fields.
190
+ - packages/*/src/index.ts: incremental edits only.
191
+
192
+ ## 6. Verification gates (CI order, exit codes not step names)
193
+ typecheck → lint → architecture-guard → identity-audit --self-test → test:json →
194
+ test:web-ui → test:skipped-audit; security-guard extra local run. Known pre-existing
195
+ red: quickInit-8056 port collision (dual-card precedent); any NEW red is mine to fix.
196
+
197
+ ## 7. Built status (landing note)
198
+
199
+ Built: YES — this commit on task/c10-c (base 00358c88).
200
+ - Construction A + B landed as designed above. agent-manager.ts changes are pure
201
+ additions (autonomy threading on create/restore + setTrustBoundaryPort); agent
202
+ registration / getAgent / listAgents are untouched.
203
+ - Tests: 28 new (shared 8 / core 6 / storage 4 / org-manager 10), red-first on base.
204
+ Falsification trio F1/F2/F3 each seeded → RED observed → reverted → GREEN.
205
+ Non-empty-shell: the new tests copied onto clean base 00358c88 → 26 red; this
206
+ tree → 28 green.
207
+ - CI (exit codes measured): typecheck / lint / architecture-guard / identity-audit
208
+ --self-test / security-guard = 0. test:json = 7634 passed | 11 skipped | 1 red,
209
+ the red being quickInit-8056 EADDRINUSE (pre-existing: the serving instance holds
210
+ :8056 — lsof PID 28013 — and this card touches zero cli files). test:web-ui =
211
+ 1591 passed | 3 skipped. test:skipped-audit = 0 (7646 total, 11 registered skips).
212
+ - Probes (second instance, HOME redirect, serving DB untouched): P2 forged From →
213
+ envelope kind=external, fromVerified=false, intent capped deliver, external
214
+ work_unit_ref (real machine). P4 elevation 401/403/200/200/400 + one audit row per
215
+ change (real machine). P3 cross-org a2a delivery envelope + elevation observe→auto
216
+ audit (real machine). P1 observe/act + P3 ceiling skip/resume behavior is evidenced
217
+ by the real-code behavior tests driving handleHeartbeat admission directly; the
218
+ HTTP heartbeat-trigger probe could not read created agents in the probe boot path
219
+ (getAgent reads the in-memory map while the list route merges DB rows) — a probe
220
+ instance characteristic orthogonal to this card's pure-additions diff.
221
+ - §2.0 RULING (ceiling scope = cross-org agent mail only; same-org a2a / IM untouched)
222
+ is the adjudication point for CTO review, as with B2.