@mrclrchtr/supi-code-runtime 4.10.0 → 6.0.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 +2 -0
- package/package.json +1 -1
- package/src/api.ts +9 -0
- package/src/capability/types.ts +53 -13
- package/src/request-control.ts +47 -0
- package/src/types.ts +13 -1
package/README.md
CHANGED
|
@@ -22,6 +22,8 @@ Read-only provider methods return `CodeQueryResult<T>`:
|
|
|
22
22
|
|
|
23
23
|
This keeps successful zero-result facts distinct from routing, transport, and provider failures.
|
|
24
24
|
|
|
25
|
+
Semantic and structural provider methods also accept optional `CodeRequestControl` metadata. It contains a caller `AbortSignal`, an absolute Unix-epoch deadline, and an optional opaque Debug Operation ID. Adapters preserve the same object. The ID does not change cancellation semantics. Canonical helpers identify cancellation and deadline expiry across bundled package copies. Cooperative structural substrates apply the control; unsupported substrates can preserve it without applying behavior.
|
|
26
|
+
|
|
25
27
|
## License
|
|
26
28
|
|
|
27
29
|
MIT
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// Capability interfaces and availability states
|
|
10
10
|
export type {
|
|
11
11
|
CapabilityState,
|
|
12
|
+
CodeRequestControl,
|
|
12
13
|
SemanticProvider,
|
|
13
14
|
StructuralProvider,
|
|
14
15
|
StructuralResult,
|
|
@@ -21,6 +22,13 @@ export {
|
|
|
21
22
|
partialCodeQuery,
|
|
22
23
|
unavailableCodeQuery,
|
|
23
24
|
} from "./query-result.ts";
|
|
25
|
+
export {
|
|
26
|
+
CodeRequestDeadlineError,
|
|
27
|
+
isCodeRequestDeadlineError,
|
|
28
|
+
isCodeRequestInterrupted,
|
|
29
|
+
isCodeRequestInterruption,
|
|
30
|
+
throwIfCodeRequestInterrupted,
|
|
31
|
+
} from "./request-control.ts";
|
|
24
32
|
// Shared canonical types
|
|
25
33
|
export type {
|
|
26
34
|
CalleeDepth,
|
|
@@ -34,6 +42,7 @@ export type {
|
|
|
34
42
|
DeclarationNesting,
|
|
35
43
|
DisambiguationCandidate,
|
|
36
44
|
DocumentCodeSymbol,
|
|
45
|
+
DocumentEditPrecondition,
|
|
37
46
|
ExportData,
|
|
38
47
|
FileEdit,
|
|
39
48
|
ImportData,
|
package/src/capability/types.ts
CHANGED
|
@@ -43,6 +43,16 @@ export type CapabilityState =
|
|
|
43
43
|
|
|
44
44
|
// ── Provider interfaces ────────────────────────────────────────────────
|
|
45
45
|
|
|
46
|
+
/** Request control that adapters preserve and cooperative providers apply. */
|
|
47
|
+
export interface CodeRequestControl {
|
|
48
|
+
/** Opaque Debug Operation ID for work directly owned by one public Tool call. */
|
|
49
|
+
readonly operationId?: string;
|
|
50
|
+
/** Caller cancellation signal, when one exists. */
|
|
51
|
+
readonly signal?: AbortSignal;
|
|
52
|
+
/** Absolute wall-clock deadline in Unix epoch milliseconds. */
|
|
53
|
+
readonly deadline?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
/**
|
|
47
57
|
* Semantic analysis capability backed by a language server (LSP).
|
|
48
58
|
*
|
|
@@ -51,16 +61,31 @@ export type CapabilityState =
|
|
|
51
61
|
* null values are completed observations rather than capability failures.
|
|
52
62
|
*/
|
|
53
63
|
export interface SemanticProvider {
|
|
54
|
-
references(
|
|
64
|
+
references(
|
|
65
|
+
filePath: string,
|
|
66
|
+
position: CodePosition,
|
|
67
|
+
control?: CodeRequestControl,
|
|
68
|
+
): Promise<CodeQueryResult<CodeLocation[]>>;
|
|
55
69
|
implementation(
|
|
56
70
|
filePath: string,
|
|
57
71
|
position: CodePosition,
|
|
72
|
+
control?: CodeRequestControl,
|
|
58
73
|
): Promise<CodeQueryResult<CodeLocation[]>>;
|
|
59
|
-
documentSymbols(
|
|
60
|
-
|
|
74
|
+
documentSymbols(
|
|
75
|
+
filePath: string,
|
|
76
|
+
control?: CodeRequestControl,
|
|
77
|
+
): Promise<CodeQueryResult<DocumentCodeSymbol[]>>;
|
|
78
|
+
workspaceSymbols(
|
|
79
|
+
query: string,
|
|
80
|
+
control?: CodeRequestControl,
|
|
81
|
+
): Promise<CodeQueryResult<CodeSymbol[]>>;
|
|
61
82
|
|
|
62
83
|
/** Optional definition capability with explicit completed-empty semantics. */
|
|
63
|
-
definition?(
|
|
84
|
+
definition?(
|
|
85
|
+
filePath: string,
|
|
86
|
+
position: CodePosition,
|
|
87
|
+
control?: CodeRequestControl,
|
|
88
|
+
): Promise<CodeQueryResult<CodeLocation[]>>;
|
|
64
89
|
|
|
65
90
|
/**
|
|
66
91
|
* Optional hover capability. A completed `null` data value means the
|
|
@@ -69,6 +94,7 @@ export interface SemanticProvider {
|
|
|
69
94
|
hover?(
|
|
70
95
|
filePath: string,
|
|
71
96
|
position: CodePosition,
|
|
97
|
+
control?: CodeRequestControl,
|
|
72
98
|
): Promise<CodeQueryResult<{ contents: string; range?: SourceRange } | null>>;
|
|
73
99
|
|
|
74
100
|
/**
|
|
@@ -79,7 +105,7 @@ export interface SemanticProvider {
|
|
|
79
105
|
* organize imports, dead-code cleanup, etc.) without exposing that branching
|
|
80
106
|
* to callers.
|
|
81
107
|
*/
|
|
82
|
-
refactor?(request: RefactorRequest): Promise<RefactorResult>;
|
|
108
|
+
refactor?(request: RefactorRequest, control?: CodeRequestControl): Promise<RefactorResult>;
|
|
83
109
|
|
|
84
110
|
/**
|
|
85
111
|
* Optional rename capability. When present, the provider supports
|
|
@@ -88,7 +114,12 @@ export interface SemanticProvider {
|
|
|
88
114
|
* This remains a lower-level substrate helper for providers that expose
|
|
89
115
|
* symbol rename independently of their general refactor planner.
|
|
90
116
|
*/
|
|
91
|
-
rename?(
|
|
117
|
+
rename?(
|
|
118
|
+
file: string,
|
|
119
|
+
position: CodePosition,
|
|
120
|
+
newName: string,
|
|
121
|
+
control?: CodeRequestControl,
|
|
122
|
+
): Promise<RefactorResult>;
|
|
92
123
|
|
|
93
124
|
/**
|
|
94
125
|
* Optional code actions capability. When present, the provider
|
|
@@ -96,7 +127,11 @@ export interface SemanticProvider {
|
|
|
96
127
|
*
|
|
97
128
|
* Kept as a low-level substrate helper and for lightweight introspection.
|
|
98
129
|
*/
|
|
99
|
-
codeActions?(
|
|
130
|
+
codeActions?(
|
|
131
|
+
file: string,
|
|
132
|
+
position: CodePosition,
|
|
133
|
+
control?: CodeRequestControl,
|
|
134
|
+
): Promise<RefactorResult[]>;
|
|
100
135
|
}
|
|
101
136
|
|
|
102
137
|
/**
|
|
@@ -111,14 +146,19 @@ export interface StructuralProvider {
|
|
|
111
146
|
file: string,
|
|
112
147
|
line: number,
|
|
113
148
|
character: number,
|
|
114
|
-
depth?: CalleeDepth,
|
|
149
|
+
depthOrOptions?: CalleeDepth | { depth?: CalleeDepth; control?: CodeRequestControl },
|
|
115
150
|
): Promise<CodeResult<CalleesData>>;
|
|
116
|
-
exports(file: string): Promise<CodeResult<ExportData[]>>;
|
|
117
|
-
outline(file: string): Promise<CodeResult<OutlineData[]>>;
|
|
118
|
-
imports(file: string): Promise<CodeResult<ImportData[]>>;
|
|
119
|
-
nodeAt(
|
|
151
|
+
exports(file: string, control?: CodeRequestControl): Promise<CodeResult<ExportData[]>>;
|
|
152
|
+
outline(file: string, control?: CodeRequestControl): Promise<CodeResult<OutlineData[]>>;
|
|
153
|
+
imports(file: string, control?: CodeRequestControl): Promise<CodeResult<ImportData[]>>;
|
|
154
|
+
nodeAt(
|
|
155
|
+
file: string,
|
|
156
|
+
line: number,
|
|
157
|
+
character: number,
|
|
158
|
+
control?: CodeRequestControl,
|
|
159
|
+
): Promise<CodeResult<NodeAtData>>;
|
|
120
160
|
/** Find all call-site identifiers in a file. Returns name + start line for each match. */
|
|
121
|
-
callSites(file: string): Promise<CodeResult<CallSite[]>>;
|
|
161
|
+
callSites(file: string, control?: CodeRequestControl): Promise<CodeResult<CallSite[]>>;
|
|
122
162
|
}
|
|
123
163
|
|
|
124
164
|
/** Convenience alias for `CodeResult` used in structural contexts. */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CodeRequestControl } from "./capability/types.ts";
|
|
2
|
+
|
|
3
|
+
/** Error raised when an absolute code-request deadline has elapsed. */
|
|
4
|
+
export class CodeRequestDeadlineError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("Code request deadline exceeded");
|
|
7
|
+
this.name = "CodeRequestDeadlineError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Test whether request cancellation or its absolute deadline has elapsed. */
|
|
12
|
+
export function isCodeRequestInterrupted(
|
|
13
|
+
control: CodeRequestControl | undefined,
|
|
14
|
+
now: () => number = Date.now,
|
|
15
|
+
): boolean {
|
|
16
|
+
return (
|
|
17
|
+
control?.signal?.aborted === true ||
|
|
18
|
+
(control?.deadline !== undefined && now() >= control.deadline)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Throw the caller abort reason or a canonical absolute-deadline error. */
|
|
23
|
+
export function throwIfCodeRequestInterrupted(
|
|
24
|
+
control: CodeRequestControl | undefined,
|
|
25
|
+
now: () => number = Date.now,
|
|
26
|
+
): void {
|
|
27
|
+
control?.signal?.throwIfAborted();
|
|
28
|
+
if (control?.deadline !== undefined && now() >= control.deadline) {
|
|
29
|
+
throw new CodeRequestDeadlineError();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Identify an absolute-deadline error across bundled package copies. */
|
|
34
|
+
export function isCodeRequestDeadlineError(error: unknown): error is Error {
|
|
35
|
+
return (
|
|
36
|
+
error instanceof CodeRequestDeadlineError ||
|
|
37
|
+
(error instanceof Error && error.name === "CodeRequestDeadlineError")
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Identify an error caused by the supplied request control. */
|
|
42
|
+
export function isCodeRequestInterruption(
|
|
43
|
+
error: unknown,
|
|
44
|
+
control: CodeRequestControl | undefined,
|
|
45
|
+
): boolean {
|
|
46
|
+
return isCodeRequestDeadlineError(error) || control?.signal?.aborted === true;
|
|
47
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -149,11 +149,18 @@ export interface FileEdit {
|
|
|
149
149
|
newText: string;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/** A document-state precondition established when semantic edits are normalized. */
|
|
153
|
+
export type DocumentEditPrecondition =
|
|
154
|
+
| { file: string; kind: "open-document-version"; version: number }
|
|
155
|
+
| { file: string; kind: "disk-content" };
|
|
156
|
+
|
|
152
157
|
/**
|
|
153
158
|
* A precise workspace edit — one or more file edits to apply atomically.
|
|
154
159
|
*/
|
|
155
160
|
export interface WorkspaceEdit {
|
|
156
161
|
edits: FileEdit[];
|
|
162
|
+
/** Document state that the semantic provider validated before it made this plan. */
|
|
163
|
+
documentPreconditions?: DocumentEditPrecondition[];
|
|
157
164
|
}
|
|
158
165
|
|
|
159
166
|
/**
|
|
@@ -202,7 +209,12 @@ export interface DisambiguationCandidate {
|
|
|
202
209
|
* - `unavailable`: refactoring not possible
|
|
203
210
|
*/
|
|
204
211
|
export type RefactorResult =
|
|
205
|
-
| {
|
|
212
|
+
| {
|
|
213
|
+
kind: "precise";
|
|
214
|
+
edits: WorkspaceEdit;
|
|
215
|
+
/** Provider roots authorized by the semantic route. Consumers canonicalize before storage. */
|
|
216
|
+
authorizedMutationRoots: string[];
|
|
217
|
+
}
|
|
206
218
|
| { kind: "ambiguous"; candidates: DisambiguationCandidate[] }
|
|
207
219
|
| { kind: "unavailable"; reason: string };
|
|
208
220
|
|