carrick 0.3.138 → 0.3.139
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/package.json +7 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/affected-set.d.ts +172 -0
- package/sidecar/dist/src/affected-set.js +936 -0
- package/sidecar/dist/src/capture/api.d.ts +23 -0
- package/sidecar/dist/src/capture/backfill.d.ts +37 -0
- package/sidecar/dist/src/capture/backfill.js +75 -0
- package/sidecar/dist/src/capture/index.js +419 -133
- package/sidecar/dist/src/capture/installed-package.js +36 -29
- package/sidecar/dist/src/capture/self-check.d.ts +14 -3
- package/sidecar/dist/src/capture/self-check.js +37 -29
- package/sidecar/dist/src/index.js +77 -0
- package/sidecar/dist/src/module-format.d.ts +13 -2
- package/sidecar/dist/src/module-format.js +31 -1
- package/sidecar/dist/src/project-loader.d.ts +7 -0
- package/sidecar/dist/src/project-loader.js +11 -0
- package/sidecar/dist/src/retype.d.ts +19 -3
- package/sidecar/dist/src/retype.js +69 -29
- package/sidecar/dist/src/types.d.ts +101 -3
- package/sidecar/dist/src/validators.d.ts +413 -4
- package/sidecar/dist/src/validators.js +41 -1
|
@@ -66,14 +66,14 @@ export class Retyper {
|
|
|
66
66
|
const before = new Map();
|
|
67
67
|
return items.map((item) => {
|
|
68
68
|
if (performance.now() >= deadline) {
|
|
69
|
-
return abstain(item, `the retype check ran out of its ${budgetMs}ms budget`);
|
|
69
|
+
return runFailed(abstain(item, `the retype check ran out of its ${budgetMs}ms budget`));
|
|
70
70
|
}
|
|
71
71
|
let outcome;
|
|
72
72
|
try {
|
|
73
73
|
outcome = this.runOne(item, before);
|
|
74
74
|
}
|
|
75
75
|
catch (err) {
|
|
76
|
-
outcome = abstain(item, `the retype check failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
76
|
+
outcome = runFailed(abstain(item, `the retype check failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
77
77
|
}
|
|
78
78
|
onJudged?.();
|
|
79
79
|
return outcome;
|
|
@@ -88,24 +88,11 @@ export class Retyper {
|
|
|
88
88
|
// comment over the rest of the call.
|
|
89
89
|
return abstain(item, "the producer's response type carries a comment");
|
|
90
90
|
}
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
return abstain(item,
|
|
94
|
-
const { sourceFile, call } =
|
|
95
|
-
|
|
96
|
-
// Nothing reads the response, so nothing can disagree with it: an
|
|
97
|
-
// "agrees" here would be a verdict about no comparison at all.
|
|
98
|
-
return abstain(item, 'the consumer never reads the response');
|
|
99
|
-
}
|
|
100
|
-
const escape = resultEscapes(call);
|
|
101
|
-
if (escape) {
|
|
102
|
-
// Only this file's diagnostics are compared, so reads made where the
|
|
103
|
-
// value escapes to are invisible and an "agrees" would claim them.
|
|
104
|
-
return abstain(item, escape);
|
|
105
|
-
}
|
|
106
|
-
const plan = this.plan(call, producer, item.wire);
|
|
107
|
-
if (typeof plan === 'string')
|
|
108
|
-
return abstain(item, plan);
|
|
91
|
+
const found = this.beforeRewrite(item);
|
|
92
|
+
if (typeof found === 'string')
|
|
93
|
+
return abstain(item, found);
|
|
94
|
+
const { sourceFile, call } = found;
|
|
95
|
+
const plan = found.plan(producer, item.wire);
|
|
109
96
|
// Planned now: a check forgets every node of the file, `call` included.
|
|
110
97
|
const unwidened = this.unwidenedPlan(call, item);
|
|
111
98
|
const original = sourceFile.getFullText();
|
|
@@ -156,6 +143,51 @@ export class Retyper {
|
|
|
156
143
|
})),
|
|
157
144
|
};
|
|
158
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Per item, the reason `run` abstains for before any rewrite, which no
|
|
148
|
+
* producer type changes, or `undefined` when only the rewrite can decide
|
|
149
|
+
* the call (carrick#3132). The scan asks this in the consumer's own
|
|
150
|
+
* analysis, so a consumer whose calls all abstain here builds no retype
|
|
151
|
+
* program. A call that throws here is left to the retype, which reports
|
|
152
|
+
* the failure itself.
|
|
153
|
+
*/
|
|
154
|
+
prescreen(items) {
|
|
155
|
+
return items.map((item) => {
|
|
156
|
+
try {
|
|
157
|
+
const found = this.beforeRewrite(item);
|
|
158
|
+
return typeof found === 'string' ? found : undefined;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The call and how to state a type at it, or why the retype abstains
|
|
167
|
+
* before any rewrite. Reads only the consumer's own code: the producer's
|
|
168
|
+
* type is stated by the returned plan.
|
|
169
|
+
*/
|
|
170
|
+
beforeRewrite(item) {
|
|
171
|
+
const located = this.inferrer.locateCall(asLocator(item));
|
|
172
|
+
if (!located)
|
|
173
|
+
return 'the consumer call could not be located in its file';
|
|
174
|
+
const { sourceFile, call } = located;
|
|
175
|
+
if (resultIsDiscarded(call)) {
|
|
176
|
+
// Nothing reads the response, so nothing can disagree with it: an
|
|
177
|
+
// "agrees" here would be a verdict about no comparison at all.
|
|
178
|
+
return 'the consumer never reads the response';
|
|
179
|
+
}
|
|
180
|
+
const escape = resultEscapes(call);
|
|
181
|
+
if (escape) {
|
|
182
|
+
// Only this file's diagnostics are compared, so reads made where the
|
|
183
|
+
// value escapes to are invisible and an "agrees" would claim them.
|
|
184
|
+
return escape;
|
|
185
|
+
}
|
|
186
|
+
const plan = this.plan(call);
|
|
187
|
+
if (typeof plan === 'string')
|
|
188
|
+
return plan;
|
|
189
|
+
return { sourceFile, call, plan };
|
|
190
|
+
}
|
|
159
191
|
/**
|
|
160
192
|
* The rewrite that states the producer's UNWIDENED return (carrick#1516),
|
|
161
193
|
* when the item carries one that can be stated at this call.
|
|
@@ -164,15 +196,16 @@ export class Retyper {
|
|
|
164
196
|
const text = oneLine(item.producer_unwidened_type ?? '');
|
|
165
197
|
if (!text || text.includes('//') || text.includes('/*'))
|
|
166
198
|
return undefined;
|
|
167
|
-
const plan = this.plan(call
|
|
168
|
-
return typeof plan === 'string' ? undefined : plan;
|
|
199
|
+
const plan = this.plan(call);
|
|
200
|
+
return typeof plan === 'string' ? undefined : plan(text, item.wire);
|
|
169
201
|
}
|
|
170
202
|
/**
|
|
171
|
-
* How to state
|
|
172
|
-
*
|
|
203
|
+
* How to state a producer's type at this call, or why it cannot be done
|
|
204
|
+
* whatever that type is. The builder it returns takes the type, and then
|
|
205
|
+
* builds the wire and the declared form from one decision.
|
|
173
206
|
*/
|
|
174
|
-
plan(call
|
|
175
|
-
const
|
|
207
|
+
plan(call) {
|
|
208
|
+
const statedAs = (producer, wire) => (useWire) => useWire && wire ? `${WIRE}<(${producer})>` : `(${producer})`;
|
|
176
209
|
const callStart = call.getStart();
|
|
177
210
|
const callEnd = call.getEnd();
|
|
178
211
|
const typeArgs = call.getTypeArguments();
|
|
@@ -183,7 +216,8 @@ export class Retyper {
|
|
|
183
216
|
// Positions are read now: the rewrite forgets every node of the file.
|
|
184
217
|
const argStart = typeArgs[0].getStart();
|
|
185
218
|
const argEnd = typeArgs[0].getEnd();
|
|
186
|
-
return (useWire) => {
|
|
219
|
+
return (producer, wire) => (useWire) => {
|
|
220
|
+
const stated = statedAs(producer, wire);
|
|
187
221
|
const text = stated(useWire);
|
|
188
222
|
const delta = text.length - (argEnd - argStart);
|
|
189
223
|
return {
|
|
@@ -205,7 +239,8 @@ export class Retyper {
|
|
|
205
239
|
if (!open)
|
|
206
240
|
return 'the consumer call has no argument list to retype';
|
|
207
241
|
const at = open.getStart();
|
|
208
|
-
return (useWire) => {
|
|
242
|
+
return (producer, wire) => (useWire) => {
|
|
243
|
+
const stated = statedAs(producer, wire);
|
|
209
244
|
const text = `<${stated(useWire)}>`;
|
|
210
245
|
return {
|
|
211
246
|
edits: [{ start: at, end: at, text, statedAt: 1 }],
|
|
@@ -231,7 +266,8 @@ export class Retyper {
|
|
|
231
266
|
return reads;
|
|
232
267
|
if (reads.length > 0) {
|
|
233
268
|
const edits = reads.map(bodyReadEdit);
|
|
234
|
-
return (useWire) => {
|
|
269
|
+
return (producer, wire) => (useWire) => {
|
|
270
|
+
const stated = statedAs(producer, wire);
|
|
235
271
|
const text = stated(useWire);
|
|
236
272
|
return {
|
|
237
273
|
edits: edits.flatMap((edit) => edit(text)),
|
|
@@ -420,6 +456,10 @@ export class Retyper {
|
|
|
420
456
|
function abstain(item, reason) {
|
|
421
457
|
return { item_id: item.item_id, outcome: 'abstain', diagnostics: [], reason };
|
|
422
458
|
}
|
|
459
|
+
/** `outcome`, marked as an abstention the run caused (carrick#3104). */
|
|
460
|
+
function runFailed(outcome) {
|
|
461
|
+
return { ...outcome, run_failed: true };
|
|
462
|
+
}
|
|
423
463
|
function asLocator(item) {
|
|
424
464
|
return {
|
|
425
465
|
file_path: item.file_path,
|
|
@@ -154,6 +154,14 @@ export interface CaptureV2Request extends BaseRequest {
|
|
|
154
154
|
tsconfig_path?: string;
|
|
155
155
|
/** The scanned repo's root, as on `init` (carrick#1776). */
|
|
156
156
|
scan_root?: string;
|
|
157
|
+
/**
|
|
158
|
+
* carrick#2041: alias -> literal type text the scanner can stand behind. A
|
|
159
|
+
* demoted alias with a text here is captured again in this request,
|
|
160
|
+
* re-anchored on the text, into `backfill_out_dir`.
|
|
161
|
+
*/
|
|
162
|
+
backfill_texts?: Record<string, string>;
|
|
163
|
+
/** Where the backfilled stub is written; sent with `backfill_texts`. */
|
|
164
|
+
backfill_out_dir?: string;
|
|
157
165
|
}
|
|
158
166
|
/**
|
|
159
167
|
* Response for the capture_v2 action
|
|
@@ -272,6 +280,52 @@ export interface ShutdownRequest extends BaseRequest {
|
|
|
272
280
|
export interface ListProgramFilesRequest extends BaseRequest {
|
|
273
281
|
action: 'list_program_files';
|
|
274
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* The import graph without statement texts. Every name and path is an index
|
|
285
|
+
* into `strings`. Per file: its path, whether it is a script, its declared
|
|
286
|
+
* names, the identifiers each declared name mentions that can matter (a
|
|
287
|
+
* binding, a whole-module local or one of the file's own declared names), the
|
|
288
|
+
* same for each loose statement, its exports, its export targets, its
|
|
289
|
+
* bindings (local, imported name or -1, origin file and name pairs), its
|
|
290
|
+
* whole-module locals, and its stems (target file or -1, locals, stems).
|
|
291
|
+
*/
|
|
292
|
+
export interface SerialGraph {
|
|
293
|
+
version: 1;
|
|
294
|
+
strings: string[];
|
|
295
|
+
files: Array<{
|
|
296
|
+
p: number;
|
|
297
|
+
g: 0 | 1;
|
|
298
|
+
d: number[];
|
|
299
|
+
r: number[][];
|
|
300
|
+
l: number[][];
|
|
301
|
+
e: number[];
|
|
302
|
+
t: number[][];
|
|
303
|
+
b: Array<[number, number, number[]]>;
|
|
304
|
+
w: number[];
|
|
305
|
+
s: Array<[number, number[], number[]]>;
|
|
306
|
+
}>;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The import graph of every program the process has built, without statement
|
|
310
|
+
* texts (carrick#3100). Builds the default program when none is built.
|
|
311
|
+
*/
|
|
312
|
+
export interface ReachGraphRequest extends BaseRequest {
|
|
313
|
+
action: 'reach_graph';
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The files a set of edits can reach in a graph `reach_graph` wrote
|
|
317
|
+
* (carrick#3100). Needs no program and no `init`. Paths are relative to the
|
|
318
|
+
* scan root; a missing side of an added or deleted file is `''`.
|
|
319
|
+
*/
|
|
320
|
+
export interface ReachRequest extends BaseRequest {
|
|
321
|
+
action: 'reach';
|
|
322
|
+
graph: SerialGraph;
|
|
323
|
+
changes: Array<{
|
|
324
|
+
file: string;
|
|
325
|
+
before: string;
|
|
326
|
+
after: string;
|
|
327
|
+
}>;
|
|
328
|
+
}
|
|
275
329
|
/**
|
|
276
330
|
* Add files to the programs that type them, in the given order
|
|
277
331
|
* (carrick#2027).
|
|
@@ -353,7 +407,7 @@ export interface ResolveDefinitionsRequest extends BaseRequest {
|
|
|
353
407
|
* The locator is the one the consumer's `call_result` inference used: a span,
|
|
354
408
|
* or expression text near a line.
|
|
355
409
|
*/
|
|
356
|
-
export interface
|
|
410
|
+
export interface RetypeLocatorItem {
|
|
357
411
|
/** Caller key, echoed on the outcome. */
|
|
358
412
|
item_id: string;
|
|
359
413
|
/** Absolute path, or relative to the init'd root. */
|
|
@@ -363,6 +417,8 @@ export interface RetypeItem {
|
|
|
363
417
|
span_end?: number;
|
|
364
418
|
expression_text?: string;
|
|
365
419
|
expression_line?: number;
|
|
420
|
+
}
|
|
421
|
+
export interface RetypeItem extends RetypeLocatorItem {
|
|
366
422
|
/** The producer's response type as TypeScript text, fully inlined. */
|
|
367
423
|
producer_type: string;
|
|
368
424
|
/**
|
|
@@ -374,6 +430,25 @@ export interface RetypeItem {
|
|
|
374
430
|
/** Judge the form JSON puts on the wire (an `http` response). */
|
|
375
431
|
wire: boolean;
|
|
376
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Ask, without a producer type, which consumer calls the retype abstains for
|
|
435
|
+
* before any rewrite (carrick#3132). Needs `init`: it reads the consumer's
|
|
436
|
+
* real program, as `retype_check` does.
|
|
437
|
+
*/
|
|
438
|
+
export interface RetypePrescreenRequest extends BaseRequest {
|
|
439
|
+
action: 'retype_prescreen';
|
|
440
|
+
items: RetypeLocatorItem[];
|
|
441
|
+
}
|
|
442
|
+
/** One call's prescreen: `reason` when the retype abstains before any rewrite. */
|
|
443
|
+
export interface RetypePrescreen {
|
|
444
|
+
item_id: string;
|
|
445
|
+
reason?: string;
|
|
446
|
+
}
|
|
447
|
+
export interface RetypePrescreenResponse extends BaseResponse {
|
|
448
|
+
/** One per item, in request order. */
|
|
449
|
+
prescreens?: RetypePrescreen[];
|
|
450
|
+
errors?: string[];
|
|
451
|
+
}
|
|
377
452
|
/**
|
|
378
453
|
* Retype consumer calls with the producer's response type and report what the
|
|
379
454
|
* consumer file's own type-check says about it. Needs `init`: it runs in the
|
|
@@ -740,7 +815,7 @@ export interface ListLibrarySurfaceRequest extends BaseRequest {
|
|
|
740
815
|
/**
|
|
741
816
|
* Union type for all possible sidecar requests
|
|
742
817
|
*/
|
|
743
|
-
export type SidecarRequest = RetypeCheckRequest | VerifyClientSemanticsRequest | VerifyLibraryClaimsRequest | ListLibrarySurfaceRequest | InitRequest | BundleRequest | CaptureV2Request | CheckV2Request | InferRequest | ResolveDefinitionsRequest | HealthRequest | ShutdownRequest | ListProgramFilesRequest | AddProgramFilesRequest | PositionRowsRequest | ImplementationsRequest;
|
|
818
|
+
export type SidecarRequest = RetypeCheckRequest | RetypePrescreenRequest | VerifyClientSemanticsRequest | VerifyLibraryClaimsRequest | ListLibrarySurfaceRequest | InitRequest | BundleRequest | CaptureV2Request | CheckV2Request | InferRequest | ResolveDefinitionsRequest | HealthRequest | ShutdownRequest | ListProgramFilesRequest | ReachGraphRequest | ReachRequest | AddProgramFilesRequest | PositionRowsRequest | ImplementationsRequest;
|
|
744
819
|
/**
|
|
745
820
|
* Request for a specific symbol to be bundled
|
|
746
821
|
*/
|
|
@@ -976,6 +1051,27 @@ export interface ListProgramFilesResponse extends BaseResponse {
|
|
|
976
1051
|
files?: string[];
|
|
977
1052
|
errors?: string[];
|
|
978
1053
|
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Response for reach_graph action
|
|
1056
|
+
*/
|
|
1057
|
+
export interface ReachGraphResponse extends BaseResponse {
|
|
1058
|
+
version?: 1;
|
|
1059
|
+
graph?: SerialGraph;
|
|
1060
|
+
errors?: string[];
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Response for reach action. `reached` is `'all'` for an installed file, a
|
|
1064
|
+
* file that is not source, or a `.json` file. `augmented` lists the changed
|
|
1065
|
+
* files that hold a script, global declaration or module augmentation, or read
|
|
1066
|
+
* a changed name of one: the caller widens each to every file of the programs
|
|
1067
|
+
* that hold it.
|
|
1068
|
+
*/
|
|
1069
|
+
export interface ReachResponse extends BaseResponse {
|
|
1070
|
+
reached?: string[] | 'all';
|
|
1071
|
+
augmented?: string[];
|
|
1072
|
+
exports_moved?: boolean;
|
|
1073
|
+
errors?: string[];
|
|
1074
|
+
}
|
|
979
1075
|
/**
|
|
980
1076
|
* Response for add_program_files action
|
|
981
1077
|
*/
|
|
@@ -1014,6 +1110,8 @@ export interface RetypeOutcome {
|
|
|
1014
1110
|
outcome: 'mismatch' | 'agrees' | 'wider' | 'abstain';
|
|
1015
1111
|
diagnostics: RetypeDiagnostic[];
|
|
1016
1112
|
reason?: string;
|
|
1113
|
+
/** Abstained because of how the run went (out of time, a judge that threw), not because of the call: the next run judges it again (carrick#3104). */
|
|
1114
|
+
run_failed?: boolean;
|
|
1017
1115
|
}
|
|
1018
1116
|
export interface RetypeCheckResponse extends BaseResponse {
|
|
1019
1117
|
outcomes?: RetypeOutcome[];
|
|
@@ -1272,7 +1370,7 @@ export interface ListLibrarySurfaceResponse extends BaseResponse {
|
|
|
1272
1370
|
/**
|
|
1273
1371
|
* Union type for all possible sidecar responses
|
|
1274
1372
|
*/
|
|
1275
|
-
export type SidecarResponse = RetypeCheckResponse | VerifyClientSemanticsResponse | VerifyLibraryClaimsResponse | ListLibrarySurfaceResponse | InitResponse | BundleResponse | CaptureV2Response | CheckV2Response | InferResponse | ResolveDefinitionsResponse | HealthResponse | ShutdownResponse | ListProgramFilesResponse | AddProgramFilesResponse | PositionRowsResponse | ImplementationsResponse | ErrorResponse;
|
|
1373
|
+
export type SidecarResponse = RetypeCheckResponse | RetypePrescreenResponse | VerifyClientSemanticsResponse | VerifyLibraryClaimsResponse | ListLibrarySurfaceResponse | InitResponse | BundleResponse | CaptureV2Response | CheckV2Response | InferResponse | ResolveDefinitionsResponse | HealthResponse | ShutdownResponse | ListProgramFilesResponse | ReachGraphResponse | ReachResponse | AddProgramFilesResponse | PositionRowsResponse | ImplementationsResponse | ErrorResponse;
|
|
1276
1374
|
/**
|
|
1277
1375
|
* An entry in the type manifest
|
|
1278
1376
|
*/
|