claude-db 0.8.4 → 0.8.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.5
4
+
5
+ ### Added
6
+
7
+ - **Using a type now produces a graph edge.**
8
+ ([#19](https://github.com/Avijit07x/claude-db/issues/19))
9
+ A type in argument, return, annotation or type-argument position matched no
10
+ rule, so all 985 interfaces and type aliases on one 214k-line repo had zero
11
+ inbound edges and `find_usages` reported every one of them as unused.
12
+ `type_identifier` is now a reference rule. Matching it directly would also
13
+ hit declaration sites and emit a self-edge for each, so `ReferenceRule` takes
14
+ an optional `excludeParents`, and the rule skips the seven parents that mean
15
+ a type is being declared rather than used. Measured on this repo: 2,387
16
+ reference edges and zero self-edges. This completes the second half of the
17
+ issue; rendering a component shipped in 0.8.4.
18
+
19
+ ### Fixed
20
+
21
+ - **Two declarations sharing a name and kind in one file collapsed into one
22
+ symbol.** ([#18](https://github.com/Avijit07x/claude-db/issues/18))
23
+ `symbolId` hashed project, file, name and kind with nothing positional, so
24
+ any two functions in a file that each declared `const total` produced a
25
+ single symbol and one of them was lost. On claude-db's own source that was 89
26
+ colliding groups and 115 symbols never stored. The id now carries the
27
+ occurrence index of the name within its file. The first occurrence keeps the
28
+ id it always had, so existing graphs do not churn; only the second and later
29
+ duplicates gain new ids. `SCAN_VERSION` is bumped so stored graphs rebuild.
30
+
3
31
  ## 0.8.4
4
32
 
5
33
  ### Fixed
@@ -19,9 +19,24 @@ const TYPED_DEFINITIONS = [
19
19
  { kind: 'type_alias_declaration', field: ['name'], symbol: 'type' },
20
20
  { kind: 'enum_declaration', field: ['name'], symbol: 'enum' },
21
21
  ];
22
+ const TYPE_DECLARATION_SITES = [
23
+ 'interface_declaration',
24
+ 'type_alias_declaration',
25
+ 'class_declaration',
26
+ 'abstract_class_declaration',
27
+ 'enum_declaration',
28
+ 'type_parameter',
29
+ 'implements_clause',
30
+ ];
22
31
  const TYPED_REFERENCES = [
23
32
  { kind: 'extends_clause', field: ['value'], relation: 'extends' },
24
33
  { kind: 'implements_clause', field: [], relation: 'implements' },
34
+ {
35
+ kind: 'type_identifier',
36
+ field: [],
37
+ relation: 'references',
38
+ excludeParents: TYPE_DECLARATION_SITES,
39
+ },
25
40
  ];
26
41
  export const typescript = {
27
42
  id: 'TypeScript',
@@ -9,6 +9,7 @@ export interface ReferenceRule {
9
9
  field: string[];
10
10
  relation: EdgeRelation;
11
11
  namePattern?: RegExp;
12
+ excludeParents?: string[];
12
13
  }
13
14
  export interface LanguageSpec {
14
15
  id: string;
@@ -13,6 +13,7 @@ export interface AstNode {
13
13
  kind(): string;
14
14
  range(): AstRange;
15
15
  field(name: string): AstNode | null;
16
+ parent(): AstNode | null;
16
17
  findAll(matcher: {
17
18
  rule: {
18
19
  kind: string;
@@ -12,5 +12,5 @@ export interface Extraction {
12
12
  symbols: CodeSymbol[];
13
13
  references: Reference[];
14
14
  }
15
- export declare function symbolId(project: string, file: string, name: string, kind: string): string;
15
+ export declare function symbolId(project: string, file: string, name: string, kind: string, index?: number): string;
16
16
  export declare function extractFile(file: SourceFile, project: string): Extraction;
@@ -4,16 +4,27 @@ import { callsIn, declarationsIn } from '../languages/index.js';
4
4
  import { languageHandle, loadParser } from '../parser.js';
5
5
  const CALLABLE = new Set(['function', 'method', 'class']);
6
6
  const IDENTIFIER = /^[\w$]+[?!]?$/;
7
- export function symbolId(project, file, name, kind) {
8
- return observationId('graph', 0, `${project}\0${file}\0${name}\0${kind}`);
7
+ export function symbolId(project, file, name, kind, index = 0) {
8
+ const seed = `${project}\0${file}\0${name}\0${kind}`;
9
+ return observationId('graph', 0, index === 0 ? seed : `${seed}\0${index}`);
10
+ }
11
+ function counter() {
12
+ const seen = new Map();
13
+ return (name, kind) => {
14
+ const key = `${name}\0${kind}`;
15
+ const index = seen.get(key) ?? 0;
16
+ seen.set(key, index + 1);
17
+ return index;
18
+ };
9
19
  }
10
20
  function extractByPattern(file, project) {
11
21
  const lines = file.source.split('\n');
12
22
  const symbols = [];
13
23
  const spans = [];
24
+ const occurrence = counter();
14
25
  for (const declaration of declarationsIn(file.source)) {
15
26
  const symbol = {
16
- id: symbolId(project, file.path, declaration.name, declaration.kind),
27
+ id: symbolId(project, file.path, declaration.name, declaration.kind, occurrence(declaration.name, declaration.kind)),
17
28
  project,
18
29
  name: declaration.name,
19
30
  kind: declaration.kind,
@@ -84,6 +95,7 @@ export function extractFile(file, project) {
84
95
  const lines = file.source.split('\n');
85
96
  const symbols = [];
86
97
  const spans = [];
98
+ const occurrence = counter();
87
99
  for (const rule of file.spec.definitions) {
88
100
  for (const node of root.findAll({ rule: { kind: rule.kind } })) {
89
101
  const named = resolveField(node, rule.field);
@@ -92,7 +104,7 @@ export function extractFile(file, project) {
92
104
  continue;
93
105
  const line = named.range().start.line + 1;
94
106
  const symbol = {
95
- id: symbolId(project, file.path, name, rule.symbol),
107
+ id: symbolId(project, file.path, name, rule.symbol, occurrence(name, rule.symbol)),
96
108
  project,
97
109
  name,
98
110
  kind: rule.symbol,
@@ -135,6 +147,8 @@ export function extractFile(file, project) {
135
147
  continue;
136
148
  if (rule.namePattern && !rule.namePattern.test(name))
137
149
  continue;
150
+ if (rule.excludeParents?.includes(node.parent()?.kind() ?? ''))
151
+ continue;
138
152
  const line = target.range().start.line + 1;
139
153
  references.push({
140
154
  file: file.path,
@@ -5,7 +5,7 @@ export interface SourceFile {
5
5
  source: string;
6
6
  hash: string;
7
7
  }
8
- export declare const SCAN_VERSION = 3;
8
+ export declare const SCAN_VERSION = 4;
9
9
  export declare function hashOf(bytes: Buffer): string;
10
10
  export declare function listFiles(root: string): string[];
11
11
  export declare function sourceFiles(root: string): string[];
@@ -5,7 +5,7 @@ import { join } from 'node:path';
5
5
  import { BASIC_FINGERPRINT, LANGUAGES, languageFor } from '../languages/index.js';
6
6
  const MAX_BUFFER = 64 * 1024 * 1024;
7
7
  const MAX_FILE_BYTES = 1024 * 1024;
8
- export const SCAN_VERSION = 3;
8
+ export const SCAN_VERSION = 4;
9
9
  const RULES_FINGERPRINT = createHash('sha256')
10
10
  .update(JSON.stringify(LANGUAGES, (_key, value) => (value instanceof RegExp ? String(value) : value)))
11
11
  .update(BASIC_FINGERPRINT)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "Persistent memory for Claude Code. Captures why decisions were made, not just which files changed. Bring your own database: SQLite, MongoDB or Postgres. No cloud, no subscription.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",