@flame0510/project-aether 1.1.9

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 (290) hide show
  1. package/README.md +150 -0
  2. package/agent-templates/README.md +37 -0
  3. package/agent-templates/argus/AGENTS.md +52 -0
  4. package/agent-templates/argus/IDENTITY.md +7 -0
  5. package/agent-templates/argus/MEMORY.md +9 -0
  6. package/agent-templates/argus/SOUL.md +24 -0
  7. package/agent-templates/argus/TOOLS.md +8 -0
  8. package/agent-templates/atlas/AGENTS.md +47 -0
  9. package/agent-templates/atlas/HEARTBEAT.md +10 -0
  10. package/agent-templates/atlas/IDENTITY.md +6 -0
  11. package/agent-templates/atlas/MEMORY.md +9 -0
  12. package/agent-templates/atlas/SOUL.md +21 -0
  13. package/agent-templates/atlas/TOOLS.md +4 -0
  14. package/agent-templates/base-image/.trigger +0 -0
  15. package/agent-templates/base-image/Dockerfile +90 -0
  16. package/agent-templates/base-image/entrypoint.sh +37 -0
  17. package/agent-templates/custom/AGENTS.md +29 -0
  18. package/agent-templates/custom/BOOTSTRAP.md +56 -0
  19. package/agent-templates/custom/MEMORY.md +8 -0
  20. package/agent-templates/prometheus/AGENTS.md +37 -0
  21. package/agent-templates/prometheus/IDENTITY.md +6 -0
  22. package/agent-templates/prometheus/MEMORY.md +9 -0
  23. package/agent-templates/prometheus/SOUL.md +21 -0
  24. package/agent-templates/prometheus/TOOLS.md +4 -0
  25. package/app/agents/ChannelManager.tsx +465 -0
  26. package/app/agents/ImageDownloadBanner.tsx +159 -0
  27. package/app/agents/PageClient.tsx +1285 -0
  28. package/app/agents/create/PageClient.tsx +437 -0
  29. package/app/agents/create/page.tsx +126 -0
  30. package/app/agents/loading.tsx +14 -0
  31. package/app/agents/page.tsx +5 -0
  32. package/app/api/agents/[id]/backup/route.ts +169 -0
  33. package/app/api/agents/[id]/channels/pairing/route.ts +69 -0
  34. package/app/api/agents/[id]/channels/route.ts +14 -0
  35. package/app/api/agents/[id]/channels/telegram/route.ts +50 -0
  36. package/app/api/agents/[id]/lifecycle/route.ts +94 -0
  37. package/app/api/agents/[id]/recreate/route.ts +199 -0
  38. package/app/api/agents/[id]/restart/route.ts +33 -0
  39. package/app/api/agents/[id]/restore/route.ts +81 -0
  40. package/app/api/agents/[id]/route.ts +280 -0
  41. package/app/api/agents/channels-summary/route.ts +39 -0
  42. package/app/api/agents/config-json/route.ts +58 -0
  43. package/app/api/agents/create/route.ts +488 -0
  44. package/app/api/agents/download-image/route.ts +32 -0
  45. package/app/api/agents/image-status/route.ts +126 -0
  46. package/app/api/agents/route.ts +213 -0
  47. package/app/api/agents/token/route.ts +94 -0
  48. package/app/api/agents-active/route.ts +190 -0
  49. package/app/api/agents-config/route.ts +629 -0
  50. package/app/api/alerts/smoke/route.ts +26 -0
  51. package/app/api/aliases/add/route.ts +28 -0
  52. package/app/api/aliases/remove/route.ts +27 -0
  53. package/app/api/assistant/route.ts +204 -0
  54. package/app/api/auth/check/route.ts +38 -0
  55. package/app/api/auth/login/route.ts +85 -0
  56. package/app/api/auth/logout/route.ts +7 -0
  57. package/app/api/auth/status/route.ts +33 -0
  58. package/app/api/config/env/route.ts +132 -0
  59. package/app/api/config/restart/route.ts +26 -0
  60. package/app/api/containers/route.ts +75 -0
  61. package/app/api/cost-override/route.ts +46 -0
  62. package/app/api/costs/route.ts +84 -0
  63. package/app/api/credentials/[id]/reveal/route.ts +21 -0
  64. package/app/api/credentials/[id]/route.ts +52 -0
  65. package/app/api/credentials/[id]/sync/route.ts +58 -0
  66. package/app/api/credentials/detect/route.ts +246 -0
  67. package/app/api/credentials/route.ts +33 -0
  68. package/app/api/crons/[id]/route.ts +69 -0
  69. package/app/api/crons/route.ts +12 -0
  70. package/app/api/crons/runs/route.ts +31 -0
  71. package/app/api/debug/route.ts +11 -0
  72. package/app/api/envcheck/route.ts +18 -0
  73. package/app/api/events/route.ts +24 -0
  74. package/app/api/gateway/agent/route.ts +154 -0
  75. package/app/api/gateway/provider/balance/route.ts +38 -0
  76. package/app/api/gateway/provider/keys.ts +38 -0
  77. package/app/api/gateway/provider/oauth/route.ts +304 -0
  78. package/app/api/gateway/provider/route.ts +209 -0
  79. package/app/api/gateway/route.ts +223 -0
  80. package/app/api/gateway/sync.ts +189 -0
  81. package/app/api/lineage/route.ts +54 -0
  82. package/app/api/memory-context/route.ts +15 -0
  83. package/app/api/metrics/route.ts +35 -0
  84. package/app/api/models/route.ts +77 -0
  85. package/app/api/plugins/route.js +37 -0
  86. package/app/api/provider/upstream.ts +142 -0
  87. package/app/api/provider/v1/chat/completions/route.ts +146 -0
  88. package/app/api/provider/v1/models/route.ts +167 -0
  89. package/app/api/provider-usage/route.ts +629 -0
  90. package/app/api/session/route.ts +39 -0
  91. package/app/api/sessions/[id]/route.ts +38 -0
  92. package/app/api/sessions/route.ts +23 -0
  93. package/app/api/setup/agent-image/route.ts +102 -0
  94. package/app/api/setup/password/route.ts +111 -0
  95. package/app/api/setup/restart/route.ts +76 -0
  96. package/app/api/skills/delete/route.js +105 -0
  97. package/app/api/skills/promote/route.js +129 -0
  98. package/app/api/skills/route.js +203 -0
  99. package/app/api/skills/save/route.js +142 -0
  100. package/app/api/stats/route.ts +34 -0
  101. package/app/api/stats-since/route.ts +20 -0
  102. package/app/api/stream/route.ts +70 -0
  103. package/app/api/system-health/route.ts +233 -0
  104. package/app/api/tool-calls/route.ts +24 -0
  105. package/app/api/tools-config/route.ts +163 -0
  106. package/app/api/update-check/route.ts +127 -0
  107. package/app/api/version/route.ts +25 -0
  108. package/app/api/wizard/complete/route.ts +32 -0
  109. package/app/api/wizard/reset/route.ts +28 -0
  110. package/app/api/wizard/status/route.ts +28 -0
  111. package/app/api/workspace/route.ts +392 -0
  112. package/app/api/workspace/stream/route.ts +136 -0
  113. package/app/components/AppShell.tsx +33 -0
  114. package/app/components/AuthGuard.tsx +91 -0
  115. package/app/components/CostBreakdown.tsx +37 -0
  116. package/app/components/DashboardHeader.tsx +73 -0
  117. package/app/components/DashboardLayout.tsx +76 -0
  118. package/app/components/DashboardToolbar.tsx +61 -0
  119. package/app/components/FloatingActions.tsx +33 -0
  120. package/app/components/Icons.tsx +78 -0
  121. package/app/components/LineageGraphPage.tsx +142 -0
  122. package/app/components/LiveFeed.tsx +48 -0
  123. package/app/components/MobileBottomNav.tsx +84 -0
  124. package/app/components/ModelPickerModal.tsx +94 -0
  125. package/app/components/PasswordInput.tsx +86 -0
  126. package/app/components/PulseChat.tsx +362 -0
  127. package/app/components/Rev4aLoader.tsx +48 -0
  128. package/app/components/SessionDrawer.tsx +263 -0
  129. package/app/components/SessionTopology.tsx +289 -0
  130. package/app/components/Sidebar.tsx +294 -0
  131. package/app/components/Skeleton.tsx +133 -0
  132. package/app/components/SystemCockpit.tsx +169 -0
  133. package/app/components/VersionBanner.tsx +105 -0
  134. package/app/components/WizardButton.tsx +30 -0
  135. package/app/components/ui/Badge.tsx +30 -0
  136. package/app/components/ui/Button.tsx +59 -0
  137. package/app/components/ui/ConfirmModal.tsx +46 -0
  138. package/app/components/ui/FilterBar.tsx +33 -0
  139. package/app/components/ui/Input.tsx +25 -0
  140. package/app/components/ui/ItemList.tsx +83 -0
  141. package/app/components/ui/LoadingSpinner.tsx +30 -0
  142. package/app/components/ui/Metric.tsx +22 -0
  143. package/app/components/ui/Modal.tsx +42 -0
  144. package/app/components/ui/Page.tsx +18 -0
  145. package/app/components/ui/Pill.tsx +6 -0
  146. package/app/components/ui/PropertyList.tsx +24 -0
  147. package/app/components/ui/Select.tsx +26 -0
  148. package/app/components/ui/StatusCard.tsx +32 -0
  149. package/app/components/ui/Surface.tsx +14 -0
  150. package/app/components/ui/Tabs.tsx +55 -0
  151. package/app/components/ui/TemplateOption.tsx +59 -0
  152. package/app/components/ui/Toast.tsx +44 -0
  153. package/app/components/ui/index.ts +19 -0
  154. package/app/components/ui/tokens.ts +18 -0
  155. package/app/config/PageClient.tsx +293 -0
  156. package/app/config/loading.tsx +10 -0
  157. package/app/config/page.tsx +7 -0
  158. package/app/containers/ContainersClient.tsx +129 -0
  159. package/app/containers/loading.tsx +21 -0
  160. package/app/containers/page.tsx +5 -0
  161. package/app/containers/terminal/[id]/TerminalClient.tsx +313 -0
  162. package/app/containers/terminal/[id]/page.tsx +6 -0
  163. package/app/credentials/PageClient.tsx +598 -0
  164. package/app/credentials/loading.tsx +10 -0
  165. package/app/credentials/page.tsx +7 -0
  166. package/app/crons/PageClient.tsx +538 -0
  167. package/app/crons/loading.tsx +10 -0
  168. package/app/crons/page.tsx +5 -0
  169. package/app/design-system.ts +57 -0
  170. package/app/gateway/PageClient.tsx +1048 -0
  171. package/app/gateway/loading.tsx +24 -0
  172. package/app/gateway/page.tsx +5 -0
  173. package/app/globals.css +1474 -0
  174. package/app/layout.tsx +45 -0
  175. package/app/lib/models-context.tsx +41 -0
  176. package/app/lineage/loading.tsx +10 -0
  177. package/app/lineage/page.tsx +13 -0
  178. package/app/loading.tsx +16 -0
  179. package/app/login/page.tsx +160 -0
  180. package/app/memory/MemoryContextPageClient.tsx +196 -0
  181. package/app/memory/loading.tsx +10 -0
  182. package/app/memory/page.tsx +8 -0
  183. package/app/page.tsx +31 -0
  184. package/app/plugins/PageClient.tsx +296 -0
  185. package/app/plugins/loading.tsx +10 -0
  186. package/app/plugins/page.tsx +5 -0
  187. package/app/setup/PageClient.tsx +227 -0
  188. package/app/setup/loading.tsx +21 -0
  189. package/app/setup/page.tsx +7 -0
  190. package/app/skills/PageClient.tsx +499 -0
  191. package/app/skills/loading.tsx +10 -0
  192. package/app/skills/page.tsx +5 -0
  193. package/app/tools/ToolsPageClient.tsx +308 -0
  194. package/app/tools/loading.tsx +10 -0
  195. package/app/tools/page.tsx +62 -0
  196. package/app/tools/tools-catalog.ts +141 -0
  197. package/app/wizard/PageClient.tsx +485 -0
  198. package/app/wizard/icons.tsx +89 -0
  199. package/app/wizard/loading.tsx +24 -0
  200. package/app/wizard/page.tsx +7 -0
  201. package/app/wizard/storage.ts +33 -0
  202. package/app/wizard/useWizard.ts +101 -0
  203. package/app/workspace/WorkspaceClient.tsx +633 -0
  204. package/app/workspace/loading.tsx +36 -0
  205. package/app/workspace/page.tsx +8 -0
  206. package/bin/docker-entrypoint.sh +21 -0
  207. package/bin/postinstall.js +20 -0
  208. package/bin/rev4a.js +696 -0
  209. package/daemon.js +783 -0
  210. package/docs/ARCHITECTURE.md +557 -0
  211. package/docs/CONTAINER-TERMINAL.md +280 -0
  212. package/docs/DESIGN-SYSTEM.md +99 -0
  213. package/docs/FRONTEND-ARCHITECTURE.md +119 -0
  214. package/docs/REV4A.md +504 -0
  215. package/docs/dev/API-REFERENCE.md +1835 -0
  216. package/docs/dev/DATABASE.md +224 -0
  217. package/docs/dev/GATEWAY.md +300 -0
  218. package/docs/dev/PROVIDERS.md +229 -0
  219. package/docs/dev/SESSION-MAINTENANCE-PLAN.md +607 -0
  220. package/docs/dev/WORKSPACE.md +199 -0
  221. package/docs/rag/DATA-FRESHNESS.md +109 -0
  222. package/docs/rag/GLOSSARY.md +125 -0
  223. package/docs/rag/REV4A-OVERVIEW.md +135 -0
  224. package/docs/rag/WHAT-I-CAN-ANSWER.md +124 -0
  225. package/lib/agent-setup.ts +130 -0
  226. package/lib/alerts.ts +115 -0
  227. package/lib/apiFetch.ts +7 -0
  228. package/lib/auth.ts +28 -0
  229. package/lib/billing.ts +100 -0
  230. package/lib/buildAgentImage.ts +346 -0
  231. package/lib/channelManager.ts +386 -0
  232. package/lib/container.ts +60 -0
  233. package/lib/credentials/db.ts +86 -0
  234. package/lib/credentials/delivery.ts +448 -0
  235. package/lib/credentials/detect.ts +149 -0
  236. package/lib/credentials/hash.ts +9 -0
  237. package/lib/credentials/providers.ts +110 -0
  238. package/lib/credentials/vault.ts +195 -0
  239. package/lib/db-bootstrap.d.ts +3 -0
  240. package/lib/db-bootstrap.mjs +144 -0
  241. package/lib/db.ts +25 -0
  242. package/lib/docker-utils.ts +60 -0
  243. package/lib/hooks/useDashboard.ts +264 -0
  244. package/lib/hooks/useRev4aTimezone.ts +28 -0
  245. package/lib/hooks/useScreenshot.ts +30 -0
  246. package/lib/memory-context.ts +385 -0
  247. package/lib/model-catalogue.ts +131 -0
  248. package/lib/model-pricing.ts +63 -0
  249. package/lib/openclaw-cron.ts +350 -0
  250. package/lib/patterns/ApiAdapter.ts +73 -0
  251. package/lib/patterns/ApiClient.ts +65 -0
  252. package/lib/patterns/EventBus.ts +113 -0
  253. package/lib/patterns/FilterStrategy.ts +79 -0
  254. package/lib/patterns/SessionFactory.ts +117 -0
  255. package/lib/patterns/sessionPresentation.ts +117 -0
  256. package/lib/provider-balance.ts +163 -0
  257. package/lib/requireAuth.tsx +38 -0
  258. package/lib/rev4a-auth.d.ts +3 -0
  259. package/lib/rev4a-auth.js +36 -0
  260. package/lib/rev4a-paths.ts +145 -0
  261. package/lib/timezone.ts +46 -0
  262. package/lib/types/index.ts +96 -0
  263. package/lib/utils/format.ts +82 -0
  264. package/lineage.js +56 -0
  265. package/model-pricing.json +482 -0
  266. package/models.config.json +844 -0
  267. package/next-env.d.ts +6 -0
  268. package/next.config.mjs +7 -0
  269. package/package.json +82 -0
  270. package/public/apple-touch-icon.png +0 -0
  271. package/public/favicon-64.png +0 -0
  272. package/public/favicon.svg +58 -0
  273. package/public/icon-192-maskable.png +0 -0
  274. package/public/icon-192.png +0 -0
  275. package/public/icon-512-maskable.png +0 -0
  276. package/public/icon-512.png +0 -0
  277. package/public/manifest.json +38 -0
  278. package/public/rev4a-logo.png +0 -0
  279. package/public/rev4a-logo.svg +58 -0
  280. package/rev4a-rules/AGENTS.md +37 -0
  281. package/scripts/add-auth.cjs +185 -0
  282. package/scripts/backup.sh +66 -0
  283. package/scripts/check-providers.mjs +143 -0
  284. package/scripts/docker/traefik/docker-compose.yml +32 -0
  285. package/scripts/docker/traefik/dynamic/.gitkeep +18 -0
  286. package/scripts/docker/traefik/traefik.yml +37 -0
  287. package/scripts/remove-auth-profile.js +56 -0
  288. package/scripts/restore.sh +82 -0
  289. package/terminal-ws-server.js +139 -0
  290. package/tsconfig.json +42 -0
@@ -0,0 +1,557 @@
1
+ # Rev4a Architecture — Design & Vision
2
+
3
+ > **Status:** Active — `main` branch
4
+ > **Last updated:** 2026-06-30
5
+ > **Goal:** Transform Rev4a from a monitoring dashboard into a central orchestrator for a distributed multi-container agency.
6
+
7
+ ---
8
+
9
+ ## 1. Why Multi-Container?
10
+
11
+ ### Current state (single container + dashboard)
12
+
13
+ ```
14
+ ┌─────────────────────────────────────────────┐
15
+ │ openclaw-core (1 container) │
16
+ │ │
17
+ │ Rev4a (Next.js + daemon + SQLite) │
18
+ │ OpenClaw runtime + systemd │
19
+ │ Subagents via sessions_spawn (same process)│
20
+ │ 3+ agent workspaces (ops, prometheus, …) │
21
+ │ │
22
+ │ ⚠️ 4 CPU, 15 GB RAM shared │
23
+ │ ⚠️ Single Node.js event loop │
24
+ │ ⚠️ Everything competes for CPU/IO │
25
+ └─────────────────────────────────────────────┘
26
+ ```
27
+
28
+ **Pain points:**
29
+ - CPU-bound processes (ESLint, builds, daemon polling) compete
30
+ - Single event loop saturated by too many Node tasks
31
+ - Single SQLite WAL under concurrent load
32
+ - Impossible to use frameworks other than OpenClaw (Hermes, OpenCode)
33
+
34
+ ### Target vision: Rev4a as orchestrator
35
+
36
+ ```
37
+ ┌────────────────────────────────────────────────────────────────┐
38
+ │ DOCKER HOST (187.77.156.41, 4 CPU, 15 GB RAM, 193 GB disk) │
39
+ │ │
40
+ │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────┐ │
41
+ │ │ rev4a-control │ │ agent-argus │ │ agent-atlas │ │
42
+ │ │ (orchestrator) │ │ (OpenClaw: Ops) │ │ (OpenClaw: │ │
43
+ │ │ │ │ │ │ Development)│ │
44
+ │ │ • Dashboard UI │ │ • Session pool │ │ • Session │ │
45
+ │ │ • Config DB │ │ • 2 CPU limit │ │ • 2 CPU │ │
46
+ │ │ • Docker socket │ │ • 4 GB RAM limit │ │ • 4 GB RAM │ │
47
+ │ │ • Auth gateway │ │ • skills (ro) │ │ • skills (ro)│ │
48
+ │ │ • Provider proxy │ │ • repos (rw) │ │ • repos (rw) │ │
49
+ │ └────────┬─────────┘ └────────┬─────────┘ └──────┬───────┘ │
50
+ │ │ │ │ │
51
+ │ ┌────────┴─────────┐ ┌────────┴─────────┐ ┌──────┴───────┐ │
52
+ │ │ agent-prometheus │ │ agent-hermes │ │ agent-future │ │
53
+ │ │ (OpenClaw: CRM) │ │ (Hermes Agent) │ │ (OpenCode?) │ │
54
+ │ └──────────────────┘ └──────────────────┘ └──────────────┘ │
55
+ │ │
56
+ │ ┌──────────────────────────────────────────────────────────┐ │
57
+ │ │ SHARED VOLUMES │ │
58
+ │ │ • /docker/shared-skills → read-only on all agents │ │
59
+ │ │ • /docker/shared-repos → shared project repos │ │
60
+ │ └──────────────────────────────────────────────────────────┘ │
61
+ │ └──────────────────────────────────────────────────────────┘ │
62
+ └────────────────────────────────────────────────────────────────┘
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 2. Current Architecture (as of 2026-06-24)
68
+
69
+ ### What's already been implemented
70
+
71
+ **Container separation:** `openclaw-atlas` already runs as a standalone container with `AGENT_ID=atlas`, discovered dynamically by Rev4a. This proves the container-per-agent model works.
72
+
73
+ **Vault system:** A credentials vault (`/vault` page) stores API keys and service tokens with per-agent permissions. File-backed vault system (removed - sensitive data is env-only).
74
+
75
+ **Container management UI:** The `/containers` page lists all running Docker containers with resource usage, logs, and quick links. Fully functional.
76
+
77
+ **Workspace API:** Lazy-loaded file tree explorer with real-time reads (no caching), supports both host and container workspaces via `docker exec`.
78
+
79
+ ### What's in place but needs refinement
80
+
81
+ | Feature | Status | Notes |
82
+ |---|---|---|
83
+ | Vault (UI + API) | 🟢 Implemented | SQLite + JSON, no encryption yet |
84
+ | Container page | 🟢 Functional | Lists all containers, logs, resources |
85
+ | Agent creation wizard | 🟢 Implemented | One-click create with model/template selection |
86
+ | Provider proxy | 🟢 Implemented | Agents route through Rev4a provider gateway |
87
+ | Shared volumes | 🟢 Implemented | Skills + repos mounted on all agents |
88
+ | Central Oracle DB | 🔴 Not started | Events are per-container |
89
+ | Auto-registration | 🔴 Not started | New containers must be manually added |
90
+
91
+ ---
92
+
93
+ ## 3. Components (Target Architecture)
94
+
95
+ ### 3.1 Rev4a Control Plane
96
+
97
+ The central container, running the Next.js dashboard + orchestration API.
98
+
99
+ **Responsibilities:**
100
+ - Web dashboard (Next.js, port 3740)
101
+ - REST orchestration API to spawn/stop/restart agents
102
+ - AI Provider Gateway (proxy for OpenAI, Anthropic, Groq, etc.)
103
+ - Centralized credential management
104
+ - Docker socket access for container management
105
+ - SQLite DB for cross-container event monitoring
106
+ - **Onboarding wizard** — first-run setup flow at `/onboarding`, tracks progress in `data/onboarding-progress.json`
107
+
108
+ **Volume mounts (target):**
109
+ ```
110
+ /path/to/rev4a/data → /data (persistent)
111
+ /var/run/docker.sock → /var/run/docker.sock
112
+ /docker/shared-skills → /data/.openclaw/shared-skills (ro)
113
+ /docker/shared-repos → /data/repos (rw)
114
+ ```
115
+
116
+ **Rev4a System Rules** (`rev4a-rules/AGENTS.md`):
117
+ - Versioned in the repo, deployed to `/docker/rev4a-rules/` on every `rev4a serve` start
118
+ - Mounted read-only into every agent at `/root/.openclaw/workspace/.rev4a/AGENTS.md`
119
+ - Injected into every session via the `bootstrap-extra-files` hook (glob `.rev4a/*.md`)
120
+ - Immutable by agents — enforced by the `:ro` mount
121
+ - See `lib/agent-setup.ts` for the centralized volume + config guarantee logic
122
+
123
+ ### 3.2 Agent Container Template (`openclaw-agent-base`)
124
+
125
+ Docker image for every agent container.
126
+
127
+ **Contents:** See the live Dockerfile at
128
+ `agent-templates/base-image/Dockerfile` (authoritative source).
129
+ The image installs `openclaw`, `vercel`, `trello-cli`, `gh`, `supabase`,
130
+ copies the entrypoint script, and applies baseline gateway config patches.
131
+
132
+
133
+ **Volume mounts (per agent):**
134
+ ```
135
+ /docker/shared-skills → /data/.openclaw/shared-skills (ro)
136
+ /docker/rev4a-rules → /root/.openclaw/workspace/.rev4a (ro)
137
+ agent-{name}-data (named vol) → /root (rw, per-agent persistent state)
138
+ ```
139
+
140
+ All shared volumes are defined centrally in `lib/agent-setup.ts`
141
+ (`REV4A_VOLUMES`) and used by both the create and recreate API routes.
142
+ The `bootstrap-extra-files` hook is pre-wired in the base image Dockerfile
143
+ and guaranteed at runtime by `applyRuntimeConfig()`.
144
+
145
+ **Injected environment variables:**
146
+ ```
147
+ AGENT_NAME=<agent-name>
148
+ AGENT_TEMPLATE=<template>
149
+ OPENCLAW_GATEWAY_TOKEN=<shared agent token>
150
+ AGENT_HOSTNAME=<host-ip>:<portStart>
151
+ TZ=Europe/Rome
152
+ ```
153
+
154
+ > **Note:** Provider API keys are never injected into agent containers. Agents use the Rev4a provider gateway at `http://host.docker.internal:3740/api/provider/v1` (resolved via `detectProviderGatewayUrl()`).
155
+
156
+ ### 3.3 AI Provider Gateway (implemented)
157
+
158
+ The Provider Gateway is fully implemented and operational. Agent containers
159
+ point to the Rev4a provider proxy instead of using direct API keys.
160
+
161
+ **Flow:**
162
+
163
+ ```
164
+ Agent Container Rev4a Gateway Provider API
165
+ │ │ │
166
+ │ Authorization: Bearer <gateway-token> │
167
+ │ POST /api/provider/v1/chat/completions │
168
+ │ model: rev4a/deepseek-v4-flash │
169
+ │────────────────────────>│ │
170
+ │ │ POST /v1/chat/completions│
171
+ │ │ Authorization: Bearer <real-key>
172
+ │ │────────────────────────>│
173
+ │ │ response │
174
+ │ │<────────────────────────│
175
+ │ response │ │
176
+ │<────────────────────────│ │
177
+ ```
178
+
179
+ **Key characteristics:**
180
+
181
+ - The Rev4a server in `app/api/provider/v1/` acts as an OpenAI-compatible proxy
182
+ - Authentication uses `data/provider-keys.json` — the Bearer token must match
183
+ the 'rev4a' entry
184
+ - Model lists (`GET /api/provider/v1/models`) return an empty list on invalid
185
+ or missing token, preventing information leakage
186
+ - Chat requests (`POST /api/provider/v1/chat/completions`) return 401 on
187
+ invalid or missing token
188
+ - API keys live only on the Rev4a server (in `data/provider-keys.json`),
189
+ never inside agent containers
190
+ - The Gateway page (`/gateway`) provides a UI to manage provider keys and
191
+ sync them to agent containers via `PUT /api/gateway/provider`
192
+
193
+ See [GATEWAY.md](dev/GATEWAY.md) and [PROVIDERS.md](dev/PROVIDERS.md) for
194
+ detailed documentation.
195
+
196
+ ---
197
+
198
+ ## 4. Credential Management (Vault)
199
+
200
+ Provider API keys are stored in `data/provider-keys.json`. Third-party service credentials
201
+ (GitHub, Trello, Vercel, Supabase) are stored in `data/credentials.db` (SQLite).
202
+ At agent spawn time, Rev4a injects only the credentials the agent is permitted to use.
203
+
204
+ ```json
205
+ {
206
+ "providers": {
207
+ "openai-codex": "sk-...",
208
+ "anthropic": "sk-ant-...",
209
+ "groq": "gsk_..."
210
+ },
211
+ "services": {
212
+ "github": { "token": "***", "user": "Flame0510" },
213
+ "vercel": { "token": "***", "team": "flame0510" }
214
+ },
215
+ "agent_permissions": {
216
+ "argus": ["providers:all", "services:github", "services:vercel"],
217
+ "atlas": ["providers:openai-codex", "services:github"],
218
+ "prometheus": ["providers:openai-codex"]
219
+ }
220
+ }
221
+ ```
222
+
223
+ **Current implementation:** SQLite (`credentials.db`) for services, JSON file (`provider-keys.json`) for provider keys (no encryption yet). Future: encrypted with AES-256-GCM or integrated with HashiCorp Vault / Vaultwarden.
224
+
225
+ ---
226
+
227
+ ## 5. Lifecycle Orchestration
228
+
229
+ ### Agent spawn flow
230
+
231
+ ```
232
+ Rev4a Dashboard UI
233
+ │
234
+ │ Click "New Agent"
235
+ ▼
236
+ ┌──────────────────────────────────────┐
237
+ │ 1. Template selection │
238
+ │ - Choose template (argus/atlas/…) │
239
+ │ - Configure model, workspace, etc │
240
+ └──────────────┬───────────────────────┘
241
+ │
242
+ ▼
243
+ ┌──────────────────────────────────────┐
244
+ │ 2. Rev4a generates OpenClaw config │
245
+ │ - Takes template │
246
+ │ - Injects providers from vault │
247
+ │ - Injects service tokens │
248
+ │ - Writes to /docker/shared-config │
249
+ └──────────────┬───────────────────────┘
250
+ │
251
+ ▼
252
+ ┌──────────────────────────────────────┐
253
+ │ 3. Rev4a spawns Docker container │
254
+ │ - docker run openclaw-agent-base │
255
+ │ - Env vars + volumes │
256
+ │ - network: rev4a-net │
257
+ │ - CPU/RAM limits │
258
+ └──────────────┬───────────────────────┘
259
+ │
260
+ ▼
261
+ ┌──────────────────────────────────────┐
262
+ │ 4. Container self-configures │
263
+ │ - Reads config from shared-config │
264
+ │ - Runs healthcheck │
265
+ │ - Registers on Rev4a API │
266
+ └──────────────┬───────────────────────┘
267
+ │
268
+ ▼
269
+ ┌──────────────────────────────────────┐
270
+ │ 5. Agent ONLINE │
271
+ │ - Appears on dashboard │
272
+ │ - Ready to receive tasks │
273
+ └──────────────────────────────────────┘
274
+ ```
275
+
276
+ ### Implemented API endpoints
277
+
278
+ ```
279
+ POST /api/agents/create Create new container agent (template + model)
280
+ DELETE /api/agents/{id} Destructive: remove container + volume + backups
281
+ POST /api/agents/{id}/restart Restart container
282
+ POST /api/agents/{id}/recreate Rebuild from latest image (volume preserved)
283
+ GET /api/agents List all agents (Docker containers with AGENT_ID)
284
+ ```
285
+
286
+ ---
287
+
288
+ ## 6. Shared Volumes
289
+
290
+ ### Shared Skills (`/docker/shared-skills`)
291
+ ```
292
+ /docker/shared-skills/
293
+ my-custom-skill/ # promoted from an agent workspace
294
+ SKILL.md
295
+ another-skill/
296
+ SKILL.md
297
+ ```
298
+
299
+ Skills are stored in a flat structure (no subcategory folders like `core/`, `ops/`, `dev/`).
300
+ This keeps the layout simple and avoids hierarchy debates at this stage.
301
+ **Permissions:**
302
+ - Rev4a host: rw (writes during promote, reads for listing)
303
+ - Agent containers: ro (mounted at `/data/.openclaw/shared-skills`)
304
+ - Owner: uid 1000 (node), group: 1000, mode: 2775 (setgid)
305
+
306
+ **Auto-configuration:**
307
+ - The agent base image (`openclaw-agent-base`) pre-configures `skills.load.extraDirs: ["/data/.openclaw/shared-skills"]` so every new agent discovers shared skills automatically.
308
+ - Both create and recreate routes guarantee this via `applyRuntimeConfig()` from `lib/agent-setup.ts`.
309
+ - On first install, create `/docker/shared-skills` with `mkdir -p /docker/shared-skills && chmod 2775 /docker/shared-skills`.
310
+
311
+ ### Rev4a System Rules (`rev4a-rules/`)
312
+
313
+ Versioned in the repo at `rev4a-rules/AGENTS.md`. Deployed to
314
+ `/docker/rev4a-rules/` on every `rev4a serve` startup via
315
+ `ensureRev4aRules()` in `bin/rev4a.js`. Mounted read-only into every
316
+ agent container and injected into sessions through the
317
+ `bootstrap-extra-files` hook (glob `.rev4a/*.md`).
318
+
319
+ All shared volumes are defined in `lib/agent-setup.ts` — a single source
320
+ of truth used by both create and recreate API routes.
321
+
322
+ ### Shared Repositories (`/docker/shared-repos`)
323
+ ```
324
+ /docker/shared-repos/
325
+ rev4a/ # the Rev4a repo
326
+ projects/ # project repos for agents to work on
327
+ ```
328
+ **Permissions:** rw for Rev4a and agents that need to write code.
329
+
330
+ ---
331
+
332
+ ## 7. Networking
333
+
334
+ All containers on the same Docker bridge network:
335
+
336
+ ```yaml
337
+ networks:
338
+ rev4a-net:
339
+ driver: bridge
340
+ ipam:
341
+ config:
342
+ - subnet: 172.28.0.0/16
343
+ ```
344
+
345
+ **Communication:**
346
+ - Agent → Rev4a Gateway: `http://rev4a-control:3721`
347
+ - Agent → Rev4a Dashboard: `http://rev4a-control:3720`
348
+ - Rev4a → Agent (healthcheck): `http://agent-{id}:3000`
349
+ - Traefik → Agent (external access): via Docker labels
350
+
351
+ ---
352
+
353
+ ## 8. Daemon & Data Pipeline
354
+
355
+ The Rev4a daemon (`daemon.js`) is a standalone Node.js process that bridges the OpenClaw runtime and the SQLite database. It is not part of the Next.js server.
356
+
357
+ ### Responsibilities
358
+
359
+ 1. Poll `openclaw sessions --json --all-agents` on a configurable interval
360
+ 2. Upsert session rows into `events.db`
361
+ 3. Emit `spawn` / `complete` / `error` events into the `events` table
362
+ 4. Collect system metrics (CPU, RAM, disk) every poll cycle
363
+ 5. Detect anomalies (CPU > 90%, RAM > 90%) and log warnings
364
+ 6. Manage DB lifecycle (WAL mode, checkpoint after each cycle)
365
+
366
+ ### Poll Intervals
367
+
368
+ | Condition | Interval |
369
+ |---|---|
370
+ | No active sessions | 30 s |
371
+ | ≥ 1 session with status `working` | 15 s |
372
+
373
+ ### Cost Estimation
374
+
375
+ Costs are estimated from token counts using per-model pricing:
376
+
377
+ | Model key | Match strategy | In (per 1M) | Out (per 1M) |
378
+ |---|---|---|---|
379
+ | `claude-sonnet-4` | substring | $3.00 | $15.00 |
380
+ | `claude-opus-4` | substring | $15.00 | $75.00 |
381
+ | `gpt-5-mini` | substring | $0.15 | $0.60 |
382
+ | `codex` | substring | $3.00 | $15.00 |
383
+ | `gemini` | substring | $0.075 | $0.30 |
384
+ | `flash` | substring | $0.075 | $0.30 |
385
+ | `deepseek` | substring | $0.55 | $2.19 |
386
+ | `default` | fallback | $3.00 | $15.00 |
387
+
388
+ **Aliases** (resolved before substring match):
389
+
390
+ | Alias | Resolves to |
391
+ |---|---|
392
+ | `cheap` | `flash` |
393
+ | `fast` | `claude-sonnet-4` |
394
+ | `big` | `claude-opus-4` |
395
+ | `coder` | `codex` |
396
+ | `pro` | `gemini` |
397
+ | `reason` | `deepseek` |
398
+
399
+ Formula: `cost = (tokens_in / 1_000_000 * price_in) + (tokens_out / 1_000_000 * price_out)`
400
+
401
+ ### Upsert Logic
402
+
403
+ The daemon uses `INSERT … ON CONFLICT DO UPDATE` with these rules:
404
+
405
+ - `updated_at` is only refreshed when tokens or status actually change (avoids phantom updates)
406
+ - `parent_id` is updated only if the incoming value is better (non-null, and current is null or a generic `:main` default)
407
+ - `label` is updated only if the current value is null or still the raw session key (preserves declared names)
408
+ - `ended_at` is set once and never overwritten with null
409
+ - `trello_card_url` is set from `task_preview` on first occurrence; never overwritten
410
+
411
+ ### System Metrics
412
+
413
+ Every poll cycle the daemon records a `system_metrics` row. Data sources:
414
+
415
+ - **CPU**: cgroup v2 usage delta (`/sys/fs/cgroup/cpu.stat`) when available, falls back to `/proc/stat` host ticks
416
+ - **RAM**: `/proc/meminfo`
417
+ - **Disk**: `df -BG /data`
418
+ - **Load**: `os.loadavg()[0]`
419
+
420
+ Metrics older than 24 h are pruned automatically each cycle.
421
+
422
+ ### Anomaly Detection
423
+
424
+ The daemon compares the last two metric samples. If a threshold is exceeded and the cooldown (5 min) has passed, it logs a `WARN` line:
425
+
426
+ | Metric | Threshold |
427
+ |---|---|
428
+ | CPU | > 90% |
429
+ | RAM | > 90% |
430
+
431
+ ### DB Safety
432
+
433
+ - WAL mode + `PRAGMA synchronous = NORMAL` for concurrent read safety
434
+ - `PRAGMA wal_checkpoint(PASSIVE)` runs after each poll cycle
435
+ - On `uncaughtException` the daemon logs but does NOT exit — relies on systemd Restart=always for recovery
436
+
437
+ ### Migrations
438
+
439
+ The daemon applies these migrations at startup if columns don't exist:
440
+
441
+ ```sql
442
+ ALTER TABLE sessions ADD COLUMN trello_card_url TEXT;
443
+ ALTER TABLE sessions ADD COLUMN ended_at INTEGER;
444
+ ```
445
+
446
+ ---
447
+
448
+ ## 9. Migration Plan
449
+
450
+ ### Phase 0 — Preparation (✅ Done)
451
+ - [x] Architecture document exists
452
+ - [x] Rev4a code is in the workspace
453
+ - [x] Git repository on `github.com/Flame0510/rev4a.git`
454
+ - [x] VPS-specific changes merged into `main` branch
455
+
456
+ ### Phase 1 — Container separation
457
+ - [x] `openclaw-atlas` running as standalone container
458
+ - [ ] Create `openclaw-agent-base` Docker image and push to registry
459
+ - [ ] Define shared volume structure
460
+ - [ ] Test cross-container communication
461
+
462
+ ### Phase 2 — Provider Gateway
463
+ - [x] Implement proxy API on Rev4a (`/api/provider/v1/`)
464
+ - [x] Gateway Page (`/gateway`) for provider key management
465
+ - [x] Agent model configuration via Gateway Agents tab
466
+ - [x] Provider sync to agent containers (`PUT /api/gateway/provider`)
467
+ - [x] Auth via rev4a token in `data/provider-keys.json`
468
+ - [ ] Rate limiting per agent
469
+ - [ ] Transparent provider switching (change keys in one place)
470
+
471
+ ### Phase 3 — Full agent extraction
472
+ - [ ] Move Prometheus to its own container
473
+ - [ ] Move Argus to its own container
474
+ - [ ] Rev4a becomes pure orchestrator (no agent sessions)
475
+
476
+ ### Phase 4 — Alternative runtimes
477
+ - [ ] Test Hermes in a dedicated container
478
+ - [ ] Test OpenCode in a dedicated container
479
+ - [ ] Unified dashboard for all runtime types
480
+
481
+ ### Phase 5 — Automation
482
+ - [ ] `rev4a agents spawn` CLI command
483
+ - [ ] Auto-scaling? (spawn more agents under load)
484
+ - [ ] Automated vault + config backups
485
+
486
+ ---
487
+
488
+ ## 10. Open Questions
489
+
490
+ 1. **Provider Gateway: custom proxy or existing product?**
491
+ - Option A: Homemade proxy (Node.js, lightweight, integrated in Rev4a)
492
+ - Option B: LiteLLM / Portkey (more features, heavier)
493
+ - Recommendation: start with homemade (A) — Rev4a is already Node.js
494
+
495
+ 2. **Memory: centralized or distributed?**
496
+ - Centralized: simpler, single DB, single point of contention
497
+ - Distributed: per-agent memory, Rev4a indexes centrally — more resilient
498
+ - Recommendation: distributed with central index
499
+
500
+ 3. **Traefik routing: should agents be externally reachable?**
501
+ - If yes: per-agent Traefik labels managed by Rev4a
502
+ - If no: internal Docker network only
503
+ - Recommendation: no by default, yes only for agents serving APIs/UI
504
+
505
+ 4. **Hermes and other frameworks: dashboard integration?**
506
+ - Hermes has its own session format
507
+ - Rev4a daemon should have "adapters" for different runtimes
508
+ - Or Hermes exposes an API compatible with OpenClaw format
509
+
510
+ 5. **Resource calc: enough for 3-4 agent containers?**
511
+ - Estimate: 1 Rev4a (~500 MB) + 3 agents (~2 GB each) = 6.5 GB RAM
512
+ - CPU: with limits, 3-4 agents should run fine
513
+ - Monitor: if saturated, consider VPS upgrade
514
+
515
+ ---
516
+
517
+ ## 11. Container Terminal
518
+
519
+ Rev4a provides a real, interactive terminal for any agent container via
520
+ a WebSocket-connected PTY. The implementation is documented in detail in
521
+ [docs/container-terminal.md](container-terminal.md).
522
+
523
+ ### Two-process architecture
524
+
525
+ | Process | Port | Role |
526
+ |---|---|---|
527
+ | `rev4a-next` (Next.js) | 3740 | Serves the terminal page, auth, API |
528
+ | `rev4a-terminal-ws` (standalone) | 3741 | WebSocket PTY server via `node-pty` |
529
+
530
+ The terminal server runs as a separate systemd service (rev4a-terminal-ws) to avoid event-loop
531
+ contention with Next.js during high-throughput I/O.
532
+
533
+ ### Why custom DOM over xterm.js
534
+
535
+ The initial implementation used xterm.js (both canvas and DOM renderers).
536
+ Both suffered from black-screen-on-large-output and broken scrolling due to
537
+ CSS conflicts. The current implementation uses a plain `<div>` with native
538
+ browser scrolling and a hidden `<textarea>` for input — stable under any
539
+ output volume.
540
+
541
+ See [container-terminal.md](container-terminal.md#terminal-client-browser)
542
+ for the full rationale.
543
+
544
+ ## 12. Technology Stack
545
+
546
+ | Layer | Technology | Notes |
547
+ |---|---|---|
548
+ | Orchestrator | Docker / Docker Compose | Already in use |
549
+ | Dashboard | Next.js 16 + React 19 | Current Rev4a |
550
+ | Provider Gateway | Express/Fastify (Node.js) | To implement in Rev4a |
551
+ | Database | SQLite (WAL mode) | Current `events.db`, may need to scale |
552
+ | Memory | Per-agent SQLite + central index | New |
553
+ | Config | Generated YAML/JSON | New |
554
+ | Vault | SQLite + JSON | Current: credentials.db + provider-keys.json. Future: encrypted |
555
+ | Reverse proxy | Traefik | Already in use |
556
+ | Monitoring | Rev4a daemon (extended) | Evolution of current daemon |
557
+ | Version control | Git + GitHub | `github.com/Flame0510/rev4a.git` |