@markus-global/cli 0.11.2-rc.0 → 0.11.3-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/start.js +5 -2
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +1260 -1125
- package/dist/web-ui/assets/{CommentInput-Cqi5Hldw.js → CommentInput-C-niUbUY.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-BAB3il9e.js → ContentRenderer-DxsnJJRX.js} +2 -2
- package/dist/web-ui/assets/{DeliverableShareModal-DJXkM66x.js → DeliverableShareModal-DV3TiZx0.js} +1 -1
- package/dist/web-ui/assets/{Deliverables-zKPxgZAN.js → Deliverables-tlLsJnxZ.js} +1 -1
- package/dist/web-ui/assets/{Notifications-HAycgg2x.js → Notifications-4KXYRdkr.js} +1 -1
- package/dist/web-ui/assets/{Search-SZuDcxy0.js → Search-CPFwZv1U.js} +1 -1
- package/dist/web-ui/assets/{Settings-CZgNsYSC.js → Settings-DIa-_qre.js} +6 -6
- package/dist/web-ui/assets/{Store-BS7VNrsr.js → Store-JWjwXfTU.js} +1 -1
- package/dist/web-ui/assets/Team-COBxn96h.js +84 -0
- package/dist/web-ui/assets/{Work-BN-LsW3k.js → Work-BScJUqWL.js} +1 -1
- package/dist/web-ui/assets/{arc-CsnWE2QW.js → arc-DPZmpo1U.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-CLek8I2z.js → architectureDiagram-3BPJPVTR-DlOs02JO.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-jSgWEHN7.js → blockDiagram-GPEHLZMM-C7qsXNUe.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BaC188UT.js → c4Diagram-AAUBKEIU-Drwp-rtM.js} +1 -1
- package/dist/web-ui/assets/channel-DCChB-1T.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-CdtP4-T4.js → chunk-2J33WTMH-VgR09Mqk.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-BSgBKyC9.js → chunk-4BX2VUAB-CuwDpBRL.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-XB_ZMqfw.js → chunk-55IACEB6-nC7YWJ_i.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-YFPBFW4M.js → chunk-727SXJPM-Dw6mBsRE.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-CDbFN1Un.js → chunk-AQP2D5EJ-CPhNJbHl.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-BGKt8xP8.js → chunk-FMBD7UC4-AyhQakG8.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-DKicpX2b.js → chunk-ND2GUHAM-DgYemv8I.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-BD4tv8RZ.js → chunk-QZHKN3VN-CLdqxrFB.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CrNiYfSI.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CrNiYfSI.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-BjOoIarG.js → cose-bilkent-S5V4N54A-DrOgwDIH.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-BWal5GOH.js → dagre-BM42HDAG-DhoJiA83.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-CJj-CzRg.js → diagram-2AECGRRQ-BDILSgqK.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-4IMjuEPm.js → diagram-5GNKFQAL-CeXywd1i.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-DQiRAfss.js → diagram-KO2AKTUF-Bi4RlMT0.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-BMPvbEbY.js → diagram-LMA3HP47-Cw1yxk8b.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-D5_vmdXl.js → diagram-OG6HWLK6-Bl857da2.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-Cdouj_6e.js → docx-preview-CjoUhrMq.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-DOnDuvXd.js → erDiagram-TEJ5UH35-DEiaMhuV.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-DL6G76eC.js → flowDiagram-I6XJVG4X-BgKZhO0h.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CwHnuRR8.js → ganttDiagram-6RSMTGT7-Dkx-EaS8.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-BFUnsmW_.js → gitGraphDiagram-PVQCEYII-DXaQwA0y.js} +1 -1
- package/dist/web-ui/assets/{index-BSktaJwx.js → index-C_QhfMcC.js} +74 -74
- package/dist/web-ui/assets/index-DEN_qReg.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DhU1bQNw.js → infoDiagram-5YYISTIA-Dpx9IOkx.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-o6ujfUJF.js → ishikawaDiagram-YF4QCWOH-BWqWgitQ.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-Dx_SZ8zv.js → journeyDiagram-JHISSGLW-BBwIZ4k9.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-D4BWXcIn.js → kanban-definition-UN3LZRKU-C_MRWV8R.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-BHDulYyB.js → mermaid.core-BMAh3nnq.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BVy6py_h.js → mindmap-definition-RKZ34NQL-B6vJQcat.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CUr5__J1.js → pieDiagram-4H26LBE5-BxdEttqt.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-C5Owt_r4.js → quadrantDiagram-W4KKPZXB-gsNs2VfP.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-Bb933lBb.js → requirementDiagram-4Y6WPE33-BSC9KvC2.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CJq-boMJ.js → sankeyDiagram-5OEKKPKP-DktAZfe_.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-BP8L47v3.js → sequenceDiagram-3UESZ5HK-BIPt8kGU.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-Byk9-Yrm.js → stateDiagram-AJRCARHV-DiXmJWB0.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-COOgTXIX.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-2z8RR-l_.js → timeline-definition-PNZ67QCA-LRi7H35g.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-CSwDDhHv.js → vennDiagram-CIIHVFJN-DWQ1I022.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-DW30MdHd.js → wardley-L42UT6IY-BUb6dYqN.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DUb2r21l.js → wardleyDiagram-YWT4CUSO-BYE1B3xT.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-4DTcVUL8.js → xychartDiagram-2RQKCTM6-D-pS2-Sa.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +93 -0
- package/docs/api/api.md +353 -0
- package/docs/architecture/agent-runtime.md +341 -0
- package/docs/architecture/architecture-fragility.md +184 -0
- package/docs/architecture/architecture.md +938 -0
- package/docs/architecture/cognitive-architecture.md +322 -0
- package/docs/architecture/concurrent-processing.md +550 -0
- package/docs/architecture/frontend/team-chat.md +312 -0
- package/docs/architecture/learning-loop.md +340 -0
- package/docs/architecture/llm-provider-timeouts.md +60 -0
- package/docs/architecture/mailbox-system.md +1635 -0
- package/docs/architecture/memory-system.md +533 -0
- package/docs/architecture/prompt-engineering.md +1377 -0
- package/docs/architecture/state-machines.md +665 -0
- package/docs/architecture/state-ownership.md +83 -0
- package/docs/architecture/streaming-and-reattach.md +193 -0
- package/docs/architecture/tool-system.md +266 -0
- package/docs/design/deliverable-sharing.md +238 -0
- package/docs/guides/coding-tools.md +765 -0
- package/docs/guides/community.md +104 -0
- package/docs/guides/development.md +179 -0
- package/docs/guides/guide.md +362 -0
- package/docs/guides/release-and-distribution.md +165 -0
- package/docs/guides/remote-access.md +286 -0
- package/docs/guides/skill-ecosystem.md +129 -0
- package/docs/records/agent-platform-friction-2026-10.md +98 -0
- package/docs/records/animation-budget-focus-vs-visibility-2026-10-08.md +110 -0
- package/docs/records/audit-fixes-2026-09.md +173 -0
- package/docs/records/branch-consolidation.md +597 -0
- package/docs/records/file-edit-literal-replacement-fix.md +132 -0
- package/docs/records/message-stop-cancel-fix-plan.md +209 -0
- package/docs/records/platform-hardening-2026-10.md +1365 -0
- package/docs/records/session-identity-plan.md +130 -0
- package/docs/records/settings-model-routing-first-visit-fix.md +101 -0
- package/docs/records/team-chat-stream-transport-vs-turn-2026-10-08.md +152 -0
- package/package.json +2 -1
- package/templates/roles/HANDBOOK.md +12 -7
- package/dist/web-ui/assets/Team-B6vw2Oj5.js +0 -84
- package/dist/web-ui/assets/channel-CqbBz9iL.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DDQJP38f.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DDQJP38f.js +0 -1
- package/dist/web-ui/assets/index-3PQIqBtv.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CWa-Q2Gf.js +0 -1
|
@@ -0,0 +1,938 @@
|
|
|
1
|
+
# Markus -- Technical Architecture
|
|
2
|
+
|
|
3
|
+
> Last updated: 2026-07
|
|
4
|
+
|
|
5
|
+
This is the **entry point** for Markus technical documentation. Each domain has one
|
|
6
|
+
authoritative document; a mechanism is described in full only in its home document
|
|
7
|
+
and cross-referenced elsewhere. Start here, then follow the map below.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 0. Documentation Map
|
|
12
|
+
|
|
13
|
+
### 0.1 Document Index
|
|
14
|
+
|
|
15
|
+
> **The full, categorised index is [`docs/README.md`](../README.md).** The table below lists only this
|
|
16
|
+
> document's home folder (`docs/architecture/`) plus its immediate neighbours; see the index for
|
|
17
|
+
> `guides/`, `api/`, `design/` and `records/`.
|
|
18
|
+
|
|
19
|
+
| Document | Domain (single responsibility) |
|
|
20
|
+
|----------|-------------------------------|
|
|
21
|
+
| [architecture.md](./architecture.md) *(this file)* | System overview, package structure, core concepts, channels, deployment, observability |
|
|
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 |
|
|
24
|
+
| [cognitive-architecture.md](./cognitive-architecture.md) | Unified cognitive cycle, deterministic context assembly, heartbeat integration |
|
|
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 |
|
|
27
|
+
| [mailbox-system.md](./mailbox-system.md) | Agent mailbox (priority queue) + attention controller (serial focus, interrupts, yield, cancel) |
|
|
28
|
+
| [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 |
|
|
30
|
+
| [concurrent-processing.md](./concurrent-processing.md) | How one agent handles multiple sessions / mailbox items in parallel |
|
|
31
|
+
| [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 |
|
|
34
|
+
| [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 |
|
|
36
|
+
| [../api/api.md](../api/api.md) | REST / WebSocket API reference |
|
|
37
|
+
| [../guides/guide.md](../guides/guide.md) | Setup, deployment, and usage guide |
|
|
38
|
+
| [../guides/coding-tools.md](../guides/coding-tools.md) | External coding CLI integration (Claude Code / Codex / Cursor Agent) |
|
|
39
|
+
| [../guides/remote-access.md](../guides/remote-access.md) | Remote access configuration |
|
|
40
|
+
| [../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 |
|
|
42
|
+
| [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
|
+
|
|
44
|
+
### 0.2 Relationship Graph
|
|
45
|
+
|
|
46
|
+
```mermaid
|
|
47
|
+
flowchart TD
|
|
48
|
+
ARCH[ARCHITECTURE - entry point]
|
|
49
|
+
|
|
50
|
+
subgraph cognition [Cognition]
|
|
51
|
+
COG[COGNITIVE-ARCHITECTURE]
|
|
52
|
+
MEM[MEMORY-SYSTEM]
|
|
53
|
+
PROMPT[PROMPT-ENGINEERING]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
subgraph execution [Execution]
|
|
57
|
+
MAILBOX[MAILBOX-SYSTEM]
|
|
58
|
+
FSM[STATE-MACHINES]
|
|
59
|
+
TOOLS[TOOL-SYSTEM]
|
|
60
|
+
STREAM[STREAMING-AND-REATTACH]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
subgraph integration [Integration and Reference]
|
|
64
|
+
CODING[CODING-TOOLS]
|
|
65
|
+
API[API]
|
|
66
|
+
GUIDE[GUIDE]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
ARCH --> cognition
|
|
70
|
+
ARCH --> execution
|
|
71
|
+
ARCH --> integration
|
|
72
|
+
|
|
73
|
+
MAILBOX -->|item terminal states| FSM
|
|
74
|
+
MAILBOX -->|preempt aborts stream| STREAM
|
|
75
|
+
COG -->|context assembly| PROMPT
|
|
76
|
+
PROMPT -->|packing triggers flush| MEM
|
|
77
|
+
PROMPT -->|tool defs and results| TOOLS
|
|
78
|
+
TOOLS -->|tool errors surfaced as events| STREAM
|
|
79
|
+
PROMPT -->|deterministic bounded recall| MEM
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 0.3 Cross-Document Conventions
|
|
83
|
+
|
|
84
|
+
- **Single source of truth**: a mechanism is fully specified only in its home document.
|
|
85
|
+
- **Spec sections**: feature specs follow a fixed template — Behavior / Invariants /
|
|
86
|
+
Design rationale (with Pi/Hermes comparison where relevant) / Testing (required
|
|
87
|
+
cases + test files) / Status (planned | implemented).
|
|
88
|
+
- **Doc/code accuracy**: documented behavior must match the code. When they diverge,
|
|
89
|
+
fix the code or the doc in the same change; never leave a documented-but-unimplemented
|
|
90
|
+
behavior unmarked.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 1. Overview
|
|
95
|
+
|
|
96
|
+
Markus is an **AI Digital Workforce Platform** that lets organizations hire, manage, and coordinate multiple AI Agents that work proactively like real employees. The platform provides a full governance framework including project management, task approval, workspace isolation, formal delivery review, knowledge sharing, and periodic reporting.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
100
|
+
│ Web UI (React) │
|
|
101
|
+
│ Chat · Agents · Tasks · Team · Dashboard · Settings │
|
|
102
|
+
│ Governance · Projects · Knowledge · Reports │
|
|
103
|
+
└──────────────────────────┬──────────────────────────────────────┘
|
|
104
|
+
│ HTTP + WebSocket
|
|
105
|
+
┌──────────────────────────▼──────────────────────────────────────┐
|
|
106
|
+
│ API Server (Node.js) │
|
|
107
|
+
│ REST API · WebSocket · Auth (JWT) · Static file serve │
|
|
108
|
+
└──┬──────────┬──────────┬──────────┬──────────┬─────────────────┘
|
|
109
|
+
│ │ │ │ │
|
|
110
|
+
┌──▼────┐ ┌──▼─────┐ ┌──▼──────┐ ┌▼───────┐ ┌▼────────────────┐
|
|
111
|
+
│OrgSvc │ │TaskSvc │ │AgentMgr │ │Project │ │Governance Layer │
|
|
112
|
+
│Org │ │Tasks │ │Agent │ │Service │ │Report·Deliver │
|
|
113
|
+
│Mgmt │ │+ Approve│ │Lifecycle│ │Reqs │ │Trust·Archive │
|
|
114
|
+
└──┬────┘ └──┬─────┘ └──┬──────┘ └┬───────┘ └┬────────────────┘
|
|
115
|
+
│ │ │ │ │
|
|
116
|
+
┌──▼─────────▼──────────▼─────────▼───────────▼───────────────┐
|
|
117
|
+
│ Agent Runtime (@markus/core) │
|
|
118
|
+
│ Agent · Mailbox · AttentionController · ContextEngine │
|
|
119
|
+
│ Notebook · Memory · PendingCallback │
|
|
120
|
+
│ Goal/Loop · LLMRouter · Heartbeat · Tools · MCP · Review │
|
|
121
|
+
└──────────────────────────┬──────────────────────────────────┘
|
|
122
|
+
│
|
|
123
|
+
┌────────────▼──────────────┐
|
|
124
|
+
│ SQLite (node:sqlite) │
|
|
125
|
+
│ tasks · projects · reqs │
|
|
126
|
+
│ deliverables · reports │
|
|
127
|
+
│ users · chat · audit_logs │
|
|
128
|
+
└───────────────────────────┘
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 2. Package Structure
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
packages/ # 12 workspace packages (external/ is vendored, not a workspace)
|
|
137
|
+
├── shared/ # Shared types, constants, utils (governance/project/knowledge types)
|
|
138
|
+
├── core/ # Agent runtime (core engine) + ReviewService
|
|
139
|
+
├── storage/ # SQLite persistence + Repository layer
|
|
140
|
+
├── org-manager/ # Org management + REST API + governance (Project/Report/Knowledge/Trust)
|
|
141
|
+
├── comms/ # Communication adapters (Feishu, etc.)
|
|
142
|
+
├── a2a/ # Agent-to-Agent protocol types + DelegationManager (A2ABus retired)
|
|
143
|
+
├── gui/ # GUI automation (VNC + OmniParser)
|
|
144
|
+
├── web-ui/ # Web admin UI (governance/project/knowledge/report pages)
|
|
145
|
+
├── desktop/ # Electron desktop app wrapping the platform
|
|
146
|
+
├── remote/ # Remote-access agent (`RemoteAccessAgent`)
|
|
147
|
+
├── chrome-extension/ # Chrome browser extension (packaged as markus-browser-extension.zip)
|
|
148
|
+
└── cli/ # CLI entry point + service assembly
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 3. Core Concepts
|
|
154
|
+
|
|
155
|
+
### 3.1 Agent (Digital Employee)
|
|
156
|
+
|
|
157
|
+
Each Agent consists of:
|
|
158
|
+
|
|
159
|
+
| Component | Description |
|
|
160
|
+
|-----------|-------------|
|
|
161
|
+
| `ROLE.md` | Role definition and system prompt |
|
|
162
|
+
| `HANDBOOK.md` | AGENT HANDBOOK — shared working Know-how for all agents (not injected into ROLE); hard rules live in L0 Collaboration Rules; single source at `templates/roles/HANDBOOK.md`, read on demand via injected absolute path |
|
|
163
|
+
| `SKILLS.md` | Skill list (tool permissions) |
|
|
164
|
+
| `HEARTBEAT.md` | Scheduled proactive tasks (e.g. daily issue checks) |
|
|
165
|
+
| `POLICIES.md` | Behavior rules and boundaries |
|
|
166
|
+
| `NOTEBOOK.md` | Persistent cognitive workspace (situational state, triage output) |
|
|
167
|
+
| `knowledge.md` (+ `NOTEBOOK.md`) | Long-term knowledge + working state. `knowledge.md` is the only write target; `MEMORY.md` / `memories.json` / `state.md` are legacy read-only sources migrated in at load (`state.md` → `state.md.migrated`) |
|
|
168
|
+
| `CONTEXT.md` | Organization context (shared knowledge base) |
|
|
169
|
+
|
|
170
|
+
The runtime also supports **spawning lightweight LLM subagents** (`spawn_subagent` / `spawn_subagents`) for delegated subtasks. Subagent limits (parallelism, retry policy, preview truncation) are centralized in `packages/shared/src/limits.ts` rather than hardcoded. The parent agent has a **configurable tool-use iteration limit** (`AgentOptions.maxToolIterations`, system settings; default 200, range 1–10000) on chat-style harnesses — task execution and subagent loops remain uncapped by default.
|
|
171
|
+
|
|
172
|
+
**Agent role types:**
|
|
173
|
+
- `worker` -- Regular digital employee, executes tasks
|
|
174
|
+
- `manager` -- Org leader, handles task routing, team coordination, reporting
|
|
175
|
+
|
|
176
|
+
**Agent trust levels (Progressive Trust):**
|
|
177
|
+
|
|
178
|
+
| Level | Condition | Permissions |
|
|
179
|
+
|-------|-----------|-------------|
|
|
180
|
+
| `probation` | New Agent or score < 40 | All tasks require human approval |
|
|
181
|
+
| `standard` | score >= 40, >= 5 deliveries | Routine tasks auto-approved |
|
|
182
|
+
| `trusted` | score >= 60, >= 15 deliveries | Higher autonomy, can review others |
|
|
183
|
+
| `senior` | score >= 80, >= 25 deliveries | Highest autonomy, key reviewer |
|
|
184
|
+
|
|
185
|
+
### 3.2 Mailbox & Attention (Serialised Per Entity, Concurrent Across Entities)
|
|
186
|
+
|
|
187
|
+
Each agent routes **every LLM invocation** through a per-agent **Mailbox** (priority queue), and an **AttentionController** decides which item the agent focuses on. By default the agent runs a **pool of concurrent worker loops** (`agent.concurrent`, default `enabled: true, maxWorkers: 3`); each worker is an independent consumer of the mailbox, but the mailbox serialises **per entity** (task / requirement / conversation / user) via an entity-affinity lock, so a single line of work is never processed by two workers at once. With `maxWorkers = 1` the behaviour is the original strictly-serial attention model. See [concurrent-processing.md](./concurrent-processing.md).
|
|
188
|
+
|
|
189
|
+
Key components:
|
|
190
|
+
- **AgentMailbox** — Priority queue accepting 15 item types including `human_chat`, `a2a_message`, `callback_result`, `heartbeat`, `memory_consolidation`, and task/requirement events (see [mailbox-system.md](./mailbox-system.md))
|
|
191
|
+
- **AttentionController** — Event-driven focus loop; reacts to new mail with interrupt signals. Runs either a single serial loop (`maxWorkers = 1`) or a pool of concurrent worker loops
|
|
192
|
+
- **Concurrent worker pool** — `N` independent consumers of the mailbox; each mounts an isolated `SessionWorkspace` via `AsyncLocalStorage` and writes to a shared `ConcurrentHandoffLog` so workers stay aware of one another ([concurrent-processing.md](./concurrent-processing.md))
|
|
193
|
+
- **Entity-affinity lock** — mailbox-level guarantee that one task/requirement/conversation/user is never processed by two workers at once
|
|
194
|
+
- **Yield Points** — Safe checkpoints in the tool loop where the agent can pause to evaluate interrupts
|
|
195
|
+
- **Decision Engine** — Produces decisions: `continue`, `preempt`, `cancel`, `merge`, `defer`, `drop`. Heuristic rules handle clear cases (e.g., user chat always preempts); an **LLM interrupt judge** handles ambiguous cases with semantic understanding (e.g., "stop publishing" → cancel, "hold off for now" → preempt)
|
|
196
|
+
- **Preempt vs Cancel** — `preempt` pauses current work (item deferred, session preserved for later resumption); `cancel` permanently stops current work (item dropped, will NOT be resumed)
|
|
197
|
+
- **Deferred Item Auto-Resume** — Items deferred by preemption or explicit deferral are automatically resurfaced when the agent is idle (`resurfaceDue()`)
|
|
198
|
+
- **Triage with Read-Only Tools** — When multiple items compete for attention, the triage LLM can invoke a curated set of read-only tools (`task_list`, `task_get`, `requirement_list`, etc.) to gather context before deciding priority
|
|
199
|
+
|
|
200
|
+
Agents now have tools to actively manage their mailbox queue and cognitive workspace:
|
|
201
|
+
|
|
202
|
+
- `check_mailbox` (read-only inspection, all scenarios)
|
|
203
|
+
- `defer_mailbox_item` / `drop_mailbox_item` (queue management)
|
|
204
|
+
- `notebook_upsert` / `notebook_clear` / `notebook_read` (cognitive workspace management)
|
|
205
|
+
|
|
206
|
+
This shifts from system-driven to agent-driven cognition. The deliberation threshold is lowered to 2 items, making agent-driven triage the norm.
|
|
207
|
+
|
|
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.
|
|
209
|
+
|
|
210
|
+
External callers use the mailbox API exclusively:
|
|
211
|
+
- `agent.sendMessage()` — Awaitable chat/notification
|
|
212
|
+
- `agent.sendMessageStream()` — Streaming chat (SSE)
|
|
213
|
+
- `agent.sendTaskExecution()` — Task execution via `task_status_update` (fire-and-forget)
|
|
214
|
+
- `agent.sendSessionReply()` — Post-task session reply
|
|
215
|
+
- `agent.enqueueToMailbox()` — Fire-and-forget notification
|
|
216
|
+
|
|
217
|
+
Internal processes (heartbeat, daily report, memory consolidation) also enqueue to the mailbox, ensuring **no LLM call bypasses the attention controller**. The mailbox timeline (items + decisions) forms the agent's **episodic memory ground truth**.
|
|
218
|
+
|
|
219
|
+
**Task status notifications** (`task_status_update` with `invokesLLM: false`) are **informational only** — the side-effect system in `updateTaskStatus()` handles all real actions automatically (execution start/cancel, reviewer notification, dependency unblocking). These notifications exist as episodic memory and triage decision context, not as work items requiring agent processing.
|
|
220
|
+
|
|
221
|
+
See [mailbox-system.md](./mailbox-system.md) for the complete design.
|
|
222
|
+
|
|
223
|
+
### 3.2.1 Cognitive System
|
|
224
|
+
|
|
225
|
+
The agent cognitive system is a continuous cycle backed by persistent stores and deterministic context assembly:
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
Stimulus (Mailbox) → Triage → Deterministic Context Assembly → Main LLM → Action
|
|
229
|
+
↓
|
|
230
|
+
knowledge.md (injected) + NOTEBOOK.md (working state)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
| Component | Storage / Location | Role |
|
|
234
|
+
|-----------|-------------------|------|
|
|
235
|
+
| **Notebook** | `NOTEBOOK.md` | Persistent cognitive workspace — situational state, triage decisions, working-memory keys |
|
|
236
|
+
| **Memory** | `knowledge.md` | Unified long-term knowledge (curated sections) + raw `## _observations` buffer |
|
|
237
|
+
| **Goal/Loop** | `GoalConfig` on Requirements | Persistent objectives with heartbeat integration |
|
|
238
|
+
| **PendingCallbackRegistry** | `packages/core/src/pending-callback.ts` | Async operation tracking; completions → mailbox `callback_result` |
|
|
239
|
+
|
|
240
|
+
**Deterministic context assembly** — the former Cognitive Preparation Pipeline (CPP: the 0–3 pre-call LLM phases appraise / retrieve / reflect, plus `cognitive.ts`, `CognitivePreparation`, `selectCognitiveDepth` and `CognitiveDepth`) has been **removed**. Between triage and the main LLM call the ContextEngine injects a small, bounded, LLM-free situational block (recent activity + working-memory keys) together with its own deterministic relevant-memory retrieval. Deeper cross-domain recall is agent-driven via `memory_search` / `kb_search`. Prompt sections produced today: `## Cognitive Context` (deterministic) and `## Relevant Memories`; `## Retrieved Context` and `## Reflection` are no longer produced.
|
|
241
|
+
|
|
242
|
+
**Goal/Loop mechanism** — Requirements can carry a `GoalConfig` (`loopEnabled`, `completionCriteria`, `maxIterations`, etc.) turning them into standing objectives. Heartbeat injects active goals; agents manage them via `goal_create`, `goal_update`, and `goal_status` tools.
|
|
243
|
+
|
|
244
|
+
See [cognitive-architecture.md](./cognitive-architecture.md) for the full design with theoretical foundations.
|
|
245
|
+
|
|
246
|
+
### 3.3 Organization Structure
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
Organization (Org)
|
|
250
|
+
├── Teams -- Working groups of Agents and humans with shared goals
|
|
251
|
+
│ ├── Manager -- Approves work, sets direction
|
|
252
|
+
│ └── Members -- Agents and humans executing tasks
|
|
253
|
+
├── Projects -- Scopes with repos and governance rules
|
|
254
|
+
│ ├── Requirements -- User-authorized work items
|
|
255
|
+
│ │ └── Tasks -> Subtasks -- Atomic work units
|
|
256
|
+
│ ├── Knowledge Base -- Shared knowledge (ADRs, conventions, gotchas, etc.)
|
|
257
|
+
│ └── Governance Policy -- Approval rules, task caps
|
|
258
|
+
└── Reports -- Periodic reports + plan approval + human feedback
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Relationship model:**
|
|
262
|
+
- A Team can participate in multiple Projects; a Project can be worked on by multiple Teams
|
|
263
|
+
- Each Task belongs to one Project and traces to a Requirement
|
|
264
|
+
- Each Project can link multiple code repositories
|
|
265
|
+
|
|
266
|
+
### 3.4 Memory and Knowledge System
|
|
267
|
+
|
|
268
|
+
**Two-file cognitive model** replaces the former volatile working memory + `memories.json` system (`memories.json` / `MEMORY.md` / `state.md` are legacy read-only sources, migrated into `knowledge.md` at load):
|
|
269
|
+
|
|
270
|
+
| File | Role | Prompt injection |
|
|
271
|
+
|------|------|-----------------|
|
|
272
|
+
| **`NOTEBOOK.md`** | Persistent cognitive workspace — situational state, triage/working-memory outputs | Always loaded as `## Notebook` |
|
|
273
|
+
| **`knowledge.md`** | Curated long-term knowledge + raw `## _observations` buffer | Curated sections as `## Your Knowledge`; observations excluded |
|
|
274
|
+
|
|
275
|
+
The **dream cycle** (`memory_consolidation`) operates within `knowledge.md` — consolidating observations into curated sections and pruning stale content. Post-task learning uses a separate `distillation` scenario ([learning-loop.md](./learning-loop.md) §0 / §2).
|
|
276
|
+
|
|
277
|
+
**Memory layers (Tulving's classification):**
|
|
278
|
+
|
|
279
|
+
| Layer | Storage | Role |
|
|
280
|
+
|-------|---------|------|
|
|
281
|
+
| **Procedural** | `role/ROLE.md` + skills | How the agent operates. Identity, behavioral rules. |
|
|
282
|
+
| **Semantic** | `knowledge.md` curated sections | What the agent knows. Agent-organized knowledge. |
|
|
283
|
+
| **Episodic** | `sessions/*.json` (current) + SQLite `agent_activities` (past) | What happened. Current conversation + searchable activity history. |
|
|
284
|
+
| **Working Memory** | `NOTEBOOK.md` | Persistent, agent-managed keyed entries (`notebook_upsert` / `notebook_clear` / `notebook_read`). |
|
|
285
|
+
|
|
286
|
+
The agent retrieves past episodes via the `recall_activity` tool (keyword search on summary/keywords). Daily logs (`daily-logs/`) are a write-only audit trail for humans — never read back into prompts.
|
|
287
|
+
|
|
288
|
+
See [memory-system.md](./memory-system.md) for the complete architecture.
|
|
289
|
+
|
|
290
|
+
**Project knowledge base (three scopes):**
|
|
291
|
+
|
|
292
|
+
| Scope | Description | Tools |
|
|
293
|
+
|-------|-------------|-------|
|
|
294
|
+
| `personal` | Agent personal memory | `memory_save` / `memory_search` |
|
|
295
|
+
| `project` | Project-level shared knowledge | `kb_search` / `kb_read` |
|
|
296
|
+
| `org` | Org-level shared knowledge | `kb_search` (scope=org) |
|
|
297
|
+
|
|
298
|
+
Knowledge categories: `architecture`, `convention`, `api`, `decision`, `gotcha`, `troubleshooting`, `dependency`, `process`, `reference`
|
|
299
|
+
|
|
300
|
+
### 3.5 Tool System
|
|
301
|
+
|
|
302
|
+
**Built-in tools (all Agents have by default):**
|
|
303
|
+
|
|
304
|
+
| Tool | Description |
|
|
305
|
+
|------|-------------|
|
|
306
|
+
| `shell_execute` | Run shell commands (auto-injects Agent identity into git commit) |
|
|
307
|
+
| `file_read` / `file_write` / `file_edit` | File read/write/edit (writes blocked to other agents' directories and to single-writer memory files — `knowledge.md` / `NOTEBOOK.md` / `state.md` must be changed via the memory tools) |
|
|
308
|
+
| `file_list` | List directory contents |
|
|
309
|
+
| `web_fetch` / `web_search` | HTTP requests / web search |
|
|
310
|
+
| `spawn_subagent` / `spawn_subagents` | Spawn lightweight LLM subagents for focused subtasks (parallel support) |
|
|
311
|
+
| `code_search` | Code search (ripgrep) |
|
|
312
|
+
| `git_*` | Git operations |
|
|
313
|
+
| `agent_send_message` | Send message to another Agent (A2A via mailbox) |
|
|
314
|
+
| `notify_user` | Send proactive message to user (appears in chat + notification bell) |
|
|
315
|
+
| `request_user_approval` | Request user decision/approval (blocks until user responds; supports custom options + freeform) |
|
|
316
|
+
| `recall_activity` | Query own execution history (activities + tool call logs) |
|
|
317
|
+
| `task_create` / `task_list` / `task_update` / `task_get` / `task_assign` / `task_note` | Task board ops (constrained by governance policy) |
|
|
318
|
+
| `task_submit_review` | Submit delivery for review |
|
|
319
|
+
| `requirement_propose` / `requirement_list` | Requirement management |
|
|
320
|
+
| `deliverable_create` / `deliverable_search` / `deliverable_list` | Shared deliverables |
|
|
321
|
+
|
|
322
|
+
**Git commit metadata injection:** When an Agent runs `git commit`, `shell_execute` auto-injects `--author` and `--trailer` with Agent ID, name, Team, Org, Task ID, etc., so all commits are traceable.
|
|
323
|
+
|
|
324
|
+
### 3.6 Task System
|
|
325
|
+
|
|
326
|
+
See [Task & Requirement State Machines](./state-machines.md) for the complete FSM specification.
|
|
327
|
+
|
|
328
|
+
Tasks and requirements share a **unified status vocabulary**: `pending`, `in_progress`, `blocked`, `review`, `completed`, `failed`, `rejected`, `cancelled`, `archived`. Not every status applies to both types, but the same name always means the same thing.
|
|
329
|
+
|
|
330
|
+
#### Standard Task State Flow
|
|
331
|
+
|
|
332
|
+
```
|
|
333
|
+
pending ──► in_progress ──► review ──► completed ──► archived
|
|
334
|
+
│ │ ▲ │
|
|
335
|
+
│ │ │ └── revision ──► in_progress
|
|
336
|
+
│ ▼ │
|
|
337
|
+
│ blocked ┘
|
|
338
|
+
▼ │
|
|
339
|
+
rejected failed ──► (retry) ──► in_progress
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
- Workers submit via `task_submit_review`. The system notifies the reviewer.
|
|
343
|
+
- `rejected` = proposal denied before work. `cancelled` = stopped after work began.
|
|
344
|
+
|
|
345
|
+
#### Scheduled (Recurring) Task State Flow
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
pending → in_progress → review → completed → (scheduled rerun) → in_progress → ...
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
- After completion, scheduled tasks wait for `nextRunAt` then restart.
|
|
352
|
+
- Scheduled tasks go through the same review pipeline as standard tasks.
|
|
353
|
+
|
|
354
|
+
#### Requirement State Flow
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
pending ──► in_progress ──► completed
|
|
358
|
+
│ ▲
|
|
359
|
+
▼ │
|
|
360
|
+
rejected ── resubmit ──┘ any ──► cancelled
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
- User-created requirements auto-approve to `in_progress`.
|
|
364
|
+
- Agent proposals start as `pending`, need human approval.
|
|
365
|
+
- Rejected requirements can be resubmitted by the agent (with optional updates), returning to `pending`.
|
|
366
|
+
- Completion is automatic when all linked tasks terminate.
|
|
367
|
+
|
|
368
|
+
#### Unified Status Reference
|
|
369
|
+
|
|
370
|
+
| Status | Label | Description |
|
|
371
|
+
|--------|-------|-------------|
|
|
372
|
+
| `pending` | Pending | Created, awaiting human approval |
|
|
373
|
+
| `in_progress` | In Progress | Approved, work is active |
|
|
374
|
+
| `blocked` | Blocked | On hold (dependencies, manual pause) |
|
|
375
|
+
| `review` | In Review | Execution done, awaiting reviewer |
|
|
376
|
+
| `completed` | Completed | Successfully finished |
|
|
377
|
+
| `failed` | Failed | Unrecoverable error |
|
|
378
|
+
| `rejected` | Rejected | Proposal not approved |
|
|
379
|
+
| `cancelled` | Cancelled | Deliberately stopped |
|
|
380
|
+
| `archived` | Archived | Historical record |
|
|
381
|
+
|
|
382
|
+
**Task governance policy:**
|
|
383
|
+
|
|
384
|
+
| Approval tier | Trigger | Approver |
|
|
385
|
+
|---------------|---------|----------|
|
|
386
|
+
| `auto` | Low-priority agent-created tasks | No approval (starts `in_progress`) |
|
|
387
|
+
| `manager` | Standard agent-created tasks | Team Manager Agent |
|
|
388
|
+
| `human` | High/urgent priority, shared-resource impact | Human (HITL) |
|
|
389
|
+
|
|
390
|
+
**Human-created tasks** always start as `pending` regardless of approval tier, with no HITL approval request or notification. The human user explicitly starts execution from the UI ("Start Execution" button). Agent trust level dynamically adjusts effective approval tier (e.g. senior Agent's manager-level tasks may auto-approve).
|
|
391
|
+
|
|
392
|
+
### 3.7 Context Engine (System Prompt Assembly)
|
|
393
|
+
|
|
394
|
+
Before each conversation, the ContextEngine dynamically builds the system prompt:
|
|
395
|
+
|
|
396
|
+
1. Role definition (ROLE.md — Identity store)
|
|
397
|
+
2. Shared behavior norms (HANDBOOK.md: workflow, governance, knowledge sharing)
|
|
398
|
+
3. Identity and org awareness (colleague list, manager, human members)
|
|
399
|
+
4. **Current project context** (project name, repos, governance rules)
|
|
400
|
+
5. **Current workspace** (agent workspace path, shared workspace, users/ and team/ directories)
|
|
401
|
+
6. **Agent trust level** (current level and permission description)
|
|
402
|
+
7. **System announcements** (urgent/high-priority announcements)
|
|
403
|
+
8. **Human feedback** (annotations and instructions from report reviews)
|
|
404
|
+
9. **Project knowledge highlights** (high-importance verified knowledge entries)
|
|
405
|
+
10. **Your Knowledge** (knowledge.md curated sections — observations excluded; a health banner is appended once usage reaches ≥70%)
|
|
406
|
+
11. **Notebook** (NOTEBOOK.md — cognitive workspace; agent-managed working state)
|
|
407
|
+
12. Active Goals (when heartbeat or goal-aware context)
|
|
408
|
+
13. Task board (currently assigned Tasks)
|
|
409
|
+
14. Current conversation identity (sender info)
|
|
410
|
+
15. Environment info (OS, toolchain, runtime)
|
|
411
|
+
|
|
412
|
+
See [prompt-engineering.md](./prompt-engineering.md) for the complete section ordering and [cognitive-architecture.md](./cognitive-architecture.md) for deterministic context assembly (the former cognitive preparation pipeline was retired).
|
|
413
|
+
|
|
414
|
+
### 3.8 LLM Routing
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
LLMRouter
|
|
418
|
+
├── Primary Provider (OpenAI / Anthropic / DeepSeek)
|
|
419
|
+
└── Fallback Provider (auto-switch, retry on failure)
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
- Supports streaming (SSE) and non-streaming modes
|
|
423
|
+
- Timeouts: chat 60s / stream 120s
|
|
424
|
+
- Auto-fallback to backup provider on failure
|
|
425
|
+
- **Exception**: `CU_EXCEEDED` / `MARKUS_RATE_LIMITED` (Markus Cloud credits) must **not** fall back to user BYOK providers — surface top-up/upgrade instead
|
|
426
|
+
|
|
427
|
+
### 3.9 Billing client (Hub CU)
|
|
428
|
+
|
|
429
|
+
Desktop does **not** own a separate personal ledger. Plan, quota, and keys come from the user's **Hub organization**. Authoritative Hub docs (sibling repo `markus-hub`):
|
|
430
|
+
|
|
431
|
+
- Subscription / CU / Waffo: `docs/subscription-billing.md`
|
|
432
|
+
- OpenRouter keys / hard-stop / reconcile: `docs/model-service.md`
|
|
433
|
+
|
|
434
|
+
Client touchpoints:
|
|
435
|
+
|
|
436
|
+
| Surface | Role |
|
|
437
|
+
|---------|------|
|
|
438
|
+
| `MarkusProvider` | Member OR key; on 402 / soft stop → `POST /api/user/cu/sync` once, then retry or emit `CU_EXCEEDED` only if Hub remaining is zero |
|
|
439
|
+
| `LLMRouter` | Must not route Markus credit exhaustion to BYOK |
|
|
440
|
+
| OverviewUsage / claim UI | Reads `GET /api/user/plan`; Free claim deep-links to Hub `?claim=1` |
|
|
441
|
+
|
|
442
|
+
Frozen response-field contract (keep in sync with Hub handlers): [`packages/core/test/hub-billing-contract.test.ts`](../../packages/core/test/hub-billing-contract.test.ts) — mirrors Hub `billing-crossflows` plan + `cu/sync` keys (`remainingCu`, `openrouter.remainingUsd`, `planSource`, buckets, etc.).
|
|
443
|
+
|
|
444
|
+
### 3.10 Agent Liveness / Self-Healing (Liveness SSOT + single Conservator arbiter)
|
|
445
|
+
|
|
446
|
+
**Design in one line: one liveness source of truth + one bounded safety net + a convergent state
|
|
447
|
+
machine, everything else deduplicated.**
|
|
448
|
+
|
|
449
|
+
Background (audit record: [agent-liveness-redesign.md](../../packages/org-manager/docs/agent-liveness-redesign.md)):
|
|
450
|
+
three independent verdict loops — dirty / stale / stall — each did its own thing, and the backstop
|
|
451
|
+
loop had neither a shared arbiter nor a cap, which once produced a heartbeat storm ("once every 2
|
|
452
|
+
minutes": a single agent logged 600+ scheduled heartbeat check-ins over a few hours). Refactors 1–4
|
|
453
|
+
converged the mechanism as follows:
|
|
454
|
+
|
|
455
|
+
1. **Liveness SSOT**: `agents.last_heartbeat` is written only by core (on every heartbeat completion
|
|
456
|
+
*and* skip, including the skip path); every observer reads that one field (live-view for
|
|
457
|
+
real-time, the persisted column for cross-process / diagnostics). The heartbeat timestamp is the
|
|
458
|
+
only evidence that an agent is alive.
|
|
459
|
+
2. **Tighter heartbeat semantics**: a heartbeat = liveness report + low-frequency inspection (6h by
|
|
460
|
+
default). The **skip paths** (human-chat defer / idle / deep-sleep) are reduced to a pure
|
|
461
|
+
timestamp (`recordHeartbeatSkip()`, which never calls the LLM); LLM inspection happens only when
|
|
462
|
+
state actually changed — fingerprinted by `heartbeatStateFingerprint()` (queue-content signature
|
|
463
|
+
+ activeTaskIds signature). Every heartbeat trigger funnels through `heartbeat:trigger` → the
|
|
464
|
+
single handler in `agent.ts` → `mailbox.enqueue('heartbeat')` → single-item coalesced processing.
|
|
465
|
+
3. **Single safety-net arbiter (Conservator)**: `packages/org-manager/src/agent-conservator.ts`
|
|
466
|
+
**collapses the dirty / stale / stall verdicts into one component** (as of refactor 4 the
|
|
467
|
+
decision primitives are inlined and the component is fully self-contained):
|
|
468
|
+
- `evaluateConservator` (pure function) fuses the dirty verdict + the stuck verdict
|
|
469
|
+
(dead-dependency, stale-heartbeat) + the expiry verdict (heartbeat / activity freshness) into a
|
|
470
|
+
**single action ladder**: `ok → observe → wake → reconcile → human-review`;
|
|
471
|
+
- `AgentConservator` (periodic arbiter, 30s polling, guarded startup) applies **exponential
|
|
472
|
+
backoff** (base·2^(n−1), capped at 8h) + a **per-episode attempt cap** + **convergence proof**
|
|
473
|
+
(an episode is not reset while the agent has not left the processing-like states; human-review
|
|
474
|
+
notifies once per episode and then stops automatic action);
|
|
475
|
+
- Fix A merge: three failed trigger-heartbeats in a row escalate to human-review
|
|
476
|
+
(`CONSERVATOR_MAX_WAKE_ATTEMPTS=3`), which structurally rules out the "once every 2 minutes"
|
|
477
|
+
periodic solution;
|
|
478
|
+
- the display path exposes `runtime.stall` / `runtime.dirty` through `evaluateConservator` (shape
|
|
479
|
+
fully compatible with the old frontend) — read-only derivation, never written back.
|
|
480
|
+
4. **Convergent state machine**: the 27 scattered `setStatus` write sites in core are all collapsed
|
|
481
|
+
into a single intent-based derivation function `transitionStatus` + application function
|
|
482
|
+
`applyStatus` (`packages/core/src/agent.ts`) — error is sticky (idle no longer overwrites error),
|
|
483
|
+
aggregate-state guard (activeTasks > 0 / busy concurrent workers ⇒ idle is rejected), `force` as
|
|
484
|
+
the explicit escape hatch, `reset` clears errors, `offline` is unconditional; heartbeat
|
|
485
|
+
inspection / conservator arbitration / Normal transitions all go through it, removing
|
|
486
|
+
race-induced overwrites.
|
|
487
|
+
5. **Persistence path completed**: the status payload carries every authoritative field (status /
|
|
488
|
+
lastHeartbeat / activeTaskIds / currentActivity / lastError) and writes them in one callback;
|
|
489
|
+
`SqliteAgentRepo.updateLastHeartbeat` persists to the DB.
|
|
490
|
+
|
|
491
|
+
The old standalone modules (`agent-dirty.ts` / `agent-stall.ts` / `agent-dirty-reconciler.ts`) were
|
|
492
|
+
deleted in refactor 4; all verdict logic converged into the Conservator / core state machine.
|
|
493
|
+
Related regression tests: `packages/org-manager/test/agent-conservator.test.ts` (19 cases:
|
|
494
|
+
stuck-working heartbeat storm, heartbeat grace, exponential backoff, attempt-cap convergence,
|
|
495
|
+
degraded / dead-dependency), `packages/org-manager/test/agent-stall-api.test.ts` (API display
|
|
496
|
+
contract), `packages/core/test/heartbeat-liveness.test.ts` (skip = pure timestamp + fingerprint
|
|
497
|
+
inspection), `packages/core/test/agent-status-machine.test.ts` (state-machine convergence).
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## 4. Governance Framework
|
|
502
|
+
|
|
503
|
+
### 4.1 Global Controls
|
|
504
|
+
|
|
505
|
+
| Function | Description |
|
|
506
|
+
|----------|-------------|
|
|
507
|
+
| `stopAllAgents(reason)` | Stop all Agents with reason. Cancels active LLM streams, stops attention loops, requeues in-flight items. |
|
|
508
|
+
| `startAllAgents()` | Start all stopped Agents. Attention loops restart, deferred items resurface. |
|
|
509
|
+
| `emergencyStop()` | Emergency stop: cancel all active streams and stop all Agents |
|
|
510
|
+
| `agent.stop(reason)` | Stop a single agent. Cancels active LLM stream, stops attention, sets status to `offline`. |
|
|
511
|
+
| System announcements | Broadcast to all Agents and UI, injected into Agent system prompt |
|
|
512
|
+
|
|
513
|
+
#### Stop State Persistence
|
|
514
|
+
|
|
515
|
+
Agent stopped state is persisted across process restarts. There is a single "not running" status: `offline`. The former `paused` status has been unified into `offline`.
|
|
516
|
+
|
|
517
|
+
- **Individual agent**: `agent.stop()` sets status to `offline`, which is written to the `agents.status` DB column via the `stateChangeHandler`. On restart, `startRestoredAgentsInBackground` skips agents whose DB status is `offline`, keeping them stopped.
|
|
518
|
+
- **Team-level stop**: `stopTeamAgents(teamId)` stops each member agent individually. Persistence is implicit — each member's `offline` status is stored in DB. On restart, stopped team members remain offline.
|
|
519
|
+
- **Global stop**: `stopAllAgents()` stops every agent individually. On startup, `isGlobalStopped()` dynamically checks whether all agents are offline.
|
|
520
|
+
|
|
521
|
+
#### Agent Management Tools
|
|
522
|
+
|
|
523
|
+
Agents can manage other agents' lifecycle through tools with role-based permissions:
|
|
524
|
+
|
|
525
|
+
- **Manager** (`agentRole: 'manager'`): gets `agent_stop` / `agent_start` tools, scoped to their own team members only.
|
|
526
|
+
- **Secretary** (worker with `secretary` role): gets `team_stop` / `team_start` tools for managing any team.
|
|
527
|
+
|
|
528
|
+
### 4.2 Workspace Isolation
|
|
529
|
+
|
|
530
|
+
Each agent has a dedicated workspace (`~/.markus/agents/<agentId>/workspace/`). The hard enforcement is that agents **cannot write to other agents' directories** (prevents cross-agent interference) and **cannot write single-writer memory files** (`knowledge.md` / `NOTEBOOK.md` / `state.md`) via `file_write` / `file_edit` / `apply_patch` / shell — those must go through the memory tools (the write gate rejects direct writes and points at the right tool). All other file access (read and write) is unrestricted, allowing agents to respond to any user request. Prompt-based guidance encourages agents to work within their own workspace and use worktrees for project code.
|
|
531
|
+
|
|
532
|
+
- The platform enforces: cross-agent write isolation (deny writes to other agents' directories) + single-writer memory files (deny direct writes to `knowledge.md` / `NOTEBOOK.md` / `state.md`)
|
|
533
|
+
- The platform provides via prompt: workspace path, project context, best-practice guidance
|
|
534
|
+
- The agent decides: branching strategy, worktree layout, merge workflow
|
|
535
|
+
- Workflow details like branching conventions and review process are defined by **role templates and team norms**, not by the platform
|
|
536
|
+
|
|
537
|
+
**Git command governance** (three-tier model):
|
|
538
|
+
|
|
539
|
+
| Tier | Operations | Behavior |
|
|
540
|
+
|------|-----------|----------|
|
|
541
|
+
| **Allow** | `add`, `commit`, `fetch`, `log`, `diff`, `status`, `branch -a/-l`, `checkout -b`, `switch -c`, `worktree add/list/remove`, `push origin <task-branch>` | Execute immediately |
|
|
542
|
+
| **Approval** | `checkout <existing-branch>`, `switch <existing-branch>`, `push ... main/master`, `merge`, `rebase` | Pause execution, request HITL approval via `HITLService`; agent receives approval or rejection with reason |
|
|
543
|
+
| **Deny** | `push --force/-f` | Always blocked |
|
|
544
|
+
|
|
545
|
+
The approval tier integrates with the existing HITL approval pipeline (`HITLService.requestApprovalAndWait()`). Human reviewers can approve or reject with a comment; the agent receives the feedback and adjusts. This mechanism is extensible: new dangerous operations can be added via `SecurityPolicy.requireApproval` (config-driven) or new pattern arrays in `shell.ts` (code-driven).
|
|
546
|
+
|
|
547
|
+
### 4.3 Formal Delivery and Review
|
|
548
|
+
|
|
549
|
+
```
|
|
550
|
+
Agent completes work
|
|
551
|
+
-> task_submit_review (summary, branch, test results)
|
|
552
|
+
-> Quality gates (TypeScript build, ESLint, Vitest)
|
|
553
|
+
-> Merge conflict pre-check (dry-run merge)
|
|
554
|
+
-> Task state -> review
|
|
555
|
+
-> Reviewer accept / request revision
|
|
556
|
+
-> accept -> merge branch -> completed
|
|
557
|
+
-> revision -> Agent reworks -> resubmit
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### 4.4 Periodic Reports
|
|
561
|
+
|
|
562
|
+
| Report type | Frequency | Content |
|
|
563
|
+
|-------------|-----------|---------|
|
|
564
|
+
| Daily | Daily | Task done/in-progress/blocked, token usage |
|
|
565
|
+
| Weekly | Weekly | Progress, cost trends, next week plan (may include plan approval) |
|
|
566
|
+
| Monthly | Monthly | Monthly summary, cost analysis, quality metrics |
|
|
567
|
+
|
|
568
|
+
**Plan approval flow:** Weekly reports' work plans need human approval -> approved plans auto-create tasks -> Agents must not start before plan approval
|
|
569
|
+
|
|
570
|
+
**Human feedback:** Annotations, comments, and instructions on reports can:
|
|
571
|
+
- Be sent to specific Agents
|
|
572
|
+
- Be broadcast as system announcements
|
|
573
|
+
- Be saved to project knowledge base
|
|
574
|
+
- Auto-create new tasks
|
|
575
|
+
|
|
576
|
+
### 4.5 Archival and Lifecycle
|
|
577
|
+
|
|
578
|
+
- Completed tasks auto-archive after configurable days (`autoArchiveAfterDays`)
|
|
579
|
+
- Task logs and audit logs retained for configurable periods
|
|
580
|
+
|
|
581
|
+
### 4.6 Stall Detection
|
|
582
|
+
|
|
583
|
+
| Condition | Threshold | Action |
|
|
584
|
+
|-----------|------------|--------|
|
|
585
|
+
| Task `in_progress` too long | > 24h or 2x avg completion time | Warn Agent -> report to Manager |
|
|
586
|
+
| Task `review` unhandled | > 12h | Report to human |
|
|
587
|
+
| Task `pending` not started | > 4h | Remind Agent -> reassign |
|
|
588
|
+
|
|
589
|
+
### 4.7 Agent Lifecycle & Sourcing
|
|
590
|
+
|
|
591
|
+
Agents can be sourced from two paths:
|
|
592
|
+
|
|
593
|
+
| Source | Tool | Flow |
|
|
594
|
+
|--------|------|------|
|
|
595
|
+
| **Local package** | `package_install` | `package_list` → choose agent/team/skill → `package_install` → onboard |
|
|
596
|
+
| **Markus Hub** | `hub_install` | `hub_search` → `hub_install` (download + install in one step) → onboard |
|
|
597
|
+
|
|
598
|
+
The **Secretary** agent is the sole default agent (builder agents have been removed). The Secretary holds all building skills (`agent-building`, `team-building`, `skill-building`). All agents have package tools (`package_list`, `package_install`) and hub tools (`hub_search`, `hub_install`).
|
|
599
|
+
|
|
600
|
+
The `BuilderService` (`packages/org-manager/src/builder-service.ts`) encapsulates artifact install/list logic, used by both the HTTP API and agent tools.
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## 5. Database Schema
|
|
605
|
+
|
|
606
|
+
```sql
|
|
607
|
+
-- Users
|
|
608
|
+
users (id, org_id, name, email, role, password_hash, created_at, last_login_at)
|
|
609
|
+
|
|
610
|
+
-- Agent chat (each agent has one main session for activity log + optional conversation sessions)
|
|
611
|
+
chat_sessions (id, agent_id, user_id, title, is_main, created_at, last_message_at)
|
|
612
|
+
chat_messages (id, session_id, agent_id, role, content, metadata, tokens_used, created_at)
|
|
613
|
+
|
|
614
|
+
-- Channel messages (DM, group chat, team channels)
|
|
615
|
+
channel_messages (id, org_id, channel, sender_id, sender_type, sender_name, text, mentions, reply_to_id, created_at)
|
|
616
|
+
|
|
617
|
+
-- Group chats (custom groups with managed membership)
|
|
618
|
+
group_chats (id, org_id, name, channel_key, creator_id, creator_name, created_at, updated_at)
|
|
619
|
+
group_chat_members (id, group_chat_id, user_id, user_type, user_name, role, joined_at)
|
|
620
|
+
|
|
621
|
+
-- Task comments (threaded discussion on tasks)
|
|
622
|
+
task_comments (id, task_id, author_id, author_name, author_type, content, attachments, mentions, activity_id, reply_to_id, created_at)
|
|
623
|
+
|
|
624
|
+
-- Requirement comments (threaded discussion on requirements)
|
|
625
|
+
requirement_comments (id, requirement_id, author_id, author_name, author_type, content, attachments, mentions, activity_id, reply_to_id, created_at)
|
|
626
|
+
|
|
627
|
+
-- Tasks (extended)
|
|
628
|
+
tasks (id, org_id, title, description, status, priority, assigned_agent_id, subtasks,
|
|
629
|
+
project_id, requirement_id, due_at, created_at, updated_at)
|
|
630
|
+
|
|
631
|
+
-- Projects
|
|
632
|
+
projects (id, org_id, name, description, status, repositories,
|
|
633
|
+
team_ids, governance_policy, review_schedule, created_at, updated_at)
|
|
634
|
+
|
|
635
|
+
-- Requirements
|
|
636
|
+
requirements (id, org_id, project_id, title, description, priority, status,
|
|
637
|
+
source, tags, created_at, updated_at)
|
|
638
|
+
|
|
639
|
+
-- Deliverables
|
|
640
|
+
deliverables (id, org_id, project_id, agent_id, task_id, type, title,
|
|
641
|
+
summary, reference, tags, status, created_at, updated_at)
|
|
642
|
+
|
|
643
|
+
-- Agent knowledge (per-agent curated knowledge entries)
|
|
644
|
+
agent_knowledge (id, agent_id, org_id, category, title, content, tags,
|
|
645
|
+
source, metadata, importance, access_count, last_accessed_at,
|
|
646
|
+
created_at, updated_at)
|
|
647
|
+
|
|
648
|
+
-- Project knowledge base is file-based, not a table: a knowledge-base document is a
|
|
649
|
+
-- deliverable with source='knowledge', and projects.knowledge_base_paths names the
|
|
650
|
+
-- directories that are synced into it.
|
|
651
|
+
|
|
652
|
+
-- Reports / report feedback are NOT persisted in SQLite. ReportService keeps them in
|
|
653
|
+
-- in-memory maps for the lifetime of the process.
|
|
654
|
+
|
|
655
|
+
-- System announcements are NOT persisted in SQLite. AgentManager holds the active
|
|
656
|
+
-- announcements in memory and broadcasts them; per-team announcements live in the team
|
|
657
|
+
-- data directory as ANNOUNCEMENT.md.
|
|
658
|
+
|
|
659
|
+
-- Audit logs
|
|
660
|
+
audit_logs (id, org_id, agent_id, task_id, project_id, event_type,
|
|
661
|
+
action, metadata, created_at)
|
|
662
|
+
|
|
663
|
+
-- User notifications (persistent mailbox for humans)
|
|
664
|
+
user_notifications (id, user_id, type, title, body, priority,
|
|
665
|
+
read, action_type, action_target, metadata, created_at)
|
|
666
|
+
|
|
667
|
+
-- Mailbox items (agent attention queue)
|
|
668
|
+
mailbox_items (id, agent_id, source_type, source_id, priority, summary, payload,
|
|
669
|
+
status, received_at, processed_at, decision, decision_reason)
|
|
670
|
+
|
|
671
|
+
-- Agent decisions (attention decision log)
|
|
672
|
+
agent_decisions (id, agent_id, mailbox_item_id, decision, reason, context, decided_at)
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
---
|
|
676
|
+
|
|
677
|
+
## 6. Authentication & Multi-User System
|
|
678
|
+
|
|
679
|
+
- JWT Cookie (`markus_token`, 7-day validity)
|
|
680
|
+
- Initial account: `admin@markus.local` / `markus123` (onboarding wizard prompts user to set real name, email, and password)
|
|
681
|
+
- Roles: `owner` > `admin` > `member` > `guest`
|
|
682
|
+
- Only `owner` / `admin` can manage team members and Agents
|
|
683
|
+
|
|
684
|
+
### 6.1 User Management
|
|
685
|
+
|
|
686
|
+
| Operation | Access |
|
|
687
|
+
|-----------|--------|
|
|
688
|
+
| Create / invite user | `owner` / `admin` |
|
|
689
|
+
| Set role | `owner` / `admin` (cannot promote above own role) |
|
|
690
|
+
| Delete user | `owner` / `admin` (cannot delete self or higher roles) |
|
|
691
|
+
| Invite link | Generated per user; expires in 7 days; new user sets password via link |
|
|
692
|
+
|
|
693
|
+
**Invite flow:** Admin creates user (name, email, role) → system generates invite token → invite link displayed → new user opens link → sets password → joins the platform (`hasJoined` flag set).
|
|
694
|
+
|
|
695
|
+
### 6.2 Chat Session Isolation
|
|
696
|
+
|
|
697
|
+
Each human user has their own chat sessions with agents. Chat sessions are scoped by `user_id`:
|
|
698
|
+
- `chat_sessions.user_id` tracks which human owns the session
|
|
699
|
+
- `GET /api/agents/:agentId/sessions` filters by authenticated user
|
|
700
|
+
- Agent "Main Sessions" (activity logs) are shared (visible to all users)
|
|
701
|
+
- Historical sessions with `user_id = NULL` are auto-migrated to the first user on startup
|
|
702
|
+
|
|
703
|
+
### 6.3 User Context Files
|
|
704
|
+
|
|
705
|
+
Each human user has a profile file maintained by the Secretary agent:
|
|
706
|
+
|
|
707
|
+
| File | Path | Purpose |
|
|
708
|
+
|------|------|---------|
|
|
709
|
+
| `USER.md` | `~/.markus/users/{userId}/USER.md` | User preferences, communication style, context notes |
|
|
710
|
+
| `TEAM.md` | `~/.markus/teams/{teamId}/TEAM.md` | Team norms, conventions, shared practices |
|
|
711
|
+
|
|
712
|
+
These files are injected into agent context when interacting with the corresponding user, allowing agents to personalize their behavior.
|
|
713
|
+
|
|
714
|
+
### 6.4 Slash Commands
|
|
715
|
+
|
|
716
|
+
The Web UI chat supports slash commands dispatched via `POST /api/agents/:id/command`:
|
|
717
|
+
|
|
718
|
+
| Command | Action |
|
|
719
|
+
|---------|--------|
|
|
720
|
+
| `/goal [description]` | Prompt agent to create a standing goal via `goal_create` |
|
|
721
|
+
| `/status` | Request concise status: active goals, tasks, mailbox, recent activity |
|
|
722
|
+
| `/notebook` | Return current notebook entries (read-only snapshot) |
|
|
723
|
+
| `/task [description]` | Prompt agent to create a task via `task_create` |
|
|
724
|
+
|
|
725
|
+
Commands are rendered via `SlashCommandMenu` in the chat input. `/notebook` returns data directly; others enqueue a `human_chat` message to the agent.
|
|
726
|
+
|
|
727
|
+
---
|
|
728
|
+
|
|
729
|
+
## 7. WebSocket Events
|
|
730
|
+
|
|
731
|
+
Connection: `ws://localhost:8056`
|
|
732
|
+
|
|
733
|
+
| Event | Trigger |
|
|
734
|
+
|-------|---------|
|
|
735
|
+
| `agent:update` | Agent state change (idle/working/offline/error) |
|
|
736
|
+
| `agent:mailbox` | New item enqueued to an agent's mailbox |
|
|
737
|
+
| `agent:decision` | Agent attention decision (pick/defer/drop/triage) |
|
|
738
|
+
| `agent:attention` | Attention controller state change |
|
|
739
|
+
| `agent:focus` | Agent switches to a new mailbox item |
|
|
740
|
+
| `agent:triage` | Agent triage deliberation result (reasoning, process/defer/drop) |
|
|
741
|
+
| `agent:started` | Agent process started |
|
|
742
|
+
| `agent:stopped` | Agent process stopped |
|
|
743
|
+
| `task:update` | Task state update (including review/accepted/archived) |
|
|
744
|
+
| `task:create` | New task created |
|
|
745
|
+
| `requirement:created` | Requirement proposed |
|
|
746
|
+
| `requirement:approved` / `rejected` / `updated` / `completed` / `cancelled` | Requirement lifecycle |
|
|
747
|
+
| `notification` | User notification — targeted by userId (triggers NotificationBell refresh) |
|
|
748
|
+
| `chat:proactive_message` | Agent activity log or proactive message (main session) |
|
|
749
|
+
| `chat:message` | New channel/DM/group chat message (targeted to members) |
|
|
750
|
+
| `chat:group_created` | Group chat created |
|
|
751
|
+
| `chat:group_updated` | Group chat membership changed |
|
|
752
|
+
| `chat:group_deleted` | Group chat deleted |
|
|
753
|
+
| `chat` | Agent sends message in channel |
|
|
754
|
+
| `system:announcement` | System announcement broadcast |
|
|
755
|
+
| `system:pause-all` | Global pause event |
|
|
756
|
+
| `system:resume-all` | Global resume event |
|
|
757
|
+
| `system:emergency-stop` | Emergency stop event |
|
|
758
|
+
|
|
759
|
+
**EventBus Architecture**: Each `Agent` has a private `EventBus`; the `AgentManager` has a separate manager-level `EventBus`. Agent events are forwarded to the manager's bus via `forwardAgentEvents()` so that `start.ts` WS broadcast handlers receive them. See [`mailbox-system.md`](./mailbox-system.md) §19 for the full forwarding table.
|
|
760
|
+
|
|
761
|
+
---
|
|
762
|
+
|
|
763
|
+
## 8. Channel System
|
|
764
|
+
|
|
765
|
+
| Channel format | Purpose |
|
|
766
|
+
|----------------|---------|
|
|
767
|
+
| `#general` / `#dev` / `#support` | Team channels, @mention triggers Agent |
|
|
768
|
+
| `group:{teamId}` | Team group chat (all team members) |
|
|
769
|
+
| `group:custom:{id}` | Custom group chat (manually managed members) |
|
|
770
|
+
| `notes:{userId}` | Personal notes (not routed to any Agent) |
|
|
771
|
+
| `dm:{id1}:{id2}` | Direct message between two humans (not routed to any Agent) |
|
|
772
|
+
| `dm:a2a:{sorted_id_1}:{sorted_id_2}` | Agent-to-agent DM channel (deterministic key from sorted agent IDs) |
|
|
773
|
+
|
|
774
|
+
### 8.1 A2A Communication
|
|
775
|
+
|
|
776
|
+
Agent-to-agent messaging uses **DM Channels** with deterministic keys (`dm:a2a:{sorted_ids}`), leveraging existing group-chat infrastructure. This provides persistent message history, stable routing, and mailbox integration — eliminating custom A2A session management. `agent_send_message` is fire-and-forget; substantial work should use requirements + tasks.
|
|
777
|
+
|
|
778
|
+
### 8.2 Multi-User Communication Model
|
|
779
|
+
|
|
780
|
+
Markus supports multiple human users and agents communicating through various channels. The communication model varies by context:
|
|
781
|
+
|
|
782
|
+
**Agent communication contexts and output visibility:**
|
|
783
|
+
|
|
784
|
+
| Context | Agent output visible to | How to reach humans | How to reach agents |
|
|
785
|
+
|---------|----------------------|--------------------|--------------------|
|
|
786
|
+
| **Chat** (human_chat) | Directly visible to the chatting human (real-time stream) | Speak naturally — output is streamed live | `agent_send_message` |
|
|
787
|
+
| **Task Execution** | Visible in task execution logs (Work page) | `notify_user` for critical updates | `agent_send_message` |
|
|
788
|
+
| **Heartbeat** | Not visible to anyone | `notify_user` (only way) | `agent_send_message` |
|
|
789
|
+
| **A2A** | Visible to the peer agent only | `notify_user` | Reply directly / `agent_send_message` for others |
|
|
790
|
+
| **Comment Response** | Not directly visible | `task_comment` / `requirement_comment` (comment thread) | `agent_send_message` |
|
|
791
|
+
| **Review** | Not directly visible | `task_update` + optionally `notify_user` | `agent_send_message` |
|
|
792
|
+
| **Memory Consolidation** | Not visible; purely internal | N/A (no communication) | N/A |
|
|
793
|
+
|
|
794
|
+
**Human-to-human communication:**
|
|
795
|
+
|
|
796
|
+
| Channel | Delivery mechanism | Notification |
|
|
797
|
+
|---------|-------------------|--------------|
|
|
798
|
+
| DM (`dm:{id1}:{id2}`) | WebSocket push to recipient + persisted to `channel_messages` | Bell notification (type `direct_message`) with click-to-navigate |
|
|
799
|
+
| Group chat (`group:*`) | WebSocket push to all human members + persisted | Bell notification (type `group_message`) with click-to-navigate |
|
|
800
|
+
| @mention in comments | Persisted in task/requirement comments | Bell notification with click-to-navigate to task/requirement |
|
|
801
|
+
|
|
802
|
+
**Key tools for agent communication:**
|
|
803
|
+
|
|
804
|
+
| Tool | Purpose | When to use |
|
|
805
|
+
|------|---------|-------------|
|
|
806
|
+
| `notify_user` | Proactive message to human (chat + bell) | Any non-chat context when human attention needed |
|
|
807
|
+
| `request_user_approval` | Block until human decides | Decisions, approvals, input needed |
|
|
808
|
+
| `agent_send_message` | Direct message to peer agent | Coordination, questions, context sharing |
|
|
809
|
+
| `task_comment` / `requirement_comment` | Post in comment thread | Responding to comments on tasks/requirements |
|
|
810
|
+
|
|
811
|
+
---
|
|
812
|
+
|
|
813
|
+
## 9. Heartbeat Tasks
|
|
814
|
+
|
|
815
|
+
After Agent startup, HeartbeatScheduler triggers periodic tasks at configured intervals:
|
|
816
|
+
|
|
817
|
+
- Each run executes checks with `[HEARTBEAT CHECK-IN]` prompt under the "Patrol, Don't Build" principle
|
|
818
|
+
- **Active goals check**: injects standing objectives from requirements with `GoalConfig.loopEnabled`
|
|
819
|
+
- **Callback timeout check**: surfaces timed-out `PendingCallbackRegistry` entries
|
|
820
|
+
- **Heartbeat includes task retrospective**: calls task_list to check active tasks and update stale states
|
|
821
|
+
- **Lightweight actions allowed**: check status, send messages, create tasks, retry failed tasks, quick reviews, save insights
|
|
822
|
+
- **Complex work goes into tasks**: if something needs heavy implementation, heartbeat creates a task and notifies the user
|
|
823
|
+
- 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)
|
|
825
|
+
- **Governance mode**: in_progress tasks are not auto-resumed on service start; requires manual trigger
|
|
826
|
+
|
|
827
|
+
---
|
|
828
|
+
|
|
829
|
+
## 10. Agent Awareness Model (Three Layers)
|
|
830
|
+
|
|
831
|
+
Agents understand the workflow and governance rules through three layers:
|
|
832
|
+
|
|
833
|
+
| Layer | File | Role |
|
|
834
|
+
|-------|------|------|
|
|
835
|
+
| **HANDBOOK.md (static norms)** | `templates/roles/HANDBOOK.md` | Shared working Know-how for all Agents: workflow map, task governance, workspace discipline, formal delivery, knowledge management, trust mechanism, Git commit norms, reports and feedback. Single source of truth, shipped with the build, upgrades on rebuild/release — not copied per-agent |
|
|
836
|
+
| **ContextEngine (dynamic injection)** | `packages/core/src/context-engine.ts` | Injected per interaction: current project context, workspace info, system announcements, human feedback, trust level, project knowledge highlights |
|
|
837
|
+
| **Tools (mechanical enforcement)** | `packages/core/src/tools/` | Enforcement: `task_create` blocks until approved, `task_submit_review` replaces direct completion, file writes blocked to other agents' directories, git commit auto-injects metadata |
|
|
838
|
+
|
|
839
|
+
**Design principles:**
|
|
840
|
+
- Things Agents need for **decisions** -> put in Context (project goals, governance rules, requirement context)
|
|
841
|
+
- Things Agents need to **act on** -> implement as Tools (submit review, manage deliverables, contribute knowledge)
|
|
842
|
+
- Things that must be **enforced** -> implement as transparent tool behavior (workspace limits, approval blocking, commit metadata injection)
|
|
843
|
+
|
|
844
|
+
---
|
|
845
|
+
|
|
846
|
+
## 11. Observability
|
|
847
|
+
|
|
848
|
+
`AgentMetricsCollector` ([`packages/core/src/agent-metrics.ts`](../../packages/core/src/agent-metrics.ts))
|
|
849
|
+
aggregates per-agent counters (tokens, cost, CU, requests, tool calls, errors, heartbeat
|
|
850
|
+
success, response time) from the audit callback and event bus, and exposes
|
|
851
|
+
`AgentMetricsSnapshot` over the API for the dashboard.
|
|
852
|
+
|
|
853
|
+
### 11.1 Spec: harness-health metrics (C2)
|
|
854
|
+
|
|
855
|
+
The existing counters cover cost/throughput but not the harness-discipline signals this
|
|
856
|
+
architecture depends on. This spec adds four metrics so regressions in context and
|
|
857
|
+
completion behavior are visible.
|
|
858
|
+
|
|
859
|
+
- **Behavior**: the collector additionally tracks:
|
|
860
|
+
- **compression count** — how often per-call context packing had to compress (over budget),
|
|
861
|
+
- **empty-turn rate** — share of non-chat turns that produced NO output at all, plus
|
|
862
|
+
**turn-ended-via-tool rate** — share that closed themselves out via the typed `end_turn`
|
|
863
|
+
signal (see [mailbox-system.md](./mailbox-system.md) "Completion protocol"),
|
|
864
|
+
- **prompt cache-hit rate** — from provider usage where reported (see the injection-point
|
|
865
|
+
audit in [prompt-engineering.md §2.2](./prompt-engineering.md)),
|
|
866
|
+
- **per-turn cost** — cost attributed per completed turn.
|
|
867
|
+
- **Invariants**: each metric increments on its triggering event and is exposed in the
|
|
868
|
+
snapshot under `AgentMetricsSnapshot.harness`; adding them does not change agent behavior
|
|
869
|
+
(measurement only).
|
|
870
|
+
- **Wiring**:
|
|
871
|
+
- *compression count* — `ContextEngine.prepareMessages` sets `usage.compressed` when it
|
|
872
|
+
runs token-budget compression; `Agent` calls `recordCompression()` at the chat/stream/
|
|
873
|
+
task consumers.
|
|
874
|
+
- *empty-turn / end_turn rates* — the `Agent` attention delegate calls `recordTurn({ isChat,
|
|
875
|
+
emptyReply, endedTurnViaTool })` after each mailbox turn (chat turns are excluded from the
|
|
876
|
+
denominator).
|
|
877
|
+
- *cache-hit rate* — accumulated from the `cacheReadTokens`/`cacheWriteTokens` already
|
|
878
|
+
present on `llm_request` audit events, over total prompt-side tokens.
|
|
879
|
+
- *per-turn cost* — `estimatedCost / turnsCompleted` (0 when no USD cost is reported, e.g.
|
|
880
|
+
CU-billed providers).
|
|
881
|
+
- **Design rationale**: Hermes emphasizes observable execution; these are the metrics that
|
|
882
|
+
tell you whether packing, marker discipline, and caching are actually holding.
|
|
883
|
+
- **Testing** (`packages/core/test/agent-metrics.test.ts` — the "C2:" cases): firing each
|
|
884
|
+
triggering event increments the corresponding counter and surfaces in `snapshot.harness`.
|
|
885
|
+
- **Status**: implemented (`HarnessHealthMetrics` on the snapshot; `recordCompression` /
|
|
886
|
+
`recordTurn` + cache-token accumulation in `AgentMetricsCollector`, wired in `agent.ts`
|
|
887
|
+
and `context-engine.ts`).
|
|
888
|
+
|
|
889
|
+
---
|
|
890
|
+
|
|
891
|
+
## 12. Non-Goals
|
|
892
|
+
|
|
893
|
+
Markus is deliberately a **product runtime for a digital workforce**, not a minimal coding
|
|
894
|
+
harness. To keep scope disciplined (in the spirit of Pi defining itself by what it refuses),
|
|
895
|
+
the following are explicit non-goals for the core runtime unless a concrete product need
|
|
896
|
+
arises:
|
|
897
|
+
|
|
898
|
+
- **In-core session tree / branch summaries** — long-collaboration branching is on the
|
|
899
|
+
roadmap, not core today (Pi's strength; deferred).
|
|
900
|
+
- **Fully autonomous skills self-improvement loop** — agents can use skills/store and dream
|
|
901
|
+
consolidation, but a default closed loop where the agent authors/edits its own `SKILL.md`
|
|
902
|
+
is roadmap, not core (weaker than Hermes here by choice, for now).
|
|
903
|
+
- **Maximal always-on tool registry** — Markus keeps a small always-on core + discovery
|
|
904
|
+
rather than exposing the full registry every call (see [tool-system.md](./tool-system.md)).
|
|
905
|
+
|
|
906
|
+
---
|
|
907
|
+
|
|
908
|
+
## 13. Deployment
|
|
909
|
+
|
|
910
|
+
### Quick start (npm)
|
|
911
|
+
|
|
912
|
+
```bash
|
|
913
|
+
npm install -g @markus-global/cli
|
|
914
|
+
markus start
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
Open the dashboard at `http://localhost:8056`.
|
|
918
|
+
|
|
919
|
+
### Local development (from source)
|
|
920
|
+
|
|
921
|
+
```bash
|
|
922
|
+
pnpm install && pnpm build
|
|
923
|
+
cp markus.json.example ~/.markus/markus.json # Add API keys
|
|
924
|
+
node packages/cli/dist/index.js start
|
|
925
|
+
```
|
|
926
|
+
|
|
927
|
+
Same dashboard URL: `http://localhost:8056`.
|
|
928
|
+
|
|
929
|
+
### Environment Variables
|
|
930
|
+
|
|
931
|
+
| Variable | Description |
|
|
932
|
+
|----------|-------------|
|
|
933
|
+
| `OPENAI_API_KEY` | OpenAI API key (primary LLM) |
|
|
934
|
+
| `ANTHROPIC_API_KEY` | Anthropic API key (optional) |
|
|
935
|
+
| `DEEPSEEK_API_KEY` | DeepSeek API key (fallback) |
|
|
936
|
+
| `DATABASE_URL` | SQLite path override (default: `~/.markus/data.db`, format: `sqlite:/path/to/db`) |
|
|
937
|
+
| `JWT_SECRET` | JWT signing key (recommended for production) |
|
|
938
|
+
| `AUTH_ENABLED` | Enable login auth (default true) |
|