@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
@@ -20,25 +20,31 @@ and cross-referenced elsewhere. Start here, then follow the map below.
20
20
  |----------|-------------------------------|
21
21
  | [architecture.md](./architecture.md) *(this file)* | System overview, package structure, core concepts, channels, deployment, observability |
22
22
  | [architecture-fragility.md](./architecture-fragility.md) | Why this system keeps producing fragile bugs, and the structural rules that prevent it |
23
- | [agent-runtime.md](./agent-runtime.md) | Agent lifecycle, execution model, workspace isolation |
23
+ | [agent-runtime.md](./agent-runtime.md) | Agent lifecycle, execution model, workspace isolation; state-ownership contract (Appendix A) |
24
24
  | [cognitive-architecture.md](./cognitive-architecture.md) | Unified cognitive cycle, deterministic context assembly, heartbeat integration |
25
25
  | [memory-system.md](./memory-system.md) | Memory layers (ROLE / knowledge / session / notebook / activity), storage compaction, memory flush |
26
- | [prompt-engineering.md](./prompt-engineering.md) | Prompt & context assembly, LLM call taxonomy, context packing, prompt caching |
26
+ | [prompt-engineering.md](./prompt-engineering.md) | System prompt architecture, LLM call taxonomy, prompt caching, output token resolution |
27
+ | [context-assembly.md](./context-assembly.md) | Message assembly & context compression — token budget, compaction pipeline, ContextOS fixed/variable split |
28
+ | [tool-loop-harness.md](./tool-loop-harness.md) | Tool loop harness + scenario-specific prompt assembly (scenario × context, scenario × tool face) |
27
29
  | [mailbox-system.md](./mailbox-system.md) | Agent mailbox (priority queue) + attention controller (serial focus, interrupts, yield, cancel) |
30
+ | [a2a-communication.md](./a2a-communication.md) | Agent-to-agent communication over the mailbox — channels, delivery facts, reply sink, entry points |
31
+ | [remote-access.md](./remote-access.md) | Remote access — frozen contract v1.0.0 (user-supplied tunnel, Hub as entry/registry/auth gate) |
32
+ | [notification-delivery.md](./notification-delivery.md) | Notification delivery to humans — user/IM notifications and agent→user messages |
28
33
  | [state-machines.md](./state-machines.md) | FSMs for tasks, requirements, callbacks, mailbox items, notebook |
29
- | [state-ownership.md](./state-ownership.md) | State-ownership contract: who owns which state, who may read it, in which execution context |
34
+ | [derived-views.md](./derived-views.md) | The four observation tables (`agent_activities`, `agent_activity_logs`, `execution_stream_logs`, `task_logs`) with their nullable `work_unit_ref`, the single source of "running" (`work_units`), plus thread-stage and inbox derivation |
30
35
  | [concurrent-processing.md](./concurrent-processing.md) | How one agent handles multiple sessions / mailbox items in parallel |
31
36
  | [tool-system.md](./tool-system.md) | Tool selection, tool result envelope, tool-execution loop, subagent spawn & budgets |
32
- | [streaming-and-reattach.md](./streaming-and-reattach.md) | SSE streaming, soft-disconnect, active-stream ring + UI snapshot, reattach, structured events, client resilience |
33
- | [llm-provider-timeouts.md](./llm-provider-timeouts.md) | Per-provider LLM timeout/retry governance matrix, known risk inventory, target design |
37
+ | [streaming-and-reattach.md](./streaming-and-reattach.md) | SSE streaming, soft-disconnect, active-stream ring + UI snapshot, reattach, structured events, client resilience; LLM provider timeout/retry governance lives in [prompt-engineering.md §1.3](./prompt-engineering.md) |
34
38
  | [learning-loop.md](./learning-loop.md) | Agent self-improvement, distillation, memory consolidation |
35
- | [frontend/team-chat.md](./frontend/team-chat.md) | Team Chat page (web-ui): state model and interaction reliability contracts |
39
+ | [messaging-gateway.md](./messaging-gateway.md) | Messaging gateway — bot instances, channel refs, bindings, conversation keys; outbound notification fan-out |
40
+ | [configuration-model.md](./configuration-model.md) | Configuration & file locations — single reference for where each value lives |
41
+ | [team-chat.md](./team-chat.md) | Team Chat page (web-ui): state model and interaction reliability contracts |
36
42
  | [../api/api.md](../api/api.md) | REST / WebSocket API reference |
37
43
  | [../guides/guide.md](../guides/guide.md) | Setup, deployment, and usage guide |
38
44
  | [../guides/coding-tools.md](../guides/coding-tools.md) | External coding CLI integration (Claude Code / Codex / Cursor Agent) |
39
45
  | [../guides/remote-access.md](../guides/remote-access.md) | Remote access configuration |
40
46
  | [../guides/release-and-distribution.md](../guides/release-and-distribution.md) | Release process and distribution |
41
- | [../design/deliverable-sharing.md](../design/deliverable-sharing.md) | Sharing deliverables to Markus Hub |
47
+ | [../records/deliverable-sharing-2026-08-12.md](../records/deliverable-sharing-2026-08-12.md) | Sharing deliverables to Markus Hub — design + as-built (implemented both ends) |
42
48
  | [agent-liveness-redesign.md](../../packages/org-manager/docs/agent-liveness-redesign.md) | Liveness / self-healing audit record (heartbeat-storm root cause + completion state of refactors 1–4); the current design lives in §3.10 below |
43
49
 
44
50
  ### 0.2 Relationship Graph
@@ -205,7 +211,7 @@ Agents now have tools to actively manage their mailbox queue and cognitive works
205
211
 
206
212
  This shifts from system-driven to agent-driven cognition. The deliberation threshold is lowered to 2 items, making agent-driven triage the norm.
207
213
 
208
- **PendingCallbackRegistry** tracks async operations (A2A messages, `background_exec`, etc.). Completions route back through the mailbox as `callback_result` items rather than being injected directly into active sessions.
214
+ **PendingCallbackRegistry** tracks async operations (A2A messages, `background_exec`, etc.). Completions route back through the mailbox as `callback_result` items. If the launching turn is still running, `injectTurnDelta` delivers the full result in-turn and consumes the row; otherwise the row drives a lineage continuation. A result already consumed in-turn (or via `process poll/log`) suppresses the redundant completion turn. Lineage (origin session + scenario + work-unit) is persisted in the registry row itself.
209
215
 
210
216
  External callers use the mailbox API exclusively:
211
217
  - `agent.sendMessage()` — Awaitable chat/notification
@@ -461,7 +467,9 @@ converged the mechanism as follows:
461
467
  timestamp (`recordHeartbeatSkip()`, which never calls the LLM); LLM inspection happens only when
462
468
  state actually changed — fingerprinted by `heartbeatStateFingerprint()` (queue-content signature
463
469
  + activeTaskIds signature). Every heartbeat trigger funnels through `heartbeat:trigger` → the
464
- single handler in `agent.ts` → `mailbox.enqueue('heartbeat')` → single-item coalesced processing.
470
+ single handler in `agent.ts`, which runs the patrol directly (`runHeartbeatPatrol()`); the
471
+ `mailbox.enqueue('heartbeat')` queue-row path is gone — cut 9 made `rest` the only sleep
472
+ entry, so there is no rollback channel back to queue rows.
465
473
  3. **Single safety-net arbiter (Conservator)**: `packages/org-manager/src/agent-conservator.ts`
466
474
  **collapses the dirty / stale / stall verdicts into one component** (as of refactor 4 the
467
475
  decision primitives are inlined and the component is fully self-contained):
@@ -812,7 +820,13 @@ Markus supports multiple human users and agents communicating through various ch
812
820
 
813
821
  ## 9. Heartbeat Tasks
814
822
 
815
- After Agent startup, HeartbeatScheduler triggers periodic tasks at configured intervals:
823
+ A patrol is **not** on a timer. `AgentClock` owns the process's only timers — two sources,
824
+ `mailbox-maintenance` (defer release / lease reclaim / stale cleanup) and `trigger-expiry`
825
+ (`rest(wakeOn)` expiry and scheduled wakeups) — and no heartbeat source is registered on it.
826
+ A patrol runs when the liveness fallback asks for one (`agent.triggerHeartbeat()`, reached
827
+ from the manager / API server dirty-state check); the default resting behaviour is
828
+ `rest(wakeOn)`, and the wake it waits for is delivered as a mailbox `system_event`. When a
829
+ patrol does run:
816
830
 
817
831
  - Each run executes checks with `[HEARTBEAT CHECK-IN]` prompt under the "Patrol, Don't Build" principle
818
832
  - **Active goals check**: injects standing objectives from requirements with `GoalConfig.loopEnabled`
@@ -821,7 +835,7 @@ After Agent startup, HeartbeatScheduler triggers periodic tasks at configured in
821
835
  - **Lightweight actions allowed**: check status, send messages, create tasks, retry failed tasks, quick reviews, save insights
822
836
  - **Complex work goes into tasks**: if something needs heavy implementation, heartbeat creates a task and notifies the user
823
837
  - Infinite loop protection via a configurable tool-iteration safety cap (default 200, `maxToolIterations`), not artificial per-heartbeat limits
824
- - **Background process completions**: `background_exec` results route through `PendingCallbackRegistry` → mailbox `callback_result` items (heartbeat also surfaces timed-out callbacks)
838
+ - **Background process completions**: `background_exec` results route through `PendingCallbackRegistry` → mailbox `callback_result` items (heartbeat also surfaces timed-out callbacks). If the launching turn is still running, `injectTurnDelta` delivers the full result in-turn and consumes the row (no separate completion turn); otherwise the row drives a lineage continuation, and same-origin queued completions coalesce into one turn
825
839
  - **Governance mode**: in_progress tasks are not auto-resumed on service start; requires manual trigger
826
840
 
827
841
  ---
@@ -845,6 +859,11 @@ Agents understand the workflow and governance rules through three layers:
845
859
 
846
860
  ## 11. Observability
847
861
 
862
+ > Persisted observation rows (activity / activity logs / execution stream / task logs)
863
+ > are **history, not state**. "Is this agent working right now" is answered only from
864
+ > `work_units` (`status='running'` + `claimed_by` + `lease_until`). See
865
+ > [derived-views.md](./derived-views.md).
866
+
848
867
  `AgentMetricsCollector` ([`packages/core/src/agent-metrics.ts`](../../packages/core/src/agent-metrics.ts))
849
868
  aggregates per-agent counters (tokens, cost, CU, requests, tool calls, errors, heartbeat
850
869
  success, response time) from the audit callback and event bus, and exposes
@@ -36,6 +36,72 @@ The cycle is **continuous**: heartbeat patrols re-enter the loop, checking activ
36
36
 
37
37
  **Concurrency note.** This five-stage cycle describes the **serial** (single-worker) attention loop. When an agent runs a concurrent worker pool ([concurrent-processing.md](./concurrent-processing.md)), each worker executes a *reduced* loop — Stimulus → Context Assembly → Deliberation → Action → Reflection — and deliberately **skips Triage / Appraisal and interrupt/preempt logic** ("concurrency without interruption", Scheme A). Triage, deliberation-over-queue, preemption and cancellation remain the serial loop's responsibility. Cross-worker consistency is instead handled structurally: an entity-affinity lock in the mailbox plus a `ConcurrentHandoffLog` whose records are injected into each worker's volatile context.
38
38
 
39
+ **What is never skipped: the books.** Recording is not part of deliberation. Both paths converge on `processFocusedItem`, which is the single execution point that writes the `pick` row — so a reduced loop still produces a complete ledger.
40
+
41
+ ### End-to-end turn, with states
42
+
43
+ ```plantuml
44
+ @startuml
45
+ skinparam defaultTextAlignment center
46
+ autonumber
47
+
48
+ title One stimulus → one turn → one terminal state (concurrent path shown)
49
+
50
+ actor "Human / peer / task" as Src
51
+ participant "Mailbox" as MB
52
+ participant "Worker loop" as W
53
+ participant "processFocusedItem" as P
54
+ participant "ContextEngine" as CE
55
+ participant "LLM + tools" as LLM
56
+ database "agent_decisions" as DEC
57
+ database "mailbox_items" as ITEMS
58
+
59
+ Src -> MB : enqueue(type, payload,\nworkUnitRef | refOrigin)
60
+ activate MB
61
+ MB -> MB : **identity gate**
62
+ alt neither ref nor declaration
63
+ MB --> Src : **rejected** + actionable hint
64
+ else declared
65
+ MB -> ITEMS : row status = **queued**
66
+ end
67
+ deactivate MB
68
+
69
+ W -> MB : dequeueAsync()
70
+ MB -> ITEMS : status = **processing**, lease claimed
71
+ W -> MB : lockEntities(entity ∪ session keys)
72
+ alt any key already held
73
+ MB --> W : putBack + backoff\nstatus back to **queued**
74
+ else all keys acquired
75
+ W -> P : processFocusedItem(item)
76
+ activate P
77
+ P -> DEC : **pick** {source: rule, workUnitRef}
78
+ P -> CE : assemble context
79
+ CE --> P : fixed segments + volatile tail
80
+ P -> LLM : run the turn
81
+ loop each turn boundary
82
+ LLM -> P : checkYieldPoint()
83
+ P -> DEC : {type, source: model|heuristic,\noverrode?}
84
+ end
85
+ LLM --> P : reply | end_turn | error
86
+ alt reply or typed end_turn
87
+ P -> ITEMS : status = **completed**
88
+ else abnormal, retries left
89
+ P -> ITEMS : requeue → **queued**
90
+ else retry exhausted / cancelled / orphan
91
+ P -> ITEMS : **bounced** + drop_reason
92
+ end
93
+ deactivate P
94
+ W -> MB : unlockEntities()
95
+ end
96
+
97
+ note over DEC, ITEMS
98
+ Every processed item can now be traced:
99
+ mailbox row → pick row → turn (workUnitRef)
100
+ → who decided (source) → terminal state.
101
+ end note
102
+ @enduml
103
+ ```
104
+
39
105
  ---
40
106
 
41
107
  ## 2. Cognitive Science Foundations
@@ -167,15 +233,119 @@ Three interlocking mechanisms drive agent attention and sustained work:
167
233
  Processes the **Mailbox** — the agent's unified stimulus queue. Responsibilities:
168
234
 
169
235
  - Priority ordering and preemption
170
- - LLM-driven triage (`TriageJudge` + `onTriageCompleted`) and full-session deliberation
171
- - Triage decisions persisted to notebook (`triage-decision`)
172
- - Yields to higher-priority items (e.g., human chat during deliberation)
236
+ - Rule-based preemption only: `heuristicDecision()` in `attention.ts` is a pure rule table
237
+ (same-session follow-up → merge, human chat preempts background, peer message preempts
238
+ background, priority comparison) — deciding whether to interrupt costs **no** model call
239
+ - One `pick` decision per dequeued item; the priority queue alone decides processing order
240
+ - Yields to higher-priority items at turn boundaries (`checkYieldPoint()`), applying the same
241
+ rule table
242
+
243
+ The queue decides **what** to process (priority + enqueue order). How context is prepared for processing is now deterministic (§3), not a second LLM stage.
244
+
245
+ #### Attention states
246
+
247
+ ```plantuml
248
+ @startuml
249
+ skinparam defaultTextAlignment center
250
+ hide empty description
251
+
252
+ title AttentionController — states (per worker in concurrent mode)
253
+
254
+ [*] --> idle
255
+
256
+ idle --> deciding : item dequeued\n(serial path: pre-triage runs here)
257
+ idle --> focused : concurrent worker\nlocks entities, skips triage
258
+
259
+ deciding --> focused : processFocusedItem()\n**records `pick`**
173
260
 
174
- Triage decides **what** to process. How context is prepared for processing is now deterministic (§3), not a second LLM stage.
261
+ focused --> deciding : checkYieldPoint()\nnew mail raised interruptSignal
262
+ focused --> idle : turn finished\nfocus cleared, lease released
263
+
264
+ deciding --> focused : continue / merge\n(back to the same turn)
265
+ focused --> idle : preempt / cancel\n(item requeued or bounced)
266
+
267
+ note right of focused
268
+ Every entry into `focused` leaves a
269
+ `pick` row: processFocusedItem is the
270
+ single recording point for both loops.
271
+ Before 2026-11-18 the concurrent path
272
+ entered this state without recording.
273
+ end note
274
+
275
+ note bottom of deciding
276
+ In concurrent mode this state is not
277
+ used: workers do not deliberate.
278
+ Skipping judgement never skips the books.
279
+ end note
280
+ @enduml
281
+ ```
282
+
283
+ #### Who decided — provenance at a yield point
284
+
285
+ Every ledger row carries `source` (`model` / `heuristic` / `rule` / `user`). A platform
286
+ rule that refuses the model's choice records **one** final row with `overrode` set,
287
+ not two rows nobody can order.
288
+
289
+ ```plantuml
290
+ @startuml
291
+ skinparam defaultTextAlignment center
292
+
293
+ title checkYieldPoint — one decision, with its provenance
294
+
295
+ start
296
+ :turn boundary reached;
297
+ if (user pressed cancel?) then (yes)
298
+ :decision = cancel\nsource = user;
299
+ stop
300
+ endif
301
+ if (interruptSignal and currentFocus?) then (no)
302
+ :decision = continue\n(no ledger row — nothing was decided);
303
+ stop
304
+ endif
305
+
306
+ if (delegate present?) then (yes)
307
+ :evaluateInterrupt()\nsource = **model**;
308
+ else (no)
309
+ :heuristicDecision()\nsource = **heuristic**;
310
+ endif
311
+
312
+ if (delegate threw?) then (yes)
313
+ :heuristicDecision()\nsource = **heuristic**\n(degradation is recorded, not hidden);
314
+ endif
315
+
316
+ if (decision == defer AND isStrictStateItem?) then (yes)
317
+ :overrode = defer\nheuristicDecision()\nsource = **heuristic**;
318
+ else (no)
319
+ endif
320
+
321
+ :formatDecisionReasoning();
322
+ :**recordDecision** — one row\n{type, source, overrode, workUnitRef};
323
+
324
+ switch (decision)
325
+ case (merge)
326
+ :mailbox.merge();
327
+ case (defer)
328
+ :mailbox.defer();
329
+ case (preempt)
330
+ :lastYieldDecision = preempt;
331
+ case (cancel)
332
+ :lastYieldDecision = cancel;
333
+ case (continue)
334
+ endswitch
335
+ stop
336
+ @enduml
337
+ ```
338
+
339
+ Reading the ledger afterwards answers three questions without guesswork: **which turn**
340
+ (`workUnitRef`), **who decided** (`source`), and **what a rule overturned** (`overrode`).
175
341
 
176
342
  ### Heartbeat
177
343
 
178
- Periodic patrol re-enters the cognitive cycle without external stimulus. Each heartbeat checks:
344
+ A patrol re-enters the cognitive cycle without external stimulus. Nothing schedules it on a
345
+ timer: `AgentClock` owns the only timers (two sources, `mailbox-maintenance` and
346
+ `trigger-expiry`), and a patrol runs only when the liveness fallback asks for one
347
+ (`agent.triggerHeartbeat()` from the manager / API server). The resting default is
348
+ `rest(wakeOn)`, whose wake arrives as a mailbox `system_event`. Each patrol checks:
179
349
 
180
350
  - Active goals (Goal/Loop — see below)
181
351
  - Timed-out `PendingCallbackRegistry` entries
@@ -187,23 +357,25 @@ There is no depth ladder anymore — every path, heartbeat included, uses the sa
187
357
 
188
358
  #### Spec: active-hours timezone (C1)
189
359
 
190
- `HeartbeatScheduler` skips ticks outside `config.activeHours`. Previously
191
- `isWithinActiveHours()` used the host machine's local clock (`new Date().getHours()`), which
192
- could disagree with the agent's configured timezone.
360
+ `isWithinActiveHours()` is the policy that says whether a patrol may run inside
361
+ `config.activeHours`. It and `minutesOfDayInTimeZone()` live in
362
+ `packages/core/src/heartbeat.ts` as pure functions; since the periodic scheduler was
363
+ deleted, **no runtime caller gates a tick on them** — there is no tick to gate. The C1 fix
364
+ they carry is the timezone rule: evaluation uses the **configured** timezone rather than the
365
+ host's local clock.
193
366
 
194
367
  - **Behavior**: `activeHours` is evaluated in the **configured timezone** (falling back to
195
368
  host local time only when none is configured or the id is invalid), so an agent set to
196
- `09:00–18:00` patrols during those hours in *its* timezone regardless of where the process
197
- runs.
369
+ `09:00–18:00` is in-window during those hours in *its* timezone regardless of where the
370
+ process runs.
198
371
  - **Invariants**: same-instant evaluation yields the correct in/out-of-window result for a
199
372
  given configured timezone; the start minute is inclusive and the end minute exclusive; the
200
373
  midnight-wrap case (e.g. `22:00–06:00`) still works.
201
- - **Testing** (`packages/core/test/heartbeat.test.ts` — the "C1:" cases): with a fixed
202
- instant (`2026-07-23T12:00:00Z`) and different configured timezones (UTC / Los_Angeles /
203
- Tokyo), assert the active-window decision matches the configured zone, plus the
204
- invalid-timezone fallback and midnight-wrap cases.
374
+ - **Testing**: the two helpers are pure and side-effect-free, so the invariants above are
375
+ directly unit-testable at a fixed instant; the old dedicated heartbeat test file is gone
376
+ along with the scheduler.
205
377
  - **Status**: implemented (pure `isWithinActiveHours` / `minutesOfDayInTimeZone` via
206
- `Intl.DateTimeFormat`; `HeartbeatScheduler.isWithinActiveHours` delegates to them).
378
+ `Intl.DateTimeFormat`), currently unreferenced from production code.
207
379
 
208
380
  > Prompt-cache note: heartbeat situational content (mailbox meta, notebook, timestamps) is
209
381
  > injected in the volatile `[Live context]` tail, never into the byte-stable system prefix — see
@@ -250,6 +422,8 @@ This leverages existing group-chat infrastructure:
250
422
 
251
423
  Async operations (e.g., `background_exec`) register callbacks tracked by `PendingCallbackRegistry`. When complete, results enter the originating agent's mailbox as `callback_result` items — ensuring they flow through the attention loop rather than being injected directly into sessions. Timed-out callbacks surface in heartbeat for investigation.
252
424
 
425
+ The result **belongs to the turn that launched it**. When the completion's `callback_result` row is queued under the launching turn's WorkUnit and that turn is still running, `injectTurnDelta` delivers the FULL result content into the turn before its next LLM call and consumes the row (a tail append — C8-B's ≤600-char label teaser cannot carry kilobytes of stdout), so no separate completion turn fires. If the turn has ended, the row drives a lineage continuation instead. `process poll/log` on a finished session also marks the result consumed, suppressing the redundant turn. Lineage (`originSessionId` + `originScenario` + `workUnitRef`) is persisted in the registry row — the ONE durable store — so a restart cannot orphan a completion from its launching scenario/entity, and same-origin queued completions coalesce into a single turn.
426
+
253
427
  Implementation: `packages/core/src/pending-callback.ts`, persisted via `SqlitePendingCallbackRepo`.
254
428
 
255
429
  ---