ltcai 3.4.1 → 3.6.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 (60) hide show
  1. package/README.md +206 -247
  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.5.0.md +56 -0
  6. package/docs/RUNTIME_HOOK_COVERAGE_v3.6.0.md +49 -0
  7. package/docs/architecture.md +13 -12
  8. package/docs/kg-schema.md +55 -0
  9. package/docs/privacy.md +18 -2
  10. package/docs/security-model.md +17 -0
  11. package/kg_schema.py +46 -0
  12. package/knowledge_graph.py +520 -1
  13. package/latticeai/__init__.py +1 -1
  14. package/latticeai/api/auth.py +37 -9
  15. package/latticeai/api/browser.py +217 -0
  16. package/latticeai/api/chat.py +4 -1
  17. package/latticeai/api/computer_use.py +21 -8
  18. package/latticeai/api/portability.py +93 -0
  19. package/latticeai/api/tools.py +29 -26
  20. package/latticeai/core/config.py +3 -0
  21. package/latticeai/core/marketplace.py +1 -1
  22. package/latticeai/core/multi_agent.py +1 -1
  23. package/latticeai/core/oidc.py +205 -0
  24. package/latticeai/core/security.py +59 -5
  25. package/latticeai/core/workspace_os.py +1 -1
  26. package/latticeai/server_app.py +39 -0
  27. package/latticeai/services/ingestion.py +271 -0
  28. package/latticeai/services/kg_portability.py +177 -0
  29. package/package.json +5 -4
  30. package/requirements.txt +1 -0
  31. package/scripts/build_vsix.mjs +72 -0
  32. package/scripts/check_python.py +87 -0
  33. package/static/css/reference/account.css +1 -1
  34. package/static/css/reference/admin.css +1 -1
  35. package/static/css/reference/base.css +8 -5
  36. package/static/css/reference/chat.css +8 -8
  37. package/static/css/reference/graph.css +2 -2
  38. package/static/css/responsive.css +2 -2
  39. package/static/v3/asset-manifest.json +9 -9
  40. package/static/v3/css/{lattice.shell.6ceea7c8.css → lattice.shell.8fcc9d33.css} +2 -1
  41. package/static/v3/css/lattice.shell.css +2 -1
  42. package/static/v3/js/{app.d086489d.js → app.c541f955.js} +1 -1
  43. package/static/v3/js/core/{api.12b568ad.js → api.33d6320e.js} +38 -0
  44. package/static/v3/js/core/api.js +38 -0
  45. package/static/v3/js/core/{routes.d214b399.js → routes.2ce3815a.js} +1 -1
  46. package/static/v3/js/core/routes.js +1 -1
  47. package/static/v3/js/core/{shell.d05266f5.js → shell.8c163e0e.js} +2 -2
  48. package/static/v3/js/views/knowledge-graph.a96040a5.js +513 -0
  49. package/static/v3/js/views/knowledge-graph.js +293 -17
  50. package/static/workspace.css +1 -1
  51. package/tools/__init__.py +276 -0
  52. package/tools/commands.py +188 -0
  53. package/tools/computer.py +185 -0
  54. package/tools/documents.py +243 -0
  55. package/tools/filesystem.py +560 -0
  56. package/tools/knowledge.py +97 -0
  57. package/tools/local_files.py +69 -0
  58. package/tools/network.py +66 -0
  59. package/static/v3/js/views/knowledge-graph.a14ea7e7.js +0 -237
  60. package/tools.py +0 -1525
@@ -1,7 +1,10 @@
1
1
  /* ============================================================================
2
- * View: Knowledge Graph — entity/relation explorer.
3
- * Renders the graph as an SVG mesh against /api/graph with a live inspector.
4
- * Missing graph data renders an empty unavailable state.
2
+ * View: Knowledge Graph — the user's digital brain (v3.6.0 Knowledge Graph First).
3
+ * Tabs: Explore (entity/relation mesh) · Status (graph + ingestion health) ·
4
+ * Sources (where every node came from) · Capture (web/URL into the graph) ·
5
+ * Backup (local export / import / backup). Everything you ingest converges here;
6
+ * models read this graph; local-first keeps it yours. Missing data renders an
7
+ * honest unavailable state — never fabricated counters.
5
8
  * ========================================================================== */
6
9
 
7
10
  import { escapeHtml } from "../core/dom.js";
@@ -12,6 +15,8 @@ const TYPE_COLOR = {
12
15
  Method: "var(--lt3-pillar-hybrid)",
13
16
  Model: "var(--accent-3)",
14
17
  File: "var(--faint)",
18
+ Source: "var(--lt3-pillar-hybrid)",
19
+ Document: "var(--accent)",
15
20
  Decision: "var(--accent-3)",
16
21
  Task: "var(--accent-2)",
17
22
  Person: "var(--accent-pink)",
@@ -19,27 +24,84 @@ const TYPE_COLOR = {
19
24
  };
20
25
  const colorFor = (t) => TYPE_COLOR[t] || TYPE_COLOR.default;
21
26
 
27
+ const TABS = [
28
+ { key: "explore", label: "Explore", icon: "chart-dots-3" },
29
+ { key: "status", label: "Status", icon: "activity-heartbeat" },
30
+ { key: "sources", label: "Sources", icon: "database" },
31
+ { key: "capture", label: "Capture", icon: "world-www" },
32
+ { key: "portability", label: "Backup", icon: "archive" },
33
+ ];
34
+
22
35
  export async function render(ctx) {
23
- const { h, icon, api, store, c } = ctx;
36
+ const { h, icon, api, c } = ctx;
37
+ let active = "explore";
24
38
 
25
- const state = { selected: null, query: "", data: { nodes: [], edges: [] }, source: "pending" };
39
+ const tabBar = h("div.lt3-row-2");
40
+ const panelHost = h("div.lt3-stack-4");
26
41
 
27
- const canvasHost = h("div", c.loading({ lines: 0, block: true }));
28
- const inspectorHost = h("div", c.loading({ lines: 4 }));
29
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
30
- const srcSlot = h("span", c.sourceBadge("pending"));
42
+ function renderTabs() {
43
+ tabBar.replaceChildren(...TABS.map((t) =>
44
+ h("button.lt3-btn" + (t.key === active ? ".lt3-btn--primary" : ".lt3-btn--ghost"),
45
+ { on: { click: () => switchTab(t.key) } }, icon(t.icon), t.label)));
46
+ }
47
+
48
+ function switchTab(key) {
49
+ if (active === key) return;
50
+ active = key;
51
+ renderTabs();
52
+ renderActive();
53
+ }
54
+
55
+ let exploreNode = null;
56
+ function renderActive() {
57
+ if (active === "explore") {
58
+ if (!exploreNode) exploreNode = buildExplore(ctx);
59
+ panelHost.replaceChildren(exploreNode);
60
+ } else if (active === "status") {
61
+ renderStatus(ctx, panelHost);
62
+ } else if (active === "sources") {
63
+ renderSources(ctx, panelHost);
64
+ } else if (active === "capture") {
65
+ panelHost.replaceChildren(buildCapture(ctx));
66
+ } else if (active === "portability") {
67
+ renderPortability(ctx, panelHost);
68
+ }
69
+ }
31
70
 
32
71
  const root = h("div.lt3-stack-6",
33
72
  c.viewHeader({
34
- eyebrow: "Retrieval · structure",
73
+ eyebrow: "Your digital brain",
35
74
  title: "Knowledge Graph",
36
- sub: "Entities and the relations the workspace extracted between them. Click a node to trace its neighborhood.",
75
+ sub: "Everything you ingest converges here files, folders, web pages, browser tabs. Models read this graph; local-first keeps it yours.",
37
76
  actions: [
38
- srcSlot,
39
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
77
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => ctx.navigate("files") } }, icon("upload"), "Add sources"),
40
78
  h("button.lt3-btn.lt3-btn--primary", { on: { click: () => ctx.navigate("hybrid-search") } }, icon("arrows-join"), "Search graph"),
41
79
  ],
42
80
  }),
81
+ tabBar,
82
+ panelHost,
83
+ );
84
+
85
+ renderTabs();
86
+ renderActive();
87
+ return root;
88
+ }
89
+
90
+ /* ── Explore tab (entity/relation mesh) ─────────────────────────────────── */
91
+ function buildExplore(ctx) {
92
+ const { h, icon, api, c } = ctx;
93
+ const state = { selected: null, query: "", data: { nodes: [], edges: [] }, source: "pending" };
94
+
95
+ const canvasHost = h("div", c.loading({ lines: 0, block: true }));
96
+ const inspectorHost = h("div", c.loading({ lines: 4 }));
97
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
98
+ const srcSlot = h("span", c.sourceBadge("pending"));
99
+
100
+ const root = h("div.lt3-stack-3",
101
+ h("div.lt3-row-2",
102
+ srcSlot,
103
+ h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
104
+ ),
43
105
  statHost,
44
106
  h("div.lt3-split",
45
107
  h("div.lt3-stack-3",
@@ -69,7 +131,7 @@ export async function render(ctx) {
69
131
  renderInspector();
70
132
  }
71
133
 
72
- function renderStats(stats, graphData) {
134
+ function renderStats(stats) {
73
135
  const nodes = state.data.nodes.length;
74
136
  const edges = state.data.edges.length;
75
137
  const types = stats && stats.nodes ? Object.keys(stats.nodes).length : new Set(state.data.nodes.map((n) => n.type)).size;
@@ -185,7 +247,221 @@ export async function render(ctx) {
185
247
  return root;
186
248
  }
187
249
 
250
+ /* ── Status tab (graph + ingestion health) ──────────────────────────────── */
251
+ async function renderStatus(ctx, host) {
252
+ const { h, icon, api, c } = ctx;
253
+ host.replaceChildren(c.loading({ lines: 3 }));
254
+ const [port, gs, idx] = await Promise.all([api.kgPortability(), api.graphStats(), api.indexStatus()]);
255
+ const p = port.data || {};
256
+ const prov = p.provenance || {};
257
+ const nodes = sumCounts((gs.data && gs.data.nodes) || {});
258
+ const edges = sumCounts((gs.data && gs.data.edges) || {});
259
+ const pipelines = (idx.data && idx.data.pipelines) || {};
260
+
261
+ host.replaceChildren(
262
+ h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } },
263
+ p.graph_schema_version != null ? `Schema v${p.graph_schema_version} · embed dim ${p.embed_dim ?? "—"}` : "Knowledge Graph status")),
264
+ h("div.lt3-statrow",
265
+ c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
266
+ c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
267
+ c.stat({ label: "Ingested items", value: c.fmtNum(prov.total || 0), icon: "package-import" }),
268
+ c.stat({ label: "Embedded (RAG-ready)", value: c.fmtNum(prov.embedded || 0), icon: "vector" }),
269
+ ),
270
+ c.card(
271
+ h("div.lt3-stack-3",
272
+ h("div.lt3-eyebrow", "Pipelines"),
273
+ pipelineRow(ctx, "Knowledge graph", pipelines.knowledge_graph),
274
+ pipelineRow(ctx, "Vector index", pipelines.vector_index),
275
+ pipelineRow(ctx, "Hybrid retrieval", pipelines.hybrid),
276
+ ),
277
+ ),
278
+ prov.last_ingested_at
279
+ ? h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, `Last ingestion: ${fmtWhen(prov.last_ingested_at)} · ${prov.duplicates || 0} duplicate(s) linked, not re-stored.`)
280
+ : c.emptyState({ icon: "package-import", title: "Nothing ingested yet", body: "Add files or capture a page to populate the graph." }),
281
+ );
282
+ }
283
+
284
+ function pipelineRow(ctx, label, pipe) {
285
+ const { h, c } = ctx;
286
+ const stateStr = (pipe && pipe.state) || "unavailable";
287
+ const detail = pipe && (pipe.entities != null ? `${pipe.entities} entities` : pipe.vectors != null ? `${pipe.vectors} vectors` : pipe.strategy || "");
288
+ return h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
289
+ h("div", label, detail ? h("span.lt3-muted", { style: { "margin-left": "var(--lt3-space-2)", "font-size": "var(--lt3-text-sm)" } }, detail) : null),
290
+ c.statePill(stateStr),
291
+ );
292
+ }
293
+
294
+ /* ── Sources tab (provenance: where every node came from) ────────────────── */
295
+ async function renderSources(ctx, host) {
296
+ const { h, icon, api, c } = ctx;
297
+ host.replaceChildren(c.loading({ lines: 3 }));
298
+ const [port, recent] = await Promise.all([api.kgPortability(), api.kgProvenance(40)]);
299
+ const bySource = (port.data && port.data.provenance && port.data.provenance.by_source_type) || {};
300
+ const items = (recent.data && recent.data.items) || [];
301
+
302
+ const sourceCards = Object.keys(bySource).length
303
+ ? h("div.lt3-statrow", Object.entries(bySource).map(([k, v]) =>
304
+ c.stat({ label: prettySource(k), value: c.fmtNum(v), icon: iconForSource(k) })))
305
+ : c.emptyState({ icon: "database", title: "No sources yet", body: "Connect a folder, upload a file, or capture a page." });
306
+
307
+ const recentList = items.length
308
+ ? h("div.lt3-stack-2", items.map((it) =>
309
+ h("div.lt3-entity",
310
+ h("div.lt3-entity__type", { style: { background: "var(--surface-3)", color: colorFor("Source") } }, icon(iconForSource(it.source_type))),
311
+ h("div.lt3-entity__body",
312
+ h("div.lt3-entity__name", it.title || it.source_uri || it.node_id),
313
+ h("div.lt3-entity__meta", `${prettySource(it.source_type)} · ${fmtWhen(it.created_at)}${it.embedded ? " · embedded" : ""}${it.duplicate ? " · duplicate" : ""}`),
314
+ ),
315
+ )))
316
+ : c.emptyState({ icon: "history", title: "No recent ingestions", body: "Ingested items will appear here with full provenance." });
317
+
318
+ host.replaceChildren(
319
+ h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Every node records where it came from (provenance).")),
320
+ sourceCards,
321
+ c.card(h("div.lt3-stack-3", h("div.lt3-eyebrow", "Recent ingestions"), recentList)),
322
+ );
323
+ }
324
+
325
+ /* ── Capture tab (web/URL into the graph) ───────────────────────────────── */
326
+ function buildCapture(ctx) {
327
+ const { h, icon, api, c } = ctx;
328
+ const input = h("input", { type: "url", placeholder: "https://example.com/article", "aria-label": "URL to capture",
329
+ style: { flex: "1" } });
330
+ const result = h("div");
331
+
332
+ async function run() {
333
+ const url = (input.value || "").trim();
334
+ if (!url) { result.replaceChildren(c.banner({ tone: "warn", text: "Enter a URL first." })); return; }
335
+ result.replaceChildren(c.loading({ lines: 1 }));
336
+ const res = await api.browserReadUrl(url);
337
+ const d = res.data || {};
338
+ if (res.ok && d.status === "ok") {
339
+ result.replaceChildren(c.banner({ tone: "ok", text: `Added to your Knowledge Graph${d.duplicate ? " (already present — linked)" : ""}. ${d.chunk_count || 0} chunk(s) indexed.` }));
340
+ ctx.toast && ctx.toast("Page added to Knowledge Graph");
341
+ } else if (d.status === "empty") {
342
+ result.replaceChildren(c.banner({ tone: "warn", text: "No readable text was found on that page." }));
343
+ } else {
344
+ const detail = d.detail || (res.status === 422 ? "The page is blocked or login-required." : "Could not read that URL.");
345
+ result.replaceChildren(c.banner({ tone: "err", text: detail }));
346
+ }
347
+ }
348
+
349
+ return h("div.lt3-stack-4",
350
+ c.card(h("div.lt3-stack-3",
351
+ h("div.lt3-eyebrow", "Capture a web page"),
352
+ h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "The local runtime fetches the page, extracts readable text, and indexes it into your graph as a web source. Nothing is sent to a cloud service."),
353
+ h("div.lt3-row-2",
354
+ input,
355
+ h("button.lt3-btn.lt3-btn--primary", { on: { click: run } }, icon("world-download"), "Read into graph"),
356
+ ),
357
+ result,
358
+ )),
359
+ c.card(h("div.lt3-stack-2",
360
+ h("div.lt3-eyebrow", "Browser extension"),
361
+ h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Install the local Manifest V3 extension (browser-extension/) to send the current tab to your Knowledge Graph with one click. It posts only to 127.0.0.1 — never to a cloud server."),
362
+ )),
363
+ );
364
+ }
365
+
366
+ /* ── Portability tab (export / import / backup) ─────────────────────────── */
367
+ async function renderPortability(ctx, host) {
368
+ const { h, icon, api, c } = ctx;
369
+ host.replaceChildren(c.loading({ lines: 2 }));
370
+ const port = await api.kgPortability();
371
+ const status = h("div");
372
+
373
+ function note(tone, text) { status.replaceChildren(c.banner({ tone, text })); }
374
+
375
+ async function doExport() {
376
+ note("info", "Exporting…");
377
+ const res = await api.graphExport();
378
+ if (!res.ok || !res.data || res.data.raw) { note("err", "Export is unavailable."); return; }
379
+ try {
380
+ const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
381
+ const url = URL.createObjectURL(blob);
382
+ const a = document.createElement("a");
383
+ a.href = url; a.download = "lattice-kg-export.json"; a.click();
384
+ URL.revokeObjectURL(url);
385
+ note("ok", `Exported ${(res.data.counts && res.data.counts.nodes) || 0} nodes. Download started.`);
386
+ } catch (e) { note("err", "Could not build the download."); }
387
+ }
388
+
389
+ async function doBackup() {
390
+ note("info", "Backing up…");
391
+ const res = await api.graphBackup();
392
+ if (res.ok && res.data && res.data.path) {
393
+ note("ok", `Backup written locally: ${res.data.path}`);
394
+ } else {
395
+ note("err", (res.data && (res.data.detail || res.data.error)) || "Backup requires admin and a running runtime.");
396
+ }
397
+ }
398
+
399
+ const importArea = h("textarea", { rows: 5, placeholder: "Paste a Knowledge Graph export (JSON) to validate, then import…",
400
+ "aria-label": "Import artifact", style: { width: "100%", "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } });
401
+
402
+ async function doImport(dryRun) {
403
+ let artifact;
404
+ try { artifact = JSON.parse(importArea.value || ""); }
405
+ catch { note("err", "That is not valid JSON."); return; }
406
+ note("info", dryRun ? "Validating…" : "Importing…");
407
+ const res = await api.graphImport(artifact, "merge", dryRun);
408
+ if (res.ok && res.data && !res.data.detail) {
409
+ const d = res.data;
410
+ note("ok", dryRun
411
+ ? `Valid — would import ${d.nodes || 0} nodes, ${d.edges || 0} edges.`
412
+ : `Imported ${d.nodes || 0} nodes, ${d.edges || 0} edges.`);
413
+ } else {
414
+ note("err", (res.data && (res.data.detail || res.data.error)) || "Import requires admin.");
415
+ }
416
+ }
417
+
418
+ const p = port.data || {};
419
+ host.replaceChildren(
420
+ h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "The Knowledge Graph is your durable asset — portable with no cloud.")),
421
+ c.card(h("div.lt3-stack-3",
422
+ h("div.lt3-eyebrow", "Export & backup"),
423
+ h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Export a portable JSON of nodes/edges/provenance, or write a full local binary backup (DB + blobs)."),
424
+ h("div.lt3-row-2",
425
+ h("button.lt3-btn.lt3-btn--primary", { on: { click: doExport } }, icon("download"), "Export JSON"),
426
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: doBackup } }, icon("archive"), "Backup (admin)"),
427
+ ),
428
+ )),
429
+ c.card(h("div.lt3-stack-3",
430
+ h("div.lt3-eyebrow", "Import"),
431
+ importArea,
432
+ h("div.lt3-row-2",
433
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => doImport(true) } }, icon("checks"), "Validate (dry-run)"),
434
+ h("button.lt3-btn.lt3-btn--primary", { on: { click: () => doImport(false) } }, icon("file-import"), "Import (merge, admin)"),
435
+ ),
436
+ )),
437
+ status,
438
+ );
439
+ }
440
+
188
441
  /* ── helpers ─────────────────────────────────────────────────────────────── */
442
+ function sumCounts(obj) {
443
+ return Object.values(obj || {}).reduce((a, b) => a + (Number(b) || 0), 0);
444
+ }
445
+
446
+ function prettySource(k) {
447
+ return ({ web_url: "Web URL", browser_tab: "Browser tab", file: "Files", local_file: "Local files",
448
+ note: "Notes", text: "Text", markdown: "Markdown", code: "Code", upload: "Uploads" })[k] || k;
449
+ }
450
+
451
+ function iconForSource(k) {
452
+ return ({ web_url: "world", browser_tab: "browser", file: "file", local_file: "folder",
453
+ note: "note", text: "text-caption", markdown: "markdown", code: "code", upload: "upload" })[k] || "database";
454
+ }
455
+
456
+ function fmtWhen(iso) {
457
+ if (!iso) return "—";
458
+ try {
459
+ const d = new Date(iso);
460
+ if (isNaN(d.getTime())) return String(iso);
461
+ return d.toLocaleString();
462
+ } catch { return String(iso); }
463
+ }
464
+
189
465
  function normalize(data) {
190
466
  const nodes = (data.nodes || []).map((n) => ({
191
467
  id: n.id,
@@ -208,7 +484,6 @@ function layout(nodes) {
208
484
  if (hasCoords) {
209
485
  return nodes.map((n) => ({ ...n, px: Math.round(60 + n.x * (W - 120)), py: Math.round(50 + n.y * (H - 100)) }));
210
486
  }
211
- // Sunflower (Vogel) spread — even spacing, highest-weight entity centered.
212
487
  const order = nodes.map((n, i) => ({ n, i })).sort((a, b) => (b.n.weight || 0) - (a.n.weight || 0));
213
488
  const maxR = Math.min(W, H) * 0.42;
214
489
  const placed = {};
@@ -226,11 +501,12 @@ function layout(nodes) {
226
501
  function truncate(s, n) { s = String(s || ""); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
227
502
 
228
503
  function iconForType(t) {
229
- return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file", Decision: "gavel", Task: "checkbox", Person: "user" })[t] || "point";
504
+ return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file", Source: "world",
505
+ Document: "file-text", Decision: "gavel", Task: "checkbox", Person: "user" })[t] || "point";
230
506
  }
231
507
 
232
508
  function buildLegend({ h }) {
233
- const types = ["Topic", "Concept", "Method", "Model", "File"];
509
+ const types = ["Source", "Document", "Concept", "Person", "Decision"];
234
510
  return h("div.lt3-graph-legend",
235
511
  types.map((t) => h("span", h("i", { style: { background: colorFor(t) } }), t)),
236
512
  );
@@ -873,7 +873,7 @@ main {
873
873
  padding: 16px clamp(16px, 2vw, 28px);
874
874
  background: color-mix(in srgb, var(--surface-elevated) 94%, transparent);
875
875
  border-bottom: 1px solid var(--line);
876
- backdrop-filter: blur(18px);
876
+ backdrop-filter: none; /* glass removed v3.5.0 */
877
877
  }
878
878
 
879
879
  .topbar-subtitle {
@@ -0,0 +1,276 @@
1
+ """Safe local tools for Lattice AI agent mode.
2
+
3
+ All filesystem operations are confined to LATTICEAI_AGENT_ROOT, defaulting to
4
+ ./agent_workspace. Command execution runs without a shell and from inside that
5
+ workspace.
6
+
7
+ v3.5.0 splits the historical flat ``tools.py`` into focused submodules
8
+ (computer, filesystem, documents, local_files, knowledge, network, commands)
9
+ while keeping the exact import surface: this package re-exports every public name
10
+ and ``execute_tool``/``DEFAULT_TOOL_REGISTRY``, so ``import tools`` and
11
+ ``from tools import X`` behave identically to before. ``AGENT_ROOT`` and the path
12
+ helpers live here as the single source of truth (tests monkeypatch
13
+ ``tools.AGENT_ROOT``); submodules read it dynamically.
14
+ """
15
+
16
+ import base64
17
+ import json
18
+ import os
19
+ import platform
20
+ import re
21
+ import shlex
22
+ import socket
23
+ import subprocess
24
+ import tempfile
25
+ from html.parser import HTMLParser
26
+ from pathlib import Path
27
+ from typing import Any, Callable, Dict, List, Optional
28
+
29
+ from latticeai.core.tool_registry import ToolRegistry
30
+ from p_reinforce import BRAIN_DIR, STRUCTURE
31
+
32
+ _PLATFORM = platform.system() # "Darwin" | "Windows" | "Linux"
33
+
34
+
35
+ # ── base: agent-root sandbox, shared constants, path helpers ──────────────────
36
+ AGENT_ROOT = Path(os.getenv("LATTICEAI_AGENT_ROOT") or "agent_workspace").resolve()
37
+ MAX_FILE_BYTES = 512_000
38
+ MAX_COMMAND_SECONDS = 30
39
+ MAX_BUILD_SECONDS = 180
40
+ MAX_DEPLOY_SECONDS = 300
41
+ MAX_COMMAND_OUTPUT = 12_000
42
+
43
+ BLOCKED_COMMANDS = {
44
+ "rm",
45
+ "rmdir",
46
+ "sudo",
47
+ "su",
48
+ "chmod",
49
+ "chown",
50
+ "curl",
51
+ "wget",
52
+ "ssh",
53
+ "scp",
54
+ "rsync",
55
+ "dd",
56
+ "mkfs",
57
+ "diskutil",
58
+ "launchctl",
59
+ }
60
+
61
+ ALLOWED_COMMANDS = {
62
+ "pwd",
63
+ "ls",
64
+ "find",
65
+ "cat",
66
+ "sed",
67
+ "head",
68
+ "tail",
69
+ "wc",
70
+ "rg",
71
+ "python",
72
+ "python3",
73
+ "node",
74
+ "npm",
75
+ "npx",
76
+ "git",
77
+ }
78
+
79
+ BUILD_SCRIPT_NAMES = {"build", "compile", "typecheck", "test"}
80
+ DEPLOY_SCRIPT_NAMES = {
81
+ "deploy",
82
+ "preview",
83
+ "release",
84
+ "package",
85
+ "dist",
86
+ "make",
87
+ "build:installer",
88
+ "build:pkg",
89
+ "build:exe",
90
+ "package:mac",
91
+ "package:win",
92
+ }
93
+
94
+ ALLOWED_GIT_SUBCOMMANDS = {"status", "diff", "log", "show"}
95
+
96
+ TEXT_EXTENSIONS = {
97
+ ".css",
98
+ ".csv",
99
+ ".html",
100
+ ".js",
101
+ ".json",
102
+ ".jsx",
103
+ ".md",
104
+ ".py",
105
+ ".ts",
106
+ ".tsx",
107
+ ".txt",
108
+ ".xml",
109
+ ".yaml",
110
+ ".yml",
111
+ }
112
+
113
+ DOCUMENT_OUTPUT_DIR = "generated_documents"
114
+ PRESENTATION_OUTPUT_DIR = "generated_presentations"
115
+ SPREADSHEET_OUTPUT_DIR = "generated_spreadsheets"
116
+
117
+
118
+ class ToolError(ValueError):
119
+ pass
120
+
121
+
122
+ def ensure_agent_root() -> Path:
123
+ AGENT_ROOT.mkdir(parents=True, exist_ok=True)
124
+ return AGENT_ROOT
125
+
126
+
127
+ def _resolve_path(path: str = "") -> Path:
128
+ ensure_agent_root()
129
+ if not path:
130
+ return AGENT_ROOT
131
+ candidate = (AGENT_ROOT / path).resolve()
132
+ if candidate != AGENT_ROOT and AGENT_ROOT not in candidate.parents:
133
+ raise ToolError("Path escapes the agent workspace.")
134
+ return candidate
135
+
136
+
137
+ def _relative(path: Path) -> str:
138
+ return str(path.relative_to(AGENT_ROOT))
139
+
140
+
141
+ # ── document / local / read constants (shared by submodules) ──────────────────
142
+ PDF_OUTPUT_DIR = "generated_pdfs"
143
+ LOCAL_MAX_FILE_BYTES = 2_000_000 # 2 MB cap for local reads
144
+
145
+
146
+ # CJK-capable fonts (Korean + Chinese + Japanese)
147
+ _CJK_FONT_CANDIDATES = [
148
+ "/System/Library/Fonts/AppleSDGothicNeo.ttc", # Korean (macOS)
149
+ "/System/Library/Fonts/STHeiti Light.ttc", # Chinese (macOS)
150
+ "/System/Library/Fonts/PingFang.ttc", # Chinese (macOS)
151
+ "/Library/Fonts/NanumGothic.ttf", # Korean
152
+ "/usr/share/fonts/truetype/nanum/NanumGothic.ttf",
153
+ ]
154
+
155
+ _SUPPORTED_READ_EXTENSIONS = {".pdf", ".docx", ".xlsx", ".pptx", ".txt", ".md", ".csv"}
156
+ DOCUMENT_MAX_READ_BYTES = 10_000_000 # 10 MB
157
+
158
+
159
+ # ── focused tool submodules (re-exported flat for import compatibility) ───────
160
+ from tools.computer import * # noqa: E402,F401,F403
161
+ from tools.filesystem import * # noqa: E402,F401,F403
162
+ from tools.documents import * # noqa: E402,F401,F403
163
+ from tools.local_files import * # noqa: E402,F401,F403
164
+ from tools.knowledge import * # noqa: E402,F401,F403
165
+ from tools.network import * # noqa: E402,F401,F403
166
+ from tools.commands import * # noqa: E402,F401,F403
167
+
168
+
169
+ # ── tool registry: the single name → invocation source of truth ───────────────
170
+ def _h_create_xlsx(args: Dict[str, Any]) -> Dict[str, Any]:
171
+ rows = args.get("rows", [])
172
+ if isinstance(rows, str):
173
+ rows = json.loads(rows)
174
+ return create_xlsx(rows, args.get("filename", "spreadsheet.xlsx"), args.get("sheet_name", "Sheet1"))
175
+
176
+
177
+ def _h_create_pptx(args: Dict[str, Any]) -> Dict[str, Any]:
178
+ slides = args.get("slides", [])
179
+ if isinstance(slides, str):
180
+ slides = json.loads(slides)
181
+ return create_pptx(args.get("title", ""), slides, args.get("filename", "presentation.pptx"))
182
+
183
+
184
+ # ── Tool registry: the single source of truth for name → invocation ───────────
185
+ # Each entry binds the args dict to a tool function. ``execute_tool`` is a
186
+ # lookup over this table — adding a tool means adding one entry here, not
187
+ # editing an if/elif chain. server.py's governance map and catalog brief are
188
+ # checked against ``registered_tools()`` so the three never silently drift.
189
+ TOOL_HANDLERS: Dict[str, Callable[[Dict[str, Any]], Dict[str, Any]]] = {
190
+ # filesystem
191
+ "list_dir": lambda a: list_dir(a.get("path", ".")),
192
+ "workspace_tree": lambda a: workspace_tree(a.get("path", "."), a.get("max_depth", 3)),
193
+ "read_file": lambda a: read_file(a["path"], offset=a.get("offset", 0), limit=a.get("limit", 0), line_numbers=a.get("line_numbers", True)),
194
+ "write_file": lambda a: write_file(a["path"], a.get("content", "")),
195
+ "edit_file": lambda a: edit_file(a["path"], a["old_string"], a["new_string"], replace_all=bool(a.get("replace_all", False))),
196
+ "grep": lambda a: grep(a["pattern"], path=a.get("path", "."), glob=a.get("glob"), max_results=a.get("max_results", 50), case_insensitive=bool(a.get("case_insensitive", False)), context_lines=a.get("context_lines", 0)),
197
+ "search_files": lambda a: search_files(a["query"], a.get("path", "."), a.get("max_results", 20)),
198
+ "inspect_html": lambda a: inspect_html(a["path"]),
199
+ "preview_url": lambda a: preview_url(a.get("path", "index.html")),
200
+ # planning
201
+ "todo_read": lambda a: todo_read(),
202
+ "todo_write": lambda a: todo_write(a.get("todos") or []),
203
+ # documents
204
+ "create_docx": lambda a: create_docx(a.get("title", ""), a.get("body", ""), a.get("filename", "document.docx")),
205
+ "create_xlsx": _h_create_xlsx,
206
+ "create_pptx": _h_create_pptx,
207
+ "create_pdf": lambda a: create_pdf(a.get("title", ""), a.get("body", ""), a.get("filename", "document.pdf")),
208
+ "create_web_project": lambda a: create_web_project(a.get("path", ""), a.get("framework", "react"), a.get("template", "vite")),
209
+ # local filesystem
210
+ "local_list": lambda a: local_list(a["path"]),
211
+ "local_read": lambda a: local_read(a["path"]),
212
+ "local_write": lambda a: local_write(a["path"], a.get("content", "")),
213
+ "read_document": lambda a: read_document(a["path"]),
214
+ "network_status": lambda a: network_status(),
215
+ # computer use
216
+ "computer_screenshot": lambda a: computer_screenshot(),
217
+ "computer_open_app": lambda a: computer_open_app(a.get("app", "Google Chrome")),
218
+ "computer_open_url": lambda a: computer_open_url(a["url"], a.get("app", "Google Chrome")),
219
+ "computer_click": lambda a: computer_click(a.get("x", 0), a.get("y", 0), a.get("button", "left"), a.get("double", False)),
220
+ "computer_type": lambda a: computer_type(a["text"], a.get("interval", 0.04)),
221
+ "computer_key": lambda a: computer_key(a["key"]),
222
+ "computer_scroll": lambda a: computer_scroll(a.get("x", 0), a.get("y", 0), a.get("direction", "down"), a.get("clicks", 3)),
223
+ "computer_move": lambda a: computer_move(a.get("x", 0), a.get("y", 0)),
224
+ "computer_drag": lambda a: computer_drag(a.get("x1", 0), a.get("y1", 0), a.get("x2", 0), a.get("y2", 0)),
225
+ "computer_status": lambda a: computer_status(),
226
+ "chrome_status": lambda a: desktop_bridge_status(),
227
+ "computer_use_status": lambda a: desktop_bridge_status(),
228
+ # knowledge / obsidian
229
+ "knowledge_save": lambda a: knowledge_save(a["content"], a.get("folder", "00_Raw"), a.get("title")),
230
+ "knowledge_search": lambda a: knowledge_search(a["query"], a.get("max_results", 5)),
231
+ "knowledge_tree": lambda a: knowledge_tree(),
232
+ "obsidian_save": lambda a: obsidian_save(a["content"], a.get("folder", "00_Raw"), a.get("title")),
233
+ "obsidian_search": lambda a: obsidian_search(a["query"], a.get("max_results", 5)),
234
+ "obsidian_tree": lambda a: obsidian_tree(),
235
+ # git (read-only)
236
+ "git_status": lambda a: git_status(a.get("cwd")),
237
+ "git_diff": lambda a: git_diff(a.get("path"), a.get("cwd")),
238
+ "git_log": lambda a: git_log(a.get("max_count", 5), a.get("cwd")),
239
+ "git_show": lambda a: git_show(a.get("revision", "HEAD"), a.get("cwd")),
240
+ # exec
241
+ "run_command": lambda a: run_command(a["command"], a.get("cwd")),
242
+ "build_project": lambda a: build_project(a.get("cwd"), a.get("script", "build")),
243
+ "deploy_project": lambda a: deploy_project(a.get("cwd"), a.get("script", "deploy")),
244
+ }
245
+
246
+
247
+ DEFAULT_TOOL_REGISTRY = ToolRegistry(TOOL_HANDLERS)
248
+
249
+
250
+ def registered_tools() -> frozenset:
251
+ """Names dispatchable through ``execute_tool`` — the seam other modules verify against."""
252
+ return DEFAULT_TOOL_REGISTRY.registered_tools()
253
+
254
+
255
+ def execute_tool(action: str, args: Dict[str, Any]) -> Dict[str, Any]:
256
+ return DEFAULT_TOOL_REGISTRY.execute(action, args, error_cls=ToolError)
257
+
258
+
259
+ __all__ = [
260
+ "AGENT_ROOT", "ToolError", "ensure_agent_root",
261
+ "list_dir", "workspace_tree", "read_file", "write_file", "edit_file", "grep",
262
+ "search_files", "inspect_html", "preview_url", "create_web_project",
263
+ "todo_read", "todo_write",
264
+ "create_docx", "create_xlsx", "create_pptx", "create_pdf", "read_document",
265
+ "local_list", "local_read", "local_write", "desktop_bridge_status",
266
+ "knowledge_save", "knowledge_search", "knowledge_tree",
267
+ "obsidian_save", "obsidian_search", "obsidian_tree",
268
+ "network_status",
269
+ "computer_screenshot", "computer_open_app", "computer_open_url",
270
+ "computer_click", "computer_type", "computer_key", "computer_scroll",
271
+ "computer_move", "computer_drag", "computer_status",
272
+ "run_command", "build_project", "deploy_project",
273
+ "git_status", "git_diff", "git_log", "git_show",
274
+ "TOOL_HANDLERS", "DEFAULT_TOOL_REGISTRY", "registered_tools", "execute_tool",
275
+ "BRAIN_DIR", "STRUCTURE",
276
+ ]