trellis 2.0.13 → 2.1.2

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 (96) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/embeddings/index.js +1 -1
  3. package/dist/{index-7gvjxt27.js → index-2917tjd8.js} +1 -1
  4. package/package.json +2 -10
  5. package/dist/transformers.node-bx3q9d7k.js +0 -33130
  6. package/src/cli/index.ts +0 -3356
  7. package/src/core/agents/harness.ts +0 -380
  8. package/src/core/agents/index.ts +0 -18
  9. package/src/core/agents/types.ts +0 -90
  10. package/src/core/index.ts +0 -118
  11. package/src/core/kernel/middleware.ts +0 -44
  12. package/src/core/kernel/trellis-kernel.ts +0 -593
  13. package/src/core/ontology/builtins.ts +0 -248
  14. package/src/core/ontology/index.ts +0 -34
  15. package/src/core/ontology/registry.ts +0 -209
  16. package/src/core/ontology/types.ts +0 -124
  17. package/src/core/ontology/validator.ts +0 -382
  18. package/src/core/persist/backend.ts +0 -74
  19. package/src/core/persist/sqlite-backend.ts +0 -298
  20. package/src/core/plugins/index.ts +0 -17
  21. package/src/core/plugins/registry.ts +0 -322
  22. package/src/core/plugins/types.ts +0 -126
  23. package/src/core/query/datalog.ts +0 -188
  24. package/src/core/query/engine.ts +0 -370
  25. package/src/core/query/index.ts +0 -34
  26. package/src/core/query/parser.ts +0 -481
  27. package/src/core/query/types.ts +0 -200
  28. package/src/core/store/eav-store.ts +0 -467
  29. package/src/decisions/auto-capture.ts +0 -136
  30. package/src/decisions/hooks.ts +0 -163
  31. package/src/decisions/index.ts +0 -261
  32. package/src/decisions/types.ts +0 -103
  33. package/src/embeddings/auto-embed.ts +0 -248
  34. package/src/embeddings/chunker.ts +0 -327
  35. package/src/embeddings/index.ts +0 -48
  36. package/src/embeddings/model.ts +0 -112
  37. package/src/embeddings/search.ts +0 -305
  38. package/src/embeddings/store.ts +0 -313
  39. package/src/embeddings/types.ts +0 -92
  40. package/src/engine.ts +0 -1125
  41. package/src/garden/cluster.ts +0 -330
  42. package/src/garden/garden.ts +0 -306
  43. package/src/garden/index.ts +0 -29
  44. package/src/git/git-exporter.ts +0 -286
  45. package/src/git/git-importer.ts +0 -329
  46. package/src/git/git-reader.ts +0 -189
  47. package/src/git/index.ts +0 -22
  48. package/src/identity/governance.ts +0 -211
  49. package/src/identity/identity.ts +0 -224
  50. package/src/identity/index.ts +0 -30
  51. package/src/identity/signing-middleware.ts +0 -97
  52. package/src/index.ts +0 -29
  53. package/src/links/index.ts +0 -49
  54. package/src/links/lifecycle.ts +0 -400
  55. package/src/links/parser.ts +0 -484
  56. package/src/links/ref-index.ts +0 -186
  57. package/src/links/resolver.ts +0 -314
  58. package/src/links/types.ts +0 -108
  59. package/src/mcp/index.ts +0 -22
  60. package/src/mcp/server.ts +0 -1278
  61. package/src/semantic/csharp-parser.ts +0 -493
  62. package/src/semantic/go-parser.ts +0 -585
  63. package/src/semantic/index.ts +0 -34
  64. package/src/semantic/java-parser.ts +0 -456
  65. package/src/semantic/python-parser.ts +0 -659
  66. package/src/semantic/ruby-parser.ts +0 -446
  67. package/src/semantic/rust-parser.ts +0 -784
  68. package/src/semantic/semantic-merge.ts +0 -210
  69. package/src/semantic/ts-parser.ts +0 -681
  70. package/src/semantic/types.ts +0 -175
  71. package/src/sync/http-transport.ts +0 -144
  72. package/src/sync/index.ts +0 -43
  73. package/src/sync/memory-transport.ts +0 -66
  74. package/src/sync/multi-repo.ts +0 -200
  75. package/src/sync/reconciler.ts +0 -237
  76. package/src/sync/sync-engine.ts +0 -258
  77. package/src/sync/types.ts +0 -104
  78. package/src/sync/ws-transport.ts +0 -145
  79. package/src/ui/client.html +0 -695
  80. package/src/ui/server.ts +0 -419
  81. package/src/vcs/blob-store.ts +0 -124
  82. package/src/vcs/branch.ts +0 -150
  83. package/src/vcs/checkpoint.ts +0 -64
  84. package/src/vcs/decompose.ts +0 -469
  85. package/src/vcs/diff.ts +0 -409
  86. package/src/vcs/engine-context.ts +0 -26
  87. package/src/vcs/index.ts +0 -23
  88. package/src/vcs/issue.ts +0 -800
  89. package/src/vcs/merge.ts +0 -425
  90. package/src/vcs/milestone.ts +0 -124
  91. package/src/vcs/ops.ts +0 -59
  92. package/src/vcs/types.ts +0 -213
  93. package/src/vcs/vcs-middleware.ts +0 -81
  94. package/src/watcher/fs-watcher.ts +0 -255
  95. package/src/watcher/index.ts +0 -9
  96. package/src/watcher/ingestion.ts +0 -116
@@ -1,313 +0,0 @@
1
- /**
2
- * Embedding Vector Store
3
- *
4
- * Persistent storage for embedding vectors using bun:sqlite.
5
- * Vectors are stored as Float32Array blobs; cosine similarity
6
- * is computed in JavaScript for cross-platform portability.
7
- *
8
- * @see TRL-18
9
- */
10
-
11
- import { Database } from 'bun:sqlite';
12
- import type {
13
- ChunkMeta,
14
- ChunkType,
15
- EmbeddingRecord,
16
- SearchOptions,
17
- SearchResult,
18
- } from './types.js';
19
-
20
- // ---------------------------------------------------------------------------
21
- // Schema
22
- // ---------------------------------------------------------------------------
23
-
24
- const SCHEMA_SQL = `
25
- CREATE TABLE IF NOT EXISTS chunks (
26
- id TEXT PRIMARY KEY,
27
- entity_id TEXT NOT NULL,
28
- content TEXT NOT NULL,
29
- chunk_type TEXT NOT NULL,
30
- file_path TEXT,
31
- updated_at TEXT NOT NULL
32
- );
33
-
34
- CREATE TABLE IF NOT EXISTS vectors (
35
- id TEXT PRIMARY KEY,
36
- embedding BLOB NOT NULL,
37
- FOREIGN KEY (id) REFERENCES chunks(id) ON DELETE CASCADE
38
- );
39
-
40
- CREATE INDEX IF NOT EXISTS idx_chunks_entity ON chunks(entity_id);
41
- CREATE INDEX IF NOT EXISTS idx_chunks_type ON chunks(chunk_type);
42
- CREATE INDEX IF NOT EXISTS idx_chunks_file ON chunks(file_path);
43
- `;
44
-
45
- // ---------------------------------------------------------------------------
46
- // Vector Store
47
- // ---------------------------------------------------------------------------
48
-
49
- export class VectorStore {
50
- private db: Database;
51
-
52
- constructor(dbPath: string) {
53
- this.db = new Database(dbPath);
54
- this.db.exec('PRAGMA journal_mode=WAL;');
55
- this.db.exec('PRAGMA foreign_keys=ON;');
56
- this.db.exec(SCHEMA_SQL);
57
- }
58
-
59
- /**
60
- * Insert or update a chunk with its embedding vector.
61
- */
62
- upsert(record: EmbeddingRecord): void {
63
- const insertChunk = this.db.prepare(`
64
- INSERT OR REPLACE INTO chunks (id, entity_id, content, chunk_type, file_path, updated_at)
65
- VALUES ($id, $entityId, $content, $chunkType, $filePath, $updatedAt)
66
- `);
67
- const insertVector = this.db.prepare(`
68
- INSERT OR REPLACE INTO vectors (id, embedding)
69
- VALUES ($id, $embedding)
70
- `);
71
-
72
- const embeddingBlob = Buffer.from(record.embedding.buffer);
73
-
74
- this.db.transaction(() => {
75
- insertChunk.run({
76
- $id: record.id,
77
- $entityId: record.entityId,
78
- $content: record.content,
79
- $chunkType: record.chunkType,
80
- $filePath: record.filePath ?? null,
81
- $updatedAt: record.updatedAt,
82
- });
83
- insertVector.run({
84
- $id: record.id,
85
- $embedding: embeddingBlob,
86
- });
87
- })();
88
- }
89
-
90
- /**
91
- * Batch upsert multiple records.
92
- */
93
- upsertBatch(records: EmbeddingRecord[]): void {
94
- if (records.length === 0) return;
95
-
96
- const insertChunk = this.db.prepare(`
97
- INSERT OR REPLACE INTO chunks (id, entity_id, content, chunk_type, file_path, updated_at)
98
- VALUES ($id, $entityId, $content, $chunkType, $filePath, $updatedAt)
99
- `);
100
- const insertVector = this.db.prepare(`
101
- INSERT OR REPLACE INTO vectors (id, embedding)
102
- VALUES ($id, $embedding)
103
- `);
104
-
105
- this.db.transaction(() => {
106
- for (const record of records) {
107
- const embeddingBlob = Buffer.from(record.embedding.buffer);
108
- insertChunk.run({
109
- $id: record.id,
110
- $entityId: record.entityId,
111
- $content: record.content,
112
- $chunkType: record.chunkType,
113
- $filePath: record.filePath ?? null,
114
- $updatedAt: record.updatedAt,
115
- });
116
- insertVector.run({
117
- $id: record.id,
118
- $embedding: embeddingBlob,
119
- });
120
- }
121
- })();
122
- }
123
-
124
- /**
125
- * Delete a chunk and its vector by ID.
126
- */
127
- delete(id: string): void {
128
- this.db.prepare('DELETE FROM vectors WHERE id = ?').run(id);
129
- this.db.prepare('DELETE FROM chunks WHERE id = ?').run(id);
130
- }
131
-
132
- /**
133
- * Delete all chunks for an entity.
134
- */
135
- deleteByEntity(entityId: string): void {
136
- const ids = this.db
137
- .prepare('SELECT id FROM chunks WHERE entity_id = ?')
138
- .all(entityId) as Array<{ id: string }>;
139
-
140
- if (ids.length === 0) return;
141
-
142
- this.db.transaction(() => {
143
- for (const { id } of ids) {
144
- this.db.prepare('DELETE FROM vectors WHERE id = ?').run(id);
145
- this.db.prepare('DELETE FROM chunks WHERE id = ?').run(id);
146
- }
147
- })();
148
- }
149
-
150
- /**
151
- * Delete all chunks associated with a file path.
152
- */
153
- deleteByFile(filePath: string): void {
154
- const ids = this.db
155
- .prepare('SELECT id FROM chunks WHERE file_path = ?')
156
- .all(filePath) as Array<{ id: string }>;
157
-
158
- if (ids.length === 0) return;
159
-
160
- this.db.transaction(() => {
161
- for (const { id } of ids) {
162
- this.db.prepare('DELETE FROM vectors WHERE id = ?').run(id);
163
- this.db.prepare('DELETE FROM chunks WHERE id = ?').run(id);
164
- }
165
- })();
166
- }
167
-
168
- /**
169
- * Get a chunk by ID (without vector).
170
- */
171
- getChunk(id: string): ChunkMeta | null {
172
- const row = this.db
173
- .prepare('SELECT * FROM chunks WHERE id = ?')
174
- .get(id) as any;
175
- if (!row) return null;
176
- return rowToChunkMeta(row);
177
- }
178
-
179
- /**
180
- * Search for chunks similar to the query vector.
181
- * Uses brute-force cosine similarity scan.
182
- */
183
- search(queryVector: Float32Array, opts: SearchOptions = {}): SearchResult[] {
184
- const limit = opts.limit ?? 10;
185
- const minScore = opts.minScore ?? 0.0;
186
-
187
- // Build SQL filter
188
- const conditions: string[] = [];
189
- const params: Record<string, unknown> = {};
190
-
191
- if (opts.types && opts.types.length > 0) {
192
- const placeholders = opts.types.map((_, i) => `$type${i}`).join(', ');
193
- conditions.push(`c.chunk_type IN (${placeholders})`);
194
- opts.types.forEach((t, i) => {
195
- params[`$type${i}`] = t;
196
- });
197
- }
198
-
199
- if (opts.filePrefix) {
200
- conditions.push('c.file_path LIKE $filePrefix');
201
- params.$filePrefix = `${opts.filePrefix}%`;
202
- }
203
-
204
- const where =
205
- conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
206
-
207
- const sql = `
208
- SELECT c.id, c.entity_id, c.content, c.chunk_type, c.file_path, c.updated_at,
209
- v.embedding
210
- FROM chunks c
211
- JOIN vectors v ON c.id = v.id
212
- ${where}
213
- `;
214
-
215
- const rows = this.db.prepare(sql).all(params) as any[];
216
-
217
- // Compute cosine similarity for each row
218
- const scored: SearchResult[] = [];
219
- for (const row of rows) {
220
- const storedVec = new Float32Array(
221
- (row.embedding as Buffer).buffer,
222
- (row.embedding as Buffer).byteOffset,
223
- (row.embedding as Buffer).byteLength / 4,
224
- );
225
- const score = cosineSimilarity(queryVector, storedVec);
226
- if (score >= minScore) {
227
- scored.push({
228
- chunk: rowToChunkMeta(row),
229
- score,
230
- });
231
- }
232
- }
233
-
234
- // Sort by score descending and limit
235
- scored.sort((a, b) => b.score - a.score);
236
- return scored.slice(0, limit);
237
- }
238
-
239
- /**
240
- * Get total count of chunks in the store.
241
- */
242
- count(): number {
243
- const row = this.db
244
- .prepare('SELECT COUNT(*) as cnt FROM chunks')
245
- .get() as any;
246
- return row?.cnt ?? 0;
247
- }
248
-
249
- /**
250
- * Get count by chunk type.
251
- */
252
- countByType(): Record<string, number> {
253
- const rows = this.db
254
- .prepare(
255
- 'SELECT chunk_type, COUNT(*) as cnt FROM chunks GROUP BY chunk_type',
256
- )
257
- .all() as any[];
258
- const result: Record<string, number> = {};
259
- for (const row of rows) {
260
- result[row.chunk_type] = row.cnt;
261
- }
262
- return result;
263
- }
264
-
265
- /**
266
- * Clear all data from the store.
267
- */
268
- clear(): void {
269
- this.db.exec('DELETE FROM vectors');
270
- this.db.exec('DELETE FROM chunks');
271
- }
272
-
273
- /**
274
- * Close the database connection.
275
- */
276
- close(): void {
277
- this.db.close();
278
- }
279
- }
280
-
281
- // ---------------------------------------------------------------------------
282
- // Helpers
283
- // ---------------------------------------------------------------------------
284
-
285
- function rowToChunkMeta(row: any): ChunkMeta {
286
- return {
287
- id: row.id,
288
- entityId: row.entity_id,
289
- content: row.content,
290
- chunkType: row.chunk_type as ChunkType,
291
- filePath: row.file_path ?? undefined,
292
- updatedAt: row.updated_at,
293
- };
294
- }
295
-
296
- /**
297
- * Compute cosine similarity between two vectors.
298
- * Both vectors should already be normalized (output of mean pooling + normalize).
299
- * For normalized vectors, cosine similarity = dot product.
300
- */
301
- export function cosineSimilarity(a: Float32Array, b: Float32Array): number {
302
- if (a.length !== b.length) return 0;
303
- let dot = 0;
304
- let normA = 0;
305
- let normB = 0;
306
- for (let i = 0; i < a.length; i++) {
307
- dot += a[i] * b[i];
308
- normA += a[i] * a[i];
309
- normB += b[i] * b[i];
310
- }
311
- const denom = Math.sqrt(normA) * Math.sqrt(normB);
312
- return denom === 0 ? 0 : dot / denom;
313
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * Embedding Types
3
- *
4
- * Types for the semantic embedding and vector search system.
5
- *
6
- * @see TRL-18
7
- */
8
-
9
- // ---------------------------------------------------------------------------
10
- // Chunk types — what gets embedded
11
- // ---------------------------------------------------------------------------
12
-
13
- export type ChunkType =
14
- | 'issue_title'
15
- | 'issue_desc'
16
- | 'milestone_msg'
17
- | 'decision_rationale'
18
- | 'summary_md'
19
- | 'code_entity'
20
- | 'doc_comment'
21
- | 'markdown';
22
-
23
- export interface ChunkMeta {
24
- /** Unique chunk ID, e.g. "issue:TRL-5:title", "file:src/engine.ts:chunk:0" */
25
- id: string;
26
- /** EAV entity ID this chunk belongs to */
27
- entityId: string;
28
- /** Original text content */
29
- content: string;
30
- /** Chunk classification */
31
- chunkType: ChunkType;
32
- /** Source file path (nullable for non-file entities) */
33
- filePath?: string;
34
- /** When this chunk was last updated */
35
- updatedAt: string;
36
- }
37
-
38
- // ---------------------------------------------------------------------------
39
- // Embedding record — chunk + vector
40
- // ---------------------------------------------------------------------------
41
-
42
- export interface EmbeddingRecord extends ChunkMeta {
43
- /** 384-dimensional embedding vector */
44
- embedding: Float32Array;
45
- }
46
-
47
- // ---------------------------------------------------------------------------
48
- // Search
49
- // ---------------------------------------------------------------------------
50
-
51
- export interface SearchResult {
52
- /** Chunk metadata */
53
- chunk: ChunkMeta;
54
- /** Cosine similarity score (0..1) */
55
- score: number;
56
- }
57
-
58
- export interface SearchOptions {
59
- /** Max results to return (default: 10) */
60
- limit?: number;
61
- /** Filter by chunk type(s) */
62
- types?: ChunkType[];
63
- /** Filter by file path prefix */
64
- filePrefix?: string;
65
- /** Minimum similarity threshold (default: 0.0) */
66
- minScore?: number;
67
- }
68
-
69
- // ---------------------------------------------------------------------------
70
- // Embedding model config
71
- // ---------------------------------------------------------------------------
72
-
73
- export interface EmbeddingModelConfig {
74
- /** Model name for transformers.js (default: "Xenova/all-MiniLM-L6-v2") */
75
- modelName: string;
76
- /** Embedding dimension (default: 384) */
77
- dimension: number;
78
- /** Cache directory for model files */
79
- cacheDir?: string;
80
- }
81
-
82
- export const DEFAULT_MODEL_CONFIG: EmbeddingModelConfig = {
83
- modelName: 'Xenova/all-MiniLM-L6-v2',
84
- dimension: 384,
85
- };
86
-
87
- /** New chunk types for generic graph entities */
88
- export type GraphChunkType =
89
- | ChunkType
90
- | 'entity_summary'
91
- | 'entity_fact'
92
- | 'entity_link';