@psnext/lscg 0.1.1
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 +143 -0
- package/dist/bin/lscg.d.ts +3 -0
- package/dist/bin/lscg.js +11 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +524 -0
- package/dist/src/config/paths.d.ts +12 -0
- package/dist/src/config/paths.js +54 -0
- package/dist/src/graph/attribution.d.ts +8 -0
- package/dist/src/graph/attribution.js +112 -0
- package/dist/src/graph/extract.d.ts +4 -0
- package/dist/src/graph/extract.js +199 -0
- package/dist/src/graph/repository.d.ts +93 -0
- package/dist/src/graph/repository.js +361 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +5 -0
- package/dist/src/mcp/server.d.ts +6 -0
- package/dist/src/mcp/server.js +81 -0
- package/dist/src/parser/treeSitter.d.ts +13 -0
- package/dist/src/parser/treeSitter.js +61 -0
- package/dist/src/scanner/discover.d.ts +4 -0
- package/dist/src/scanner/discover.js +62 -0
- package/dist/src/scanner/fingerprint.d.ts +3 -0
- package/dist/src/scanner/fingerprint.js +27 -0
- package/dist/src/storage/database.d.ts +72 -0
- package/dist/src/storage/database.js +563 -0
- package/dist/src/storage/schema.d.ts +4 -0
- package/dist/src/storage/schema.js +93 -0
- package/dist/src/types.d.ts +233 -0
- package/dist/src/types.js +2 -0
- package/dist/src/view/index.d.ts +27 -0
- package/dist/src/view/index.js +42 -0
- package/dist/src/view/layout.d.ts +28 -0
- package/dist/src/view/layout.js +235 -0
- package/dist/src/view/model.d.ts +64 -0
- package/dist/src/view/model.js +396 -0
- package/dist/src/view/open.d.ts +15 -0
- package/dist/src/view/open.js +37 -0
- package/dist/src/view/render.d.ts +9 -0
- package/dist/src/view/render.js +321 -0
- package/dist/src/watch.d.ts +40 -0
- package/dist/src/watch.js +118 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# lscg
|
|
2
|
+
|
|
3
|
+
Local source context graphs for repositories. `lscg` parses code with
|
|
4
|
+
Tree-sitter, stores discovered nodes and edges in SQLite, and exposes the graph
|
|
5
|
+
through both a CLI and an MCP server.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js 24+
|
|
10
|
+
- npm install scripts allowed for Tree-sitter native packages
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## CLI
|
|
19
|
+
|
|
20
|
+
Use global help to list commands, or ask any operational command for focused usage, supported options, and examples with `--help` or `-h`:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
lscg --help
|
|
24
|
+
lscg context --help
|
|
25
|
+
lscg callgraph -h
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The positional form `lscg <command> help` is not a command-help alias; `help` remains available as a normal command argument.
|
|
29
|
+
|
|
30
|
+
Common option aliases are `-r`/`--root`, `-s`/`--scope`, `-k`/`--kind`, `-d`/`--depth`, `-l`/`--limit`, `-f`/`--file`, and `-o`/`--output` where the command supports the corresponding option. `callgraph` and `context` use text output by default; pass `--output json` when machine-readable JSON is needed.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Create repo-local and home-level graph databases
|
|
34
|
+
npm start -- init --scope both
|
|
35
|
+
|
|
36
|
+
# Scan the current repository into both graph scopes
|
|
37
|
+
npm start -- scan --scope both
|
|
38
|
+
|
|
39
|
+
# Watch the current repository and rescan on scanner-relevant changes
|
|
40
|
+
npm run watch
|
|
41
|
+
npm run scan:watch
|
|
42
|
+
npm start -- watch
|
|
43
|
+
npm start -- scan --watch
|
|
44
|
+
|
|
45
|
+
# Retrieve bounded context around a symbol (JSON envelope)
|
|
46
|
+
npm start -- context greet --kind symbol
|
|
47
|
+
npm start -- context greet --depth 2 --limit 25
|
|
48
|
+
npm start -- context greet --file src/app.ts --excerpts --excerpt-lines 40 --excerpt-bytes 8000
|
|
49
|
+
npm start -- context greet --output text
|
|
50
|
+
npm start -- context greet --output svg > /tmp/context.svg
|
|
51
|
+
|
|
52
|
+
# Inspect graph contents
|
|
53
|
+
npm start -- status --scope repo
|
|
54
|
+
npm start -- nodes --limit 20
|
|
55
|
+
npm start -- nodes greet --kind symbol --limit 20
|
|
56
|
+
npm start -- nodes greet --output text
|
|
57
|
+
npm start -- edges --kind calls --limit 20
|
|
58
|
+
npm start -- edges --kind attributed_to --limit 20
|
|
59
|
+
npm start -- neighbors <node-id> --depth 2
|
|
60
|
+
|
|
61
|
+
# Visualize the graph
|
|
62
|
+
npm start -- view --scope repo
|
|
63
|
+
npm start -- view --scope home --anchor greet --search util
|
|
64
|
+
npm start -- view --output /tmp/lscg-view.svg
|
|
65
|
+
|
|
66
|
+
# Run a read-only SQL query
|
|
67
|
+
npm start -- query "select kind, count(*) as n from nodes group by kind"
|
|
68
|
+
|
|
69
|
+
# Start the MCP server over stdio
|
|
70
|
+
npm start -- mcp
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
When installed as a package, the binary names are `lscg` and `context-graph`.
|
|
74
|
+
|
|
75
|
+
## MCP tools
|
|
76
|
+
|
|
77
|
+
The MCP server exposes:
|
|
78
|
+
|
|
79
|
+
- `context_graph_scan`
|
|
80
|
+
- `context_graph_status`
|
|
81
|
+
- `context_graph_nodes`
|
|
82
|
+
- `context_graph_edges`
|
|
83
|
+
- `context_graph_neighbors`
|
|
84
|
+
- `context_graph_query`
|
|
85
|
+
|
|
86
|
+
## Storage
|
|
87
|
+
|
|
88
|
+
- Repo database: `.sling/graph.sqlite`
|
|
89
|
+
- Home database: `~/.sling/graph.sqlite`
|
|
90
|
+
|
|
91
|
+
Use `--scope repo`, `--scope home`, or `--scope both` on commands that read or
|
|
92
|
+
write graph data.
|
|
93
|
+
|
|
94
|
+
`lscg view` opens a temporary interactive HTML page by default and shows the
|
|
95
|
+
anchor-centered subgraph for the selected scope when no `--anchor` is provided.
|
|
96
|
+
The browser view includes a toggle to switch between the subgraph and the full
|
|
97
|
+
graph. Pass `--search` to filter within the active graph mode, or `--output
|
|
98
|
+
<path>` to write a static SVG snapshot of the default subgraph instead of
|
|
99
|
+
opening a browser.
|
|
100
|
+
|
|
101
|
+
Examples:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
lscg view --anchor greet --search util
|
|
105
|
+
lscg view --output graph.svg
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`lscg context <symbol>` is the agent-oriented retrieval workflow. It returns a
|
|
109
|
+
versioned JSON envelope with one result per selected scope by default. Use
|
|
110
|
+
`--output text` for a concise human-readable summary or `--output svg` for a
|
|
111
|
+
static graph of the returned context slice. Results distinguish
|
|
112
|
+
`ok`, `ambiguous`, `not_found`, `refresh_failed`, and `stale` states from an
|
|
113
|
+
empty context. Anchor matching prefers qualified/path and exact names before
|
|
114
|
+
prefix and substring matches; an ambiguous match returns ranked candidates
|
|
115
|
+
instead of merging unrelated symbols. Use `--kind` and repository-relative
|
|
116
|
+
`--file` to disambiguate. Results are references by default; `--excerpts` opts
|
|
117
|
+
into bounded source text with `--excerpt-lines` and `--excerpt-bytes` limits.
|
|
118
|
+
The command compares a cheap path/size/mtime fingerprint with indexed files and
|
|
119
|
+
reports whether the graph was reused or refreshed. This metadata check is not a
|
|
120
|
+
content-verification guarantee for same-size edits with restored mtimes.
|
|
121
|
+
|
|
122
|
+
Impact contains only syntax-grounded `calls` edges (with caller/callee
|
|
123
|
+
direction), and dependencies contain `imports`/`exports`; parser confidence
|
|
124
|
+
and provenance are included so callers can verify relationships in source.
|
|
125
|
+
Substring fallback is intentionally reported as a bounded capability warning.
|
|
126
|
+
Use `rg` or `grep` for literal discovery when a term is not indexed—`context`
|
|
127
|
+
does not replace arbitrary text search or claim complete semantic resolution.
|
|
128
|
+
|
|
129
|
+
`lscg watch` keeps the selected repository current in the foreground. It runs
|
|
130
|
+
one scan immediately, then watches scanner-relevant files and prints compact
|
|
131
|
+
status updates between rescans. Use `lscg scan` when you want the full one-shot
|
|
132
|
+
scan output.
|
|
133
|
+
|
|
134
|
+
When the repository has git history, `lscg scan` also records contributor user
|
|
135
|
+
nodes keyed by email and tracks the most recent contributor for each discovered
|
|
136
|
+
node.
|
|
137
|
+
|
|
138
|
+
## Current parser support
|
|
139
|
+
|
|
140
|
+
The starter scanner supports JavaScript, JSX, TypeScript, and TSX via
|
|
141
|
+
Tree-sitter. The extraction layer records syntax-grounded edges such as
|
|
142
|
+
`defines`, `contains`, `imports`, `exports`, and `calls`. Cross-file symbol
|
|
143
|
+
resolution should be added as language-specific semantic enrichers.
|
package/dist/bin/lscg.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runCli } from '../src/cli.js';
|
|
3
|
+
try {
|
|
4
|
+
await runCli(process.argv.slice(2));
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
8
|
+
console.error(`lscg: ${message}`);
|
|
9
|
+
process.exitCode = 1;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=lscg.js.map
|