@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,607 @@
1
+ # Session Maintenance Integration Plan
2
+
3
+ > **Created:** 2026-08-04
4
+ > **Status:** Proposal — not yet implemented
5
+ > **Based on:** OpenClaw docs v2026.1.x — session maintenance, pruning, compaction, transcript hygiene
6
+
7
+ ---
8
+
9
+ ## 1. What OpenClaw Provides (Reference)
10
+
11
+ Rev4a already reads session state via the daemon (`daemon.js`) polling `openclaw sessions --json --all-agents`. The proposed integration adds **read + write** access to OpenClaw's built-in maintenance controls.
12
+
13
+ ### 1.1 `session.maintenance` (store + transcript cleanup)
14
+
15
+ ```json5
16
+ {
17
+ session: {
18
+ maintenance: {
19
+ mode: "warn", // "warn" | "enforce"
20
+ pruneAfter: "30d", // age cutoff for stale entries
21
+ maxEntries: 500, // cap on sessions.json entries
22
+ resetArchiveRetention: "30d", // retention for *.reset.<timestamp> archives
23
+ maxDiskBytes: "500mb", // optional hard budget
24
+ highWaterBytes: "400mb", // optional target after cleanup (default: 80% of maxDiskBytes)
25
+ }
26
+ }
27
+ }
28
+ ```
29
+
30
+ **Enforcement order** (`mode: "enforce"`):
31
+ 1. Remove oldest unreferenced transcript/trajectory artifacts first.
32
+ 2. If still over `highWaterBytes`, evict oldest session entries + their files.
33
+ 3. Keep going until at or below `highWaterBytes`.
34
+
35
+ **CLI:**
36
+ ```bash
37
+ openclaw sessions cleanup --dry-run # preview
38
+ openclaw sessions cleanup --enforce # apply
39
+ openclaw sessions cleanup --all-agents # all configured agents
40
+ ```
41
+
42
+ ### 1.2 `session.reset` (session rotation)
43
+
44
+ ```json5
45
+ {
46
+ session: {
47
+ reset: {
48
+ mode: "daily", // "daily" | "idle"
49
+ atHour: 4, // daily reset hour (local TZ)
50
+ idleMinutes: 60, // idle reset threshold
51
+ },
52
+ resetByType: {
53
+ direct: { mode: "idle", idleMinutes: 240 },
54
+ group: { mode: "idle", idleMinutes: 120 },
55
+ thread: { mode: "daily", atHour: 4 },
56
+ },
57
+ }
58
+ }
59
+ ```
60
+
61
+ Background events (heartbeat, cron, exec notifications) do **not** keep daily/idle sessions fresh.
62
+
63
+ ### 1.3 `contextPruning` (in-memory tool-result trimming)
64
+
65
+ ```json5
66
+ {
67
+ agents: {
68
+ defaults: {
69
+ contextPruning: { mode: "cache-ttl", ttl: "5m" }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ Does not modify transcripts. Reduces context bloat from accumulated tool outputs.
76
+
77
+ ### 1.4 `compaction` refinements
78
+
79
+ ```json5
80
+ {
81
+ agents: {
82
+ defaults: {
83
+ compaction: {
84
+ model: "ollama/qwen3:8b", // dedicated summarization model
85
+ memoryFlush: { enabled: true }, // silent memory save before compaction
86
+ truncateAfterCompaction: true, // rotate to successor transcript
87
+ maxActiveTranscriptBytes: "20mb", // file-size guard for local reopen
88
+ midTurnPrecheck: { enabled: true }, // tool-loop guard
89
+ notifyUser: true, // show compaction status in chat
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### 1.5 `cron.sessionRetention` + `cron.runLog`
97
+
98
+ ```json5
99
+ {
100
+ cron: {
101
+ sessionRetention: "24h", // prune isolated cron sessions
102
+ runLog: { maxBytes: 2_000_000, keepLines: 2000 }
103
+ }
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ## 2. Integration Scope
110
+
111
+ ### Phase A — Read-only: Show current state
112
+
113
+ - [ ] **Maintenance status card** — new card on the Sessions page showing current `session.maintenance` config and disk usage stats
114
+ - [ ] **Pruning/compaction indicators** — per-agent badges showing whether pruning is enabled, compaction count, last compaction timestamp
115
+
116
+ ### Phase B — Configuration UI
117
+
118
+ - [ ] **New page: `/maintenance`** (or section inside `/sessions`)
119
+ - Configure `session.maintenance.mode`, `pruneAfter`, `maxEntries`, `maxDiskBytes`, `highWaterBytes`
120
+ - Configure `session.reset` (mode, atHour, idleMinutes, resetByType overrides)
121
+ - Configure `contextPruning` (mode, ttl)
122
+ - Configure compaction knobs (model, truncation, memory flush)
123
+ - [ ] **Write back to `openclaw.json`** via `POST /api/maintenance/config`
124
+
125
+ ### Phase C — Trigger actions
126
+
127
+ - [ ] **"Run Cleanup Now" button** — triggers `openclaw sessions cleanup` with dry-run preview
128
+ - API: `POST /api/maintenance/cleanup` with `{ dryRun: true/false }`
129
+ - [ ] **Per-agent cleanup** — cleanup for a single agent
130
+ - [ ] **Scheduled cleanup** — register a cron job in `openclaw.json` that runs periodic cleanup
131
+
132
+ ### Phase D — Dashboard widgets
133
+
134
+ - [ ] **Disk health card** — sessions directory size, trajectory sidecars, orphan count
135
+ - [ ] **Retention timeline** — visual of sessions aging toward prune cutoff
136
+ - [ ] **Compaction history** — per-agent compaction counts + timestamps
137
+
138
+ ---
139
+
140
+ ## 3. API Design
141
+
142
+ ### `GET /api/sessions/maintenance`
143
+
144
+ Returns current maintenance status from all agent stores.
145
+
146
+ ```json
147
+ {
148
+ "agents": [
149
+ {
150
+ "agentId": "atlas",
151
+ "storePath": "/root/.openclaw/agents/main/sessions/sessions.json",
152
+ "entryCount": 47,
153
+ "diskBytes": 2457600,
154
+ "config": {
155
+ "mode": "warn",
156
+ "pruneAfter": "30d",
157
+ "maxEntries": 500,
158
+ "maxDiskBytes": null,
159
+ "highWaterBytes": null,
160
+ "resetArchiveRetention": "30d"
161
+ },
162
+ "staleCount": 12,
163
+ "orphanCount": 3
164
+ }
165
+ ],
166
+ "summary": {
167
+ "totalEntries": 120,
168
+ "totalDiskBytes": 5242880,
169
+ "totalStale": 28,
170
+ "warnings": ["85% of disk budget used for agent: atlas"]
171
+ }
172
+ }
173
+ ```
174
+
175
+ **Implementation:**
176
+ - Host agent: read `~/.openclaw/agents/<id>/sessions/sessions.json` + parse config
177
+ - Container agents: `docker exec` to read the same paths
178
+ - Disk usage: `du -s` on the sessions directory
179
+
180
+ ### `POST /api/sessions/maintenance/config`
181
+
182
+ Write maintenance config to an agent's `openclaw.json`.
183
+
184
+ **Body:**
185
+ ```json
186
+ {
187
+ "agentId": "atlas",
188
+ "maintenance": {
189
+ "mode": "enforce",
190
+ "pruneAfter": "14d",
191
+ "maxEntries": 300,
192
+ "maxDiskBytes": "200mb",
193
+ "highWaterBytes": "160mb"
194
+ }
195
+ }
196
+ ```
197
+
198
+ **Side effects:**
199
+ - Writes `session.maintenance.*` into the agent's `openclaw.json` via `openclaw config patch`
200
+ - No restart needed (read at runtime)
201
+
202
+ ### `POST /api/sessions/maintenance/cleanup`
203
+
204
+ Trigger a cleanup run. Supports dry-run + per-agent scope.
205
+
206
+ **Body:**
207
+ ```json
208
+ {
209
+ "agentId": "atlas",
210
+ "dryRun": true
211
+ }
212
+ ```
213
+
214
+ **Response (dry-run):**
215
+ ```json
216
+ {
217
+ "agentId": "atlas",
218
+ "dryRun": true,
219
+ "beforeCount": 47,
220
+ "afterCount": 35,
221
+ "pruned": 12,
222
+ "capped": 0,
223
+ "diskFreedBytes": 1024000
224
+ }
225
+ ```
226
+
227
+ **Implementation:**
228
+ - Host agent: `openclaw sessions cleanup --agent <id> --dry-run --json`
229
+ - Container agents: `docker exec openclaw-atlas openclaw sessions cleanup --dry-run --json`
230
+
231
+ ### `POST /api/sessions/maintenance/schedule`
232
+
233
+ Register a cleanup cron job on the host gateway or inside an agent container.
234
+
235
+ **Body:**
236
+ ```json
237
+ {
238
+ "agentId": "atlas",
239
+ "schedule": "0 3 * * 0", // weekly Sunday 3 AM
240
+ "mode": "enforce"
241
+ }
242
+ ```
243
+
244
+ **Implementation:**
245
+ - Uses `openclaw cron add` inside the target container or host
246
+ - Creates an `agentTurn` job that runs `openclaw sessions cleanup --enforce`
247
+
248
+ ---
249
+
250
+ ## 4. UI/UX Design — Complete User Flow
251
+
252
+ ### 4.0 Entry Point & Navigation
253
+
254
+ User lands on `/maintenance` from the sidebar (between `Sessions` and `Crons`). A badge on the nav item shows the total stale entry count when > 0.
255
+
256
+ **Top-level structure:** Two tabs — `[Overview]` (default) and `[Settings]`.
257
+
258
+ ### 4.0a Complete Interaction Flow
259
+
260
+ ```
261
+ User lands on /maintenance (Overview tab — read-only)
262
+ │
263
+ ├── Tab: Overview ──────────────────────────────┐
264
+ │ │ │
265
+ │ ├── View aggregate metrics (all agents) │
266
+ │ ├── View per-agent status cards │
267
+ │ │ │ │
268
+ │ │ ├── [Dry-Run] → inline preview │
269
+ │ │ │ └── Preview expanded │
270
+ │ │ │ ├── [Apply this cleanup] → confirm modal → execute → toast
271
+ │ │ │ └── [Dismiss] → collapse │
272
+ │ │ │ │
273
+ │ │ └── [Apply] → confirm modal │
274
+ │ │ └── Confirm → execute → toast │
275
+ │ │
276
+ └── Tab: Settings ────────────────────────────┐ │
277
+ │ │ │
278
+ ├── Select agent from left ItemList │ │
279
+ ├── View/Edit config (right panel) │ │
280
+ │ ├── Cleanup section │ │
281
+ │ ├── Disk Budget section │ │
282
+ │ ├── Session Reset section │ │
283
+ │ │ └── [Configure ▸] → modal │ │
284
+ │ ├── Context Pruning section │ │
285
+ │ ├── Compaction section │ │
286
+ │ └── Scheduled Cleanup section │ │
287
+ │ │ │
288
+ └── [Save Configuration] → toast │ │
289
+ └─┘
290
+ ```
291
+
292
+ ---
293
+
294
+ ### 4.1 Overview Tab
295
+
296
+ **Purpose:** At-a-glance health of all agent session stores. Read-only except for dry-run → apply actions.
297
+
298
+ **Full layout:**
299
+
300
+ ```
301
+ ┌──────────────────────────────────────────────────────────────┐
302
+ │ [Overview] [Settings] │
303
+ │ │
304
+ │ ┌────────────┬────────────┬────────────┬────────────────┐ │
305
+ │ │ Sessions │ Disk Usage │ Stale │ Mode │ │
306
+ │ │ 120 total │ 5.2 MB │ 28 (>30d) │ warn ⚠️ │ │
307
+ │ └────────────┴────────────┴────────────┴────────────────┘ │
308
+ │ │
309
+ │ Agents │
310
+ │ ┌────────────────────────────────────────────────────────┐ │
311
+ │ │ ● atlas warn 47 sessions │ │
312
+ │ │ ▓▓▓▓▓▓▓▓▓░░░ 2.4 MB 12 stale · 3 orphans │ │
313
+ │ │ [Dry-Run] [Apply]│ │
314
+ │ │ ┌────────────────────────────────────────────────────┐ │ │
315
+ │ │ │ 🔍 Dry-Run Results │ │ │
316
+ │ │ │ ──────────────── │ │ │
317
+ │ │ │ Entries: 47 → 35 (-12, 0 capped) │ │ │
318
+ │ │ │ Disk: 2.4 MB → 1.8 MB (-600 KB) │ │ │
319
+ │ │ │ • 9 entries >30d — pruned │ │ │
320
+ │ │ │ • 3 orphan transcripts — removed │ │ │
321
+ │ │ │ • 0 entries capped │ │ │
322
+ │ │ │ [Apply this cleanup] [Dismiss] │ │ │
323
+ │ │ └────────────────────────────────────────────────────┘ │ │
324
+ │ ├────────────────────────────────────────────────────────┤ │
325
+ │ │ ○ prometheus warn 18 sessions │ │
326
+ │ │ ▓▓▓▓▓▓▓░░░░░ 0.8 MB 2 stale · 0 orphans │ │
327
+ │ │ [Dry-Run] [Apply]│ │
328
+ │ └────────────────────────────────────────────────────────┘ │
329
+ └──────────────────────────────────────────────────────────────┘
330
+ ```
331
+
332
+ **Interaction details:**
333
+
334
+ 1. **Top metric row** — 4 `Metric` cards showing aggregate totals across all agents
335
+ 2. **Agent cards** — one `Surface` per agent, showing:
336
+ - Agent name + mode `Badge` (`warn` yellow / `enforce` green)
337
+ - Session count with a horizontal bar (fill = sessionCount / maxEntries, color: green <50%, yellow <80%, red >90%)
338
+ - Disk usage bar (same color logic, fill = currentBytes / maxDiskBytes)
339
+ - Stale count + orphan count
340
+ - Two `Button` components: `[Dry-Run]` (secondary) and `[Apply]` (danger)
341
+ 3. **Dry-Run** click → `CleanupResult` component expands inline below the card with a smooth height transition
342
+ 4. **Apply** click from card → opens the confirm modal directly (skips preview)
343
+ 5. **Apply this cleanup** click from expanded Dry-Run → opens the same confirm modal
344
+ 6. **Dismiss** → collapses the inline result
345
+
346
+ **Confirm modal (Apply):**
347
+ ```
348
+ ┌──────────────────────────────────────────────┐
349
+ │ Apply Cleanup — atlas │
350
+ │ │
351
+ │ This will permanently remove: │
352
+ │ • 12 stale session entries (>30d) │
353
+ │ • 3 orphan transcript files │
354
+ │ │
355
+ │ ⚠️ This cannot be undone. │
356
+ │ │
357
+ │ [Confirm & Cleanup] [Cancel] │
358
+ └──────────────────────────────────────────────┘
359
+ ```
360
+
361
+ **Loading states:**
362
+ - `[Dry-Run]` → shows "Analyzing…" with spinner on the button
363
+ - `[Apply]` → shows "Cleaning…" with spinner on the button
364
+ - During cleanup, the confirm modal's `[Confirm & Cleanup]` shows spinner, both buttons disabled
365
+
366
+ **Success:** Toast `✓ Cleanup complete — atlas. Removed 12 entries, freed 600 KB.`
367
+
368
+ ---
369
+
370
+ ### 4.2 Settings Tab
371
+
372
+ **Purpose:** Configure `session.maintenance`, `session.reset`, `contextPruning`, and `compaction` per agent. Dual-panel layout.
373
+
374
+ **Full layout:**
375
+
376
+ ```
377
+ ┌──────────────────────────────────────────────────────────────────┐
378
+ │ [Overview] [Settings] │
379
+ │ │
380
+ │ ┌──────────────┐ ┌──────────────────────────────────────────┐ │
381
+ │ │ Agents │ │ Maintenance — atlas │ │
382
+ │ │ │ │ │ │
383
+ │ │ ● atlas │ │ ── Cleanup ── │ │
384
+ │ │ warn 47 │ │ Mode: ○ Warn ● Enforce │ │
385
+ │ │ │ │ Prune After: [ 30 ] days │ │
386
+ │ │ ○ prometheus │ │ Max Entries: [ 500 ] │ │
387
+ │ │ warn 18 │ │ Reset Archives: [ 30 ] days [Disable] │ │
388
+ │ │ │ │ │ │
389
+ │ │ ○ argus │ │ ── Disk Budget (optional) ── │ │
390
+ │ │ enforce 73 │ │ Max Disk: [ 500 ] MB │ │
391
+ │ │ │ │ High Water: [ 400 ] MB (80% of max) │ │
392
+ │ │ │ │ │ │
393
+ │ │ │ │ ── Session Reset ── │ │
394
+ │ │ │ │ Mode: ● Daily at [04]:00 │ │
395
+ │ │ │ │ ○ Idle after [60] min │ │
396
+ │ │ │ │ Per-type overrides: [Configure ▸] │ │
397
+ │ │ │ │ │ │
398
+ │ │ │ │ ── Context Pruning ── │ │
399
+ │ │ │ │ Mode: ● Off │ │
400
+ │ │ │ │ ○ cache-ttl [ 5 ] min │ │
401
+ │ │ │ │ │ │
402
+ │ │ │ │ ── Compaction ── │ │
403
+ │ │ │ │ Memory Flush: [✓] Enabled │ │
404
+ │ │ │ │ Truncate: [✓] Enabled │ │
405
+ │ │ │ │ Max Transcript: [ 20 ] MB │ │
406
+ │ │ │ │ Mid-turn guard: [ ] Enabled │ │
407
+ │ │ │ │ Notify User: [✓] Enabled │ │
408
+ │ │ │ │ Dedicated model: [ollama/qwen3:8b ▾] │ │
409
+ │ │ │ │ │ │
410
+ │ │ │ │ ── Scheduled Cleanup ── │ │
411
+ │ │ │ │ [✓] Run automatically │ │
412
+ │ │ │ │ Schedule: [0 3 * * 0 ▾] Weekly Sun 3AM│ │
413
+ │ │ │ │ Quick: [Daily] [Weekly] [Monthly] │ │
414
+ │ │ │ │ Mode: ● Enforce ○ Dry-run only │ │
415
+ │ │ │ │ Next run: Sun, Aug 10 2026 03:00 │ │
416
+ │ │ │ │ Last run: never │ │
417
+ │ │ │ │ │ │
418
+ │ │ │ │ [Save Configuration] │ │
419
+ │ └──────────────┘ └──────────────────────────────────────────┘ │
420
+ └──────────────────────────────────────────────────────────────────┘
421
+ ```
422
+
423
+ **Interaction details:**
424
+
425
+ 1. **Left panel — Agent selector** (`ItemList`):
426
+ - Each agent row shows name + mode badge + session count
427
+ - Active agent is highlighted (●)
428
+ - Clicking an agent loads its config into the right panel
429
+ - If user has unsaved changes, show a confirmation before switching
430
+
431
+ 2. **Right panel — Config form**:
432
+ - Each section has a section header (e.g. `── Cleanup ──`)
433
+ - Radio buttons for mode selections (Warn/Enforce, Daily/Idle, Off/cache-ttl)
434
+ - Number inputs for thresholds (days, MB, entries)
435
+ - Checkboxes for boolean toggles
436
+ - `Select` dropdown for the compaction model
437
+ - The `[Disable]` button on Reset Archives sets the value to `false`
438
+ - `[Configure ▸]` opens the Per-type overrides modal
439
+
440
+ 3. **Button state logic:**
441
+ - No changes → `[Save Configuration]` is disabled (grey/greyed-out primary)
442
+ - Any field changed → button becomes active (primary/blue)
443
+ - After save → disabled again, toast confirms "Configuration saved"
444
+
445
+ **Per-type Overrides Modal** (triggered by `[Configure ▸]`):
446
+
447
+ ```
448
+ ┌──────────────────────────────────────────────┐
449
+ │ Session Reset — Per-Type Overrides │
450
+ │ │
451
+ │ Direct: ● Daily at [04]:00 │
452
+ │ ○ Idle after [240] min │
453
+ │ ○ Inherit (from global) │
454
+ │ │
455
+ │ Group: ○ Daily at [04]:00 │
456
+ │ ○ Idle after [120] min │
457
+ │ ● Inherit (from global) │
458
+ │ │
459
+ │ Thread: ○ Daily at [04]:00 │
460
+ │ ○ Idle after [60] min │
461
+ │ ● Inherit (from global) │
462
+ │ │
463
+ │ [Save] [Cancel] │
464
+ └──────────────────────────────────────────────┘
465
+ ```
466
+
467
+ - Three rows: Direct, Group, Thread
468
+ - Each row: mode radio + value input
469
+ - "Inherit (from global)" means no override — uses the parent config
470
+ - Modal Save merges into the main form state (not saved independently)
471
+
472
+ **Scheduled Cleanup — Quick Presets:**
473
+ - `[Daily]` → fills `0 3 * * *` (every day at 3 AM)
474
+ - `[Weekly]` → fills `0 3 * * 0` (Sunday at 3 AM)
475
+ - `[Monthly]` → fills `0 3 1 * *` (1st of month at 3 AM)
476
+ - User can still type a custom cron expression manually
477
+ - "Next run" preview updates reactively as the schedule changes
478
+ - "Last run" reads from cron run history (nullable, shows "never" if no runs)
479
+
480
+ ---
481
+
482
+ ### 4.3 Component Checklist
483
+
484
+ | New Component | Location | Purpose |
485
+ |---|---|---|
486
+ | `MaintenancePageClient` | `app/maintenance/PageClient.tsx` | Page shell, tab state, top-level data fetching |
487
+ | `MaintenanceOverview` | `app/maintenance/Overview.tsx` | Aggregate metric cards + agent card list |
488
+ | `AgentMaintenanceCard` | `app/maintenance/AgentCard.tsx` | Single agent: bars, dry-run/apply, expands inline result |
489
+ | `CleanupResult` | `app/maintenance/CleanupResult.tsx` | Inline expandable cleanup preview/result (shared by Overview + Settings) |
490
+ | `MaintenanceSettings` | `app/maintenance/Settings.tsx` | Dual-panel: agent selector + config form |
491
+ | `MaintenanceConfigForm` | `app/maintenance/ConfigForm.tsx` | Config editor with all sections, dirty-tracking, save |
492
+ | `ResetOverridesModal` | `app/maintenance/ResetOverridesModal.tsx` | Per-type reset override modal (direct/group/thread) |
493
+ | `ConfirmCleanupModal` | `app/maintenance/ConfirmCleanupModal.tsx` | Confirmation dialog before destructive cleanup |
494
+
495
+ **Reused from `ui/`:** `Page`, `PageHeader`, `Surface`, `Metric`, `Button`, `Select`, `Input`, `Tabs`, `ItemList`, `Pill`, `Badge`, `Toast`, `Modal`, `LoadingSpinner`.
496
+
497
+ **Zero new visual primitives.** All layout uses existing components + inline style on wrapping `<div>` elements only. Interactive elements are `<button type="button">` with `aria-label`.
498
+
499
+ ---
500
+
501
+ ## 5. Data Flow
502
+
503
+ ```
504
+ Rev4a UI Rev4a API Agent Container
505
+ ───────── ─────────── ────────────────
506
+
507
+ GET /api/sessions/maintenance
508
+ │ docker exec openclaw-atlas \
509
+ │ openclaw sessions cleanup \
510
+ │ --dry-run --json
511
+ │ du -s /root/.openclaw/agents/*/sessions/
512
+ │ │
513
+ │◄── JSON ──────────────────│
514
+ │ │
515
+ POST /api/sessions/maintenance/config
516
+ │ │
517
+ │ │── docker exec openclaw-atlas \
518
+ │ │ openclaw config patch --stdin
519
+ │ │ (writes session.maintenance)
520
+ │ │
521
+ │◄── OK ────────────────────│
522
+
523
+ POST /api/sessions/maintenance/cleanup
524
+ │ │
525
+ │ │── docker exec openclaw-atlas \
526
+ │ │ openclaw sessions cleanup \
527
+ │ │ --enforce --json
528
+ │ │
529
+ │◄── result ────────────────│
530
+ ```
531
+
532
+ ---
533
+
534
+ ## 6. Implementation Plan
535
+
536
+ ### Sprint 1: Read-only status (2-3 days)
537
+
538
+ 1. Create `GET /api/sessions/maintenance` endpoint
539
+ - Read config from agents' `openclaw.json` (host + containers)
540
+ - Count entries in `sessions.json`
541
+ - Compute disk usage via `du`
542
+ - Identify stale entries (older than `pruneAfter`)
543
+ 2. Create `MaintenancePageClient` + `MaintenanceOverview` + `AgentMaintenanceCard`
544
+ 3. Wire into sidebar navigation
545
+ 4. Add to `docs/FRONTEND-ARCHITECTURE.md` and `docs/REV4A.md`
546
+
547
+ ### Sprint 2: Configuration (2 days)
548
+
549
+ 1. Create `POST /api/sessions/maintenance/config` endpoint
550
+ - Write `session.maintenance` into target `openclaw.json`
551
+ - Validate duration strings (`"30d"`, `"500mb"`, etc.)
552
+ 2. Create `MaintenanceConfigForm` component
553
+ 3. Add session reset + context pruning + compaction controls
554
+
555
+ ### Sprint 3: Trigger actions (1-2 days)
556
+
557
+ 1. Create `POST /api/sessions/maintenance/cleanup` endpoint
558
+ - Dry-run + enforce modes
559
+ - Per-agent or all-agents scope
560
+ 2. Create `CleanupResult` component
561
+ 3. Create `POST /api/sessions/maintenance/schedule` endpoint
562
+ - Register periodic cleanup cron
563
+
564
+ ### Sprint 4: Dashboard widgets (1 day)
565
+
566
+ 1. Disk health card on `/dashboard`
567
+ 2. Retention timeline widget
568
+ 3. Compaction history widget
569
+
570
+ ---
571
+
572
+ ## 7. Open Questions
573
+
574
+ 1. **Host vs container scoping:** The `openclaw sessions cleanup` command is per-agent-store. Should the Rev4a `/maintenance` page scope by agent or show host-level aggregate? _Recommendation: per-agent with aggregate overview._
575
+
576
+ 2. **Write-back auth:** Writing `session.maintenance` config into agent containers requires `docker exec` access. Already used by Gateway sync — no new permissions needed.
577
+
578
+ 3. **Cron session retention:** `cron.sessionRetention` is separate from `session.maintenance`. Should Rev4a expose this too? _Recommendation: yes, add to the cron page or as a maintenance sub-tab._
579
+
580
+ 4. **Scheduling cleanup as a cron job:** Who owns the cleanup cron? Options:
581
+ - Host gateway cron (runs for all agents)
582
+ - Per-agent container cron (each agent cleans itself)
583
+ _Recommendation: per-agent container cron by default, host-level as optional override._
584
+
585
+ ---
586
+
587
+ ## 8. Doc Checklist (for final PR)
588
+
589
+ - [ ] `docs/REV4A.md` — new `/maintenance` page
590
+ - [ ] `docs/FRONTEND-ARCHITECTURE.md` — new components
591
+ - [ ] `docs/dev/API-REFERENCE.md` — new endpoints
592
+ - [ ] `docs/ARCHITECTURE.md` — maintenance subsystem if needed
593
+ - [ ] `docs/DESIGN-SYSTEM.md` — no new tokens needed (reuses existing)
594
+ - [ ] `docs/dev/GATEWAY.md` — applicable? Unlikely unless agent-level config changes
595
+
596
+ ---
597
+
598
+ ## 9. References
599
+
600
+ - [Session maintenance](/concepts/session) — OpenClaw docs
601
+ - [Session management deep dive](/reference/session-management-compaction) — store schema + maintenance rules
602
+ - [Compaction](/concepts/compaction) — auto + manual compaction
603
+ - [Session pruning](/concepts/session-pruning) — tool-result trimming
604
+ - [Transcript hygiene](/reference/transcript-hygiene) — provider-specific fixups
605
+ - [Cron jobs](/automation/cron-jobs) — cron.sessionRetention + run log config
606
+ - [Rev4a API Reference](API-REFERENCE.md)
607
+ - [Rev4a Frontend Architecture](../FRONTEND-ARCHITECTURE.md)