@mr-jones123/toji 0.1.1

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 (42) hide show
  1. package/README.md +158 -0
  2. package/package.json +47 -0
  3. package/packages/toji-comms/README.md +71 -0
  4. package/packages/toji-comms/src/cli/agents.ts +121 -0
  5. package/packages/toji-comms/src/cli/mmx.ts +65 -0
  6. package/packages/toji-comms/src/cli/subprocess.ts +47 -0
  7. package/packages/toji-comms/src/comms/orchestrator.ts +92 -0
  8. package/packages/toji-comms/src/comms/prompt.ts +84 -0
  9. package/packages/toji-comms/src/comms/store.ts +145 -0
  10. package/packages/toji-comms/src/comms/types.ts +94 -0
  11. package/packages/toji-comms/src/db/connection.ts +58 -0
  12. package/packages/toji-comms/src/db/migrations.ts +69 -0
  13. package/packages/toji-comms/src/index.ts +368 -0
  14. package/packages/toji-comms/src/mcp/client.ts +71 -0
  15. package/packages/toji-comms/src/mcp/server.ts +81 -0
  16. package/packages/toji-mem/README.md +52 -0
  17. package/packages/toji-mem/grammars/manifest.json +9 -0
  18. package/packages/toji-mem/grammars/tree-sitter-cpp.wasm +0 -0
  19. package/packages/toji-mem/grammars/tree-sitter-dart.wasm +0 -0
  20. package/packages/toji-mem/grammars/tree-sitter-java.wasm +0 -0
  21. package/packages/toji-mem/grammars/tree-sitter-javascript.wasm +0 -0
  22. package/packages/toji-mem/grammars/tree-sitter-python.wasm +0 -0
  23. package/packages/toji-mem/grammars/tree-sitter-tsx.wasm +0 -0
  24. package/packages/toji-mem/grammars/tree-sitter-typescript.wasm +0 -0
  25. package/packages/toji-mem/src/db/connection.ts +58 -0
  26. package/packages/toji-mem/src/db/migrations.ts +181 -0
  27. package/packages/toji-mem/src/index.ts +326 -0
  28. package/packages/toji-mem/src/indexer/file-walker.ts +45 -0
  29. package/packages/toji-mem/src/indexer/index-project.ts +277 -0
  30. package/packages/toji-mem/src/indexer/parsers/cpp.ts +81 -0
  31. package/packages/toji-mem/src/indexer/parsers/dart.ts +91 -0
  32. package/packages/toji-mem/src/indexer/parsers/java.ts +83 -0
  33. package/packages/toji-mem/src/indexer/parsers/python.ts +84 -0
  34. package/packages/toji-mem/src/indexer/parsers/registry.ts +28 -0
  35. package/packages/toji-mem/src/indexer/parsers/tree-sitter-loader.ts +39 -0
  36. package/packages/toji-mem/src/indexer/parsers/types.ts +48 -0
  37. package/packages/toji-mem/src/indexer/parsers/typescript.ts +105 -0
  38. package/packages/toji-mem/src/standards/store.ts +52 -0
  39. package/packages/toji-mem/src/tools/blast-radius.ts +98 -0
  40. package/packages/toji-mem/src/tools/graph-explore.ts +186 -0
  41. package/packages/toji-mem/src/tools/project-overview.ts +102 -0
  42. package/packages/toji-mem/src/tools/query-memory.ts +105 -0
@@ -0,0 +1,105 @@
1
+ import type { TojiDatabase } from "../db/connection";
2
+
3
+ export type QueryKind = "symbols" | "files" | "standards" | "all";
4
+
5
+ export function queryMemory(database: TojiDatabase, query: string, kind: QueryKind = "all"): Record<string, unknown[]> {
6
+ const result: Record<string, unknown[]> = {};
7
+
8
+ if (kind === "symbols" || kind === "all") {
9
+ result.symbols = exactSymbols(database, query);
10
+ if (result.symbols.length === 0) result.symbols = ftsSymbols(database, query);
11
+ }
12
+
13
+ if (kind === "files" || kind === "all") {
14
+ result.files = exactFiles(database, query);
15
+ if (result.files.length === 0) result.files = ftsFiles(database, query);
16
+ }
17
+
18
+ if (kind === "standards" || kind === "all") {
19
+ result.standards = ftsStandards(database, query);
20
+ }
21
+
22
+ return result;
23
+ }
24
+
25
+ function exactSymbols(database: TojiDatabase, query: string): unknown[] {
26
+ const lowered = query.toLowerCase();
27
+ return database
28
+ .query(
29
+ `SELECT s.id, s.name, s.canon_name, s.kind, s.language, f.path, s.signature, s.start_line, s.end_line, 0.0 AS rank
30
+ FROM symbols s
31
+ JOIN files f ON f.id = s.file_id
32
+ WHERE lower(s.name) = ? OR lower(s.canon_name) = ?
33
+ ORDER BY CASE WHEN lower(s.name) = ? THEN 0 ELSE 1 END, length(s.canon_name)
34
+ LIMIT 20`,
35
+ )
36
+ .all(lowered, lowered, lowered);
37
+ }
38
+
39
+ function exactFiles(database: TojiDatabase, query: string): unknown[] {
40
+ const lowered = query.toLowerCase();
41
+ return database
42
+ .query(
43
+ `SELECT id, name, path, language, 0.0 AS rank
44
+ FROM files
45
+ WHERE lower(path) = ? OR lower(name) = ?
46
+ ORDER BY CASE WHEN lower(path) = ? THEN 0 ELSE 1 END, length(path)
47
+ LIMIT 20`,
48
+ )
49
+ .all(lowered, lowered, lowered);
50
+ }
51
+
52
+ function ftsSymbols(database: TojiDatabase, query: string): unknown[] {
53
+ return database
54
+ .query(
55
+ `SELECT s.id, s.name, s.canon_name, s.kind, s.language, f.path, s.signature, s.start_line, s.end_line, bm25(symbol_fts) AS rank
56
+ FROM symbol_fts
57
+ JOIN symbols s ON s.id = symbol_fts.symbol_id
58
+ JOIN files f ON f.id = s.file_id
59
+ WHERE symbol_fts MATCH ?
60
+ ORDER BY rank
61
+ LIMIT 20`,
62
+ )
63
+ .all(buildFtsQuery(query));
64
+ }
65
+
66
+ function ftsFiles(database: TojiDatabase, query: string): unknown[] {
67
+ return database
68
+ .query(
69
+ `SELECT f.id, f.name, f.path, f.language, bm25(file_fts) AS rank
70
+ FROM file_fts
71
+ JOIN files f ON f.id = file_fts.file_id
72
+ WHERE file_fts MATCH ?
73
+ ORDER BY rank
74
+ LIMIT 20`,
75
+ )
76
+ .all(buildFtsQuery(query));
77
+ }
78
+
79
+ function ftsStandards(database: TojiDatabase, query: string): unknown[] {
80
+ return database
81
+ .query(
82
+ `SELECT s.id, s.rule, s.rationale, s.language, s.framework, s.priority, bm25(standards_fts) AS rank
83
+ FROM standards_fts
84
+ JOIN standards s ON s.id = standards_fts.standard_id
85
+ WHERE standards_fts MATCH ?
86
+ ORDER BY rank
87
+ LIMIT 20`,
88
+ )
89
+ .all(buildFtsQuery(query));
90
+ }
91
+
92
+ function buildFtsQuery(query: string): string {
93
+ const tokens = query
94
+ .split(/[^\p{L}\p{N}_./:-]+/u)
95
+ .map((token) => token.trim())
96
+ .filter(Boolean);
97
+
98
+ if (tokens.length === 0) return quoteFtsPhrase(query);
99
+ if (tokens.length === 1) return quoteFtsPhrase(tokens[0] ?? query);
100
+ return tokens.slice(0, 12).map(quoteFtsPhrase).join(" OR ");
101
+ }
102
+
103
+ function quoteFtsPhrase(value: string): string {
104
+ return `"${value.replaceAll('"', '""')}"`;
105
+ }