ltcai 11.2.0 → 11.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +46 -53
  2. package/docs/CHANGELOG.md +61 -0
  3. package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
  4. package/docs/DEVELOPMENT.md +1 -1
  5. package/docs/MULTI_AGENT_RUNTIME.md +1 -1
  6. package/docs/ONBOARDING.md +1 -1
  7. package/docs/OPERATIONS.md +6 -2
  8. package/docs/PERMISSION_MODE.md +1 -1
  9. package/docs/TRUST_MODEL.md +1 -1
  10. package/docs/WHY_LATTICE.md +1 -1
  11. package/docs/kg-schema.md +2 -2
  12. package/docs/v11.3.0_PLAN.md +202 -0
  13. package/docs/v11.4.0_RUST_FOUNDATION_PLAN.md +176 -0
  14. package/lattice_brain/__init__.py +1 -1
  15. package/lattice_brain/graph/_kg_common/__init__.py +287 -0
  16. package/lattice_brain/graph/_kg_common/extraction.py +516 -0
  17. package/lattice_brain/graph/_kg_common/relations.py +161 -0
  18. package/lattice_brain/graph/_kg_common/text.py +479 -0
  19. package/lattice_brain/graph/discovery_index/__init__.py +35 -0
  20. package/lattice_brain/graph/discovery_index/cleanup.py +182 -0
  21. package/lattice_brain/graph/discovery_index/extract.py +137 -0
  22. package/lattice_brain/graph/discovery_index/scan.py +411 -0
  23. package/lattice_brain/graph/discovery_index/upsert.py +495 -0
  24. package/lattice_brain/graph/projection/__init__.py +42 -0
  25. package/lattice_brain/graph/projection/curation.py +500 -0
  26. package/lattice_brain/graph/{projection.py → projection/v2_schema.py} +15 -477
  27. package/lattice_brain/graph/retrieval/__init__.py +54 -0
  28. package/lattice_brain/graph/retrieval/context.py +197 -0
  29. package/lattice_brain/graph/retrieval/graph_view.py +319 -0
  30. package/lattice_brain/graph/retrieval/hybrid.py +488 -0
  31. package/lattice_brain/graph/retrieval/maintenance.py +121 -0
  32. package/lattice_brain/graph/retrieval/signals.py +95 -0
  33. package/lattice_brain/graph/retrieval_vector/__init__.py +42 -0
  34. package/lattice_brain/graph/retrieval_vector/fingerprint.py +97 -0
  35. package/lattice_brain/graph/retrieval_vector/indexing.py +347 -0
  36. package/lattice_brain/graph/retrieval_vector/search.py +560 -0
  37. package/lattice_brain/graph/retrieval_vector/status.py +374 -0
  38. package/lattice_brain/ingestion/__init__.py +130 -0
  39. package/lattice_brain/ingestion/_contract.py +90 -0
  40. package/lattice_brain/ingestion/constants.py +127 -0
  41. package/lattice_brain/ingestion/folder_scan.py +57 -0
  42. package/lattice_brain/ingestion/folders.py +258 -0
  43. package/lattice_brain/ingestion/hashing.py +26 -0
  44. package/lattice_brain/ingestion/jobs_api.py +107 -0
  45. package/lattice_brain/ingestion/models.py +80 -0
  46. package/lattice_brain/ingestion/pipeline.py +486 -0
  47. package/lattice_brain/ingestion/quality.py +209 -0
  48. package/lattice_brain/ingestion/routing.py +295 -0
  49. package/lattice_brain/multimodal/__init__.py +164 -0
  50. package/lattice_brain/multimodal/audio.py +77 -0
  51. package/lattice_brain/multimodal/common.py +118 -0
  52. package/lattice_brain/multimodal/images.py +498 -0
  53. package/lattice_brain/multimodal/ports.py +169 -0
  54. package/lattice_brain/multimodal/video.py +410 -0
  55. package/lattice_brain/portability/__init__.py +90 -0
  56. package/lattice_brain/portability/_contract.py +42 -0
  57. package/lattice_brain/portability/backups.py +338 -0
  58. package/lattice_brain/portability/bundles.py +136 -0
  59. package/lattice_brain/portability/constants.py +93 -0
  60. package/lattice_brain/portability/fsops.py +138 -0
  61. package/lattice_brain/portability/service.py +41 -0
  62. package/lattice_brain/{portability.py → portability/sharing.py} +44 -677
  63. package/lattice_brain/runtime/__init__.py +1 -1
  64. package/lattice_brain/runtime/multi_agent.py +1 -1
  65. package/latticeai/__init__.py +1 -1
  66. package/latticeai/api/chronicle.py +63 -0
  67. package/latticeai/core/agent/__init__.py +93 -0
  68. package/latticeai/core/agent/_contract.py +79 -0
  69. package/latticeai/core/agent/context.py +57 -0
  70. package/latticeai/core/agent/deps.py +125 -0
  71. package/latticeai/core/agent/execution.py +622 -0
  72. package/latticeai/core/agent/planning.py +145 -0
  73. package/latticeai/core/agent/recovery.py +157 -0
  74. package/latticeai/core/agent/runtime.py +210 -0
  75. package/latticeai/core/agent/verification.py +231 -0
  76. package/latticeai/core/embedding_providers/__init__.py +151 -0
  77. package/latticeai/core/embedding_providers/base.py +199 -0
  78. package/latticeai/core/embedding_providers/captions.py +162 -0
  79. package/latticeai/core/embedding_providers/profiles.py +126 -0
  80. package/latticeai/core/embedding_providers/text.py +350 -0
  81. package/latticeai/core/embedding_providers/vision.py +352 -0
  82. package/latticeai/core/file_generation/__init__.py +115 -0
  83. package/latticeai/core/file_generation/bundles.py +76 -0
  84. package/latticeai/core/file_generation/extraction.py +154 -0
  85. package/latticeai/core/file_generation/inference.py +235 -0
  86. package/latticeai/core/file_generation/orchestration.py +152 -0
  87. package/latticeai/core/file_generation/prompting.py +117 -0
  88. package/latticeai/core/file_generation/repair.py +114 -0
  89. package/latticeai/core/file_generation/sanitize.py +61 -0
  90. package/latticeai/core/file_generation/validation.py +201 -0
  91. package/latticeai/core/legacy_compatibility.py +1 -1
  92. package/latticeai/core/marketplace.py +1 -1
  93. package/latticeai/core/messages.py +9 -0
  94. package/latticeai/core/workspace_os_constants.py +1 -1
  95. package/latticeai/integrations/telegram_bot/__init__.py +123 -0
  96. package/latticeai/integrations/telegram_bot/__main__.py +17 -0
  97. package/latticeai/integrations/telegram_bot/config.py +86 -0
  98. package/latticeai/integrations/telegram_bot/dispatch.py +311 -0
  99. package/latticeai/integrations/telegram_bot/flows.py +478 -0
  100. package/latticeai/integrations/telegram_bot/helpers.py +322 -0
  101. package/latticeai/integrations/telegram_bot/screens.py +394 -0
  102. package/latticeai/models/router/__init__.py +88 -0
  103. package/latticeai/models/router/_contract.py +66 -0
  104. package/latticeai/models/router/branding.py +56 -0
  105. package/latticeai/models/router/catalog.py +69 -0
  106. package/latticeai/models/router/documents.py +199 -0
  107. package/latticeai/models/router/errors.py +37 -0
  108. package/latticeai/models/router/generation.py +258 -0
  109. package/latticeai/models/router/loading.py +291 -0
  110. package/latticeai/models/router/local_models.py +85 -0
  111. package/latticeai/models/router/registry.py +147 -0
  112. package/latticeai/runtime/build_phases/__init__.py +82 -0
  113. package/latticeai/runtime/build_phases/features.py +407 -0
  114. package/latticeai/runtime/build_phases/foundation.py +555 -0
  115. package/latticeai/runtime/build_phases/web.py +492 -0
  116. package/latticeai/runtime/runtime_context.py +1 -0
  117. package/latticeai/services/architecture_readiness.py +48 -19
  118. package/latticeai/services/brain_intelligence/__init__.py +58 -0
  119. package/latticeai/services/brain_intelligence/_contract.py +71 -0
  120. package/latticeai/services/brain_intelligence/consistency.py +193 -0
  121. package/latticeai/services/brain_intelligence/constants.py +47 -0
  122. package/latticeai/services/brain_intelligence/digest.py +258 -0
  123. package/latticeai/services/brain_intelligence/health.py +331 -0
  124. package/latticeai/services/brain_intelligence/proposals.py +264 -0
  125. package/latticeai/services/brain_intelligence/sampling.py +84 -0
  126. package/latticeai/services/brain_intelligence/service.py +48 -0
  127. package/latticeai/services/chronicle.py +557 -0
  128. package/latticeai/services/memory_service/__init__.py +52 -0
  129. package/latticeai/services/memory_service/_contract.py +100 -0
  130. package/latticeai/services/memory_service/brief.py +431 -0
  131. package/latticeai/services/memory_service/constants.py +57 -0
  132. package/latticeai/services/memory_service/maintenance.py +138 -0
  133. package/latticeai/services/memory_service/manager.py +186 -0
  134. package/latticeai/services/memory_service/proof.py +136 -0
  135. package/latticeai/services/memory_service/recall.py +225 -0
  136. package/latticeai/services/memory_service/service.py +48 -0
  137. package/latticeai/services/memory_service/stores.py +110 -0
  138. package/latticeai/services/model_runtime/__init__.py +322 -0
  139. package/latticeai/services/model_runtime/cloud.py +87 -0
  140. package/latticeai/services/model_runtime/download.py +282 -0
  141. package/latticeai/services/model_runtime/engines.py +341 -0
  142. package/latticeai/services/model_runtime/loading.py +178 -0
  143. package/latticeai/services/model_runtime/service.py +129 -0
  144. package/latticeai/services/model_runtime/state.py +131 -0
  145. package/latticeai/services/model_runtime/status.py +255 -0
  146. package/latticeai/services/product_readiness.py +15 -7
  147. package/latticeai/setup/wizard/__init__.py +126 -0
  148. package/latticeai/setup/wizard/catalog.py +172 -0
  149. package/latticeai/setup/wizard/detect.py +323 -0
  150. package/latticeai/setup/wizard/install.py +348 -0
  151. package/latticeai/setup/wizard/paths.py +168 -0
  152. package/latticeai/setup/wizard/plans.py +74 -0
  153. package/latticeai/setup/wizard/recommend.py +320 -0
  154. package/package.json +6 -2
  155. package/scripts/bump_version.py +14 -0
  156. package/scripts/capture_release_evidence.mjs +33 -21
  157. package/scripts/check_current_release_docs.mjs +1 -1
  158. package/scripts/check_i18n_namespace_coverage.mjs +41 -4
  159. package/scripts/check_max_file_lines.mjs +102 -0
  160. package/scripts/check_release_evidence_bound.mjs +30 -15
  161. package/scripts/check_screenshot_pixel_delta.py +34 -4
  162. package/scripts/check_server_i18n.mjs +1 -0
  163. package/scripts/generate_rust_parity_fixtures.py +562 -0
  164. package/scripts/lib/mock_server_fingerprint.mjs +94 -0
  165. package/scripts/release_screen_claims.json +31 -2
  166. package/src-tauri/Cargo.lock +361 -3
  167. package/src-tauri/Cargo.toml +6 -1
  168. package/src-tauri/src/backend.rs +349 -0
  169. package/src-tauri/src/folder.rs +33 -0
  170. package/src-tauri/src/main.rs +97 -399
  171. package/src-tauri/tauri.conf.json +1 -1
  172. package/static/app/asset-manifest.json +41 -37
  173. package/static/app/assets/Act-yYpYnn0v.js +1 -0
  174. package/static/app/assets/AdminConsole-DL3Cr5pL.js +1 -0
  175. package/static/app/assets/{Brain-tuhI4sOC.js → Brain-C1HBN0Wf.js} +2 -2
  176. package/static/app/assets/BrainHome-DoXRhUUC.js +2 -0
  177. package/static/app/assets/BrainSignals-6yR6ir5t.js +1 -0
  178. package/static/app/assets/Capture-CFIRsFNE.js +1 -0
  179. package/static/app/assets/Chronicle-BZbEgiwN.js +1 -0
  180. package/static/app/assets/CommandPalette-D2pMxC2I.js +1 -0
  181. package/static/app/assets/Library-DwO3yZST.js +1 -0
  182. package/static/app/assets/{LivingBrain-DBwhto14.js → LivingBrain-Jn1GK0-S.js} +1 -1
  183. package/static/app/assets/ProductFlow-B-w1R4Oo.js +1 -0
  184. package/static/app/assets/ReviewCard-6B27X8Vg.js +3 -0
  185. package/static/app/assets/System-DW8F-2xL.js +1 -0
  186. package/static/app/assets/arrow-left-DXvKg9U6.js +1 -0
  187. package/static/app/assets/{bot-Cia42c2h.js → bot-IM_E_Y12.js} +1 -1
  188. package/static/app/assets/brain-Ci1CkWjM.js +1 -0
  189. package/static/app/assets/{button-2j2Ijzgq.js → button-COwyqfHM.js} +1 -1
  190. package/static/app/assets/circle-check-DfInj-qD.js +1 -0
  191. package/static/app/assets/{circle-pause-BEFeWpVW.js → circle-pause-DEM4A1Y5.js} +1 -1
  192. package/static/app/assets/{circle-play-ujXMcHxl.js → circle-play-C9djDuLd.js} +1 -1
  193. package/static/app/assets/{cpu-k4awryFq.js → cpu-DFdo1gw-.js} +1 -1
  194. package/static/app/assets/{download-DFbLJ_ig.js → download-SnJL6oqk.js} +1 -1
  195. package/static/app/assets/{folder-open-7y_b6xkM.js → folder-open-CqZeDkjE.js} +1 -1
  196. package/static/app/assets/{hard-drive-Bidh02Kr.js → hard-drive-j1jJXYYf.js} +1 -1
  197. package/static/app/assets/{index-DwDl9-8Y.css → index-BLPb5lmE.css} +1 -1
  198. package/static/app/assets/index-_u5iUHDr.js +10 -0
  199. package/static/app/assets/input-B0lPdRQZ.js +1 -0
  200. package/static/app/assets/link-2-CoFbooHS.js +1 -0
  201. package/static/app/assets/{permissionCopy-Bpb83Hx9.js → permissionCopy-BsyLxtao.js} +1 -1
  202. package/static/app/assets/primitives-DEbN-d6p.js +1 -0
  203. package/static/app/assets/search-BybIWPNd.js +1 -0
  204. package/static/app/assets/{share-2-BH1M-WNi.js → share-2-CVtZ_ewX.js} +1 -1
  205. package/static/app/assets/{shield-alert-BlKdBXcG.js → shield-alert-CBi2GNWM.js} +1 -1
  206. package/static/app/assets/{textarea-CCWbUfFB.js → textarea-DNMpB5ih.js} +1 -1
  207. package/static/app/assets/{useFocusTrap-YdHQ7pJ1.js → useFocusTrap-C83t3GXF.js} +1 -1
  208. package/static/app/assets/useMutation-DtbJDoyz.js +1 -0
  209. package/static/app/assets/{useQuery-CXQiwbVT.js → useQuery-Dcp1OChy.js} +1 -1
  210. package/static/app/assets/utils-BlZr7Pd4.js +4 -0
  211. package/static/app/assets/workspace-jJY4RuAV.js +1 -0
  212. package/static/app/index.html +4 -4
  213. package/static/sw.js +1 -1
  214. package/lattice_brain/graph/_kg_common.py +0 -1331
  215. package/lattice_brain/graph/discovery_index.py +0 -1141
  216. package/lattice_brain/graph/retrieval.py +0 -1120
  217. package/lattice_brain/graph/retrieval_vector.py +0 -1293
  218. package/lattice_brain/ingestion.py +0 -1525
  219. package/lattice_brain/multimodal.py +0 -1258
  220. package/latticeai/core/agent.py +0 -1465
  221. package/latticeai/core/embedding_providers.py +0 -1196
  222. package/latticeai/core/file_generation.py +0 -1047
  223. package/latticeai/integrations/telegram_bot.py +0 -1390
  224. package/latticeai/models/router.py +0 -1007
  225. package/latticeai/runtime/build_phases.py +0 -1450
  226. package/latticeai/services/brain_intelligence.py +0 -1083
  227. package/latticeai/services/memory_service.py +0 -1177
  228. package/latticeai/services/model_runtime.py +0 -1281
  229. package/latticeai/setup/wizard.py +0 -1310
  230. package/static/app/assets/Act-AWf0SAKp.js +0 -1
  231. package/static/app/assets/AdminConsole-D0u8Tiyj.js +0 -1
  232. package/static/app/assets/BrainHome-Ts7G_Ila.js +0 -2
  233. package/static/app/assets/BrainSignals-jMYgQ2Ar.js +0 -1
  234. package/static/app/assets/Capture-CqOSzyPr.js +0 -1
  235. package/static/app/assets/CommandPalette-DC0Bzh-I.js +0 -1
  236. package/static/app/assets/Library-CX-bbhmK.js +0 -1
  237. package/static/app/assets/ProductFlow-BHA2cfKI.js +0 -1
  238. package/static/app/assets/ReviewCard-BUhCKRNM.js +0 -3
  239. package/static/app/assets/System-Bu2t5hn1.js +0 -1
  240. package/static/app/assets/arrow-left-Dzwa5zRb.js +0 -1
  241. package/static/app/assets/brain-DJMoqrwx.js +0 -1
  242. package/static/app/assets/index-BpYkzcVm.js +0 -10
  243. package/static/app/assets/input-DSlJJxRs.js +0 -1
  244. package/static/app/assets/primitives-BCx6TvfG.js +0 -1
  245. package/static/app/assets/search-Cgy8cCFJ.js +0 -1
  246. package/static/app/assets/utils-zqPZJxdx.js +0 -4
  247. package/static/app/assets/workspace-DXTihhfU.js +0 -1
@@ -0,0 +1,100 @@
1
+ """The seam the memory mixins share.
2
+
3
+ ``MemoryService`` is assembled from the store-read, manager, brief, proof,
4
+ recall and maintenance mixins. Every one of them reads constructor state it
5
+ does not own, and most of them call methods another mixin implements. That
6
+ contract existed as an unwritten convention inside one class; this module
7
+ writes it down.
8
+
9
+ Typing-only, exactly like :mod:`lattice_brain.portability._contract`: the
10
+ declarations below are never executed as behaviour — each body is a bare
11
+ ``raise NotImplementedError`` that the composed class always overrides — so the
12
+ MRO and every method resolution stay what the single-file class had. Adding a
13
+ cross-mixin call without declaring it here is a type error.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from pathlib import Path
19
+ from typing import Any, Dict, List, Optional
20
+
21
+
22
+ class MemoryCore:
23
+ """What any memory mixin may assume about ``self``.
24
+
25
+ Members are declared, not implemented: the implementation lives in
26
+ ``service.py`` (constructor state) or in whichever mixin owns the method.
27
+ """
28
+
29
+ # ── State owned by MemoryService.__init__ ────────────────────────────────
30
+ _store: Any
31
+ _kg: Any
32
+ _enable_graph: bool
33
+ _data_dir: Path
34
+ _history_file: Path
35
+ _conversation_store: Any
36
+
37
+ # ── stores.py: the reads every other surface is built on ─────────────────
38
+ def _workspace_memories(
39
+ self, *, user_email: Optional[str], workspace_id: Optional[str]
40
+ ) -> List[Dict[str, Any]]:
41
+ raise NotImplementedError
42
+
43
+ def _all_memories(self) -> List[Dict[str, Any]]:
44
+ raise NotImplementedError
45
+
46
+ def _snapshots(self, *, workspace_id: Optional[str]) -> List[Dict[str, Any]]:
47
+ raise NotImplementedError
48
+
49
+ def _conversations(self) -> List[Dict[str, Any]]:
50
+ raise NotImplementedError
51
+
52
+ def _scoped_conversations(
53
+ self, *, user_email: Optional[str], workspace_id: Optional[str]
54
+ ) -> List[Dict[str, Any]]:
55
+ raise NotImplementedError
56
+
57
+ def _kg_stats(self) -> Optional[Dict[str, Any]]:
58
+ raise NotImplementedError
59
+
60
+ def _kg_index(self) -> Optional[Dict[str, Any]]:
61
+ raise NotImplementedError
62
+
63
+ # ── manager.py: the cross-tier report the brief and the proof rest on ────
64
+ def manager(
65
+ self, *, user_email: Optional[str] = None, workspace_id: Optional[str] = None
66
+ ) -> Dict[str, Any]:
67
+ raise NotImplementedError
68
+
69
+ # ── proof.py / recall.py: what the brief composes ────────────────────────
70
+ def brain_proof(
71
+ self,
72
+ *,
73
+ user_email: Optional[str] = None,
74
+ workspace_id: Optional[str] = None,
75
+ active_model: Optional[str] = None,
76
+ recall_query: str = "",
77
+ limit: int = 3,
78
+ ) -> Dict[str, Any]:
79
+ raise NotImplementedError
80
+
81
+ def recall(
82
+ self,
83
+ query: str,
84
+ *,
85
+ user_email: Optional[str] = None,
86
+ workspace_id: Optional[str] = None,
87
+ limit: int = 20,
88
+ ) -> Dict[str, Any]:
89
+ raise NotImplementedError
90
+
91
+ # ── maintenance.py: clear() delegates every scope to prune() ─────────────
92
+ def prune(
93
+ self,
94
+ *,
95
+ ids: Optional[List[str]] = None,
96
+ kind: Optional[str] = None,
97
+ user_email: Optional[str] = None,
98
+ workspace_id: Optional[str] = None,
99
+ ) -> Dict[str, Any]:
100
+ raise NotImplementedError
@@ -0,0 +1,431 @@
1
+ """The Brain Brief: what to notice, why it is believable, what to do next.
2
+
3
+ The home screen's compact briefing. It answers three product questions from
4
+ data that already exists — the Memory Manager report and the Brain Proof — and
5
+ invents nothing: the focus is a real recalled row, a real memory, a real
6
+ conversation or a real graph count, in that order, and an empty Brain says so.
7
+
8
+ Everything else here is a descriptor list, not copy: labels are i18n keys the
9
+ UI resolves, so the wording stays in the frontend and the *ordering* — which is
10
+ a product judgement about priority — stays here.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Any, Dict, List, Optional
16
+
17
+ from latticeai.core.timeutil import now_iso as _now
18
+
19
+ from ._contract import MemoryCore as _Core
20
+
21
+
22
+ class MemoryBriefMixin(_Core):
23
+ """The Brain Brief and its descriptors. Mixed into ``MemoryService``."""
24
+
25
+ def brain_brief(
26
+ self,
27
+ *,
28
+ user_email: Optional[str] = None,
29
+ workspace_id: Optional[str] = None,
30
+ active_model: Optional[str] = None,
31
+ recall_query: str = "",
32
+ limit: int = 3,
33
+ ) -> Dict[str, Any]:
34
+ """Return a compact, evidence-backed Brain briefing for the home screen.
35
+
36
+ The brief intentionally reuses the Memory Manager and Brain Proof data
37
+ instead of inventing UI-only facts. It answers three product questions:
38
+ what should the user notice, why can the Brain prove it, and what is the
39
+ easiest next action.
40
+ """
41
+ manager = self.manager(user_email=user_email, workspace_id=workspace_id)
42
+ proof = self.brain_proof(
43
+ user_email=user_email,
44
+ workspace_id=workspace_id,
45
+ active_model=active_model,
46
+ recall_query=recall_query,
47
+ limit=limit,
48
+ )
49
+ readiness = manager.get("brain_readiness") or {}
50
+ state = str(readiness.get("state") or "quiet")
51
+ proofs = proof.get("proofs") or {}
52
+ recall = proof.get("recall") or {}
53
+ recall_items = [item for item in recall.get("items") or [] if isinstance(item, dict)]
54
+ durable_items = int(proofs.get("durable_items") or 0)
55
+ workspace_memories = int(proofs.get("workspace_memories") or 0)
56
+ conversations = int(proofs.get("conversations") or 0)
57
+ graph_concepts = int(proofs.get("graph_concepts") or 0)
58
+ vector_items = int(proofs.get("vector_items") or 0)
59
+ healthy_sources = int(proofs.get("healthy_sources") or 0)
60
+
61
+ focus = self._brain_brief_focus(
62
+ user_email=user_email,
63
+ workspace_id=workspace_id,
64
+ recall_items=recall_items,
65
+ durable_items=durable_items,
66
+ graph_concepts=graph_concepts,
67
+ query=str(recall.get("query") or recall_query or ""),
68
+ )
69
+ actions = self._brain_brief_actions(
70
+ state=state,
71
+ has_durable_evidence=bool(proofs.get("has_durable_evidence")),
72
+ has_recall=bool(recall_items),
73
+ graph_concepts=graph_concepts,
74
+ )
75
+ suggested_questions = self._brain_brief_suggested_questions(
76
+ focus=focus,
77
+ has_durable_evidence=bool(proofs.get("has_durable_evidence")),
78
+ has_recall=bool(recall_items),
79
+ graph_concepts=graph_concepts,
80
+ conversations=conversations,
81
+ )
82
+ proactive_actions = self._brain_brief_proactive_actions(
83
+ focus=focus,
84
+ state=state,
85
+ has_durable_evidence=bool(proofs.get("has_durable_evidence")),
86
+ has_recall=bool(recall_items),
87
+ graph_concepts=graph_concepts,
88
+ vector_items=vector_items,
89
+ healthy_sources=healthy_sources,
90
+ )
91
+ return {
92
+ "status": state,
93
+ "score": int(readiness.get("score") or 0),
94
+ "headline_key": f"brain.brief.headline.{state if state in {'quiet', 'forming', 'alive'} else 'quiet'}",
95
+ "body_key": f"brain.brief.body.{state if state in {'quiet', 'forming', 'alive'} else 'quiet'}",
96
+ "focus": focus,
97
+ "next_actions": actions,
98
+ "suggested_questions": suggested_questions,
99
+ "proactive_actions": proactive_actions,
100
+ "evidence": [
101
+ {
102
+ "id": "durable",
103
+ "label_key": "brain.brief.evidence.durable",
104
+ "value": durable_items,
105
+ "detail_key": "brain.brief.evidence.durable.detail",
106
+ },
107
+ {
108
+ "id": "graph",
109
+ "label_key": "brain.brief.evidence.graph",
110
+ "value": graph_concepts,
111
+ "detail_key": "brain.brief.evidence.graph.detail",
112
+ },
113
+ {
114
+ "id": "sources",
115
+ "label_key": "brain.brief.evidence.sources",
116
+ "value": healthy_sources,
117
+ "detail_key": "brain.brief.evidence.sources.detail",
118
+ },
119
+ ],
120
+ "signals": {
121
+ "workspace_memories": workspace_memories,
122
+ "conversations": conversations,
123
+ "graph_concepts": graph_concepts,
124
+ "vector_items": vector_items,
125
+ "healthy_sources": healthy_sources,
126
+ },
127
+ "proof": {
128
+ "query": recall.get("query") or "",
129
+ "items": recall_items[: max(1, min(limit, 6))],
130
+ "model_continuity": proof.get("model_continuity") or {},
131
+ },
132
+ "generated_at": _now(),
133
+ }
134
+
135
+ def _brain_brief_focus(
136
+ self,
137
+ *,
138
+ user_email: Optional[str],
139
+ workspace_id: Optional[str],
140
+ recall_items: List[Dict[str, Any]],
141
+ durable_items: int,
142
+ graph_concepts: int,
143
+ query: str,
144
+ ) -> Dict[str, Any]:
145
+ if recall_items:
146
+ first = recall_items[0]
147
+ return {
148
+ "kind": "recall",
149
+ "title": str(first.get("title") or "Memory"),
150
+ "detail": str(first.get("snippet") or query or ""),
151
+ "source": str(first.get("source") or "memory"),
152
+ "score": float(first.get("score") or 0),
153
+ }
154
+
155
+ memories = self._workspace_memories(user_email=user_email, workspace_id=workspace_id or "personal")
156
+ if memories:
157
+ first_memory = memories[0]
158
+ return {
159
+ "kind": "memory",
160
+ "title": str(first_memory.get("kind") or "memory"),
161
+ "detail": str(first_memory.get("content") or "")[:240],
162
+ "source": "workspace",
163
+ "score": 1.0,
164
+ }
165
+
166
+ conversations = self._scoped_conversations(user_email=user_email, workspace_id=workspace_id)
167
+ if conversations:
168
+ latest = conversations[-1]
169
+ messages = latest.get("messages") if isinstance(latest, dict) else []
170
+ last_message = next((m for m in reversed(messages or []) if isinstance(m, dict) and str(m.get("content") or "").strip()), {})
171
+ return {
172
+ "kind": "conversation",
173
+ "title": str(latest.get("title") or latest.get("id") or "conversation"),
174
+ "detail": str(last_message.get("content") or "")[:240],
175
+ "source": "conversation",
176
+ "score": 1.0,
177
+ }
178
+
179
+ if graph_concepts > 0:
180
+ return {
181
+ "kind": "graph",
182
+ "title": "Knowledge Graph",
183
+ "detail": f"{graph_concepts} graph concepts are ready to inspect.",
184
+ "source": "graph",
185
+ "score": 1.0,
186
+ }
187
+
188
+ return {
189
+ "kind": "empty",
190
+ "title": "",
191
+ "detail": "",
192
+ "source": "none",
193
+ "score": 0,
194
+ "empty": durable_items <= 0,
195
+ }
196
+
197
+ @staticmethod
198
+ def _brain_brief_actions(
199
+ *,
200
+ state: str,
201
+ has_durable_evidence: bool,
202
+ has_recall: bool,
203
+ graph_concepts: int,
204
+ ) -> List[Dict[str, Any]]:
205
+ actions: List[Dict[str, Any]] = []
206
+ if not has_durable_evidence:
207
+ actions.extend([
208
+ {
209
+ "id": "add_source",
210
+ "label_key": "brain.brief.action.add",
211
+ "detail_key": "brain.brief.action.add.detail",
212
+ "route": "/capture",
213
+ "priority": 10,
214
+ },
215
+ {
216
+ "id": "ask_brain",
217
+ "label_key": "brain.brief.action.ask",
218
+ "detail_key": "brain.brief.action.ask.detail",
219
+ "route": "",
220
+ "priority": 9,
221
+ },
222
+ ])
223
+ else:
224
+ actions.append({
225
+ "id": "ask_brain",
226
+ "label_key": "brain.brief.action.ask",
227
+ "detail_key": "brain.brief.action.ask.detail",
228
+ "route": "",
229
+ "priority": 10,
230
+ })
231
+ if graph_concepts > 0 or state == "alive":
232
+ actions.append({
233
+ "id": "inspect_topics",
234
+ "label_key": "brain.brief.action.topics",
235
+ "detail_key": "brain.brief.action.topics.detail",
236
+ "route": "/knowledge-graph",
237
+ "priority": 8,
238
+ })
239
+ if has_recall:
240
+ actions.append({
241
+ "id": "verify_model",
242
+ "label_key": "brain.brief.action.verify",
243
+ "detail_key": "brain.brief.action.verify.detail",
244
+ "route": "",
245
+ "priority": 7,
246
+ })
247
+ actions.append({
248
+ "id": "backup_brain",
249
+ "label_key": "brain.brief.action.backup",
250
+ "detail_key": "brain.brief.action.backup.detail",
251
+ "route": "/settings",
252
+ "priority": 6,
253
+ })
254
+ return sorted(actions, key=lambda item: int(item.get("priority") or 0), reverse=True)[:4]
255
+
256
+ @staticmethod
257
+ def _brain_brief_proactive_actions(
258
+ *,
259
+ focus: Dict[str, Any],
260
+ state: str,
261
+ has_durable_evidence: bool,
262
+ has_recall: bool,
263
+ graph_concepts: int,
264
+ vector_items: int,
265
+ healthy_sources: int,
266
+ ) -> List[Dict[str, Any]]:
267
+ """Return concrete, one-click actions Brain can proactively suggest."""
268
+ focus_title = str(focus.get("title") or "").strip() or "Brain"
269
+ focus_detail = str(focus.get("detail") or "").strip()
270
+ actions: List[Dict[str, Any]] = []
271
+ if not has_durable_evidence:
272
+ actions.append({
273
+ "id": "proactive_add_source",
274
+ "intent": "route",
275
+ "label_key": "brain.proactive.addSource.label",
276
+ "detail_key": "brain.proactive.addSource.detail",
277
+ "route": "/capture",
278
+ "prompt": "Add a useful source to my Brain and explain what it learned.",
279
+ "priority": 100,
280
+ })
281
+ actions.append({
282
+ "id": "proactive_seed_memory",
283
+ "intent": "ask",
284
+ "label_key": "brain.proactive.seed.label",
285
+ "detail_key": "brain.proactive.seed.detail",
286
+ "prompt": "Help me seed my Brain with the most useful personal context to remember.",
287
+ "priority": 90,
288
+ })
289
+ return actions
290
+
291
+ if has_recall:
292
+ actions.append({
293
+ "id": "proactive_evidence_review",
294
+ "intent": "ask",
295
+ "label_key": "brain.proactive.evidence.label",
296
+ "detail_key": "brain.proactive.evidence.detail",
297
+ "prompt": (
298
+ f"Review the evidence Brain has for {focus_title}. "
299
+ "Separate confirmed facts, weak signals, contradictions, and next checks."
300
+ ),
301
+ "priority": 100,
302
+ "context": {"focus": focus_title, "detail": focus_detail},
303
+ })
304
+ actions.append({
305
+ "id": "proactive_delegate",
306
+ "intent": "delegate",
307
+ "label_key": "brain.proactive.delegate.label",
308
+ "detail_key": "brain.proactive.delegate.detail",
309
+ "prompt": (
310
+ f"Turn {focus_title} into an execution plan, verify the known context, "
311
+ "and return concrete next steps with risks."
312
+ ),
313
+ "priority": 95,
314
+ "context": {"focus": focus_title, "detail": focus_detail},
315
+ })
316
+ actions.append({
317
+ "id": "proactive_review_draft",
318
+ "intent": "review",
319
+ "label_key": "brain.proactive.review.label",
320
+ "detail_key": "brain.proactive.review.detail",
321
+ "prompt": (
322
+ f"Create a reviewable task from Brain's current focus: {focus_title}. "
323
+ f"{focus_detail[:240]}"
324
+ ).strip(),
325
+ "priority": 90,
326
+ "context": {"focus": focus_title, "detail": focus_detail},
327
+ })
328
+
329
+ if graph_concepts > 0:
330
+ actions.append({
331
+ "id": "proactive_map_connections",
332
+ "intent": "route",
333
+ "label_key": "brain.proactive.map.label",
334
+ "detail_key": "brain.proactive.map.detail",
335
+ "route": "/knowledge-graph",
336
+ "prompt": f"Map the strongest Knowledge Graph connections around {focus_title}.",
337
+ "priority": 82,
338
+ "context": {"focus": focus_title, "graph_concepts": graph_concepts},
339
+ })
340
+
341
+ if state == "alive" and vector_items > 0 and healthy_sources > 0:
342
+ actions.append({
343
+ "id": "proactive_weekly_brief",
344
+ "intent": "review",
345
+ "label_key": "brain.proactive.weekly.label",
346
+ "detail_key": "brain.proactive.weekly.detail",
347
+ "prompt": (
348
+ "Prepare a weekly Brain review: what changed, what decisions are pending, "
349
+ "what should be delegated, and what evidence is stale."
350
+ ),
351
+ "priority": 78,
352
+ "context": {"vector_items": vector_items, "healthy_sources": healthy_sources},
353
+ })
354
+
355
+ return sorted(actions, key=lambda item: int(item.get("priority") or 0), reverse=True)[:4]
356
+
357
+ @staticmethod
358
+ def _brain_brief_suggested_questions(
359
+ *,
360
+ focus: Dict[str, Any],
361
+ has_durable_evidence: bool,
362
+ has_recall: bool,
363
+ graph_concepts: int,
364
+ conversations: int,
365
+ ) -> List[Dict[str, Any]]:
366
+ """Return reusable, localized UI prompt descriptors for the Brain home."""
367
+ focus_title = str(focus.get("title") or "").strip()
368
+ focus_kind = str(focus.get("kind") or "empty")
369
+ questions: List[Dict[str, Any]] = []
370
+
371
+ if not has_durable_evidence or focus_kind == "empty":
372
+ questions.extend([
373
+ {
374
+ "id": "start_brain",
375
+ "label_key": "brain.suggestion.start.label",
376
+ "detail_key": "brain.suggestion.start.detail",
377
+ "prompt_key": "brain.suggestion.start.prompt",
378
+ "params": {},
379
+ "priority": 10,
380
+ },
381
+ {
382
+ "id": "add_context",
383
+ "label_key": "brain.suggestion.context.label",
384
+ "detail_key": "brain.suggestion.context.detail",
385
+ "prompt_key": "brain.suggestion.context.prompt",
386
+ "params": {},
387
+ "priority": 9,
388
+ },
389
+ ])
390
+ return questions
391
+
392
+ questions.append({
393
+ "id": "focus_next",
394
+ "label_key": "brain.suggestion.focus.label",
395
+ "detail_key": "brain.suggestion.focus.detail",
396
+ "prompt_key": "brain.suggestion.focus.prompt",
397
+ "params": {"focus": focus_title or "Brain"},
398
+ "priority": 10,
399
+ })
400
+
401
+ if has_recall:
402
+ questions.append({
403
+ "id": "evidence_check",
404
+ "label_key": "brain.suggestion.evidence.label",
405
+ "detail_key": "brain.suggestion.evidence.detail",
406
+ "prompt_key": "brain.suggestion.evidence.prompt",
407
+ "params": {"focus": focus_title or "this topic"},
408
+ "priority": 9,
409
+ })
410
+
411
+ if graph_concepts > 0:
412
+ questions.append({
413
+ "id": "graph_connections",
414
+ "label_key": "brain.suggestion.graph.label",
415
+ "detail_key": "brain.suggestion.graph.detail",
416
+ "prompt_key": "brain.suggestion.graph.prompt",
417
+ "params": {"focus": focus_title or "Knowledge Graph"},
418
+ "priority": 8,
419
+ })
420
+
421
+ if conversations > 0:
422
+ questions.append({
423
+ "id": "conversation_followup",
424
+ "label_key": "brain.suggestion.history.label",
425
+ "detail_key": "brain.suggestion.history.detail",
426
+ "prompt_key": "brain.suggestion.history.prompt",
427
+ "params": {"focus": focus_title or "recent conversations"},
428
+ "priority": 7,
429
+ })
430
+
431
+ return sorted(questions, key=lambda item: int(item.get("priority") or 0), reverse=True)[:4]
@@ -0,0 +1,57 @@
1
+ """The memory tiers' vocabulary, the service's error, and the visual passthrough.
2
+
3
+ Everything here is a literal or a pure function over one recall row: no store,
4
+ no service, no I/O. Keeping it in one leaf module is what lets the store reads,
5
+ the manager, the brief and the maintenance surfaces share the same names
6
+ without importing each other.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import logging
12
+ from typing import Any, Dict
13
+
14
+ # Personal workspace memory kinds (from WorkspaceOS.MEMORY_KINDS).
15
+ WORKSPACE_KINDS = (
16
+ "short_term",
17
+ "workspace",
18
+ "preferences",
19
+ "decisions",
20
+ "working_style",
21
+ "frequently_used_tools",
22
+ "long_term",
23
+ )
24
+
25
+ TIERS = ("workspace", "project", "agent", "conversation", "graph", "vector")
26
+ LOGGER = logging.getLogger(__name__)
27
+
28
+
29
+ #: Longest inline thumbnail a recall row will carry (see ``_visual_fields``).
30
+ MAX_RECALL_THUMBNAIL_CHARS = 24_000
31
+
32
+
33
+ def _visual_fields(hit: Dict[str, Any]) -> Dict[str, Any]:
34
+ """Caption + inline thumbnail for a recall row, when the node has them.
35
+
36
+ v11.1.0: an ``Image`` node stores a 96px ``data:`` thumbnail and — only if
37
+ a vision-language model produced one — a caption. Passing them through here
38
+ is what lets the Evidence panel show the picture it is citing without a new
39
+ static route over the user's disk and without going around the local-file
40
+ approval gate: the bytes are already inside the graph payload the user
41
+ asked for. Absent keys stay absent, so every non-image row is unchanged.
42
+ """
43
+ metadata = hit.get("metadata")
44
+ if not isinstance(metadata, dict):
45
+ return {}
46
+ fields: Dict[str, Any] = {}
47
+ caption = str(metadata.get("caption") or "").strip()
48
+ if caption:
49
+ fields["caption"] = caption[:400]
50
+ thumbnail = str(metadata.get("thumbnail") or "")
51
+ if thumbnail.startswith("data:image/") and len(thumbnail) <= MAX_RECALL_THUMBNAIL_CHARS:
52
+ fields["thumbnail"] = thumbnail
53
+ return fields
54
+
55
+
56
+ class MemoryServiceError(RuntimeError):
57
+ """Raised when a configured memory backend cannot be read reliably."""