@mrclrchtr/supi-tree-sitter 1.7.0 → 1.9.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 +44 -16
- package/node_modules/@mrclrchtr/supi-code-runtime/README.md +13 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +97 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +53 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +30 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +76 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config.ts +186 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config.ts +11 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/context/context-messages.ts +119 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/context/context-provider-registry.ts +36 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +31 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/context.ts +16 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +255 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/index.ts +30 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +40 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/path.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +170 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/project.ts +15 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +86 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +29 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/session.ts +4 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +15 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +41 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +226 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings.ts +9 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/substrate-types.ts +11 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/terminal.ts +60 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +116 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/types.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +40 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +35 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +68 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/index.ts +31 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +110 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/context.ts +41 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +170 -0
- package/node_modules/@mrclrchtr/supi-core/README.md +3 -13
- package/node_modules/@mrclrchtr/supi-core/package.json +13 -8
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +26 -92
- 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 +26 -92
- 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/types.ts +2 -0
- package/package.json +9 -6
- package/src/provider/tree-sitter-provider.ts +144 -0
- package/src/session/runtime-registration.ts +37 -0
- 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 +21 -307
- package/node_modules/@mrclrchtr/supi-core/src/extension.ts +0 -1
- package/src/tool/action-specs.ts +0 -92
|
@@ -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,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mrclrchtr/supi-code-runtime",
|
|
3
|
+
"version": "1.9.0",
|
|
4
|
+
"description": "SuPi code-runtime — shared workspace context, capability contracts, and canonical types for the code-understanding stack",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/mrclrchtr/supi.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi",
|
|
15
|
+
"pi-coding-agent"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"src/**/*.ts",
|
|
19
|
+
"!__tests__"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@mrclrchtr/supi-core": "1.9.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"@earendil-works/pi-coding-agent": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"bundledDependencies": [
|
|
33
|
+
"@mrclrchtr/supi-core"
|
|
34
|
+
],
|
|
35
|
+
"main": "src/api.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
"./api": "./src/api.ts",
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API surface for @mrclrchtr/supi-code-runtime.
|
|
3
|
+
*
|
|
4
|
+
* This package exports shared canonical types, capability interfaces,
|
|
5
|
+
* workspace runtime primitives, and typed request context helpers.
|
|
6
|
+
* It is a library-only package with no pi extension entrypoint.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Capability interfaces and availability states
|
|
10
|
+
export type {
|
|
11
|
+
CapabilityState,
|
|
12
|
+
SemanticProvider,
|
|
13
|
+
StructuralProvider,
|
|
14
|
+
StructuralResult,
|
|
15
|
+
} from "./capability/types.ts";
|
|
16
|
+
// Shared canonical types
|
|
17
|
+
export type {
|
|
18
|
+
CalleesData,
|
|
19
|
+
CodeLocation,
|
|
20
|
+
CodePosition,
|
|
21
|
+
CodeResult,
|
|
22
|
+
CodeSymbol,
|
|
23
|
+
ConfidenceMode,
|
|
24
|
+
ExportData,
|
|
25
|
+
ImportData,
|
|
26
|
+
NodeAtData,
|
|
27
|
+
OutlineData,
|
|
28
|
+
SourceRange,
|
|
29
|
+
} from "./types.ts";
|
|
30
|
+
export type { WorkspaceContext } from "./workspace/context.ts";
|
|
31
|
+
// Workspace context
|
|
32
|
+
export { createWorkspaceContext } from "./workspace/context.ts";
|
|
33
|
+
export type { WorkspaceCapabilities } from "./workspace/runtime.ts";
|
|
34
|
+
// Workspace runtime
|
|
35
|
+
export { getDefaultWorkspaceRuntime, WorkspaceRuntime } from "./workspace/runtime.ts";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability interfaces and availability states for the code-understanding
|
|
3
|
+
* stack. These define the contracts through which substrates (LSP,
|
|
4
|
+
* tree-sitter) advertise what they can do.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
CalleesData,
|
|
9
|
+
CodeLocation,
|
|
10
|
+
CodePosition,
|
|
11
|
+
CodeResult,
|
|
12
|
+
CodeSymbol,
|
|
13
|
+
ExportData,
|
|
14
|
+
ImportData,
|
|
15
|
+
NodeAtData,
|
|
16
|
+
OutlineData,
|
|
17
|
+
} from "../types.ts";
|
|
18
|
+
|
|
19
|
+
// ── Availability state ─────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Availability state for a capability within a workspace.
|
|
23
|
+
*
|
|
24
|
+
* - `pending`: the capability may become ready soon (e.g., server starting)
|
|
25
|
+
* - `ready`: the capability is active and can be used
|
|
26
|
+
* - `inactive`: the capability exists but is intentionally turned off
|
|
27
|
+
* - `disabled`: the capability is unavailable for workspace-specific reasons
|
|
28
|
+
* - `unavailable`: the capability cannot be provided at all
|
|
29
|
+
*/
|
|
30
|
+
export type CapabilityState =
|
|
31
|
+
| { kind: "pending" }
|
|
32
|
+
| { kind: "ready" }
|
|
33
|
+
| { kind: "inactive" }
|
|
34
|
+
| { kind: "disabled" }
|
|
35
|
+
| { kind: "unavailable"; reason: string };
|
|
36
|
+
|
|
37
|
+
// ── Provider interfaces ────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Semantic analysis capability backed by a language server (LSP).
|
|
41
|
+
*
|
|
42
|
+
* Methods return `null` to signal absence (unavailable / inactive) and
|
|
43
|
+
* an array to signal a successful query (possibly empty).
|
|
44
|
+
*/
|
|
45
|
+
export interface SemanticProvider {
|
|
46
|
+
references(filePath: string, position: CodePosition): Promise<CodeLocation[] | null>;
|
|
47
|
+
implementation(filePath: string, position: CodePosition): Promise<CodeLocation[] | null>;
|
|
48
|
+
documentSymbols(filePath: string): Promise<CodeSymbol[] | null>;
|
|
49
|
+
workspaceSymbols(query: string): Promise<CodeSymbol[] | null>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Structural analysis capability backed by a parser (tree-sitter).
|
|
54
|
+
*
|
|
55
|
+
* Methods return a discriminated `CodeResult` union that explicitly encodes
|
|
56
|
+
* success, unsupported-language, file-access error, validation error,
|
|
57
|
+
* and runtime error states.
|
|
58
|
+
*/
|
|
59
|
+
export interface StructuralProvider {
|
|
60
|
+
calleesAt(file: string, line: number, character: number): Promise<CodeResult<CalleesData>>;
|
|
61
|
+
exports(file: string): Promise<CodeResult<ExportData[]>>;
|
|
62
|
+
outline(file: string): Promise<CodeResult<OutlineData[]>>;
|
|
63
|
+
imports(file: string): Promise<CodeResult<ImportData[]>>;
|
|
64
|
+
nodeAt(file: string, line: number, character: number): Promise<CodeResult<NodeAtData>>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Convenience alias for `CodeResult` used in structural contexts. */
|
|
68
|
+
export type StructuralResult<T> = CodeResult<T>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-root re-export surface for @mrclrchtr/supi-code-runtime.
|
|
3
|
+
*
|
|
4
|
+
* Prefer importing from `@mrclrchtr/supi-code-runtime/api` for explicit
|
|
5
|
+
* access to the shared contracts and workspace primitives.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type {
|
|
9
|
+
CalleesData,
|
|
10
|
+
CapabilityState,
|
|
11
|
+
CodeLocation,
|
|
12
|
+
CodePosition,
|
|
13
|
+
CodeResult,
|
|
14
|
+
CodeSymbol,
|
|
15
|
+
ConfidenceMode,
|
|
16
|
+
ExportData,
|
|
17
|
+
ImportData,
|
|
18
|
+
NodeAtData,
|
|
19
|
+
OutlineData,
|
|
20
|
+
SemanticProvider,
|
|
21
|
+
SourceRange,
|
|
22
|
+
StructuralProvider,
|
|
23
|
+
StructuralResult,
|
|
24
|
+
WorkspaceCapabilities,
|
|
25
|
+
WorkspaceContext,
|
|
26
|
+
} from "./api.ts";
|
|
27
|
+
export {
|
|
28
|
+
createWorkspaceContext,
|
|
29
|
+
getDefaultWorkspaceRuntime,
|
|
30
|
+
WorkspaceRuntime,
|
|
31
|
+
} from "./api.ts";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical shared types for the SuPi code-understanding stack.
|
|
3
|
+
*
|
|
4
|
+
* These types are package-agnostic and used across supi-lsp, supi-tree-sitter,
|
|
5
|
+
* and supi-code-intelligence for communicating code analysis results,
|
|
6
|
+
* capability availability, and structural data shapes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ── Position and location types ────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
/** 0-based LSP position. */
|
|
12
|
+
export interface CodePosition {
|
|
13
|
+
line: number;
|
|
14
|
+
character: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A source range spanning two CodePositions. */
|
|
18
|
+
export interface SourceRange {
|
|
19
|
+
start: CodePosition;
|
|
20
|
+
end: CodePosition;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A code location (file URI + range). */
|
|
24
|
+
export interface CodeLocation {
|
|
25
|
+
uri: string;
|
|
26
|
+
range: SourceRange;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ── Symbol types ───────────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
/** A discovered symbol / declaration. */
|
|
32
|
+
export interface CodeSymbol {
|
|
33
|
+
name: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
file: string;
|
|
36
|
+
line: number;
|
|
37
|
+
character: number;
|
|
38
|
+
container?: string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ── Result types ───────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Discriminated result union for provider operations.
|
|
45
|
+
*
|
|
46
|
+
* Used primarily by structural (tree-sitter-backed) operations that
|
|
47
|
+
* have explicit error and unsupported-language states. Semantic operations
|
|
48
|
+
* use `null` to signal absence.
|
|
49
|
+
*/
|
|
50
|
+
export type CodeResult<T> =
|
|
51
|
+
| { kind: "success"; data: T }
|
|
52
|
+
| { kind: "unsupported-language"; file: string; message: string }
|
|
53
|
+
| { kind: "file-access-error"; file: string; message: string }
|
|
54
|
+
| { kind: "validation-error"; message: string }
|
|
55
|
+
| { kind: "runtime-error"; message: string }
|
|
56
|
+
| { kind: "unavailable"; message: string };
|
|
57
|
+
|
|
58
|
+
/** Result confidence classification. */
|
|
59
|
+
export type ConfidenceMode = "semantic" | "structural" | "heuristic" | "unavailable";
|
|
60
|
+
|
|
61
|
+
// ── Structural data shapes (value types, range-flattened) ──────────────
|
|
62
|
+
|
|
63
|
+
export interface OutlineData {
|
|
64
|
+
name: string;
|
|
65
|
+
kind: string;
|
|
66
|
+
startLine: number;
|
|
67
|
+
startCharacter: number;
|
|
68
|
+
endLine: number;
|
|
69
|
+
endCharacter: number;
|
|
70
|
+
children?: OutlineData[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ExportData {
|
|
74
|
+
name: string;
|
|
75
|
+
kind: string;
|
|
76
|
+
startLine: number;
|
|
77
|
+
startCharacter: number;
|
|
78
|
+
endLine: number;
|
|
79
|
+
endCharacter: number;
|
|
80
|
+
moduleSpecifier?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ImportData {
|
|
84
|
+
moduleSpecifier: string;
|
|
85
|
+
startLine: number;
|
|
86
|
+
startCharacter: number;
|
|
87
|
+
endLine: number;
|
|
88
|
+
endCharacter: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface NodeAtData {
|
|
92
|
+
type: string;
|
|
93
|
+
startLine: number;
|
|
94
|
+
startCharacter: number;
|
|
95
|
+
endLine: number;
|
|
96
|
+
endCharacter: number;
|
|
97
|
+
text: string;
|
|
98
|
+
ancestry: Array<{
|
|
99
|
+
type: string;
|
|
100
|
+
startLine: number;
|
|
101
|
+
startCharacter: number;
|
|
102
|
+
endLine: number;
|
|
103
|
+
endCharacter: number;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface CalleesData {
|
|
108
|
+
enclosingScope: { name: string; startLine: number; endLine: number };
|
|
109
|
+
callees: Array<{ name: string; startLine: number }>;
|
|
110
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed request context helper for consumers that need a convenient view
|
|
3
|
+
* of the capability state for a workspace cwd.
|
|
4
|
+
*
|
|
5
|
+
* This is the primary way that `supi-code-intelligence` reads capability
|
|
6
|
+
* state from the shared runtime. Substrates register providers through
|
|
7
|
+
* {@link WorkspaceRuntime} directly.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CapabilityState, SemanticProvider, StructuralProvider } from "../capability/types.ts";
|
|
11
|
+
import type { WorkspaceRuntime } from "./runtime.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A workspace-scoped request context that provides access to active
|
|
15
|
+
* semantic and structural capabilities along with their availability
|
|
16
|
+
* state and the cached project model.
|
|
17
|
+
*/
|
|
18
|
+
export interface WorkspaceContext {
|
|
19
|
+
/** The working directory this context is scoped to. */
|
|
20
|
+
cwd: string;
|
|
21
|
+
/** Semantic analysis capability state and provider. */
|
|
22
|
+
semantic: { state: CapabilityState; provider: SemanticProvider | null };
|
|
23
|
+
/** Structural analysis capability state and provider. */
|
|
24
|
+
structural: { state: CapabilityState; provider: StructuralProvider | null };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a typed workspace context from the shared runtime.
|
|
29
|
+
*
|
|
30
|
+
* @param cwd - The working directory for this context.
|
|
31
|
+
* @param runtime - The shared workspace runtime instance.
|
|
32
|
+
* @returns A snapshot of the capability state for this workspace.
|
|
33
|
+
*/
|
|
34
|
+
export function createWorkspaceContext(cwd: string, runtime: WorkspaceRuntime): WorkspaceContext {
|
|
35
|
+
const ws = runtime.getWorkspace(cwd);
|
|
36
|
+
return {
|
|
37
|
+
cwd,
|
|
38
|
+
semantic: ws.semantic,
|
|
39
|
+
structural: ws.structural,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace-scoped capability registry.
|
|
3
|
+
*
|
|
4
|
+
* Substrates (LSP, tree-sitter) register their capabilities per cwd
|
|
5
|
+
* at session startup. Code-intelligence reads capability state from
|
|
6
|
+
* this registry instead of maintaining a local provider composition
|
|
7
|
+
* layer.
|
|
8
|
+
*
|
|
9
|
+
* Capabilities are independent: registering a semantic provider does not
|
|
10
|
+
* affect an already-registered structural provider for the same cwd.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { CapabilityState, SemanticProvider, StructuralProvider } from "../capability/types.ts";
|
|
14
|
+
|
|
15
|
+
// ── Public types ───────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The combined capability state for a workspace.
|
|
19
|
+
* Each capability slot includes both the availability state and the
|
|
20
|
+
* provider instance (null when not ready).
|
|
21
|
+
*/
|
|
22
|
+
export interface WorkspaceCapabilities {
|
|
23
|
+
semantic: { state: CapabilityState; provider: SemanticProvider | null };
|
|
24
|
+
structural: { state: CapabilityState; provider: StructuralProvider | null };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ── Defaults ───────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
const DEFAULT_UNAVAILABLE_REASON = "No provider registered for this workspace";
|
|
30
|
+
|
|
31
|
+
function createDefaultCapabilities(): WorkspaceCapabilities {
|
|
32
|
+
return {
|
|
33
|
+
semantic: {
|
|
34
|
+
state: { kind: "unavailable", reason: DEFAULT_UNAVAILABLE_REASON },
|
|
35
|
+
provider: null,
|
|
36
|
+
},
|
|
37
|
+
structural: {
|
|
38
|
+
state: { kind: "unavailable", reason: DEFAULT_UNAVAILABLE_REASON },
|
|
39
|
+
provider: null,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── Runtime ────────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Workspace-scoped capability registry keyed by cwd/project root.
|
|
48
|
+
*
|
|
49
|
+
* Each workspace stores independent capability state for semantic
|
|
50
|
+
* (LSP-backed) and structural (tree-sitter-backed) analysis. Substrates
|
|
51
|
+
* register their capabilities at session start; consumers read them
|
|
52
|
+
* as needed.
|
|
53
|
+
*
|
|
54
|
+
* The registry is intentionally unopinionated about which capabilities
|
|
55
|
+
* are required — a workspace may have only semantic, only structural,
|
|
56
|
+
* both, or neither.
|
|
57
|
+
*/
|
|
58
|
+
export class WorkspaceRuntime {
|
|
59
|
+
readonly #workspaces = new Map<string, WorkspaceCapabilities>();
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get the capability state for a workspace cwd.
|
|
63
|
+
* Returns a default "unavailable" state if the workspace
|
|
64
|
+
* has never been registered.
|
|
65
|
+
*/
|
|
66
|
+
getWorkspace(cwd: string): WorkspaceCapabilities {
|
|
67
|
+
return this.#workspaces.get(cwd) ?? createDefaultCapabilities();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Register a semantic provider for a workspace.
|
|
72
|
+
* Replaces any existing semantic provider for the same cwd
|
|
73
|
+
* without affecting the structural provider.
|
|
74
|
+
*/
|
|
75
|
+
registerSemantic(cwd: string, provider: SemanticProvider): void {
|
|
76
|
+
const existing = this.#workspaces.get(cwd);
|
|
77
|
+
if (existing) {
|
|
78
|
+
existing.semantic = { state: { kind: "ready" }, provider };
|
|
79
|
+
} else {
|
|
80
|
+
this.#workspaces.set(cwd, {
|
|
81
|
+
semantic: { state: { kind: "ready" }, provider },
|
|
82
|
+
structural: createDefaultCapabilities().structural,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Register a structural provider for a workspace.
|
|
89
|
+
* Replaces any existing structural provider for the same cwd
|
|
90
|
+
* without affecting the semantic provider.
|
|
91
|
+
*/
|
|
92
|
+
registerStructural(cwd: string, provider: StructuralProvider): void {
|
|
93
|
+
const existing = this.#workspaces.get(cwd);
|
|
94
|
+
if (existing) {
|
|
95
|
+
existing.structural = { state: { kind: "ready" }, provider };
|
|
96
|
+
} else {
|
|
97
|
+
this.#workspaces.set(cwd, {
|
|
98
|
+
semantic: createDefaultCapabilities().semantic,
|
|
99
|
+
structural: { state: { kind: "ready" }, provider },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Remove all capability state for a single workspace cwd.
|
|
106
|
+
*/
|
|
107
|
+
clearWorkspace(cwd: string): void {
|
|
108
|
+
this.#workspaces.delete(cwd);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Clear only the semantic capability slot for a workspace.
|
|
113
|
+
* Leaves the structural slot untouched.
|
|
114
|
+
*/
|
|
115
|
+
clearSemantic(cwd: string): void {
|
|
116
|
+
const ws = this.#workspaces.get(cwd);
|
|
117
|
+
if (!ws) return;
|
|
118
|
+
ws.semantic = createDefaultCapabilities().semantic;
|
|
119
|
+
// If both slots are now unavailable, remove the entire entry
|
|
120
|
+
if (ws.semantic.state.kind === "unavailable" && ws.structural.state.kind === "unavailable") {
|
|
121
|
+
this.#workspaces.delete(cwd);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Clear only the structural capability slot for a workspace.
|
|
127
|
+
* Leaves the semantic slot untouched.
|
|
128
|
+
*/
|
|
129
|
+
clearStructural(cwd: string): void {
|
|
130
|
+
const ws = this.#workspaces.get(cwd);
|
|
131
|
+
if (!ws) return;
|
|
132
|
+
ws.structural = createDefaultCapabilities().structural;
|
|
133
|
+
// If both slots are now unavailable, remove the entire entry
|
|
134
|
+
if (ws.semantic.state.kind === "unavailable" && ws.structural.state.kind === "unavailable") {
|
|
135
|
+
this.#workspaces.delete(cwd);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Remove all capability state for every workspace.
|
|
141
|
+
*/
|
|
142
|
+
clearAll(): void {
|
|
143
|
+
this.#workspaces.clear();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── Default singleton ───────────────────────────────────────────────────
|
|
148
|
+
|
|
149
|
+
const RUNTIME_SYMBOL = Symbol.for("@mrclrchtr/supi-code-runtime/default-runtime");
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get the shared default workspace runtime instance.
|
|
153
|
+
*
|
|
154
|
+
* Backed by `globalThis` + `Symbol.for` so that all jiti module instances
|
|
155
|
+
* (even duplicate loads through separate `node_modules` paths) share the
|
|
156
|
+
* same WorkspaceRuntime. Without this, standalone installs where
|
|
157
|
+
* `supi-lsp`, `supi-tree-sitter`, and `supi-code-intelligence` each bundle
|
|
158
|
+
* their own copy of `@mrclrchtr/supi-code-runtime` would get separate
|
|
159
|
+
* runtimes — LSP/tree-sitter would register capabilities into one while
|
|
160
|
+
* code-intelligence reads from another.
|
|
161
|
+
*/
|
|
162
|
+
export function getDefaultWorkspaceRuntime(): WorkspaceRuntime {
|
|
163
|
+
const g = globalThis as Record<symbol, unknown>;
|
|
164
|
+
let runtime = g[RUNTIME_SYMBOL] as WorkspaceRuntime | undefined;
|
|
165
|
+
if (!runtime) {
|
|
166
|
+
runtime = new WorkspaceRuntime();
|
|
167
|
+
g[RUNTIME_SYMBOL] = runtime;
|
|
168
|
+
}
|
|
169
|
+
return runtime;
|
|
170
|
+
}
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# @mrclrchtr/supi-core
|
|
2
4
|
|
|
3
5
|
Shared infrastructure for SuPi extensions.
|
|
4
6
|
|
|
5
|
-
This
|
|
7
|
+
This is a **pure library** — it does not register any pi commands or tools. The `/supi-settings` command is now available through `@mrclrchtr/supi-settings`.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
|
-
### As a dependency for another extension
|
|
10
|
-
|
|
11
11
|
```bash
|
|
12
12
|
pnpm add @mrclrchtr/supi-core
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
### As a pi package
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
pi install npm:@mrclrchtr/supi-core
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Installing it as a pi package adds the minimal `/supi-settings` extension surface.
|
|
22
|
-
|
|
23
15
|
## Package surfaces
|
|
24
16
|
|
|
25
17
|
- `@mrclrchtr/supi-core/api` — reusable helpers for other packages and extensions
|
|
26
|
-
- `@mrclrchtr/supi-core/extension` — minimal pi extension that registers `/supi-settings`
|
|
27
18
|
|
|
28
19
|
## What you get from the API
|
|
29
20
|
|
|
@@ -101,7 +92,6 @@ const message = wrapExtensionContext("my-extension", "hello", {
|
|
|
101
92
|
## Source
|
|
102
93
|
|
|
103
94
|
- `src/api.ts` — exported library surface
|
|
104
|
-
- `src/extension.ts` — minimal `/supi-settings` entrypoint
|
|
105
95
|
- `src/config.ts` — shared config loading and writing
|
|
106
96
|
- `src/config-settings.ts` — config-backed settings registration helper
|
|
107
97
|
- `src/settings-ui.ts` — shared settings overlay
|