ltcai 3.5.0 → 4.0.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 (181) hide show
  1. package/README.md +73 -35
  2. package/docs/CARRYOVER_AUDIT_v3.6.0.md +61 -0
  3. package/docs/CHANGELOG.md +32 -0
  4. package/docs/HANDOVER_v3.6.0.md +46 -0
  5. package/docs/RUNTIME_HOOK_COVERAGE_v3.6.0.md +49 -0
  6. package/docs/V4_BRAIN_ARCHITECTURE.md +322 -0
  7. package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +509 -0
  8. package/docs/V4_IMPLEMENTATION_PLAN.md +470 -0
  9. package/docs/architecture.md +13 -12
  10. package/docs/kg-schema.md +102 -53
  11. package/docs/privacy.md +18 -2
  12. package/docs/security-model.md +17 -0
  13. package/kg_schema.py +139 -10
  14. package/knowledge_graph.py +874 -26
  15. package/knowledge_graph_api.py +11 -127
  16. package/latticeai/__init__.py +1 -1
  17. package/latticeai/api/admin.py +1 -1
  18. package/latticeai/api/agents.py +7 -1
  19. package/latticeai/api/auth.py +27 -4
  20. package/latticeai/api/browser.py +217 -0
  21. package/latticeai/api/chat.py +112 -76
  22. package/latticeai/api/health.py +1 -1
  23. package/latticeai/api/hooks.py +1 -1
  24. package/latticeai/api/knowledge_graph.py +146 -0
  25. package/latticeai/api/local_files.py +1 -1
  26. package/latticeai/api/mcp.py +23 -11
  27. package/latticeai/api/memory.py +1 -1
  28. package/latticeai/api/models.py +1 -1
  29. package/latticeai/api/network.py +81 -0
  30. package/latticeai/api/portability.py +93 -0
  31. package/latticeai/api/realtime.py +1 -1
  32. package/latticeai/api/search.py +26 -2
  33. package/latticeai/api/security_dashboard.py +2 -3
  34. package/latticeai/api/setup.py +2 -2
  35. package/latticeai/api/static_routes.py +2 -4
  36. package/latticeai/api/tools.py +3 -0
  37. package/latticeai/api/workflow_designer.py +46 -0
  38. package/latticeai/api/workspace.py +71 -49
  39. package/latticeai/app_factory.py +1710 -0
  40. package/latticeai/brain/__init__.py +18 -0
  41. package/latticeai/brain/context.py +213 -0
  42. package/latticeai/brain/conversations.py +236 -0
  43. package/latticeai/brain/identity.py +175 -0
  44. package/latticeai/brain/memory.py +102 -0
  45. package/latticeai/brain/network.py +205 -0
  46. package/latticeai/core/agent.py +31 -7
  47. package/latticeai/core/audit.py +0 -7
  48. package/latticeai/core/config.py +1 -1
  49. package/latticeai/core/context_builder.py +1 -2
  50. package/latticeai/core/enterprise.py +1 -1
  51. package/latticeai/core/graph_curator.py +2 -2
  52. package/latticeai/core/marketplace.py +1 -1
  53. package/latticeai/core/mcp_registry.py +791 -0
  54. package/latticeai/core/model_compat.py +1 -1
  55. package/latticeai/core/model_resolution.py +0 -1
  56. package/latticeai/core/multi_agent.py +238 -4
  57. package/latticeai/core/security.py +1 -1
  58. package/latticeai/core/sessions.py +37 -7
  59. package/latticeai/core/workflow_engine.py +114 -2
  60. package/latticeai/core/workspace_os.py +58 -10
  61. package/latticeai/models/__init__.py +7 -0
  62. package/latticeai/models/router.py +779 -0
  63. package/latticeai/server_app.py +29 -1504
  64. package/latticeai/services/agent_runtime.py +1 -0
  65. package/latticeai/services/app_context.py +75 -14
  66. package/latticeai/services/ingestion.py +318 -0
  67. package/latticeai/services/kg_portability.py +207 -0
  68. package/latticeai/services/memory_service.py +39 -11
  69. package/latticeai/services/model_runtime.py +2 -5
  70. package/latticeai/services/platform_runtime.py +100 -23
  71. package/latticeai/services/search_service.py +17 -8
  72. package/latticeai/services/tool_dispatch.py +12 -2
  73. package/latticeai/services/triggers.py +241 -0
  74. package/latticeai/services/upload_service.py +37 -12
  75. package/latticeai/services/workspace_service.py +31 -0
  76. package/llm_router.py +29 -772
  77. package/ltcai_cli.py +1 -2
  78. package/mcp_registry.py +25 -788
  79. package/p_reinforce.py +124 -14
  80. package/package.json +11 -8
  81. package/scripts/build_vsix.mjs +72 -0
  82. package/scripts/bump_version.py +99 -0
  83. package/scripts/generate_diagrams.py +0 -1
  84. package/scripts/lint_v3.mjs +82 -18
  85. package/scripts/validate_release_artifacts.py +0 -1
  86. package/scripts/wheel_smoke.py +142 -0
  87. package/server.py +11 -7
  88. package/setup_wizard.py +1142 -0
  89. package/static/account.html +2 -4
  90. package/static/admin.html +3 -5
  91. package/static/chat.html +3 -6
  92. package/static/graph.html +2 -4
  93. package/static/sw.js +81 -52
  94. package/static/v3/asset-manifest.json +20 -19
  95. package/static/v3/css/{lattice.base.e4cdd05d.css → lattice.base.49deefb5.css} +1 -1
  96. package/static/v3/css/lattice.base.css +1 -1
  97. package/static/v3/css/{lattice.components.9b49d614.css → lattice.components.cde18231.css} +1 -1
  98. package/static/v3/css/lattice.components.css +1 -1
  99. package/static/v3/css/{lattice.shell.8fcc9d33.css → lattice.shell.29d36d85.css} +1 -1
  100. package/static/v3/css/lattice.shell.css +1 -1
  101. package/static/v3/css/{lattice.tokens.e7018963.css → lattice.tokens.304cbc40.css} +3 -0
  102. package/static/v3/css/lattice.tokens.css +3 -0
  103. package/static/v3/css/{lattice.views.22f69117.css → lattice.views.0a18b6c5.css} +2 -2
  104. package/static/v3/css/lattice.views.css +2 -2
  105. package/static/v3/index.html +3 -4
  106. package/static/v3/js/{app.d086489d.js → app.356e6452.js} +1 -1
  107. package/static/v3/js/core/{api.12b568ad.js → api.7a308b89.js} +39 -1
  108. package/static/v3/js/core/api.js +38 -0
  109. package/static/v3/js/core/{routes.d214b399.js → routes.7222343d.js} +22 -22
  110. package/static/v3/js/core/routes.js +22 -22
  111. package/static/v3/js/core/{shell.d05266f5.js → shell.a1657f20.js} +4 -4
  112. package/static/v3/js/core/shell.js +1 -1
  113. package/static/v3/js/core/{store.34ebd5e6.js → store.204a08b2.js} +1 -1
  114. package/static/v3/js/core/store.js +1 -1
  115. package/static/v3/js/views/graph-canvas.17c15d65.js +509 -0
  116. package/static/v3/js/views/graph-canvas.js +509 -0
  117. package/static/v3/js/views/{hybrid-search.b22b97e0.js → hybrid-search.2fb63ed9.js} +1 -2
  118. package/static/v3/js/views/hybrid-search.js +1 -2
  119. package/static/v3/js/views/knowledge-graph.5e40cbeb.js +509 -0
  120. package/static/v3/js/views/knowledge-graph.js +326 -54
  121. package/static/vendor/chart.umd.min.js +20 -0
  122. package/static/vendor/fonts/inter-latin-300-normal.woff2 +0 -0
  123. package/static/vendor/fonts/inter-latin-400-normal.woff2 +0 -0
  124. package/static/vendor/fonts/inter-latin-500-normal.woff2 +0 -0
  125. package/static/vendor/fonts/inter-latin-600-normal.woff2 +0 -0
  126. package/static/vendor/fonts/inter-latin-700-normal.woff2 +0 -0
  127. package/static/vendor/fonts/inter-latin-800-normal.woff2 +0 -0
  128. package/static/vendor/fonts/inter.css +44 -0
  129. package/static/vendor/icons/tabler-icons.min.css +4 -0
  130. package/static/vendor/icons/tabler-icons.woff2 +0 -0
  131. package/static/vendor/marked.min.js +69 -0
  132. package/static/workspace.html +2 -2
  133. package/telegram_bot.py +1 -2
  134. package/tools/commands.py +4 -2
  135. package/tools/computer.py +1 -1
  136. package/tools/documents.py +1 -3
  137. package/tools/filesystem.py +0 -4
  138. package/tools/knowledge.py +1 -3
  139. package/tools/network.py +1 -3
  140. package/codex_telegram_bot.py +0 -195
  141. package/docs/assets/v3.4.0/agent-run.png +0 -0
  142. package/docs/assets/v3.4.0/agents.png +0 -0
  143. package/docs/assets/v3.4.0/before/chat-before.png +0 -0
  144. package/docs/assets/v3.4.0/before/files-before.png +0 -0
  145. package/docs/assets/v3.4.0/chat.png +0 -0
  146. package/docs/assets/v3.4.0/connect-folder.png +0 -0
  147. package/docs/assets/v3.4.0/files.png +0 -0
  148. package/docs/assets/v3.4.0/home.png +0 -0
  149. package/docs/assets/v3.4.0/hooks-dispatch.png +0 -0
  150. package/docs/assets/v3.4.0/knowledge-graph.png +0 -0
  151. package/docs/assets/v3.4.0/local-agent.png +0 -0
  152. package/docs/assets/v3.4.0/memory.png +0 -0
  153. package/docs/assets/v3.4.0/settings.png +0 -0
  154. package/docs/assets/v3.4.0/vision-input.png +0 -0
  155. package/docs/assets/v3.4.0/workflows.png +0 -0
  156. package/docs/assets/v3.4.1/e2e_runtime_log.txt +0 -42
  157. package/docs/assets/v3.4.1/hooks-dispatch.png +0 -0
  158. package/docs/assets/v3.4.1/local-agent.png +0 -0
  159. package/docs/images/admin-dashboard.png +0 -0
  160. package/docs/images/architecture.png +0 -0
  161. package/docs/images/enterprise.png +0 -0
  162. package/docs/images/graph.png +0 -0
  163. package/docs/images/hero.gif +0 -0
  164. package/docs/images/knowledge-graph.png +0 -0
  165. package/docs/images/lattice-ai-demo.gif +0 -0
  166. package/docs/images/lattice-ai-hero.png +0 -0
  167. package/docs/images/logo.svg +0 -33
  168. package/docs/images/mobile-responsive.png +0 -0
  169. package/docs/images/model-recommendation.png +0 -0
  170. package/docs/images/onboarding.png +0 -0
  171. package/docs/images/organization.png +0 -0
  172. package/docs/images/pipeline.png +0 -0
  173. package/docs/images/screenshot-admin.png +0 -0
  174. package/docs/images/screenshot-chat.png +0 -0
  175. package/docs/images/screenshot-graph.png +0 -0
  176. package/docs/images/skills.png +0 -0
  177. package/docs/images/workspace-dark.png +0 -0
  178. package/docs/images/workspace-light.png +0 -0
  179. package/docs/images/workspace.png +0 -0
  180. package/requirements.txt +0 -16
  181. package/static/v3/js/views/knowledge-graph.a14ea7e7.js +0 -237
@@ -0,0 +1,509 @@
1
+ # V4 Digital Brain — Transformation Program Recovery File
2
+
3
+ > **Purpose**: This file makes the v4.0.0 transformation program recoverable by any
4
+ > session (Claude, Codex, other models, or a human developer) without repeating
5
+ > completed analysis. **Update this file before ending any phase and before any
6
+ > likely session/context/usage limit.**
7
+ >
8
+ > Last updated: 2026-06-12 — RELEASE CANDIDATE PREPARED (Phase D complete; awaiting human review)
9
+
10
+ ---
11
+
12
+ ## 0. RC STATUS (final)
13
+
14
+ **v4.0.0 release candidate is on `origin/feat/v4-digital-brain`.**
15
+ Validation: 571 unit tests pass · ruff clean · check:python 186 modules ·
16
+ lint_v3 all checks · installed-wheel smoke (19 modules from clean venv) ·
17
+ release artifacts validated (wheel + sdist + npm tgz, 2.0MB).
18
+ NO merge, NO tag, NO publish — awaiting review.
19
+ Remaining gaps (labeled in FEATURE_STATUS.md §v4.0.0 + RELEASE_NOTES_v4.0.0.md):
20
+ T3d decomposition/v2-flip, T7c async engine, T6 remainder (UUIDs/policy/
21
+ invitations/SQLite state), T9 remainder (legacy deletion + parity views,
22
+ login, i18n, T9b surfaces), pptx history rewrite (owner), consent-gated
23
+ embedder provisioning. All contracts live in docs/V4_IMPLEMENTATION_PLAN.md.
24
+
25
+ ## 1. Program Charter (from the user's v4.0.0 directive)
26
+
27
+ - Transform Lattice AI v3.6.0 into the **final-form Digital Brain Platform** (v4.0.0).
28
+ - Philosophy: models are temporary, knowledge is durable; user owns knowledge/memory/
29
+ context; local-first, privacy-first, digital sovereignty.
30
+ - **Preserve capabilities** (may redesign, must not remove): local-first, Knowledge
31
+ Graph (first-class, visible), graph visualization, search, model recommendation/
32
+ installation, environment analysis, workflow/pipeline, multi-agent, personal +
33
+ organization workspace, provenance, import/export, backup/restore.
34
+ - **Never fake functionality. No placeholders. No demo-only features.** If a
35
+ capability can't be fully realized, build real architecture/interfaces/contracts.
36
+ - Git: work on `feat/v4-digital-brain` only; commit verified work frequently; push to
37
+ remote feature branch; **no merge to main, no production release, no final tags** —
38
+ prepare a release candidate and stop for review.
39
+ - Quality gates: lint, typecheck, tests, build, release-artifact validation, version
40
+ refs updated, docs updated.
41
+ - Deliverables (13): product review, identity review, architecture review, UX review,
42
+ data-model review, brain architecture proposal, implementation plan, implementation,
43
+ validation results, risks/tradeoffs, remaining gaps, RC summary, commit history.
44
+
45
+ ## 2. Current Phase
46
+
47
+ **Phase A (Repository Audit) — COMPLETE (all 8 dimensions).**
48
+ **Phase B (Brain Architecture Proposal + Implementation Plan) — COMPLETE.**
49
+ Adversarial design review done: 3 critics (feasibility, data-safety,
50
+ coherence), all `approve_with_changes`; 19 blocking issues integrated as the
51
+ NORMATIVE "Design-review amendments" section of
52
+ `docs/V4_IMPLEMENTATION_PLAN.md` + corrections in the architecture doc
53
+ (knowledge_graph_api.py is LIVE not dead; edges_v2 identity redefined;
54
+ chat-history import added; garden = watched source; T9b UI track added;
55
+ T7 owns workflow_engine.py + realtime.py with suspension/reconciliation
56
+ specs; tracks run strictly serially). Review record:
57
+ `docs/v4-audit/v4_design_review.json`.
58
+ **Phase C (Implementation) — T1 COMPLETE; next: T2 (Packaging & app factory).**
59
+
60
+ Track log (update at every track boundary):
61
+ - **T2 DONE** (commit `5e8aa1b`, 74 files). Agent did ~90% then died on a
62
+ session limit; finished + verified inline. setup_wizard.py packaged & wheel
63
+ smoke (scripts/wheel_smoke.py, runs in release CI, verified locally: 19
64
+ modules import from clean-venv install); latticeai/app_factory.py
65
+ create_app + lazy server_app facade (subprocess no-side-effect acceptance
66
+ test in test_app_factory.py); AppContext chat+workspace routers; telegram
67
+ via injectable on_chat_message; knowledge_graph_api → api/knowledge_graph
68
+ (parity tests); llm_router → latticeai/models/router, mcp_registry →
69
+ latticeai/core/mcp_registry (root shims); dead bots deleted; [tool.ruff]
70
+ baseline — repo lints CLEAN, CI gate added; deps bounded;
71
+ requirements.txt retired (CI+Dockerfile install from pyproject).
72
+ Suite: 486 passed. Gotcha fixed inline: app_factory must keep the legacy
73
+ alias imports (_agent_risk etc.) as locals — they ARE the server_app
74
+ attribute surface via dict(locals()).
75
+ - **T3 IN PROGRESS as atomic sub-units**:
76
+ - **T3a DONE** (commit `d7f8291`): FTS5 trigram index (node_fts + triggers
77
+ + backfill), search() FTS-first w/ deterministic id-ASC ties, LIKE
78
+ fallback (short queries + builds w/o trigram), capability reported in
79
+ index_status().storage.fts_enabled. 7 tests; suite 493.
80
+ Learned: search() reads the kgv2 views — direct legacy-table SQL is not
81
+ a valid way to test read-path behavior; KnowledgeGraphStore ctor is
82
+ (db_path, blob_dir); ingest_message(role, content, ...).
83
+ - **T3b-1 DONE** (commit `650d4df`): edges_v2 rebuilt to
84
+ UNIQUE(source,target,type,legacy_type) (create→copy→swap, re-entrant,
85
+ data-preserving; projection ON CONFLICT updated); from_legacy()
86
+ round-trips canonical values on both enums (was degrading
87
+ CODE_FILE/AI_RESPONSE/… to CONCEPT). Suite 498.
88
+ - **T3b-2 DONE** (commit `b7de8d7`): _upsert_edge normalizes ALL edge
89
+ writes to canonical EdgeType (legacy label → metadata.legacy_label;
90
+ synonyms dedupe; delete_conversation filters accept both vocabularies);
91
+ nodes_v2 += workspace_id (additive ALTER heal), unscoped visibility =
92
+ 'legacy' sentinel, scope params threaded w/ COALESCE no-strip upserts.
93
+ Suite 503. NOTE for T4/T6: ingestion + workspace callers should now
94
+ pass owner/workspace_id explicitly (metadata user_email/workspace_id
95
+ hints already resolve).
96
+ - **T3c DONE** (commit after b7de8d7): edge_occurrences table (every
97
+ observation recorded, cascades) + nodes_v2.superseded_by +
98
+ mark_superseded(). Suite 507.
99
+ - **T3e DONE**: docs/kg-schema.md rewritten to match code (false API
100
+ claims removed; FTS5/scope/temporal documented).
101
+ - RESEQUENCING DECISION: T3d (decomposition + write-mastering flip) is
102
+ agent-scale and limit-blocked until ~17:30 KST; T4 sub-units proceed
103
+ inline meanwhile — safe because T4 rewires *callers* onto public store
104
+ APIs which T3d preserves (suite-green gate).
105
+ - **T4.1 DONE** (commits `427d6a3` + `a2a1445`): chat (app_factory
106
+ save_to_history), MCP (/mcp/call knowledge_graph_ingest), and uploads
107
+ (upload_service) all route through IngestionPipeline — new
108
+ CHAT_SOURCE_TYPES route calls ingest_message w/ role/conversation
109
+ semantics; provenance_coverage() store metric + GET
110
+ /knowledge-graph/provenance/coverage endpoint (parity baseline updated
111
+ deliberately). Coverage now 4/5 (workspace events land with T6 rebuild).
112
+ Suite 511.
113
+ - **T4.2 DONE** (commit `34ba891`): latticeai/brain/conversations.py
114
+ ConversationStore (same SQLite file as the KG → backup co-location free);
115
+ idempotent chat_history.json import; get_history/clear_* contracts
116
+ preserved incl. legacy bucket + started_at sweep; MemoryService
117
+ conversation tier reads the store. latticeai.brain packaged. Suite 517.
118
+ Branch pushed to origin/feat/v4-digital-brain.
119
+ - **T4.3 DONE** (commit `17dbe0a`): gardener dual-writes (vault markdown
120
+ mirror + pipeline ingest w/ provenance source_type=note); idempotent
121
+ startup vault import; get_relevant_context = brain query (vault-scan
122
+ fallback only when graph disabled); get_tree() implemented (was a
123
+ latent 500). Suite 528.
124
+ - **T4.4 DONE** (commit `e341f74`): graph_curator live — store.curate()
125
+ gated topic promotion w/ real nodes_v2.importance_score + POST
126
+ /knowledge-graph/curate. Suite 530. Backup round-trip test proves
127
+ conversations ride the KG backup. **T4 COMPLETE.**
128
+ - **T6.5 DONE** (commits `84ca636`+`443a8ce`): hashed session tokens at
129
+ rest (transparent plaintext migration), 8+ alnum password policy on
130
+ register/change-password, S256 PKCE on SSO. Suite 523→531.
131
+ - **T5 COMPLETE** (commits b12a68c, 4e8cd70, ca50d10): latticeai/brain/
132
+ memory.py (BrainMemory: Decision/Experience typed records via new
133
+ decision/experience/workspace_event pipeline source types; simulation
134
+ runs REFUSED at the memory boundary) + latticeai/brain/context.py
135
+ (ContextAssembler: budgeted chars/4 approx_tokens, per-section
136
+ provenance, honest absence, seam isolation). Chat context = assembler
137
+ (memories finally injected at inference + hybrid search replaces LIKE;
138
+ doc-gen branch preserved; trace persisted as trace_seed.context_assembly).
139
+ Agent learnings → Experience records via AgentDeps.brain_memory port
140
+ (vault dump fallback only when port absent; no more bare-except).
141
+ Suite 541.
142
+ - **T8 COMPLETE** (commit b1e05f4): latticeai/brain/identity.py (Ed25519
143
+ device keypair, file 0600 default / keyring opt-in via
144
+ LATTICEAI_DEVICE_KEY_KEYRING=1 — keyring at startup blew test runtime
145
+ 6s→237s, hence opt-in), signed export bundles + verified imports w/
146
+ origin provenance + unsigned-legacy local policy, export(workspace_id)
147
+ now REALLY filters (was header-only), latticeai/brain/network.py Brain
148
+ Network v1 (pairing, signed+replay-protected peer auth, push/receive,
149
+ signer-must-match-peer), /network API. Suite 548.
150
+ - **T7a DONE** (commit 1fc96ec): workflow tool nodes EXECUTE via
151
+ dispatch_tool under governance; ApprovalRequired pauses runs into
152
+ awaiting_approval w/ JSON cursor (WorkflowEngine.resume re-enters at the
153
+ paused node, never re-executing; denial fails honestly); skill +
154
+ plugin-skill nodes refuse honestly; plugin run_tool executes governed;
155
+ live runs persist mode='live' + pause cursor; POST
156
+ /workflows/api/runs/{id}/resume (one decision; record resolves).
157
+ - **T7b DONE** (commit 3064fa3): llm_role_runner — planner/executor/
158
+ reviewer call the loaded model; parse failure FAILS the run w/ raw
159
+ preserved (fail-closed); build_orchestrator picks mode='llm' only when
160
+ a model is loaded; agents run endpoint via asyncio.to_thread + sync
161
+ model bridge (asyncio.run safe in worker thread). Suite 559.
162
+ - **T6-scoped-reads DONE** (commit 7f58a57): workspaces_of/
163
+ filter_scoped_nodes on the store; all SearchService channels + kg.graph()
164
+ accept allowed_workspaces; search router scopes via _ScopedSearchService
165
+ proxy + PLATFORM.allowed_scopes; ContextAssembler hybrid seam scoped per
166
+ user. Legacy NULL rows machine-visible (documented). Suite 564.
167
+ - **T7d DONE** (commit 235f9b6): latticeai/services/triggers.py —
168
+ interval scheduler (missed-while-down → recorded skip events, no
169
+ catch-up) + brain_event triggers via visible post_tool hook on
170
+ kg_ingest.*; __trigger__ provenance in run inputs; describe() honest
171
+ status; started in app factory w/ idempotent hook registration. Suite 569.
172
+ - **T7e DONE** (commit 014ca91): custom registry agents executable
173
+ (config actually loaded; honest skip in simulation).
174
+ - **T9-canvas DONE** (commit 2fee077): force-directed canvas explorer
175
+ (graph-canvas.js + Explore rewire; visual spec updated).
176
+ - **T9-IA DONE** (commit 972d34c): brain-first nav (Brain/Ask/Capture/
177
+ Act/Library/System); knowledge-graph is the default landing route.
178
+ - **PHASE D DECISION**: moving to T10 RC prep. REMAINING GAPS (honest,
179
+ labeled, not faked): T3d brain decomposition + v2 write-mastering flip;
180
+ T7c async run engine/cancellation/SSE/startup reconciliation; T6
181
+ remainder (user UUIDs, enforced policy module, invitations, workspace
182
+ SQLite state); T9 remainder (legacy page deletion + parity views, login
183
+ rebuild, artifact ungitting, i18n, T9b approval/network/trace surfaces).
184
+ All have full contracts in docs/V4_IMPLEMENTATION_PLAN.md + amendments.
185
+ - T9-canvas agent left static/v3/js/views/graph-canvas.js (509 lines,
186
+ node --check passes) but NEVER rewired knowledge-graph.js — file kept
187
+ uncommitted in tree; integration outstanding.
188
+ - NOTE: T3d + T9-canvas agents died instantly on session limits THREE times
189
+ (latest reset 4:10am KST)
190
+ (next reset 23:00 KST); both tasks remain queued with full contracts in
191
+ this file + the plan.
192
+ - **T3d** (agent task after limits reset 17:30 KST): latticeai/brain/
193
+ decomposition (store/discovery/ingest/provenance/documents/extraction,
194
+ ≤1,500 lines/module, no mixin god-object) + v2 write-mastering flip
195
+ (backup-first, re-entrant migrator keyed on data state, downgrade
196
+ marker via PRAGMA user_version, equivalence scoped to pre-flip data).
197
+ - **T3e**: docs/kg-schema.md regenerated from enums.
198
+ - graph_curator decision moved to T4.
199
+ - **T9 PARTIAL — vendoring half DONE** (commit `aa613ae`, parallel-safe per
200
+ amendments): all CDN references removed from every shipped page (Inter,
201
+ Tabler icons, chart.js, marked.js vendored under static/vendor);
202
+ --lt3-on-accent token added; sw.js rebuilt around the v3 manifest;
203
+ lint_v3.mjs now mechanically enforces token/inline-style/CDN rules;
204
+ 6 guard tests. REMAINING T9: canvas graph port (item 2), IA regroup (1),
205
+ legacy deletion + redirects (3, needs parity views), login rebuild,
206
+ artifact ungitting, i18n, T9b surfaces (after T7/T8).
207
+ - **T1 DONE** (commits `1cddc67` frontend + `c574eb6` backend). All 7 items:
208
+ by-id snapshot/memory authz via new WorkspaceService.authorize_record_read/
209
+ authorize_memory_delete; /workspace/os leak removed (workspace_count
210
+ replaces raw registry; legacy+v3 UI only read workspace_registry — checked);
211
+ chat context pairing fix (pair_user_history, module-level in api/chat.py);
212
+ recall matches-key fix + shared lexical scorer (no constants); run records
213
+ carry mode/record_schema_version=2 and simulation runs skip KG ingestion
214
+ (record_agent_run/record_workflow_run mode param; orchestrator declares
215
+ mode; agent_runtime threads it); fake fusion meters removed (hashed bundle
216
+ regenerated, manifest updated); README overclaims corrected.
217
+ Suite: 469 passed (455 baseline + 3 static guards + 11 T1 tests).
218
+ Note: T1 ran inline (main session) after the workflow implementer hit a
219
+ usage limit; only the frontend half came from the workflow agent.
220
+
221
+ Scope ruling (user directive, session 3): risk/effort/migration size are NOT
222
+ valid exclusion reasons — only true technical blockers. Consequently the
223
+ architecture now INCLUDES: KG v2 write-mastering flip, durable async run
224
+ engine + cancellation + SSE + triggers, per-tool approval gate, user-UUID
225
+ identity + policy enforcement + invitations, transactional workspace state,
226
+ FTS5 + optional sqlite-vec, Brain Network v1 peer exchange (signed bundles
227
+ over LAN HTTP), knowledge_graph.py decomposition into latticeai/brain/,
228
+ root-module absorption, create_app factory, legacy frontend deletion,
229
+ token-native login, i18n. Only two exclusions remain (both true blockers):
230
+ git history rewrite for the tracked pptx (force-push = owner decision at RC
231
+ review; file IS deleted at HEAD in T10) and silent default download of a
232
+ production embedder (consent violation; wizard-provisioned opt-in instead).
233
+
234
+ Full structured audit findings for all 8 dimensions are committed at
235
+ `docs/v4-audit/v4_audit_<dimension>.json` (summary / strengths / problems
236
+ with severity+files / opportunities with effort). §4 below condenses the two
237
+ that predate the JSON drop; **read the JSON files for the other six — they are
238
+ the canonical Phase A record.**
239
+
240
+ ## 3. Completed Work
241
+
242
+ 1. **Baseline established (main @ 5889195, v3.6.0)**
243
+ - Tests: `.venv/bin/python -m pytest tests/` → **455 unit pass, 9 integration
244
+ fail**. The 9 failures are *pre-existing* `httpx.ConnectError`s — they need a
245
+ live server. **Unit tests (`tests/unit`) are the validation gate.**
246
+ - `.venv` Python is 3.14.5. `pyproject.toml` requires >=3.11 (avoid PEP 701
247
+ f-strings nesting same quotes — 3.11 compat; CI runs 3.11).
248
+ - Code inventory: `latticeai/` package ~15,007 lines (28 core modules, 16
249
+ services, 27 API routers + `server_app.py` at 1,554 lines). Legacy root
250
+ modules ~6,720 lines incl. `knowledge_graph.py` **4,633 lines**,
251
+ `kg_schema.py` 521, `llm_router.py` 775, `mcp_registry.py` 791.
252
+ - Frontend: `/app` v3 SPA (`static/v3/`, 22 views, token-native) is primary;
253
+ legacy static HTML pages (`static/*.html`) still shipped in parallel.
254
+ - Repo root clutter: ~30 `ltcai-*.tgz` tarballs, `ltcai-0.3.1/` extracted copy,
255
+ logs, `chat_history.json`, 15MB pptx — most likely untracked; verify with
256
+ `git ls-files` before cleaning.
257
+ 2. **Branch created**: `feat/v4-digital-brain` (from main @ 5889195). No commits yet
258
+ besides this recovery file.
259
+ 3. **Phase A audits completed (2 of 8)** — full JSON in
260
+ `/tmp/v4_audit_agent-workflow-runtime.json` and
261
+ `/tmp/v4_audit_workspace-enterprise.json` (also summarized in §4 below; tmp files
262
+ may not survive reboot — §4 is the durable record).
263
+
264
+ ## 4. Findings (completed audit dimensions)
265
+
266
+ ### 4.1 Agent & Workflow Runtime — VERDICT: one real runtime, two demo-grade ones
267
+
268
+ **Real (keep/extend):**
269
+ - `latticeai/core/agent.py` — genuine single-agent LLM state machine
270
+ (PLAN→EXECUTE→VERIFY→ROLLBACK), real tool execution via `DEFAULT_TOOL_REGISTRY`
271
+ (`tools/__init__.py:247-256`), destructive-action blocking, loop detection, git
272
+ rollback, human-in-the-loop plan approval (`latticeai/api/chat.py:714-727`).
273
+ - Hooks platform is real as of v3.4+ (v3.3.0 gap closed): execution engine in
274
+ `latticeai/core/hooks.py:498-713`, 7 built-ins bound at startup
275
+ (`server_app.py:1327`), subprocess user hooks, fail-closed `pre_*` gates,
276
+ persisted run log (`hooks_runs.json`), fired from agent/workflow/tool/ingestion.
277
+ - `dispatch_tool` (`hooks.py:187-233`) is the single shared tool lifecycle seam.
278
+ - `WorkflowEngine` (`core/workflow_engine.py`) is a clean, tested interpreter
279
+ (validation, cycle guard, eval-free conditions) — the *engine* is fine.
280
+ - Tool governance single ownership point: `core/tool_registry.py`.
281
+
282
+ **Critical problems:**
283
+ - **Multi-Agent Runtime is deterministic theater**: production always uses
284
+ `default_role_runner` (`platform_runtime.py:211-216`); planner emits canned
285
+ 3-step plan (`multi_agent.py:339-343`), self-approves, executor does no work,
286
+ reviewer rubber-stamps — yet persists fake plans/handoffs/reviews into the
287
+ workspace store **and the Knowledge Graph** (fabricated provenance).
288
+ - **Workflow runs execute nothing**: `platform_runtime._tool_node_runner` (:79-97)
289
+ returns `{recorded: true}` instead of calling `execute_tool`; skill/plugin
290
+ runners are existence checks. Runs finish "ok" having done zero work.
291
+ - Custom agents in `AgentRegistry` are metadata-only — orchestrator filters to 5
292
+ hardcoded `AGENT_ROLES` (`multi_agent.py:476`); registration is a UI illusion.
293
+ - No async execution/cancellation/scheduling; `stop()` can't cancel; only
294
+ 'manual' trigger exists.
295
+ - Tool approval is audit-only (`agent.py:176-194` always auto-approves);
296
+ per-tool human gate doesn't exist despite governance vocabulary.
297
+ - Two parallel agent systems with colliding names (`core/agent.py` vs
298
+ `core/multi_agent.py`+`services/agent_runtime.py`).
299
+
300
+ **Key opportunities (= v4 work):** back orchestrator roles with the real
301
+ single-agent runtime + LLM router; make workflow tool nodes call `dispatch_tool`
302
+ with real governance (pause-for-approval state); async durable runs + SSE events +
303
+ real cancellation; trigger system (cron/interval + KG-event triggers via existing
304
+ hooks, e.g. "on document ingested, run workflow"); unify agent systems so registry
305
+ entries carry executable config (model/prompt/tool allowlist); route agent
306
+ learnings through `services/ingestion.py` with provenance; label simulation runs
307
+ honestly (`mode` field) until/unless execution is real.
308
+
309
+ ### 4.2 Workspace, Identity & Enterprise — VERDICT: solid auth, illusory isolation
310
+
311
+ **Real (keep):** `core/oidc.py` (fail-closed OIDC verifier, anti-downgrade),
312
+ SSO nonce binding (`api/auth.py:137-201`), honest open-core enterprise seam
313
+ (`core/enterprise.py` — everything reports `enabled=False`), `core/security.py`
314
+ (scrypt, trusted-proxy XFF, constant-time compares), `PermissionGateway`
315
+ (path+action+user+hash+TTL consent), workspace role enforcement in store with
316
+ tests, non-destructive workspace migration.
317
+
318
+ **Critical problems:**
319
+ - **The actual "brain" is machine-global, not workspace-scoped**:
320
+ `workspace_service.py:39` `SHARED_GLOBAL_AREAS = ('graph', 'skills')`;
321
+ KG store constructed once per machine (`server_app.py:296+`); chat history
322
+ global; portability export is admin-only machine-global. Personal vs
323
+ Organization workspace isolation only covers auxiliary JSON records.
324
+ - **By-id authz bypasses**: `GET /workspace/snapshots/{id}` (+`/{area}`,
325
+ `/export`, `/compare`) only `require_user` — any authenticated user reads any
326
+ workspace's snapshots (`workspace.py:343-389`). Memory delete lacks ownership
327
+ checks; `/workspace/os` leaks full registry incl. other orgs' member lists
328
+ (`workspace_os.py:433`).
329
+ - Single unlocked whole-file `workspace_os.json` (1,959 lines module, 0 locks):
330
+ lost updates under concurrency; silent `[-200:]`/`[-500:]` truncation of
331
+ memories/traces/timeline — contradicts "knowledge is durable".
332
+ - Three conflicting role vocabularies (users.json admin|user; workspace
333
+ owner/admin/member/viewer; `_ROLE_CAPS` matrix that **nothing enforces** though
334
+ `admin.py:112-113` claims it's "the real access policy").
335
+ - Minor: session tokens stored plaintext; 4-char min password; dead
336
+ `detect_edition()` env branch; dead `_sso_states`; org-creation timeline event
337
+ mis-scoped; SSO lacks PKCE.
338
+
339
+ **Key opportunities (= v4 work):** partition KG by workspace (prereq for
340
+ Personal/Organization Brain) — `~/.ltcai/workspaces/<id>/` or workspace_id
341
+ columns, threaded through ingestion/search/portability; close by-id authz gaps
342
+ (small!); unify identity (stable user UUIDs, one policy module, real
343
+ invitations); per-workspace SQLite for workspace state (kill lost updates +
344
+ truncation); federation foundations: device keypair identity (keyring), signed
345
+ provenance-stamped export bundles, selective sharing; visibility levels
346
+ (private/workspace/org) on memories+nodes; per-user "take your brain with you"
347
+ export + encryption at rest; harden edges (hash session tokens, PKCE, password
348
+ policy).
349
+
350
+ ### 4.3 Remaining six dimensions — COMPLETE; headline findings
351
+
352
+ Canonical record: `docs/v4-audit/*.json`. Cross-dimension headline synthesis:
353
+
354
+ - **product-identity**: identity is skin-deep — only README/ARCHITECTURE say
355
+ "Digital Brain"; PROJECT_PRINCIPLES/pyproject/package.json/SPA IA still say
356
+ "AI workspace". **p_reinforce.py "garden" vault (`~/.ltcai-brain`) is a second
357
+ brain bypassing the KG**, injected into every chat (`api/chat.py:368`),
358
+ contradicting "no source bypasses the graph". README overclaims agents/
359
+ workflows that FEATURE_STATUS admits are LLM-free. Naming sprawl (9 ids,
360
+ 2 env prefixes, uppercase `LTCAI` bin). FEATURE_STATUS.md honesty ledger is
361
+ the prize asset — institutionalize it.
362
+ - **backend-architecture**: inverted dependency — clean `latticeai/` imports
363
+ legacy root modules everywhere. `knowledge_graph.py` = 4,633-line single
364
+ class w/ 7 responsibilities. **IngestionPipeline covers only 1 of 4 KG write
365
+ paths** (browser only; chat/uploads/MCP write directly, no provenance).
366
+ `server_app.py` 1,555-line god module, import-time side effects, dormant
367
+ AppContext/deps.py. Chat history hard-capped at 50 messages in JSON.
368
+ telegram_bot imported unconditionally by chat router. Dead: codex_telegram_bot,
369
+ perm_monitor, knowledge_graph_api (vestigial).
370
+ - **knowledge-data-model**: KG v2 is **schema theater** — reads reconstruct
371
+ legacy Korean free-string types via COALESCE views; v2's owner_id/visibility/
372
+ evidence/created_by/embedding columns never populated; writes still mint
373
+ '업로드함'/'포함함'. No temporal/episodic dimension (edges UNIQUE collapse
374
+ history). No memory-type model. Search default = LIKE + brute-force cosine
375
+ over hash embeddings (grade='fallback'). graph_curator.py dead in production.
376
+ docs/kg-schema.md documents nonexistent APIs (validate_endpoints).
377
+ - **frontend-ux**: TWO complete frontends in production (legacy ~17k lines at
378
+ /chat,/graph,/workspace,/admin… vs v3 SPA at /app); onboarding + /admin route
379
+ into the LEGACY stack. v3 KG explorer (static SVG) is weaker than legacy
380
+ force-directed canvas — backwards for KG-first. CDN fonts/icons contradict
381
+ privacy-first. sw.js stale (precaches legacy). Hashed build artifacts
382
+ committed beside sources. lint_v3.mjs is syntax-check only.
383
+ - **memory-context**: memory IS injected at chat time but naively (string
384
+ concat of vault substring-scan + SQLite LIKE); workspace personal-memory tier
385
+ NEVER consumed at inference; **`MemoryService.recall` graph branch dead code**
386
+ (`.get("results")` vs actual `matches` key); fabricated recall scores
387
+ (hardcoded 0.6/0.5); recent-chat context **leaks other users' messages**
388
+ (filter passes any assistant reply); hybrid/vector search never used at
389
+ inference; agent learnings dumped to vault markdown w/ swallowed errors.
390
+ - **release-quality**: **published wheel is broken** — `server_app.py:149`
391
+ imports root `setup` module which py-modules omits; root `setup.py` is
392
+ application code colliding with setuptools. Zero Python lint/typecheck.
393
+ Deps fully unpinned (pyproject + duplicated requirements.txt). npm tarball
394
+ 24.8MB (ships docs images, bots). Version = 9 synchronized copies guarded by
395
+ a test. 15MB pptx tracked at HEAD. Root clutter (31 tgz, 2 venvs, logs) is
396
+ untracked (440 tracked files; 0 tgz tracked). Strong assets to keep:
397
+ validate_release_artifacts.py, version-consistency tests, CI matrix,
398
+ tag-driven release workflow.
399
+
400
+ ## 5. Decisions Made
401
+
402
+ 1. `feat/v4-digital-brain` is the working branch; main untouched.
403
+ 2. Unit tests (455) are the green gate; the 9 integration failures are
404
+ pre-existing and excluded from the gate (re-verify they don't regress further).
405
+ 3. Phase structure: A audit → B design (Brain Architecture Proposal + impl plan,
406
+ with adversarial design review) → C implementation tracks (disjoint file
407
+ ownership, frequent verified commits) → D validation + RC + final report.
408
+ 4. Audit failures are re-run as a fresh 6-dimension workflow (not resume) to
409
+ avoid cache ambiguity around failed agents.
410
+ 5. Recovery discipline: update this file at every phase boundary and before
411
+ any foreseeable limit.
412
+
413
+ ## 6. Remaining Work / Exact Next Actions
414
+
415
+ 1. **[NOW] Re-run the 6 failed audit dimensions** (same prompts as in workflow
416
+ script `v4-audit-wf_d690b8d1-60c.js` under the session workflows/scripts dir;
417
+ prompts are reproducible from §4.3 dimension list + FINDINGS schema).
418
+ 2. Merge all 8 findings into §4 of this file; mark Phase A complete.
419
+ 3. **Phase B**: write `docs/V4_BRAIN_ARCHITECTURE.md` (Brain Architecture
420
+ Proposal) + `docs/V4_IMPLEMENTATION_PLAN.md`; run adversarial design review
421
+ (2-3 critic agents); revise; commit.
422
+ 4. **Phase C**: implement per the plan (queue below), committing after each
423
+ verified track.
424
+ 5. **Phase D**: full validation, version bump to 4.0.0 (RC), docs, release notes,
425
+ push branch, final 13-deliverable report. STOP — wait for human review.
426
+
427
+ ## 7. Detailed Implementation Queue
428
+
429
+ **SUPERSEDED by `docs/V4_IMPLEMENTATION_PLAN.md` (tracks T1–T10 with file
430
+ ownership, migration strategies, tests, and risk register). That document is
431
+ the execution contract for Phase C.** The original provisional queue below is
432
+ retained for context only:
433
+
434
+ - **C1. Truth & safety floor (small, do first)**
435
+ - Close workspace by-id authz gaps; strip registry leak from `/workspace/os`.
436
+ - Mark multi-agent/workflow simulation runs with persisted `mode:
437
+ "simulation"`; stop writing fabricated runs into the KG as real provenance.
438
+ - Hash session tokens at rest; real password policy; PKCE on SSO exchange.
439
+ - **C2. Brain Core data layer**
440
+ - Workspace-partitioned Knowledge Graph + memory + chat scoping
441
+ (Personal Brain vs Organization Brain become real).
442
+ - Durable workspace state (per-workspace SQLite or locked store); remove
443
+ silent truncation.
444
+ - Memory model: episodic/semantic/experience/decision record types with
445
+ provenance, on the KG substrate.
446
+ - **C3. Real Agent Runtime**
447
+ - LLM-backed role runners on top of `core/agent.py` + `llm_router`;
448
+ registry entries become executable (model/prompt/tool allowlist).
449
+ - Per-tool approval gate generalizing the human-in-loop pause.
450
+ - **C4. Real Workflow Runtime**
451
+ - Tool/skill nodes execute through `dispatch_tool` under governance with
452
+ pause-for-approval; async runs + cancellation + SSE progress.
453
+ - Trigger foundations: interval/cron + KG-event triggers via hooks.
454
+ - **C5. Sovereignty & federation foundations**
455
+ - Per-user/per-workspace brain export (signed bundles, device keypair),
456
+ import with provenance; visibility levels.
457
+ - **C6. Identity unification** — user UUIDs, single policy module, invitations.
458
+ - **C7. UX/IA re-architecture** — pending frontend-ux audit results.
459
+ - **C8. Backend decomposition** — knowledge_graph.py monolith etc., pending
460
+ backend audit results.
461
+ - **C9. Release hygiene** — version single-source, root cleanup, lint/typecheck
462
+ story, pending release-quality audit results.
463
+
464
+ ## 8. Planned Phase B Activities
465
+
466
+ - Synthesize all 8 audits into: Product Review, Identity Review, Architecture
467
+ Review, UX Review, Data Model Review (deliverables 1-5).
468
+ - Author **Brain Architecture Proposal**: Brain Core; Memory/Knowledge/
469
+ Relationship/Experience/Decision/Context systems; Agent Runtime; Dynamic
470
+ Workflow Runtime; Personal Brain / Organization Brain / Brain Network /
471
+ Knowledge Exchange / Federation foundations — mapped onto the real existing
472
+ seams (ingestion pipeline, hooks, dispatch_tool, workspace service, KG store).
473
+ - Author Implementation Plan with track ownership (disjoint files per track).
474
+ - Adversarial review: 2-3 critic agents attack the proposal (feasibility,
475
+ fake-functionality risk, capability-preservation, migration safety); revise.
476
+ - Commit both docs.
477
+
478
+ ## 9. Planned Phase C Activities
479
+
480
+ - Execute queue §7 as sequenced tracks; after each track: run
481
+ `.venv/bin/python -m pytest tests/unit -q` (+ targeted new tests; every new
482
+ feature ships with tests), commit with conventional message, update this file.
483
+ - Implementation agents must follow: no placeholder code, no demo data, honest
484
+ labeling, additive migrations with backfill, 3.11-compatible syntax.
485
+
486
+ ## 10. Planned Phase D Activities
487
+
488
+ - `scripts/validate_release_artifacts.py`, `scripts/lint_v3.mjs`, full pytest,
489
+ `npm`/vsix build as applicable, packaging build.
490
+ - Version → 4.0.0 across pyproject.toml/package.json/setup.py/health endpoint
491
+ (verify the single-source mechanism from v3.3.0 audit).
492
+ - Update README/ARCHITECTURE/FEATURE_STATUS/CHANGELOG + RELEASE_NOTES_v4.0.0.md.
493
+ - Push `feat/v4-digital-brain`; produce final 13-deliverable report; STOP for
494
+ human review (no merge, no tag, no publish).
495
+
496
+ ## 11. Branch Status
497
+
498
+ - `feat/v4-digital-brain` exists locally, based on main @ 5889195 (v3.6.0).
499
+ - Not yet pushed to origin. No implementation commits yet.
500
+
501
+ ## 12. Validation Status
502
+
503
+ - main baseline: 455 unit pass / 9 pre-existing integration failures
504
+ (ConnectError, need live server). Nothing run on the branch yet beyond this.
505
+
506
+ ## 13. Files Modified (branch vs main)
507
+
508
+ - `docs/V4_DIGITAL_BRAIN_RECOVERY.md` (this file) — NEW.
509
+ - (none else yet)