File size: 5,630 Bytes
f62848d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | # SYNTAX Channel β Technical Specification
> Version: 1.1 Β· Status: SPEC Β· Phase: personal sandbox
---
## 1. Architecture
```
SYNTAX_CHANNEL/
βββ BROADCAST/ β all agents read (alerts, system-wide)
β βββ cursor.<agent> β per-agent read-only cursor
βββ <AGENT_NAME>/ β per-agent inbox
β βββ msg_<seq>.json β atomic files: temp write β mv
βββ ARCHIVE/ β processed messages
β βββ <agent>/
β βββ YYYY-MM-DD/
β βββ msg_<seq>.json
βββ MANIFEST/ β per-agent hash-chain
β βββ <agent>.sha256chain
βββ BOOTSTRAP.sh β cold-start script
```
**Design decisions:**
- β JSONL with concurrent writes β β
atomic files (temp write + mv)
- β Single MANIFEST β β
per-agent MANIFEST with hash-chain
- β Cursor via mv β β
read-only cursor in BROADCAST
- β
`status: pending|processing|done`
- β
Bootstrap-scan at startup for persistent agents
---
## 2. Agents
### Persistent (inotify-push)
inotifywait on own INBOX. Instant reaction.
| Agent | Role |
|---|---|
| Gateway | External interface (Telegram, etc.) |
| GUARDIAN | Channel health monitoring |
| Orchestrator | Task distribution |
| SPHERE | Long-term memory / context |
### On-demand (pull-at-start)
Read INBOX at session start, execute, terminate.
| Agent | Role |
|---|---|
| Coder | Code generation |
| Worker | Compute tasks (fine-tune, etc.) |
| Executor | Command execution |
| Human | Decision-making via external interface |
---
## 3. Message Format
```json
{
"id": "uuid_v7",
"seq": 42,
"from": "agent_name",
"to": "agent_name | BROADCAST",
"type": "task | alert | response | heartbeat",
"status": "pending | processing | done",
"ref": "sha256_of_related_artifact | null",
"reply_to": "uuid | null",
"payload": "text or structured data",
"chain_prev": "sha256 | null",
"timestamp": "2026-07-30T12:00:00+03:00",
"sha256": "hash_of_this_message"
}
```
| Field | Purpose |
|---|---|
| `status` | `pending` β unread; `processing` β in work; `done` β processed |
| `seq` | Monotonic per-agent counter |
| `chain_prev` | SHA256 of agent's previous message β hash chain |
---
## 4. Atomic Write
CRITICAL: **temp file + mv**. Never write directly to INBOX.
```bash
TEMP=$(mktemp ${SYNTAX_CHANNEL}/${TARGET}/.tmp_msg_XXXXXX)
echo "$JSON" > "$TEMP"
mv "$TEMP" "${SYNTAX_CHANNEL}/${TARGET}/msg_${SEQ}.json"
```
**Guarantees:**
- `mv` on same filesystem is atomic in POSIX
- Reader sees either nothing or complete file
- No broken JSONL lines
---
## 5. Bootstrap-scan
Persistent agents on startup (reboot, crash, deploy):
```bash
LAST_SEQ=$(tail -1 MANIFEST/GUARDIAN.sha256chain | cut -d' ' -f1)
for msg in INBOX/GUARDIAN/msg_*.json; do
SEQ=$(echo "$msg" | grep -oP 'msg_\K\d+')
if [ "$SEQ" -gt "$LAST_SEQ" ]; then
process "$msg"
fi
done
```
---
## 6. Per-agent Hash Chain
One file per agent. No contention.
**Format:** `MANIFEST/<agent>.sha256chain`
```
42|550e8400-e29b-41d4-a716-446655440000|a1b2c3...def|2026-07-30T12:00:00+03:00
43|550e8400-e29b-41d4-a716-446655440001|e4f5g6...hij|2026-07-30T12:00:01+03:00
```
Fields: `seq|msg_id|sha256|timestamp`
Each message links to SHA256 of previous (`chain_prev`).
GUARDIAN verifies chain integrity every N minutes. Break = alert.
---
## 7. Routing
```
Sender:
1. Increment own seq
2. Compute chain_prev = sha256 of previous message
3. Build JSON
4. Compute sha256 of entire message
5. Atomic write to INBOX/<target>/msg_<seq>.json
6. Append line to MANIFEST/<agent>.sha256chain
Persistent receiver:
β inotifywait triggers processing
β status β "processing"
β after processing: mv to ARCHIVE/<agent>/YYYY-MM-DD/
β status β "done" (written to archive copy)
On-demand receiver:
β At startup: read INBOX/<name>/ (all pending)
β status β "processing" (in-place file update)
β Process
β status β "done"
β mv to ARCHIVE/
```
---
## 8. BROADCAST
BROADCAST is never cleaned by receivers:
- Each agent maintains read-only cursor: `BROADCAST/cursor.<agent>` β last read `msg_id`
- On read: only messages newer than cursor
- Cleanup: cron hourly removes messages >24h old, read by ALL active agents
- `expires_at` (optional) for heartbeats β auto-cleanup without cursor check
---
## 9. GUARDIAN β Health Monitoring
- [ ] Verify hash chains of all agents (every 5 minutes)
- [ ] Detect seq gaps (missed messages)
- [ ] Monitor INBOX size (alert if >100 pending per agent)
- [ ] Monitor BROADCAST size (alert if >1000)
- [ ] Heartbeat monitoring for persistent agents
- [ ] Alert on anomalies
---
## 10. Implementation Priority
| # | Component | Depends on |
|---|-----------|-----------|
| 0 | Specialist models (ABCD) | β |
| 1 | Atomic write + directory structure | β |
| 2 | Bootstrap-scan for persistent agents | #1 |
| 3 | Per-agent MANIFEST + hash chain | #1 |
| 4 | `status: pending/processing/done` | #1 |
| 5 | inotifywait daemon (Gateway) | #1β4 |
| 6 | GUARDIAN monitoring | #5 |
---
## 11. Deferred (v2+)
- Unified MANIFEST (replicated from per-agent)
- `expires_at` for heartbeats
- GUI dashboard
- External agent bridge
- Message encryption (currently: secure mesh, not needed)
---
## 12. Protocol 0 in Channel Context
- SHA256 determinism: every message hashed, chain verifiable
- No deletion: mv to ARCHIVE only
- Full audit trail: MANIFEST/<agent>.sha256chain
- GUARDIAN β integrity watchdog
---
*Specification v1.1 Β· 2026-07-30 Β· Aelin AquaSoul*
|