ts-knowledge-graph 0.1.1 → 0.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.
- package/README.md +34 -13
- package/contribs/web_visualisation/README.md +55 -0
- package/contribs/web_visualisation/web/css/style.css +115 -0
- package/contribs/web_visualisation/web/data/.gitignore +2 -0
- package/contribs/web_visualisation/web/index.html +58 -0
- package/contribs/web_visualisation/web/js/app.js +364 -0
- package/dist/agent/agent_tools.d.ts +13 -0
- package/dist/agent/agent_tools.d.ts.map +1 -0
- package/dist/agent/agent_tools.js +153 -0
- package/dist/agent/agent_tools.js.map +1 -0
- package/dist/agent/code_editor.d.ts +18 -0
- package/dist/agent/code_editor.d.ts.map +1 -0
- package/dist/agent/code_editor.js +43 -0
- package/dist/agent/code_editor.js.map +1 -0
- package/dist/agent/optimizer_agent.d.ts +30 -0
- package/dist/agent/optimizer_agent.d.ts.map +1 -0
- package/dist/agent/optimizer_agent.js +97 -0
- package/dist/agent/optimizer_agent.js.map +1 -0
- package/dist/cli.d.ts +0 -9
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +24 -208
- package/dist/cli.js.map +1 -1
- package/dist/commands/blast-radius.d.ts +5 -0
- package/dist/commands/blast-radius.d.ts.map +1 -0
- package/dist/commands/blast-radius.js +18 -0
- package/dist/commands/blast-radius.js.map +1 -0
- package/dist/commands/blast_radius.d.ts +5 -0
- package/dist/commands/blast_radius.d.ts.map +1 -0
- package/dist/commands/blast_radius.js +18 -0
- package/dist/commands/blast_radius.js.map +1 -0
- package/dist/commands/blast_radius_command.d.ts +5 -0
- package/dist/commands/blast_radius_command.d.ts.map +1 -0
- package/dist/commands/blast_radius_command.js +18 -0
- package/dist/commands/blast_radius_command.js.map +1 -0
- package/dist/commands/calls.d.ts +5 -0
- package/dist/commands/calls.d.ts.map +1 -0
- package/dist/commands/calls.js +7 -0
- package/dist/commands/calls.js.map +1 -0
- package/dist/commands/calls_command.d.ts +5 -0
- package/dist/commands/calls_command.d.ts.map +1 -0
- package/dist/commands/calls_command.js +7 -0
- package/dist/commands/calls_command.js.map +1 -0
- package/dist/commands/command-helpers.d.ts +15 -0
- package/dist/commands/command-helpers.d.ts.map +1 -0
- package/dist/commands/command-helpers.js +61 -0
- package/dist/commands/command-helpers.js.map +1 -0
- package/dist/commands/command_helpers.d.ts +15 -0
- package/dist/commands/command_helpers.d.ts.map +1 -0
- package/dist/commands/command_helpers.js +61 -0
- package/dist/commands/command_helpers.js.map +1 -0
- package/dist/commands/dead-exports.d.ts +5 -0
- package/dist/commands/dead-exports.d.ts.map +1 -0
- package/dist/commands/dead-exports.js +7 -0
- package/dist/commands/dead-exports.js.map +1 -0
- package/dist/commands/dead_exports.d.ts +5 -0
- package/dist/commands/dead_exports.d.ts.map +1 -0
- package/dist/commands/dead_exports.js +7 -0
- package/dist/commands/dead_exports.js.map +1 -0
- package/dist/commands/dead_exports_command.d.ts +5 -0
- package/dist/commands/dead_exports_command.d.ts.map +1 -0
- package/dist/commands/dead_exports_command.js +7 -0
- package/dist/commands/dead_exports_command.js.map +1 -0
- package/dist/commands/extract.d.ts +8 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +49 -0
- package/dist/commands/extract.js.map +1 -0
- package/dist/commands/extract_command.d.ts +8 -0
- package/dist/commands/extract_command.d.ts.map +1 -0
- package/dist/commands/extract_command.js +49 -0
- package/dist/commands/extract_command.js.map +1 -0
- package/dist/commands/find.d.ts +5 -0
- package/dist/commands/find.d.ts.map +1 -0
- package/dist/commands/find.js +7 -0
- package/dist/commands/find.js.map +1 -0
- package/dist/commands/find_command.d.ts +5 -0
- package/dist/commands/find_command.d.ts.map +1 -0
- package/dist/commands/find_command.js +7 -0
- package/dist/commands/find_command.js.map +1 -0
- package/dist/commands/install_command.d.ts +16 -0
- package/dist/commands/install_command.d.ts.map +1 -0
- package/dist/commands/install_command.js +42 -0
- package/dist/commands/install_command.js.map +1 -0
- package/dist/commands/load.d.ts +6 -0
- package/dist/commands/load.d.ts.map +1 -0
- package/dist/commands/load.js +28 -0
- package/dist/commands/load.js.map +1 -0
- package/dist/commands/load_command.d.ts +6 -0
- package/dist/commands/load_command.d.ts.map +1 -0
- package/dist/commands/load_command.js +28 -0
- package/dist/commands/load_command.js.map +1 -0
- package/dist/commands/neighbors.d.ts +5 -0
- package/dist/commands/neighbors.d.ts.map +1 -0
- package/dist/commands/neighbors.js +17 -0
- package/dist/commands/neighbors.js.map +1 -0
- package/dist/commands/neighbors_command.d.ts +5 -0
- package/dist/commands/neighbors_command.d.ts.map +1 -0
- package/dist/commands/neighbors_command.js +17 -0
- package/dist/commands/neighbors_command.js.map +1 -0
- package/dist/commands/optimize.d.ts +6 -0
- package/dist/commands/optimize.d.ts.map +1 -0
- package/dist/commands/optimize.js +59 -0
- package/dist/commands/optimize.js.map +1 -0
- package/dist/commands/optimize_command.d.ts +6 -0
- package/dist/commands/optimize_command.d.ts.map +1 -0
- package/dist/commands/optimize_command.js +59 -0
- package/dist/commands/optimize_command.js.map +1 -0
- package/dist/commands/references.d.ts +5 -0
- package/dist/commands/references.d.ts.map +1 -0
- package/dist/commands/references.js +17 -0
- package/dist/commands/references.js.map +1 -0
- package/dist/commands/references_command.d.ts +5 -0
- package/dist/commands/references_command.d.ts.map +1 -0
- package/dist/commands/references_command.js +17 -0
- package/dist/commands/references_command.js.map +1 -0
- package/dist/commands/web.d.ts +19 -0
- package/dist/commands/web.d.ts.map +1 -0
- package/dist/commands/web.js +120 -0
- package/dist/commands/web.js.map +1 -0
- package/dist/commands/web_command.d.ts +19 -0
- package/dist/commands/web_command.d.ts.map +1 -0
- package/dist/commands/web_command.js +120 -0
- package/dist/commands/web_command.js.map +1 -0
- package/dist/commands/who-calls.d.ts +5 -0
- package/dist/commands/who-calls.d.ts.map +1 -0
- package/dist/commands/who-calls.js +7 -0
- package/dist/commands/who-calls.js.map +1 -0
- package/dist/commands/who_calls.d.ts +5 -0
- package/dist/commands/who_calls.d.ts.map +1 -0
- package/dist/commands/who_calls.js +7 -0
- package/dist/commands/who_calls.js.map +1 -0
- package/dist/commands/who_calls_command.d.ts +5 -0
- package/dist/commands/who_calls_command.d.ts.map +1 -0
- package/dist/commands/who_calls_command.js +7 -0
- package/dist/commands/who_calls_command.js.map +1 -0
- package/dist/extract/graph_builder.d.ts +16 -0
- package/dist/extract/graph_builder.d.ts.map +1 -0
- package/dist/extract/graph_builder.js +39 -0
- package/dist/extract/graph_builder.js.map +1 -0
- package/dist/extract/node_id.d.ts +8 -0
- package/dist/extract/node_id.d.ts.map +1 -0
- package/dist/extract/node_id.js +22 -0
- package/dist/extract/node_id.js.map +1 -0
- package/dist/extract/project_loader.d.ts +5 -0
- package/dist/extract/project_loader.d.ts.map +1 -0
- package/dist/extract/project_loader.js +19 -0
- package/dist/extract/project_loader.js.map +1 -0
- package/dist/extract/semantic_extractor.d.ts +22 -0
- package/dist/extract/semantic_extractor.d.ts.map +1 -0
- package/dist/extract/semantic_extractor.js +254 -0
- package/dist/extract/semantic_extractor.js.map +1 -0
- package/dist/extract/structural_extractor.d.ts +18 -0
- package/dist/extract/structural_extractor.d.ts.map +1 -0
- package/dist/extract/structural_extractor.js +97 -0
- package/dist/extract/structural_extractor.js.map +1 -0
- package/dist/query/graph_query.d.ts +28 -0
- package/dist/query/graph_query.d.ts.map +1 -0
- package/dist/query/graph_query.js +93 -0
- package/dist/query/graph_query.js.map +1 -0
- package/dist/store/jsonl_reader.d.ts +11 -0
- package/dist/store/jsonl_reader.d.ts.map +1 -0
- package/dist/store/jsonl_reader.js +19 -0
- package/dist/store/jsonl_reader.js.map +1 -0
- package/dist/store/jsonl_store.d.ts +7 -0
- package/dist/store/jsonl_store.d.ts.map +1 -0
- package/dist/store/jsonl_store.js +13 -0
- package/dist/store/jsonl_store.js.map +1 -0
- package/dist/store/kuzu_store.d.ts +20 -0
- package/dist/store/kuzu_store.d.ts.map +1 -0
- package/dist/store/kuzu_store.js +66 -0
- package/dist/store/kuzu_store.js.map +1 -0
- package/package.json +6 -2
- package/skills/ts-knowledge-graph/SKILL.md +91 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { Connection, Database } from 'kuzu';
|
|
4
|
+
const SCHEMA = [
|
|
5
|
+
'CREATE NODE TABLE IF NOT EXISTS GraphNode (id STRING, kind STRING, name STRING, filePath STRING, exported BOOLEAN, startLine INT64, endLine INT64, PRIMARY KEY (id))',
|
|
6
|
+
'CREATE REL TABLE IF NOT EXISTS Edge (FROM GraphNode TO GraphNode, kind STRING)',
|
|
7
|
+
];
|
|
8
|
+
export class KuzuStore {
|
|
9
|
+
constructor(dbPath) {
|
|
10
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
11
|
+
this.db = new Database(dbPath);
|
|
12
|
+
this.conn = new Connection(this.db);
|
|
13
|
+
}
|
|
14
|
+
async initSchema() {
|
|
15
|
+
for (const statement of SCHEMA) {
|
|
16
|
+
KuzuStore.closeResults(await this.conn.query(statement));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async load(nodes, edges) {
|
|
20
|
+
const nodeStmt = await this.conn.prepare('MERGE (n:GraphNode {id: $id}) SET n.kind = $kind, n.name = $name, n.filePath = $filePath, n.exported = $exported, n.startLine = $startLine, n.endLine = $endLine');
|
|
21
|
+
for (const node of nodes) {
|
|
22
|
+
KuzuStore.closeResults(await this.conn.execute(nodeStmt, {
|
|
23
|
+
id: node.id,
|
|
24
|
+
kind: node.kind,
|
|
25
|
+
name: node.name,
|
|
26
|
+
filePath: node.filePath,
|
|
27
|
+
exported: node.exported ?? false,
|
|
28
|
+
startLine: node.range?.startLine ?? 0,
|
|
29
|
+
endLine: node.range?.endLine ?? 0,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
const edgeStmt = await this.conn.prepare('MATCH (f:GraphNode {id: $from}), (t:GraphNode {id: $to}) MERGE (f)-[:Edge {kind: $kind}]->(t)');
|
|
33
|
+
for (const edge of edges) {
|
|
34
|
+
KuzuStore.closeResults(await this.conn.execute(edgeStmt, { from: edge.from, to: edge.to, kind: edge.kind }));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async run(cypher, params) {
|
|
38
|
+
const result = params === undefined
|
|
39
|
+
? await this.conn.query(cypher)
|
|
40
|
+
: await this.conn.execute(await this.conn.prepare(cypher), params);
|
|
41
|
+
try {
|
|
42
|
+
return await KuzuStore.first(result).getAll();
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
KuzuStore.closeResults(result);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async close() {
|
|
49
|
+
await this.conn.close();
|
|
50
|
+
await this.db.close();
|
|
51
|
+
}
|
|
52
|
+
static first(result) {
|
|
53
|
+
return Array.isArray(result) ? result[0] : result;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Releases the native memory behind one or more query results. Results left
|
|
57
|
+
* unclosed are finalized after the database shuts down at process exit,
|
|
58
|
+
* which crashes the kuzu native module with a segmentation fault.
|
|
59
|
+
*/
|
|
60
|
+
static closeResults(result) {
|
|
61
|
+
for (const item of Array.isArray(result) ? result : [result]) {
|
|
62
|
+
item.close();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=kuzu_store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kuzu_store.js","sourceRoot":"","sources":["../../src/store/kuzu_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAe,MAAM,MAAM,CAAC;AAKzD,MAAM,MAAM,GAAG;IACd,sKAAsK;IACtK,gFAAgF;CAChF,CAAC;AAEF,MAAM,OAAO,SAAS;IAIrB,YAAY,MAAc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AAK,EAAE,CAAC;QACd,CAAC;IACF,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-knowledge-graph",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Parse TypeScript source into a knowledge graph for autonomous code optimization",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
|
+
"contribs/web_visualisation/web",
|
|
12
|
+
"skills/ts-knowledge-graph/SKILL.md",
|
|
11
13
|
"README.md",
|
|
12
14
|
"LICENSE",
|
|
13
15
|
".env-sample"
|
|
@@ -20,10 +22,12 @@
|
|
|
20
22
|
},
|
|
21
23
|
"scripts": {
|
|
22
24
|
"extract": "tsx src/cli.ts extract",
|
|
25
|
+
"web": "tsx src/cli.ts web",
|
|
23
26
|
"dev": "tsx src/cli.ts",
|
|
24
27
|
"build": "tsc -p tsconfig.build.json",
|
|
25
28
|
"publish:all": "npm run build && npm version patch && npm publish",
|
|
26
|
-
"typecheck": "tsc --noEmit"
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"test": "node --import tsx --test \"test/**/*.test.ts\""
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"chalk": "^5.3.0",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ts-knowledge-graph
|
|
3
|
+
description: >-
|
|
4
|
+
Query a TypeScript codebase as a knowledge graph to answer impact, caller,
|
|
5
|
+
dependency, and dead-code questions. Use this instead of grep/glob for
|
|
6
|
+
"who calls X", "what breaks if I change X" (blast radius), "is X dead code",
|
|
7
|
+
"what references this type", and "what is X connected to". Requires the
|
|
8
|
+
ts-knowledge-graph CLI and a built graph database.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# ts-knowledge-graph
|
|
12
|
+
|
|
13
|
+
Answer structural questions about a TypeScript project by querying a semantic
|
|
14
|
+
knowledge graph (built with the TypeScript compiler API) rather than reading or
|
|
15
|
+
grepping source files. The graph has resolved symbols and types, so its answers
|
|
16
|
+
are precise where text search is not.
|
|
17
|
+
|
|
18
|
+
## When to use this skill
|
|
19
|
+
|
|
20
|
+
Reach for these commands — not `Grep`/`Glob` — when the question is about code
|
|
21
|
+
structure or impact:
|
|
22
|
+
|
|
23
|
+
- **Callers** — "who calls this function?" → `who-calls`
|
|
24
|
+
- **Callees** — "what does this function call?" → `calls`
|
|
25
|
+
- **Impact / blast radius** — "what breaks if I change this?" → `blast-radius`
|
|
26
|
+
- **References** — "what uses this symbol or type?" → `references`
|
|
27
|
+
- **Dead code** — "which exports are unused?" → `dead-exports`
|
|
28
|
+
- **Neighbourhood** — "what is this connected to?" → `neighbors`
|
|
29
|
+
|
|
30
|
+
For reading the actual implementation of a known file, normal file tools are
|
|
31
|
+
still the right choice. Use this skill to decide *which* code matters first.
|
|
32
|
+
|
|
33
|
+
## Prerequisite: build the graph once
|
|
34
|
+
|
|
35
|
+
Querying needs a Kùzu database at `./outputs/graph.kuzu`. If it is missing,
|
|
36
|
+
build it first (the `--semantic` flag is required for `CALLS` and heritage
|
|
37
|
+
edges, which power `who-calls`, `calls`, and `blast-radius`):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx ts-knowledge-graph extract <path-to-project> --semantic # writes ./outputs/graph/*.jsonl
|
|
41
|
+
npx ts-knowledge-graph load # writes ./outputs/graph.kuzu
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Inside this repository's own checkout, substitute `npm run dev --` for the
|
|
45
|
+
`ts-knowledge-graph` binary (e.g. `npm run dev -- load`).
|
|
46
|
+
|
|
47
|
+
## Core workflow: names are not ids
|
|
48
|
+
|
|
49
|
+
Every query that inspects a symbol takes a **node id**, not a name. Resolve a
|
|
50
|
+
name to id(s) first with `find`, then pass an id to the other commands. Never
|
|
51
|
+
hand-write ids.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx ts-knowledge-graph find <name> --json # -> array of { id, name, kind, filePath, startLine }
|
|
55
|
+
npx ts-knowledge-graph who-calls <id> --json # use an id from the find result
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Always pass `--json`; consume the JSON, not the human-readable output.
|
|
59
|
+
|
|
60
|
+
## Command reference
|
|
61
|
+
|
|
62
|
+
All commands accept `--json` and `-d, --db <path>` (default `./outputs/graph.kuzu`).
|
|
63
|
+
|
|
64
|
+
| Command | Argument | Purpose |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `find <pattern>` | name substring | resolve a name to node id(s) |
|
|
67
|
+
| `who-calls <id>` | node id | direct callers of a symbol |
|
|
68
|
+
| `calls <id>` | node id | what a symbol directly calls |
|
|
69
|
+
| `blast-radius <id> [--depth <n>]` | node id | transitive callers / impact set (default depth 10) |
|
|
70
|
+
| `references <id>` | node id | everything referencing a symbol/type (calls, type usage, heritage, new) |
|
|
71
|
+
| `neighbors <id>` | node id | one-hop neighbourhood, inbound and outbound |
|
|
72
|
+
| `dead-exports` | (none) | exported symbols with no inbound references |
|
|
73
|
+
|
|
74
|
+
## Output contract
|
|
75
|
+
|
|
76
|
+
- `find`, `who-calls`, `calls`, `blast-radius`, `dead-exports` return a JSON
|
|
77
|
+
array of `SymbolRef`: `{ id, kind, name, filePath, startLine }`.
|
|
78
|
+
- `references` and `neighbors` return `NeighborRef`: a `SymbolRef` plus
|
|
79
|
+
`edgeKind` and `direction` (`"in"` or `"out"`).
|
|
80
|
+
|
|
81
|
+
## Worked example
|
|
82
|
+
|
|
83
|
+
> "Is it safe to change the signature of `loadProject`?"
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npx ts-knowledge-graph find loadProject --json # -> get its id
|
|
87
|
+
npx ts-knowledge-graph blast-radius <id> --json # -> every symbol transitively impacted
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Report the impacted set (file paths + names) as the blast radius, then read
|
|
91
|
+
those specific call sites to judge the change.
|