@grafema/cli 0.2.4-beta → 0.2.6-beta
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 +85 -0
- package/dist/cli.js +7 -2
- package/dist/cli.js.map +1 -0
- package/dist/commands/analyze.d.ts +3 -1
- package/dist/commands/analyze.d.ts.map +1 -1
- package/dist/commands/analyze.js +8 -266
- package/dist/commands/analyze.js.map +1 -0
- package/dist/commands/analyzeAction.d.ts +28 -0
- package/dist/commands/analyzeAction.d.ts.map +1 -0
- package/dist/commands/analyzeAction.js +243 -0
- package/dist/commands/analyzeAction.js.map +1 -0
- package/dist/commands/check.d.ts +2 -6
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +34 -48
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/context.d.ts +16 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +238 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/coverage.js +1 -0
- package/dist/commands/coverage.js.map +1 -0
- package/dist/commands/doctor/checks.d.ts.map +1 -1
- package/dist/commands/doctor/checks.js +10 -6
- package/dist/commands/doctor/checks.js.map +1 -0
- package/dist/commands/doctor/output.js +1 -0
- package/dist/commands/doctor/output.js.map +1 -0
- package/dist/commands/doctor/types.js +1 -0
- package/dist/commands/doctor/types.js.map +1 -0
- package/dist/commands/doctor.js +1 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/explain.d.ts.map +1 -1
- package/dist/commands/explain.js +5 -3
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/explore.d.ts.map +1 -1
- package/dist/commands/explore.js +9 -4
- package/dist/commands/explore.js.map +1 -0
- package/dist/commands/file.d.ts +15 -0
- package/dist/commands/file.d.ts.map +1 -0
- package/dist/commands/file.js +144 -0
- package/dist/commands/file.js.map +1 -0
- package/dist/commands/get.d.ts.map +1 -1
- package/dist/commands/get.js +7 -0
- package/dist/commands/get.js.map +1 -0
- package/dist/commands/impact.d.ts.map +1 -1
- package/dist/commands/impact.js +3 -3
- package/dist/commands/impact.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +20 -2
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +10 -2
- package/dist/commands/ls.js.map +1 -0
- package/dist/commands/overview.d.ts.map +1 -1
- package/dist/commands/overview.js +1 -0
- package/dist/commands/overview.js.map +1 -0
- package/dist/commands/query.d.ts +8 -0
- package/dist/commands/query.d.ts.map +1 -1
- package/dist/commands/query.js +217 -43
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/schema.d.ts.map +1 -1
- package/dist/commands/schema.js +4 -2
- package/dist/commands/schema.js.map +1 -0
- package/dist/commands/server.d.ts +2 -1
- package/dist/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +76 -14
- package/dist/commands/server.js.map +1 -0
- package/dist/commands/setup-skill.d.ts +17 -0
- package/dist/commands/setup-skill.d.ts.map +1 -0
- package/dist/commands/setup-skill.js +131 -0
- package/dist/commands/setup-skill.js.map +1 -0
- package/dist/commands/stats.js +1 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/commands/trace.d.ts.map +1 -1
- package/dist/commands/trace.js +21 -10
- package/dist/commands/trace.js.map +1 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/plugins/builtinPlugins.d.ts +10 -0
- package/dist/plugins/builtinPlugins.d.ts.map +1 -0
- package/dist/plugins/builtinPlugins.js +68 -0
- package/dist/plugins/builtinPlugins.js.map +1 -0
- package/dist/plugins/pluginLoader.d.ts +16 -0
- package/dist/plugins/pluginLoader.d.ts.map +1 -0
- package/dist/plugins/pluginLoader.js +101 -0
- package/dist/plugins/pluginLoader.js.map +1 -0
- package/dist/plugins/pluginResolver.js +38 -0
- package/dist/utils/codePreview.d.ts +1 -0
- package/dist/utils/codePreview.d.ts.map +1 -1
- package/dist/utils/codePreview.js +6 -3
- package/dist/utils/codePreview.js.map +1 -0
- package/dist/utils/errorFormatter.js +1 -0
- package/dist/utils/errorFormatter.js.map +1 -0
- package/dist/utils/formatNode.d.ts +1 -1
- package/dist/utils/formatNode.d.ts.map +1 -1
- package/dist/utils/formatNode.js +3 -2
- package/dist/utils/formatNode.js.map +1 -0
- package/dist/utils/pathUtils.d.ts +2 -0
- package/dist/utils/pathUtils.d.ts.map +1 -0
- package/dist/utils/pathUtils.js +9 -0
- package/dist/utils/pathUtils.js.map +1 -0
- package/dist/utils/progressRenderer.d.ts +119 -0
- package/dist/utils/progressRenderer.d.ts.map +1 -0
- package/dist/utils/progressRenderer.js +245 -0
- package/dist/utils/progressRenderer.js.map +1 -0
- package/dist/utils/spinner.d.ts +39 -0
- package/dist/utils/spinner.d.ts.map +1 -0
- package/dist/utils/spinner.js +84 -0
- package/dist/utils/spinner.js.map +1 -0
- package/package.json +8 -9
- package/skills/grafema-codebase-analysis/SKILL.md +295 -0
- package/skills/grafema-codebase-analysis/references/node-edge-types.md +123 -0
- package/skills/grafema-codebase-analysis/references/query-patterns.md +205 -0
- package/src/cli.ts +8 -2
- package/src/commands/analyze.ts +7 -342
- package/src/commands/analyzeAction.ts +284 -0
- package/src/commands/check.ts +38 -70
- package/src/commands/context.ts +309 -0
- package/src/commands/doctor/checks.ts +9 -6
- package/src/commands/explain.ts +4 -3
- package/src/commands/explore.tsx +15 -9
- package/src/commands/file.ts +179 -0
- package/src/commands/get.ts +8 -0
- package/src/commands/impact.ts +3 -4
- package/src/commands/init.ts +19 -3
- package/src/commands/ls.ts +11 -2
- package/src/commands/overview.ts +0 -4
- package/src/commands/query.ts +235 -44
- package/src/commands/schema.ts +3 -2
- package/src/commands/server.ts +85 -15
- package/src/commands/setup-skill.ts +162 -0
- package/src/commands/trace.ts +18 -9
- package/src/plugins/builtinPlugins.ts +108 -0
- package/src/plugins/pluginLoader.ts +123 -0
- package/src/plugins/pluginResolver.js +38 -0
- package/src/utils/codePreview.ts +7 -3
- package/src/utils/formatNode.ts +3 -3
- package/src/utils/pathUtils.ts +9 -0
- package/src/utils/progressRenderer.ts +288 -0
- package/src/utils/spinner.ts +94 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple terminal spinner for slow operations.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - TTY detection: silent in non-TTY environments (CI, pipes)
|
|
6
|
+
* - Delayed display: spinner only appears after 100ms to avoid flicker
|
|
7
|
+
* - Elapsed time: shows seconds for long operations
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const spinner = new Spinner('Querying graph...');
|
|
11
|
+
* spinner.start();
|
|
12
|
+
* await slowOperation();
|
|
13
|
+
* spinner.stop();
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT: Always call stop() BEFORE any console.log output.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Spinner {
|
|
18
|
+
private message;
|
|
19
|
+
private frames;
|
|
20
|
+
private interval;
|
|
21
|
+
private displayTimer;
|
|
22
|
+
private frameIndex;
|
|
23
|
+
private startTime;
|
|
24
|
+
private displayDelay;
|
|
25
|
+
private isSpinning;
|
|
26
|
+
constructor(message: string, displayDelay?: number);
|
|
27
|
+
/**
|
|
28
|
+
* Start the spinner. Spinner appears only after displayDelay ms.
|
|
29
|
+
* In non-TTY environments (CI, pipes), this is a no-op.
|
|
30
|
+
*/
|
|
31
|
+
start(): void;
|
|
32
|
+
private render;
|
|
33
|
+
/**
|
|
34
|
+
* Stop the spinner and clear the line.
|
|
35
|
+
* Safe to call multiple times or if spinner never started.
|
|
36
|
+
*/
|
|
37
|
+
stop(): void;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=spinner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../src/utils/spinner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAsD;IACpE,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,YAAY,CAA8C;IAClE,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,EAAE,MAAM,EAAE,YAAY,SAAM;IAK/C;;;OAGG;IACH,KAAK,IAAI,IAAI;IAqBb,OAAO,CAAC,MAAM;IAYd;;;OAGG;IACH,IAAI,IAAI,IAAI;CAqBb"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple terminal spinner for slow operations.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - TTY detection: silent in non-TTY environments (CI, pipes)
|
|
6
|
+
* - Delayed display: spinner only appears after 100ms to avoid flicker
|
|
7
|
+
* - Elapsed time: shows seconds for long operations
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const spinner = new Spinner('Querying graph...');
|
|
11
|
+
* spinner.start();
|
|
12
|
+
* await slowOperation();
|
|
13
|
+
* spinner.stop();
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT: Always call stop() BEFORE any console.log output.
|
|
16
|
+
*/
|
|
17
|
+
export class Spinner {
|
|
18
|
+
message;
|
|
19
|
+
frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
20
|
+
interval = null;
|
|
21
|
+
displayTimer = null;
|
|
22
|
+
frameIndex = 0;
|
|
23
|
+
startTime = 0;
|
|
24
|
+
displayDelay;
|
|
25
|
+
isSpinning = false;
|
|
26
|
+
constructor(message, displayDelay = 100) {
|
|
27
|
+
this.message = message;
|
|
28
|
+
this.displayDelay = displayDelay;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Start the spinner. Spinner appears only after displayDelay ms.
|
|
32
|
+
* In non-TTY environments (CI, pipes), this is a no-op.
|
|
33
|
+
*/
|
|
34
|
+
start() {
|
|
35
|
+
// TTY check - ora pattern
|
|
36
|
+
if (!process.stdout.isTTY) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.startTime = Date.now();
|
|
40
|
+
// Defer display to avoid flicker on fast queries
|
|
41
|
+
this.displayTimer = setTimeout(() => {
|
|
42
|
+
this.isSpinning = true;
|
|
43
|
+
this.render();
|
|
44
|
+
// Animate frames at 80ms interval
|
|
45
|
+
this.interval = setInterval(() => {
|
|
46
|
+
this.frameIndex = (this.frameIndex + 1) % this.frames.length;
|
|
47
|
+
this.render();
|
|
48
|
+
}, 80);
|
|
49
|
+
}, this.displayDelay);
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
if (!this.isSpinning)
|
|
53
|
+
return;
|
|
54
|
+
const frame = this.frames[this.frameIndex];
|
|
55
|
+
const elapsed = Math.floor((Date.now() - this.startTime) / 1000);
|
|
56
|
+
const timeStr = elapsed > 0 ? ` (${elapsed}s)` : '';
|
|
57
|
+
process.stdout.clearLine(0);
|
|
58
|
+
process.stdout.cursorTo(0);
|
|
59
|
+
process.stdout.write(`${frame} ${this.message}${timeStr}`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Stop the spinner and clear the line.
|
|
63
|
+
* Safe to call multiple times or if spinner never started.
|
|
64
|
+
*/
|
|
65
|
+
stop() {
|
|
66
|
+
// Clear deferred display timer
|
|
67
|
+
if (this.displayTimer) {
|
|
68
|
+
clearTimeout(this.displayTimer);
|
|
69
|
+
this.displayTimer = null;
|
|
70
|
+
}
|
|
71
|
+
// Stop animation
|
|
72
|
+
if (this.interval) {
|
|
73
|
+
clearInterval(this.interval);
|
|
74
|
+
this.interval = null;
|
|
75
|
+
}
|
|
76
|
+
// Clear line if we were displaying
|
|
77
|
+
if (this.isSpinning && process.stdout.isTTY) {
|
|
78
|
+
process.stdout.clearLine(0);
|
|
79
|
+
process.stdout.cursorTo(0);
|
|
80
|
+
}
|
|
81
|
+
this.isSpinning = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=spinner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.js","sourceRoot":"","sources":["../../src/utils/spinner.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafema/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6-beta",
|
|
4
4
|
"description": "CLI for Grafema code analysis toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cli.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
|
-
"src"
|
|
19
|
+
"src",
|
|
20
|
+
"skills"
|
|
20
21
|
],
|
|
21
22
|
"keywords": [
|
|
22
23
|
"grafema",
|
|
@@ -28,25 +29,23 @@
|
|
|
28
29
|
"author": "Vadim Reshetnikov",
|
|
29
30
|
"repository": {
|
|
30
31
|
"type": "git",
|
|
31
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/Disentinel/grafema.git",
|
|
32
33
|
"directory": "packages/cli"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"commander": "^13.0.0",
|
|
36
|
-
"ink": "^6.6.0",
|
|
37
|
-
"ink-text-input": "^6.0.0",
|
|
38
|
-
"react": "^19.2.3",
|
|
39
37
|
"yaml": "^2.8.2",
|
|
40
|
-
"@grafema/core": "0.2.
|
|
41
|
-
"@grafema/types": "0.2.
|
|
38
|
+
"@grafema/core": "0.2.6-beta",
|
|
39
|
+
"@grafema/types": "0.2.6-beta",
|
|
40
|
+
"@grafema/api": "0.2.6-beta"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@types/node": "^25.0.8",
|
|
45
|
-
"@types/react": "^19.2.9",
|
|
46
44
|
"typescript": "^5.9.3"
|
|
47
45
|
},
|
|
48
46
|
"scripts": {
|
|
49
47
|
"build": "tsc",
|
|
48
|
+
"postbuild": "mkdir -p dist/plugins && cp src/plugins/pluginResolver.js dist/plugins/",
|
|
50
49
|
"clean": "rm -rf dist",
|
|
51
50
|
"start": "node dist/cli.js",
|
|
52
51
|
"test": "node --import tsx --test test/*.test.ts"
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: grafema-codebase-analysis
|
|
3
|
+
description: >
|
|
4
|
+
Analyze codebases using a graph database instead of reading source files.
|
|
5
|
+
Use when understanding code architecture, finding functions or call patterns,
|
|
6
|
+
tracing data flow, checking dependencies, or answering "where is X used?"
|
|
7
|
+
questions. Grafema builds a queryable code graph from static analysis —
|
|
8
|
+
prefer querying the graph over reading files manually.
|
|
9
|
+
license: Apache-2.0
|
|
10
|
+
compatibility: Requires Grafema MCP server configured (grafema or @grafema/mcp package)
|
|
11
|
+
metadata:
|
|
12
|
+
author: Grafema
|
|
13
|
+
version: "0.2.5"
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Grafema: Graph-Based Codebase Analysis
|
|
17
|
+
|
|
18
|
+
## Core Principle
|
|
19
|
+
|
|
20
|
+
**Query the graph, not read code.**
|
|
21
|
+
|
|
22
|
+
Grafema builds a graph database from your codebase via static analysis.
|
|
23
|
+
Instead of reading dozens of files to understand how code connects,
|
|
24
|
+
query the graph to get structured, complete answers instantly.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
BAD: Read 20 files hoping to find all callers of a function
|
|
28
|
+
GOOD: find_calls({ name: "processPayment" }) -> get all callers in one query
|
|
29
|
+
|
|
30
|
+
BAD: Grep for variable name across files, miss aliased references
|
|
31
|
+
GOOD: trace_dataflow({ source: "userInput", direction: "forward" }) -> complete data flow
|
|
32
|
+
|
|
33
|
+
BAD: Read file by file to understand module dependencies
|
|
34
|
+
GOOD: get_file_overview({ file: "src/api.ts" }) -> structured imports, exports, classes, functions
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### When to Use Grafema
|
|
38
|
+
|
|
39
|
+
- Finding where functions/methods are called
|
|
40
|
+
- Understanding module dependencies and imports
|
|
41
|
+
- Tracing data flow (forward or backward)
|
|
42
|
+
- Getting function details (signature, callers, callees)
|
|
43
|
+
- Checking code invariants with Datalog rules
|
|
44
|
+
- Exploring file structure and entity relationships
|
|
45
|
+
|
|
46
|
+
### When NOT to Use Grafema
|
|
47
|
+
|
|
48
|
+
- Reading a single specific file (use your editor/Read tool — faster)
|
|
49
|
+
- Editing code (Grafema is read-only analysis)
|
|
50
|
+
- Runtime behavior questions (Grafema is static analysis)
|
|
51
|
+
- Files not yet analyzed (run `analyze_project` first)
|
|
52
|
+
|
|
53
|
+
## Essential Tools (Tier 1)
|
|
54
|
+
|
|
55
|
+
These 5 tools handle ~80% of queries. Start here.
|
|
56
|
+
|
|
57
|
+
### find_nodes — Find entities by type, name, or file
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
find_nodes({ type: "FUNCTION", name: "validateUser" })
|
|
61
|
+
find_nodes({ type: "CLASS", file: "src/auth.ts" })
|
|
62
|
+
find_nodes({ type: "http:request" })
|
|
63
|
+
find_nodes({ type: "MODULE" })
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Use when:** "Find all X", "What functions are in file Y", "List all routes"
|
|
67
|
+
|
|
68
|
+
**Node types:** MODULE, FUNCTION, METHOD, CLASS, VARIABLE, PARAMETER,
|
|
69
|
+
CALL, PROPERTY_ACCESS, METHOD_CALL, CALL_SITE,
|
|
70
|
+
http:route, http:request, db:query, socketio:emit, socketio:on
|
|
71
|
+
|
|
72
|
+
### find_calls — Find function/method call sites
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
find_calls({ name: "processPayment" })
|
|
76
|
+
find_calls({ name: "query", className: "Database" })
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Use when:** "Where is X called?", "Who calls this function?", "Find all usages"
|
|
80
|
+
|
|
81
|
+
Returns call sites with file locations and whether the target is resolved.
|
|
82
|
+
|
|
83
|
+
### get_function_details — Complete function info
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
get_function_details({ name: "handleRequest" })
|
|
87
|
+
get_function_details({ name: "validate", file: "src/auth.ts" })
|
|
88
|
+
get_function_details({ name: "processOrder", transitive: true })
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Use when:** "What does function X do?", "What does it call?", "Who calls it?"
|
|
92
|
+
|
|
93
|
+
Returns: signature, parameters, what it calls, who calls it.
|
|
94
|
+
Use `transitive: true` to follow call chains (A calls B calls C, max depth 5).
|
|
95
|
+
|
|
96
|
+
### get_context — Deep context for any node
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
get_context({ semanticId: "src/api.ts:handleRequest#fn" })
|
|
100
|
+
get_context({ semanticId: "src/db.ts:Database#class", edgeType: "CALLS" })
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Use when:** "Tell me everything about this entity", "Show me its relationships"
|
|
104
|
+
|
|
105
|
+
Returns: node info, source code, ALL incoming/outgoing edges with code context.
|
|
106
|
+
Use after `find_nodes` to deep-dive into a specific result.
|
|
107
|
+
|
|
108
|
+
### trace_dataflow — Trace data flow
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
trace_dataflow({ source: "userInput", file: "src/handler.ts", direction: "forward" })
|
|
112
|
+
trace_dataflow({ source: "dbResult", file: "src/query.ts", direction: "backward" })
|
|
113
|
+
trace_dataflow({ source: "config", direction: "both", max_depth: 5 })
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Use when:** "Where does this value end up?", "Where does this data come from?",
|
|
117
|
+
"Is user input reaching the database unsanitized?"
|
|
118
|
+
|
|
119
|
+
Directions: `forward` (where does it go?), `backward` (where did it come from?), `both`.
|
|
120
|
+
|
|
121
|
+
## Decision Tree
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
START: What do you need?
|
|
125
|
+
|
|
|
126
|
+
|-- "Find entities (functions, classes, routes)"
|
|
127
|
+
| -> find_nodes({ type, name, file })
|
|
128
|
+
|
|
|
129
|
+
|-- "Find who calls function X"
|
|
130
|
+
| -> find_calls({ name: "X" })
|
|
131
|
+
| -> For full details: get_function_details({ name: "X" })
|
|
132
|
+
|
|
|
133
|
+
|-- "Understand a specific entity deeply"
|
|
134
|
+
| -> First: find_nodes to get its semantic ID
|
|
135
|
+
| -> Then: get_context({ semanticId: "..." })
|
|
136
|
+
|
|
|
137
|
+
|-- "Trace data flow"
|
|
138
|
+
| -> trace_dataflow({ source, file, direction })
|
|
139
|
+
|
|
|
140
|
+
|-- "Understand a file's structure"
|
|
141
|
+
| -> get_file_overview({ file: "path/to/file.ts" })
|
|
142
|
+
|
|
|
143
|
+
|-- "Trace an alias/re-export chain"
|
|
144
|
+
| -> trace_alias({ variableName: "alias", file: "path.ts" })
|
|
145
|
+
|
|
|
146
|
+
|-- "Check a code rule/invariant"
|
|
147
|
+
| -> check_invariant({ rule: "violation(X) :- ..." })
|
|
148
|
+
|
|
|
149
|
+
|-- "Custom complex query"
|
|
150
|
+
| -> query_graph({ query: "violation(X) :- ..." })
|
|
151
|
+
| -> See references/query-patterns.md for Datalog syntax
|
|
152
|
+
|
|
|
153
|
+
|-- "Explore unknown codebase"
|
|
154
|
+
| -> get_stats() for high-level overview
|
|
155
|
+
| -> get_schema() for available node/edge types
|
|
156
|
+
| -> find_nodes({ type: "MODULE" }) for module list
|
|
157
|
+
| -> get_file_overview for specific files
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Common Workflows
|
|
161
|
+
|
|
162
|
+
### 1. Impact Analysis: "What breaks if I change function X?"
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
get_function_details({ name: "X", transitive: true })
|
|
166
|
+
-> Check calledBy array for all callers (direct + transitive)
|
|
167
|
+
-> For critical callers: get_context({ semanticId }) for full picture
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 2. Security Audit: "Does user input reach the database?"
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
find_nodes({ type: "http:request" })
|
|
174
|
+
-> For each route, trace_dataflow({ source: requestParam, direction: "forward" })
|
|
175
|
+
-> Check if flow reaches db:query nodes
|
|
176
|
+
-> Use find_guards to check for sanitization
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 3. Onboarding: "How is this codebase structured?"
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
get_stats() -> Node/edge counts by type
|
|
183
|
+
find_nodes({ type: "MODULE" }) -> All modules
|
|
184
|
+
get_file_overview({ file: "src/index.ts" }) -> Entry point structure
|
|
185
|
+
find_nodes({ type: "http:request" }) -> All API endpoints
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 4. Dependency Analysis: "What does module X depend on?"
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
get_file_overview({ file: "src/service.ts" })
|
|
192
|
+
-> Check imports section for dependencies
|
|
193
|
+
-> For each import: get_context for deeper relationships
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 5. Find Dead Code: "What functions have no callers?"
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
query_graph({
|
|
200
|
+
query: 'violation(X) :- node(X, "FUNCTION"), \\+ edge(_, X, "CALLS").'
|
|
201
|
+
})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Anti-Patterns
|
|
205
|
+
|
|
206
|
+
**Don't read files to find call sites.** Use `find_calls` — it finds ALL callers across
|
|
207
|
+
the entire codebase, including indirect references you'd miss by grepping.
|
|
208
|
+
|
|
209
|
+
**Don't use `query_graph` for simple lookups.** `find_nodes`, `find_calls`, and
|
|
210
|
+
`get_function_details` are optimized for common queries. Reserve Datalog for
|
|
211
|
+
complex patterns (joins, transitive closure, invariant checks).
|
|
212
|
+
|
|
213
|
+
**Don't skip analysis status.** If you just ran `analyze_project`, check
|
|
214
|
+
`get_analysis_status` before querying — partial results are misleading.
|
|
215
|
+
|
|
216
|
+
**Don't request excessive depth.** `get_context` with no filters returns everything.
|
|
217
|
+
Use `edgeType` filter to focus on specific relationships (e.g., `"CALLS,ASSIGNED_FROM"`).
|
|
218
|
+
|
|
219
|
+
**Don't use Grafema for single-file questions.** If you only need to read one file,
|
|
220
|
+
use your editor. Grafema shines for cross-file relationships.
|
|
221
|
+
|
|
222
|
+
## Advanced Tools (Tier 2)
|
|
223
|
+
|
|
224
|
+
### query_graph — Custom Datalog queries
|
|
225
|
+
|
|
226
|
+
For complex patterns not covered by high-level tools.
|
|
227
|
+
See [references/query-patterns.md](references/query-patterns.md) for syntax and examples.
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
query_graph({
|
|
231
|
+
query: "violation(X) :- node(X, \"CALL\"), attr(X, \"name\", \"eval\").",
|
|
232
|
+
explain: true
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Available predicates: `node(Id, Type)`, `edge(Src, Dst, Type)`, `attr(Id, Name, Value)`.
|
|
237
|
+
Must define `violation/1` predicate for results. Use `explain: true` to debug empty results.
|
|
238
|
+
|
|
239
|
+
### get_file_overview — File-level structure
|
|
240
|
+
|
|
241
|
+
Structured overview of imports, exports, classes, functions, variables with relationships.
|
|
242
|
+
Recommended first step when exploring a specific file before using `get_context`.
|
|
243
|
+
|
|
244
|
+
### trace_alias — Resolve alias chains
|
|
245
|
+
|
|
246
|
+
For code like `const alias = obj.method; alias()` — traces "alias" back to "obj.method".
|
|
247
|
+
|
|
248
|
+
### get_schema — Available types
|
|
249
|
+
|
|
250
|
+
Returns all node and edge types in the graph. Use when you need exact type names.
|
|
251
|
+
|
|
252
|
+
### check_invariant — Code rule checking
|
|
253
|
+
|
|
254
|
+
Check if a Datalog rule has violations. For persistent rules, use `create_guarantee`.
|
|
255
|
+
|
|
256
|
+
## Specialized Tools (Tier 3)
|
|
257
|
+
|
|
258
|
+
| Tool | Purpose |
|
|
259
|
+
|------|---------|
|
|
260
|
+
| get_stats | Graph statistics (node/edge counts by type) |
|
|
261
|
+
| get_coverage | Analysis coverage for a path |
|
|
262
|
+
| find_guards | Conditional guards protecting a node |
|
|
263
|
+
| create_guarantee | Create persistent code invariant |
|
|
264
|
+
| list_guarantees | List all guarantees |
|
|
265
|
+
| check_guarantees | Check guarantee violations |
|
|
266
|
+
| delete_guarantee | Remove a guarantee |
|
|
267
|
+
| discover_services | Discover services without full analysis |
|
|
268
|
+
| analyze_project | Run/re-run analysis |
|
|
269
|
+
| get_analysis_status | Check analysis progress |
|
|
270
|
+
| read_project_structure | Directory tree |
|
|
271
|
+
| write_config | Update .grafema/config.yaml |
|
|
272
|
+
| get_documentation | Grafema usage docs |
|
|
273
|
+
| report_issue | Report bugs |
|
|
274
|
+
|
|
275
|
+
## Troubleshooting
|
|
276
|
+
|
|
277
|
+
**Query returns nothing?**
|
|
278
|
+
1. Check analysis ran: `get_analysis_status`
|
|
279
|
+
2. Check type names: `get_schema` for available types
|
|
280
|
+
3. Use `explain: true` in `query_graph` to debug
|
|
281
|
+
4. Check file paths match (relative to project root)
|
|
282
|
+
|
|
283
|
+
**Need help with Datalog syntax?**
|
|
284
|
+
- See [references/query-patterns.md](references/query-patterns.md)
|
|
285
|
+
- Use `get_documentation({ topic: "queries" })` for inline help
|
|
286
|
+
|
|
287
|
+
**Graph seems incomplete?**
|
|
288
|
+
- Run `get_coverage({ path: "src/" })` to check coverage
|
|
289
|
+
- Re-analyze with `analyze_project({ force: true })`
|
|
290
|
+
- Check `.grafema/config.yaml` for include/exclude patterns
|
|
291
|
+
|
|
292
|
+
## References
|
|
293
|
+
|
|
294
|
+
- [Node and Edge Types](references/node-edge-types.md) — Complete graph schema
|
|
295
|
+
- [Query Patterns](references/query-patterns.md) — Datalog cookbook with examples
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Grafema Graph Schema: Node and Edge Types
|
|
2
|
+
|
|
3
|
+
## Node Types
|
|
4
|
+
|
|
5
|
+
### Core Entities
|
|
6
|
+
|
|
7
|
+
| Type | Description | Key Attributes |
|
|
8
|
+
|------|-------------|----------------|
|
|
9
|
+
| `MODULE` | A source file/module | name, file |
|
|
10
|
+
| `FUNCTION` | Function declaration | name, file, line, async |
|
|
11
|
+
| `METHOD` | Class method | name, file, line, className |
|
|
12
|
+
| `CLASS` | Class declaration | name, file, line |
|
|
13
|
+
| `VARIABLE` | Variable declaration | name, file, line, kind (const/let/var) |
|
|
14
|
+
| `PARAMETER` | Function parameter | name, file, line, index |
|
|
15
|
+
|
|
16
|
+
### Call & Access Nodes
|
|
17
|
+
|
|
18
|
+
| Type | Description | Key Attributes |
|
|
19
|
+
|------|-------------|----------------|
|
|
20
|
+
| `CALL` | Function call expression | name, file, line, resolved |
|
|
21
|
+
| `METHOD_CALL` | Method call expression | name, file, line, object, resolved |
|
|
22
|
+
| `CALL_SITE` | Call site context | file, line |
|
|
23
|
+
| `PROPERTY_ACCESS` | Property access (obj.prop) | name, object, file, line |
|
|
24
|
+
|
|
25
|
+
### Domain-Specific Nodes
|
|
26
|
+
|
|
27
|
+
| Type | Description | Key Attributes |
|
|
28
|
+
|------|-------------|----------------|
|
|
29
|
+
| `http:route` | HTTP route definition | path, method |
|
|
30
|
+
| `http:request` | HTTP request handler | path, method, file, line |
|
|
31
|
+
| `db:query` | Database query | file, line |
|
|
32
|
+
| `socketio:emit` | Socket.IO emit call | event, file, line |
|
|
33
|
+
| `socketio:on` | Socket.IO event listener | event, file, line |
|
|
34
|
+
|
|
35
|
+
### Structural Nodes
|
|
36
|
+
|
|
37
|
+
| Type | Description |
|
|
38
|
+
|------|-------------|
|
|
39
|
+
| `SCOPE` | Code scope (function body, if block, loop) |
|
|
40
|
+
| `OBJECT_LITERAL` | Object literal expression |
|
|
41
|
+
| `ARRAY_LITERAL` | Array literal expression |
|
|
42
|
+
| `LITERAL` | Primitive literal value |
|
|
43
|
+
| `IMPORT` | Import declaration |
|
|
44
|
+
| `EXPORT` | Export declaration |
|
|
45
|
+
|
|
46
|
+
## Edge Types
|
|
47
|
+
|
|
48
|
+
| Type | Direction | Description |
|
|
49
|
+
|------|-----------|-------------|
|
|
50
|
+
| `CONTAINS` | Parent -> Child | Structural containment (module contains function) |
|
|
51
|
+
| `CALLS` | Caller -> Callee | Function/method call relationship |
|
|
52
|
+
| `DEPENDS_ON` | Module -> Module | Module dependency (import) |
|
|
53
|
+
| `ASSIGNED_FROM` | Variable -> Source | Value assignment source |
|
|
54
|
+
| `INSTANCE_OF` | Instance -> Class | Class instantiation |
|
|
55
|
+
| `PASSES_ARGUMENT` | Call -> Value | Argument passing at call site |
|
|
56
|
+
| `HAS_SCOPE` | Function -> Scope | Function's scope chain |
|
|
57
|
+
| `EXTENDS` | Class -> Class | Class inheritance |
|
|
58
|
+
| `IMPLEMENTS` | Class -> Interface | Interface implementation |
|
|
59
|
+
| `RETURNS` | Function -> Type | Return type relationship |
|
|
60
|
+
| `DATAFLOW` | Source -> Sink | Data flow edge |
|
|
61
|
+
| `GUARDED_BY` | Node -> Scope | Conditional guard relationship |
|
|
62
|
+
|
|
63
|
+
## Common Attribute Names
|
|
64
|
+
|
|
65
|
+
These can be used with `attr(Id, Name, Value)` in Datalog queries:
|
|
66
|
+
|
|
67
|
+
| Attribute | Types | Description |
|
|
68
|
+
|-----------|-------|-------------|
|
|
69
|
+
| `name` | All named nodes | Entity name |
|
|
70
|
+
| `file` | All nodes | Source file path (relative) |
|
|
71
|
+
| `line` | All located nodes | Line number |
|
|
72
|
+
| `column` | All located nodes | Column number |
|
|
73
|
+
| `type` | All nodes | Node type (via `node(Id, Type)`) |
|
|
74
|
+
| `async` | FUNCTION, METHOD | Is async function |
|
|
75
|
+
| `kind` | VARIABLE | const, let, or var |
|
|
76
|
+
| `method` | http:request | HTTP method (GET, POST, etc.) |
|
|
77
|
+
| `path` | http:request, http:route | URL path pattern |
|
|
78
|
+
| `resolved` | CALL, METHOD_CALL | Whether call target is resolved |
|
|
79
|
+
| `object` | METHOD_CALL, PROPERTY_ACCESS | Receiver object name |
|
|
80
|
+
| `className` | METHOD | Owning class name |
|
|
81
|
+
| `event` | socketio:emit, socketio:on | Socket.IO event name |
|
|
82
|
+
|
|
83
|
+
## Quick Reference: Finding Common Patterns
|
|
84
|
+
|
|
85
|
+
### Find all functions
|
|
86
|
+
```
|
|
87
|
+
node(X, "FUNCTION")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Find all classes
|
|
91
|
+
```
|
|
92
|
+
node(X, "CLASS")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Find all HTTP endpoints
|
|
96
|
+
```
|
|
97
|
+
node(X, "http:request")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Find calls to a specific function
|
|
101
|
+
```
|
|
102
|
+
node(X, "CALL"), attr(X, "name", "targetFunction")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Find all methods of a class
|
|
106
|
+
```
|
|
107
|
+
node(C, "CLASS"), attr(C, "name", "MyClass"), edge(C, M, "CONTAINS"), node(M, "METHOD")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Find module dependencies
|
|
111
|
+
```
|
|
112
|
+
edge(A, B, "DEPENDS_ON"), node(A, "MODULE"), node(B, "MODULE")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Find data flow from a variable
|
|
116
|
+
```
|
|
117
|
+
node(X, "VARIABLE"), attr(X, "name", "myVar"), edge(X, Y, "DATAFLOW")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Find unresolved calls
|
|
121
|
+
```
|
|
122
|
+
node(X, "CALL"), attr(X, "resolved", "false")
|
|
123
|
+
```
|