@mrclrchtr/supi-code-intelligence 1.6.0 → 1.7.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 (79) hide show
  1. package/README.md +42 -24
  2. package/node_modules/@mrclrchtr/supi-core/package.json +6 -2
  3. package/node_modules/@mrclrchtr/supi-core/src/api.ts +12 -1
  4. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +1 -1
  5. package/node_modules/@mrclrchtr/supi-core/src/index.ts +12 -1
  6. package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +116 -0
  7. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +6 -2
  8. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +12 -1
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config.ts +1 -1
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +12 -1
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +116 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/package.json +9 -3
  13. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +8 -5
  14. package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +79 -190
  15. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +38 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/src/config/types.ts +61 -387
  17. package/node_modules/@mrclrchtr/supi-lsp/src/format.ts +16 -8
  18. package/node_modules/@mrclrchtr/supi-lsp/src/lsp.ts +2 -2
  19. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +1 -1
  20. package/node_modules/@mrclrchtr/supi-lsp/src/session/lsp-state.ts +1 -1
  21. package/node_modules/@mrclrchtr/supi-lsp/src/tool/guidance.ts +1 -1
  22. package/node_modules/@mrclrchtr/supi-lsp/src/tool/tool-specs.ts +1 -1
  23. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +6 -2
  24. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +12 -1
  25. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config.ts +1 -1
  26. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +12 -1
  27. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +116 -0
  28. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/LICENSE +21 -0
  29. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/README.md +265 -0
  30. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs +4661 -0
  31. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.cjs.map +7 -0
  32. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js +4605 -0
  33. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.js.map +7 -0
  34. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm +0 -0
  35. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/debug/web-tree-sitter.wasm.map +57 -0
  36. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/package.json +100 -0
  37. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs +4063 -0
  38. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.cjs.map +7 -0
  39. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts +1025 -0
  40. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.cts.map +58 -0
  41. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts +1025 -0
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.d.ts.map +58 -0
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js +4007 -0
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.js.map +7 -0
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm +0 -0
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/web-tree-sitter/web-tree-sitter.wasm.map +55 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +2 -2
  48. package/package.json +4 -4
  49. package/src/actions/affected-action.ts +67 -54
  50. package/src/actions/brief-action.ts +142 -5
  51. package/src/actions/callees-action.ts +1 -1
  52. package/src/actions/callers-action.ts +38 -67
  53. package/src/actions/implementations-action.ts +27 -63
  54. package/src/actions/map-action.ts +206 -0
  55. package/src/actions/pattern-action.ts +1 -1
  56. package/src/api.ts +1 -0
  57. package/src/brief-focused.ts +5 -5
  58. package/src/brief.ts +3 -3
  59. package/src/code-intelligence.ts +6 -75
  60. package/src/index.ts +1 -0
  61. package/src/pattern-structured.ts +1 -1
  62. package/src/prioritization-signals.ts +13 -26
  63. package/src/query-params.ts +15 -0
  64. package/src/resolve-target.ts +2 -2
  65. package/src/search-helpers.ts +2 -2
  66. package/src/target-resolution.ts +27 -102
  67. package/src/tool/execute-affected.ts +25 -0
  68. package/src/tool/execute-brief.ts +25 -0
  69. package/src/tool/execute-map.ts +32 -0
  70. package/src/tool/execute-pattern.ts +26 -0
  71. package/src/tool/execute-relations.ts +48 -0
  72. package/src/tool/guidance.ts +24 -13
  73. package/src/tool/register-tools.ts +32 -0
  74. package/src/tool/tool-specs.ts +184 -0
  75. package/src/tool/validation.ts +43 -0
  76. package/src/types.ts +10 -0
  77. package/src/actions/index-action.ts +0 -187
  78. package/src/tool/action-specs.ts +0 -66
  79. package/src/tool-actions.ts +0 -100
@@ -0,0 +1,116 @@
1
+ // Shared tool framework for SuPi extensions.
2
+ //
3
+ // Provides a standard ToolSpec→PromptSurface→registerTool pipeline so
4
+ // individual packages do not duplicate spec interfaces, guidance derivation,
5
+ // registration loops, or common TypeBox parameter schemas.
6
+
7
+ import type {
8
+ AgentToolResult,
9
+ AgentToolUpdateCallback,
10
+ ExtensionAPI,
11
+ ExtensionContext,
12
+ } from "@earendil-works/pi-coding-agent";
13
+ import { type TSchema, Type } from "typebox";
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Types
17
+ // ---------------------------------------------------------------------------
18
+
19
+ /** Minimum contract for a SuPi tool definition. */
20
+ export interface SuiPiToolSpec {
21
+ name: string;
22
+ label: string;
23
+ description: string;
24
+ promptSnippet: string;
25
+ promptGuidelines: string[];
26
+ parameters: TSchema;
27
+ }
28
+
29
+ /** Derived prompt surface — what pi flattens into the system prompt. */
30
+ export interface SuiPiToolPromptSurface {
31
+ description: string;
32
+ promptSnippet: string;
33
+ promptGuidelines: string[];
34
+ }
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // Guidance derivation
38
+ // ---------------------------------------------------------------------------
39
+
40
+ /**
41
+ * Static derivation: copies spec fields into a prompt surface.
42
+ *
43
+ * Packages that need dynamic guidance (e.g. server-coverage injection) should
44
+ * build their own surfaces, optionally starting from the output of this helper.
45
+ */
46
+ export function derivePromptSurface(spec: SuiPiToolSpec): SuiPiToolPromptSurface {
47
+ return {
48
+ description: spec.description,
49
+ promptSnippet: spec.promptSnippet,
50
+ promptGuidelines: [...spec.promptGuidelines],
51
+ };
52
+ }
53
+
54
+ // ---------------------------------------------------------------------------
55
+ // Registration
56
+ // ---------------------------------------------------------------------------
57
+
58
+ // biome-ignore lint/complexity/useMaxParams: matches pi ToolDefinition.execute signature
59
+ export type ToolExecuteFn = (
60
+ toolCallId: string,
61
+ params: unknown,
62
+ signal: AbortSignal | undefined,
63
+ onUpdate: AgentToolUpdateCallback<Record<string, unknown>> | undefined,
64
+ ctx: ExtensionContext,
65
+ ) => Promise<AgentToolResult<Record<string, unknown>>>;
66
+
67
+ /**
68
+ * Register a set of tools from specs + pre-derived surfaces.
69
+ *
70
+ * `createExecute` receives the spec and returns a pi-compatible execute
71
+ * function. This keeps execute-logic package-local while the framework owns
72
+ * the declarative surface and registration boilerplate.
73
+ */
74
+ export function registerSuiPiTools(
75
+ pi: ExtensionAPI,
76
+ specs: readonly SuiPiToolSpec[],
77
+ surfaces: Record<string, SuiPiToolPromptSurface>,
78
+ createExecute: (spec: SuiPiToolSpec) => ToolExecuteFn,
79
+ ): void {
80
+ for (const spec of specs) {
81
+ const surface = surfaces[spec.name];
82
+ pi.registerTool({
83
+ name: spec.name,
84
+ label: spec.label,
85
+ description: surface?.description ?? spec.description,
86
+ promptSnippet: surface?.promptSnippet ?? spec.promptSnippet,
87
+ promptGuidelines: surface?.promptGuidelines ?? [...spec.promptGuidelines],
88
+ parameters: spec.parameters,
89
+ execute: createExecute(spec),
90
+ });
91
+ }
92
+ }
93
+
94
+ // ---------------------------------------------------------------------------
95
+ // Shared parameter builders
96
+ // ---------------------------------------------------------------------------
97
+
98
+ /** File path (relative or absolute). */
99
+ export const FileParam = Type.String({ description: "File path (relative or absolute)" });
100
+
101
+ /** 1-based line number. */
102
+ export const LineParam = Type.Number({ description: "1-based line number", minimum: 1 });
103
+
104
+ /** 1-based character column (UTF-16). */
105
+ export const CharacterParam = Type.Number({
106
+ description: "1-based column number (UTF-16)",
107
+ minimum: 1,
108
+ });
109
+
110
+ /** Symbol name for discovery-based resolution. */
111
+ export const SymbolParam = Type.String({
112
+ description: "Symbol name for discovery-based resolution",
113
+ });
114
+
115
+ /** Maximum results to return. */
116
+ export const MaxResultsParam = Type.Number({ description: "Maximum results to return" });
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Max Brunsfeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,265 @@
1
+ # Web Tree-sitter
2
+
3
+ [![npmjs.com badge]][npmjs.com]
4
+
5
+ [npmjs.com]: https://www.npmjs.org/package/web-tree-sitter
6
+ [npmjs.com badge]: https://img.shields.io/npm/v/web-tree-sitter.svg?color=%23BF4A4A
7
+
8
+ WebAssembly bindings to the [Tree-sitter](https://github.com/tree-sitter/tree-sitter) parsing library.
9
+
10
+ ## Setup
11
+
12
+ You can download the `web-tree-sitter.js` and `web-tree-sitter.wasm` files from [the latest GitHub release][gh release] and load
13
+ them using a standalone script:
14
+
15
+ ```html
16
+ <script src="/the/path/to/web-tree-sitter.js"></script>
17
+
18
+ <script>
19
+ const { Parser } = window.TreeSitter;
20
+ Parser.init().then(() => { /* the library is ready */ });
21
+ </script>
22
+ ```
23
+
24
+ You can also install [the `web-tree-sitter` module][npm module] from NPM and load it using a system like Webpack:
25
+
26
+ ```js
27
+ const { Parser } = require('web-tree-sitter');
28
+ Parser.init().then(() => { /* the library is ready */ });
29
+ ```
30
+
31
+ or Vite:
32
+
33
+ ```js
34
+ import { Parser } from 'web-tree-sitter';
35
+ Parser.init().then(() => { /* the library is ready */ });
36
+ ```
37
+
38
+ With Vite, you also need to make sure your server provides the `tree-sitter.wasm`
39
+ file to your `public` directory. You can do this automatically with a `postinstall`
40
+ [script](https://docs.npmjs.com/cli/v10/using-npm/scripts) in your `package.json`:
41
+
42
+ ```js
43
+ "postinstall": "cp node_modules/web-tree-sitter/tree-sitter.wasm public"
44
+ ```
45
+
46
+ You can also use this module with [deno](https://deno.land/):
47
+
48
+ ```js
49
+ import { Parser } from "npm:web-tree-sitter";
50
+ await Parser.init();
51
+ // the library is ready
52
+ ```
53
+
54
+ To use the debug version of the library, replace your import of `web-tree-sitter` with `web-tree-sitter/debug`:
55
+
56
+ ```js
57
+ import { Parser } from 'web-tree-sitter/debug'; // or require('web-tree-sitter/debug')
58
+
59
+ Parser.init().then(() => { /* the library is ready */ });
60
+ ```
61
+
62
+ This will load the debug version of the `.js` and `.wasm` file, which includes debug symbols and assertions.
63
+
64
+ > [!NOTE]
65
+ > The `web-tree-sitter.js` file on GH releases is an ES6 module. If you are interested in using a pure CommonJS library, such
66
+ > as for Electron, you should use the `web-tree-sitter.cjs` file instead.
67
+
68
+ ### Basic Usage
69
+
70
+ First, create a parser:
71
+
72
+ ```js
73
+ const parser = new Parser();
74
+ ```
75
+
76
+ Then assign a language to the parser. Tree-sitter languages are packaged as individual `.wasm` files (more on this below):
77
+
78
+ ```js
79
+ const { Language } = require('web-tree-sitter');
80
+ const JavaScript = await Language.load('/path/to/tree-sitter-javascript.wasm');
81
+ parser.setLanguage(JavaScript);
82
+ ```
83
+
84
+ Now you can parse source code:
85
+
86
+ ```js
87
+ const sourceCode = 'let x = 1; console.log(x);';
88
+ const tree = parser.parse(sourceCode);
89
+ ```
90
+
91
+ and inspect the syntax tree.
92
+
93
+ ```javascript
94
+ console.log(tree.rootNode.toString());
95
+
96
+ // (program
97
+ // (lexical_declaration
98
+ // (variable_declarator (identifier) (number)))
99
+ // (expression_statement
100
+ // (call_expression
101
+ // (member_expression (identifier) (property_identifier))
102
+ // (arguments (identifier)))))
103
+
104
+ const callExpression = tree.rootNode.child(1).firstChild;
105
+ console.log(callExpression);
106
+
107
+ // { type: 'call_expression',
108
+ // startPosition: {row: 0, column: 16},
109
+ // endPosition: {row: 0, column: 30},
110
+ // startIndex: 0,
111
+ // endIndex: 30 }
112
+ ```
113
+
114
+ ### Editing
115
+
116
+ If your source code *changes*, you can update the syntax tree. This will take less time than the first parse.
117
+
118
+ ```javascript
119
+ // Replace 'let' with 'const'
120
+ const newSourceCode = 'const x = 1; console.log(x);';
121
+
122
+ tree.edit({
123
+ startIndex: 0,
124
+ oldEndIndex: 3,
125
+ newEndIndex: 5,
126
+ startPosition: {row: 0, column: 0},
127
+ oldEndPosition: {row: 0, column: 3},
128
+ newEndPosition: {row: 0, column: 5},
129
+ });
130
+
131
+ const newTree = parser.parse(newSourceCode, tree);
132
+ ```
133
+
134
+ ### Parsing Text From a Custom Data Structure
135
+
136
+ If your text is stored in a data structure other than a single string, you can parse it by supplying a callback to `parse`
137
+ instead of a string:
138
+
139
+ ```javascript
140
+ const sourceLines = [
141
+ 'let x = 1;',
142
+ 'console.log(x);'
143
+ ];
144
+
145
+ const tree = parser.parse((index, position) => {
146
+ let line = sourceLines[position.row];
147
+ if (line) return line.slice(position.column);
148
+ });
149
+ ```
150
+
151
+ ### Getting the `.wasm` language files
152
+
153
+ There are several options on how to get the `.wasm` files for the languages you want to parse.
154
+
155
+ #### From npmjs.com
156
+
157
+ The recommended way is to just install the package from npm. For example, to parse JavaScript, you can install the `tree-sitter-javascript`
158
+ package:
159
+
160
+ ```sh
161
+ npm install tree-sitter-javascript
162
+ ```
163
+
164
+ Then you can find the `.wasm` file in the `node_modules/tree-sitter-javascript` directory.
165
+
166
+ #### From GitHub
167
+
168
+ You can also download the `.wasm` files from GitHub releases, so long as the repository uses our reusable workflow to publish
169
+ them.
170
+ For example, you can download the JavaScript `.wasm` file from the tree-sitter-javascript [releases page][gh release js].
171
+
172
+ #### Generating `.wasm` files
173
+
174
+ You can also generate the `.wasm` file for your desired grammar. Shown below is an example of how to generate the `.wasm`
175
+ file for the JavaScript grammar.
176
+
177
+ **IMPORTANT**: [Emscripten][emscripten], [Docker][docker], or [Podman][podman] need to be installed.
178
+
179
+ First install `tree-sitter-cli`, and the tree-sitter language for which to generate `.wasm`
180
+ (`tree-sitter-javascript` in this example):
181
+
182
+ ```sh
183
+ npm install --save-dev tree-sitter-cli tree-sitter-javascript
184
+ ```
185
+
186
+ Then just use tree-sitter cli tool to generate the `.wasm`.
187
+
188
+ ```sh
189
+ npx tree-sitter build --wasm node_modules/tree-sitter-javascript
190
+ ```
191
+
192
+ If everything is fine, file `tree-sitter-javascript.wasm` should be generated in current directory.
193
+
194
+ ### Running .wasm in Node.js
195
+
196
+ Notice that executing `.wasm` files in Node.js is considerably slower than running [Node.js bindings][node bindings].
197
+ However, this could be useful for testing purposes:
198
+
199
+ ```javascript
200
+ const Parser = require('web-tree-sitter');
201
+
202
+ (async () => {
203
+ await Parser.init();
204
+ const parser = new Parser();
205
+ const Lang = await Parser.Language.load('tree-sitter-javascript.wasm');
206
+ parser.setLanguage(Lang);
207
+ const tree = parser.parse('let x = 1;');
208
+ console.log(tree.rootNode.toString());
209
+ })();
210
+ ```
211
+
212
+ ### Running .wasm in browser
213
+
214
+ `web-tree-sitter` can run in the browser, but there are some common pitfalls.
215
+
216
+ #### Loading the .wasm file
217
+
218
+ `web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
219
+ same path as the JavaScript code. Therefore, if the code is being served from `http://localhost:3000/bundle.js`, then
220
+ the Wasm file should be at `http://localhost:3000/tree-sitter.wasm`.
221
+
222
+ For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
223
+ `http://localhost:3000/_next/static/chunks/pages/index.js`. The loader will therefore look for the Wasm file at
224
+ `http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
225
+ the `moduleOptions` argument to `Parser.init()`:
226
+
227
+ ```javascript
228
+ await Parser.init({
229
+ locateFile(scriptName: string, scriptDirectory: string) {
230
+ return scriptName;
231
+ },
232
+ });
233
+ ```
234
+
235
+ `locateFile` takes in two parameters, `scriptName`, i.e. the Wasm file name, and `scriptDirectory`, i.e. the directory
236
+ where the loader expects the script to be. It returns the path where the loader will look for the Wasm file. In the NextJS
237
+ case, we want to return just the `scriptName` so that the loader will look at `http://localhost:3000/tree-sitter.wasm`
238
+ and not `http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`.
239
+
240
+ For more information on the module options you can pass in, see the [emscripten documentation][emscripten-module-options].
241
+
242
+ #### "Can't resolve 'fs' in 'node_modules/web-tree-sitter"
243
+
244
+ Most bundlers will notice that the `web-tree-sitter.js` file is attempting to import `fs`, i.e. node's file system library.
245
+ Since this doesn't exist in the browser, the bundlers will get confused. For Webpack, you can fix this by adding the
246
+ following to your webpack config:
247
+
248
+ ```javascript
249
+ {
250
+ resolve: {
251
+ fallback: {
252
+ fs: false
253
+ }
254
+ }
255
+ }
256
+ ```
257
+
258
+ [docker]: https://www.docker.com
259
+ [emscripten]: https://emscripten.org
260
+ [emscripten-module-options]: https://emscripten.org/docs/api_reference/module.html#affecting-execution
261
+ [gh release]: https://github.com/tree-sitter/tree-sitter/releases/latest
262
+ [gh release js]: https://github.com/tree-sitter/tree-sitter-javascript/releases/latest
263
+ [node bindings]: https://github.com/tree-sitter/node-tree-sitter
264
+ [npm module]: https://www.npmjs.com/package/web-tree-sitter
265
+ [podman]: https://podman.io