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,463 +0,0 @@
1
- /* ============================================================================
2
- * View: My Computer — local hardware, memory, and runtime.
3
- * Reinforces the local-first promise: every gauge, model, and byte of memory
4
- * lives on this machine. Live-reads /local/sysinfo + /models and reports
5
- * unavailable state when those endpoints are not reachable.
6
- * ========================================================================== */
7
-
8
- const GAUGES = [
9
- { key: "cpu_pct", label: "CPU", icon: "cpu", variant: "graph", sub: () => "Compute cores" },
10
- { key: "ram_pct", label: "RAM", icon: "device-desktop-analytics", variant: "vector", sub: () => "Unified memory" },
11
- { key: "gpu_mem_pct", label: "GPU (MLX)", icon: "brand-apple", variant: "hybrid", sub: (d) => `${fmtGb(d.gpu_mem_gb)} GB in use` },
12
- ];
13
-
14
- export async function render(ctx) {
15
- const { h, icon, api, c } = ctx;
16
-
17
- const state = { memoryOn: false, activities: [], memSource: "pending" };
18
-
19
- // Hydrated after the async reads land.
20
- const srcSlot = h("span", c.sourceBadge("pending"));
21
- const gaugeHost = h("div.lt3-grid-3", c.loading({ lines: 0, block: true }));
22
- const runtimeHost = h("div", c.loading({ lines: 4 }));
23
- const agentHost = h("div", c.loading({ lines: 5 }));
24
- const foldersHost = h("div", c.loading({ lines: 4 }));
25
-
26
- const root = h("div.lt3-stack-6",
27
- c.viewHeader({
28
- eyebrow: "Compute",
29
- title: "My Computer",
30
- sub: "The local hardware and MLX runtime powering this workspace. Inference and indexing run here — on Apple Silicon — never on an external server.",
31
- actions: [
32
- srcSlot,
33
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => { load(); loadAgent(); } } }, icon("refresh"), "Refresh"),
34
- ],
35
- }),
36
-
37
- c.banner("All inference and indexing happen on this computer. Nothing you index, ask, or remember is sent to external servers.", "info", "shield-lock"),
38
-
39
- h("section",
40
- c.sectionHead("Live utilization"),
41
- gaugeHost,
42
- ),
43
-
44
- // Local Agent — the on-device Lattice runtime acting as the local agent.
45
- c.panel({
46
- eyebrow: "Local agent",
47
- title: "Local agent",
48
- sub: "The local agent is the on-device Lattice runtime; no separate desktop install is required.",
49
- children: agentHost,
50
- }),
51
-
52
- // Connect Folder + Folder Watch — over the same on-device runtime.
53
- c.panel({
54
- eyebrow: "On-device",
55
- title: "Connect folder & folder watch",
56
- sub: "Index a folder on this computer and keep it in sync. Files never leave the machine.",
57
- actions: [
58
- h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => connectFolder() } }, icon("folder-plus"), "Connect folder"),
59
- ],
60
- children: foldersHost,
61
- }),
62
-
63
- h("div.lt3-grid-2",
64
- c.panel({
65
- eyebrow: "Runtime",
66
- title: "Local runtime",
67
- sub: "Where this workspace runs and where it keeps its data.",
68
- children: runtimeHost,
69
- }),
70
- buildMemoryPanel(ctx, state),
71
- ),
72
- );
73
-
74
- async function load() {
75
- gaugeHost.replaceChildren(c.loading({ lines: 0, block: true }));
76
- runtimeHost.replaceChildren(c.loading({ lines: 4 }));
77
-
78
- const [sys, models] = await Promise.all([api.sysinfo(), api.models()]);
79
-
80
- srcSlot.replaceChildren(c.sourceBadge(sys.source));
81
- gaugeHost.replaceChildren(buildGauges(ctx, sys));
82
- runtimeHost.replaceChildren(buildRuntime(ctx, sys, models));
83
- }
84
-
85
- // Hydrate the Local Agent + Connect Folder panels from the live runtime.
86
- async function loadAgent() {
87
- agentHost.replaceChildren(c.loading({ lines: 5 }));
88
- foldersHost.replaceChildren(c.loading({ lines: 4 }));
89
-
90
- const res = await api.localAgent();
91
- agentHost.replaceChildren(buildAgent(ctx, res));
92
- foldersHost.replaceChildren(buildFolders(ctx, res, { connectFolder, stopWatching }));
93
- }
94
-
95
- // stopWatching lives here so it can reach the real adapter + toast.
96
- async function stopWatching(id) {
97
- const notify = ctx.toast || c.toast;
98
- const r = await api.localWatchStop(id);
99
- if (r && r.ok) {
100
- notify("Stopped watching that folder. It remains indexed.", "info");
101
- loadAgent();
102
- return true;
103
- }
104
- const detail = (r && r.data && (r.data.detail || r.data.error)) || "the runtime is unavailable";
105
- notify(`Could not stop watching — ${detail}.`, "warn");
106
- return false;
107
- }
108
-
109
- // Prompt for a path, connect (index + watch) it, then re-hydrate.
110
- async function connectFolder() {
111
- const notify = ctx.toast || c.toast;
112
- const path = window.prompt("Connect a folder on this computer (it will be indexed and watched):", "~/Documents");
113
- if (!path || !path.trim()) return;
114
- notify(`Connecting ${path.trim()} — indexing on this computer…`, "info");
115
- const res = await api.connectFolder(path.trim(), { watch: true });
116
- if (res && res.ok) {
117
- notify(`Connected ${path.trim()}. Indexing and folder watch are active.`, "ok");
118
- loadAgent();
119
- } else {
120
- notify((res && res.error) || "Could not connect that folder.", "warn");
121
- }
122
- }
123
-
124
- // Reflect real local-memory state (enabled + recorded activity) from the backend.
125
- async function loadMemory() {
126
- const res = await api.computerMemory();
127
- const cfg = (res && res.ok && res.data) ? res.data : null;
128
- state.memSource = cfg ? "live" : "unavailable";
129
- state.memoryOn = !!(cfg && cfg.enabled);
130
- state.activities = (cfg && Array.isArray(cfg.activities)) ? cfg.activities.slice().reverse() : [];
131
- if (state._refreshMemory) state._refreshMemory();
132
- }
133
-
134
- load();
135
- loadAgent();
136
- loadMemory();
137
- return root;
138
- }
139
-
140
- /* ── Gauges ──────────────────────────────────────────────────────────────── */
141
- function buildGauges({ h, icon, c }, sys) {
142
- const data = (sys && sys.data) || {};
143
- return h("div.lt3-grid-3",
144
- GAUGES.map((g) => {
145
- const raw = Number(data[g.key]);
146
- const pct = Number.isFinite(raw) ? raw : null;
147
- return c.card(
148
- h("div.lt3-stack-3",
149
- h("div.lt3-row", { style: { "justify-content": "space-between" } },
150
- h("div.lt3-stat__label", icon(g.icon), g.label),
151
- c.statePill(pct == null ? "idle" : pct >= 90 ? "warn" : "active"),
152
- ),
153
- h("div.lt3-stat__value", { style: { "font-size": "var(--lt3-text-3xl)" } },
154
- pct == null ? "—" : `${roundPct(pct)}%`),
155
- c.meter(pct == null ? 0 : pct / 100, g.variant),
156
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, g.sub(data)),
157
- ),
158
- );
159
- }),
160
- );
161
- }
162
-
163
- /* ── Runtime key/value panel ─────────────────────────────────────────────── */
164
- function buildRuntime({ h, icon, c }, sys, models) {
165
- const md = (models && models.data) || {};
166
- const current =
167
- md.current ||
168
- (md.catalog || []).find((m) => m.state === "loaded")?.id ||
169
- null;
170
-
171
- const rows = [
172
- { k: "Platform", v: "Apple Silicon · MLX", icon: "brand-apple" },
173
- { k: "Loaded model", v: current || "No model loaded", mono: true, icon: "cpu" },
174
- { k: "Local storage", v: "~/.ltcai", mono: true, icon: "folder" },
175
- { k: "Memory model", v: "Unified memory (CPU + GPU shared)", icon: "stack-2" },
176
- { k: "Network", v: "Local-only — no external inference", icon: "wifi-off" },
177
- ];
178
-
179
- return h("div",
180
- h("dl.lt3-keyval",
181
- rows.flatMap((r) => [
182
- h("dt", h("span.lt3-row-2", icon(r.icon), r.k)),
183
- h("dd", r.mono ? h("span.lt3-mono", r.v) : r.v),
184
- ]),
185
- ),
186
- h("div.lt3-row-2", { style: { "margin-top": "var(--lt3-space-4)" } },
187
- c.sourceBadge((models && models.source) || (sys && sys.source)),
188
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Derived from local runtime"),
189
- ),
190
- );
191
- }
192
-
193
- /* ── Local agent panel (wired to /api/local-agent/status) ─────────────────── */
194
- function buildAgent({ h, icon, c }, res) {
195
- // Honesty: if the runtime isn't reachable, never imply a "ready" agent.
196
- if (!res || !res.ok || res.source === "unavailable") {
197
- return h("div.lt3-stack-3",
198
- h("div.lt3-row-2", c.sourceBadge("unavailable")),
199
- c.emptyState({
200
- icon: "plug-connected-x",
201
- title: "Local runtime not reachable",
202
- body: "The on-device Lattice runtime is not responding, so the local agent's status can't be confirmed. Start the server, then Refresh.",
203
- }),
204
- );
205
- }
206
-
207
- const d = res.data || {};
208
- const agent = d.agent || {};
209
- const handshake = d.handshake || {};
210
- const health = d.health || {};
211
- const folders = d.folders || {};
212
-
213
- const online = !!agent.online;
214
- const mode = d.mode || (online ? "online" : "offline");
215
-
216
- const rows = [
217
- { k: "Mode", v: mode, icon: "activity" },
218
- { k: "Version", v: d.version || "—", mono: true, icon: "tag" },
219
- { k: "PID", v: d.pid != null ? String(d.pid) : "—", mono: true, icon: "hash" },
220
- { k: "Platform", v: agent.platform || "—", icon: "device-desktop" },
221
- { k: "Machine", v: agent.machine || "—", mono: true, icon: "cpu" },
222
- { k: "Python", v: agent.python || "—", mono: true, icon: "code" },
223
- ];
224
-
225
- return h("div.lt3-stack-3",
226
- // Identity + live online state.
227
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center" } },
228
- h("div.lt3-row-2",
229
- icon("robot"),
230
- h("div",
231
- h("div", { style: { "font-weight": "var(--lt3-weight-semi)", "font-size": "var(--lt3-text-sm)" } },
232
- agent.name || "Lattice local agent"),
233
- agent.id && h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } },
234
- h("span.lt3-mono", agent.id)),
235
- ),
236
- ),
237
- // mode is probed by the live endpoint (online/degraded/error) — never faked.
238
- c.statePill(mode),
239
- ),
240
-
241
- h("dl.lt3-keyval",
242
- rows.flatMap((r) => [
243
- h("dt", h("span.lt3-row-2", icon(r.icon), r.k)),
244
- h("dd", r.mono ? h("span.lt3-mono", r.v) : r.v),
245
- ]),
246
- ),
247
-
248
- // Handshake + health, read straight from the runtime.
249
- h("div.lt3-stack-2", { style: { "margin-top": "var(--lt3-space-2)" } },
250
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center" } },
251
- h("span.lt3-row-2", icon("plug-connected"),
252
- handshake.ok
253
- ? `Handshake OK · ${handshake.transport || "local"}${handshake.latency_ms != null ? " · " + handshake.latency_ms + "ms" : ""}`
254
- : "Handshake not established"),
255
- c.statePill(handshake.ok ? "active" : "idle"),
256
- ),
257
- handshake.detail && h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, handshake.detail),
258
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center" } },
259
- h("span.lt3-row-2", icon("folder-search"), "Filesystem access"),
260
- c.statePill(health.filesystem_access ? "active" : "idle"),
261
- ),
262
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center" } },
263
- h("span.lt3-row-2", icon("eye"), "Watcher available"),
264
- c.statePill(health.watcher_available ? "active" : "idle"),
265
- ),
266
- ),
267
-
268
- // Folder counts as stats.
269
- h("div.lt3-grid-2", { style: { "margin-top": "var(--lt3-space-2)" } },
270
- c.stat({ label: "Folders connected", value: c.fmtNum(folders.connected ?? 0), icon: "folder" }),
271
- c.stat({ label: "Folders watching", value: c.fmtNum(folders.watching ?? 0), icon: "eye" }),
272
- ),
273
-
274
- h("div.lt3-row-2", { style: { "margin-top": "var(--lt3-space-2)" } },
275
- c.sourceBadge(res.source),
276
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } },
277
- "On-device runtime — no separate desktop install"),
278
- ),
279
- );
280
- }
281
-
282
- /* ── Connect Folder + Folder Watch panel (wired to /knowledge-graph/local) ── */
283
- function buildFolders({ h, icon, c }, res, { connectFolder, stopWatching }) {
284
- const d = (res && res.data) || {};
285
- const watch = d.watch || {};
286
- const sources = Array.isArray(d.sources) ? d.sources : [];
287
-
288
- // Runtime unreachable → honest unavailable, no fabricated folder list.
289
- if (!res || !res.ok || res.source === "unavailable") {
290
- return h("div.lt3-stack-3",
291
- h("div.lt3-row-2", c.sourceBadge("unavailable")),
292
- c.emptyState({
293
- icon: "folder-off",
294
- title: "Connected folders unavailable",
295
- body: "The on-device runtime is not reachable, so connected folders can't be listed. Start the server, then Refresh.",
296
- action: h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => connectFolder() } }, icon("folder-plus"), "Connect folder"),
297
- }),
298
- );
299
- }
300
-
301
- // Honest note when the watchdog dependency is missing.
302
- const watchNote = watch.available === false
303
- ? c.banner(
304
- `Folder watch needs the watchdog dependency${watch.error ? ` — ${watch.error}` : ""}. Folders can still be indexed once; live sync is paused until it's installed.`,
305
- "warn", "alert-triangle")
306
- : null;
307
-
308
- let body;
309
- if (!sources.length) {
310
- body = c.emptyState({
311
- icon: "folder-plus",
312
- title: "No folders connected yet",
313
- body: "Connect a folder to index its files on this computer. Indexing and content stay local.",
314
- action: h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => connectFolder() } }, icon("folder-plus"), "Connect folder"),
315
- });
316
- } else {
317
- body = h("div.lt3-list",
318
- sources.map((s) => {
319
- const watching = !!s.watch_active;
320
- const indexed = Number(s.success_count ?? s.indexed_count ?? 0) || 0;
321
- const last = s.last_event_at || s.last_indexed_at;
322
- const metaParts = [`${c.fmtNum(indexed)} indexed`];
323
- if (last) metaParts.push(`last ${last}`);
324
- return h("div.lt3-list__item",
325
- icon(watching ? "folder-search" : "folder"),
326
- h("div.lt3-list__body",
327
- h("div.lt3-list__title", h("span.lt3-mono", s.root_path || s.path || s.id || "—")),
328
- h("div.lt3-list__meta", metaParts.join(" · ")),
329
- ),
330
- h("div.lt3-row-2", { style: { "align-items": "center" } },
331
- c.statePill(watching ? "watching" : "idle"),
332
- watching && s.id && h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", {
333
- on: {
334
- click: async (e) => {
335
- const btn = e.currentTarget;
336
- btn.disabled = true;
337
- const ok = await stopWatching(s.id);
338
- if (!ok) btn.disabled = false;
339
- },
340
- },
341
- }, icon("player-stop"), "Stop watching"),
342
- ),
343
- );
344
- }),
345
- );
346
- }
347
-
348
- return h("div.lt3-stack-3",
349
- watchNote,
350
- body,
351
- h("div.lt3-row-2", { style: { "margin-top": "var(--lt3-space-2)" } },
352
- c.sourceBadge(res.source),
353
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Indexed and watched on this computer"),
354
- ),
355
- );
356
- }
357
-
358
- /* ── Local memory panel (wired to /workspace/computer-memory) ─────────────── */
359
- function buildMemoryPanel(ctx, state) {
360
- const { h, icon, c } = ctx;
361
- const notify = ctx.toast || c.toast;
362
-
363
- const activityHost = h("div", renderActivity(ctx, state));
364
- const input = h("input", {
365
- type: "checkbox",
366
- "aria-label": "Enable local computer memory",
367
- checked: state.memoryOn,
368
- on: {
369
- change: async (e) => {
370
- const want = e.target.checked;
371
- input.disabled = true;
372
- const res = await ctx.api.setComputerMemory(want);
373
- input.disabled = false;
374
- if (res && res.ok) {
375
- state.memoryOn = want;
376
- state.memSource = "live";
377
- const cfg = res.data || {};
378
- state.activities = Array.isArray(cfg.activities) ? cfg.activities.slice().reverse() : state.activities;
379
- refresh();
380
- notify(
381
- want
382
- ? "Local memory enabled — context persists on this computer (~/.ltcai)."
383
- : "Local memory disabled. Nothing will be persisted on this computer.",
384
- want ? "ok" : "info",
385
- );
386
- } else {
387
- // Revert the toggle; report the real reason (e.g. 403 consent, no backend).
388
- e.target.checked = state.memoryOn;
389
- const detail = (res && res.data && (res.data.detail || res.data.error)) || "the runtime is unavailable";
390
- notify(`Could not change local memory — ${detail}.`, "warn");
391
- }
392
- },
393
- },
394
- });
395
-
396
- // Built from the frozen .lt3-switch markup (input + span); no shared file touched.
397
- const sw = h("label.lt3-switch", { title: "Enable local computer memory" }, input, h("span"));
398
-
399
- function refresh() {
400
- input.checked = state.memoryOn;
401
- activityHost.replaceChildren(renderActivity(ctx, state));
402
- }
403
- state._refreshMemory = refresh;
404
-
405
- return c.panel({
406
- eyebrow: "On-device",
407
- title: "Local memory",
408
- sub: "Let the assistant remember context across sessions — stored only on this computer, never uploaded.",
409
- children: h("div.lt3-stack-4",
410
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
411
- h("div.lt3-stack-2", { style: { "max-width": "40ch" } },
412
- h("div", { style: { "font-weight": "var(--lt3-weight-semi)", "font-size": "var(--lt3-text-sm)" } },
413
- "Enable local computer memory"),
414
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } },
415
- "Persists to ~/.ltcai. Off by default."),
416
- ),
417
- sw,
418
- ),
419
- h("div",
420
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", "margin-bottom": "var(--lt3-space-2)" } },
421
- h("div.lt3-eyebrow", "Recent local activity"),
422
- h("span", { "data-mem-src": "1" }, c.sourceBadge(state.memSource)),
423
- ),
424
- activityHost,
425
- ),
426
- ),
427
- });
428
- }
429
-
430
- function renderActivity({ h, icon, c }, state) {
431
- if (!state.memoryOn) {
432
- return c.emptyState({
433
- icon: "database-off",
434
- title: "Memory is off",
435
- body: "Enable local memory to let the assistant retain context on this computer.",
436
- });
437
- }
438
- const items = Array.isArray(state.activities) ? state.activities : [];
439
- if (!items.length) {
440
- return c.emptyState({
441
- icon: "history-off",
442
- title: "No activity recorded yet",
443
- body: "Once memory is on, on-device actions the assistant takes will be logged here.",
444
- });
445
- }
446
- return h("div.lt3-list",
447
- items.slice(0, 8).map((a) => h("div.lt3-list__item",
448
- icon(a.icon || "activity"),
449
- h("div.lt3-list__body",
450
- h("div.lt3-list__title", a.title || a.action || a.kind || "Activity"),
451
- h("div.lt3-list__meta", a.meta || a.detail || a.timestamp || ""),
452
- ),
453
- c.statePill(a.state || "ok"),
454
- )),
455
- );
456
- }
457
-
458
- /* ── helpers ─────────────────────────────────────────────────────────────── */
459
- function roundPct(n) { return Math.round(Number(n) * 10) / 10; }
460
- function fmtGb(n) {
461
- const v = Number(n);
462
- return Number.isFinite(v) ? (Math.round(v * 10) / 10).toString() : "—";
463
- }