@mrclrchtr/supi-tree-sitter 1.6.0 → 1.8.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.
- package/README.md +26 -15
- package/node_modules/@mrclrchtr/supi-core/package.json +18 -3
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +27 -82
- package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +11 -0
- package/node_modules/@mrclrchtr/supi-core/src/context.ts +16 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +27 -82
- package/node_modules/@mrclrchtr/supi-core/src/path.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/project.ts +15 -0
- package/node_modules/@mrclrchtr/supi-core/src/session.ts +4 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings.ts +9 -0
- package/node_modules/@mrclrchtr/supi-core/src/substrate-types.ts +11 -0
- package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +116 -0
- package/node_modules/@mrclrchtr/supi-core/src/types.ts +2 -0
- package/package.json +2 -2
- package/src/session/runtime.ts +1 -1
- package/src/session/service-registry.ts +1 -1
- package/src/tool/guidance.ts +29 -25
- package/src/tool/handlers.ts +196 -0
- package/src/tool/register-tools.ts +107 -0
- package/src/tool/tool-specs.ts +117 -0
- package/src/tree-sitter.ts +4 -300
- package/src/tool/action-specs.ts +0 -92
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mrclrchtr/supi-tree-sitter
|
|
2
2
|
|
|
3
|
-
Adds
|
|
3
|
+
Adds focused structural code analysis tools to the [pi coding agent](https://github.com/earendil-works/pi) using Tree-sitter parsers.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -18,27 +18,35 @@ After editing the source, run `/reload`.
|
|
|
18
18
|
|
|
19
19
|
## What you get
|
|
20
20
|
|
|
21
|
-
After install, pi gets
|
|
21
|
+
After install, pi gets **6 focused tools** for parser-based structural analysis:
|
|
22
22
|
|
|
23
|
-
- `
|
|
23
|
+
- `tree_sitter_outline` — shallow structural outline of declarations in JavaScript/TypeScript files
|
|
24
|
+
- `tree_sitter_imports` — list imports in JavaScript/TypeScript files
|
|
25
|
+
- `tree_sitter_exports` — list exports in JavaScript/TypeScript files
|
|
26
|
+
- `tree_sitter_node_at` — find the exact syntax node and ancestry at a position (any supported grammar)
|
|
27
|
+
- `tree_sitter_query` — run a custom Tree-sitter query against a file (any supported grammar)
|
|
28
|
+
- `tree_sitter_callees` — find outgoing calls from the enclosing function or method at a position (most grammars)
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
### Outline, imports, exports
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
These three tools work on JavaScript, TypeScript, JSX, and TSX files. They provide parser-level structural information without needing a language server:
|
|
33
|
+
|
|
34
|
+
- `tree_sitter_outline` — top-level declarations plus class/interface/enum members
|
|
35
|
+
- `tree_sitter_imports` — module specifiers and source locations for each import
|
|
36
|
+
- `tree_sitter_exports` — kind, name, and module specifier (for re-exports) of each export
|
|
37
|
+
|
|
38
|
+
### Node-at, query, callees
|
|
39
|
+
|
|
40
|
+
These tools work across all or most supported grammars:
|
|
41
|
+
|
|
42
|
+
- `tree_sitter_node_at` — exact syntax node type and ancestry at a given file position
|
|
43
|
+
- `tree_sitter_query` — custom Tree-sitter query pattern matching on any supported grammar
|
|
44
|
+
- `tree_sitter_callees` — outgoing calls from the enclosing function or method at a given position
|
|
35
45
|
|
|
36
46
|
Coordinates use **1-based** line and character columns. Character positions use UTF-16 code units. Relative paths resolve from the session cwd, and a leading `@` on file paths is stripped.
|
|
37
47
|
|
|
38
48
|
## Supported file families
|
|
39
49
|
|
|
40
|
-
The current tool description covers:
|
|
41
|
-
|
|
42
50
|
- JavaScript / TypeScript (`.js`, `.jsx`, `.ts`, `.tsx`, `.mjs`, `.cjs`, `.mts`, `.cts`)
|
|
43
51
|
- Python (`.py`, `.pyi`)
|
|
44
52
|
- Rust (`.rs`)
|
|
@@ -84,7 +92,10 @@ if (state.kind === "ready") {
|
|
|
84
92
|
|
|
85
93
|
## Source
|
|
86
94
|
|
|
87
|
-
- `src/
|
|
95
|
+
- `src/tool/tool-specs.ts` — single source of truth for the public tool surface
|
|
96
|
+
- `src/tool/guidance.ts` — prompt surfaces derived from tool specs
|
|
97
|
+
- `src/tool/register-tools.ts` — focused tool registration driven by tool specs
|
|
98
|
+
- `src/tree-sitter.ts` — extension entrypoint (thin wire-up)
|
|
88
99
|
- `src/session/runtime.ts` — parser and query runtime
|
|
89
100
|
- `src/session/session.ts` — runtime-backed service helpers and owned session API
|
|
90
101
|
- `src/session/service-registry.ts` — shared session-scoped structural service registry
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
],
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@earendil-works/pi-coding-agent": "*",
|
|
23
|
-
"@earendil-works/pi-tui": "*"
|
|
23
|
+
"@earendil-works/pi-tui": "*",
|
|
24
|
+
"typebox": "*"
|
|
24
25
|
},
|
|
25
26
|
"peerDependenciesMeta": {
|
|
26
27
|
"@earendil-works/pi-coding-agent": {
|
|
@@ -28,13 +29,27 @@
|
|
|
28
29
|
},
|
|
29
30
|
"@earendil-works/pi-tui": {
|
|
30
31
|
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"typebox": {
|
|
34
|
+
"optional": true
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"main": "src/api.ts",
|
|
34
38
|
"exports": {
|
|
35
39
|
"./api": "./src/api.ts",
|
|
40
|
+
"./config": "./src/config.ts",
|
|
41
|
+
"./context": "./src/context.ts",
|
|
42
|
+
"./debug": "./src/debug-registry.ts",
|
|
36
43
|
"./extension": "./src/extension.ts",
|
|
37
|
-
"./package.json": "./package.json"
|
|
44
|
+
"./package.json": "./package.json",
|
|
45
|
+
"./path": "./src/path.ts",
|
|
46
|
+
"./project": "./src/project.ts",
|
|
47
|
+
"./session": "./src/session.ts",
|
|
48
|
+
"./settings": "./src/settings.ts",
|
|
49
|
+
"./settings-ui": "./src/settings-ui.ts",
|
|
50
|
+
"./terminal": "./src/terminal.ts",
|
|
51
|
+
"./tool-framework": "./src/tool-framework.ts",
|
|
52
|
+
"./types": "./src/types.ts"
|
|
38
53
|
},
|
|
39
54
|
"pi": {
|
|
40
55
|
"extensions": [
|
|
@@ -1,85 +1,30 @@
|
|
|
1
1
|
// supi-core — shared infrastructure for SuPi extensions.
|
|
2
2
|
// Provides XML context tag wrapping, unified config system, context-message utilities,
|
|
3
|
-
//
|
|
3
|
+
// settings registry for supi-wide TUI settings, and a shared tool-spec/registration framework.
|
|
4
|
+
//
|
|
5
|
+
// Convenience barrel — re-exports all domain entry points.
|
|
6
|
+
// For lighter imports, use one of the domain subpaths directly
|
|
7
|
+
// (e.g. @mrclrchtr/supi-core/config, @mrclrchtr/supi-core/context).
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from "./context/context-provider-registry.ts";
|
|
28
|
-
export { wrapExtensionContext } from "./context/context-tag.ts";
|
|
29
|
-
export type {
|
|
30
|
-
DebugAgentAccess,
|
|
31
|
-
DebugEvent,
|
|
32
|
-
DebugEventInput,
|
|
33
|
-
DebugEventQuery,
|
|
34
|
-
DebugEventQueryResult,
|
|
35
|
-
DebugEventView,
|
|
36
|
-
DebugLevel,
|
|
37
|
-
DebugNotifyLevel,
|
|
38
|
-
DebugRegistryConfig,
|
|
39
|
-
DebugSummary,
|
|
40
|
-
} from "./debug-registry.ts";
|
|
41
|
-
export {
|
|
42
|
-
clearDebugEvents,
|
|
43
|
-
configureDebugRegistry,
|
|
44
|
-
DEBUG_REGISTRY_DEFAULTS,
|
|
45
|
-
getDebugEvents,
|
|
46
|
-
getDebugRegistryConfig,
|
|
47
|
-
getDebugSummary,
|
|
48
|
-
recordDebugEvent,
|
|
49
|
-
redactDebugData,
|
|
50
|
-
resetDebugRegistry,
|
|
51
|
-
} from "./debug-registry.ts";
|
|
52
|
-
export { fileToUri, resolveToolPath, stripToolPathPrefix, uriToFile } from "./path-utils.ts";
|
|
53
|
-
export type { KnownRootEntry } from "./project-roots.ts";
|
|
54
|
-
export {
|
|
55
|
-
buildKnownRootsMap,
|
|
56
|
-
byPathDepth,
|
|
57
|
-
dedupeTopmostRoots,
|
|
58
|
-
findProjectRoot,
|
|
59
|
-
isWithin,
|
|
60
|
-
isWithinOrEqual,
|
|
61
|
-
mergeKnownRoots,
|
|
62
|
-
resolveKnownRoot,
|
|
63
|
-
segmentCount,
|
|
64
|
-
sortRootsBySpecificity,
|
|
65
|
-
walkProject,
|
|
66
|
-
} from "./project-roots.ts";
|
|
67
|
-
export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
|
|
68
|
-
export { getActiveBranchEntries } from "./session-utils.ts";
|
|
69
|
-
export { registerSettingsCommand } from "./settings/settings-command.ts";
|
|
70
|
-
export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
|
|
71
|
-
export {
|
|
72
|
-
clearRegisteredSettings,
|
|
73
|
-
getRegisteredSettings,
|
|
74
|
-
registerSettings,
|
|
75
|
-
} from "./settings/settings-registry.ts";
|
|
76
|
-
export { createInputSubmenu, openSettingsOverlay } from "./settings/settings-ui.ts";
|
|
77
|
-
export type { TitleTarget } from "./terminal.ts";
|
|
78
|
-
export {
|
|
79
|
-
DONE_SYMBOL,
|
|
80
|
-
formatTitle,
|
|
81
|
-
signalBell,
|
|
82
|
-
signalDone,
|
|
83
|
-
signalWaiting,
|
|
84
|
-
WAITING_SYMBOL,
|
|
85
|
-
} from "./terminal.ts";
|
|
9
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
10
|
+
export * from "./config.ts";
|
|
11
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
12
|
+
export * from "./context.ts";
|
|
13
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
14
|
+
export * from "./debug-registry.ts";
|
|
15
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
16
|
+
export * from "./path.ts";
|
|
17
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
18
|
+
export * from "./project.ts";
|
|
19
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
20
|
+
export * from "./session.ts";
|
|
21
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
22
|
+
export * from "./settings.ts";
|
|
23
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
24
|
+
export * from "./settings-ui.ts";
|
|
25
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
26
|
+
export * from "./terminal.ts";
|
|
27
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
28
|
+
export * from "./tool-framework.ts";
|
|
29
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
30
|
+
export * from "./types.ts";
|
|
@@ -20,7 +20,7 @@ function getProjectConfigPath(cwd: string): string {
|
|
|
20
20
|
return path.join(cwd, PROJECT_CONFIG_DIR, CONFIG_FILE);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function readJsonFile(filePath: string): Record<string, unknown> | null {
|
|
23
|
+
export function readJsonFile(filePath: string): Record<string, unknown> | null {
|
|
24
24
|
let content: string;
|
|
25
25
|
try {
|
|
26
26
|
content = fs.readFileSync(filePath, "utf-8");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// supi-core config domain — config loading and config-settings helpers.
|
|
2
|
+
export type { SupiConfigLocation, SupiConfigOptions } from "./config/config.ts";
|
|
3
|
+
export {
|
|
4
|
+
loadSupiConfig,
|
|
5
|
+
loadSupiConfigForScope,
|
|
6
|
+
readJsonFile,
|
|
7
|
+
removeSupiConfigKey,
|
|
8
|
+
writeSupiConfig,
|
|
9
|
+
} from "./config/config.ts";
|
|
10
|
+
export type { ConfigSettingsHelpers, ConfigSettingsOptions } from "./config/config-settings.ts";
|
|
11
|
+
export { registerConfigSettings } from "./config/config-settings.ts";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// supi-core context domain — context messages, providers, and XML tags.
|
|
2
|
+
export type { ContextMessageLike } from "./context/context-messages.ts";
|
|
3
|
+
export {
|
|
4
|
+
findLastUserMessageIndex,
|
|
5
|
+
getContextToken,
|
|
6
|
+
getPromptContent,
|
|
7
|
+
pruneAndReorderContextMessages,
|
|
8
|
+
restorePromptContent,
|
|
9
|
+
} from "./context/context-messages.ts";
|
|
10
|
+
export type { ContextProvider } from "./context/context-provider-registry.ts";
|
|
11
|
+
export {
|
|
12
|
+
clearRegisteredContextProviders,
|
|
13
|
+
getRegisteredContextProviders,
|
|
14
|
+
registerContextProvider,
|
|
15
|
+
} from "./context/context-provider-registry.ts";
|
|
16
|
+
export { wrapExtensionContext } from "./context/context-tag.ts";
|
|
@@ -1,85 +1,30 @@
|
|
|
1
1
|
// supi-core — shared infrastructure for SuPi extensions.
|
|
2
2
|
// Provides XML context tag wrapping, unified config system, context-message utilities,
|
|
3
|
-
//
|
|
3
|
+
// settings registry for supi-wide TUI settings, and a shared tool-spec/registration framework.
|
|
4
|
+
//
|
|
5
|
+
// Convenience barrel — re-exports all domain entry points.
|
|
6
|
+
// For lighter imports, use one of the domain subpaths directly
|
|
7
|
+
// (e.g. @mrclrchtr/supi-core/config, @mrclrchtr/supi-core/context).
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from "./context/context-provider-registry.ts";
|
|
28
|
-
export { wrapExtensionContext } from "./context/context-tag.ts";
|
|
29
|
-
export type {
|
|
30
|
-
DebugAgentAccess,
|
|
31
|
-
DebugEvent,
|
|
32
|
-
DebugEventInput,
|
|
33
|
-
DebugEventQuery,
|
|
34
|
-
DebugEventQueryResult,
|
|
35
|
-
DebugEventView,
|
|
36
|
-
DebugLevel,
|
|
37
|
-
DebugNotifyLevel,
|
|
38
|
-
DebugRegistryConfig,
|
|
39
|
-
DebugSummary,
|
|
40
|
-
} from "./debug-registry.ts";
|
|
41
|
-
export {
|
|
42
|
-
clearDebugEvents,
|
|
43
|
-
configureDebugRegistry,
|
|
44
|
-
DEBUG_REGISTRY_DEFAULTS,
|
|
45
|
-
getDebugEvents,
|
|
46
|
-
getDebugRegistryConfig,
|
|
47
|
-
getDebugSummary,
|
|
48
|
-
recordDebugEvent,
|
|
49
|
-
redactDebugData,
|
|
50
|
-
resetDebugRegistry,
|
|
51
|
-
} from "./debug-registry.ts";
|
|
52
|
-
export { fileToUri, resolveToolPath, stripToolPathPrefix, uriToFile } from "./path-utils.ts";
|
|
53
|
-
export type { KnownRootEntry } from "./project-roots.ts";
|
|
54
|
-
export {
|
|
55
|
-
buildKnownRootsMap,
|
|
56
|
-
byPathDepth,
|
|
57
|
-
dedupeTopmostRoots,
|
|
58
|
-
findProjectRoot,
|
|
59
|
-
isWithin,
|
|
60
|
-
isWithinOrEqual,
|
|
61
|
-
mergeKnownRoots,
|
|
62
|
-
resolveKnownRoot,
|
|
63
|
-
segmentCount,
|
|
64
|
-
sortRootsBySpecificity,
|
|
65
|
-
walkProject,
|
|
66
|
-
} from "./project-roots.ts";
|
|
67
|
-
export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
|
|
68
|
-
export { getActiveBranchEntries } from "./session-utils.ts";
|
|
69
|
-
export { registerSettingsCommand } from "./settings/settings-command.ts";
|
|
70
|
-
export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
|
|
71
|
-
export {
|
|
72
|
-
clearRegisteredSettings,
|
|
73
|
-
getRegisteredSettings,
|
|
74
|
-
registerSettings,
|
|
75
|
-
} from "./settings/settings-registry.ts";
|
|
76
|
-
export { createInputSubmenu, openSettingsOverlay } from "./settings/settings-ui.ts";
|
|
77
|
-
export type { TitleTarget } from "./terminal.ts";
|
|
78
|
-
export {
|
|
79
|
-
DONE_SYMBOL,
|
|
80
|
-
formatTitle,
|
|
81
|
-
signalBell,
|
|
82
|
-
signalDone,
|
|
83
|
-
signalWaiting,
|
|
84
|
-
WAITING_SYMBOL,
|
|
85
|
-
} from "./terminal.ts";
|
|
9
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
10
|
+
export * from "./config.ts";
|
|
11
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
12
|
+
export * from "./context.ts";
|
|
13
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
14
|
+
export * from "./debug-registry.ts";
|
|
15
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
16
|
+
export * from "./path.ts";
|
|
17
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
18
|
+
export * from "./project.ts";
|
|
19
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
20
|
+
export * from "./session.ts";
|
|
21
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
22
|
+
export * from "./settings.ts";
|
|
23
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
24
|
+
export * from "./settings-ui.ts";
|
|
25
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
26
|
+
export * from "./terminal.ts";
|
|
27
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
28
|
+
export * from "./tool-framework.ts";
|
|
29
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
30
|
+
export * from "./types.ts";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// supi-core project domain — project root discovery and traversal.
|
|
2
|
+
export type { KnownRootEntry } from "./project-roots.ts";
|
|
3
|
+
export {
|
|
4
|
+
buildKnownRootsMap,
|
|
5
|
+
byPathDepth,
|
|
6
|
+
dedupeTopmostRoots,
|
|
7
|
+
findProjectRoot,
|
|
8
|
+
isWithin,
|
|
9
|
+
isWithinOrEqual,
|
|
10
|
+
mergeKnownRoots,
|
|
11
|
+
resolveKnownRoot,
|
|
12
|
+
segmentCount,
|
|
13
|
+
sortRootsBySpecificity,
|
|
14
|
+
walkProject,
|
|
15
|
+
} from "./project-roots.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// supi-core settings domain — settings registry (lightweight, type-only pi-tui import).
|
|
2
|
+
|
|
3
|
+
export { registerSettingsCommand } from "./settings/settings-command.ts";
|
|
4
|
+
export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
|
|
5
|
+
export {
|
|
6
|
+
clearRegisteredSettings,
|
|
7
|
+
getRegisteredSettings,
|
|
8
|
+
registerSettings,
|
|
9
|
+
} from "./settings/settings-registry.ts";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** 0-based position used by LSP and code-intelligence internally. */
|
|
2
|
+
export interface CodePosition {
|
|
3
|
+
line: number;
|
|
4
|
+
character: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** Normalized location — flat replacement for LSP's nested Location/range shape. */
|
|
8
|
+
export interface CodeLocation {
|
|
9
|
+
uri: string;
|
|
10
|
+
range: { start: CodePosition; end: CodePosition };
|
|
11
|
+
}
|
|
@@ -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" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-tree-sitter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "SuPi Tree-sitter extension — structural AST analysis for pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"web-tree-sitter": "^0.26.8",
|
|
27
|
-
"@mrclrchtr/supi-core": "1.
|
|
27
|
+
"@mrclrchtr/supi-core": "1.8.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@earendil-works/pi-ai": "*",
|
package/src/session/runtime.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
import { resolveToolPath } from "@mrclrchtr/supi-core/
|
|
5
|
+
import { resolveToolPath } from "@mrclrchtr/supi-core/path";
|
|
6
6
|
import type { Language, Parser, Tree } from "web-tree-sitter";
|
|
7
7
|
import { nodeToRange } from "../coordinates.ts";
|
|
8
8
|
import { detectGrammar, resolveGrammarWasmPath } from "../language.ts";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Peer extensions can import `getSessionTreeSitterService` from the package API
|
|
3
3
|
// to reuse the active structural runtime without creating duplicate sessions.
|
|
4
4
|
|
|
5
|
-
import { createSessionStateRegistry } from "@mrclrchtr/supi-core/
|
|
5
|
+
import { createSessionStateRegistry } from "@mrclrchtr/supi-core/session";
|
|
6
6
|
import type { SessionTreeSitterService, SessionTreeSitterServiceState } from "../types.ts";
|
|
7
7
|
|
|
8
8
|
const registry = createSessionStateRegistry<SessionTreeSitterServiceState>(
|