ltcai 4.0.0 → 4.1.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 (195) hide show
  1. package/README.md +42 -33
  2. package/desktop/electron/main.cjs +44 -0
  3. package/docs/CHANGELOG.md +106 -0
  4. package/docs/REALTIME_COLLABORATION.md +3 -3
  5. package/docs/V3_FRONTEND.md +9 -8
  6. package/docs/V4_1_FRONTEND_ARCHITECTURE_REVIEW.md +65 -0
  7. package/docs/V4_1_FRONTEND_MIGRATION_REPORT.md +70 -0
  8. package/docs/V4_1_VALIDATION_REPORT.md +47 -0
  9. package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +95 -45
  10. package/docs/kg-schema.md +6 -2
  11. package/docs/spec-vs-impl.md +10 -10
  12. package/frontend/index.html +24 -0
  13. package/frontend/openapi.json +14190 -0
  14. package/frontend/src/App.tsx +184 -0
  15. package/frontend/src/api/client.ts +317 -0
  16. package/frontend/src/api/openapi.ts +16637 -0
  17. package/frontend/src/components/primitives.tsx +204 -0
  18. package/frontend/src/components/ui/badge.tsx +27 -0
  19. package/frontend/src/components/ui/button.tsx +37 -0
  20. package/frontend/src/components/ui/card.tsx +22 -0
  21. package/frontend/src/components/ui/input.tsx +16 -0
  22. package/frontend/src/components/ui/textarea.tsx +16 -0
  23. package/frontend/src/lib/utils.ts +33 -0
  24. package/frontend/src/main.tsx +23 -0
  25. package/frontend/src/pages/Act.tsx +245 -0
  26. package/frontend/src/pages/Ask.tsx +200 -0
  27. package/frontend/src/pages/Brain.tsx +267 -0
  28. package/frontend/src/pages/Capture.tsx +158 -0
  29. package/frontend/src/pages/Library.tsx +187 -0
  30. package/frontend/src/pages/System.tsx +344 -0
  31. package/frontend/src/routes.ts +85 -0
  32. package/frontend/src/store/appStore.ts +54 -0
  33. package/frontend/src/styles.css +107 -0
  34. package/kg_schema.py +2 -603
  35. package/knowledge_graph.py +37 -4958
  36. package/latticeai/__init__.py +1 -1
  37. package/latticeai/api/admin.py +15 -16
  38. package/latticeai/api/agents.py +13 -6
  39. package/latticeai/api/auth.py +19 -11
  40. package/latticeai/api/invitations.py +100 -0
  41. package/latticeai/api/knowledge_graph.py +4 -11
  42. package/latticeai/api/plugins.py +3 -6
  43. package/latticeai/api/realtime.py +4 -7
  44. package/latticeai/api/setup.py +5 -4
  45. package/latticeai/api/static_routes.py +13 -16
  46. package/latticeai/api/ui_redirects.py +26 -0
  47. package/latticeai/api/workflow_designer.py +39 -6
  48. package/latticeai/api/workspace.py +24 -10
  49. package/latticeai/app_factory.py +88 -17
  50. package/latticeai/brain/_kg_common.py +1123 -0
  51. package/latticeai/brain/discovery.py +1455 -0
  52. package/latticeai/brain/documents.py +218 -0
  53. package/latticeai/brain/ingest.py +644 -0
  54. package/latticeai/brain/projection.py +561 -0
  55. package/latticeai/brain/provenance.py +401 -0
  56. package/latticeai/brain/retrieval.py +1316 -0
  57. package/latticeai/brain/schema.py +640 -0
  58. package/latticeai/brain/store.py +216 -0
  59. package/latticeai/brain/write_master.py +225 -0
  60. package/latticeai/core/invitations.py +131 -0
  61. package/latticeai/core/marketplace.py +1 -1
  62. package/latticeai/core/multi_agent.py +1 -1
  63. package/latticeai/core/policy.py +54 -0
  64. package/latticeai/core/realtime.py +65 -44
  65. package/latticeai/core/sessions.py +31 -5
  66. package/latticeai/core/users.py +147 -0
  67. package/latticeai/core/workspace_os.py +420 -20
  68. package/latticeai/services/agent_runtime.py +242 -4
  69. package/latticeai/services/run_executor.py +328 -0
  70. package/latticeai/services/workspace_service.py +27 -19
  71. package/package.json +54 -27
  72. package/scripts/build_frontend_assets.mjs +38 -0
  73. package/scripts/bump_version.py +1 -1
  74. package/scripts/export_openapi.py +31 -0
  75. package/scripts/lint_frontend.mjs +86 -0
  76. package/scripts/run_python.mjs +47 -0
  77. package/src-tauri/Cargo.lock +4833 -0
  78. package/src-tauri/Cargo.toml +19 -0
  79. package/src-tauri/build.rs +3 -0
  80. package/src-tauri/capabilities/default.json +7 -0
  81. package/src-tauri/src/main.rs +78 -0
  82. package/src-tauri/tauri.conf.json +36 -0
  83. package/static/app/asset-manifest.json +32 -0
  84. package/static/app/assets/core-CwxXejkd.js +2 -0
  85. package/static/app/assets/core-CwxXejkd.js.map +1 -0
  86. package/static/app/assets/index-CJRAzNnf.js +333 -0
  87. package/static/app/assets/index-CJRAzNnf.js.map +1 -0
  88. package/static/app/assets/index-CSwBBgf4.css +2 -0
  89. package/static/app/index.html +25 -0
  90. package/static/manifest.json +2 -2
  91. package/static/sw.js +4 -4
  92. package/scripts/build_v3_assets.mjs +0 -170
  93. package/scripts/lint_v3.mjs +0 -97
  94. package/static/account.html +0 -113
  95. package/static/activity.html +0 -73
  96. package/static/admin.html +0 -486
  97. package/static/agents.html +0 -139
  98. package/static/chat.html +0 -841
  99. package/static/css/reference/account.css +0 -439
  100. package/static/css/reference/admin.css +0 -610
  101. package/static/css/reference/base.css +0 -1661
  102. package/static/css/reference/chat.css +0 -4623
  103. package/static/css/reference/graph.css +0 -1016
  104. package/static/css/responsive.css +0 -861
  105. package/static/graph.html +0 -122
  106. package/static/platform.css +0 -104
  107. package/static/plugins.html +0 -136
  108. package/static/scripts/account.js +0 -238
  109. package/static/scripts/admin.js +0 -1614
  110. package/static/scripts/chat.js +0 -5081
  111. package/static/scripts/graph.js +0 -1804
  112. package/static/scripts/platform.js +0 -64
  113. package/static/scripts/ux.js +0 -167
  114. package/static/scripts/workspace.js +0 -948
  115. package/static/v3/asset-manifest.json +0 -56
  116. package/static/v3/css/lattice.base.49deefb5.css +0 -128
  117. package/static/v3/css/lattice.base.css +0 -128
  118. package/static/v3/css/lattice.components.cde18231.css +0 -472
  119. package/static/v3/css/lattice.components.css +0 -472
  120. package/static/v3/css/lattice.shell.29d36d85.css +0 -452
  121. package/static/v3/css/lattice.shell.css +0 -452
  122. package/static/v3/css/lattice.tokens.304cbc40.css +0 -135
  123. package/static/v3/css/lattice.tokens.css +0 -135
  124. package/static/v3/css/lattice.views.0a18b6c5.css +0 -360
  125. package/static/v3/css/lattice.views.css +0 -360
  126. package/static/v3/index.html +0 -68
  127. package/static/v3/js/app.356e6452.js +0 -26
  128. package/static/v3/js/app.js +0 -26
  129. package/static/v3/js/core/api.7a308b89.js +0 -568
  130. package/static/v3/js/core/api.js +0 -568
  131. package/static/v3/js/core/components.f25b3b93.js +0 -230
  132. package/static/v3/js/core/components.js +0 -230
  133. package/static/v3/js/core/dom.a2773eb0.js +0 -148
  134. package/static/v3/js/core/dom.js +0 -148
  135. package/static/v3/js/core/router.584570f2.js +0 -37
  136. package/static/v3/js/core/router.js +0 -37
  137. package/static/v3/js/core/routes.7222343d.js +0 -93
  138. package/static/v3/js/core/routes.js +0 -93
  139. package/static/v3/js/core/shell.a1657f20.js +0 -391
  140. package/static/v3/js/core/shell.js +0 -391
  141. package/static/v3/js/core/store.204a08b2.js +0 -113
  142. package/static/v3/js/core/store.js +0 -113
  143. package/static/v3/js/views/admin-audit.660a1fb1.js +0 -185
  144. package/static/v3/js/views/admin-audit.js +0 -185
  145. package/static/v3/js/views/admin-permissions.a7ae5f09.js +0 -177
  146. package/static/v3/js/views/admin-permissions.js +0 -177
  147. package/static/v3/js/views/admin-policies.3658fd86.js +0 -102
  148. package/static/v3/js/views/admin-policies.js +0 -102
  149. package/static/v3/js/views/admin-private-vpc.7d342d36.js +0 -135
  150. package/static/v3/js/views/admin-private-vpc.js +0 -135
  151. package/static/v3/js/views/admin-security.07c66b72.js +0 -180
  152. package/static/v3/js/views/admin-security.js +0 -180
  153. package/static/v3/js/views/admin-users.03bac88c.js +0 -168
  154. package/static/v3/js/views/admin-users.js +0 -168
  155. package/static/v3/js/views/agents.014d0b74.js +0 -541
  156. package/static/v3/js/views/agents.js +0 -541
  157. package/static/v3/js/views/chat.e6dd7dd0.js +0 -601
  158. package/static/v3/js/views/chat.js +0 -601
  159. package/static/v3/js/views/files.adad14c1.js +0 -365
  160. package/static/v3/js/views/files.js +0 -365
  161. package/static/v3/js/views/graph-canvas.17c15d65.js +0 -509
  162. package/static/v3/js/views/graph-canvas.js +0 -509
  163. package/static/v3/js/views/home.24f8b8ae.js +0 -200
  164. package/static/v3/js/views/home.js +0 -200
  165. package/static/v3/js/views/hooks.37895880.js +0 -220
  166. package/static/v3/js/views/hooks.js +0 -220
  167. package/static/v3/js/views/hybrid-search.2fb63ed9.js +0 -194
  168. package/static/v3/js/views/hybrid-search.js +0 -194
  169. package/static/v3/js/views/knowledge-graph.5e40cbeb.js +0 -509
  170. package/static/v3/js/views/knowledge-graph.js +0 -509
  171. package/static/v3/js/views/marketplace.ab0583d4.js +0 -141
  172. package/static/v3/js/views/marketplace.js +0 -141
  173. package/static/v3/js/views/mcp.99b5c6a7.js +0 -114
  174. package/static/v3/js/views/mcp.js +0 -114
  175. package/static/v3/js/views/memory.4ebdf474.js +0 -147
  176. package/static/v3/js/views/memory.js +0 -147
  177. package/static/v3/js/views/models.a1ffa147.js +0 -256
  178. package/static/v3/js/views/models.js +0 -256
  179. package/static/v3/js/views/my-computer.d9d9ae1c.js +0 -463
  180. package/static/v3/js/views/my-computer.js +0 -463
  181. package/static/v3/js/views/pipeline.c522f1ce.js +0 -157
  182. package/static/v3/js/views/pipeline.js +0 -157
  183. package/static/v3/js/views/planning.9ac3e313.js +0 -153
  184. package/static/v3/js/views/planning.js +0 -153
  185. package/static/v3/js/views/settings.8631fa5e.js +0 -318
  186. package/static/v3/js/views/settings.js +0 -318
  187. package/static/v3/js/views/skills.c6c2f965.js +0 -109
  188. package/static/v3/js/views/skills.js +0 -109
  189. package/static/v3/js/views/tools.e4f11276.js +0 -108
  190. package/static/v3/js/views/tools.js +0 -108
  191. package/static/v3/js/views/workflows.26c57290.js +0 -128
  192. package/static/v3/js/views/workflows.js +0 -128
  193. package/static/workflows.html +0 -146
  194. package/static/workspace.css +0 -1121
  195. package/static/workspace.html +0 -357
@@ -1,200 +0,0 @@
1
- /* ============================================================================
2
- * View: Home — the workspace command center.
3
- * Leads with the product identity (the retrieval lattice: Knowledge Graph +
4
- * Vector Index + Hybrid Search) and routes into every primary area.
5
- *
6
- * View contract (shared by all views):
7
- * export async function render(ctx) -> single DOM node
8
- * ctx = { h, icon, api, store, c, route, params, navigate, toast }
9
- * ========================================================================== */
10
-
11
- export async function render(ctx) {
12
- const { h, icon, api, store, c, navigate } = ctx;
13
- const ws = store.activeWorkspace();
14
- const readinessHost = h("div.lt3-readiness", c.loading({ lines: 4 }));
15
- const activityHost = h("div", c.loading({ lines: 3 }));
16
-
17
- const root = h("div.lt3-stack-6",
18
- c.viewHeader({
19
- eyebrow: "Local-first AI workspace",
20
- title: `Welcome to ${ws.name}`,
21
- sub: "Everything you index stays on this machine. Ask questions, explore the graph, and fuse structure with semantics — no data leaves your computer.",
22
- actions: [
23
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => navigate("hybrid-search") } }, icon("arrows-join"), "Hybrid search"),
24
- h("button.lt3-btn.lt3-btn--primary", { on: { click: () => navigate("chat", { new: "1" }) } }, icon("message-plus"), "New chat"),
25
- ],
26
- }),
27
- buildHero(ctx, readinessHost),
28
- h("section",
29
- c.sectionHead("Retrieval lattice", h("span", { id: "home-idx-src" }, c.sourceBadge("pending"))),
30
- h("div", { id: "home-pillars" }, c.loading({ lines: 2, block: true })),
31
- ),
32
- h("section",
33
- c.sectionHead("Jump back in"),
34
- buildQuickGrid(ctx),
35
- ),
36
- h("div.lt3-grid-2",
37
- c.panel({ eyebrow: "Index", title: "Connected sources", children: h("div", { id: "home-sources" }, c.loading({ lines: 3 })) }),
38
- c.panel({ eyebrow: "Workspace", title: "At a glance", children: h("div", { id: "home-stats" }, c.loading({ lines: 3 })) }),
39
- ),
40
- c.panel({
41
- eyebrow: "Activity",
42
- title: "Recent activity",
43
- sub: "Shown only when the local backend provides trace history.",
44
- children: activityHost,
45
- className: "lt3-panel--activity",
46
- }),
47
- );
48
-
49
- hydrate(ctx, root, { readinessHost, activityHost });
50
- return root;
51
- }
52
-
53
- function buildHero({ h, icon, navigate }, readinessHost) {
54
- return h("div.lt3-hero",
55
- h("div",
56
- h("div.lt3-eyebrow.lt3-hero__eyebrow", icon("sparkles"), "Knowledge Graph · Vector Index · Hybrid Search"),
57
- h("h2.lt3-hero__title", "Local workspace status, without pretending."),
58
- h("p.lt3-hero__sub", "Lattice shows what is ready, what is unavailable, and what needs a local runtime before Chat, Search, Knowledge, and Memory can work together."),
59
- h("div.lt3-hero__actions",
60
- h("button.lt3-btn.lt3-btn--primary.lt3-btn--lg", { on: { click: () => navigate("chat", { new: "1" }) } }, icon("message-plus"), "Start chat"),
61
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--lg", { on: { click: () => navigate("files") } }, icon("upload"), "Upload files"),
62
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--lg", { on: { click: () => navigate("models") } }, icon("cpu"), "Check models"),
63
- ),
64
- h("div.lt3-mini-lattice", { style: { "margin-top": "var(--lt3-space-6)" } },
65
- h("div.lt3-mini-lattice__node", h("b", "Knowledge"), h("span", "Entities and relations")),
66
- h("div.lt3-mini-lattice__node", h("b", "Vectors"), h("span", "Local semantic recall")),
67
- h("div.lt3-mini-lattice__node", h("b", "Hybrid"), h("span", "Fused answer grounding")),
68
- ),
69
- ),
70
- h("aside.lt3-hero__aside",
71
- h("div.lt3-eyebrow", "Readiness"),
72
- readinessHost,
73
- ),
74
- );
75
- }
76
-
77
- const QUICK = [
78
- { key: "chat", icon: "message-2", title: "Chat", desc: "Grounded conversation." },
79
- { key: "files", icon: "folders", title: "Files", desc: "Sources and indexing." },
80
- { key: "hybrid-search", icon: "arrows-join", title: "Search", desc: "Fuse graph + vector recall." },
81
- { key: "knowledge-graph", icon: "chart-dots-3", title: "Knowledge", desc: "Browse entities and relations." },
82
- { key: "memory", icon: "brain", title: "Memory", desc: "Inspect long-term recall." },
83
- { key: "models", icon: "cpu", title: "Models", desc: "Local MLX runtime." },
84
- ];
85
-
86
- function buildQuickGrid({ h, icon, navigate }) {
87
- return h("div.lt3-quickgrid",
88
- QUICK.map((q) => h("button.lt3-quick", { style: { "text-align": "left" }, on: { click: () => navigate(q.key) } },
89
- h("div.lt3-quick__icon", icon(q.icon)),
90
- h("div.lt3-quick__title", q.title),
91
- h("div.lt3-quick__desc", q.desc),
92
- )),
93
- );
94
- }
95
-
96
- async function hydrate(ctx, root, hosts) {
97
- const { h, icon, api, store, c } = ctx;
98
- const { readinessHost, activityHost } = hosts;
99
- const numFmt = c.fmtNum;
100
-
101
- // Index status → pillars + sources + topbar chip.
102
- const idx = store.get().indexStatus
103
- ? { data: store.get().indexStatus, source: "live" }
104
- : await api.indexStatus().then((r) => { store.setIndexStatus(r.data); return r; });
105
-
106
- root.querySelector("#home-idx-src")?.replaceChildren(c.sourceBadge(idx.source));
107
- root.querySelector("#home-pillars")?.replaceChildren(c.pillars(idx.data));
108
-
109
- const sources = (idx.data && idx.data.sources) || [];
110
- const srcHost = root.querySelector("#home-sources");
111
- if (srcHost) {
112
- srcHost.replaceChildren(
113
- sources.length
114
- ? h("div.lt3-stack-3", sources.map((s) => h("div.lt3-stack-2",
115
- h("div.lt3-row", { style: { "justify-content": "space-between" } },
116
- h("div.lt3-row-2", icon("database"), h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, s.label)),
117
- c.statePill(s.state),
118
- ),
119
- c.meter(s.progress ?? (s.state === "indexed" ? 1 : 0.5), s.state === "indexing" ? "warn" : "vector"),
120
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${numFmt(s.files)} files`),
121
- )))
122
- : c.emptyState({ icon: "database-off", title: "No sources connected", body: "Upload documents to start indexing. Folder watching requires the desktop local agent." }),
123
- );
124
- }
125
-
126
- const [os, models, memory, traces] = await Promise.all([
127
- api.workspaceOs(),
128
- api.models(),
129
- api.memoryManager(),
130
- api.get("/workspace/traces", { traces: [] }),
131
- ]);
132
- renderReadiness({ h, icon, c, readinessHost, idx, models, os, memory });
133
-
134
- // Workspace counts.
135
- const counts = (os.data && os.data.counts) || {};
136
- const statHost = root.querySelector("#home-stats");
137
- if (statHost) {
138
- statHost.replaceChildren(
139
- h("div.lt3-statrow",
140
- c.stat({ label: "Memories", value: numFmt(counts.memories), icon: "brain" }),
141
- c.stat({ label: "Traces", value: numFmt(counts.traces), icon: "route" }),
142
- c.stat({ label: "Workflows", value: numFmt(counts.workflows), icon: "git-branch" }),
143
- c.stat({ label: "Skills", value: numFmt(counts.skills), icon: "puzzle" }),
144
- ),
145
- h("div", { style: { "margin-top": "var(--lt3-space-3)" } }, c.sourceBadge(os.source)),
146
- );
147
- }
148
-
149
- renderActivity({ h, icon, c, activityHost, traces });
150
- }
151
-
152
- function renderReadiness({ h, icon, c, readinessHost, idx, models, os, memory }) {
153
- const pipes = (idx.data && idx.data.pipelines) || {};
154
- const vectorReady = String(pipes.vector_index?.state || "").toLowerCase() === "ready";
155
- const graphReady = String(pipes.knowledge_graph?.state || "").toLowerCase() === "ready";
156
- const modelName = models.data && models.data.current;
157
- const counts = (os.data && os.data.counts) || {};
158
- const memSources = (memory.data && memory.data.sources) || [];
159
- readinessHost.replaceChildren(
160
- readinessRow({ h, icon, c, ic: "server", title: "Backend", meta: idx.source === "live" ? "Live local API" : "Local API unavailable", state: idx.source === "live" ? "ready" : "pending" }),
161
- readinessRow({ h, icon, c, ic: "cpu", title: "Model", meta: modelName ? shortModel(modelName) : "No model loaded", state: modelName ? "ready" : "pending" }),
162
- readinessRow({ h, icon, c, ic: "database", title: "Retrieval", meta: graphReady && vectorReady ? "Graph and vector ready" : "Index needs data or rebuild", state: graphReady && vectorReady ? "ready" : "pending" }),
163
- readinessRow({ h, icon, c, ic: "brain", title: "Memory", meta: memSources.length ? `${c.fmtNum(counts.memories)} memories across ${memSources.length} tiers` : "Memory backend unavailable or empty", state: memSources.length ? "ready" : "idle" }),
164
- );
165
- }
166
-
167
- function readinessRow({ h, icon, c, ic, title, meta, state }) {
168
- return h("div.lt3-readiness__row",
169
- h("div.lt3-readiness__icon", icon(ic)),
170
- h("div", h("div.lt3-readiness__title", title), h("div.lt3-readiness__meta", meta)),
171
- c.statePill(state),
172
- );
173
- }
174
-
175
- function renderActivity({ h, icon, c, activityHost, traces }) {
176
- const rows = (traces.data && Array.isArray(traces.data.traces)) ? traces.data.traces : [];
177
- if (!rows.length) {
178
- activityHost.replaceChildren(c.emptyState({
179
- icon: "history-off",
180
- title: "No recent activity available",
181
- body: traces.source === "live" ? "The backend returned no trace history yet." : "Start the backend to show recent local workspace activity.",
182
- }));
183
- return;
184
- }
185
- activityHost.replaceChildren(h("div.lt3-list", rows.slice(0, 6).map((tr) =>
186
- h("div.lt3-list__item",
187
- h("span.lt3-avatar", { style: { width: "28px", height: "28px" } }, icon("route")),
188
- h("div.lt3-list__body",
189
- h("div.lt3-list__title", tr.question || tr.event_type || "Workspace event"),
190
- h("div.lt3-list__meta", [tr.confidence != null ? `${Math.round(Number(tr.confidence) * 100)}% confidence` : null, tr.created_at || tr.timestamp || null].filter(Boolean).join(" · ")),
191
- ),
192
- c.sourceBadge(traces.source),
193
- ))));
194
- }
195
-
196
- function shortModel(id) {
197
- const s = String(id || "");
198
- const tail = s.includes("/") ? s.split("/").pop() : s;
199
- return tail.length > 28 ? tail.slice(0, 27) + "…" : tail;
200
- }
@@ -1,200 +0,0 @@
1
- /* ============================================================================
2
- * View: Home — the workspace command center.
3
- * Leads with the product identity (the retrieval lattice: Knowledge Graph +
4
- * Vector Index + Hybrid Search) and routes into every primary area.
5
- *
6
- * View contract (shared by all views):
7
- * export async function render(ctx) -> single DOM node
8
- * ctx = { h, icon, api, store, c, route, params, navigate, toast }
9
- * ========================================================================== */
10
-
11
- export async function render(ctx) {
12
- const { h, icon, api, store, c, navigate } = ctx;
13
- const ws = store.activeWorkspace();
14
- const readinessHost = h("div.lt3-readiness", c.loading({ lines: 4 }));
15
- const activityHost = h("div", c.loading({ lines: 3 }));
16
-
17
- const root = h("div.lt3-stack-6",
18
- c.viewHeader({
19
- eyebrow: "Local-first AI workspace",
20
- title: `Welcome to ${ws.name}`,
21
- sub: "Everything you index stays on this machine. Ask questions, explore the graph, and fuse structure with semantics — no data leaves your computer.",
22
- actions: [
23
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => navigate("hybrid-search") } }, icon("arrows-join"), "Hybrid search"),
24
- h("button.lt3-btn.lt3-btn--primary", { on: { click: () => navigate("chat", { new: "1" }) } }, icon("message-plus"), "New chat"),
25
- ],
26
- }),
27
- buildHero(ctx, readinessHost),
28
- h("section",
29
- c.sectionHead("Retrieval lattice", h("span", { id: "home-idx-src" }, c.sourceBadge("pending"))),
30
- h("div", { id: "home-pillars" }, c.loading({ lines: 2, block: true })),
31
- ),
32
- h("section",
33
- c.sectionHead("Jump back in"),
34
- buildQuickGrid(ctx),
35
- ),
36
- h("div.lt3-grid-2",
37
- c.panel({ eyebrow: "Index", title: "Connected sources", children: h("div", { id: "home-sources" }, c.loading({ lines: 3 })) }),
38
- c.panel({ eyebrow: "Workspace", title: "At a glance", children: h("div", { id: "home-stats" }, c.loading({ lines: 3 })) }),
39
- ),
40
- c.panel({
41
- eyebrow: "Activity",
42
- title: "Recent activity",
43
- sub: "Shown only when the local backend provides trace history.",
44
- children: activityHost,
45
- className: "lt3-panel--activity",
46
- }),
47
- );
48
-
49
- hydrate(ctx, root, { readinessHost, activityHost });
50
- return root;
51
- }
52
-
53
- function buildHero({ h, icon, navigate }, readinessHost) {
54
- return h("div.lt3-hero",
55
- h("div",
56
- h("div.lt3-eyebrow.lt3-hero__eyebrow", icon("sparkles"), "Knowledge Graph · Vector Index · Hybrid Search"),
57
- h("h2.lt3-hero__title", "Local workspace status, without pretending."),
58
- h("p.lt3-hero__sub", "Lattice shows what is ready, what is unavailable, and what needs a local runtime before Chat, Search, Knowledge, and Memory can work together."),
59
- h("div.lt3-hero__actions",
60
- h("button.lt3-btn.lt3-btn--primary.lt3-btn--lg", { on: { click: () => navigate("chat", { new: "1" }) } }, icon("message-plus"), "Start chat"),
61
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--lg", { on: { click: () => navigate("files") } }, icon("upload"), "Upload files"),
62
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--lg", { on: { click: () => navigate("models") } }, icon("cpu"), "Check models"),
63
- ),
64
- h("div.lt3-mini-lattice", { style: { "margin-top": "var(--lt3-space-6)" } },
65
- h("div.lt3-mini-lattice__node", h("b", "Knowledge"), h("span", "Entities and relations")),
66
- h("div.lt3-mini-lattice__node", h("b", "Vectors"), h("span", "Local semantic recall")),
67
- h("div.lt3-mini-lattice__node", h("b", "Hybrid"), h("span", "Fused answer grounding")),
68
- ),
69
- ),
70
- h("aside.lt3-hero__aside",
71
- h("div.lt3-eyebrow", "Readiness"),
72
- readinessHost,
73
- ),
74
- );
75
- }
76
-
77
- const QUICK = [
78
- { key: "chat", icon: "message-2", title: "Chat", desc: "Grounded conversation." },
79
- { key: "files", icon: "folders", title: "Files", desc: "Sources and indexing." },
80
- { key: "hybrid-search", icon: "arrows-join", title: "Search", desc: "Fuse graph + vector recall." },
81
- { key: "knowledge-graph", icon: "chart-dots-3", title: "Knowledge", desc: "Browse entities and relations." },
82
- { key: "memory", icon: "brain", title: "Memory", desc: "Inspect long-term recall." },
83
- { key: "models", icon: "cpu", title: "Models", desc: "Local MLX runtime." },
84
- ];
85
-
86
- function buildQuickGrid({ h, icon, navigate }) {
87
- return h("div.lt3-quickgrid",
88
- QUICK.map((q) => h("button.lt3-quick", { style: { "text-align": "left" }, on: { click: () => navigate(q.key) } },
89
- h("div.lt3-quick__icon", icon(q.icon)),
90
- h("div.lt3-quick__title", q.title),
91
- h("div.lt3-quick__desc", q.desc),
92
- )),
93
- );
94
- }
95
-
96
- async function hydrate(ctx, root, hosts) {
97
- const { h, icon, api, store, c } = ctx;
98
- const { readinessHost, activityHost } = hosts;
99
- const numFmt = c.fmtNum;
100
-
101
- // Index status → pillars + sources + topbar chip.
102
- const idx = store.get().indexStatus
103
- ? { data: store.get().indexStatus, source: "live" }
104
- : await api.indexStatus().then((r) => { store.setIndexStatus(r.data); return r; });
105
-
106
- root.querySelector("#home-idx-src")?.replaceChildren(c.sourceBadge(idx.source));
107
- root.querySelector("#home-pillars")?.replaceChildren(c.pillars(idx.data));
108
-
109
- const sources = (idx.data && idx.data.sources) || [];
110
- const srcHost = root.querySelector("#home-sources");
111
- if (srcHost) {
112
- srcHost.replaceChildren(
113
- sources.length
114
- ? h("div.lt3-stack-3", sources.map((s) => h("div.lt3-stack-2",
115
- h("div.lt3-row", { style: { "justify-content": "space-between" } },
116
- h("div.lt3-row-2", icon("database"), h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, s.label)),
117
- c.statePill(s.state),
118
- ),
119
- c.meter(s.progress ?? (s.state === "indexed" ? 1 : 0.5), s.state === "indexing" ? "warn" : "vector"),
120
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${numFmt(s.files)} files`),
121
- )))
122
- : c.emptyState({ icon: "database-off", title: "No sources connected", body: "Upload documents to start indexing. Folder watching requires the desktop local agent." }),
123
- );
124
- }
125
-
126
- const [os, models, memory, traces] = await Promise.all([
127
- api.workspaceOs(),
128
- api.models(),
129
- api.memoryManager(),
130
- api.get("/workspace/traces", { traces: [] }),
131
- ]);
132
- renderReadiness({ h, icon, c, readinessHost, idx, models, os, memory });
133
-
134
- // Workspace counts.
135
- const counts = (os.data && os.data.counts) || {};
136
- const statHost = root.querySelector("#home-stats");
137
- if (statHost) {
138
- statHost.replaceChildren(
139
- h("div.lt3-statrow",
140
- c.stat({ label: "Memories", value: numFmt(counts.memories), icon: "brain" }),
141
- c.stat({ label: "Traces", value: numFmt(counts.traces), icon: "route" }),
142
- c.stat({ label: "Workflows", value: numFmt(counts.workflows), icon: "git-branch" }),
143
- c.stat({ label: "Skills", value: numFmt(counts.skills), icon: "puzzle" }),
144
- ),
145
- h("div", { style: { "margin-top": "var(--lt3-space-3)" } }, c.sourceBadge(os.source)),
146
- );
147
- }
148
-
149
- renderActivity({ h, icon, c, activityHost, traces });
150
- }
151
-
152
- function renderReadiness({ h, icon, c, readinessHost, idx, models, os, memory }) {
153
- const pipes = (idx.data && idx.data.pipelines) || {};
154
- const vectorReady = String(pipes.vector_index?.state || "").toLowerCase() === "ready";
155
- const graphReady = String(pipes.knowledge_graph?.state || "").toLowerCase() === "ready";
156
- const modelName = models.data && models.data.current;
157
- const counts = (os.data && os.data.counts) || {};
158
- const memSources = (memory.data && memory.data.sources) || [];
159
- readinessHost.replaceChildren(
160
- readinessRow({ h, icon, c, ic: "server", title: "Backend", meta: idx.source === "live" ? "Live local API" : "Local API unavailable", state: idx.source === "live" ? "ready" : "pending" }),
161
- readinessRow({ h, icon, c, ic: "cpu", title: "Model", meta: modelName ? shortModel(modelName) : "No model loaded", state: modelName ? "ready" : "pending" }),
162
- readinessRow({ h, icon, c, ic: "database", title: "Retrieval", meta: graphReady && vectorReady ? "Graph and vector ready" : "Index needs data or rebuild", state: graphReady && vectorReady ? "ready" : "pending" }),
163
- readinessRow({ h, icon, c, ic: "brain", title: "Memory", meta: memSources.length ? `${c.fmtNum(counts.memories)} memories across ${memSources.length} tiers` : "Memory backend unavailable or empty", state: memSources.length ? "ready" : "idle" }),
164
- );
165
- }
166
-
167
- function readinessRow({ h, icon, c, ic, title, meta, state }) {
168
- return h("div.lt3-readiness__row",
169
- h("div.lt3-readiness__icon", icon(ic)),
170
- h("div", h("div.lt3-readiness__title", title), h("div.lt3-readiness__meta", meta)),
171
- c.statePill(state),
172
- );
173
- }
174
-
175
- function renderActivity({ h, icon, c, activityHost, traces }) {
176
- const rows = (traces.data && Array.isArray(traces.data.traces)) ? traces.data.traces : [];
177
- if (!rows.length) {
178
- activityHost.replaceChildren(c.emptyState({
179
- icon: "history-off",
180
- title: "No recent activity available",
181
- body: traces.source === "live" ? "The backend returned no trace history yet." : "Start the backend to show recent local workspace activity.",
182
- }));
183
- return;
184
- }
185
- activityHost.replaceChildren(h("div.lt3-list", rows.slice(0, 6).map((tr) =>
186
- h("div.lt3-list__item",
187
- h("span.lt3-avatar", { style: { width: "28px", height: "28px" } }, icon("route")),
188
- h("div.lt3-list__body",
189
- h("div.lt3-list__title", tr.question || tr.event_type || "Workspace event"),
190
- h("div.lt3-list__meta", [tr.confidence != null ? `${Math.round(Number(tr.confidence) * 100)}% confidence` : null, tr.created_at || tr.timestamp || null].filter(Boolean).join(" · ")),
191
- ),
192
- c.sourceBadge(traces.source),
193
- ))));
194
- }
195
-
196
- function shortModel(id) {
197
- const s = String(id || "");
198
- const tail = s.includes("/") ? s.split("/").pop() : s;
199
- return tail.length > 28 ? tail.slice(0, 27) + "…" : tail;
200
- }
@@ -1,220 +0,0 @@
1
- /* ============================================================================
2
- * View: Hooks — the lifecycle hooks registry + dispatch.
3
- * Reads /api/hooks (built-in + user hooks across the pre_/post_ run, tool,
4
- * workflow, upload, and index lifecycle pairs + agent), toggles enabled state,
5
- * reorders, registers, runs hooks, and shows a recent-executions log. Built-in
6
- * hooks are platform-managed; non-executable hooks are labelled "advisory".
7
- * ========================================================================== */
8
-
9
- const KIND_LABEL = {
10
- pre_run: "Pre-run", post_run: "Post-run",
11
- pre_tool: "Pre-tool", post_tool: "Post-tool",
12
- pre_workflow: "Pre-workflow", post_workflow: "Post-workflow",
13
- pre_upload: "Pre-upload", post_upload: "Post-upload",
14
- pre_index: "Pre-index", post_index: "Post-index",
15
- agent: "Agent",
16
- };
17
-
18
- export async function render(ctx) {
19
- const { h, c } = ctx;
20
- const src = h("span", c.sourceBadge("pending"));
21
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
22
- const groupsHost = h("div", c.loading({ lines: 4, block: true }));
23
-
24
- // Recent executions — proves hooks fire end-to-end (v3.4.0).
25
- const runsSrc = h("span", c.sourceBadge("pending"));
26
- const runsHost = h("div", c.loading({ lines: 3, block: true }));
27
-
28
- const nameInput = h("input.lt3-input", { type: "text", placeholder: "Hook name" });
29
- const kindSelect = h("select.lt3-select", Object.keys(KIND_LABEL).map((k) => h("option", { value: k }, KIND_LABEL[k])));
30
- const descInput = h("input.lt3-input", { type: "text", placeholder: "What it does (optional)" });
31
-
32
- const root = h("div.lt3-stack-6",
33
- c.viewHeader({
34
- eyebrow: "Platform",
35
- title: "Hooks",
36
- sub: "Lifecycle extension points across runs, tools, agents, pipelines, and workflows — visible, ordered, and individually toggleable.",
37
- actions: [src],
38
- }),
39
- statHost,
40
- c.panel({
41
- title: "Register a hook", sub: "Custom hooks are listed, ordered, and inspectable.",
42
- children: h("div.lt3-stack-3",
43
- h("div.lt3-grid-2", h("div.lt3-field", h("label", "Name"), nameInput), h("div.lt3-field", h("label", "Kind"), kindSelect)),
44
- h("div.lt3-field", h("label", "Description"), descInput),
45
- h("div.lt3-row-2", h("button.lt3-btn.lt3-btn--primary", { on: { click: register } }, c.icon("plus"), "Register hook")),
46
- ),
47
- }),
48
- groupsHost,
49
- c.panel({
50
- title: "Recent executions",
51
- sub: "What actually ran. Blocked pre-hooks and advisory built-ins are surfaced honestly — no fabricated success.",
52
- actions: [
53
- runsSrc,
54
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: loadRuns } }, c.icon("refresh"), "Refresh"),
55
- ],
56
- children: runsHost,
57
- }),
58
- );
59
-
60
- load();
61
- loadRuns();
62
- return root;
63
-
64
- async function load() {
65
- const res = await ctx.api.hooks();
66
- src.replaceChildren(c.sourceBadge(res.source));
67
- const hooks = (res.data && res.data.hooks) || [];
68
- if (!hooks.length) {
69
- statHost.replaceChildren(c.stat({ label: "Hooks", value: "—", icon: "webhook" }));
70
- groupsHost.replaceChildren(c.emptyState({ icon: "webhook-off", title: "Hooks unavailable", body: "Start the backend to read the hooks registry." }));
71
- return;
72
- }
73
- const en = hooks.filter((x) => x.enabled).length;
74
- statHost.replaceChildren(
75
- c.stat({ label: "Hooks", value: c.fmtNum(hooks.length), icon: "webhook" }),
76
- c.stat({ label: "Enabled", value: c.fmtNum(en), icon: "circle-check" }),
77
- c.stat({ label: "Kinds", value: c.fmtNum((res.data.kinds || []).length), icon: "layers" }),
78
- );
79
- const byKind = {};
80
- for (const hk of hooks) (byKind[hk.kind] = byKind[hk.kind] || []).push(hk);
81
- groupsHost.replaceChildren(h("div.lt3-stack-6", Object.keys(byKind).map((kind) =>
82
- h("section", c.sectionHead(
83
- KIND_LABEL[kind] || kind,
84
- c.pill(String(byKind[kind].length)),
85
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => runKind(kind) } }, c.icon("player-play"), `Run ${KIND_LABEL[kind] || kind}`),
86
- ),
87
- h("div.lt3-stack-2", byKind[kind].map((hk) => hookRow(ctx, hk)))))));
88
- }
89
-
90
- function hookRow(ctx2, hk) {
91
- return c.card(h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", gap: "var(--lt3-space-3)" } },
92
- h("div", { style: { "min-width": 0 } },
93
- h("div.lt3-row-2", h("b", hk.name), c.pill(hk.source === "builtin" ? "built-in" : "custom", hk.source === "builtin" ? "info" : ""), hk.managed === "platform" ? c.pill("managed", "") : null, hk.advisory ? c.pill("advisory", "warn") : c.pill("executable", "ok")),
94
- h("p.lt3-muted", { style: { margin: "2px 0 0", "font-size": "var(--lt3-text-sm)" } }, hk.description || ""),
95
- hk.binding ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, hk.binding) : null,
96
- ),
97
- h("div.lt3-row-2", { style: { "flex-shrink": 0 } },
98
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `#${hk.order}`),
99
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => runHook(hk) } }, c.icon("player-play"), "Run"),
100
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => toggle(ctx2, hk) } }, c.icon(hk.enabled ? "toggle-right" : "toggle-left"), hk.enabled ? "On" : "Off"),
101
- hk.removable ? h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => remove(ctx2, hk) } }, c.icon("trash")) : null,
102
- ),
103
- ), { flat: true });
104
- }
105
-
106
- async function toggle(ctx2, hk) {
107
- const res = hk.enabled ? await ctx2.api.hookDisable(hk.id) : await ctx2.api.hookEnable(hk.id, true);
108
- ctx2.toast(res && res.ok ? `${hk.name}: ${hk.enabled ? "disabled" : "enabled"}` : "Action unavailable", res && res.ok ? "ok" : "err");
109
- load();
110
- }
111
- async function remove(ctx2, hk) {
112
- const res = await ctx2.api.hookRemove(hk.id);
113
- ctx2.toast(res && res.ok ? `Removed ${hk.name}` : "Remove unavailable", res && res.ok ? "ok" : "err");
114
- load();
115
- }
116
- async function register() {
117
- const name = nameInput.value.trim();
118
- if (!name) { ctx.toast("Enter a hook name", "info"); return; }
119
- const res = await ctx.api.hookRegister({ name, kind: kindSelect.value, description: descInput.value.trim() });
120
- if (res && res.ok) { ctx.toast(`Registered ${name}`, "ok"); nameInput.value = ""; descInput.value = ""; load(); }
121
- else { ctx.toast("Register unavailable", "err"); }
122
- }
123
-
124
- /* ── Dispatch ─────────────────────────────────────────────────────────────
125
- * Fire hooks for real and surface the honest outcome. status === "ok" is a
126
- * clean run; "blocked"/"skipped"/"advisory" are warnings (advisory built-ins
127
- * never claim success); "error" is a failure. The run log refreshes after. */
128
-
129
- // Map a hook status to a toast variant — advisory/blocked are never "ok".
130
- function statusVariant(status) {
131
- if (status === "ok") return "ok";
132
- if (status === "error") return "err";
133
- return "warn"; // blocked | skipped | advisory | anything unexpected
134
- }
135
-
136
- async function runHook(hk) {
137
- const res = await ctx.api.hookRun({ hook_id: hk.id, event: "manual" });
138
- if (!res || !res.ok || !res.data) {
139
- const detail = (res && res.data && (res.data.detail || res.data.error)) || (res && res.error) || "dispatch unavailable";
140
- ctx.toast(`Run failed: ${detail}`, "err");
141
- loadRuns();
142
- return;
143
- }
144
- const d = res.data;
145
- const status = d.status || "unknown";
146
- ctx.toast(`Ran ${hk.name}: ${status}${d.detail ? " — " + d.detail : ""}`, statusVariant(status));
147
- loadRuns();
148
- }
149
-
150
- async function runKind(kind) {
151
- const res = await ctx.api.hookRun({ kind, event: "manual" });
152
- if (!res || !res.ok || !res.data) {
153
- const detail = (res && res.data && (res.data.detail || res.data.error)) || (res && res.error) || "dispatch unavailable";
154
- ctx.toast(`Run ${KIND_LABEL[kind] || kind} failed: ${detail}`, "err");
155
- loadRuns();
156
- return;
157
- }
158
- const d = res.data;
159
- const ran = d.ran == null ? 0 : d.ran;
160
- const label = KIND_LABEL[kind] || kind;
161
- const variant = d.blocked ? "warn" : (ran > 0 ? "ok" : "info");
162
- ctx.toast(`${ran} ${label} hook(s) ran${d.blocked ? " — blocked: " + (d.block_reason || "policy") : ""}`, variant);
163
- loadRuns();
164
- }
165
-
166
- /* ── Recent executions log ─────────────────────────────────────────────── */
167
-
168
- async function loadRuns() {
169
- runsHost.replaceChildren(c.loading({ lines: 3, block: true }));
170
- const res = await ctx.api.hookRuns(50);
171
- runsSrc.replaceChildren(c.sourceBadge(res.source));
172
- const runs = (res.data && res.data.runs) || [];
173
- if (!res.ok && res.source === "unavailable") {
174
- runsHost.replaceChildren(c.emptyState({
175
- icon: "webhook-off",
176
- title: "Run log unavailable",
177
- body: "Start the backend to read recent hook executions.",
178
- }));
179
- return;
180
- }
181
- if (!runs.length) {
182
- runsHost.replaceChildren(c.emptyState({
183
- icon: "history-off",
184
- title: "No hook executions yet",
185
- body: "Run a hook, or trigger an agent run / workflow / upload to see lifecycle hooks fire here.",
186
- }));
187
- return;
188
- }
189
- runsHost.replaceChildren(h("div.lt3-stack-2", runs.map((r) => runRow(r))));
190
- }
191
-
192
- function runRow(r) {
193
- const status = r.status || "unknown";
194
- const detail = r.detail || r.output || "";
195
- return c.card(h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start", gap: "var(--lt3-space-3)" } },
196
- h("div", { style: { "min-width": 0 } },
197
- h("div.lt3-row-2",
198
- h("b", r.name || r.hook_id || "hook"),
199
- c.pill(KIND_LABEL[r.kind] || r.kind || "—", "info"),
200
- c.statePill(status),
201
- ),
202
- (r.target_event || r.target_kind) ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)", "margin-top": "2px" } },
203
- `event: ${r.target_event || r.target_kind || "—"}`) : null,
204
- detail ? h("p.lt3-faint", {
205
- style: { margin: "4px 0 0", "font-size": "var(--lt3-text-xs)", "font-family": "var(--lt3-font-mono)", "white-space": "nowrap", overflow: "hidden", "text-overflow": "ellipsis", "max-width": "100%" },
206
- title: detail,
207
- }, truncate(detail, 160)) : null,
208
- ),
209
- h("div", { style: { "flex-shrink": 0, "text-align": "right" } },
210
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, r.duration_ms == null ? "—" : `${r.duration_ms}ms`),
211
- r.started_at ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "margin-top": "2px" } }, r.started_at) : null,
212
- ),
213
- ), { flat: true });
214
- }
215
-
216
- function truncate(s, n) {
217
- s = String(s);
218
- return s.length > n ? s.slice(0, n - 1) + "…" : s;
219
- }
220
- }