@zipbul/gildash 0.6.0 → 0.8.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.
@@ -0,0 +1,2 @@
1
+ ALTER TABLE `watcher_owner` ADD COLUMN `instance_id` text;--> statement-breakpoint
2
+ CREATE INDEX `idx_relations_project_type_src` ON `relations` (`project`,`type`,`src_file_path`);
@@ -0,0 +1,445 @@
1
+ {
2
+ "version": "6",
3
+ "dialect": "sqlite",
4
+ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
5
+ "prevId": "4792483b-0af0-4775-a2df-c04b8066770e",
6
+ "tables": {
7
+ "files": {
8
+ "name": "files",
9
+ "columns": {
10
+ "project": {
11
+ "name": "project",
12
+ "type": "text",
13
+ "primaryKey": false,
14
+ "notNull": true,
15
+ "autoincrement": false
16
+ },
17
+ "file_path": {
18
+ "name": "file_path",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true,
22
+ "autoincrement": false
23
+ },
24
+ "mtime_ms": {
25
+ "name": "mtime_ms",
26
+ "type": "real",
27
+ "primaryKey": false,
28
+ "notNull": true,
29
+ "autoincrement": false
30
+ },
31
+ "size": {
32
+ "name": "size",
33
+ "type": "integer",
34
+ "primaryKey": false,
35
+ "notNull": true,
36
+ "autoincrement": false
37
+ },
38
+ "content_hash": {
39
+ "name": "content_hash",
40
+ "type": "text",
41
+ "primaryKey": false,
42
+ "notNull": true,
43
+ "autoincrement": false
44
+ },
45
+ "updated_at": {
46
+ "name": "updated_at",
47
+ "type": "text",
48
+ "primaryKey": false,
49
+ "notNull": true,
50
+ "autoincrement": false
51
+ },
52
+ "line_count": {
53
+ "name": "line_count",
54
+ "type": "integer",
55
+ "primaryKey": false,
56
+ "notNull": false,
57
+ "autoincrement": false
58
+ }
59
+ },
60
+ "indexes": {},
61
+ "foreignKeys": {},
62
+ "compositePrimaryKeys": {
63
+ "files_project_file_path_pk": {
64
+ "columns": [
65
+ "project",
66
+ "file_path"
67
+ ],
68
+ "name": "files_project_file_path_pk"
69
+ }
70
+ },
71
+ "uniqueConstraints": {},
72
+ "checkConstraints": {}
73
+ },
74
+ "relations": {
75
+ "name": "relations",
76
+ "columns": {
77
+ "id": {
78
+ "name": "id",
79
+ "type": "integer",
80
+ "primaryKey": true,
81
+ "notNull": true,
82
+ "autoincrement": true
83
+ },
84
+ "project": {
85
+ "name": "project",
86
+ "type": "text",
87
+ "primaryKey": false,
88
+ "notNull": true,
89
+ "autoincrement": false
90
+ },
91
+ "type": {
92
+ "name": "type",
93
+ "type": "text",
94
+ "primaryKey": false,
95
+ "notNull": true,
96
+ "autoincrement": false
97
+ },
98
+ "src_file_path": {
99
+ "name": "src_file_path",
100
+ "type": "text",
101
+ "primaryKey": false,
102
+ "notNull": true,
103
+ "autoincrement": false
104
+ },
105
+ "src_symbol_name": {
106
+ "name": "src_symbol_name",
107
+ "type": "text",
108
+ "primaryKey": false,
109
+ "notNull": false,
110
+ "autoincrement": false
111
+ },
112
+ "dst_project": {
113
+ "name": "dst_project",
114
+ "type": "text",
115
+ "primaryKey": false,
116
+ "notNull": true,
117
+ "autoincrement": false
118
+ },
119
+ "dst_file_path": {
120
+ "name": "dst_file_path",
121
+ "type": "text",
122
+ "primaryKey": false,
123
+ "notNull": true,
124
+ "autoincrement": false
125
+ },
126
+ "dst_symbol_name": {
127
+ "name": "dst_symbol_name",
128
+ "type": "text",
129
+ "primaryKey": false,
130
+ "notNull": false,
131
+ "autoincrement": false
132
+ },
133
+ "meta_json": {
134
+ "name": "meta_json",
135
+ "type": "text",
136
+ "primaryKey": false,
137
+ "notNull": false,
138
+ "autoincrement": false
139
+ }
140
+ },
141
+ "indexes": {
142
+ "idx_relations_src": {
143
+ "name": "idx_relations_src",
144
+ "columns": [
145
+ "project",
146
+ "src_file_path"
147
+ ],
148
+ "isUnique": false
149
+ },
150
+ "idx_relations_dst": {
151
+ "name": "idx_relations_dst",
152
+ "columns": [
153
+ "dst_project",
154
+ "dst_file_path"
155
+ ],
156
+ "isUnique": false
157
+ },
158
+ "idx_relations_type": {
159
+ "name": "idx_relations_type",
160
+ "columns": [
161
+ "project",
162
+ "type"
163
+ ],
164
+ "isUnique": false
165
+ },
166
+ "idx_relations_project_type_src": {
167
+ "name": "idx_relations_project_type_src",
168
+ "columns": [
169
+ "project",
170
+ "type",
171
+ "src_file_path"
172
+ ],
173
+ "isUnique": false
174
+ }
175
+ },
176
+ "foreignKeys": {
177
+ "relations_project_src_file_path_files_project_file_path_fk": {
178
+ "name": "relations_project_src_file_path_files_project_file_path_fk",
179
+ "tableFrom": "relations",
180
+ "tableTo": "files",
181
+ "columnsFrom": [
182
+ "project",
183
+ "src_file_path"
184
+ ],
185
+ "columnsTo": [
186
+ "project",
187
+ "file_path"
188
+ ],
189
+ "onDelete": "cascade",
190
+ "onUpdate": "no action"
191
+ },
192
+ "relations_dst_project_dst_file_path_files_project_file_path_fk": {
193
+ "name": "relations_dst_project_dst_file_path_files_project_file_path_fk",
194
+ "tableFrom": "relations",
195
+ "tableTo": "files",
196
+ "columnsFrom": [
197
+ "dst_project",
198
+ "dst_file_path"
199
+ ],
200
+ "columnsTo": [
201
+ "project",
202
+ "file_path"
203
+ ],
204
+ "onDelete": "cascade",
205
+ "onUpdate": "no action"
206
+ }
207
+ },
208
+ "compositePrimaryKeys": {},
209
+ "uniqueConstraints": {},
210
+ "checkConstraints": {}
211
+ },
212
+ "symbols": {
213
+ "name": "symbols",
214
+ "columns": {
215
+ "id": {
216
+ "name": "id",
217
+ "type": "integer",
218
+ "primaryKey": true,
219
+ "notNull": true,
220
+ "autoincrement": true
221
+ },
222
+ "project": {
223
+ "name": "project",
224
+ "type": "text",
225
+ "primaryKey": false,
226
+ "notNull": true,
227
+ "autoincrement": false
228
+ },
229
+ "file_path": {
230
+ "name": "file_path",
231
+ "type": "text",
232
+ "primaryKey": false,
233
+ "notNull": true,
234
+ "autoincrement": false
235
+ },
236
+ "kind": {
237
+ "name": "kind",
238
+ "type": "text",
239
+ "primaryKey": false,
240
+ "notNull": true,
241
+ "autoincrement": false
242
+ },
243
+ "name": {
244
+ "name": "name",
245
+ "type": "text",
246
+ "primaryKey": false,
247
+ "notNull": true,
248
+ "autoincrement": false
249
+ },
250
+ "start_line": {
251
+ "name": "start_line",
252
+ "type": "integer",
253
+ "primaryKey": false,
254
+ "notNull": true,
255
+ "autoincrement": false
256
+ },
257
+ "start_column": {
258
+ "name": "start_column",
259
+ "type": "integer",
260
+ "primaryKey": false,
261
+ "notNull": true,
262
+ "autoincrement": false
263
+ },
264
+ "end_line": {
265
+ "name": "end_line",
266
+ "type": "integer",
267
+ "primaryKey": false,
268
+ "notNull": true,
269
+ "autoincrement": false
270
+ },
271
+ "end_column": {
272
+ "name": "end_column",
273
+ "type": "integer",
274
+ "primaryKey": false,
275
+ "notNull": true,
276
+ "autoincrement": false
277
+ },
278
+ "is_exported": {
279
+ "name": "is_exported",
280
+ "type": "integer",
281
+ "primaryKey": false,
282
+ "notNull": true,
283
+ "autoincrement": false,
284
+ "default": 0
285
+ },
286
+ "signature": {
287
+ "name": "signature",
288
+ "type": "text",
289
+ "primaryKey": false,
290
+ "notNull": false,
291
+ "autoincrement": false
292
+ },
293
+ "fingerprint": {
294
+ "name": "fingerprint",
295
+ "type": "text",
296
+ "primaryKey": false,
297
+ "notNull": false,
298
+ "autoincrement": false
299
+ },
300
+ "detail_json": {
301
+ "name": "detail_json",
302
+ "type": "text",
303
+ "primaryKey": false,
304
+ "notNull": false,
305
+ "autoincrement": false
306
+ },
307
+ "content_hash": {
308
+ "name": "content_hash",
309
+ "type": "text",
310
+ "primaryKey": false,
311
+ "notNull": true,
312
+ "autoincrement": false
313
+ },
314
+ "indexed_at": {
315
+ "name": "indexed_at",
316
+ "type": "text",
317
+ "primaryKey": false,
318
+ "notNull": true,
319
+ "autoincrement": false
320
+ },
321
+ "resolved_type": {
322
+ "name": "resolved_type",
323
+ "type": "text",
324
+ "primaryKey": false,
325
+ "notNull": false,
326
+ "autoincrement": false
327
+ }
328
+ },
329
+ "indexes": {
330
+ "idx_symbols_project_file": {
331
+ "name": "idx_symbols_project_file",
332
+ "columns": [
333
+ "project",
334
+ "file_path"
335
+ ],
336
+ "isUnique": false
337
+ },
338
+ "idx_symbols_project_kind": {
339
+ "name": "idx_symbols_project_kind",
340
+ "columns": [
341
+ "project",
342
+ "kind"
343
+ ],
344
+ "isUnique": false
345
+ },
346
+ "idx_symbols_project_name": {
347
+ "name": "idx_symbols_project_name",
348
+ "columns": [
349
+ "project",
350
+ "name"
351
+ ],
352
+ "isUnique": false
353
+ },
354
+ "idx_symbols_fingerprint": {
355
+ "name": "idx_symbols_fingerprint",
356
+ "columns": [
357
+ "project",
358
+ "fingerprint"
359
+ ],
360
+ "isUnique": false
361
+ }
362
+ },
363
+ "foreignKeys": {
364
+ "symbols_project_file_path_files_project_file_path_fk": {
365
+ "name": "symbols_project_file_path_files_project_file_path_fk",
366
+ "tableFrom": "symbols",
367
+ "tableTo": "files",
368
+ "columnsFrom": [
369
+ "project",
370
+ "file_path"
371
+ ],
372
+ "columnsTo": [
373
+ "project",
374
+ "file_path"
375
+ ],
376
+ "onDelete": "cascade",
377
+ "onUpdate": "no action"
378
+ }
379
+ },
380
+ "compositePrimaryKeys": {},
381
+ "uniqueConstraints": {},
382
+ "checkConstraints": {}
383
+ },
384
+ "watcher_owner": {
385
+ "name": "watcher_owner",
386
+ "columns": {
387
+ "id": {
388
+ "name": "id",
389
+ "type": "integer",
390
+ "primaryKey": true,
391
+ "notNull": true,
392
+ "autoincrement": false
393
+ },
394
+ "pid": {
395
+ "name": "pid",
396
+ "type": "integer",
397
+ "primaryKey": false,
398
+ "notNull": true,
399
+ "autoincrement": false
400
+ },
401
+ "started_at": {
402
+ "name": "started_at",
403
+ "type": "text",
404
+ "primaryKey": false,
405
+ "notNull": true,
406
+ "autoincrement": false
407
+ },
408
+ "heartbeat_at": {
409
+ "name": "heartbeat_at",
410
+ "type": "text",
411
+ "primaryKey": false,
412
+ "notNull": true,
413
+ "autoincrement": false
414
+ },
415
+ "instance_id": {
416
+ "name": "instance_id",
417
+ "type": "text",
418
+ "primaryKey": false,
419
+ "notNull": false,
420
+ "autoincrement": false
421
+ }
422
+ },
423
+ "indexes": {},
424
+ "foreignKeys": {},
425
+ "compositePrimaryKeys": {},
426
+ "uniqueConstraints": {},
427
+ "checkConstraints": {
428
+ "watcher_owner_singleton": {
429
+ "name": "watcher_owner_singleton",
430
+ "value": "\"watcher_owner\".\"id\" = 1"
431
+ }
432
+ }
433
+ }
434
+ },
435
+ "views": {},
436
+ "enums": {},
437
+ "_meta": {
438
+ "schemas": {},
439
+ "tables": {},
440
+ "columns": {}
441
+ },
442
+ "internal": {
443
+ "indexes": {}
444
+ }
445
+ }
@@ -36,6 +36,13 @@
36
36
  "when": 1772043335425,
37
37
  "tag": "0004_cool_firestar",
38
38
  "breakpoints": true
39
+ },
40
+ {
41
+ "idx": 5,
42
+ "version": "6",
43
+ "when": 1772150400000,
44
+ "tag": "0005_instance_id_covering_index",
45
+ "breakpoints": true
39
46
  }
40
47
  ]
41
48
  }
@@ -3,13 +3,14 @@
3
3
  */
4
4
  export type GildashErrorType = 'watcher' | 'parse' | 'extract' | 'index' | 'store' | 'search' | 'closed' | 'validation' | 'close' | 'semantic';
5
5
  /**
6
- * Plain-object error value used throughout Gildash's Result-based error handling.
7
- * Produced by {@link gildashError} and carried as the `data` field of an `Err<GildashError>`.
6
+ * Error class used throughout Gildash.
7
+ * Extends `Error` so that `instanceof Error` checks work and stack traces are captured.
8
8
  */
9
- export interface GildashError {
10
- type: GildashErrorType;
11
- message: string;
12
- cause?: unknown;
9
+ export declare class GildashError extends Error {
10
+ readonly type: GildashErrorType;
11
+ constructor(type: GildashErrorType, message: string, options?: {
12
+ cause?: unknown;
13
+ });
13
14
  }
14
15
  /**
15
16
  * Factory function that creates a {@link GildashError} value.
@@ -18,5 +19,6 @@ export interface GildashError {
18
19
  * @param message - Human-readable description of the error.
19
20
  * @param cause - Optional root cause (any value). When `undefined`, the `cause`
20
21
  * property is omitted from the returned object entirely.
22
+ * @deprecated Use `new GildashError(type, message, { cause })` instead.
21
23
  */
22
24
  export declare function gildashError(type: GildashErrorType, message: string, cause?: unknown): GildashError;
@@ -77,6 +77,7 @@ export interface GildashContext {
77
77
  readonly updateHeartbeatFn: UpdateHeartbeatFn;
78
78
  readonly watcherFactory?: () => WatcherLike;
79
79
  readonly coordinatorFactory?: () => CoordinatorLike;
80
+ readonly instanceId: string;
80
81
  closed: boolean;
81
82
  coordinator: CoordinatorLike | null;
82
83
  watcher: WatcherLike | null;
@@ -85,7 +86,11 @@ export interface GildashContext {
85
86
  tsconfigPaths: TsconfigPaths | null;
86
87
  boundaries: ProjectBoundary[];
87
88
  onIndexedCallbacks: Set<(result: IndexResult) => void>;
89
+ onFileChangedCallbacks: Set<(event: FileChangeEvent) => void>;
90
+ onErrorCallbacks: Set<(error: GildashError) => void>;
91
+ onRoleChangedCallbacks: Set<(newRole: 'owner' | 'reader') => void>;
88
92
  graphCache: DependencyGraph | null;
89
93
  graphCacheKey: string | null;
94
+ graphCacheBuiltAt: number | null;
90
95
  semanticLayer: SemanticLayerLike | null;
91
96
  }
@@ -1,9 +1,7 @@
1
- import { type Result } from '@zipbul/result';
2
1
  import type { ParsedFile } from '../parser/types';
3
2
  import type { ExtractedSymbol, CodeRelation } from '../extractor/types';
4
- import type { GildashError } from '../errors';
5
3
  import type { GildashContext } from './context';
6
4
  /** Extract all symbol declarations from a previously parsed file. */
7
- export declare function extractSymbols(ctx: GildashContext, parsed: ParsedFile): Result<ExtractedSymbol[], GildashError>;
5
+ export declare function extractSymbols(ctx: GildashContext, parsed: ParsedFile): ExtractedSymbol[];
8
6
  /** Extract inter-file relationships from a previously parsed file. */
9
- export declare function extractRelations(ctx: GildashContext, parsed: ParsedFile): Result<CodeRelation[], GildashError>;
7
+ export declare function extractRelations(ctx: GildashContext, parsed: ParsedFile): CodeRelation[];
@@ -1,30 +1,31 @@
1
- import { type Result } from '@zipbul/result';
2
- import type { GildashError } from '../errors';
3
1
  import { DependencyGraph } from '../search/dependency-graph';
4
2
  import type { GildashContext } from './context';
5
3
  import type { FanMetrics } from './types';
4
+ /** Graph cache TTL — matches healthcheck interval so readers stay fresh. */
5
+ export declare const GRAPH_CACHE_TTL_MS = 15000;
6
6
  /** Invalidate the cached DependencyGraph (called after every index run). */
7
7
  export declare function invalidateGraphCache(ctx: GildashContext): void;
8
8
  /**
9
9
  * Return a cached or freshly-built DependencyGraph for the given project.
10
10
  * Builds once per key; subsequent calls with the same key return the cached instance.
11
+ * TTL-based expiry ensures readers don't hold stale graphs indefinitely.
11
12
  */
12
13
  export declare function getOrBuildGraph(ctx: GildashContext, project?: string): DependencyGraph;
13
14
  /** List the files that a given file directly imports. */
14
- export declare function getDependencies(ctx: GildashContext, filePath: string, project?: string, limit?: number): Result<string[], GildashError>;
15
+ export declare function getDependencies(ctx: GildashContext, filePath: string, project?: string, limit?: number): string[];
15
16
  /** List the files that directly import a given file. */
16
- export declare function getDependents(ctx: GildashContext, filePath: string, project?: string, limit?: number): Result<string[], GildashError>;
17
+ export declare function getDependents(ctx: GildashContext, filePath: string, project?: string, limit?: number): string[];
17
18
  /** Compute the full set of files transitively affected by changes. */
18
- export declare function getAffected(ctx: GildashContext, changedFiles: string[], project?: string): Promise<Result<string[], GildashError>>;
19
+ export declare function getAffected(ctx: GildashContext, changedFiles: string[], project?: string): Promise<string[]>;
19
20
  /** Check whether the import graph contains a circular dependency. */
20
- export declare function hasCycle(ctx: GildashContext, project?: string): Promise<Result<boolean, GildashError>>;
21
+ export declare function hasCycle(ctx: GildashContext, project?: string): Promise<boolean>;
21
22
  /** Return the full import graph as an adjacency list. */
22
- export declare function getImportGraph(ctx: GildashContext, project?: string): Promise<Result<Map<string, string[]>, GildashError>>;
23
+ export declare function getImportGraph(ctx: GildashContext, project?: string): Promise<Map<string, string[]>>;
23
24
  /** Return all files that `filePath` transitively imports (forward BFS). */
24
- export declare function getTransitiveDependencies(ctx: GildashContext, filePath: string, project?: string): Promise<Result<string[], GildashError>>;
25
+ export declare function getTransitiveDependencies(ctx: GildashContext, filePath: string, project?: string): Promise<string[]>;
25
26
  /** Return all cycle paths in the import graph. */
26
27
  export declare function getCyclePaths(ctx: GildashContext, project?: string, options?: {
27
28
  maxCycles?: number;
28
- }): Promise<Result<string[][], GildashError>>;
29
+ }): Promise<string[][]>;
29
30
  /** Compute import-graph fan metrics (fan-in / fan-out) for a single file. */
30
- export declare function getFanMetrics(ctx: GildashContext, filePath: string, project?: string): Promise<Result<FanMetrics, GildashError>>;
31
+ export declare function getFanMetrics(ctx: GildashContext, filePath: string, project?: string): Promise<FanMetrics>;