@mrclrchtr/supi-tree-sitter 1.1.2 → 1.2.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.
Files changed (2) hide show
  1. package/README.md +38 -70
  2. package/package.json +12 -1
package/README.md CHANGED
@@ -1,97 +1,65 @@
1
1
  # @mrclrchtr/supi-tree-sitter
2
2
 
3
- Tree-sitter structural analysis for the [pi coding agent](https://github.com/earendil-works/pi).
3
+ Structural code analysis for PI your agent parses code, not just text.
4
4
 
5
- This package registers a `tree_sitter` tool and also exports a small TypeScript service API for other SuPi extensions. It is designed as a standalone structural-analysis substrate: it does not depend on `supi-lsp` or semantic language-server tooling, and it remains correct and useful when installed by itself.
5
+ Grep matches strings. Tree-sitter parses structure functions, classes, imports, call chains. The agent stops pattern-matching and starts understanding your code.
6
6
 
7
- ## Install
7
+ ## What you get
8
8
 
9
- ```bash
10
- pi install npm:@mrclrchtr/supi-tree-sitter
11
- ```
9
+ ### See code structure
12
10
 
13
- Standalone installs include the runtime grammar dependencies needed for the supported non-vendored languages. Kotlin and SQL use vendored WASM grammars bundled with this package.
11
+ Extract functions, classes, interfaces, and methods from any file. The agent knows what lives where without reading every line.
14
12
 
15
- It is also bundled by the full SuPi meta-package:
13
+ ### Trace call chains
16
14
 
17
- ```bash
18
- pi install npm:@mrclrchtr/supi
19
- ```
15
+ Find every function call from a given location. The agent follows the code's actual shape instead of guessing from text proximity.
20
16
 
21
- ## Supported files
17
+ ### 14 languages
22
18
 
23
- The runtime can parse these file families:
19
+ JavaScript, TypeScript, Python, Rust, Go, C, C++, Java, Kotlin, Ruby, Bash, HTML, R, SQL — get structural analysis for every project you touch.
24
20
 
25
- - **JavaScript / TypeScript**`.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, `.cjs`
26
- - **Python** — `.py`, `.pyi`
27
- - **Rust** — `.rs`
28
- - **Go** — `.go`, `.mod`
29
- - **C / C++** — `.c`, `.h`, `.cpp`, `.hpp`, `.cc`, `.cxx`, `.hxx`, `.c++`, `.h++`
30
- - **Java** — `.java`
31
- - **Kotlin** — `.kt`, `.kts`
32
- - **Ruby** — `.rb`
33
- - **Bash / Shell** — `.sh`, `.bash`, `.zsh`
34
- - **HTML** — `.html`, `.htm`, `.xhtml`
35
- - **R** — `.r`
36
- - **SQL** — `.sql`
21
+ Works standalone or alongside LSP. Grammar files are vendored no native toolchain required at install time.
22
+
23
+ ## Install
37
24
 
38
- Grammar `.wasm` files are resolved from installed package metadata for npm-shipped grammars, not from repository-relative paths.
25
+ ```bash
26
+ pi install npm:@mrclrchtr/supi-tree-sitter
27
+ ```
39
28
 
40
- ## `tree_sitter` tool
29
+ ## Quick look
41
30
 
42
- Actions:
31
+ The agent gets a `tree_sitter` tool with these actions:
43
32
 
44
- - `outline` list structural declarations such as functions, classes, interfaces, methods, and variables (**currently JavaScript / TypeScript only**)
45
- - `imports` — list import statements and module specifiers (**currently JavaScript / TypeScript only**)
46
- - `exports` list exported declarations, re-exports, and TypeScript `export =` assignments (**currently JavaScript / TypeScript only**)
47
- - `node_at` return the smallest syntax node at a 1-based `line`/`character` position, plus ancestry (all supported grammars)
48
- - `query` run a custom Tree-sitter query and return captures (all supported grammars)
49
- - `callees` find outgoing function/method calls from a position; supports all grammars with a callee query configured
33
+ | Action | What it does |
34
+ |--------|-------------|
35
+ | `outline` | List functions, classes, interfaces in a file |
36
+ | `callees` | Find all function calls from a position |
37
+ | `imports` / `exports` | See what a file imports and exports |
38
+ | `node_at` | Inspect the AST node at any line/column |
39
+ | `query` | Run a custom Tree-sitter query |
50
40
 
51
- Coordinates are 1-based and compatible with the `lsp` tool. `character` is a UTF-16 code-unit column. Relative file paths resolve from the pi session working directory.
41
+ `outline`, `imports`, and `exports` are currently JavaScript/TypeScript only. `node_at`, `query`, and `callees` work across all 14 supported languages. Coordinates are 1-based, matching the `lsp` tool convention.
52
42
 
53
- Large result sets are capped at 100 emitted items per tool response. For outlines, nested children count toward the same cap so deeply nested classes do not bypass the limit.
43
+ ## For extension developers
54
44
 
55
- ## Service API
45
+ This package exports a reusable session-scoped parsing service:
56
46
 
57
47
  ```ts
58
48
  import { createTreeSitterSession } from "@mrclrchtr/supi-tree-sitter";
59
49
 
60
- const session = createTreeSitterSession(process.cwd());
61
- try {
62
- const parseable = await session.canParse("src/index.ts");
63
- if (parseable.kind === "success") {
64
- console.log(parseable.data.file, parseable.data.language);
65
- }
66
-
67
- const outline = await session.outline("src/index.ts");
68
- if (outline.kind === "success") {
69
- console.log(outline.data);
70
- }
71
-
72
- const callees = await session.calleesAt("src/index.ts", 1, 10);
73
- if (callees.kind === "success") {
74
- console.log(callees.data.enclosingScope.name, callees.data.callees);
75
- }
76
- } finally {
77
- session.dispose();
78
- }
79
- ```
80
-
81
- `canParse(file)` validates that a supported file can be read and parsed, then returns the resolved file path and grammar id. It does not expose the raw Tree-sitter tree; use `outline`, `query`, `imports`, `exports`, `nodeAt`, or `calleesAt` for structured results.
82
-
83
- `calleesAt(file, line, character)` extracts structural outgoing calls from the enclosing function/method scope at the given position. It returns the enclosing scope name and a deduplicated list of callees with their source ranges.
50
+ const session = createTreeSitterSession("/project");
84
51
 
85
- Exported types include `TreeSitterResult`, `TreeSitterSession`, `OutlineItem`, `ImportRecord`, `ExportRecord`, `NodeAtResult`, `QueryCapture`, `CalleesAtResult`, `SourceRange`, `GrammarId`, and `SupportedExtension`.
52
+ // Check if a file is parseable
53
+ const result = await session.canParse("src/index.ts");
86
54
 
87
- Always call `dispose()` when the session is no longer needed. The runtime lazily initializes grammars, reuses parser instances within a session, deduplicates concurrent first-use grammar initialization, and retries after initialization failures.
55
+ // Get structural outline
56
+ const outline = await session.outline("src/index.ts");
88
57
 
89
- ## Positioning
58
+ // Trace outgoing calls from a position
59
+ const callees = await session.calleesAt("src/index.ts", 42, 10);
90
60
 
91
- `supi-tree-sitter` is the structural-analysis substrate in SuPi's layered code-understanding stack:
92
-
93
- - `supi-tree-sitter` — parser-backed structural analysis (this package)
94
- - `supi-lsp` — live semantic analysis through language servers
95
- - `supi-code-intelligence` — higher-level agent-facing analysis built on top of both substrates
61
+ // Always clean up
62
+ session.dispose();
63
+ ```
96
64
 
97
- Each substrate can be installed and used independently. `supi-tree-sitter` does not require `supi-lsp` to be present, and its prompt guidance is written so it remains correct in standalone installs.
65
+ Import from the package root. No internal imports needed. Call `dispose()` when done.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-tree-sitter",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "SuPi Tree-sitter extension — structural AST analysis for pi",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,6 +30,17 @@
30
30
  "@earendil-works/pi-coding-agent": "*",
31
31
  "typebox": "*"
32
32
  },
33
+ "peerDependenciesMeta": {
34
+ "@earendil-works/pi-ai": {
35
+ "optional": true
36
+ },
37
+ "@earendil-works/pi-coding-agent": {
38
+ "optional": true
39
+ },
40
+ "typebox": {
41
+ "optional": true
42
+ }
43
+ },
33
44
  "pi": {
34
45
  "extensions": [
35
46
  "./src/tree-sitter.ts"