somora 2026.930.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +364 -0
  3. package/bin/node-version.d.mts +3 -0
  4. package/bin/node-version.mjs +45 -0
  5. package/bin/somora.mjs +77 -0
  6. package/config.example.yaml +896 -0
  7. package/docs/agents.md +677 -0
  8. package/docs/api.md +3194 -0
  9. package/docs/browser.md +317 -0
  10. package/docs/builder.md +331 -0
  11. package/docs/cache-strategy.md +373 -0
  12. package/docs/compaction.md +253 -0
  13. package/docs/display.md +154 -0
  14. package/docs/dream-phases.md +891 -0
  15. package/docs/files.md +387 -0
  16. package/docs/imagegen.md +366 -0
  17. package/docs/images/somora-hero.png +0 -0
  18. package/docs/images/somora-mobile-2026-05-23.png +0 -0
  19. package/docs/images/somora-tui-2026-05-23.png +0 -0
  20. package/docs/images/somora-web-2026-05-23.png +0 -0
  21. package/docs/index.md +178 -0
  22. package/docs/lsp.md +93 -0
  23. package/docs/mcp.md +332 -0
  24. package/docs/memory.md +407 -0
  25. package/docs/mobile.md +310 -0
  26. package/docs/models.md +379 -0
  27. package/docs/projects.md +425 -0
  28. package/docs/realtime-voice.md +293 -0
  29. package/docs/resources.md +230 -0
  30. package/docs/sampling.md +128 -0
  31. package/docs/security.md +189 -0
  32. package/docs/sentinel.md +295 -0
  33. package/docs/setup.md +1217 -0
  34. package/docs/skills.md +501 -0
  35. package/docs/team.md +189 -0
  36. package/docs/thinking.md +463 -0
  37. package/docs/tmux.md +399 -0
  38. package/docs/tools.md +117 -0
  39. package/docs/videogen.md +191 -0
  40. package/docs/voice.md +288 -0
  41. package/docs/web.md +893 -0
  42. package/docs/wiki.md +583 -0
  43. package/npm-shrinkwrap.json +5670 -0
  44. package/package.json +116 -0
  45. package/src/attachments/store.ts +196 -0
  46. package/src/browser/change-stream.ts +31 -0
  47. package/src/browser/display.ts +108 -0
  48. package/src/browser/policy.ts +121 -0
  49. package/src/browser/screencast.ts +374 -0
  50. package/src/browser/service.ts +1337 -0
  51. package/src/browser/session.ts +15 -0
  52. package/src/browser/snapshot.ts +40 -0
  53. package/src/cli/auth.ts +117 -0
  54. package/src/cli/codex.ts +41 -0
  55. package/src/cli/lsp.ts +71 -0
  56. package/src/cli/resolvers/clawhub.ts +400 -0
  57. package/src/cli/setup.ts +835 -0
  58. package/src/cli/skill.ts +619 -0
  59. package/src/cli/somora.ts +548 -0
  60. package/src/cli/systemd-unit.ts +72 -0
  61. package/src/cli/team.ts +148 -0
  62. package/src/cli/tui/activity-stream.ts +121 -0
  63. package/src/cli/tui/api.ts +479 -0
  64. package/src/cli/tui/app.tsx +1169 -0
  65. package/src/cli/tui/autocomplete.tsx +55 -0
  66. package/src/cli/tui/commands.ts +913 -0
  67. package/src/cli/tui/dream-glyphs.ts +22 -0
  68. package/src/cli/tui/footer.tsx +15 -0
  69. package/src/cli/tui/format.ts +28 -0
  70. package/src/cli/tui/header.tsx +279 -0
  71. package/src/cli/tui/index.tsx +120 -0
  72. package/src/cli/tui/markdown.tsx +63 -0
  73. package/src/cli/tui/sampling.ts +162 -0
  74. package/src/cli/tui/separator.tsx +13 -0
  75. package/src/cli/tui/state.ts +42 -0
  76. package/src/cli/tui/stream.ts +330 -0
  77. package/src/cli/tui/thinking-text.ts +54 -0
  78. package/src/cli/tui/turn-views.tsx +499 -0
  79. package/src/cli/tui/types.ts +410 -0
  80. package/src/cli/tui/work-queue.ts +161 -0
  81. package/src/cli/update-args.ts +55 -0
  82. package/src/cli/wiki.ts +406 -0
  83. package/src/compaction/index.ts +28 -0
  84. package/src/compaction/midturn.ts +210 -0
  85. package/src/compaction/policy.ts +154 -0
  86. package/src/compaction/summarize.ts +691 -0
  87. package/src/compaction/template.ts +90 -0
  88. package/src/compaction/types.ts +148 -0
  89. package/src/config/loader.ts +276 -0
  90. package/src/config/reload.ts +43 -0
  91. package/src/config/types.ts +2292 -0
  92. package/src/dream/deep-actions.ts +324 -0
  93. package/src/dream/deep-dispatcher.ts +237 -0
  94. package/src/dream/deep-llm.ts +388 -0
  95. package/src/dream/deep-prompts.ts +106 -0
  96. package/src/dream/deep-runner.ts +757 -0
  97. package/src/dream/deep-skip-cache.ts +199 -0
  98. package/src/dream/deep-worker.ts +229 -0
  99. package/src/dream/json-salvage.ts +34 -0
  100. package/src/dream/judge.ts +188 -0
  101. package/src/dream/loop-state.ts +286 -0
  102. package/src/dream/lucid-actions.ts +303 -0
  103. package/src/dream/lucid-batches.ts +94 -0
  104. package/src/dream/lucid-prompt.ts +82 -0
  105. package/src/dream/lucid-runner.ts +744 -0
  106. package/src/dream/lucid-storage.ts +277 -0
  107. package/src/dream/lucid-structure.ts +102 -0
  108. package/src/dream/lucid-types.ts +137 -0
  109. package/src/dream/lucid-worker.ts +224 -0
  110. package/src/dream/rem-dedup.ts +502 -0
  111. package/src/dream/rem-extract.ts +782 -0
  112. package/src/dream/rem-reset-run.ts +67 -0
  113. package/src/dream/rem-runner.ts +696 -0
  114. package/src/dream/rem-worker.ts +527 -0
  115. package/src/dream/review-window.ts +71 -0
  116. package/src/dream/scheduler-state.ts +129 -0
  117. package/src/dream/storage.ts +497 -0
  118. package/src/dream/types.ts +133 -0
  119. package/src/dream/wiki-context.ts +133 -0
  120. package/src/engine/a2a.ts +33 -0
  121. package/src/engine/availability.ts +63 -0
  122. package/src/engine/claude-cli.ts +969 -0
  123. package/src/engine/codex-app-server-client.ts +294 -0
  124. package/src/engine/codex-bin.ts +49 -0
  125. package/src/engine/codex-cli.ts +1014 -0
  126. package/src/engine/codex-dynamic-tools.ts +239 -0
  127. package/src/engine/codex-home.ts +63 -0
  128. package/src/engine/codex-thread-config.ts +74 -0
  129. package/src/engine/context-budget.ts +257 -0
  130. package/src/engine/engine-meta-labels.ts +211 -0
  131. package/src/engine/grok-cli.ts +941 -0
  132. package/src/engine/inline-think.ts +59 -0
  133. package/src/engine/model-availability.ts +105 -0
  134. package/src/engine/openai-compatible.ts +2464 -0
  135. package/src/engine/reasoning-retry.ts +83 -0
  136. package/src/engine/registry.ts +13 -0
  137. package/src/engine/replay.ts +195 -0
  138. package/src/engine/sampling.ts +90 -0
  139. package/src/engine/thinking-params.ts +264 -0
  140. package/src/engine/types.ts +269 -0
  141. package/src/engine/user-tag.ts +24 -0
  142. package/src/imagegen/aspect.ts +128 -0
  143. package/src/imagegen/generate.ts +642 -0
  144. package/src/imagegen/references.ts +75 -0
  145. package/src/imagegen/types.ts +154 -0
  146. package/src/lsp/client.ts +183 -0
  147. package/src/lsp/fake-server.helper.mjs +42 -0
  148. package/src/lsp/format.ts +29 -0
  149. package/src/lsp/index.ts +21 -0
  150. package/src/lsp/manager.ts +238 -0
  151. package/src/lsp/registry.ts +151 -0
  152. package/src/mcp/config.ts +117 -0
  153. package/src/mcp/hub/audit.ts +55 -0
  154. package/src/mcp/hub/bridge.ts +115 -0
  155. package/src/mcp/hub/catalog.ts +69 -0
  156. package/src/mcp/hub/credentials.ts +406 -0
  157. package/src/mcp/hub/env-expand.ts +14 -0
  158. package/src/mcp/hub/manager.ts +770 -0
  159. package/src/mcp/hub/normalize.ts +213 -0
  160. package/src/mcp/server.ts +368 -0
  161. package/src/mcp/tool-schema.ts +20 -0
  162. package/src/media/capabilities.ts +392 -0
  163. package/src/media/records.ts +175 -0
  164. package/src/media/store.ts +217 -0
  165. package/src/media/types.ts +69 -0
  166. package/src/memory/chunking.ts +168 -0
  167. package/src/memory/embeddings.ts +262 -0
  168. package/src/memory/index.ts +15 -0
  169. package/src/memory/inject.ts +197 -0
  170. package/src/memory/manager.ts +996 -0
  171. package/src/memory/registry.ts +176 -0
  172. package/src/memory/rescan.ts +101 -0
  173. package/src/memory/retrieval.ts +586 -0
  174. package/src/memory/shared-index.ts +372 -0
  175. package/src/memory/slug.ts +39 -0
  176. package/src/memory/storage.ts +385 -0
  177. package/src/memory/watcher.ts +134 -0
  178. package/src/multimodal/blocks.ts +101 -0
  179. package/src/multimodal/dimensions.ts +214 -0
  180. package/src/multimodal/load.ts +86 -0
  181. package/src/multimodal/mime.ts +135 -0
  182. package/src/multimodal/pdf-render.ts +80 -0
  183. package/src/multimodal/user-content.ts +266 -0
  184. package/src/persona/files.ts +144 -0
  185. package/src/persona/loader.ts +598 -0
  186. package/src/persona/skill-gating-store.ts +59 -0
  187. package/src/persona/tool-gating-store.ts +113 -0
  188. package/src/projects/focus.ts +186 -0
  189. package/src/projects/prompt-block.ts +106 -0
  190. package/src/projects/scheme.ts +107 -0
  191. package/src/projects/store.ts +144 -0
  192. package/src/projects/types.ts +73 -0
  193. package/src/sentinel/dispatcher.ts +97 -0
  194. package/src/sentinel/schedule.ts +271 -0
  195. package/src/sentinel/scheduler.ts +840 -0
  196. package/src/sentinel/store.ts +259 -0
  197. package/src/sentinel/types.ts +221 -0
  198. package/src/server/activity-stream.ts +160 -0
  199. package/src/server/ask-calls.ts +137 -0
  200. package/src/server/ask-wait-graph.ts +171 -0
  201. package/src/server/async-tasks.ts +199 -0
  202. package/src/server/builder-busy.ts +86 -0
  203. package/src/server/builder-prompt.ts +204 -0
  204. package/src/server/builder-questions.ts +117 -0
  205. package/src/server/builder-session.ts +249 -0
  206. package/src/server/chat-aborts.ts +83 -0
  207. package/src/server/claude-config-dir.ts +71 -0
  208. package/src/server/claude-credential-sync.ts +454 -0
  209. package/src/server/env-file.ts +100 -0
  210. package/src/server/env.ts +115 -0
  211. package/src/server/heal-session.ts +151 -0
  212. package/src/server/history-page.ts +46 -0
  213. package/src/server/index.ts +7244 -0
  214. package/src/server/lockfile.ts +89 -0
  215. package/src/server/logger.ts +67 -0
  216. package/src/server/logs.ts +187 -0
  217. package/src/server/loopback-fetch.ts +130 -0
  218. package/src/server/openai-client.ts +89 -0
  219. package/src/server/prompt-assembly.ts +334 -0
  220. package/src/server/restart-reconcile.ts +139 -0
  221. package/src/server/run-turn-fallback.ts +275 -0
  222. package/src/server/run-turn-types.ts +91 -0
  223. package/src/server/run-turn.ts +1474 -0
  224. package/src/server/sanitize-assistant-text.ts +112 -0
  225. package/src/server/session-export.ts +220 -0
  226. package/src/server/session-queue.ts +376 -0
  227. package/src/server/session-workdir.ts +49 -0
  228. package/src/server/sse-h2-safe.ts +61 -0
  229. package/src/server/sse-liveness.ts +162 -0
  230. package/src/server/sse-serializer.ts +161 -0
  231. package/src/server/start-turn.ts +249 -0
  232. package/src/server/steer-inbox.ts +107 -0
  233. package/src/server/tls-keeper.ts +153 -0
  234. package/src/server/tool-format.ts +167 -0
  235. package/src/server/turn-framing.ts +52 -0
  236. package/src/server/turn-origin-kind.ts +74 -0
  237. package/src/server/turn-origin.ts +40 -0
  238. package/src/server/work-ledger.ts +975 -0
  239. package/src/server/workspace.ts +114 -0
  240. package/src/setup/config-edit.ts +201 -0
  241. package/src/setup/presets.ts +71 -0
  242. package/src/setup/prompt.ts +163 -0
  243. package/src/setup/tailscale.ts +44 -0
  244. package/src/skills/bin-checks.ts +227 -0
  245. package/src/skills/bootstrap.ts +347 -0
  246. package/src/skills/env-scope.ts +175 -0
  247. package/src/skills/gating.ts +71 -0
  248. package/src/skills/lint.ts +202 -0
  249. package/src/skills/load.ts +368 -0
  250. package/src/skills/path-helpers.ts +102 -0
  251. package/src/skills/registry.ts +178 -0
  252. package/src/ssh/exec.ts +142 -0
  253. package/src/ssh/index.ts +12 -0
  254. package/src/ssh/known-hosts.ts +109 -0
  255. package/src/ssh/pool.ts +307 -0
  256. package/src/storage/sessions.ts +602 -0
  257. package/src/team/render.ts +149 -0
  258. package/src/team/resolve.ts +122 -0
  259. package/src/team/store.ts +124 -0
  260. package/src/team/types.ts +111 -0
  261. package/src/team/write.ts +95 -0
  262. package/src/testing/isolated-home.mts +46 -0
  263. package/src/tmux/attention-watcher.ts +272 -0
  264. package/src/tmux/attention.ts +336 -0
  265. package/src/tmux/list.ts +91 -0
  266. package/src/tmux/origin-store.ts +102 -0
  267. package/src/tmux/tui-markers.ts +267 -0
  268. package/src/tools/agents/ask-cancel.ts +94 -0
  269. package/src/tools/agents/ask-result.ts +235 -0
  270. package/src/tools/agents/ask.ts +704 -0
  271. package/src/tools/agents/builder-dispatch.ts +217 -0
  272. package/src/tools/agents/images.ts +104 -0
  273. package/src/tools/agents/index.ts +42 -0
  274. package/src/tools/agents/long-task-timeouts.ts +39 -0
  275. package/src/tools/agents/session-list.ts +136 -0
  276. package/src/tools/agents/session-model.ts +106 -0
  277. package/src/tools/agents/spawn.ts +845 -0
  278. package/src/tools/agents/status.ts +589 -0
  279. package/src/tools/browser/index.ts +6 -0
  280. package/src/tools/browser/ops.ts +145 -0
  281. package/src/tools/browser/tools.ts +184 -0
  282. package/src/tools/builder/short-descriptions.ts +80 -0
  283. package/src/tools/builder/tools.ts +222 -0
  284. package/src/tools/docs/index.ts +1 -0
  285. package/src/tools/docs/tools.ts +228 -0
  286. package/src/tools/dream/index.ts +11 -0
  287. package/src/tools/dream/tools.ts +1002 -0
  288. package/src/tools/exec/allowlist.ts +233 -0
  289. package/src/tools/exec/background-detach.helper.mts +27 -0
  290. package/src/tools/exec/blacklist.ts +336 -0
  291. package/src/tools/exec/concurrency.ts +150 -0
  292. package/src/tools/exec/fit-output.ts +82 -0
  293. package/src/tools/exec/index.ts +7 -0
  294. package/src/tools/exec/internal-env.ts +89 -0
  295. package/src/tools/exec/job-store.ts +403 -0
  296. package/src/tools/exec/local.ts +649 -0
  297. package/src/tools/exec/remote.ts +399 -0
  298. package/src/tools/exec/tools.ts +934 -0
  299. package/src/tools/file/analyze.ts +378 -0
  300. package/src/tools/file/index.ts +2 -0
  301. package/src/tools/file/local.ts +707 -0
  302. package/src/tools/file/lsp-hook.ts +72 -0
  303. package/src/tools/file/persona-guard.ts +61 -0
  304. package/src/tools/file/policy.ts +292 -0
  305. package/src/tools/file/read-format.ts +129 -0
  306. package/src/tools/file/remote.ts +680 -0
  307. package/src/tools/file/replace.ts +507 -0
  308. package/src/tools/file/search-window.ts +224 -0
  309. package/src/tools/file/tools.ts +658 -0
  310. package/src/tools/file/write-scope.ts +182 -0
  311. package/src/tools/gating.ts +106 -0
  312. package/src/tools/image/budget.ts +82 -0
  313. package/src/tools/image/index.ts +7 -0
  314. package/src/tools/image/tools.ts +601 -0
  315. package/src/tools/index.ts +99 -0
  316. package/src/tools/memory/index.ts +12 -0
  317. package/src/tools/memory/tools.ts +399 -0
  318. package/src/tools/projects/index.ts +1 -0
  319. package/src/tools/projects/tools.ts +643 -0
  320. package/src/tools/registry.ts +427 -0
  321. package/src/tools/resources/index.ts +8 -0
  322. package/src/tools/resources/tools.ts +176 -0
  323. package/src/tools/resources/visibility.ts +60 -0
  324. package/src/tools/sentinel/index.ts +1 -0
  325. package/src/tools/sentinel/tools.ts +592 -0
  326. package/src/tools/skill/index.ts +4 -0
  327. package/src/tools/skill/tools.ts +285 -0
  328. package/src/tools/time/index.ts +5 -0
  329. package/src/tools/time/tools.ts +123 -0
  330. package/src/tools/tmux/index.ts +1 -0
  331. package/src/tools/tmux/local.ts +277 -0
  332. package/src/tools/tmux/remote.ts +168 -0
  333. package/src/tools/tmux/tools.ts +1064 -0
  334. package/src/tools/tool-output.ts +97 -0
  335. package/src/tools/types.ts +227 -0
  336. package/src/tools/video/index.ts +1 -0
  337. package/src/tools/video/tools.ts +425 -0
  338. package/src/tools/web/fetch.ts +337 -0
  339. package/src/tools/web/index.ts +4 -0
  340. package/src/tools/web/tools.ts +186 -0
  341. package/src/tools/wiki/index.ts +1 -0
  342. package/src/tools/wiki/tools.ts +445 -0
  343. package/src/tts/cache-gc.ts +128 -0
  344. package/src/tts/prepare-for-tts.ts +114 -0
  345. package/src/tts/service.ts +332 -0
  346. package/src/types/events.ts +695 -0
  347. package/src/types/turn-origin.ts +53 -0
  348. package/src/version.ts +21 -0
  349. package/src/videogen/dialects.ts +222 -0
  350. package/src/videogen/generate.ts +484 -0
  351. package/src/videogen/jobs.ts +178 -0
  352. package/src/videogen/runner.ts +125 -0
  353. package/src/videogen/wake.ts +119 -0
  354. package/src/voice/realtime/call.ts +948 -0
  355. package/src/voice/realtime/consult.ts +293 -0
  356. package/src/voice/realtime/fake-provider.ts +134 -0
  357. package/src/voice/realtime/manager.ts +384 -0
  358. package/src/voice/realtime/openai-provider.ts +471 -0
  359. package/src/voice/realtime/persona.ts +227 -0
  360. package/src/voice/realtime/session-match.ts +116 -0
  361. package/src/voice/realtime/types.ts +182 -0
  362. package/src/wiki/conflict.ts +113 -0
  363. package/src/wiki/explorer.ts +578 -0
  364. package/src/wiki/index-builder.ts +172 -0
  365. package/src/wiki/language.ts +134 -0
  366. package/src/wiki/log-builder.ts +150 -0
  367. package/src/wiki/map.ts +258 -0
  368. package/src/wiki/migration/analyze.ts +304 -0
  369. package/src/wiki/migration/execute.ts +689 -0
  370. package/src/wiki/migration/refine.ts +402 -0
  371. package/src/wiki/migration/store.ts +100 -0
  372. package/src/wiki/move-page.ts +57 -0
  373. package/src/wiki/structure-file.ts +192 -0
  374. package/src/wiki/taxonomy.ts +140 -0
  375. package/src/wiki/templates.ts +163 -0
  376. package/src/wiki/types.ts +133 -0
  377. package/templates/skills/README.md +24 -0
  378. package/templates/skills/_templates/api-wrapper/SKILL.md +26 -0
  379. package/templates/skills/_templates/cli-wrapper/BOOTSTRAP.md +32 -0
  380. package/templates/skills/_templates/cli-wrapper/SKILL.md +24 -0
  381. package/templates/skills/_templates/default/SKILL.md +25 -0
  382. package/templates/skills/builder-handover/SKILL.md +96 -0
  383. package/templates/skills/builder-handover/assets/ORDER.md +12 -0
  384. package/templates/skills/skill-author/SKILL.md +110 -0
  385. package/tsconfig.json +22 -0
  386. package/web/dist/assets/index-BaVv6pB2.js +631 -0
  387. package/web/dist/assets/index-BaVv6pB2.js.map +1 -0
  388. package/web/dist/assets/index-V3FV3Z25.css +32 -0
  389. package/web/dist/favicon.svg +8 -0
  390. package/web/dist/index.html +20 -0
  391. package/web/package.json +36 -0
  392. package/web/tsconfig.json +25 -0
  393. package/web-mobile/dist/apple-touch-icon.png +0 -0
  394. package/web-mobile/dist/assets/index-BqKt7IMx.css +1 -0
  395. package/web-mobile/dist/assets/index-X_vRr6cd.js +88 -0
  396. package/web-mobile/dist/assets/index-X_vRr6cd.js.map +1 -0
  397. package/web-mobile/dist/favicon.svg +8 -0
  398. package/web-mobile/dist/icon-192.png +0 -0
  399. package/web-mobile/dist/icon-512.png +0 -0
  400. package/web-mobile/dist/index.html +27 -0
  401. package/web-mobile/dist/manifest.webmanifest +32 -0
  402. package/web-mobile/dist/service-worker.js +90 -0
  403. package/web-mobile/package.json +28 -0
  404. package/web-mobile/tsconfig.json +25 -0
@@ -0,0 +1,891 @@
1
+ # Dream Phases
2
+
3
+ > Background memory consolidation in three phases — REM, Deep, Lucid.
4
+ > Together they turn raw conversation into curated long-term knowledge
5
+ > without any single LLM call doing too much.
6
+
7
+ ## Why three phases?
8
+
9
+ When you chat with an agent, useful facts get said in passing. „I moved
10
+ to Berlin." „My new car is a hybrid." „We decided to ship the dark-mode
11
+ toggle next sprint." A naive memory layer would either dump every turn
12
+ into long-term storage (noise) or rely on the agent to manually save
13
+ (unreliable + tedious). somora splits the work:
14
+
15
+ 1. **REM** notices what's new in a recent session and proposes facts to
16
+ keep — small per-agent jobs, you approve each one. Result lands in
17
+ the agent's *private memory inbox*.
18
+ 2. **Deep** rolls multiple inbox entries up into the *shared wiki*
19
+ pages — bigger consolidation runs across all agents, every ~12 h.
20
+ Auto-applies (you'd be drowning in approvals otherwise) but the wiki
21
+ stays editable in Obsidian.
22
+ 3. **Lucid** audits the wiki for contradictions, dead refs, missing
23
+ pages and links worth adding — every ~7 d. Findings come back as proposals
24
+ you walk through with the agent in a `dream_review` loop.
25
+
26
+ Each phase has its own LLM worker (small/cheap for REM, strong/expensive
27
+ for Deep+Lucid), its own cadence, and its own approval semantics. No
28
+ single prompt has to do everything; the system just keeps grinding
29
+ incrementally in the background while you use somora normally.
30
+
31
+ ## The mental model
32
+
33
+ ```
34
+ ┌─ REM ─────────────────┐ ┌─ Deep ─────────────────┐ ┌─ Lucid ──────────────┐
35
+ │ Session → Memory │ │ Memory → Wiki │ │ Wiki cleanup │
36
+ │ per-agent │ │ platform-wide │ │ platform-wide │
37
+ │ ~30 min idle │ │ ~12 h scheduled │ │ ~7 d scheduled │
38
+ │ small/local model │ │ strong model │ │ strong model │
39
+ │ approval required │ │ auto-applies │ │ approval required │
40
+ └───────────────────────┘ └────────────────────────┘ └──────────────────────┘
41
+ │ │ │
42
+ ▼ ▼ ▼
43
+ memory inbox grows wiki gets new pages / wiki gets fixed:
44
+ with new facts the merges of new content; contradictions resolved,
45
+ agent should keep consumed memory files dead links repaired,
46
+ are deleted missing pages created
47
+ ```
48
+
49
+ Each phase has one job. Each runs at its own cadence. Each uses an LLM
50
+ worker model you configure separately. The phases compose into a clean
51
+ flow: facts come in via REM, get consolidated by Deep, get audited by
52
+ Lucid.
53
+
54
+ ## Phase REM — Session → Memory
55
+
56
+ REM ("Rapid Eye Movement") extracts new factual information from a
57
+ session's transcript and proposes additions to the agent's **private
58
+ memory inbox**.
59
+
60
+ ### Job
61
+
62
+ Read the session JSONL since the last REM run, identify FACTS the user
63
+ asserted (not jokes, not transient state, not things already in memory or
64
+ the wiki), and surface them as `pending` findings for your approval.
65
+
66
+ ### Triggers
67
+
68
+ Three triggers, all per-agent:
69
+
70
+ **Manual: `/reset YES`** — when you reset a session, somora archives the
71
+ current `main.jsonl` to a timestamped name and starts a fresh `main`.
72
+ If REM is enabled for the agent, it spawns a manual run over the part of
73
+ the archive REM has not read yet, and marks the archive as read when
74
+ that run succeeds — so the idle worker does not read it a second time.
75
+ Result lands in
76
+ `~/.somora/agents/<name>/memory/.dreams/<id>.dream.md` and shows up in
77
+ `dream_list`.
78
+
79
+ **Automatic: idle-timer** — when REM is enabled, an in-process worker
80
+ watches each agent's chat activity. After `idleMinutes` of no chat
81
+ (default 30), the worker:
82
+
83
+ 1. Resumes any previously-paused dream first (don't waste prior work).
84
+ 2. Otherwise picks the most-recently-active session whose last activity
85
+ is past its `dreamReadThroughTs` marker. **Archived sessions count**:
86
+ filing a conversation away says you are done with it, not that it
87
+ should be forgotten, so a session archived before REM caught up still
88
+ gets its last stretch read.
89
+ 3. Runs an extraction over the delta range — minus any Lucid review
90
+ loop inside it (`dream_review start` … `end`): facts the user
91
+ clarifies there are written to the wiki directly, so REM skips that
92
+ window instead of re-extracting them as duplicate findings.
93
+ 4. On success, bumps the marker — and goes straight on to the next
94
+ unread session, up to eight in one cycle. A backlog is read in one
95
+ stretch of silence instead of one session per idle interval. The
96
+ cycle ends at the first run that does not succeed (the worker is
97
+ probably still down), and a session whose last attempt failed is
98
+ picked last, so it cannot hold up the others.
99
+
100
+ **Catch up now: `dream_run({phase: 'rem'})`** or
101
+ `POST /agents/:agent/dream/run-rem` — starts that same cycle at once
102
+ instead of waiting for the idle timer, e.g. after a worker outage.
103
+ Answers `started`, `busy` or `nothing_to_do`.
104
+
105
+ **It comes back on its own.** When a cycle ends with work still left —
106
+ a run that failed, a paused dream, a session nobody has read yet — the
107
+ worker schedules itself again rather than waiting for you to chat. Four
108
+ attempts at one, two, four and eight idle intervals, then it goes quiet
109
+ until real activity restarts the count. A backend that is down for an
110
+ hour is caught; one that is down all afternoon does not become an
111
+ all-afternoon retry loop. A successful run resets the count, so draining
112
+ a backlog of several sessions is not charged against it.
113
+
114
+ A failed range keeps its record until a run actually reads it. A
115
+ successful run only clears the failures it covered, so a shorter manual
116
+ run cannot make the evidence of an unread stretch disappear.
117
+
118
+ Manual REM runs do **not** pause when you start chatting again — they're
119
+ user-initiated, bounded, just run to completion.
120
+ Automatic REM runs **abort** on user activity (the in-flight extraction
121
+ gets paused; resumed on next idle).
122
+
123
+ ### Worker model
124
+
125
+ Configured per-agent in `agent.yaml`:
126
+
127
+ ```yaml
128
+ rem:
129
+ enabled: true
130
+ model: <alias> # alias from config.yaml or 'provider/modelId'
131
+ # fallback: <alias> # optional backup worker — or [a, b], tried in turn
132
+ idleMinutes: 30
133
+ chunkTokens: 50000 # range-split for very long sessions
134
+ chunkTimeoutMs: 600000 # 10 min per chunk (room for local models)
135
+ participate_in_wiki: true # default true; false = REM only, never Deep
136
+ # thinking: medium # optional; off | low | medium | high
137
+ # only honored if the REM worker model has the
138
+ # 'reasoning' capability — otherwise dormant.
139
+ ```
140
+
141
+ `model` is required when REM is enabled: there is no implicit default
142
+ and REM never falls back to the agent's chat model, so a run can never
143
+ silently land on an expensive model. A small local model (30B class)
144
+ is good enough for atomic-fact extraction with the right prompt, and
145
+ REM runs often, so cost matters. A strong hosted model works too.
146
+
147
+ **`rem.fallback` — a backup worker, or a chain of them.** A local
148
+ worker is away whenever its box switches profiles, benchmarks or
149
+ reboots. With `fallback:` set to a second model (typically a cheap
150
+ hosted one on a *different* provider) — or to an ordered list,
151
+ `fallback: [glm, deep41flash]`, like the chat `fallback` — a run whose
152
+ current worker is unreachable — connection refused, 5xx, timeout, 429
153
+ after the SDK's retries — continues on the next backup from the chunk
154
+ that hit the outage; chunks already finished are kept, the failed chunk
155
+ is retried on the backup, and the backup stays in charge until it is
156
+ unreachable itself, when the next one in the chain takes over. When the
157
+ chain is exhausted the chunk fails as it would without a backup. A
158
+ worker that is currently marked unreachable (the note every cascade
159
+ shares, `fallback.retryUnavailableMinutes`, default 60 min) is not
160
+ tried: the run starts on the first backup that is not marked, recorded
161
+ in the dream file as a switch at chunk 0. What does NOT
162
+ switch: a 4xx rejection (bad parameter, unsupported reasoning level,
163
+ auth) — that is a config problem and the dream fails visibly; and a
164
+ run paused by user activity — that pauses as before. The agent's chat
165
+ `model:`/`fallback:` are never used implicitly: REM only ever runs on
166
+ workers you named. Both refs are validated when the run starts, so a
167
+ typo in `fallback:` fails the dream immediately rather than on the day
168
+ the primary is down. The dream file records `worker_fallback_ref` and,
169
+ when the switch happened, `worker_switch` (`from`, `to`, `reason`,
170
+ `at_chunk`); the Markdown body shows the same line, and the log carries
171
+ `dream.worker_fallback`.
172
+
173
+ ### What REM sees
174
+
175
+ Each REM run feeds the worker:
176
+
177
+ - Transcript chunk (1+ chunks if session is long)
178
+ - Existing memory inbox contents for this agent
179
+ - Wiki context (index.md + top-N relevant wiki pages, embedding-matched
180
+ against session content)
181
+ - Vault-recall snippets (if vault is configured)
182
+ - The REM system prompt (in `src/dream/rem-extract.ts`)
183
+
184
+ The transcript says who wrote each message. Not every `user_message` is
185
+ the person: another agent's `agent_ask`, a sentinel trigger's prompt, a
186
+ tmux or job wake arrive the same way. They are labelled
187
+ `OTHER-AGENT(<name>)` and `SYSTEM(<kind>)`; only `USER` lines (a voice
188
+ consult counts, it is the person relayed) are the person speaking. A
189
+ stable fact another agent passed on may still become a finding — often
190
+ it is the only way an orchestrated agent learns it — but it is recorded
191
+ with its source ("Laut <name>: …"), never as something the user said.
192
+ Trigger text is never a source of facts.
193
+
194
+ The wiki context is critical: REM dedupes against the **wiki**, not just
195
+ memory. New facts that contradict the wiki get surfaced as
196
+ `memory_write` so Deep can later merge them in.
197
+
198
+ ### Output: findings
199
+
200
+ A REM run produces `pending` findings, each with:
201
+
202
+ - `action` — `memory_write | memory_edit | memory_delete | vault_hint`
203
+ - `slug` — kebab-case identifier
204
+ - `proposed_content` — what should land in memory if approved
205
+ - `reason` — why this finding (quotes user's statement)
206
+
207
+ Approve with `dream_apply`, reject with `dream_dismiss`. Memory file is
208
+ written/edited/deleted only on approval. If a finding was correct but
209
+ already handled outside the dream flow (you edited the wiki yourself,
210
+ the agent documented it in chat), close it with
211
+ `dream_dismiss({resolved_manually: true, reason})` — it is then recorded
212
+ as `resolved_manually` instead of `dismissed`, so the history reads
213
+ "done elsewhere" rather than "rejected".
214
+
215
+ ### Mechanical dedup
216
+
217
+ Small worker models don't reliably act on the "propose only NEW facts"
218
+ instruction — recurring sessions (weekly sentinels) can produce the same
219
+ findings run after run. A code-level filter runs after extraction,
220
+ before findings are stored:
221
+
222
+ - **Exact slug collision** with a loaded wiki page → the finding is
223
+ dropped (logged as `dream.rem.dedup_dropped`). With an existing
224
+ **memory note** it depends on what the note says: if the note already
225
+ carries the finding's content it is a repeat and dropped; if it says
226
+ something else — the worker reuses the obvious slug when the person
227
+ corrects a fact — the finding is kept under a slug of its own
228
+ (`<slug>-update-<date>`, logged as `dream.rem.dedup_reslugged`), so
229
+ the correction reaches the review and nothing is overwritten.
230
+ - **High content similarity** (hybrid search against memory + wiki) →
231
+ the finding is kept but marked `likely_duplicate` with a
232
+ `duplicate_of` pointer plus a `matched_excerpt` showing the text the
233
+ similarity actually fired on. Wiki audit logs (`logs/…`, written by
234
+ Deep) are excluded from the comparison corpus — they record that
235
+ something was *processed*, not the knowledge itself.
236
+
237
+ **The flag marks topic overlap, not fact identity.** Embedding
238
+ similarity cannot tell "waiting for the GO" from "GO was given" — on a
239
+ fast-moving project every finding scores high against the project's own
240
+ wiki page, including genuinely new state. Two guardrails:
241
+
242
+ - When the finding carries concrete tokens (numbers, dates, versions)
243
+ that appear nowhere in the matched text, it is additionally marked
244
+ `novel_details: true` and the review output says so explicitly —
245
+ **do not batch-dismiss those**; they are usually a new fact on a
246
+ known topic.
247
+ - For everything else, glance at the `matched_excerpt` before
248
+ dismissing. Batch-dismissal is safe when the excerpt already states
249
+ the finding's fact, not merely its topic.
250
+
251
+ Platform-wide tunables in `config.yaml` (defaults apply when the block
252
+ is absent):
253
+
254
+ ```yaml
255
+ rem:
256
+ dedup:
257
+ enabled: true # default true
258
+ similarityThreshold: 0.85 # cosine similarity of the finding's
259
+ # embedding to the closest existing
260
+ # memory/wiki chunk, 0..1. NOT the fused
261
+ # search score (that is a rank within one
262
+ # query — the top hit is always 1.0 before
263
+ # boosts). Paraphrases of the same fact
264
+ # ~0.85-0.95, same topic / different fact
265
+ # ~0.6-0.8. Lower = mark more.
266
+ ```
267
+
268
+ ### Coverage judge
269
+
270
+ Similarity finds topic overlap; it cannot say whether the *fact* is
271
+ already written. On a hundred hand-reviewed findings the cosine flag
272
+ caught five real duplicates. The coverage judge asks a model instead:
273
+ it reads the whole pages of the closest candidates (memory notes and
274
+ wiki pages the similarity search returned) and answers one question —
275
+ is every substantive element of this finding already stated there
276
+ (`covered`), or does it add at least one fact, number, date, decision
277
+ or conclusion none of them state (`adds_new`)? On the same hundred
278
+ findings the question caught 93, with 91 % of its marks right.
279
+
280
+ What the verdict does — nothing is deleted, the finding stays in the
281
+ review either way:
282
+
283
+ - `covered` at or above `minConfidence` → the finding is marked
284
+ `likely_duplicate` like a similarity hit, `duplicate_of` names the
285
+ page as `<source>:<slug>@judge` (when similarity had already marked
286
+ it, its pointer and number stay), and `matched_excerpt` shows the
287
+ paragraph of that page that carries the finding's numbers or dates.
288
+ - `adds_new` → no mark; if similarity had marked the finding, it is
289
+ additionally flagged `novel_details`, the review's "do not
290
+ batch-dismiss" signal.
291
+ - Every judged finding carries `judge_verdict`, `judge_confidence`
292
+ (0–100), `judge_reason` (the model's one sentence, in English like
293
+ every model-facing text somora produces) and, for `covered`,
294
+ `judge_by`. `dream_list` / `dream_get` show them beside
295
+ `matched_excerpt`.
296
+
297
+ A finding without candidates is not judged; a call that fails or
298
+ replies unreadably leaves the finding without a verdict (logged as
299
+ `dream.rem.judge_failed` / `judge_unreadable`); past `maxPerRun` the
300
+ rest of the run goes unjudged and the log says so once. The run's
301
+ `dream.rem.dedup_summary` line carries `judged`, `judge_marked`,
302
+ `judge_cleared`, `judge_failed`, `judge_skipped` and `judge_model`.
303
+
304
+ Off by default. The model is the REM worker of the agent whose dream
305
+ is running unless `model` names another one — a smaller, cheaper
306
+ model does fine, the question is easier than the extraction. A named
307
+ model is validated when the run starts, like `rem.fallback`; without
308
+ one the judge follows the worker, so when a run switched to
309
+ `rem.fallback` the judge asks the fallback too. Cost:
310
+ one call per finding with candidates, a few thousand input tokens each
311
+ (the pages), so on a hosted model keep `maxPerRun` in mind.
312
+
313
+ ```yaml
314
+ rem:
315
+ dedup:
316
+ judge:
317
+ enabled: false # default false
318
+ # model: <alias> # default: the agent's REM worker (rem.model)
319
+ candidates: 4 # distinct pages the judge reads per finding
320
+ maxPageChars: 6000 # each page is cut to this
321
+ minConfidence: 80 # a `covered` verdict below this marks nothing
322
+ maxPerRun: 60 # findings judged per run; the rest go unjudged
323
+ timeoutMs: 120000
324
+ # thinking: low # optional; honoured when the model can reason
325
+ ```
326
+
327
+ ## Phase Deep — Memory → Wiki
328
+
329
+ Deep consolidates **all agents' memory inboxes** into the shared wiki.
330
+
331
+ ### Job
332
+
333
+ For each memory file across all participating agents, decide one of three
334
+ outcomes:
335
+
336
+ - **Skip** — transient (daily log, scratchpad), already covered, too thin.
337
+ - **Promote** — new wiki topic, create dedicated page with frontmatter,
338
+ sections, cross-references.
339
+ - **Merge** — topic exists in the wiki, integrate new content into the
340
+ existing page (preserves structure, updates `## Aktueller Stand` and
341
+ `## Zeitleiste` typically).
342
+
343
+ After successful Promote or Merge, the source memory file is **deleted**.
344
+ Wiki = canonical, inbox stays a clean queue.
345
+
346
+ ### Triggers
347
+
348
+ **Schedule** — every 12h (configurable).
349
+
350
+ **Manual** — `dream_run({phase: 'deep'})` from any agent's chat, or
351
+ `POST /dream/run-deep` over HTTP. Optional `force: true` bypasses the
352
+ hash-cache (re-evaluates every memory file).
353
+
354
+ Deep operates on whatever memory files are currently on disk. It does
355
+ **not** trigger REM. New observations only enter memory when you
356
+ approve a REM finding via `dream_apply`; Deep picks them up on its
357
+ next run.
358
+
359
+ ### Worker model
360
+
361
+ Configured platform-wide in `config.yaml`:
362
+
363
+ ```yaml
364
+ wiki:
365
+ deep:
366
+ enabled: true
367
+ intervalHours: 12
368
+ model: <alias> # required — alias from config.yaml or 'provider/modelId'
369
+ # thinking: medium # optional; per-engine reasoning_effort. Honored
370
+ # when the worker model has the 'reasoning'
371
+ # capability. On a strong model this tends to
372
+ # improve skip/promote/merge judgement at the
373
+ # cost of more rate-limit budget.
374
+ ```
375
+
376
+ Without `model` Deep does not run: the scheduler logs
377
+ `dream.deep.no_worker_model_configured` and returns without touching
378
+ anything.
379
+
380
+ ### Single-prompt logic (skip / promote / merge in one call)
381
+
382
+ Per memory file, Deep does ONE LLM call that decides skip/promote/merge.
383
+ The worker sees:
384
+
385
+ - The memory file's body, and when its content was stated: a note that
386
+ came from a REM finding carries `stated_at` (the end of the
387
+ conversation it was read from) — not the day the finding was applied,
388
+ which for a conversation dreamed late can be months off
389
+ - The wiki map: every folder with what kind of page lives in it and
390
+ how many, the template folders not created yet, and the filing
391
+ rules (see [wiki.md](wiki.md#folders-kind-not-topic))
392
+ - Top-8 relevant wiki pages, embedding-matched against the memory
393
+ body. A page over 8000 characters arrives shortened to its first
394
+ 6000 — good enough to decide with, not to rewrite from: a merge into
395
+ a page the worker saw shortened, or did not see at all, is asked
396
+ again with that one page in full, and the write is refused if the
397
+ page changed while the worker was deciding
398
+
399
+ When the memory contradicts a fact on the page, Deep compares dates
400
+ before touching it: a memory that is clearly newer updates the fact and
401
+ notes the revision in the timeline; one that is older than the page's
402
+ statement — or whose order cannot be told — leaves the current fact
403
+ alone and is added to the timeline as a dated earlier entry.
404
+
405
+ Returns a structured `MemoryFateDecision`:
406
+
407
+ ```json
408
+ { "kind": "skip", "reason": "..." }
409
+
410
+ { "kind": "promote", "subfolder": "personen", "slug": "personen/jane-doe",
411
+ "type": "person", "title": "Jane Doe",
412
+ "body": "## Aktueller Stand\n…", "related": [...],
413
+ "newFolder": { "path": "…", "purpose": "…" } } // only for a folder the map lacks
414
+
415
+ { "kind": "merge", "wikiPath": "personen/familie-klein",
416
+ "body": "...full updated body...",
417
+ "logSummary": "familie-klein aktualisiert: ..." }
418
+ ```
419
+
420
+ Deep applies the decision verbatim — after three checks against the
421
+ wiki. A page over `wiki.deep.maxPageChars` (default 50 000) takes no
422
+ more content: instead of merging, Deep is asked once more to write the
423
+ note as a sub-page under it (`projekte/somora/traum-pipeline`, its own
424
+ current state and timeline) — the migration had folded 97 reports into
425
+ one 100 KB page, and pages like that are never to grow again. Then two
426
+ checks against the wiki map. A promote into a folder that neither exists nor is proposed
427
+ by the template is refused unless the model gave the folder a purpose
428
+ (then the folder is created and described in the structure file); a
429
+ folder deeper than one subfolder is refused. And the page name is
430
+ checked across all folders: when a page of that name already exists
431
+ elsewhere, the promote becomes a merge into that page, asked again
432
+ with the page in full. No second LLM call otherwise — with one
433
+ exception, the merge guard below.
434
+
435
+ ### Merge guard (anti-clobber)
436
+
437
+ The `merge` decision asks the worker for the **full** updated page body,
438
+ and Deep writes that body as the new page. On large pages this is a real
439
+ failure mode: instead of integrating the new fact, a model may return a
440
+ *summary* of the page — and the page shrinks from 22 KB to 3 KB with the
441
+ old content gone. Deep auto-applies, so nothing catches it in between.
442
+
443
+ Before writing, Deep therefore compares body sizes. When the new body is
444
+ shorter than `minRatio` × the existing body, the merge is refused:
445
+
446
+ - the wiki page stays untouched,
447
+ - the **source memory file is not deleted** — it survives for the next
448
+ run, so the content still exists in two places rather than none,
449
+ - a `dream.deep.merge_shrink_blocked` warning is logged with both sizes,
450
+ - the candidate is not written to the skip-cache, so the next Deep run
451
+ retries it with a fresh LLM call.
452
+
453
+ ```yaml
454
+ wiki:
455
+ deep:
456
+ mergeShrinkGuard:
457
+ enabled: true # default
458
+ minRatio: 0.5 # refuse when newBody < 0.5 × existingBody
459
+ minExistingBytes: 2000 # pages below this are never guarded
460
+ ```
461
+
462
+ `minExistingBytes` exempts small pages: shrinking a 400-byte stub is
463
+ normal editing, and guarding it would only stall consolidation.
464
+
465
+ If a specific page trips the guard repeatedly, that is the signal that
466
+ it has outgrown full-body merges — split it into sub-pages.
467
+
468
+ ### Hash-cache
469
+
470
+ Skipped memory files get cached by body-hash in
471
+ `~/.somora/agents/<name>/memory/.deep-skip-cache.json`. On the next Deep
472
+ run, files whose hash matches the cached entry are skipped without an
473
+ LLM call. When most memories are unchanged between runs, a Deep run
474
+ costs no worker tokens at all.
475
+
476
+ The cache invalidates automatically when:
477
+ - Memory body changes (hash mismatch → re-evaluate)
478
+ - Promote/merge consumed the file (entry pruned)
479
+ - File is deleted (opportunistic cleanup on next loadCache)
480
+ - The skip is older than `wiki.deep.skipCacheDays` (default 30; `0` =
481
+ never). A skip is a verdict against the wiki of that day — "too thin
482
+ for a page of its own" stops being true once the page exists, and the
483
+ note belongs on it. Expiry is spread over up to a quarter of the
484
+ period per note, and at most 10 expired notes per agent are looked at
485
+ again in one run, so a batch skipped on one day does not come back as
486
+ one expensive run. Skipped again, a note rests for another period.
487
+
488
+ `dream_run({phase: 'deep', force: true})` ignores the cache for one run.
489
+
490
+ ### No approval
491
+
492
+ Deep runs auto-apply. No per-finding review — the trade-off is that
493
+ Memory→Wiki is mechanical consolidation, not subjective. If a Deep run
494
+ makes a bad decision you don't like, you fix it in Obsidian (the wiki
495
+ is just markdown) or wait for Lucid to flag it.
496
+
497
+ The audit trail lives in `<vault>/<wiki-subfolder>/logs/YYYY-MM.md` —
498
+ monthly append-only logs of all Promotes and Merges with one-line
499
+ summaries.
500
+
501
+ ## Phase Lucid — Wiki cleanup
502
+
503
+ Lucid audits the existing wiki, surfaces objectively-verifiable
504
+ quality issues, and hands them off to **a conversational review loop**
505
+ where you walk the findings with one of your agents and that agent
506
+ writes the changes via loop-scoped `wiki_*` tools. Lucid itself never
507
+ auto-edits the wiki.
508
+
509
+ ### Job
510
+
511
+ Walk the wiki (subfolder by subfolder), identify issues that are
512
+ objectively provable from the wiki content, surface a SHORT list (max
513
+ 8 per batch — one batch per subfolder plus the cross pass). Lucid is
514
+ intentionally narrow:
515
+
516
+ | Finding kind | What it means |
517
+ |---|---|
518
+ | `contradiction` | Two pages assert mutually exclusive facts about the same subject. Cite specific text from each. |
519
+ | `duplicate_page` | Two pages describe the same thing under different names — the migration unites only same-name pages. The page that should survive comes first; `dream_apply` unites them (the model writes the merged body, the other page goes to the report archive, links follow). |
520
+ | `misfiled_page` | A page plainly not of its folder's kind, judged against the wiki map. Only in a wiki on the folder template; the finding names the folder, `dream_apply` moves the page there. |
521
+ | `oversized_page` | A page over `wiki.lucid.oversizedChars` (default 50 000). Found without a model, only in a wiki on the template; the review can split it into sub-pages (`wiki_create` + `wiki_edit` + `wiki_move`). |
522
+ | `not_migrated` | One per run in a wiki without the template: Lucid checks content only here, `somora wiki migrate` is available. Dismiss it once to keep the wiki as it is. |
523
+ | `dead_ref` | `[[wiki-path]]` references a page that doesn't exist. |
524
+ | `wanted_page` | Topic referenced by ≥3 wiki pages but missing its own page. |
525
+ | `link_suggestion` (set by Lucid itself, see below) | A page mentions a named entity in prose AND a wiki page exists with that name AND there is no `[[wikilink]]` from one to the other. Strict: only for clearly identifiable named entities, not generic words. |
526
+
527
+ Subjective polish (stylistic rewrites, "this could read better",
528
+ "feels old") is **deliberately NOT in scope**. Those decisions belong
529
+ in the review conversation, not pre-baked as findings. Three further
530
+ kinds (`stale_claim`, `outdated`, `inconsistent_xref`) are accepted
531
+ when a run file is read, so archived runs in `processed/` still parse,
532
+ but no run produces them.
533
+
534
+ ### Triggers
535
+
536
+ **Schedule** — every 7 days (configurable).
537
+
538
+ **Manual** — `dream_run({phase: 'lucid'})` or `POST /dream/run-lucid`.
539
+
540
+ ### Cluster strategy
541
+
542
+ Lucid cuts the wiki into calls by size: one call carries as many pages
543
+ of one folder (subfolders are folders of their own) as fit
544
+ `wiki.lucid.batchChars` (default 100 000 characters); a page larger
545
+ than that travels alone; a big folder goes in numbered parts. A grown
546
+ wiki with seventy small folders gets seventy small calls, a wiki on
547
+ the template with three big folders gets those in parts — the same
548
+ rule for both. Beside its pages every call sees the wiki map (the
549
+ folders and what lives in each) and the other pages of its top folder
550
+ as one line each, not the whole `index.md`. Then a final
551
+ cross-folder pass looks across folders — but it sees only the opening
552
+ line of each page. That is enough for a dead link or a missing page
553
+ that spans folders; a contradiction between the body of
554
+ `personen/jane-doe` and the body of `projekte/familie-luca-podcast` is
555
+ out of its sight.
556
+
557
+ The size limit is not only for scale — claude-cli's stdin-stream
558
+ parser fails on very large single user-messages. As a side-effect the
559
+ worker reads each part with full focus, which produces higher-quality
560
+ findings than scanning everything at once.
561
+
562
+ ### Worker model
563
+
564
+ Configured platform-wide:
565
+
566
+ ```yaml
567
+ wiki:
568
+ lucid:
569
+ enabled: true
570
+ intervalDays: 7
571
+ model: <alias> # required — alias from config.yaml or 'provider/modelId'
572
+ requireApproval: true
573
+ maxCallsPerTurn: 3 # wiki_* calls the loop holder may make per turn
574
+ batchChars: 100000 # page text per Lucid call; a bigger folder goes in parts
575
+ oversizedChars: 50000 # pages above this are reported (template wikis only)
576
+ maxFindings: 12 # kept per run for review, weighted: contradictions, dead refs,
577
+ # duplicates, misfiled/oversized, wanted pages
578
+ autoLinks: true # link suggestions are set by Lucid, not reviewed
579
+ autoLinksPerRun: 30
580
+ seenDays: 90 # a dismissed finding is not filed again for this long
581
+ # thinking: medium # optional; same semantics as wiki.deep.thinking.
582
+ # Lucid is judgement-heavy (consistency + dead-
583
+ # ref detection) so medium thinking is often
584
+ # the sweet spot on cost/quality.
585
+ ```
586
+
587
+ Without `model` a Lucid run fails with
588
+ `no worker model configured for lucid`.
589
+
590
+ ### Output
591
+
592
+ A `LucidRun` JSON file in `~/.somora/wiki-lucid/<run-id>.json`. The cap
593
+ of 8 findings applies to each call (one per batch, plus the cross
594
+ pass); a run over ninety batches could return hundreds, so
595
+ `wiki.lucid.maxFindings` (default 60) keeps the weighty ones —
596
+ contradictions, dead refs, duplicates, misfiled and oversized pages,
597
+ wanted pages; a pair filed by two calls counts once; what was dropped
598
+ is logged (`dream.lucid.run_capped`). Link suggestions are not
599
+ reviewed at all: Lucid sets them itself — the first plain mention of
600
+ the name becomes a `[[link]]` — up to `wiki.lucid.autoLinksPerRun`
601
+ (30) per run, and records each as `applied` or, when the phrase was
602
+ not found as plain text, `dismissed` with the reason (`autoLinks:
603
+ false` turns this off). A finding a person dismissed is not filed
604
+ again for `wiki.lucid.seenDays` (90). And while a run still has
605
+ findings waiting, no new run starts — the scheduler looks again six
606
+ hours later, `dream_run({phase:'lucid', force:true})` runs anyway. The
607
+ file also
608
+ records `batches_total` and `batches_failed`: a run in which every batch
609
+ failed, or that was aborted, is `failed` — not a clean wiki with zero
610
+ findings. Each finding is **informational only** — `fix.kind:
611
+ 'no_op'` with the description of the issue. The actual editing happens
612
+ in a `dream_review` loop (next section), not via `dream_apply`.
613
+
614
+ When the review loop closes (or you dismiss the whole run), the file
615
+ moves to `~/.somora/wiki-lucid/processed/` with the loop summary
616
+ appended for the audit trail.
617
+
618
+ ### Reviewing Lucid findings — the `dream_review` loop
619
+
620
+ Findings are walked by an agent in conversation with you, not via
621
+ button-click approval. You start the loop with one agent, talk through
622
+ each finding, the agent writes changes via loop-scoped `wiki_*` tools
623
+ when you OK each step, and you close the loop when done.
624
+
625
+ ```
626
+ > you: have a look at the lucid result
627
+ scribe: dream_list → finds the Lucid run
628
+ dream_get(id) → reads all findings
629
+ dream_review({dream_id, action: 'start'}) ← opens the loop
630
+ "Here is what Lucid found: 5 contradictions, 2 dead refs.
631
+ Starting with the first: page X says Y, page Z says W.
632
+ My proposal: <concrete change>. OK?"
633
+
634
+ > you: yes, do it
635
+ scribe: wiki_edit({...}) ← writes the page
636
+ "Done. Next finding: ..."
637
+
638
+ > [several rounds of walk-discuss-edit]
639
+
640
+ > you: good, wrap it up
641
+ scribe: dream_review({dream_id, action: 'end', summary: '...'}) ← closes
642
+ findings you did not get to stay open; the run is archived only
643
+ when none are left (or with dismiss_rest: true); a later loop
644
+ continues where this one stopped, and Lucid runs no new scan
645
+ while findings wait
646
+ ```
647
+
648
+ While the loop is active for an agent:
649
+
650
+ - The agent gets `wiki_edit` / `wiki_create` / `wiki_delete` / `wiki_move` (loop-scoped)
651
+ - Read-only file tools (`file_read`, `file_search`, `file_list`,
652
+ `analyze_file`) stay available so the agent can look up source
653
+ material before proposing an edit. `file_write` / `file_patch` are
654
+ hidden — only wiki_* may mutate.
655
+ - The agent's `exec_*` / `agents_*` / `skill_*` / `tmux_*` tools are
656
+ temporarily hidden so the conversation stays focused. Hiding is
657
+ enforced at the call, not only in the listing: a hidden tool invoked
658
+ from a definition the model already had is refused.
659
+ - **CLI engines (claude-cli, codex-cli, grok-cli) receive the tool
660
+ list once per turn.** Starting the loop mid-turn does not make
661
+ `wiki_*` callable in that same turn — they appear on the next turn.
662
+ Practical pattern: `dream_review start`, end the reply, continue after
663
+ the user speaks. `dream_dismiss` with `resolved_manually: true`
664
+ closes a finding you resolved by other means at any time.
665
+ - Other agents continue normal operation but cannot start their own
666
+ loop until this one ends — somora-instance-global lock
667
+ - The TUI status line shows `📝 wiki-review:<agent>`
668
+ - Per-turn cap: max 3 wiki_* calls in a single turn
669
+ (`wiki.lucid.maxCallsPerTurn`) so the agent cannot batch-edit
670
+ without checking in. Resets on every user message.
671
+ - Auto-expiry: 24h idle without activity → loop auto-closes as a
672
+ safety net in case the agent forgot to call `action: 'end'`
673
+
674
+ `wiki_edit` accepts body changes (`newBody`) and/or frontmatter ops
675
+ (`relatedAdd`, `relatedRemove`, `sourcesAdd`, `sourcesRemove`) — all
676
+ optional. Pass only what you want to touch. Useful pattern: clear a
677
+ dead `related:` ref with `wiki_edit({wikiPath, relatedRemove: ['dead/page']})`
678
+ without touching the body.
679
+
680
+ ## Reviewing findings — the `dream_*` tool surface
681
+
682
+ REM and Lucid have different review flows because the cost of a wrong
683
+ auto-apply differs:
684
+
685
+ - **REM findings** are atomic memory writes — small, easy to audit
686
+ individually, isolated to one agent's inbox. They use the per-finding
687
+ approval pattern (`dream_apply` / `dream_dismiss`).
688
+ - **Lucid findings** are wiki edits that ripple across multiple pages
689
+ and need the user's judgement. They use the conversational
690
+ `dream_review` loop described above.
691
+
692
+ Tools:
693
+
694
+ ```
695
+ dream_list([include_processed]) List pending dreams (REM + Lucid);
696
+ include_processed:true adds resolved ones
697
+ dream_get(dream_id) Show full content of a dream
698
+ dream_apply(dream_id, finding_id) Accept REM finding → applied
699
+ dream_dismiss(dream_id, [finding_id], Reject (one finding or whole run);
700
+ [reason], resolved_manually:true records
701
+ [resolved_manually]) "handled outside the dream flow"
702
+ instead of "rejected"
703
+ dream_run({phase, [wait], [force]}) Trigger Deep or Lucid manually
704
+ dream_review({dream_id, action, [summary]})
705
+ Open/close the wiki review loop
706
+ for a Lucid run (Lucid only)
707
+ ```
708
+
709
+ `dream_list` returns a `kind` discriminator per entry:
710
+
711
+ - `kind: 'memory'` — REM finding, scoped to the agent in whose chat
712
+ you're calling. Other agents don't see it.
713
+ - `kind: 'wiki_lucid'` — Lucid finding, platform-wide. Any agent with
714
+ the `dream` toolset sees the same set.
715
+
716
+ Typical REM flow:
717
+
718
+ ```
719
+ scribe> dream_list
720
+ → memory dream: 5 pending findings
721
+ scribe> dream_get dream_id=<id>
722
+ → full finding list with action, slug, reason, proposed_content
723
+ > walk through with me, finding by finding
724
+ scribe> dream_apply (or dream_dismiss)
725
+ → repeats until all resolved → dream_done: true
726
+ ```
727
+
728
+ Typical Lucid flow:
729
+
730
+ ```
731
+ scribe> dream_list
732
+ → wiki_lucid run: 6 pending findings
733
+ scribe> dream_get dream_id=<id>
734
+ → full finding list (all fix.kind = 'no_op' informational)
735
+ scribe> dream_review({dream_id, action: 'start'})
736
+ → loop opens, wiki_* tools become available, file_*/exec_* etc. hide
737
+ [walk-discuss-edit conversation rounds]
738
+ scribe> dream_review({dream_id, action: 'end', summary: 'F1 applied as edit X, F2 dismissed, ...'})
739
+ → loop closes, run archived
740
+ ```
741
+
742
+ `dream_apply` on a Lucid finding (always `no_op`) marks it applied
743
+ without writing anything — useful only as
744
+ acknowledge-and-move-on if you don't want the loop. The actual fix
745
+ path is the loop.
746
+
747
+ ## Triggering manually
748
+
749
+ REM is per-agent: `/reset YES` reads the session it archives,
750
+ `dream_run({phase: 'rem'})` (or `POST /agents/:agent/dream/run-rem`)
751
+ catches up every unread session of the calling agent, and the idle
752
+ timer does the same on its own.
753
+
754
+ Deep and Lucid are platform-wide:
755
+
756
+ ```
757
+ # In any agent's chat:
758
+ > ruf bitte dream_run({phase: 'deep'}) auf
759
+ > dream_run({phase: 'lucid'})
760
+ > dream_run({phase: 'deep', force: true}) # bypass hash-cache
761
+
762
+ # Or HTTP directly:
763
+ curl -X POST http://127.0.0.1:18737/dream/run-deep -d '{"wait":true}'
764
+ curl -X POST http://127.0.0.1:18737/dream/run-lucid -d '{"wait":true}'
765
+ ```
766
+
767
+ `wait: true` blocks the request until the run finishes (returns full
768
+ outcome). Default `wait: false` is fire-and-forget — agent gets a
769
+ "started in background" reply, run completes on its own. `force` is
770
+ honoured by `run-deep` only.
771
+
772
+ Two read-only routes expose the state: `GET /dream-states` (per-agent
773
+ REM activity and pending counts plus the Deep/Lucid running flags) and
774
+ `GET /dream/loop-state` (the active review loop, if any).
775
+
776
+ ## Configuration cheat-sheet
777
+
778
+ ```yaml
779
+ # config.yaml — platform-wide
780
+ wiki:
781
+ enabled: true
782
+ vaultSubfolder: somora # → <vault>/somora/
783
+ language: de # de | en — scaffolding + prose language
784
+ deep:
785
+ enabled: true
786
+ intervalHours: 12
787
+ model: <alias> # required
788
+ # thinking: medium # optional; reasoning_effort for the
789
+ # Deep worker LLM. Off by default.
790
+ mergeShrinkGuard:
791
+ enabled: true # refuse merges that shrink a page
792
+ minRatio: 0.5 # newBody < 0.5 × existingBody → skip
793
+ minExistingBytes: 2000 # smaller pages are never guarded
794
+ skipCacheDays: 30 # a cached skip of an unchanged note is
795
+ # looked at again after this; 0 = never
796
+ lucid:
797
+ enabled: true
798
+ intervalDays: 7
799
+ model: <alias> # required
800
+ requireApproval: true
801
+ maxCallsPerTurn: 3
802
+ # thinking: medium # optional; reasoning_effort for the
803
+ # Lucid worker LLM. Off by default.
804
+ search:
805
+ boostWiki: 1.4 # wiki hits rank above memory
806
+ boostMemory: 0.85
807
+ boostVault: 0.65
808
+ rem:
809
+ dedup:
810
+ enabled: true # mechanical dedup after extraction
811
+ similarityThreshold: 0.85
812
+ judge:
813
+ enabled: false # coverage judge (see REM → Coverage judge)
814
+ # model: <alias> # default: the agent's REM worker
815
+ candidates: 4
816
+ maxPageChars: 6000
817
+ minConfidence: 80
818
+ maxPerRun: 60
819
+ ```
820
+
821
+ ```yaml
822
+ # agent.yaml — per-agent
823
+ rem:
824
+ enabled: true
825
+ model: <alias> # required when enabled
826
+ # fallback: <alias> # optional backup worker
827
+ idleMinutes: 30
828
+ chunkTokens: 50000
829
+ chunkTimeoutMs: 600000
830
+ participate_in_wiki: true
831
+ # thinking: medium # optional; dormant unless the REM
832
+ # worker model has the 'reasoning'
833
+ # capability.
834
+ ```
835
+
836
+ All three `thinking` fields are optional and unset = engine default
837
+ (no reasoning_effort sent). See [thinking.md](thinking.md) for the
838
+ per-engine mapping table and dormant-state semantics.
839
+
840
+ ## Where things live
841
+
842
+ ```
843
+ ~/.somora/agents/<agent>/memory/ ← memory inbox (REM writes here)
844
+ ~/.somora/agents/<agent>/memory/.dreams/ ← REM run files awaiting approval
845
+ ~/.somora/agents/<agent>/memory/.dreams/processed/ ← resolved REM runs
846
+ ~/.somora/agents/<agent>/memory/.deep-skip-cache.json ← Deep hash-cache
847
+ ~/.somora/wiki-lucid/<run-id>.json ← Lucid run files
848
+ ~/.somora/wiki-lucid/processed/ ← resolved Lucid runs
849
+ <vault>/<wiki-subfolder>/ ← the wiki itself
850
+ <vault>/<wiki-subfolder>/index.md ← auto-regenerated topology
851
+ <vault>/<wiki-subfolder>/logs/YYYY-MM.md ← monthly Deep audit log
852
+ ```
853
+
854
+ ## What dreams won't do
855
+
856
+ - **Auto-write to memory or wiki without approval** — except Deep, which
857
+ runs auto-apply (no approval) but is bounded to the structured
858
+ `MemoryFateDecision` and writes only the markdown the LLM produced.
859
+ - **Edit content outside the agent's memory or the wiki subfolder** — the
860
+ rest of your Obsidian vault stays read-only from somora's perspective.
861
+ - **Sync across machines automatically** — somora is single-host. Use git
862
+ or syncthing on the wiki subfolder if you want cross-device sync (memory
863
+ inboxes are ephemeral inboxes, not worth syncing).
864
+
865
+ ## Design rationale
866
+
867
+ Each phase has its own worker model so you can tune cost vs quality
868
+ independently:
869
+
870
+ - REM runs often → cheap local model is fine for atomic-fact extraction.
871
+ - Deep runs occasionally → strong model is worth it for quality consolidation.
872
+ - Lucid runs rarely → strong model definitely worth it for finding
873
+ contradictions.
874
+
875
+ Each phase has its own approval policy so you control surface area:
876
+
877
+ - REM proposes; you decide what enters memory.
878
+ - Deep auto-applies; mistakes are recoverable in Obsidian.
879
+ - Lucid proposes; you decide what gets fixed in the wiki.
880
+
881
+ The wiki is the only place where stable knowledge lives. The memory
882
+ inbox is volatile by design — files come in, get consolidated, get
883
+ deleted. The vault is read-only context (your Obsidian notes outside
884
+ the wiki subfolder are yours, not somora's).
885
+
886
+ ## See also
887
+
888
+ - [memory.md](memory.md) — how the memory inbox indexes and retrieves
889
+ - [wiki.md](wiki.md) — the shared long-term wiki layer
890
+ - [agents.md](agents.md) — per-agent configuration including REM
891
+ - [tools.md](tools.md) — full tool reference (`dream_*` is one toolset among the others)