carrick 0.3.145 → 0.3.147
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/bin/carrick.mjs +4 -4
- package/dist/cli.d.ts +8 -1
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +31 -0
- package/dist/contract.js +29 -3
- package/dist/contract.js.map +1 -1
- package/dist/diagnostics.js +1 -9
- package/dist/diagnostics.js.map +1 -1
- package/dist/fs-util.d.ts +6 -0
- package/dist/fs-util.js +29 -0
- package/dist/fs-util.js.map +1 -0
- package/dist/global-install.js +1 -8
- package/dist/global-install.js.map +1 -1
- package/dist/hook/apply-patch.js +3 -4
- package/dist/hook/apply-patch.js.map +1 -1
- package/dist/hook/checked.d.ts +3 -1
- package/dist/hook/checked.js +9 -2
- package/dist/hook/checked.js.map +1 -1
- package/dist/hook/late.js +9 -2
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/post-edit.js +33 -24
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +1 -6
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/rechecks.d.ts +45 -1
- package/dist/hook/rechecks.js +116 -10
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/reuse.d.ts +31 -58
- package/dist/hook/reuse.js +48 -112
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-start.d.ts +9 -0
- package/dist/hook/session-start.js +43 -16
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stdin.d.ts +2 -0
- package/dist/hook/stdin.js +8 -0
- package/dist/hook/stdin.js.map +1 -0
- package/dist/hook/stop-wait.d.ts +24 -1
- package/dist/hook/stop-wait.js +163 -28
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/stop.js +17 -36
- package/dist/hook/stop.js.map +1 -1
- package/dist/hook/user-prompt.js +13 -30
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hosted-snapshot.d.ts +37 -0
- package/dist/hosted-snapshot.js +49 -0
- package/dist/hosted-snapshot.js.map +1 -0
- package/dist/init/agents-section.d.ts +16 -2
- package/dist/init/agents-section.js +43 -7
- package/dist/init/agents-section.js.map +1 -1
- package/dist/init/codex.js +8 -7
- package/dist/init/codex.js.map +1 -1
- package/dist/init/mcp.js +1 -3
- package/dist/init/mcp.js.map +1 -1
- package/dist/init/remove.d.ts +2 -0
- package/dist/init/remove.js +18 -4
- package/dist/init/remove.js.map +1 -1
- package/dist/init/repo-copies.js +2 -10
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/repos.d.ts +0 -2
- package/dist/init/repos.js +1 -9
- package/dist/init/repos.js.map +1 -1
- package/dist/init/run.js +14 -4
- package/dist/init/run.js.map +1 -1
- package/dist/init/self-update.d.ts +2 -2
- package/dist/init/self-update.js +89 -3
- package/dist/init/self-update.js.map +1 -1
- package/dist/init/settings.js +5 -7
- package/dist/init/settings.js.map +1 -1
- package/dist/native.js +1 -9
- package/dist/native.js.map +1 -1
- package/dist/render.d.ts +54 -11
- package/dist/render.js +188 -34
- package/dist/render.js.map +1 -1
- package/dist/root.d.ts +1 -2
- package/dist/root.js +1 -9
- package/dist/root.js.map +1 -1
- package/dist/surfaces.js +1 -3
- package/dist/surfaces.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/bundler.js +30 -28
- package/sidecar/dist/src/capture/service-config.d.ts +6 -0
- package/sidecar/dist/src/capture/service-config.js +11 -1
- package/sidecar/dist/src/library-claims.js +14 -0
- package/sidecar/dist/src/platform-body-read.d.ts +46 -0
- package/sidecar/dist/src/platform-body-read.js +82 -0
- package/sidecar/dist/src/response-modes.d.ts +5 -4
- package/sidecar/dist/src/response-modes.js +21 -25
- package/sidecar/dist/src/retype.js +11 -16
- package/sidecar/dist/src/stated-params.d.ts +6 -0
- package/sidecar/dist/src/stated-params.js +13 -0
- package/sidecar/dist/src/type-inferrer.d.ts +47 -14
- package/sidecar/dist/src/type-inferrer.js +119 -62
- package/sidecar/dist/src/types.d.ts +20 -3
- package/templates/skills/carrick-census.md +24 -3
- package/templates/skills/carrick-drift.md +11 -3
- package/templates/skills/carrick-impact.md +8 -3
- package/dist/hook/edited.d.ts +0 -22
- package/dist/hook/edited.js +0 -84
- package/dist/hook/edited.js.map +0 -1
|
@@ -168,6 +168,20 @@ export declare class TypeInferrer {
|
|
|
168
168
|
* read holds `any` or `unknown` somewhere.
|
|
169
169
|
*/
|
|
170
170
|
private relateModelSymbol;
|
|
171
|
+
/**
|
|
172
|
+
* Blueprint row N27 (i) (carrick#3334): a consumer call whose result is
|
|
173
|
+
* untyped (`client.post(url, event)` on an untyped client) states nothing
|
|
174
|
+
* the model's symbol could be compared with, and the model sometimes names
|
|
175
|
+
* the type of what the call SENDS. Where the symbol is the type of one of
|
|
176
|
+
* the call's arguments, or that argument's element, the answer is
|
|
177
|
+
* `different`: the symbol names the request, not the result, and the
|
|
178
|
+
* driver drops it so the inference defines the alias.
|
|
179
|
+
*
|
|
180
|
+
* Nothing is recorded where the result (`read`, the type the published
|
|
181
|
+
* text prints) is typed: a consumer's read can be a later expression of
|
|
182
|
+
* the caller's, so a typed result is not related here.
|
|
183
|
+
*/
|
|
184
|
+
private relateModelSymbolToArguments;
|
|
171
185
|
/**
|
|
172
186
|
* `func` is the function the row's line names: it opens on that line (a
|
|
173
187
|
* method under its decorators, an exported handler), or it is the handler
|
|
@@ -357,10 +371,11 @@ export declare class TypeInferrer {
|
|
|
357
371
|
* call nothing resolves (its library is not installed), the return walk
|
|
358
372
|
* reads no argument the source does not annotate, because it cannot tell a
|
|
359
373
|
* response sender from a query. A located payload that is an ARGUMENT of
|
|
360
|
-
* such a returned call
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
374
|
+
* such a returned call is the model's word that it is a sender, and that is
|
|
375
|
+
* a lead, never an enforced type (blueprint row N34): the walk's honest
|
|
376
|
+
* `any` stands, and its `no_payload_evidence` provenance quotes the
|
|
377
|
+
* argument's reading. A send the service's labels name is read by the walk
|
|
378
|
+
* itself (`returnsLabelledSend`), so it never reaches this case.
|
|
364
379
|
*
|
|
365
380
|
* Returns `undefined` when the located expression is something the return
|
|
366
381
|
* walk never looked at, so it is left to the readings below:
|
|
@@ -552,8 +567,22 @@ export declare class TypeInferrer {
|
|
|
552
567
|
* the call hands the response to (`fetch(u).then((res) => res.text())`).
|
|
553
568
|
*/
|
|
554
569
|
private textReadAtTerminal;
|
|
555
|
-
/**
|
|
570
|
+
/**
|
|
571
|
+
* `call` is the platform's `<receiver>.text()` (blueprint row N33), and
|
|
572
|
+
* `accept` takes its receiver.
|
|
573
|
+
*/
|
|
556
574
|
private isTextReadOf;
|
|
575
|
+
/**
|
|
576
|
+
* Whether a declaring file is the runtime's, as `isExternalOrigin` answers
|
|
577
|
+
* it: the default library, an installed package, or Carrick's materialised
|
|
578
|
+
* runtime declarations.
|
|
579
|
+
*/
|
|
580
|
+
private readonly runtimeFile;
|
|
581
|
+
/**
|
|
582
|
+
* `call` is one of the platform's whole-body reads (blueprint row N33).
|
|
583
|
+
* `undeclared` says whether a read on a receiver nothing declares counts.
|
|
584
|
+
*/
|
|
585
|
+
isPlatformBodyRead(call: CallExpression, reads: ReadonlySet<string>, undeclared: 'undeclared_reads' | 'platform_only'): boolean;
|
|
557
586
|
/**
|
|
558
587
|
* The call's resolved signature, at this site, types a member of an object
|
|
559
588
|
* argument as exactly the literal `'text'`, and the source passes that
|
|
@@ -601,6 +630,15 @@ export declare class TypeInferrer {
|
|
|
601
630
|
* reference, whose name is the root, or anything else, which has none.
|
|
602
631
|
*/
|
|
603
632
|
private statedRoot;
|
|
633
|
+
/**
|
|
634
|
+
* Blueprint row N30 (carrick#3336): how the root's declared type (what
|
|
635
|
+
* bundling the root alone publishes) relates to the type the source states
|
|
636
|
+
* (`as readonly User[]` against `User`: a list, 1 deep). The compiler
|
|
637
|
+
* decides; the printed text is never compared. A generic root's declared
|
|
638
|
+
* type keeps its parameters, so `Page<User>` relates to `Page` as
|
|
639
|
+
* `different`. Absent where nothing could be compared.
|
|
640
|
+
*/
|
|
641
|
+
private statedRootRelation;
|
|
604
642
|
private inferVariable;
|
|
605
643
|
private inferExpression;
|
|
606
644
|
private inferRequestBody;
|
|
@@ -1009,8 +1047,9 @@ export declare class TypeInferrer {
|
|
|
1009
1047
|
*/
|
|
1010
1048
|
private bodyReadOnCallValue;
|
|
1011
1049
|
/**
|
|
1012
|
-
* The zero-argument whole-body read that takes `receiver` as its
|
|
1013
|
-
* `res.json()` or `res.text()`, or `undefined
|
|
1050
|
+
* The platform's zero-argument whole-body read that takes `receiver` as its
|
|
1051
|
+
* receiver, `res.json()` or `res.text()`, or `undefined` (blueprint row N33:
|
|
1052
|
+
* the receiver's declaration decides, not the name). A text read is a body read
|
|
1014
1053
|
* like a json one (carrick#1842): without it, `return res.text()` left the
|
|
1015
1054
|
* walk on the response binding and published the transport object. `reads`
|
|
1016
1055
|
* names the reads asked for.
|
|
@@ -1529,11 +1568,6 @@ export declare class TypeInferrer {
|
|
|
1529
1568
|
* bare object literal does.
|
|
1530
1569
|
*/
|
|
1531
1570
|
private responseReturnedExpressions;
|
|
1532
|
-
/**
|
|
1533
|
-
* Stable identity for a call's callee within one file: its resolved symbol
|
|
1534
|
-
* when the compiler has one, else the callee's source text.
|
|
1535
|
-
*/
|
|
1536
|
-
private calleeIdentity;
|
|
1537
1571
|
/**
|
|
1538
1572
|
* The payload argument of a returned response-helper call, or `undefined`.
|
|
1539
1573
|
*
|
|
@@ -1547,8 +1581,7 @@ export declare class TypeInferrer {
|
|
|
1547
1581
|
* shape it returns when it succeeds.
|
|
1548
1582
|
*
|
|
1549
1583
|
* `statedOnly` narrows what counts as a payload to an argument the source
|
|
1550
|
-
* annotates; see `recoverPayloadFromReturnStatements`.
|
|
1551
|
-
* callee a caller has its own evidence for (`serialisers`).
|
|
1584
|
+
* annotates; see `recoverPayloadFromReturnStatements`.
|
|
1552
1585
|
*/
|
|
1553
1586
|
private responseHelperPayloadNode;
|
|
1554
1587
|
/**
|
|
@@ -25,6 +25,7 @@ import { declarationSite } from './bundler.js';
|
|
|
25
25
|
import { printedTypeHoldsTopType, relateSymbolToRead } from './symbol-relation.js';
|
|
26
26
|
import { notePrintedType, PrintedTypes } from './printed-names.js';
|
|
27
27
|
import { externalImportsOf, isExternalOrigin } from './origin.js';
|
|
28
|
+
import { BINARY_BODY_READS, isPlatformBodyRead, JSON_READ, RAW_TEXT_FORMAT, WHOLE_BODY_READS, } from './platform-body-read.js';
|
|
28
29
|
import { reachedOnlyOnFailure } from './failure-path.js';
|
|
29
30
|
import { readResponseModes } from './response-modes.js';
|
|
30
31
|
import { callInto, calledFunction, narrowByArguments } from './argument-modes.js';
|
|
@@ -183,6 +184,10 @@ const RESPONSE_INIT_MEMBER_NAMES = new Set([
|
|
|
183
184
|
* two; the bound is a backstop against a pathologically nested return.
|
|
184
185
|
*/
|
|
185
186
|
const RESPONSE_HELPER_MAX_DEPTH = 4;
|
|
187
|
+
/** Longest lead type text a provenance detail quotes (blueprint row N34). */
|
|
188
|
+
const LEAD_TEXT_MAX = 200;
|
|
189
|
+
/** The platform's raw-text read alone (carrick#1842). */
|
|
190
|
+
const TEXT_READ = new Set([RAW_TEXT_FORMAT]);
|
|
186
191
|
/**
|
|
187
192
|
* How many wrapper calls a handler bound to one is followed through
|
|
188
193
|
* (carrick#2472 P3-2b): `wrap(trace(async (req, res) => …))` needs two. A
|
|
@@ -281,20 +286,6 @@ const REQUEST_BODY_PARTS = new Set(['json', 'form', 'body']);
|
|
|
281
286
|
* these names; a type parameter alone also types response modes and fallbacks.
|
|
282
287
|
*/
|
|
283
288
|
const BODY_MEMBER_NAMES = new Set(['data', 'body', 'json']);
|
|
284
|
-
/**
|
|
285
|
-
* The zero-argument reads that take the WHOLE body out of a transport response
|
|
286
|
-
* (the platform `Response` and the clients that copy its shape): parsed as
|
|
287
|
-
* JSON, or as raw text (carrick#1842).
|
|
288
|
-
*/
|
|
289
|
-
const WHOLE_BODY_READS = new Set(['json', 'text']);
|
|
290
|
-
/**
|
|
291
|
-
* The other zero-argument reads the platform `Response` takes its whole body
|
|
292
|
-
* out with, in a form that is neither JSON nor text. The expression that
|
|
293
|
-
* holds one holds the body the call answered with (carrick#2112).
|
|
294
|
-
*/
|
|
295
|
-
const BINARY_BODY_READS = new Set(['arrayBuffer', 'blob', 'bytes', 'formData']);
|
|
296
|
-
/** The body format a caller names to read a response as raw text (carrick#1842). */
|
|
297
|
-
const RAW_TEXT_FORMAT = 'text';
|
|
298
289
|
/**
|
|
299
290
|
* Print a `Type` to its string form WITHOUT the compiler's default truncation.
|
|
300
291
|
*
|
|
@@ -702,6 +693,44 @@ export class TypeInferrer {
|
|
|
702
693
|
this.logError(`Model symbol relation failed for ${inferred.alias}: ${err instanceof Error ? err.message : String(err)}`);
|
|
703
694
|
}
|
|
704
695
|
}
|
|
696
|
+
/**
|
|
697
|
+
* Blueprint row N27 (i) (carrick#3334): a consumer call whose result is
|
|
698
|
+
* untyped (`client.post(url, event)` on an untyped client) states nothing
|
|
699
|
+
* the model's symbol could be compared with, and the model sometimes names
|
|
700
|
+
* the type of what the call SENDS. Where the symbol is the type of one of
|
|
701
|
+
* the call's arguments, or that argument's element, the answer is
|
|
702
|
+
* `different`: the symbol names the request, not the result, and the
|
|
703
|
+
* driver drops it so the inference defines the alias.
|
|
704
|
+
*
|
|
705
|
+
* Nothing is recorded where the result (`read`, the type the published
|
|
706
|
+
* text prints) is typed: a consumer's read can be a later expression of
|
|
707
|
+
* the caller's, so a typed result is not related here.
|
|
708
|
+
*/
|
|
709
|
+
relateModelSymbolToArguments(request, inferred, callExpr, read) {
|
|
710
|
+
if (request.infer_kind !== 'call_result' || !read)
|
|
711
|
+
return;
|
|
712
|
+
const named = this.modelSymbols.get(inferred.alias);
|
|
713
|
+
if (!named)
|
|
714
|
+
return;
|
|
715
|
+
const result = this.unwrapPromiseType(read);
|
|
716
|
+
if (!result.isAny() && !result.isUnknown())
|
|
717
|
+
return;
|
|
718
|
+
try {
|
|
719
|
+
const symbolType = this.modelSymbolType(named);
|
|
720
|
+
if (!symbolType)
|
|
721
|
+
return;
|
|
722
|
+
const checker = this.project.getTypeChecker().compilerObject;
|
|
723
|
+
const sent = callExpr.getArguments().some((argument) => {
|
|
724
|
+
const answer = relateSymbolToRead(checker, symbolType.compilerType, [argument.getType().compilerType]);
|
|
725
|
+
return answer?.relation === 'same' || answer?.relation === 'list';
|
|
726
|
+
});
|
|
727
|
+
if (sent)
|
|
728
|
+
inferred.model_symbol_relation = { relation: 'different' };
|
|
729
|
+
}
|
|
730
|
+
catch (err) {
|
|
731
|
+
this.logError(`Model symbol relation failed for ${inferred.alias}: ${err instanceof Error ? err.message : String(err)}`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
705
734
|
/**
|
|
706
735
|
* `func` is the function the row's line names: it opens on that line (a
|
|
707
736
|
* method under its decorators, an exported handler), or it is the handler
|
|
@@ -1760,10 +1789,11 @@ export class TypeInferrer {
|
|
|
1760
1789
|
* call nothing resolves (its library is not installed), the return walk
|
|
1761
1790
|
* reads no argument the source does not annotate, because it cannot tell a
|
|
1762
1791
|
* response sender from a query. A located payload that is an ARGUMENT of
|
|
1763
|
-
* such a returned call
|
|
1764
|
-
*
|
|
1765
|
-
*
|
|
1766
|
-
*
|
|
1792
|
+
* such a returned call is the model's word that it is a sender, and that is
|
|
1793
|
+
* a lead, never an enforced type (blueprint row N34): the walk's honest
|
|
1794
|
+
* `any` stands, and its `no_payload_evidence` provenance quotes the
|
|
1795
|
+
* argument's reading. A send the service's labels name is read by the walk
|
|
1796
|
+
* itself (`returnsLabelledSend`), so it never reaches this case.
|
|
1767
1797
|
*
|
|
1768
1798
|
* Returns `undefined` when the located expression is something the return
|
|
1769
1799
|
* walk never looked at, so it is left to the readings below:
|
|
@@ -1809,16 +1839,24 @@ export class TypeInferrer {
|
|
|
1809
1839
|
if (!unresolvedCallee) {
|
|
1810
1840
|
return walked;
|
|
1811
1841
|
}
|
|
1842
|
+
// Blueprint row N34: the callee resolves to nothing, so only the model's
|
|
1843
|
+
// locator says the returned call is a response sender. That is a lead,
|
|
1844
|
+
// never a type the check enforces: the row keeps its honest `any`, and the
|
|
1845
|
+
// located argument's reading rides in the provenance for a reader.
|
|
1812
1846
|
const sender = this.returnedSendHolding(returned, located);
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1847
|
+
if (sender) {
|
|
1848
|
+
// The printed type names a module the use site does not import by its
|
|
1849
|
+
// declaring file, `import("/abs/path").Name`, and this text reaches a
|
|
1850
|
+
// reader: keep the bare name, before truncation can split the path.
|
|
1851
|
+
const lead = this.payloadCandidateOf(this.peelTransparentExpression(located), this.wireFormatFor(request)).typeString.replace(/import\("[^"]*"\)\./g, '');
|
|
1852
|
+
const shown = lead.length > LEAD_TEXT_MAX ? `${lead.slice(0, LEAD_TEXT_MAX)}…` : lead;
|
|
1853
|
+
walked.any_provenance = (walked.any_provenance ?? []).map((entry) => entry.reason === 'no_payload_evidence'
|
|
1854
|
+
? {
|
|
1855
|
+
...entry,
|
|
1856
|
+
detail: 'the handler returns a call whose callee has no resolvable declaration; the model located ' +
|
|
1857
|
+
`its argument as the body, which reads as \`${shown}\`, a lead the check does not enforce`,
|
|
1858
|
+
}
|
|
1859
|
+
: entry);
|
|
1822
1860
|
}
|
|
1823
1861
|
return walked;
|
|
1824
1862
|
}
|
|
@@ -2807,6 +2845,9 @@ export class TypeInferrer {
|
|
|
2807
2845
|
if (statedBody) {
|
|
2808
2846
|
inferred.stated_body = statedBody;
|
|
2809
2847
|
}
|
|
2848
|
+
else {
|
|
2849
|
+
this.relateModelSymbolToArguments(request, inferred, callExpr, printedType);
|
|
2850
|
+
}
|
|
2810
2851
|
// carrick#1842: `string` cannot tell a body read as raw text from a JSON
|
|
2811
2852
|
// body that is a string, and raw text states no structural contract. The
|
|
2812
2853
|
// row says which it is, so the check phase can read the pair unverifiable
|
|
@@ -2852,14 +2893,29 @@ export class TypeInferrer {
|
|
|
2852
2893
|
Node.isCallExpression(inner) &&
|
|
2853
2894
|
this.isTextReadOf(inner, (receiver) => Node.isIdentifier(receiver) && receiver.getSymbol() === param.getSymbol()));
|
|
2854
2895
|
}
|
|
2855
|
-
/**
|
|
2896
|
+
/**
|
|
2897
|
+
* `call` is the platform's `<receiver>.text()` (blueprint row N33), and
|
|
2898
|
+
* `accept` takes its receiver.
|
|
2899
|
+
*/
|
|
2856
2900
|
isTextReadOf(call, accept) {
|
|
2857
2901
|
const access = call.getExpression();
|
|
2858
2902
|
return (Node.isPropertyAccessExpression(access) &&
|
|
2859
|
-
|
|
2860
|
-
call.getArguments().length === 0 &&
|
|
2903
|
+
isPlatformBodyRead(call, TEXT_READ, this.runtimeFile, 'undeclared_reads') &&
|
|
2861
2904
|
accept(this.unwrapExpressionNode(access.getExpression())));
|
|
2862
2905
|
}
|
|
2906
|
+
/**
|
|
2907
|
+
* Whether a declaring file is the runtime's, as `isExternalOrigin` answers
|
|
2908
|
+
* it: the default library, an installed package, or Carrick's materialised
|
|
2909
|
+
* runtime declarations.
|
|
2910
|
+
*/
|
|
2911
|
+
runtimeFile = (file) => isExternalOrigin(this.project.getProgram().compilerObject, file, this.repoRoot, externalImportsOf(this.project));
|
|
2912
|
+
/**
|
|
2913
|
+
* `call` is one of the platform's whole-body reads (blueprint row N33).
|
|
2914
|
+
* `undeclared` says whether a read on a receiver nothing declares counts.
|
|
2915
|
+
*/
|
|
2916
|
+
isPlatformBodyRead(call, reads, undeclared) {
|
|
2917
|
+
return isPlatformBodyRead(call, reads, this.runtimeFile, undeclared);
|
|
2918
|
+
}
|
|
2863
2919
|
/**
|
|
2864
2920
|
* The call's resolved signature, at this site, types a member of an object
|
|
2865
2921
|
* argument as exactly the literal `'text'`, and the source passes that
|
|
@@ -3032,14 +3088,33 @@ export class TypeInferrer {
|
|
|
3032
3088
|
}
|
|
3033
3089
|
const source = symbol?.getDeclarations()[0]?.getSourceFile().getFilePath();
|
|
3034
3090
|
const typeArguments = node.getTypeArguments().length;
|
|
3091
|
+
const rootRelation = symbol ? this.statedRootRelation(symbol, typeNode) : undefined;
|
|
3035
3092
|
return {
|
|
3036
3093
|
root: nameNode.getText(),
|
|
3037
3094
|
...(source ? { root_source: source } : {}),
|
|
3038
3095
|
...depthField,
|
|
3039
3096
|
...(typeArguments > 0 ? { root_type_arguments: typeArguments } : {}),
|
|
3097
|
+
...(rootRelation ? { root_relation: rootRelation } : {}),
|
|
3040
3098
|
...(this.isFrameworkMachinery(node.getType()) ? { machinery: true } : {}),
|
|
3041
3099
|
};
|
|
3042
3100
|
}
|
|
3101
|
+
/**
|
|
3102
|
+
* Blueprint row N30 (carrick#3336): how the root's declared type (what
|
|
3103
|
+
* bundling the root alone publishes) relates to the type the source states
|
|
3104
|
+
* (`as readonly User[]` against `User`: a list, 1 deep). The compiler
|
|
3105
|
+
* decides; the printed text is never compared. A generic root's declared
|
|
3106
|
+
* type keeps its parameters, so `Page<User>` relates to `Page` as
|
|
3107
|
+
* `different`. Absent where nothing could be compared.
|
|
3108
|
+
*/
|
|
3109
|
+
statedRootRelation(symbol, typeNode) {
|
|
3110
|
+
try {
|
|
3111
|
+
return relateSymbolToRead(this.project.getTypeChecker().compilerObject, symbol.getDeclaredType().compilerType, [this.unwrapPromiseType(typeNode.getType()).compilerType]);
|
|
3112
|
+
}
|
|
3113
|
+
catch (err) {
|
|
3114
|
+
this.logError(`Stated root relation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
3115
|
+
return undefined;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3043
3118
|
inferVariable(sourceFile, request, extractionConfig) {
|
|
3044
3119
|
const node = this.resolveTargetNode(sourceFile, request);
|
|
3045
3120
|
if (!node) {
|
|
@@ -4791,8 +4866,9 @@ export class TypeInferrer {
|
|
|
4791
4866
|
return this.bodyReadOnReceiver(value);
|
|
4792
4867
|
}
|
|
4793
4868
|
/**
|
|
4794
|
-
* The zero-argument whole-body read that takes `receiver` as its
|
|
4795
|
-
* `res.json()` or `res.text()`, or `undefined
|
|
4869
|
+
* The platform's zero-argument whole-body read that takes `receiver` as its
|
|
4870
|
+
* receiver, `res.json()` or `res.text()`, or `undefined` (blueprint row N33:
|
|
4871
|
+
* the receiver's declaration decides, not the name). A text read is a body read
|
|
4796
4872
|
* like a json one (carrick#1842): without it, `return res.text()` left the
|
|
4797
4873
|
* walk on the response binding and published the transport object. `reads`
|
|
4798
4874
|
* names the reads asked for.
|
|
@@ -4809,7 +4885,7 @@ export class TypeInferrer {
|
|
|
4809
4885
|
if (!call ||
|
|
4810
4886
|
!Node.isCallExpression(call) ||
|
|
4811
4887
|
call.getExpression() !== access ||
|
|
4812
|
-
call.
|
|
4888
|
+
!isPlatformBodyRead(call, reads, this.runtimeFile, 'undeclared_reads')) {
|
|
4813
4889
|
return undefined;
|
|
4814
4890
|
}
|
|
4815
4891
|
return call;
|
|
@@ -5739,14 +5815,11 @@ export class TypeInferrer {
|
|
|
5739
5815
|
* stated status, and what survives is joined as a union exactly as several
|
|
5740
5816
|
* return statements are.
|
|
5741
5817
|
*/
|
|
5742
|
-
recoverPayloadFromResponseExpressions(expressions, statedOnly, wire
|
|
5818
|
+
recoverPayloadFromResponseExpressions(expressions, statedOnly, wire) {
|
|
5743
5819
|
const candidates = [];
|
|
5744
5820
|
const returned = expressions.flatMap((expression) => this.expandResponseBranches(expression, 0));
|
|
5745
|
-
// `alsoSerialisers` are callees a caller has its own evidence for
|
|
5746
|
-
// (`calleeIdentity` keys).
|
|
5747
|
-
const serialisers = new Set(alsoSerialisers ?? []);
|
|
5748
5821
|
for (const expression of returned) {
|
|
5749
|
-
const payloadNode = this.responseHelperPayloadNode(expression, 0, statedOnly
|
|
5822
|
+
const payloadNode = this.responseHelperPayloadNode(expression, 0, statedOnly);
|
|
5750
5823
|
if (!payloadNode)
|
|
5751
5824
|
continue;
|
|
5752
5825
|
candidates.push(this.payloadCandidateOf(payloadNode, wire));
|
|
@@ -6388,7 +6461,10 @@ export class TypeInferrer {
|
|
|
6388
6461
|
*/
|
|
6389
6462
|
responseModesOf(bodies) {
|
|
6390
6463
|
try {
|
|
6391
|
-
return readResponseModes(bodies, (texts) => distinctByText(texts, (text) => text).join(' | '),
|
|
6464
|
+
return readResponseModes(bodies, (texts) => distinctByText(texts, (text) => text).join(' | '),
|
|
6465
|
+
// On main a receiver nothing declares was never read here, so it is not now.
|
|
6466
|
+
(call) => this.isPlatformBodyRead(call, JSON_READ, 'platform_only') ||
|
|
6467
|
+
this.statedParams.readsLabelledBody(call));
|
|
6392
6468
|
}
|
|
6393
6469
|
catch (error) {
|
|
6394
6470
|
this.log(`Response modes not read: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -6453,21 +6529,6 @@ export class TypeInferrer {
|
|
|
6453
6529
|
}
|
|
6454
6530
|
return flattened;
|
|
6455
6531
|
}
|
|
6456
|
-
/**
|
|
6457
|
-
* Stable identity for a call's callee within one file: its resolved symbol
|
|
6458
|
-
* when the compiler has one, else the callee's source text.
|
|
6459
|
-
*/
|
|
6460
|
-
calleeIdentity(call) {
|
|
6461
|
-
if (!Node.isCallExpression(call) && !Node.isNewExpression(call)) {
|
|
6462
|
-
return undefined;
|
|
6463
|
-
}
|
|
6464
|
-
const callee = call.getExpression();
|
|
6465
|
-
const symbol = callee.getSymbol();
|
|
6466
|
-
if (symbol)
|
|
6467
|
-
return `symbol:${symbol.getFullyQualifiedName()}`;
|
|
6468
|
-
const text = callee.getText().trim();
|
|
6469
|
-
return text.length > 0 ? `text:${text}` : undefined;
|
|
6470
|
-
}
|
|
6471
6532
|
/**
|
|
6472
6533
|
* The payload argument of a returned response-helper call, or `undefined`.
|
|
6473
6534
|
*
|
|
@@ -6481,10 +6542,9 @@ export class TypeInferrer {
|
|
|
6481
6542
|
* shape it returns when it succeeds.
|
|
6482
6543
|
*
|
|
6483
6544
|
* `statedOnly` narrows what counts as a payload to an argument the source
|
|
6484
|
-
* annotates; see `recoverPayloadFromReturnStatements`.
|
|
6485
|
-
* callee a caller has its own evidence for (`serialisers`).
|
|
6545
|
+
* annotates; see `recoverPayloadFromReturnStatements`.
|
|
6486
6546
|
*/
|
|
6487
|
-
responseHelperPayloadNode(expression, depth, statedOnly
|
|
6547
|
+
responseHelperPayloadNode(expression, depth, statedOnly) {
|
|
6488
6548
|
if (depth > RESPONSE_HELPER_MAX_DEPTH)
|
|
6489
6549
|
return undefined;
|
|
6490
6550
|
const call = this.peelTransparentExpression(expression);
|
|
@@ -6512,9 +6572,6 @@ export class TypeInferrer {
|
|
|
6512
6572
|
const slotted = this.unwrapJsonStringifyArg(body);
|
|
6513
6573
|
return this.nodeCarriesPayloadContract(slotted, false) ? slotted : undefined;
|
|
6514
6574
|
}
|
|
6515
|
-
const identity = this.calleeIdentity(call);
|
|
6516
|
-
const proven = identity !== undefined && serialisers.has(identity);
|
|
6517
|
-
const effectiveStatedOnly = statedOnly && !proven;
|
|
6518
6575
|
for (const [index, arg] of args.entries()) {
|
|
6519
6576
|
// An options object BESIDE the body states how to send it, never what is
|
|
6520
6577
|
// sent (carrick#1017): `new Response(null, { status: 204 })` has no body
|
|
@@ -6524,10 +6581,10 @@ export class TypeInferrer {
|
|
|
6524
6581
|
if (index > 0 && this.statesResponseInit(arg))
|
|
6525
6582
|
continue;
|
|
6526
6583
|
const candidate = this.unwrapJsonStringifyArg(arg);
|
|
6527
|
-
if (this.nodeCarriesPayloadContract(candidate,
|
|
6584
|
+
if (this.nodeCarriesPayloadContract(candidate, statedOnly)) {
|
|
6528
6585
|
return candidate;
|
|
6529
6586
|
}
|
|
6530
|
-
const nested = this.responseHelperPayloadNode(candidate, depth + 1, statedOnly
|
|
6587
|
+
const nested = this.responseHelperPayloadNode(candidate, depth + 1, statedOnly);
|
|
6531
6588
|
if (nested)
|
|
6532
6589
|
return nested;
|
|
6533
6590
|
}
|
|
@@ -1536,9 +1536,11 @@ export interface InferredType {
|
|
|
1536
1536
|
*/
|
|
1537
1537
|
stated_body?: StatedBody;
|
|
1538
1538
|
/**
|
|
1539
|
-
* carrick#2111, a producer's response read
|
|
1540
|
-
*
|
|
1541
|
-
*
|
|
1539
|
+
* carrick#2111, a producer's response read: how the type the model named
|
|
1540
|
+
* for this row relates to the type read here. Absent where the model named
|
|
1541
|
+
* none, or nothing could be compared. Blueprint row N27 (i), a consumer's
|
|
1542
|
+
* `call_result`: only ever `different`, where the call's result is untyped
|
|
1543
|
+
* and the symbol is the type of an argument the call sends.
|
|
1542
1544
|
*/
|
|
1543
1545
|
model_symbol_relation?: ModelSymbolRelation;
|
|
1544
1546
|
/**
|
|
@@ -1605,6 +1607,13 @@ export interface StatedBody {
|
|
|
1605
1607
|
* declared, as `InferredType.machinery`. Absent otherwise.
|
|
1606
1608
|
*/
|
|
1607
1609
|
machinery?: true;
|
|
1610
|
+
/**
|
|
1611
|
+
* Blueprint row N30: how `root`'s declared type, the type bundling `root`
|
|
1612
|
+
* alone publishes, relates to the stated type (`readonly User[]` against
|
|
1613
|
+
* `User`: `list`, depth 1). The compiler decides; the scanner re-aims at
|
|
1614
|
+
* `root` only on `same` or `list`. Absent where nothing could be compared.
|
|
1615
|
+
*/
|
|
1616
|
+
root_relation?: ModelSymbolRelation;
|
|
1608
1617
|
}
|
|
1609
1618
|
/**
|
|
1610
1619
|
* Why a type carries `any`/`unknown` at a position, and where.
|
|
@@ -1643,7 +1652,15 @@ export interface SymbolFailure {
|
|
|
1643
1652
|
source_file: string;
|
|
1644
1653
|
/** Reason for the failure */
|
|
1645
1654
|
reason: string;
|
|
1655
|
+
/** What kind of failure, where the bundler states one (read by the scanner) */
|
|
1656
|
+
kind?: SymbolFailureKind;
|
|
1646
1657
|
}
|
|
1658
|
+
/**
|
|
1659
|
+
* `not_a_type`: the symbol is declared as a value (a variable or a function),
|
|
1660
|
+
* not as a type, so it never defines the alias it was asked for (blueprint
|
|
1661
|
+
* row N10c).
|
|
1662
|
+
*/
|
|
1663
|
+
export type SymbolFailureKind = 'not_a_type';
|
|
1647
1664
|
/**
|
|
1648
1665
|
* Internal result from the bundler
|
|
1649
1666
|
*/
|
|
@@ -77,16 +77,37 @@ that do the thing, and drop the rest with one line each saying what they turned
|
|
|
77
77
|
out to be. `role` on a row says what the scan joined it to, such as a route
|
|
78
78
|
handler or a client, and a route handler for a different operation is not a hit.
|
|
79
79
|
|
|
80
|
-
## 5.
|
|
80
|
+
## 5. Follow helpers to callers
|
|
81
|
+
|
|
82
|
+
The rows from step 4 are often the mechanism: a helper that others call to do
|
|
83
|
+
the thing. The places that do X are then its callers. For each kept row that is
|
|
84
|
+
a helper, run:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
get_callers({{SCOPE}}, function_name: "<helper>", file: "<file>", depth: 1)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
or grep for the helper's name where the index returns nothing. A function passed
|
|
91
|
+
as a value is not counted, so grep before you treat zero callers as none. Report
|
|
92
|
+
the callers as the places that do X, each with `call_site_line` where the row
|
|
93
|
+
carries it, and list the helper itself apart as the mechanism.
|
|
94
|
+
|
|
95
|
+
Where the question names an identifier, such as an environment variable, a
|
|
96
|
+
table or a header, grep the source for that identifier as well and merge the two
|
|
97
|
+
lists on file and line. A match inside a config file, a template or generated
|
|
98
|
+
output reaches you only this way. Mark each row with how it was found: index,
|
|
99
|
+
callers, grep.
|
|
100
|
+
|
|
101
|
+
## 6. Report
|
|
81
102
|
|
|
82
103
|
| file:line | function | what it does | found by |
|
|
83
104
|
|---|---|---|---|
|
|
84
105
|
| src/billing/charge.ts:88 | chargeCard | reads the billing key | purpose, mechanism |
|
|
85
106
|
|
|
86
|
-
Close with the receipt from step 3, so the list is read against what was
|
|
107
|
+
Close with the receipt from step 3, and the helpers followed in step 5, so the list is read against what was
|
|
87
108
|
searched.
|
|
88
109
|
|
|
89
|
-
##
|
|
110
|
+
## 7. Act
|
|
90
111
|
|
|
91
112
|
Change nothing unless you were asked to. Offer one issue per finding that needs
|
|
92
113
|
work, and file the ones accepted:
|
|
@@ -37,8 +37,11 @@ Operations are ranked by call-site count then by untyped sides. Page with
|
|
|
37
37
|
A verdict's `state` is `compatible`, `incompatible` or `unresolved`, and it
|
|
38
38
|
carries `scanner_version` with `mismatch_reason` or `unresolved_reason` where
|
|
39
39
|
the scan wrote one. One verdict covers the whole consumer and producer pair, so
|
|
40
|
-
every call site on that operation shares it.
|
|
41
|
-
|
|
40
|
+
every call site on that operation shares it. Each entry of `consumer.call_sites`
|
|
41
|
+
may also carry its own `verdict` with `scope: "call_site"` and a `state`, and
|
|
42
|
+
the top-level `verdicts` can be `[]` while the call sites hold them. An
|
|
43
|
+
operation is never judged only where `verdicts` is empty and no call site
|
|
44
|
+
carries a `verdict`; `verdict_note` says so.
|
|
42
45
|
|
|
43
46
|
Honour the wire note. Where `wire_notes` is present, one side declares a field
|
|
44
47
|
as `Date` and the other as `string`. JSON serialises a Date to a string, so
|
|
@@ -46,6 +49,11 @@ those two texts can describe the same bytes, and that is not drift.
|
|
|
46
49
|
|
|
47
50
|
## 3. Class each operation
|
|
48
51
|
|
|
52
|
+
Read the stored verdict from the top-level `verdicts`, and where that is empty
|
|
53
|
+
from the `verdict.state` on each call site. Class the operation on the worst
|
|
54
|
+
state across its call sites (incompatible, then unresolved, then compatible),
|
|
55
|
+
and give each call site its own state in the report.
|
|
56
|
+
|
|
49
57
|
- **MATCH**: the stored verdict is `compatible`.
|
|
50
58
|
- **DRIFT**: the stored verdict is `incompatible`. Name the field and the
|
|
51
59
|
direction, request or response, from `mismatch_reason` and the two type texts.
|
|
@@ -55,7 +63,7 @@ those two texts can describe the same bytes, and that is not drift.
|
|
|
55
63
|
they differ name the field and say whether it is missing on one side, optional
|
|
56
64
|
on one side and required on the other, or of a different type. Report that as
|
|
57
65
|
"type texts differ", never as a verdict.
|
|
58
|
-
- **NOT JUDGED**: `verdicts` is empty
|
|
66
|
+
- **NOT JUDGED**: `verdicts` is empty and no call site carries a `verdict`. Relay `verdict_note`, then read the same
|
|
59
67
|
two type texts the same way and report any difference as "type texts differ".
|
|
60
68
|
- **CONSUMER UNTYPED**: a call site's `expected_request` or `expected_response`
|
|
61
69
|
is null on a side that carries one.
|
|
@@ -45,9 +45,14 @@ For a function:
|
|
|
45
45
|
get_callers({{SCOPE}}, function_name: "<name>", file: "<file>", depth: 1)
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
Each row names the enclosing caller and its line span,
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
Each row names the enclosing caller and its line span, and carries
|
|
49
|
+
`call_site_line`, the line the call is written on, where the scan recorded one.
|
|
50
|
+
Raise `depth` to 2 or 3 for transitive callers. When `get_callers` returns 0
|
|
51
|
+
rows, grep the function's name across the workspace before you conclude anything:
|
|
52
|
+
a function passed as a value, such as a callback or a handler table entry, is
|
|
53
|
+
not counted. Zero recorded callers with no grep match is the only reading that
|
|
54
|
+
supports "nothing calls this", and a function outside the index is still not
|
|
55
|
+
covered.
|
|
51
56
|
|
|
52
57
|
## 3. Verdicts, one consumer at a time
|
|
53
58
|
|
package/dist/hook/edited.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { CheckResult } from "../contract.ts";
|
|
2
|
-
import type { NewFunction } from "./reuse.ts";
|
|
3
|
-
/** Whether `carrick check --changed` would judge this edited file: source, and not a test or story. */
|
|
4
|
-
export declare function isCheckedSource(file: string): boolean;
|
|
5
|
-
/**
|
|
6
|
-
* What the re-check said this file declares and the index does not
|
|
7
|
-
* (carrick#1330).
|
|
8
|
-
*
|
|
9
|
-
* Nothing is printed about it here. This hook fires on every edit and most
|
|
10
|
-
* edits add no function; the one line about the ones that did belongs at the
|
|
11
|
-
* end of the task, where it costs one model turn instead of one per edit. All
|
|
12
|
-
* this does is put the names somewhere the Stop hook can find them.
|
|
13
|
-
*/
|
|
14
|
-
export declare function newFunctions(result: CheckResult, file: string): NewFunction[];
|
|
15
|
-
/**
|
|
16
|
-
* `file` relative to the nearest checkout top at or below `root`: the nearest
|
|
17
|
-
* directory holding `.git` (a folder, or the file a linked worktree has). An
|
|
18
|
-
* edit inside a nested worktree is then keyed as the index keys it, not with
|
|
19
|
-
* the worktree's own prefix (carrick#2936). With no nested checkout it is
|
|
20
|
-
* relative to `root`, as before.
|
|
21
|
-
*/
|
|
22
|
-
export declare function checkoutRelative(root: string, file: string): string;
|