ltcai 11.5.2 → 11.7.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 (443) hide show
  1. package/README.md +93 -148
  2. package/bin/ltcai.js +234 -24
  3. package/docs/CHANGELOG.md +119 -0
  4. package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
  5. package/docs/DEVELOPMENT.md +8 -6
  6. package/docs/ENTERPRISE.md +2 -1
  7. package/docs/MULTI_AGENT_RUNTIME.md +12 -5
  8. package/docs/ONBOARDING.md +1 -1
  9. package/docs/OPERATIONS.md +6 -3
  10. package/docs/REALTIME_COLLABORATION.md +1 -1
  11. package/docs/TRUST_MODEL.md +1 -1
  12. package/docs/WHY_LATTICE.md +1 -1
  13. package/docs/WORKFLOW_DESIGNER.md +3 -2
  14. package/docs/kg-schema.md +1 -1
  15. package/docs/v11.6.0_ONE_DOOR_PLAN.md +170 -0
  16. package/lattice_brain/__init__.py +42 -79
  17. package/lattice_brain/graph/__init__.py +9 -24
  18. package/lattice_brain/graph/_kg_common/__init__.py +13 -24
  19. package/lattice_brain/ingestion/__init__.py +19 -58
  20. package/lattice_brain/ingestion/pipeline.py +20 -398
  21. package/lattice_brain/multimodal/__init__.py +7 -18
  22. package/lattice_brain/multimodal/images.py +6 -264
  23. package/lattice_brain/multimodal/video.py +8 -247
  24. package/lattice_brain/runtime/__init__.py +8 -79
  25. package/lattice_brain/runtime/hooks.py +22 -584
  26. package/latticeai/__init__.py +1 -1
  27. package/latticeai/api/agent_worker_seam.py +7 -80
  28. package/latticeai/api/health.py +6 -20
  29. package/latticeai/api/local_files.py +16 -613
  30. package/latticeai/api/models.py +12 -87
  31. package/latticeai/api/search.py +17 -255
  32. package/latticeai/api/tools.py +69 -750
  33. package/latticeai/api/voice_capture.py +8 -70
  34. package/latticeai/api/worker_compute.py +842 -0
  35. package/latticeai/api/worker_seams.py +216 -0
  36. package/latticeai/app_factory.py +23 -232
  37. package/latticeai/cli/entrypoint.py +36 -249
  38. package/latticeai/core/agent_permission.py +16 -91
  39. package/latticeai/core/messages.py +89 -531
  40. package/latticeai/runtime/access_runtime.py +0 -14
  41. package/latticeai/runtime/bootstrap.py +10 -21
  42. package/latticeai/runtime/brain_runtime.py +35 -43
  43. package/latticeai/runtime/build_phases/__init__.py +21 -37
  44. package/latticeai/runtime/build_phases/features.py +99 -389
  45. package/latticeai/runtime/build_phases/foundation.py +82 -392
  46. package/latticeai/runtime/build_phases/web.py +91 -408
  47. package/latticeai/runtime/build_phases/worker_profile.py +244 -0
  48. package/latticeai/runtime/lifespan_runtime.py +7 -16
  49. package/latticeai/runtime/platform_services_runtime.py +1 -15
  50. package/latticeai/runtime/runtime_context.py +13 -130
  51. package/latticeai/runtime/security_runtime.py +10 -103
  52. package/latticeai/services/architecture_readiness.py +82 -43
  53. package/latticeai/services/model_runtime/__init__.py +2 -11
  54. package/latticeai/services/model_runtime/service.py +4 -28
  55. package/latticeai/services/p_reinforce.py +10 -261
  56. package/latticeai/services/product_readiness.py +31 -38
  57. package/latticeai/services/search_service.py +37 -795
  58. package/latticeai/services/tool_dispatch.py +30 -386
  59. package/latticeai/services/voice_capture.py +13 -107
  60. package/latticeai/tools/__init__.py +22 -49
  61. package/latticeai/tools/commands.py +0 -163
  62. package/latticeai/tools/computer.py +0 -39
  63. package/latticeai/tools/documents.py +1 -134
  64. package/latticeai/tools/filesystem.py +1 -247
  65. package/latticeai/tools/knowledge.py +1 -52
  66. package/latticeai/tools/local_files.py +0 -20
  67. package/latticeai/worker_app.py +75 -0
  68. package/package.json +2 -3
  69. package/requirements.txt +0 -5
  70. package/scripts/agent_eval.py +16 -28
  71. package/scripts/brain_quality_eval.py +20 -183
  72. package/scripts/bump_version.py +5 -5
  73. package/scripts/check_current_release_docs.mjs +7 -4
  74. package/scripts/check_openapi_drift.mjs +10 -0
  75. package/scripts/check_server_i18n.mjs +2 -18
  76. package/scripts/compose_openapi.py +377 -0
  77. package/scripts/export_openapi.py +32 -4
  78. package/scripts/gen_messages_catalog_fixture.py +302 -0
  79. package/scripts/gen_openapi_fragments.py +365 -0
  80. package/scripts/gen_redact_fixture.py +196 -0
  81. package/scripts/gen_worker_allowlist_fixture.py +115 -0
  82. package/scripts/generate_agent_parity_fixtures.py +33 -14
  83. package/scripts/openapi_route_families.json +2161 -0
  84. package/scripts/release_screen_claims.json +54 -0
  85. package/scripts/run_integration_tests.mjs +134 -29
  86. package/scripts/run_sidecar_e2e.mjs +104 -11
  87. package/scripts/wheel_smoke.py +32 -22
  88. package/src-tauri/Cargo.lock +375 -9
  89. package/src-tauri/Cargo.toml +1 -1
  90. package/src-tauri/src/backend.rs +151 -45
  91. package/src-tauri/src/main.rs +18 -18
  92. package/src-tauri/src/topology.rs +58 -88
  93. package/src-tauri/tauri.conf.json +1 -2
  94. package/static/app/asset-manifest.json +41 -41
  95. package/static/app/assets/{Act-DcQizkl1.js → Act-BPcVAbOL.js} +1 -1
  96. package/static/app/assets/AdminConsole-Bw1ATQL0.js +1 -0
  97. package/static/app/assets/{Brain-3VCSHFcn.js → Brain-CT92Kos0.js} +2 -2
  98. package/static/app/assets/{BrainHome-Qm8eaztx.js → BrainHome-CFBkt1K_.js} +1 -1
  99. package/static/app/assets/{BrainSignals-DS9BtKOW.js → BrainSignals-ReLWF2H8.js} +1 -1
  100. package/static/app/assets/Capture-BsTokYkk.js +1 -0
  101. package/static/app/assets/{Chronicle-BGvuAchH.js → Chronicle-B6f0T9id.js} +1 -1
  102. package/static/app/assets/{CommandPalette-Bqhm0Urn.js → CommandPalette-CuvjTv1u.js} +1 -1
  103. package/static/app/assets/{Library-BV6NnF0a.js → Library-BGJbG9Hd.js} +1 -1
  104. package/static/app/assets/{LivingBrain-GzenJchP.js → LivingBrain-DGYK_Jsa.js} +1 -1
  105. package/static/app/assets/{ProductFlow-DEP6-vML.js → ProductFlow-DXBC6brE.js} +1 -1
  106. package/static/app/assets/{ReviewCard-CNZ7XjWG.js → ReviewCard-HXRle3qq.js} +2 -2
  107. package/static/app/assets/System-CMHSO9qM.js +1 -0
  108. package/static/app/assets/arrow-left-BfmkskWx.js +1 -0
  109. package/static/app/assets/{bot-B_K1Tdmw.js → bot-Cn8bWRuq.js} +1 -1
  110. package/static/app/assets/{brain-DWyaV1L1.js → brain-CQJberbE.js} +1 -1
  111. package/static/app/assets/{button-aTn4s84A.js → button-Ct9f2_oT.js} +1 -1
  112. package/static/app/assets/circle-check-DruOxB-4.js +1 -0
  113. package/static/app/assets/{circle-pause-xKgeGXkT.js → circle-pause-CmzC_apg.js} +1 -1
  114. package/static/app/assets/{circle-play-DkT6tYPX.js → circle-play-D8mW2aQ7.js} +1 -1
  115. package/static/app/assets/{cpu-85xYObUC.js → cpu-DZcdd0PZ.js} +1 -1
  116. package/static/app/assets/{download-B5Fm7YXo.js → download-bv1KEPGQ.js} +1 -1
  117. package/static/app/assets/{folder-open-kk2Xa52u.js → folder-open-d-Pip5gr.js} +1 -1
  118. package/static/app/assets/{hard-drive-DkA3zBW_.js → hard-drive-D20iavUb.js} +1 -1
  119. package/static/app/assets/index-D9x-kSNy.css +2 -0
  120. package/static/app/assets/{index-BMPdTmlY.js → index-Do83hDzJ.js} +3 -3
  121. package/static/app/assets/{input-B0nRf2jO.js → input-BLXVNmj1.js} +1 -1
  122. package/static/app/assets/{link-2-Dwb4gnTc.js → link-2-BPJOFlAy.js} +1 -1
  123. package/static/app/assets/{permissionCopy-CQDUBrOZ.js → permissionCopy-ChdJd493.js} +1 -1
  124. package/static/app/assets/primitives-Cv5tbZBY.js +1 -0
  125. package/static/app/assets/search-CT9aho2j.js +1 -0
  126. package/static/app/assets/{share-2-BsrxFglO.js → share-2-YNX_NtMU.js} +1 -1
  127. package/static/app/assets/{shield-alert-5BStfp2_.js → shield-alert-DuQ3zrVL.js} +1 -1
  128. package/static/app/assets/{textarea-Cg8IUA-k.js → textarea-DqwLnli4.js} +1 -1
  129. package/static/app/assets/{useFocusTrap-CYKvE46M.js → useFocusTrap-ZVI98jaW.js} +1 -1
  130. package/static/app/assets/{useMutation-CSn9t1op.js → useMutation-CVC4qv_D.js} +1 -1
  131. package/static/app/assets/{useQuery-CY2OI2uy.js → useQuery-C7BeG4HU.js} +1 -1
  132. package/static/app/assets/{utils-Ddol2RWD.js → utils-CiFtIdZq.js} +1 -1
  133. package/static/app/assets/{workspace-BqDwOz_p.js → workspace-DQz9vIId.js} +1 -1
  134. package/static/app/index.html +4 -4
  135. package/static/sw.js +1 -1
  136. package/lattice_brain/archive.py +0 -522
  137. package/lattice_brain/context.py +0 -325
  138. package/lattice_brain/conversations.py +0 -382
  139. package/lattice_brain/core.py +0 -82
  140. package/lattice_brain/graph/_kg_contract.py +0 -249
  141. package/lattice_brain/graph/curator.py +0 -676
  142. package/lattice_brain/graph/discovery.py +0 -595
  143. package/lattice_brain/graph/discovery_index/__init__.py +0 -35
  144. package/lattice_brain/graph/discovery_index/cleanup.py +0 -182
  145. package/lattice_brain/graph/discovery_index/extract.py +0 -137
  146. package/lattice_brain/graph/discovery_index/scan.py +0 -411
  147. package/lattice_brain/graph/discovery_index/upsert.py +0 -495
  148. package/lattice_brain/graph/documents.py +0 -380
  149. package/lattice_brain/graph/fusion.py +0 -395
  150. package/lattice_brain/graph/identity.py +0 -175
  151. package/lattice_brain/graph/image_vectors.py +0 -230
  152. package/lattice_brain/graph/ingest.py +0 -829
  153. package/lattice_brain/graph/network.py +0 -205
  154. package/lattice_brain/graph/proactive.py +0 -724
  155. package/lattice_brain/graph/projection/__init__.py +0 -42
  156. package/lattice_brain/graph/projection/curation.py +0 -500
  157. package/lattice_brain/graph/projection/v2_schema.py +0 -518
  158. package/lattice_brain/graph/provenance.py +0 -524
  159. package/lattice_brain/graph/rerank.py +0 -163
  160. package/lattice_brain/graph/retrieval/__init__.py +0 -54
  161. package/lattice_brain/graph/retrieval/context.py +0 -197
  162. package/lattice_brain/graph/retrieval/graph_view.py +0 -319
  163. package/lattice_brain/graph/retrieval/hybrid.py +0 -488
  164. package/lattice_brain/graph/retrieval/maintenance.py +0 -121
  165. package/lattice_brain/graph/retrieval/signals.py +0 -95
  166. package/lattice_brain/graph/retrieval_docgen.py +0 -253
  167. package/lattice_brain/graph/retrieval_policy.py +0 -180
  168. package/lattice_brain/graph/retrieval_reads.py +0 -769
  169. package/lattice_brain/graph/retrieval_vector/__init__.py +0 -42
  170. package/lattice_brain/graph/retrieval_vector/fingerprint.py +0 -97
  171. package/lattice_brain/graph/retrieval_vector/indexing.py +0 -347
  172. package/lattice_brain/graph/retrieval_vector/search.py +0 -560
  173. package/lattice_brain/graph/retrieval_vector/status.py +0 -374
  174. package/lattice_brain/graph/schema.py +0 -792
  175. package/lattice_brain/graph/store.py +0 -268
  176. package/lattice_brain/graph/vector_index/__init__.py +0 -85
  177. package/lattice_brain/graph/vector_index/base.py +0 -167
  178. package/lattice_brain/graph/vector_index/brute_force.py +0 -110
  179. package/lattice_brain/graph/vector_index/hnsw.py +0 -290
  180. package/lattice_brain/graph/vector_index/jobs.py +0 -287
  181. package/lattice_brain/graph/vector_index/quantized.py +0 -148
  182. package/lattice_brain/graph/vector_index/selector.py +0 -161
  183. package/lattice_brain/graph/write_master.py +0 -308
  184. package/lattice_brain/ingestion/_contract.py +0 -90
  185. package/lattice_brain/ingestion/folder_scan.py +0 -57
  186. package/lattice_brain/ingestion/folders.py +0 -258
  187. package/lattice_brain/ingestion/jobs_api.py +0 -107
  188. package/lattice_brain/ingestion/routing.py +0 -295
  189. package/lattice_brain/ingestion_jobs.py +0 -380
  190. package/lattice_brain/memory.py +0 -75
  191. package/lattice_brain/portability/__init__.py +0 -90
  192. package/lattice_brain/portability/_contract.py +0 -42
  193. package/lattice_brain/portability/backups.py +0 -338
  194. package/lattice_brain/portability/bundles.py +0 -136
  195. package/lattice_brain/portability/constants.py +0 -93
  196. package/lattice_brain/portability/fsops.py +0 -138
  197. package/lattice_brain/portability/service.py +0 -41
  198. package/lattice_brain/portability/sharing.py +0 -710
  199. package/lattice_brain/quality.py +0 -543
  200. package/lattice_brain/retrieval_benchmark_fixtures.py +0 -92
  201. package/lattice_brain/runtime/agent_runtime.py +0 -859
  202. package/lattice_brain/runtime/contracts.py +0 -460
  203. package/lattice_brain/runtime/multi_agent.py +0 -942
  204. package/lattice_brain/runtime/statuses.py +0 -10
  205. package/lattice_brain/sealed_box.py +0 -240
  206. package/lattice_brain/self_model.py +0 -675
  207. package/lattice_brain/sensitivity.py +0 -94
  208. package/lattice_brain/storage/__init__.py +0 -22
  209. package/lattice_brain/storage/base.py +0 -100
  210. package/lattice_brain/storage/docker.py +0 -105
  211. package/lattice_brain/storage/factory.py +0 -31
  212. package/lattice_brain/storage/migration.py +0 -191
  213. package/lattice_brain/storage/postgres.py +0 -123
  214. package/lattice_brain/storage/sqlite.py +0 -143
  215. package/lattice_brain/synthesis.py +0 -824
  216. package/lattice_brain/workflow.py +0 -497
  217. package/latticeai/api/admin.py +0 -471
  218. package/latticeai/api/agent_registry.py +0 -105
  219. package/latticeai/api/agents.py +0 -228
  220. package/latticeai/api/auth.py +0 -383
  221. package/latticeai/api/automation_intelligence.py +0 -401
  222. package/latticeai/api/brain_intelligence.py +0 -199
  223. package/latticeai/api/browser.py +0 -493
  224. package/latticeai/api/change_proposals.py +0 -89
  225. package/latticeai/api/chat.py +0 -572
  226. package/latticeai/api/chat_agent_http.py +0 -892
  227. package/latticeai/api/chat_contracts.py +0 -73
  228. package/latticeai/api/chat_documents.py +0 -276
  229. package/latticeai/api/chat_helpers.py +0 -460
  230. package/latticeai/api/chat_history.py +0 -101
  231. package/latticeai/api/chat_hybrid.py +0 -113
  232. package/latticeai/api/chat_intents.py +0 -646
  233. package/latticeai/api/chat_stream.py +0 -216
  234. package/latticeai/api/chronicle.py +0 -63
  235. package/latticeai/api/command_center.py +0 -51
  236. package/latticeai/api/computer_use.py +0 -474
  237. package/latticeai/api/evidence_actions.py +0 -48
  238. package/latticeai/api/features.py +0 -70
  239. package/latticeai/api/funnel_metrics.py +0 -31
  240. package/latticeai/api/garden.py +0 -34
  241. package/latticeai/api/hooks.py +0 -165
  242. package/latticeai/api/index_jobs.py +0 -145
  243. package/latticeai/api/invitations.py +0 -100
  244. package/latticeai/api/knowledge_graph.py +0 -536
  245. package/latticeai/api/marketplace.py +0 -105
  246. package/latticeai/api/mcp.py +0 -482
  247. package/latticeai/api/memory.py +0 -270
  248. package/latticeai/api/network.py +0 -81
  249. package/latticeai/api/network_boundary.py +0 -225
  250. package/latticeai/api/permission_mode.py +0 -61
  251. package/latticeai/api/permissions.py +0 -436
  252. package/latticeai/api/plugins.py +0 -126
  253. package/latticeai/api/portability.py +0 -391
  254. package/latticeai/api/project_sessions.py +0 -114
  255. package/latticeai/api/realtime.py +0 -118
  256. package/latticeai/api/review_queue.py +0 -364
  257. package/latticeai/api/security_dashboard.py +0 -604
  258. package/latticeai/api/setup.py +0 -319
  259. package/latticeai/api/static_routes.py +0 -354
  260. package/latticeai/api/ui_redirects.py +0 -26
  261. package/latticeai/api/workflow_designer.py +0 -394
  262. package/latticeai/api/workspace.py +0 -856
  263. package/latticeai/api/workspace_scope.py +0 -125
  264. package/latticeai/core/agent/__init__.py +0 -93
  265. package/latticeai/core/agent/_contract.py +0 -79
  266. package/latticeai/core/agent/context.py +0 -57
  267. package/latticeai/core/agent/deps.py +0 -125
  268. package/latticeai/core/agent/execution.py +0 -622
  269. package/latticeai/core/agent/planning.py +0 -145
  270. package/latticeai/core/agent/recovery.py +0 -157
  271. package/latticeai/core/agent/runtime.py +0 -210
  272. package/latticeai/core/agent/verification.py +0 -231
  273. package/latticeai/core/agent_eval.py +0 -739
  274. package/latticeai/core/agent_helpers.py +0 -493
  275. package/latticeai/core/agent_profiles.py +0 -110
  276. package/latticeai/core/agent_prompts.py +0 -171
  277. package/latticeai/core/agent_registry.py +0 -232
  278. package/latticeai/core/agent_state.py +0 -41
  279. package/latticeai/core/agent_trace.py +0 -104
  280. package/latticeai/core/artifact_ledger.py +0 -109
  281. package/latticeai/core/audit.py +0 -260
  282. package/latticeai/core/builtin_hooks.py +0 -105
  283. package/latticeai/core/context_builder.py +0 -394
  284. package/latticeai/core/document_generator.py +0 -103
  285. package/latticeai/core/enterprise.py +0 -154
  286. package/latticeai/core/enterprise_admin.py +0 -158
  287. package/latticeai/core/file_generation/__init__.py +0 -115
  288. package/latticeai/core/file_generation/bundles.py +0 -76
  289. package/latticeai/core/file_generation/extraction.py +0 -154
  290. package/latticeai/core/file_generation/inference.py +0 -235
  291. package/latticeai/core/file_generation/orchestration.py +0 -152
  292. package/latticeai/core/file_generation/prompting.py +0 -117
  293. package/latticeai/core/file_generation/repair.py +0 -114
  294. package/latticeai/core/file_generation/sanitize.py +0 -61
  295. package/latticeai/core/file_generation/validation.py +0 -201
  296. package/latticeai/core/invitations.py +0 -132
  297. package/latticeai/core/legacy_compatibility.py +0 -243
  298. package/latticeai/core/logging_safety.py +0 -46
  299. package/latticeai/core/marketplace.py +0 -293
  300. package/latticeai/core/mcp_catalog.py +0 -452
  301. package/latticeai/core/mcp_registry.py +0 -506
  302. package/latticeai/core/network_boundary.py +0 -168
  303. package/latticeai/core/oidc.py +0 -208
  304. package/latticeai/core/plugins.py +0 -432
  305. package/latticeai/core/product_hardening.py +0 -218
  306. package/latticeai/core/project_sessions.py +0 -337
  307. package/latticeai/core/realtime.py +0 -238
  308. package/latticeai/core/run_explain.py +0 -426
  309. package/latticeai/core/run_store.py +0 -252
  310. package/latticeai/core/timezones.py +0 -80
  311. package/latticeai/core/workspace_computer_memory.py +0 -84
  312. package/latticeai/core/workspace_graph_trace.py +0 -155
  313. package/latticeai/core/workspace_indexing.py +0 -102
  314. package/latticeai/core/workspace_memory.py +0 -77
  315. package/latticeai/core/workspace_onboarding.py +0 -104
  316. package/latticeai/core/workspace_os.py +0 -978
  317. package/latticeai/core/workspace_os_constants.py +0 -126
  318. package/latticeai/core/workspace_os_state.py +0 -180
  319. package/latticeai/core/workspace_os_utils.py +0 -103
  320. package/latticeai/core/workspace_permissions.py +0 -101
  321. package/latticeai/core/workspace_plugins.py +0 -97
  322. package/latticeai/core/workspace_relationships.py +0 -99
  323. package/latticeai/core/workspace_reorganization.py +0 -335
  324. package/latticeai/core/workspace_review_items.py +0 -112
  325. package/latticeai/core/workspace_runs.py +0 -726
  326. package/latticeai/core/workspace_skills.py +0 -109
  327. package/latticeai/core/workspace_snapshots.py +0 -198
  328. package/latticeai/core/workspace_timeline.py +0 -110
  329. package/latticeai/integrations/__init__.py +0 -0
  330. package/latticeai/integrations/telegram_bot/__init__.py +0 -123
  331. package/latticeai/integrations/telegram_bot/__main__.py +0 -17
  332. package/latticeai/integrations/telegram_bot/config.py +0 -86
  333. package/latticeai/integrations/telegram_bot/dispatch.py +0 -311
  334. package/latticeai/integrations/telegram_bot/flows.py +0 -478
  335. package/latticeai/integrations/telegram_bot/helpers.py +0 -322
  336. package/latticeai/integrations/telegram_bot/screens.py +0 -394
  337. package/latticeai/runtime/audit_runtime.py +0 -76
  338. package/latticeai/runtime/automation_runtime.py +0 -81
  339. package/latticeai/runtime/chat_wiring.py +0 -141
  340. package/latticeai/runtime/context_runtime.py +0 -66
  341. package/latticeai/runtime/feature_toggle_wiring.py +0 -157
  342. package/latticeai/runtime/history_runtime.py +0 -163
  343. package/latticeai/runtime/history_writer.py +0 -138
  344. package/latticeai/runtime/hooks_runtime.py +0 -77
  345. package/latticeai/runtime/model_wiring.py +0 -68
  346. package/latticeai/runtime/namespace_runtime.py +0 -163
  347. package/latticeai/runtime/network_boundary_wiring.py +0 -117
  348. package/latticeai/runtime/network_config_runtime.py +0 -56
  349. package/latticeai/runtime/permission_mode_wiring.py +0 -112
  350. package/latticeai/runtime/persistence_runtime.py +0 -159
  351. package/latticeai/runtime/platform_runtime_wiring.py +0 -89
  352. package/latticeai/runtime/review_wiring.py +0 -42
  353. package/latticeai/runtime/router_registration.py +0 -693
  354. package/latticeai/runtime/service_singletons.py +0 -55
  355. package/latticeai/runtime/sso_config_runtime.py +0 -128
  356. package/latticeai/runtime/user_key_runtime.py +0 -106
  357. package/latticeai/runtime/web_runtime.py +0 -92
  358. package/latticeai/server_app.py +0 -51
  359. package/latticeai/services/app_context.py +0 -130
  360. package/latticeai/services/automation_execution.py +0 -266
  361. package/latticeai/services/automation_intelligence.py +0 -614
  362. package/latticeai/services/brain_automation.py +0 -191
  363. package/latticeai/services/brain_intelligence/__init__.py +0 -58
  364. package/latticeai/services/brain_intelligence/_contract.py +0 -71
  365. package/latticeai/services/brain_intelligence/consistency.py +0 -193
  366. package/latticeai/services/brain_intelligence/constants.py +0 -47
  367. package/latticeai/services/brain_intelligence/digest.py +0 -258
  368. package/latticeai/services/brain_intelligence/health.py +0 -331
  369. package/latticeai/services/brain_intelligence/proposals.py +0 -259
  370. package/latticeai/services/brain_intelligence/sampling.py +0 -84
  371. package/latticeai/services/brain_intelligence/service.py +0 -48
  372. package/latticeai/services/change_proposals.py +0 -471
  373. package/latticeai/services/chat_service.py +0 -243
  374. package/latticeai/services/chronicle.py +0 -555
  375. package/latticeai/services/cloud_egress_audit.py +0 -85
  376. package/latticeai/services/cloud_extraction.py +0 -129
  377. package/latticeai/services/cloud_streaming.py +0 -268
  378. package/latticeai/services/cloud_token_guard.py +0 -84
  379. package/latticeai/services/command_center.py +0 -548
  380. package/latticeai/services/evidence_actions.py +0 -258
  381. package/latticeai/services/feature_toggles.py +0 -502
  382. package/latticeai/services/folder_watch.py +0 -520
  383. package/latticeai/services/funnel_metrics.py +0 -307
  384. package/latticeai/services/hybrid_chat.py +0 -316
  385. package/latticeai/services/hybrid_context.py +0 -228
  386. package/latticeai/services/hybrid_policy.py +0 -129
  387. package/latticeai/services/interop_bridges.py +0 -978
  388. package/latticeai/services/local_knowledge.py +0 -465
  389. package/latticeai/services/memory_service/__init__.py +0 -52
  390. package/latticeai/services/memory_service/_contract.py +0 -100
  391. package/latticeai/services/memory_service/brief.py +0 -431
  392. package/latticeai/services/memory_service/constants.py +0 -57
  393. package/latticeai/services/memory_service/maintenance.py +0 -138
  394. package/latticeai/services/memory_service/manager.py +0 -186
  395. package/latticeai/services/memory_service/proof.py +0 -136
  396. package/latticeai/services/memory_service/recall.py +0 -225
  397. package/latticeai/services/memory_service/service.py +0 -48
  398. package/latticeai/services/memory_service/stores.py +0 -110
  399. package/latticeai/services/mode_store.py +0 -132
  400. package/latticeai/services/model_recommendation.py +0 -224
  401. package/latticeai/services/model_runtime/cloud.py +0 -87
  402. package/latticeai/services/network_boundary_service.py +0 -117
  403. package/latticeai/services/obsidian_bridge.py +0 -609
  404. package/latticeai/services/openai_compatible_adapter.py +0 -101
  405. package/latticeai/services/permission_mode_service.py +0 -122
  406. package/latticeai/services/platform_runtime.py +0 -366
  407. package/latticeai/services/review_queue.py +0 -380
  408. package/latticeai/services/router_context.py +0 -59
  409. package/latticeai/services/run_executor.py +0 -387
  410. package/latticeai/services/self_model_service.py +0 -171
  411. package/latticeai/services/setup_detection.py +0 -147
  412. package/latticeai/services/triggers.py +0 -378
  413. package/latticeai/services/upload_service.py +0 -172
  414. package/latticeai/services/workspace_service.py +0 -165
  415. package/latticeai/setup/__init__.py +0 -25
  416. package/latticeai/setup/auto_setup.py +0 -846
  417. package/latticeai/setup/demo_corpus.py +0 -98
  418. package/latticeai/setup/wizard/__init__.py +0 -126
  419. package/latticeai/setup/wizard/catalog.py +0 -175
  420. package/latticeai/setup/wizard/detect.py +0 -302
  421. package/latticeai/setup/wizard/install.py +0 -348
  422. package/latticeai/setup/wizard/paths.py +0 -165
  423. package/latticeai/setup/wizard/plans.py +0 -74
  424. package/latticeai/setup/wizard/recommend.py +0 -320
  425. package/scripts/bench_agent_smoke.py +0 -409
  426. package/scripts/bench_models.py +0 -540
  427. package/scripts/bench_vector_index.py +0 -295
  428. package/scripts/funnel_soft_gate.py +0 -192
  429. package/scripts/generate_agent_loop_fixtures.py +0 -994
  430. package/scripts/generate_rust_parity_fixtures.py +0 -908
  431. package/scripts/migrate_brain_storage.py +0 -57
  432. package/scripts/parity_fixture_corpus_context.py +0 -162
  433. package/scripts/parity_fixture_corpus_docgen.py +0 -341
  434. package/scripts/profile_kg.py +0 -355
  435. package/server.py +0 -30
  436. package/static/app/assets/AdminConsole-cf4npybT.js +0 -1
  437. package/static/app/assets/Capture-DiQ219jW.js +0 -1
  438. package/static/app/assets/System-CieofHQa.js +0 -1
  439. package/static/app/assets/arrow-left-kfsrk0mv.js +0 -1
  440. package/static/app/assets/circle-check-qqLug9nU.js +0 -1
  441. package/static/app/assets/index-DxmOfNRi.css +0 -2
  442. package/static/app/assets/primitives-SNp0LRJz.js +0 -1
  443. package/static/app/assets/search-BcHqkjoy.js +0 -1
@@ -1,908 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Build the committed Python↔Rust retrieval parity fixture.
3
-
4
- ``rust/lattice-retrieval`` is a port, and a port is only worth having if
5
- something keeps proving it is still one. This script is the Python half of that
6
- proof: it builds a small, fully deterministic Brain with the **real** write path
7
- (``KnowledgeGraphStore._upsert_node`` / ``_upsert_chunk`` / ``_upsert_edge``,
8
- the real hash embedder, the real v2 projection and trigram FTS index), then runs
9
- the real engines over it and writes their answers to ``rust/fixtures/golden/``.
10
- The suite set widens with the port (:data:`SUITES`): the search engines
11
- (v11.4.0); the KG relationship/traverse reads, the service layer, the durable
12
- history reads and the context assembler (v11.5.0); the document-generation
13
- search, traversal and context builder (v11.5.1, whose corpus and runners live
14
- in ``scripts/parity_fixture_corpus_docgen.py``).
15
-
16
- Two consumers read what it writes: ``tests/unit/test_rust_parity_contract.py``
17
- re-runs the Python entry points against the committed database and asserts the
18
- goldens still hold — so a change to Python semantics fails loudly instead of
19
- silently invalidating the contract the Rust side is pinned to — and
20
- ``rust/lattice-retrieval/tests/{parity,suites}.rs`` run the Rust ports against
21
- the same database and the same goldens. Determinism is the whole design
22
- constraint: every timestamp is written by the real code and then **backdated**;
23
- every ``datetime.now()`` the ports reach is frozen at :data:`FROZEN_NOW`
24
- (recorded in the manifest); LLM concept extraction is forced off; every
25
- environment knob is pinned to its default.
26
-
27
- Usage::
28
-
29
- .venv/bin/python scripts/generate_rust_parity_fixtures.py
30
- """
31
-
32
- from __future__ import annotations
33
-
34
- import json
35
- import logging
36
- import os
37
- import shutil
38
- import sqlite3
39
- import sys
40
- from contextlib import contextmanager
41
- from datetime import datetime
42
- from pathlib import Path
43
- from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple
44
-
45
- REPO_ROOT = Path(__file__).resolve().parents[1]
46
- # The repo (for the product packages) and this directory: `scripts` is not a
47
- # package, so the docgen corpus is imported by name off the script directory —
48
- # the same by-path convention the contract test uses to import this file.
49
- for _import_root in (REPO_ROOT, Path(__file__).resolve().parent):
50
- if str(_import_root) not in sys.path:
51
- sys.path.insert(0, str(_import_root))
52
-
53
- import parity_fixture_corpus_context as context_corpus # noqa: E402
54
- import parity_fixture_corpus_docgen as docgen # noqa: E402
55
-
56
- FIXTURE_DIR = REPO_ROOT / "rust" / "fixtures"
57
- GOLDEN_DIR = FIXTURE_DIR / "golden"
58
- STORE_PATH = FIXTURE_DIR / "parity_store.sqlite"
59
-
60
- #: The wall clock the ports see: a golden built against a moving clock is none.
61
- FROZEN_NOW = "2026-08-01T12:00:00"
62
-
63
- #: Every environment variable the ported path reads, pinned to the configuration
64
- #: it targets (brute backend, RRF/expansion/rerank off, rewrite on).
65
- PINNED_ENV: Dict[str, str] = {
66
- "LATTICEAI_VECTOR_DIM": "384",
67
- "LATTICEAI_VECTOR_INDEX": "brute",
68
- "LATTICEAI_VECTOR_MAX_CANDIDATES": "10000",
69
- "LATTICEAI_KG_READ_V2": "1",
70
- "LATTICEAI_FUSION_WEIGHTS": "",
71
- "LATTICEAI_FUSION_STRATEGY": "",
72
- "LATTICEAI_FUSION_RRF": "",
73
- "LATTICEAI_GRAPH_EXPANSION": "",
74
- "LATTICEAI_CROSS_ENCODER_RERANK": "",
75
- "LATTICEAI_QUERY_REWRITE": "",
76
- "LATTICEAI_LLM_EXTRACTION": "false",
77
- }
78
-
79
- WS_ALPHA = "ws-alpha"
80
- WS_BETA = "ws-beta"
81
-
82
- # ── the corpus ───────────────────────────────────────────────────────────────
83
- # (node_id, type, title, summary, metadata, workspace_id, updated_at)
84
- #
85
- # Shaped on purpose: every ``type_boost`` type appears and so do types outside it;
86
- # titles/summaries are half Korean (tokenizer, classifier and extractor all branch
87
- # on script); the ``tie:`` block is five rows sharing one timestamp, one type and
88
- # nothing to match, pinning the (hits, boost, updated_at) → id ASC tie-break; two
89
- # workspaces plus NULL-workspace rows cover all three scoping answers (no scoping
90
- # / empty set / a specific workspace). The v11.5.1 tail is in the docgen corpus.
91
- NODES: List[Tuple[str, str, str, str, Dict[str, Any], Optional[str], str]] = [
92
- ("dec:fusion-alpha", "Decision", "Hybrid retrieval fusion stays alpha weighted",
93
- "We decided the ranking keeps alpha fusion: lexical rank plus max normalized vector score.",
94
- {"category": "retrieval", "owner": "jiwon"}, WS_ALPHA, "2026-07-20T09:00:00"),
95
- ("dec:rust-foundation", "Decision", "Rust 기반 검색 이관 결정",
96
- "검색 랭킹을 Rust로 이관하기로 결정했습니다. 회의 결과 패리티 증명을 먼저 만듭니다.",
97
- {"category": "platform"}, WS_ALPHA, "2026-07-18T14:30:00"),
98
- ("task:parity-harness", "Task", "Build the retrieval parity harness",
99
- "Generate a golden fixture so the Rust ranking can be compared against the Python ranking.",
100
- {"status": "open"}, WS_ALPHA, "2026-07-15T11:00:00"),
101
- ("task:onboarding-checklist", "Task", "온보딩 체크리스트 정리",
102
- "새로운 사용자가 처음 다섯 걸음을 마칠 수 있도록 온보딩 체크리스트를 정리합니다.",
103
- {"status": "open"}, WS_BETA, "2026-06-30T08:20:00"),
104
- ("file:ranking-notes", "File", "ranking-notes.md",
105
- "Notes on ranking: lexical channel scores one over rank, vector channel is max normalized.",
106
- {"filename": "ranking-notes.md", "ext": ".md"}, WS_ALPHA, "2026-07-10T16:45:00"),
107
- ("doc:handbook", "Document", "Lattice AI 사용 안내서",
108
- "제품 안내서입니다. 검색, 회의 기록, 온보딩 체크리스트를 한 곳에서 설명합니다.",
109
- {"filename": "handbook.pdf", "ext": ".pdf", "source_node": "doc:handbook"},
110
- WS_ALPHA, "2026-06-12T10:00:00"),
111
- ("doc:retrieval-spec", "Document", "Retrieval specification",
112
- "The retrieval specification describes the lexical channel, the vector channel and their fusion.",
113
- {"filename": "retrieval-spec.pdf", "ext": ".pdf"}, WS_BETA, "2026-05-28T13:15:00"),
114
- ("code:hybrid-search", "CodeFile", "hybrid.py",
115
- "def hybrid_search(query): the ranking pipeline lives here and calls vector_search().",
116
- {"filename": "hybrid.py", "ext": ".py"}, WS_ALPHA, "2026-07-08T09:30:00"),
117
- ("code:build-failure", "CodeFile", "build_pipeline.py",
118
- "빌드 실패 원인을 남겨두는 파일입니다. 컴파일 오류가 나면 여기부터 확인합니다.",
119
- {"filename": "build_pipeline.py", "ext": ".py"}, WS_BETA, "2026-04-22T18:05:00"),
120
- ("sheet:metrics", "Spreadsheet", "retrieval-metrics.xlsx",
121
- "Recall and precision per query class for the ranking experiments.",
122
- {"filename": "retrieval-metrics.xlsx", "ext": ".xlsx"}, WS_ALPHA, "2026-05-06T09:45:00"),
123
- ("deck:review", "SlideDeck", "분기 리뷰 발표자료",
124
- "지난주 분기 리뷰에서 사용한 발표자료입니다. 검색 품질 지표를 담고 있습니다.",
125
- {"filename": "quarterly-review.pptx", "ext": ".pptx"}, WS_ALPHA, "2026-07-02T15:00:00"),
126
- ("img:whiteboard", "Image", "whiteboard-retrieval.png",
127
- "Whiteboard photo from the retrieval design session.",
128
- {"filename": "whiteboard-retrieval.png", "ext": ".png"}, WS_BETA, "2026-03-19T11:11:00"),
129
- ("img:ocr-notes", "ImageText", "화이트보드 OCR 텍스트",
130
- "회의 결정 사항: 랭킹은 alpha 융합을 유지한다.",
131
- {"filename": "whiteboard-retrieval.png", "ocr": True}, WS_BETA, "2026-03-19T11:12:00"),
132
- ("audio:standup", "Audio", "standup-2026-07-13.m4a",
133
- "Standup recording where the parity harness was assigned.",
134
- {"filename": "standup-2026-07-13.m4a", "ext": ".m4a"}, WS_ALPHA, "2026-07-13T09:05:00"),
135
- ("page:onboarding", "Page", "온보딩 첫 다섯 걸음",
136
- "온보딩 페이지입니다. 체크리스트와 안내 문구를 담습니다.", {}, None, "2026-06-01T12:00:00"),
137
- ("slide:fusion", "Slide", "Fusion slide",
138
- "One slide explaining alpha fusion of the lexical and vector channels.",
139
- {}, None, "2026-05-14T12:00:00"),
140
- ("concept:retrieval", "Concept", "Retrieval",
141
- "Retrieval is the act of finding the right memory for a question.",
142
- {}, WS_ALPHA, "2026-04-02T10:00:00"),
143
- ("concept:ranking", "Concept", "Ranking",
144
- "Ranking orders candidates so the best answer is first.", {}, WS_BETA, "2026-04-03T10:00:00"),
145
- ("person:jiwon", "Person", "김지원 님",
146
- "검색 품질 담당자입니다. 온보딩 개선도 함께 맡고 있습니다.",
147
- {"role": "owner"}, WS_ALPHA, "2026-04-11T10:00:00"),
148
- ("person:minseo", "Person", "박민서 님",
149
- "빌드 파이프라인 담당자입니다.", {"role": "reviewer"}, WS_BETA, "2026-04-12T10:00:00"),
150
- ("meeting:weekly", "Meeting", "주간 회의 2026-07-14",
151
- "지난주 주간 회의 기록입니다. 검색 랭킹과 온보딩을 논의했습니다.",
152
- {}, WS_ALPHA, "2026-07-14T10:00:00"),
153
- ("meeting:kickoff", "Meeting", "Kickoff meeting",
154
- "Kickoff meeting for the Rust foundation work.", {}, WS_BETA, "2026-02-09T10:00:00"),
155
- ("chat:ranking", "Chat", "랭킹 관련 대화",
156
- "랭킹이 왜 이렇게 나오는지 물어본 대화입니다.",
157
- {"conversation_id": "conv-1"}, WS_ALPHA, "2026-07-05T21:00:00"),
158
- ("source:repo", "Source", "github.com/lattice/ai",
159
- "Source repository for the product.", {"source": "git"}, WS_ALPHA, "2026-02-20T10:00:00"),
160
- ("repo:lattice", "Repository", "lattice-ai",
161
- "The monorepo holding the Python worker and the Rust workspace.",
162
- {}, WS_ALPHA, "2026-02-21T10:00:00"),
163
- ("org:lattice", "Organization", "Lattice", "The organization.", {}, None, "2026-02-22T10:00:00"),
164
- ("workflow:nightly", "Workflow", "Nightly reindex",
165
- "A workflow that reindexes the vector store overnight.", {}, WS_BETA, "2026-03-02T10:00:00"),
166
- ("agent:librarian", "Agent", "Librarian agent",
167
- "An agent that files new documents into the graph.", {}, WS_BETA, "2026-03-03T10:00:00"),
168
- ("error:timeout", "Error", "Search timeout",
169
- "An error where the ranking took longer than the request budget.",
170
- {}, WS_ALPHA, "2026-03-04T10:00:00"),
171
- ("feature:command-palette", "Feature", "Command palette",
172
- "The palette that opens search from anywhere.", {}, WS_ALPHA, "2026-03-05T10:00:00"),
173
- ("topic:quality", "Topic", "검색 품질",
174
- "검색 품질에 대한 주제입니다.", {}, WS_ALPHA, "2026-03-06T10:00:00"),
175
- # ── the tie block: identical type, identical timestamp, nothing to match ──
176
- ("tie:a", "Concept", "Tie candidate A", "", {}, WS_ALPHA, "2026-02-01T00:00:00"),
177
- ("tie:b", "Concept", "Tie candidate B", "", {}, WS_ALPHA, "2026-02-01T00:00:00"),
178
- ("tie:c", "Concept", "Tie candidate C", "", {}, WS_BETA, "2026-02-01T00:00:00"),
179
- ("tie:d", "Concept", "Tie candidate D", "", {}, None, "2026-02-01T00:00:00"),
180
- ("tie:e", "Concept", "Tie candidate E", "", {}, None, "2026-02-01T00:00:00"),
181
- # ── boosted twins on the same timestamp: type_boost breaks nothing here,
182
- # id ASC does, and that is the assertion.
183
- ("twin:doc-a", "Document", "Twin document A", "동일한 시각의 문서 A", {}, WS_ALPHA,
184
- "2026-02-05T00:00:00"),
185
- ("twin:doc-b", "Document", "Twin document B", "동일한 시각의 문서 B", {}, WS_ALPHA,
186
- "2026-02-05T00:00:00"),
187
- ("twin:concept-a", "Concept", "Twin concept A", "동일한 시각의 개념 A", {}, WS_ALPHA,
188
- "2026-02-05T00:00:00"),
189
- ("legacy:global-note", "Document", "Legacy global note",
190
- "A legacy row with no workspace, visible only with include_legacy_global.",
191
- {}, None, "2026-06-20T10:00:00"),
192
- *docgen.DOCGEN_NODES,
193
- ]
194
-
195
- # (chunk_id, parent_node_id, index, node_title, text, chunk_fields, workspace, updated_at)
196
- #
197
- # The shape mirrors ``KnowledgeGraphIngestMixin``: every chunk is BOTH a ``Chunk``
198
- # node (lexical lane + workspace scoping) and a ``chunks`` row with its own embedding
199
- # (vector lane, rolled up to its parent) — the duality chunk-heavy queries pin.
200
- CHUNKS: List[Tuple[str, str, int, str, str, Dict[str, Any], Optional[str], str]] = [
201
- ("chunk:handbook:1", "doc:handbook", 0, "handbook.pdf chunk 1",
202
- "온보딩 체크리스트: 첫째, 폴더를 연결합니다. 둘째, 질문을 합니다. 셋째, 근거를 확인합니다.",
203
- {"heading_path": "안내서 > 온보딩", "page": 3, "page_end": 4, "start_char": 0},
204
- WS_ALPHA, "2026-06-12T10:00:01"),
205
- ("chunk:handbook:2", "doc:handbook", 1, "handbook.pdf chunk 2",
206
- "검색 화면에서는 회의 결정 사항을 한 번에 찾을 수 있습니다.",
207
- {"heading_path": "안내서 > 검색", "page": 7, "start_char": 1200},
208
- WS_ALPHA, "2026-06-12T10:00:02"),
209
- ("chunk:spec:1", "doc:retrieval-spec", 0, "retrieval-spec.pdf chunk 1",
210
- "The lexical channel scores one over rank. The vector channel is max normalized before fusion.",
211
- {"heading_path": "Retrieval > Fusion", "page": 2, "start_char": 0},
212
- WS_BETA, "2026-05-28T13:15:01"),
213
- ("chunk:spec:2", "doc:retrieval-spec", 1, "retrieval-spec.pdf chunk 2",
214
- "Ranking ties are broken by node id ascending, which keeps the answer stable across runs.",
215
- {"start_char": 900}, WS_BETA, "2026-05-28T13:15:02"),
216
- ]
217
-
218
- # (from, to, type, weight, created_at)
219
- #
220
- # Weights and timestamps are assigned rather than inherited: ``relationship_search``
221
- # orders by ``weight DESC, created_at DESC, id ASC`` and ``traverse`` caps every BFS
222
- # round with ``ORDER BY weight DESC, id ASC``, so an edge set sharing one weight and
223
- # one clock proves nothing. Three shapes are deliberate — a weight tie broken by
224
- # ``created_at`` (``org:lattice``), a weight *and* clock tie broken by edge id
225
- # (``topic:quality``/``deck:review``), and legacy-global endpoints for scoping. The
226
- # write door canonicalizes types (``relates_to``/``owns`` → ``MENTIONS``), which is
227
- # why the goldens record uppercase names the fixture never spells.
228
- EDGES: List[Tuple[str, str, str, float, str]] = [
229
- ("dec:fusion-alpha", "concept:retrieval", "mentions", 0.9, "2026-07-01T00:00:00"),
230
- ("dec:fusion-alpha", "concept:ranking", "mentions", 0.8, "2026-07-02T00:00:00"),
231
- ("task:parity-harness", "dec:rust-foundation", "relates_to", 1.0, "2026-07-03T00:00:00"),
232
- ("doc:handbook", "page:onboarding", "contains", 0.7, "2026-07-04T00:00:00"),
233
- ("meeting:weekly", "dec:fusion-alpha", "discusses", 0.95, "2026-07-05T00:00:00"),
234
- ("person:jiwon", "task:parity-harness", "owns", 0.6, "2026-07-06T00:00:00"),
235
- ("person:minseo", "code:build-failure", "owns", 0.6, "2026-07-07T00:00:00"),
236
- ("meeting:weekly", "task:onboarding-checklist", "discusses", 0.55, "2026-07-08T00:00:00"),
237
- ("meeting:kickoff", "dec:rust-foundation", "discusses", 0.5, "2026-06-01T00:00:00"),
238
- ("doc:retrieval-spec", "concept:ranking", "mentions", 0.45, "2026-06-02T00:00:00"),
239
- ("concept:retrieval", "concept:ranking", "relates_to", 0.4, "2026-06-03T00:00:00"),
240
- ("file:ranking-notes", "dec:fusion-alpha", "relates_to", 0.35, "2026-06-04T00:00:00"),
241
- ("code:hybrid-search", "file:ranking-notes", "relates_to", 0.3, "2026-06-05T00:00:00"),
242
- # Same weight, different clock → created_at DESC decides.
243
- ("org:lattice", "person:jiwon", "contains", 0.25, "2026-06-06T00:00:00"),
244
- ("org:lattice", "person:minseo", "contains", 0.25, "2026-06-07T00:00:00"),
245
- ("slide:fusion", "concept:retrieval", "mentions", 0.25, "2026-06-08T00:00:00"),
246
- # Same weight AND same clock → the id ASC tie-break is the only thing left.
247
- ("topic:quality", "deck:review", "relates_to", 0.2, "2026-06-09T00:00:00"),
248
- ("deck:review", "meeting:weekly", "relates_to", 0.2, "2026-06-09T00:00:00"),
249
- ("task:onboarding-checklist", "page:onboarding", "relates_to", 0.15, "2026-05-01T00:00:00"),
250
- ("doc:handbook", "doc:retrieval-spec", "relates_to", 0.1, "2026-05-02T00:00:00"),
251
- ("tie:a", "tie:b", "relates_to", 1.0, "2026-07-03T00:00:00"),
252
- *docgen.DOCGEN_EDGES,
253
- ]
254
-
255
- # ── the conversation corpus (episodic memory, same database file) ────────────
256
- # (conversation_id, role, content, user_email, nickname, source, timestamp,
257
- # workspace_id, organization_id, extra)
258
- #
259
- # Every branch the history reads take: two users × three workspaces, NULL and
260
- # empty-string workspaces (the legacy rows ``_scope_sql`` admits), rows with no
261
- # ``conversation_id`` (the ``legacy-previous-history`` bucket), a whitespace-only
262
- # first message (the ``새 대화`` placeholder and its later upgrade), an
263
- # assistant-first conversation (no upgrade), an empty timestamp (the ``or ""``
264
- # fallbacks), extra keys ``metadata_json`` merges flat, ko/en content.
265
- MESSAGES: List[Tuple[Any, ...]] = [
266
- ("conv-a", "user", "온보딩 체크리스트 어떻게 시작해?", "jiwon@lattice.ai", "지원", "web", "2026-07-20T09:00:00", WS_ALPHA, "org-1", {}),
267
- ("conv-a", "assistant", "먼저 폴더를 연결하세요. 그다음 질문하면 됩니다.", "jiwon@lattice.ai", None, "web", "2026-07-20T09:00:05", WS_ALPHA, "org-1", {}),
268
- ("conv-a", "user", "고마워", "jiwon@lattice.ai", "지원", "web", "2026-07-20T09:01:00", WS_ALPHA, "org-1", {"trace_id": "t-1"}),
269
- ("conv-b", "user", "How does hybrid retrieval ranking work?", "minseo@lattice.ai", "Minseo", "telegram", "2026-07-21T10:00:00", WS_BETA, "org-1", {}),
270
- ("conv-b", "assistant", "The lexical channel scores one over rank.", "minseo@lattice.ai", None, "telegram", "2026-07-21T10:00:07", WS_BETA, "org-1", {"tokens": 42, "cited": ["doc:retrieval-spec"]}),
271
- ("conv-c", "user", " \n ", None, None, None, "2026-07-22T08:00:00", None, None, {}),
272
- ("conv-c", "assistant", "무엇을 도와드릴까요?", None, None, None, "2026-07-22T08:00:05", None, None, {}),
273
- ("conv-c", "user", "지난주 회의 기록 보여줘", None, None, None, "2026-07-22T08:01:00", None, None, {}),
274
- (None, "user", "이전 대화 기록입니다", "jiwon@lattice.ai", "지원", "web", "2026-06-01T09:00:00", "", None, {}),
275
- (None, "assistant", "네, 확인했습니다.", "jiwon@lattice.ai", None, "web", "2026-06-01T09:00:03", "", None, {}),
276
- (None, "user", "legacy english message about ranking", None, None, None, "", None, None, {}),
277
- ("conv-d", "user", "빌드 실패 원인 알려줘", "minseo@lattice.ai", "Minseo", "vscode", "2026-07-23T11:00:00", WS_ALPHA, "org-1", {}),
278
- ("conv-d", "assistant", "컴파일 오류 로그를 확인하세요.", "minseo@lattice.ai", None, "vscode", "2026-07-23T11:00:04", WS_ALPHA, "org-1", {}),
279
- ("conv-e", "user", "Ranking ties are broken by node id", "jiwon@lattice.ai", "지원", "web", "2026-07-24T12:00:00", WS_BETA, "org-2", {}),
280
- ("conv-e", "assistant", "Yes — id ascending keeps it stable.", "jiwon@lattice.ai", None, "web", "2026-07-24T12:00:05", WS_BETA, "org-2", {}),
281
- ("conv-f", "user", "검색 품질을 어떻게 측정하나요? 재현율과 정밀도를 모두 보고 싶고 주간 회의에서 공유할 예정입니다.", None, None, "web", "2026-07-25T13:00:00", None, None, {}),
282
- ("conv-f", "assistant", "재현율/정밀도 지표는 분기 리뷰 발표자료에 있습니다.", None, None, "web", "2026-07-25T13:00:05", None, None, {}),
283
- ("conv-g", "assistant", "assistant-first conversation", None, None, "web", "2026-07-26T14:00:00", None, None, {}),
284
- ("conv-g", "user", "follow up question about ranking", None, None, "web", "2026-07-26T14:00:10", None, None, {}),
285
- ("conv-h", "user", "Empty user and empty workspace row", "", "", "", "2026-07-27T15:00:00", "", "", {}),
286
- ("conv-h", "assistant", "회의 결정 사항을 정리했습니다.", "", "", "", "2026-07-27T15:00:06", "", "", {}),
287
- ]
288
-
289
- # ── the query set ────────────────────────────────────────────────────────────
290
- # ``allowed`` is None (no scoping), [] (a caller who may read nothing) or a list
291
- # of workspace ids; ``legacy`` is ``include_legacy_global``.
292
- QUERIES: List[Dict[str, Any]] = [
293
- {"key": "en_fact", "query": "hybrid retrieval ranking"},
294
- {"key": "ko_fact", "query": "회의 결정 사항"},
295
- {"key": "en_code", "query": "vector_search() returns"},
296
- {"key": "ko_code", "query": "빌드 실패 원인"},
297
- {"key": "en_person", "query": "who owns the onboarding checklist"},
298
- {"key": "ko_person", "query": "담당자 누구"},
299
- {"key": "en_recency", "query": "recent decisions last week"},
300
- {"key": "ko_recency", "query": "지난주 회의 기록"},
301
- {"key": "en_filler", "query": " what is the retrieval specification please "},
302
- {"key": "ko_filler", "query": "온보딩 체크리스트 좀 알려줘"},
303
- {"key": "short_query", "query": "ai"},
304
- {"key": "no_hit", "query": "zzqq wumpus nonsense"},
305
- {"key": "tie_heavy", "query": "Tie candidate"},
306
- {"key": "chunk_heavy", "query": "온보딩 체크리스트"},
307
- {"key": "quoted", "query": 'said "retrieval" twice'},
308
- {"key": "empty_query", "query": ""},
309
- {"key": "ws_empty", "query": "hybrid retrieval ranking", "allowed": []},
310
- {"key": "ws_empty_legacy", "query": "회의 결정 사항", "allowed": [], "legacy": True},
311
- {"key": "ws_alpha", "query": "hybrid retrieval ranking", "allowed": [WS_ALPHA]},
312
- {"key": "ws_alpha_legacy", "query": "회의 결정 사항", "allowed": [WS_ALPHA], "legacy": True},
313
- {"key": "ws_beta", "query": "온보딩 체크리스트", "allowed": [WS_BETA]},
314
- # A vector floor nothing clears: the stale-embedder probe and the
315
- # lexical-only fusion label, without breaking the store.
316
- {"key": "min_vector_floor", "query": "hybrid retrieval ranking", "min_vector": 0.95},
317
- # top_k small enough that the rerank window (top_k * 2) cuts the candidates.
318
- {"key": "top_k_small", "query": "hybrid retrieval ranking", "top_k": 3},
319
- # Pinned alpha: no policy, so no class/rewrite/age decay on a recency query.
320
- {"key": "alpha_pinned", "query": "지난주 회의 기록", "alpha": 0.2},
321
- # A limit below the FTS hit count, so `ORDER BY rank LIMIT ?` decides which rows
322
- # exist at all — the one place bm25 ordering (a SQLite version difference) shows.
323
- {"key": "fts_rank_cut", "query": "Tie candidate", "limit": 2, "top_k": 2},
324
- ]
325
-
326
- #: Every branch of the memories section: a workspace hit, one with no kind and an
327
- #: empty snippet, a non-workspace row to drop, and one past the limit.
328
- #: The Phase-2/3 suites: one spec list per ported entry point.
329
- SUITES: Dict[str, List[Dict[str, Any]]] = {
330
- "relationship": [
331
- {"key": "all"},
332
- {"key": "by_type_mention", "relationship_type": "mention"},
333
- {"key": "by_type_contains", "relationship_type": "CONTAINS"},
334
- {"key": "by_type_unknown", "relationship_type": "relates_to"},
335
- {"key": "by_node", "node_id": "dec:fusion-alpha"},
336
- {"key": "by_query_ko", "query": "회의"},
337
- {"key": "by_query_en", "query": "ranking"},
338
- {"key": "by_query_meta", "query": "lattice"},
339
- {"key": "combined", "node_id": "dec:fusion-alpha", "relationship_type": "mention", "query": "retrieval"},
340
- {"key": "limit_one", "limit": 1},
341
- {"key": "limit_zero", "limit": 0},
342
- {"key": "limit_over", "limit": 500},
343
- {"key": "scoped_alpha", "allowed": [WS_ALPHA]},
344
- {"key": "scoped_alpha_legacy", "allowed": [WS_ALPHA], "legacy": True},
345
- {"key": "scoped_beta", "allowed": [WS_BETA]},
346
- {"key": "scoped_empty", "allowed": []},
347
- {"key": "no_hit", "query": "zzqq wumpus"},
348
- ],
349
- "traverse": [
350
- # 9 clamps to 4 and -1 clamps to 0; both are on purpose.
351
- *[{"key": f"hub_d{depth}", "node_id": "dec:fusion-alpha", "depth": depth}
352
- for depth in (0, 1, 2, 3, 9)],
353
- {"key": "hub_dneg", "node_id": "dec:fusion-alpha", "depth": -1},
354
- {"key": "leaf_d2", "node_id": "code:hybrid-search", "depth": 2},
355
- {"key": "isolated", "node_id": "tie:c", "depth": 2},
356
- {"key": "limit_two", "node_id": "dec:fusion-alpha", "depth": 3, "limit": 2},
357
- {"key": "limit_five", "node_id": "dec:fusion-alpha", "depth": 3, "limit": 5},
358
- {"key": "limit_zero", "node_id": "dec:fusion-alpha", "depth": 2, "limit": 0},
359
- {"key": "limit_over", "node_id": "dec:fusion-alpha", "depth": 2, "limit": 900},
360
- {"key": "org_hub", "node_id": "org:lattice", "depth": 2},
361
- {"key": "tie_pair", "node_id": "tie:a", "depth": 2},
362
- {"key": "scoped_alpha", "node_id": "dec:fusion-alpha", "depth": 2, "allowed": [WS_ALPHA]},
363
- {"key": "scoped_alpha_legacy", "node_id": "dec:fusion-alpha", "depth": 2, "allowed": [WS_ALPHA], "legacy": True},
364
- {"key": "scoped_seed_hidden", "node_id": "dec:fusion-alpha", "allowed": [WS_BETA]},
365
- {"key": "scoped_empty", "node_id": "dec:fusion-alpha", "allowed": []},
366
- {"key": "empty_id", "node_id": ""},
367
- {"key": "missing_seed", "node_id": "nope:missing"},
368
- ],
369
- "graph_search": [
370
- {"key": "en_fact", "query": "hybrid retrieval ranking"},
371
- {"key": "ko_fact", "query": "회의 결정 사항"},
372
- {"key": "person", "query": "who owns the onboarding checklist"},
373
- {"key": "code", "query": "빌드 실패 원인"},
374
- {"key": "expand0", "query": "hybrid retrieval ranking", "expand_depth": 0},
375
- {"key": "expand3", "query": "hybrid retrieval ranking", "expand_depth": 3},
376
- {"key": "expand_clamp", "query": "회의 결정 사항", "expand_depth": 9},
377
- {"key": "limit_small", "query": "hybrid retrieval ranking", "limit": 3},
378
- {"key": "limit_over", "query": "회의 결정 사항", "limit": 500},
379
- {"key": "scoped_alpha", "query": "hybrid retrieval ranking", "allowed": [WS_ALPHA]},
380
- {"key": "scoped_alpha_legacy", "query": "회의 결정 사항", "allowed": [WS_ALPHA], "legacy": True},
381
- {"key": "scoped_empty", "query": "hybrid retrieval ranking", "allowed": []},
382
- {"key": "no_hit", "query": "zzqq wumpus nonsense"},
383
- {"key": "empty_query", "query": ""},
384
- ],
385
- "service_hybrid": [
386
- {"key": "en_fact", "query": "hybrid retrieval ranking"},
387
- {"key": "ko_recency", "query": "지난주 회의 기록"},
388
- {"key": "en_code", "query": "vector_search() returns"},
389
- {"key": "ko_person", "query": "담당자 누구"},
390
- {"key": "en_filler", "query": " what is the retrieval specification please "},
391
- # Explicit weights disable BOTH rewrite and age decay on a query that
392
- # would otherwise get both — that asymmetry is the contract.
393
- {"key": "pinned_recency", "query": "지난주 회의 기록", "weights": {"keyword": 0.5, "vector": 0.3, "graph": 0.2}},
394
- {"key": "pinned_partial", "query": "hybrid retrieval ranking", "weights": {"graph": 1.0}},
395
- {"key": "pinned_zero", "query": "회의 결정 사항", "weights": {"keyword": 0.0, "vector": 0.0, "graph": 0.0}},
396
- {"key": "limit_small", "query": "hybrid retrieval ranking", "limit": 3},
397
- {"key": "limit_over", "query": "회의 결정 사항", "limit": 500},
398
- {"key": "channel_limits", "query": "hybrid retrieval ranking", "keyword_limit": 5, "vector_limit": 5, "graph_limit": 5},
399
- {"key": "scoped_alpha", "query": "hybrid retrieval ranking", "allowed": [WS_ALPHA]},
400
- {"key": "scoped_alpha_legacy", "query": "회의 결정 사항", "allowed": [WS_ALPHA], "legacy": True},
401
- {"key": "scoped_empty", "query": "hybrid retrieval ranking", "allowed": []},
402
- {"key": "no_hit", "query": "zzqq wumpus nonsense"},
403
- {"key": "empty_query", "query": ""},
404
- ],
405
- "history": [
406
- {"key": "all"},
407
- {"key": "limit_two", "limit": 2},
408
- {"key": "limit_zero", "limit": 0},
409
- {"key": "conv_a", "conversation_id": "conv-a"},
410
- {"key": "conv_missing", "conversation_id": "nope"},
411
- {"key": "conv_null", "conversation_id": ""},
412
- {"key": "user_jiwon", "user_email": "jiwon@lattice.ai"},
413
- {"key": "user_jiwon_strict", "user_email": "jiwon@lattice.ai", "legacy": False},
414
- {"key": "user_unknown", "user_email": "ghost@lattice.ai"},
415
- {"key": "ws_alpha", "allowed": [WS_ALPHA]},
416
- {"key": "ws_alpha_strict", "allowed": [WS_ALPHA], "legacy": False},
417
- {"key": "ws_both_strict", "allowed": [WS_ALPHA, WS_BETA], "legacy": False},
418
- {"key": "ws_empty_legacy", "allowed": []},
419
- {"key": "ws_empty_strict", "allowed": [], "legacy": False},
420
- {"key": "user_and_ws", "user_email": "jiwon@lattice.ai", "allowed": [WS_ALPHA], "legacy": False},
421
- {"key": "conv_and_user", "conversation_id": "conv-a", "user_email": "jiwon@lattice.ai", "legacy": False},
422
- {"key": "ws_blank_only", "allowed": [""], "legacy": False},
423
- ],
424
- "conversations": [
425
- {"key": "all"},
426
- {"key": "user_jiwon", "user_email": "jiwon@lattice.ai"},
427
- {"key": "user_jiwon_strict", "user_email": "jiwon@lattice.ai", "legacy": False},
428
- {"key": "ws_alpha_strict", "allowed": [WS_ALPHA], "legacy": False},
429
- {"key": "ws_beta_strict", "allowed": [WS_BETA], "legacy": False},
430
- {"key": "ws_empty_strict", "allowed": [], "legacy": False},
431
- ],
432
- "conversation_messages": [
433
- {"key": "conv_a", "conversation_id": "conv-a"},
434
- {"key": "legacy_bucket", "conversation_id": "legacy-previous-history"},
435
- {"key": "missing", "conversation_id": "nope"},
436
- {"key": "scoped_alpha_strict", "conversation_id": "conv-a", "allowed": [WS_ALPHA], "legacy": False},
437
- {"key": "legacy_bucket_scoped", "conversation_id": "legacy-previous-history", "allowed": [WS_ALPHA], "legacy": False},
438
- ],
439
- "history_search": [
440
- {"key": "ko_hit", "query": "회의"},
441
- {"key": "ko_partial", "query": "체크리스트"},
442
- {"key": "en_hit", "query": "ranking"},
443
- {"key": "case_insensitive", "query": "RANKING"},
444
- {"key": "blank", "query": " "},
445
- {"key": "no_hit", "query": "zzqq"},
446
- {"key": "limit_one", "query": "ranking", "limit": 1},
447
- {"key": "scoped_strict", "query": "ranking", "allowed": [WS_BETA], "legacy": False},
448
- ],
449
- **context_corpus.CONTEXT_SUITES,
450
- # v11.5.1: the document-generation ports, specs and runners alike.
451
- **docgen.DOCGEN_SUITES,
452
- }
453
-
454
- #: Texts whose tokenizer output, hashes and vectors pin the embedding port.
455
- EMBEDDING_TEXTS: List[str] = [
456
- "hybrid retrieval ranking",
457
- "회의 결정 사항",
458
- "온보딩 체크리스트 v2",
459
- "vector_search() returns a dict",
460
- "!!! ??? ...",
461
- "MixedCase and snake_case and kebab-case",
462
- "2026-07-20T09:00:00",
463
- "a",
464
- ]
465
-
466
- #: Values separating CPython round-half-even from naive scaling, plus real shapes.
467
- ROUNDING_VALUES: List[float] = [
468
- 0.0, 1.0, 5e-07, 1.5e-06, 2.5e-06, 2.6535895, 1 / 3, 1 / 7,
469
- 0.1234565, 0.1234575, 0.9999999999, 123456.7890625, -0.0000005,
470
- 0.6 * 0.5 + 0.4 * (1 / 3), 0.35 * 0.25 + 0.65 * (1 / 7), 0.5 + 0.5 * 0.7071067811865476,
471
- ]
472
-
473
-
474
- @contextmanager
475
- def pinned_environment() -> Iterator[None]:
476
- """Pin every env knob the retrieval stack reads, then restore."""
477
- previous = {key: os.environ.get(key) for key in PINNED_ENV}
478
- os.environ.update(PINNED_ENV)
479
- try:
480
- yield
481
- finally:
482
- for key, value in previous.items():
483
- if value is None:
484
- os.environ.pop(key, None)
485
- else:
486
- os.environ[key] = value
487
-
488
-
489
- @contextmanager
490
- def frozen_clock() -> Iterator[None]:
491
- """Freeze every ported ``datetime.now()`` at :data:`FROZEN_NOW`.
492
-
493
- Only the recency decay reads the clock, through the ``datetime`` name its
494
- module imported, so rebinding that name is the whole patch. Three modules
495
- reach it: the graph-layer and service-layer ``hybrid_search``, and the
496
- document-generation search's own 14-day half-life.
497
- """
498
- from lattice_brain.graph import retrieval_docgen as docgen_module
499
- from lattice_brain.graph.retrieval import hybrid as hybrid_module
500
- from latticeai.services import search_service as service_module
501
-
502
- frozen = datetime.fromisoformat(FROZEN_NOW)
503
-
504
- class _FrozenDatetime(datetime):
505
- @classmethod
506
- def now(cls, tz=None): # noqa: ARG003 — mirrors datetime.now's signature
507
- return frozen
508
-
509
- modules = (hybrid_module, service_module, docgen_module)
510
- originals = [module.datetime for module in modules]
511
- for module in modules:
512
- module.datetime = _FrozenDatetime
513
- try:
514
- yield
515
- finally:
516
- for module, original in zip(modules, originals, strict=True):
517
- module.datetime = original
518
-
519
-
520
- @contextmanager
521
- def rules_only_extraction() -> Iterator[None]:
522
- """Force ``_topic_candidates`` down its rule-based path.
523
-
524
- The LLM path needs a bound router no fixture run has, but "no router
525
- happens to be bound" is an accident this contract cannot rest on.
526
- """
527
- from lattice_brain.graph._kg_common import extraction
528
-
529
- original = extraction.ENABLE_LLM_EXTRACTION
530
- extraction.ENABLE_LLM_EXTRACTION = False
531
- try:
532
- yield
533
- finally:
534
- extraction.ENABLE_LLM_EXTRACTION = original
535
-
536
-
537
- def open_store(db_path: Path):
538
- """A ``KnowledgeGraphStore`` over ``db_path`` (blobs beside it)."""
539
- from lattice_brain.graph import KnowledgeGraphStore
540
- return KnowledgeGraphStore(Path(db_path), Path(db_path).parent / "blobs")
541
-
542
-
543
- def open_conversations(db_path: Path):
544
- """A ``ConversationStore`` over ``db_path`` (the same file as the graph)."""
545
- from lattice_brain.conversations import ConversationStore
546
- return ConversationStore(Path(db_path))
547
-
548
-
549
- def write_conversations(db_path: Path) -> None:
550
- """Append :data:`MESSAGES` through the real durable-history write path."""
551
- conversations = open_conversations(db_path)
552
- for conv_id, role, content, email, nick, source, stamp, workspace, org, extra in MESSAGES:
553
- conversations.append({
554
- "conversation_id": conv_id, "role": role, "content": content,
555
- "user_email": email, "user_nickname": nick, "source": source,
556
- "timestamp": stamp, "workspace_id": workspace, "organization_id": org,
557
- **extra,
558
- })
559
-
560
-
561
- def _backdate(conn: sqlite3.Connection, node_id: str, stamp: str) -> None:
562
- conn.execute("UPDATE nodes SET created_at=?, updated_at=? WHERE id=?", (stamp, stamp, node_id))
563
- conn.execute(
564
- "UPDATE nodes_v2 SET created_at=?, updated_at=? WHERE id=?", (stamp, stamp, node_id)
565
- )
566
-
567
-
568
- def build_store(db_path: Path) -> None:
569
- """Create the fixture database from scratch with the real write path."""
570
- for sibling in (db_path, Path(f"{db_path}-wal"), Path(f"{db_path}-shm")):
571
- if sibling.exists():
572
- sibling.unlink()
573
- blob_dir = db_path.parent / "blobs"
574
- if blob_dir.exists():
575
- shutil.rmtree(blob_dir)
576
-
577
- store = open_store(db_path)
578
- with store._connect() as conn:
579
- for node_id, node_type, title, summary, metadata, workspace, stamp in NODES:
580
- store._upsert_node(
581
- conn, node_id, node_type, title, summary, metadata, workspace_id=workspace
582
- )
583
- _backdate(conn, node_id, stamp)
584
- for chunk_id, parent, index, title, text, fields, workspace, stamp in CHUNKS:
585
- metadata = {"index": index, "source_node": parent, **fields}
586
- store._upsert_node(
587
- conn, chunk_id, "Chunk", title, text[:500], metadata, workspace_id=workspace
588
- )
589
- store._upsert_chunk(
590
- conn, chunk_id=chunk_id, source_node=parent, text=text, metadata=metadata
591
- )
592
- _backdate(conn, chunk_id, stamp)
593
- for from_node, to_node, edge_type, weight, stamp in EDGES:
594
- # ``_upsert_edge`` stamps ``created_at`` from the wall clock in BOTH
595
- # tables, and the read path is the ``kgv2_edges`` view over ``edges_v2``:
596
- # backdating only the legacy table left the ordering moving with the clock.
597
- edge_id = store._upsert_edge(conn, from_node, to_node, edge_type, weight, {})
598
- conn.execute("UPDATE edges SET created_at=? WHERE id=?", (stamp, edge_id))
599
- conn.execute("UPDATE edges_v2 SET created_at=? WHERE id=?", (stamp, edge_id))
600
- # ``indexed_at`` decides the candidate scan order (and, when the cap
601
- # bites, which candidates exist), so it is assigned rather than inherited.
602
- item_ids = [row["item_id"] for row in conn.execute(
603
- "SELECT item_id FROM vector_embeddings ORDER BY item_id ASC"
604
- ).fetchall()]
605
- for seq, item_id in enumerate(item_ids):
606
- stamp = f"2026-03-01T{seq // 60:02d}:{seq % 60:02d}:00"
607
- conn.execute(
608
- "UPDATE vector_embeddings SET indexed_at=? WHERE item_id=?", (stamp, item_id)
609
- )
610
- store.record_embedder_fingerprint()
611
- write_conversations(db_path)
612
-
613
- # One self-contained file: checkpoint the WAL, drop to a rollback journal
614
- # so no sidecar is committed, and compact.
615
- with sqlite3.connect(str(db_path)) as conn:
616
- conn.execute("PRAGMA wal_checkpoint(TRUNCATE)")
617
- conn.execute("PRAGMA journal_mode=DELETE")
618
- with sqlite3.connect(str(db_path)) as conn:
619
- conn.execute("VACUUM")
620
- conn.close()
621
- for sibling in (Path(f"{db_path}-wal"), Path(f"{db_path}-shm")):
622
- if sibling.exists():
623
- sibling.unlink()
624
- if blob_dir.exists():
625
- shutil.rmtree(blob_dir)
626
-
627
-
628
- def _allowed(spec: Dict[str, Any]):
629
- allowed = spec.get("allowed")
630
- return None if allowed is None else set(allowed)
631
-
632
-
633
- ENGINES: Dict[str, Callable[[Any, Dict[str, Any]], Dict[str, Any]]] = {
634
- "hybrid": lambda store, spec: store.hybrid_search(
635
- spec["query"], top_k=spec.get("top_k", 20), alpha=spec.get("alpha"),
636
- allowed_workspaces=_allowed(spec), min_vector_score=spec.get("min_vector", 0.0),
637
- include_legacy_global=spec.get("legacy", False),
638
- ),
639
- "keyword": lambda store, spec: store.search(
640
- spec["query"], spec.get("limit", 30), allowed_workspaces=_allowed(spec),
641
- include_legacy_global=spec.get("legacy", False),
642
- ),
643
- "vector": lambda store, spec: store.vector_search(
644
- spec["query"], limit=spec.get("limit", 30), min_score=spec.get("min_score", 0.0)
645
- ),
646
- }
647
-
648
-
649
- def run_engine(store, engine: str, spec: Dict[str, Any]) -> Dict[str, Any]:
650
- """Run one engine for one query spec under the frozen clock."""
651
- with frozen_clock(), rules_only_extraction():
652
- return ENGINES[engine](store, spec)
653
-
654
-
655
- # ── the suites beyond search (v11.5.0/v11.5.1) ───────────────────────────────
656
- #
657
- # The Phase-1 engines share one query shape (a query set × an engine set); the
658
- # later ports do not, so each gets its own spec list and runner, both carried in
659
- # the manifest so Rust and Python enumerate exactly the same work.
660
-
661
-
662
- class Harness:
663
- """Every Python entry point the v11.5.0 goldens are produced from.
664
-
665
- ``require_auth=False`` is the loopback-owner configuration the native routes
666
- reproduce: the history scope is whatever the caller passes.
667
- """
668
-
669
- def __init__(self, db_path: Path):
670
- from latticeai.runtime.history_runtime import build_history_query_runtime
671
- from latticeai.services.chat_service import ChatService
672
- from latticeai.services.search_service import SearchService
673
- self.store = open_store(db_path)
674
- self.service = SearchService(graph_store=self.store)
675
- self.conversations = open_conversations(db_path)
676
- self.history_runtime = build_history_query_runtime(
677
- conversations=self.conversations,
678
- workspace_service=None,
679
- require_auth=False,
680
- logging=logging,
681
- )
682
- self.chat = ChatService(store=None, get_history=self.history_runtime["get_history"])
683
-
684
-
685
- def _allowed_list(spec: Dict[str, Any]):
686
- """``allowed`` as the graph layer wants it: ``None`` or a set."""
687
- allowed = spec.get("allowed")
688
- return None if allowed is None else set(allowed)
689
-
690
-
691
- def _history_scope(spec: Dict[str, Any]) -> Dict[str, Any]:
692
- """The identity/workspace scope every history read takes.
693
-
694
- ``include_legacy_global`` defaults to ``True`` — ``ConversationStore``'s own
695
- default, the opposite of the graph layer's and an asymmetry a port gets wrong.
696
- """
697
- allowed = spec.get("allowed")
698
- return {
699
- "user_email": spec.get("user_email"),
700
- "allowed_workspaces": None if allowed is None else list(allowed),
701
- "include_legacy_global": spec.get("legacy", True),
702
- }
703
-
704
-
705
- def _run_relationship(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
706
- return h.store.relationship_search(
707
- query=spec.get("query", ""), node_id=spec.get("node_id", ""),
708
- relationship_type=spec.get("relationship_type", ""), limit=spec.get("limit", 30),
709
- allowed_workspaces=_allowed_list(spec),
710
- include_legacy_global=spec.get("legacy", False),
711
- )
712
-
713
-
714
- def _run_traverse(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
715
- try:
716
- return h.store.traverse(
717
- spec.get("node_id", ""), depth=spec.get("depth", 1),
718
- limit=spec.get("limit", 100), allowed_workspaces=_allowed_list(spec),
719
- include_legacy_global=spec.get("legacy", False),
720
- )
721
- except ValueError as exc:
722
- # The two documented refusals (blank id, seed invisible to the caller's
723
- # scope) are contract, so they are recorded rather than skipped; a payload
724
- # never carries an "error" key, so the golden stays unambiguous.
725
- return {"error": str(exc)}
726
-
727
-
728
- def _run_graph_search(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
729
- return h.service.graph_search(
730
- spec["query"], limit=spec.get("limit", 30),
731
- expand_depth=spec.get("expand_depth", 1), allowed_workspaces=_allowed_list(spec),
732
- include_legacy_global=spec.get("legacy", False),
733
- )
734
-
735
-
736
- def _run_service_hybrid(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
737
- return h.service.hybrid_search(
738
- spec["query"], limit=spec.get("limit", 30),
739
- keyword_limit=spec.get("keyword_limit", 30),
740
- vector_limit=spec.get("vector_limit", 30),
741
- graph_limit=spec.get("graph_limit", 30), weights=spec.get("weights"),
742
- allowed_workspaces=_allowed_list(spec),
743
- include_legacy_global=spec.get("legacy", False),
744
- )
745
-
746
-
747
- def _run_history(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
748
- return h.conversations.history(
749
- conversation_id=spec.get("conversation_id"), limit=spec.get("limit"),
750
- **_history_scope(spec),
751
- )
752
-
753
-
754
- def _run_conversations(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
755
- history = h.history_runtime["get_history"](**_history_scope(spec))
756
- return h.history_runtime["group_history_conversations"](history)
757
-
758
-
759
- def _run_conversation_messages(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
760
- return h.history_runtime["get_conversation_messages"](
761
- spec["conversation_id"], **_history_scope(spec)
762
- )
763
-
764
-
765
- def _run_history_search(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
766
- return h.chat.search_history(
767
- spec["query"], scope=_history_scope(spec), limit=spec.get("limit", 30),
768
- conversation_title=h.history_runtime["conversation_title"],
769
- )
770
-
771
-
772
- SUITE_RUNNERS: Dict[str, Callable[[Harness, Dict[str, Any]], Any]] = {
773
- "relationship": _run_relationship,
774
- "traverse": _run_traverse,
775
- "graph_search": _run_graph_search,
776
- "service_hybrid": _run_service_hybrid,
777
- "history": _run_history,
778
- "conversations": _run_conversations,
779
- "conversation_messages": _run_conversation_messages,
780
- "history_search": _run_history_search,
781
- **context_corpus.CONTEXT_RUNNERS,
782
- **docgen.DOCGEN_RUNNERS,
783
- }
784
-
785
-
786
- def run_suite(harness: Harness, suite: str, spec: Dict[str, Any]) -> Any:
787
- """Run one suite spec under the frozen clock and the rule-based extractor."""
788
- with frozen_clock(), rules_only_extraction():
789
- return SUITE_RUNNERS[suite](harness, spec)
790
-
791
-
792
- def golden_path(engine: str, key: str) -> Path:
793
- return GOLDEN_DIR / f"{engine}__{key}.json"
794
-
795
-
796
- def golden_payload(engine: str, spec: Dict[str, Any], result: Dict[str, Any]) -> Dict[str, Any]:
797
- return {
798
- "engine": engine,
799
- "key": spec["key"],
800
- "query": spec["query"],
801
- "params": {
802
- "top_k": spec.get("top_k", 20), "alpha": spec.get("alpha"),
803
- "limit": spec.get("limit", 30), "min_score": spec.get("min_score", 0.0),
804
- "min_vector_score": spec.get("min_vector", 0.0),
805
- "allowed_workspaces": spec.get("allowed"),
806
- "include_legacy_global": spec.get("legacy", False),
807
- },
808
- "result": result,
809
- }
810
-
811
-
812
- def suite_payload(suite: str, spec: Dict[str, Any], result: Any) -> Dict[str, Any]:
813
- """One suite golden: the spec that produced it, verbatim, and the answer.
814
-
815
- The spec rides along rather than being flattened into a fixed ``params``
816
- block — these entry points share no parameter shape.
817
- """
818
- return {"suite": suite, "key": spec["key"], "spec": spec, "result": result}
819
-
820
-
821
- def _dump(path: Path, payload: Any) -> None:
822
- path.write_text(
823
- json.dumps(payload, ensure_ascii=False, sort_keys=True, indent=2) + "\n",
824
- encoding="utf-8",
825
- )
826
-
827
-
828
- def embeddings_golden() -> Dict[str, Any]:
829
- """Tokenizer output, hash pairs and full vectors for the pinned texts."""
830
- from lattice_brain.embeddings import LocalEmbeddingModel, _hash_to_index, _tokenize
831
-
832
- model = LocalEmbeddingModel()
833
- cases = []
834
- for text in EMBEDDING_TEXTS:
835
- features = _tokenize(text)
836
- cases.append(
837
- {
838
- "text": text,
839
- "features": features,
840
- "hashes": [
841
- {"feature": feature, "index": index, "sign": sign}
842
- for feature, (index, sign) in (
843
- (feature, _hash_to_index(feature, model.dim))
844
- for feature in features[:8]
845
- )
846
- ],
847
- "vector": model.embed(text),
848
- "encoded_hex": model.encode(model.embed(text)).hex(),
849
- }
850
- )
851
- return {"model_id": model.model_id, "dim": model.dim, "cases": cases}
852
-
853
-
854
- def rounding_golden() -> List[Dict[str, float]]:
855
- """``round(x, 6)`` for values where the tie rule is observable."""
856
- return [{"input": v, "expected": round(v, 6)} for v in ROUNDING_VALUES]
857
-
858
-
859
- def manifest() -> Dict[str, Any]:
860
- from lattice_brain.embeddings import LocalEmbeddingModel
861
- model = LocalEmbeddingModel()
862
- return {
863
- "frozen_now": FROZEN_NOW,
864
- "store": STORE_PATH.name,
865
- "embedding_model": model.model_id,
866
- "embedding_dim": model.dim,
867
- "engines": sorted(ENGINES),
868
- "queries": QUERIES,
869
- "suites": {suite: SUITES[suite] for suite in sorted(SUITES)},
870
- "pinned_env": PINNED_ENV,
871
- }
872
-
873
-
874
- def main() -> int:
875
- FIXTURE_DIR.mkdir(parents=True, exist_ok=True)
876
- if GOLDEN_DIR.exists():
877
- shutil.rmtree(GOLDEN_DIR)
878
- GOLDEN_DIR.mkdir(parents=True, exist_ok=True)
879
- with pinned_environment():
880
- build_store(STORE_PATH)
881
- store = open_store(STORE_PATH)
882
- written = 0
883
- for spec in QUERIES:
884
- for engine in sorted(ENGINES):
885
- result = run_engine(store, engine, spec)
886
- _dump(golden_path(engine, spec["key"]), golden_payload(engine, spec, result))
887
- written += 1
888
- harness = Harness(STORE_PATH)
889
- for suite in sorted(SUITES):
890
- for spec in SUITES[suite]:
891
- result = run_suite(harness, suite, spec)
892
- _dump(golden_path(suite, spec["key"]), suite_payload(suite, spec, result))
893
- written += 1
894
- _dump(GOLDEN_DIR / "embeddings_golden.json", embeddings_golden())
895
- _dump(GOLDEN_DIR / "rounding_golden.json", rounding_golden())
896
- _dump(GOLDEN_DIR / "manifest.json", manifest())
897
- # The store creates its blob directory eagerly and the fixture has no blobs.
898
- blob_dir = STORE_PATH.parent / "blobs"
899
- if blob_dir.is_dir() and not any(blob_dir.iterdir()):
900
- blob_dir.rmdir()
901
- size_kb = STORE_PATH.stat().st_size / 1024
902
- print(f"store: {STORE_PATH.relative_to(REPO_ROOT)} ({size_kb:.1f} KiB)")
903
- print(f"golden: {written} engine files + embeddings + rounding + manifest")
904
- return 0
905
-
906
-
907
- if __name__ == "__main__":
908
- raise SystemExit(main())