carrick 0.3.144 → 0.3.146

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.
Files changed (88) hide show
  1. package/bin/carrick.mjs +4 -4
  2. package/dist/contract.js +1 -3
  3. package/dist/contract.js.map +1 -1
  4. package/dist/diagnostics.js +1 -9
  5. package/dist/diagnostics.js.map +1 -1
  6. package/dist/fs-util.d.ts +6 -0
  7. package/dist/fs-util.js +29 -0
  8. package/dist/fs-util.js.map +1 -0
  9. package/dist/global-install.js +1 -8
  10. package/dist/global-install.js.map +1 -1
  11. package/dist/hook/apply-patch.js +3 -4
  12. package/dist/hook/apply-patch.js.map +1 -1
  13. package/dist/hook/post-edit.js +4 -19
  14. package/dist/hook/post-edit.js.map +1 -1
  15. package/dist/hook/post-read.js +1 -6
  16. package/dist/hook/post-read.js.map +1 -1
  17. package/dist/hook/rechecks.js +1 -5
  18. package/dist/hook/rechecks.js.map +1 -1
  19. package/dist/hook/reuse.d.ts +5 -52
  20. package/dist/hook/reuse.js +24 -95
  21. package/dist/hook/reuse.js.map +1 -1
  22. package/dist/hook/session-start.d.ts +9 -0
  23. package/dist/hook/session-start.js +43 -16
  24. package/dist/hook/session-start.js.map +1 -1
  25. package/dist/hook/stdin.d.ts +2 -0
  26. package/dist/hook/stdin.js +8 -0
  27. package/dist/hook/stdin.js.map +1 -0
  28. package/dist/hook/stop-wait.d.ts +1 -1
  29. package/dist/hook/stop.js +13 -35
  30. package/dist/hook/stop.js.map +1 -1
  31. package/dist/hook/user-prompt.js +14 -31
  32. package/dist/hook/user-prompt.js.map +1 -1
  33. package/dist/hosted-snapshot.d.ts +37 -0
  34. package/dist/hosted-snapshot.js +49 -0
  35. package/dist/hosted-snapshot.js.map +1 -0
  36. package/dist/init/agents-section.d.ts +22 -4
  37. package/dist/init/agents-section.js +70 -16
  38. package/dist/init/agents-section.js.map +1 -1
  39. package/dist/init/codex.js +8 -7
  40. package/dist/init/codex.js.map +1 -1
  41. package/dist/init/mcp.js +1 -3
  42. package/dist/init/mcp.js.map +1 -1
  43. package/dist/init/remove.js +3 -3
  44. package/dist/init/remove.js.map +1 -1
  45. package/dist/init/repo-copies.js +2 -10
  46. package/dist/init/repo-copies.js.map +1 -1
  47. package/dist/init/repos.d.ts +0 -2
  48. package/dist/init/repos.js +1 -9
  49. package/dist/init/repos.js.map +1 -1
  50. package/dist/init/run.js +8 -3
  51. package/dist/init/run.js.map +1 -1
  52. package/dist/init/self-update.d.ts +2 -2
  53. package/dist/init/self-update.js +61 -3
  54. package/dist/init/self-update.js.map +1 -1
  55. package/dist/init/settings.js +5 -7
  56. package/dist/init/settings.js.map +1 -1
  57. package/dist/init/task-skills.d.ts +1 -0
  58. package/dist/init/task-skills.js +1 -1
  59. package/dist/init/task-skills.js.map +1 -1
  60. package/dist/native.js +1 -9
  61. package/dist/native.js.map +1 -1
  62. package/dist/render.d.ts +21 -1
  63. package/dist/render.js +83 -2
  64. package/dist/render.js.map +1 -1
  65. package/dist/root.d.ts +1 -2
  66. package/dist/root.js +1 -9
  67. package/dist/root.js.map +1 -1
  68. package/dist/surfaces.js +1 -3
  69. package/dist/surfaces.js.map +1 -1
  70. package/package.json +6 -6
  71. package/plugin/.claude-plugin/plugin.json +1 -1
  72. package/sidecar/dist/src/bundler.js +30 -28
  73. package/sidecar/dist/src/platform-body-read.d.ts +46 -0
  74. package/sidecar/dist/src/platform-body-read.js +82 -0
  75. package/sidecar/dist/src/response-modes.d.ts +5 -4
  76. package/sidecar/dist/src/response-modes.js +21 -25
  77. package/sidecar/dist/src/retype.js +11 -16
  78. package/sidecar/dist/src/stated-params.d.ts +6 -0
  79. package/sidecar/dist/src/stated-params.js +13 -0
  80. package/sidecar/dist/src/type-inferrer.d.ts +47 -14
  81. package/sidecar/dist/src/type-inferrer.js +119 -62
  82. package/sidecar/dist/src/types.d.ts +20 -3
  83. package/templates/skills/carrick-census.md +24 -3
  84. package/templates/skills/carrick-drift.md +11 -3
  85. package/templates/skills/carrick-impact.md +8 -3
  86. package/dist/hook/edited.d.ts +0 -22
  87. package/dist/hook/edited.js +0 -84
  88. package/dist/hook/edited.js.map +0 -1
@@ -27,6 +27,16 @@ function declaresName(sourceFile, name) {
27
27
  sourceFile.getVariableDeclaration(name) ??
28
28
  sourceFile.getFunction(name));
29
29
  }
30
+ /**
31
+ * Whether `sourceFile` declares `name` as a type: an interface, a type alias,
32
+ * a class or an enum. A variable or a function is a value only.
33
+ */
34
+ function declaresType(sourceFile, name) {
35
+ return Boolean(sourceFile.getInterface(name) ??
36
+ sourceFile.getTypeAlias(name) ??
37
+ sourceFile.getClass(name) ??
38
+ sourceFile.getEnum(name));
39
+ }
30
40
  /**
31
41
  * The declarations `name` resolves to when imported from `sourceFile`
32
42
  * (carrick#1605), or `ambiguous`.
@@ -223,6 +233,7 @@ export class TypeBundler {
223
233
  symbol_name: symbol.symbol_name,
224
234
  source_file: symbol.source_file,
225
235
  reason: result.reason || 'Unknown error',
236
+ ...(result.kind ? { kind: result.kind } : {}),
226
237
  });
227
238
  }
228
239
  }
@@ -263,7 +274,19 @@ export class TypeBundler {
263
274
  };
264
275
  }
265
276
  const site = declarationSite(sourceFile, symbol.symbol_name, symbol.source_file, this.expandOrigin());
266
- return 'reason' in site ? { valid: false, reason: site.reason } : { valid: true };
277
+ if ('reason' in site)
278
+ return { valid: false, reason: site.reason };
279
+ // A model may name the value a handler reads its payload from (a service
280
+ // object, a function) as the payload's type. A value is not a type: the
281
+ // inference asked for the same alias defines it (blueprint row N10c).
282
+ if (!declaresType(site.sourceFile, site.name)) {
283
+ return {
284
+ valid: false,
285
+ reason: `Symbol '${symbol.symbol_name}' in ${symbol.source_file} is a value, not a type`,
286
+ kind: 'not_a_type',
287
+ };
288
+ }
289
+ return { valid: true };
267
290
  }
268
291
  /** Where a requested symbol is declared, or undefined when it cannot be found. */
269
292
  siteOf(symbol) {
@@ -382,15 +405,15 @@ export class TypeBundler {
382
405
  }
383
406
  /// Whether the element type must be parenthesised before an `[]` suffix.
384
407
  /// Interfaces/classes/enums are always object/nominal (never a top-level
385
- /// union), so only type aliases and typed variables can carry a bare
386
- /// union/intersection/function that would misparse; those are re-resolved
387
- /// from the source Type here (this runs only on the rare array_depth path).
408
+ /// union), so only type aliases can carry a bare union/intersection/function
409
+ /// that would misparse; those are re-resolved from the source Type here
410
+ /// (this runs only on the rare array_depth path).
388
411
  elementNeedsArrayParens(symbol) {
389
412
  const site = this.siteOf(symbol);
390
413
  if (!site)
391
414
  return false;
392
415
  const { sourceFile, name } = site;
393
- const decl = sourceFile.getTypeAlias(name) ?? sourceFile.getVariableDeclaration(name);
416
+ const decl = sourceFile.getTypeAlias(name);
394
417
  if (!decl)
395
418
  return false;
396
419
  const t = decl.getType();
@@ -494,29 +517,8 @@ export class TypeBundler {
494
517
  : `export ${text}`;
495
518
  return { definition, typeString, typeStringIsExpression: false };
496
519
  }
497
- // Try variable (const type definitions)
498
- const varDecl = sourceFile.getVariableDeclaration(symbolName);
499
- if (varDecl) {
500
- const type = varDecl.getType();
501
- const typeString = type.getText();
502
- const definition = `export type ${alias} = ${typeString};`;
503
- return { definition, typeString, typeStringIsExpression: true };
504
- }
505
- // Try function
506
- const funcDecl = sourceFile.getFunction(symbolName);
507
- if (funcDecl) {
508
- const text = funcDecl.getText();
509
- const typeString = text;
510
- const alreadyExported = text.trimStart().startsWith('export');
511
- const definition = alias !== symbolName
512
- ? (alreadyExported
513
- ? text.replace(`function ${symbolName}`, `declare function ${alias}`)
514
- : text.replace(`function ${symbolName}`, `export declare function ${alias}`))
515
- : alreadyExported
516
- ? text
517
- : `export declare ${text}`;
518
- return { definition, typeString, typeStringIsExpression: false };
519
- }
520
+ // A variable or a function is a value, never bundled: `validateSymbol`
521
+ // fails it as `not_a_type` (blueprint row N10c).
520
522
  return null;
521
523
  }
522
524
  isPathSource(sourceFile) {
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The platform's body reads (blueprint row N33).
3
+ *
4
+ * A zero-argument `json()`, `text()`, `arrayBuffer()`, `blob()`, `bytes()` or
5
+ * `formData()` takes the whole body out of the platform's `Request` or
6
+ * `Response`. The member's name picks which read it is; it never decides
7
+ * that it is one. That is decided by the value the member is called on: its
8
+ * type is a global the runtime declares, in the compiler's default library
9
+ * (`lib.dom.d.ts`) or an installed runtime typings package that declares it
10
+ * as a global (`declare global { interface Response ... }`). A repository's
11
+ * own class with a `json()` member reads its own value, and a client that
12
+ * copies the platform's shape from a package of its own is read through the
13
+ * library store's label for its result, never by this name.
14
+ *
15
+ * A receiver nothing declares (`any` or `unknown`: `fetch` on a checkout whose
16
+ * configuration loads neither the DOM library nor installed runtime typings)
17
+ * has no declaration to decide by, so there the name is all there is and the
18
+ * read is taken as it always was. A declaration that is not the runtime's
19
+ * always decides against it.
20
+ */
21
+ import { Node, ts, type CallExpression } from 'ts-morph';
22
+ /** The reads that take the whole body as JSON or as raw text (carrick#1842). */
23
+ export declare const WHOLE_BODY_READS: ReadonlySet<string>;
24
+ /** The JSON read alone. */
25
+ export declare const JSON_READ: ReadonlySet<string>;
26
+ /** The whole-body reads that are neither JSON nor text (carrick#2112). */
27
+ export declare const BINARY_BODY_READS: ReadonlySet<string>;
28
+ /** The read, and the body format a caller names, for raw text (carrick#1842). */
29
+ export declare const RAW_TEXT_FORMAT = "text";
30
+ /** Whether a declaring file is the runtime's: the default library or an installed package. */
31
+ export type RuntimeFile = (file: ts.SourceFile) => boolean;
32
+ /**
33
+ * `call` is `<receiver>.<read>()` with no arguments, `read` is one of
34
+ * `reads`, and the receiver is a platform value (`isPlatformValue`) or, with
35
+ * `undeclared` set, a value nothing declares (`isUndeclaredValue`).
36
+ */
37
+ export declare function isPlatformBodyRead(call: CallExpression, reads: ReadonlySet<string>, runtimeFile: RuntimeFile, undeclared: 'undeclared_reads' | 'platform_only'): boolean;
38
+ /** The value's type is `any` or `unknown`: nothing declares it. */
39
+ export declare function isUndeclaredValue(value: Node): boolean;
40
+ /**
41
+ * The value's type, `null` and `undefined` aside, is a global the runtime
42
+ * declares: every part of it is named by a symbol with a global declaration
43
+ * in a runtime file. `any`, `unknown` and an anonymous type declare nothing,
44
+ * so they are not.
45
+ */
46
+ export declare function isPlatformValue(value: Node, runtimeFile: RuntimeFile): boolean;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The platform's body reads (blueprint row N33).
3
+ *
4
+ * A zero-argument `json()`, `text()`, `arrayBuffer()`, `blob()`, `bytes()` or
5
+ * `formData()` takes the whole body out of the platform's `Request` or
6
+ * `Response`. The member's name picks which read it is; it never decides
7
+ * that it is one. That is decided by the value the member is called on: its
8
+ * type is a global the runtime declares, in the compiler's default library
9
+ * (`lib.dom.d.ts`) or an installed runtime typings package that declares it
10
+ * as a global (`declare global { interface Response ... }`). A repository's
11
+ * own class with a `json()` member reads its own value, and a client that
12
+ * copies the platform's shape from a package of its own is read through the
13
+ * library store's label for its result, never by this name.
14
+ *
15
+ * A receiver nothing declares (`any` or `unknown`: `fetch` on a checkout whose
16
+ * configuration loads neither the DOM library nor installed runtime typings)
17
+ * has no declaration to decide by, so there the name is all there is and the
18
+ * read is taken as it always was. A declaration that is not the runtime's
19
+ * always decides against it.
20
+ */
21
+ import { Node, ts } from 'ts-morph';
22
+ /** The reads that take the whole body as JSON or as raw text (carrick#1842). */
23
+ export const WHOLE_BODY_READS = new Set(['json', 'text']);
24
+ /** The JSON read alone. */
25
+ export const JSON_READ = new Set(['json']);
26
+ /** The whole-body reads that are neither JSON nor text (carrick#2112). */
27
+ export const BINARY_BODY_READS = new Set(['arrayBuffer', 'blob', 'bytes', 'formData']);
28
+ /** The read, and the body format a caller names, for raw text (carrick#1842). */
29
+ export const RAW_TEXT_FORMAT = 'text';
30
+ /**
31
+ * `call` is `<receiver>.<read>()` with no arguments, `read` is one of
32
+ * `reads`, and the receiver is a platform value (`isPlatformValue`) or, with
33
+ * `undeclared` set, a value nothing declares (`isUndeclaredValue`).
34
+ */
35
+ export function isPlatformBodyRead(call, reads, runtimeFile, undeclared) {
36
+ const callee = call.getExpression();
37
+ if (!Node.isPropertyAccessExpression(callee) || !reads.has(callee.getName()) || call.getArguments().length > 0) {
38
+ return false;
39
+ }
40
+ const receiver = callee.getExpression();
41
+ return (isPlatformValue(receiver, runtimeFile) ||
42
+ (undeclared === 'undeclared_reads' && isUndeclaredValue(receiver)));
43
+ }
44
+ /** The value's type is `any` or `unknown`: nothing declares it. */
45
+ export function isUndeclaredValue(value) {
46
+ try {
47
+ const type = value.getType();
48
+ return type.isAny() || type.isUnknown();
49
+ }
50
+ catch {
51
+ return false;
52
+ }
53
+ }
54
+ /**
55
+ * The value's type, `null` and `undefined` aside, is a global the runtime
56
+ * declares: every part of it is named by a symbol with a global declaration
57
+ * in a runtime file. `any`, `unknown` and an anonymous type declare nothing,
58
+ * so they are not.
59
+ */
60
+ export function isPlatformValue(value, runtimeFile) {
61
+ let type;
62
+ try {
63
+ type = value.getType().getNonNullableType();
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ const parts = type.isUnion() ? type.getUnionTypes() : [type];
69
+ return (parts.length > 0 &&
70
+ parts.every((part) => (part.getSymbol()?.getDeclarations() ?? []).some((declaration) => isGlobalDeclaration(declaration.compilerNode) &&
71
+ runtimeFile(declaration.getSourceFile().compilerNode))));
72
+ }
73
+ /** Declared in the global scope: a script file's top level, or a `declare global` block. */
74
+ function isGlobalDeclaration(node) {
75
+ for (let at = node.parent; at; at = at.parent) {
76
+ if (ts.isModuleDeclaration(at))
77
+ return (at.flags & ts.NodeFlags.GlobalAugmentation) !== 0;
78
+ if (ts.isSourceFile(at))
79
+ return !ts.isExternalModule(at);
80
+ }
81
+ return false;
82
+ }
@@ -29,7 +29,7 @@
29
29
  *
30
30
  * The published union is not changed by any of this.
31
31
  */
32
- import { Node, type Symbol as TsSymbol } from 'ts-morph';
32
+ import { Node, type CallExpression } from 'ts-morph';
33
33
  /**
34
34
  * Where in the incoming message a field is read from. Only the HTTP sources
35
35
  * are read so far; another protocol (a socket message, a pub/sub payload)
@@ -74,9 +74,10 @@ export interface JoinedBody {
74
74
  /**
75
75
  * The modes of the union joined from `bodies`, or `undefined` when no message
76
76
  * read separates them. `join` builds a union text from member texts with the
77
- * rules the published union is built with. `isLibOrExternal` says whether a
78
- * symbol is declared by a TypeScript lib or an installed library.
77
+ * rules the published union is built with. `isBodyRead` says whether a call
78
+ * is the platform's `json()` body read (`platform-body-read.ts`, blueprint
79
+ * row N33).
79
80
  */
80
- export declare function readResponseModes(bodies: JoinedBody[], join: (texts: string[]) => string, isLibOrExternal: (symbol: TsSymbol | undefined) => boolean): ResponseModes | undefined;
81
+ export declare function readResponseModes(bodies: JoinedBody[], join: (texts: string[]) => string, isBodyRead: (call: CallExpression) => boolean): ResponseModes | undefined;
81
82
  /** The text of a string literal, `undefined` for anything else. */
82
83
  export declare function stringLiteral(node: Node | undefined): string | undefined;
@@ -35,10 +35,11 @@ const MAX_CHAIN = 32;
35
35
  /**
36
36
  * The modes of the union joined from `bodies`, or `undefined` when no message
37
37
  * read separates them. `join` builds a union text from member texts with the
38
- * rules the published union is built with. `isLibOrExternal` says whether a
39
- * symbol is declared by a TypeScript lib or an installed library.
38
+ * rules the published union is built with. `isBodyRead` says whether a call
39
+ * is the platform's `json()` body read (`platform-body-read.ts`, blueprint
40
+ * row N33).
40
41
  */
41
- export function readResponseModes(bodies, join, isLibOrExternal) {
42
+ export function readResponseModes(bodies, join, isBodyRead) {
42
43
  if (bodies.length < 2)
43
44
  return undefined;
44
45
  const boundary = smallestEnclosingFunction(bodies.map((body) => body.node));
@@ -61,7 +62,7 @@ export function readResponseModes(bodies, join, isLibOrExternal) {
61
62
  for (const { step, byBody } of sides.values()) {
62
63
  if (new Set(byBody.values()).size < 2)
63
64
  continue;
64
- const reading = readStep(step, isLibOrExternal);
65
+ const reading = readStep(step, isBodyRead);
65
66
  if (!reading)
66
67
  continue;
67
68
  if (reading.kind === 'unread') {
@@ -163,13 +164,13 @@ function admitsValue(admits, value) {
163
164
  return 'only' in admits ? admits.only.has(value) : !admits.except.has(value);
164
165
  }
165
166
  /** What `step`'s test reads of the incoming message, `undefined` when nothing. */
166
- function readStep(step, isLibOrExternal) {
167
+ function readStep(step, isBodyRead) {
167
168
  if (step.kind === 'branch')
168
- return readCondition(step.condition, isLibOrExternal);
169
+ return readCondition(step.condition, isBodyRead);
169
170
  const subject = step.test.getExpression();
170
- const read = messageRead(subject, isLibOrExternal);
171
+ const read = messageRead(subject, isBodyRead);
171
172
  if (!read) {
172
- const inside = readsIn(subject, isLibOrExternal);
173
+ const inside = readsIn(subject, isBodyRead);
173
174
  return inside.length > 0 ? { kind: 'unread', reads: inside } : undefined;
174
175
  }
175
176
  // A body after the switch is reached by the values whose clauses run on
@@ -214,7 +215,7 @@ function readStep(step, isLibOrExternal) {
214
215
  };
215
216
  }
216
217
  /** What an `if` or conditional condition reads of the incoming message. */
217
- function readCondition(condition, isLibOrExternal) {
218
+ function readCondition(condition, isBodyRead) {
218
219
  let test = condition;
219
220
  let flipped = false;
220
221
  for (;;) {
@@ -242,7 +243,7 @@ function readCondition(condition, isLibOrExternal) {
242
243
  const leftLiteral = stringLiteral(left);
243
244
  const value = rightLiteral ?? leftLiteral;
244
245
  const operand = rightLiteral !== undefined ? left : right;
245
- const read = value !== undefined ? messageRead(operand, isLibOrExternal) : undefined;
246
+ const read = value !== undefined ? messageRead(operand, isBodyRead) : undefined;
246
247
  if (read && value !== undefined) {
247
248
  // True side admits the value when the test is an equality.
248
249
  const trueAdmitsValue = equal !== flipped;
@@ -257,7 +258,7 @@ function readCondition(condition, isLibOrExternal) {
257
258
  }
258
259
  }
259
260
  }
260
- const inside = readsIn(condition, isLibOrExternal);
261
+ const inside = readsIn(condition, isBodyRead);
261
262
  return inside.length > 0 ? { kind: 'unread', reads: inside } : undefined;
262
263
  }
263
264
  /** The text of a string literal, `undefined` for anything else. */
@@ -273,12 +274,12 @@ export function stringLiteral(node) {
273
274
  return undefined;
274
275
  }
275
276
  /** Every message read inside `node`, outermost reads only. */
276
- function readsIn(node, isLibOrExternal) {
277
+ function readsIn(node, isBodyRead) {
277
278
  const found = [];
278
279
  for (const candidate of [node, ...node.getDescendants()]) {
279
280
  if (found.some((read) => read.node.containsRange(candidate.getPos(), candidate.getEnd())))
280
281
  continue;
281
- const read = messageRead(candidate, isLibOrExternal);
282
+ const read = messageRead(candidate, isBodyRead);
282
283
  if (read)
283
284
  found.push(read);
284
285
  }
@@ -293,14 +294,14 @@ function readsIn(node, isLibOrExternal) {
293
294
  * `URL`. A `let`, a binding default, or a call that takes the message as an
294
295
  * argument ends the chain, and it is not a read.
295
296
  */
296
- function messageRead(node, isLibOrExternal) {
297
+ function messageRead(node, isBodyRead) {
297
298
  const links = chainOf(node, enclosingParameters(node), 0);
298
299
  if (!links || links.length === 0)
299
300
  return undefined;
300
301
  const field = fieldOf(links);
301
302
  if (field === undefined)
302
303
  return undefined;
303
- return { location: locationOf(links, isLibOrExternal), field, node };
304
+ return { location: locationOf(links, isBodyRead), field, node };
304
305
  }
305
306
  function enclosingParameters(node) {
306
307
  const parameters = new Set();
@@ -353,9 +354,7 @@ function chainOf(node, roots, depth) {
353
354
  if (Node.isNewExpression(node)) {
354
355
  const callee = node.getExpression();
355
356
  const [input] = node.getArguments();
356
- if (!Node.isIdentifier(callee) || callee.getText() !== 'URL' || !input)
357
- return undefined;
358
- if (!declaredByDefaultLib(callee.getSymbol()))
357
+ if (!input || !declaredByDefaultLib(callee.getSymbol(), 'URL'))
359
358
  return undefined;
360
359
  const base = next(input);
361
360
  return base && [...base, { kind: 'url' }];
@@ -421,7 +420,7 @@ function fieldOf(links) {
421
420
  }
422
421
  return undefined;
423
422
  }
424
- function locationOf(links, isLibOrExternal) {
423
+ function locationOf(links, isBodyRead) {
425
424
  const last = links[links.length - 1];
426
425
  if (last.kind === 'call' &&
427
426
  last.name === 'get' &&
@@ -435,12 +434,9 @@ function locationOf(links, isLibOrExternal) {
435
434
  if (awaited.kind === 'await' &&
436
435
  json.kind === 'call' &&
437
436
  json.name === 'json' &&
438
- json.args.length === 0 &&
439
- Node.isCallExpression(json.call)) {
440
- const callee = json.call.getExpression();
441
- const symbol = Node.isPropertyAccessExpression(callee) ? callee.getNameNode().getSymbol() : undefined;
442
- if (isLibOrExternal(symbol))
443
- return 'body';
437
+ Node.isCallExpression(json.call) &&
438
+ isBodyRead(json.call)) {
439
+ return 'body';
444
440
  }
445
441
  }
446
442
  return 'unplaced';
@@ -33,6 +33,7 @@ import { typeToStringAsDeclared } from './print-type.js';
33
33
  import { deferredResultNeedsUndefined } from './retype-deferred.js';
34
34
  import { resolvedDeclaration, typeArgumentOnlySelects } from './retype-selector.js';
35
35
  import { fileDiagnostics } from './unwidened.js';
36
+ import { JSON_READ } from './platform-body-read.js';
36
37
  /** Names appended to a file that is not ours carry this prefix. */
37
38
  const PREFIX = '__carrick_';
38
39
  const WIRE = `${PREFIX}Wire`;
@@ -278,7 +279,7 @@ export class Retyper {
278
279
  // `.json()`: the payload is that read, so the cast goes there
279
280
  // (carrick#1493). The call's own result is not the payload and is not
280
281
  // touched.
281
- const reads = bodyReadsOf(call);
282
+ const reads = bodyReadsOf(call, (read) => this.inferrer.isPlatformBodyRead(read, JSON_READ, 'undeclared_reads'));
282
283
  if (typeof reads === 'string')
283
284
  return reads;
284
285
  if (reads.length > 0) {
@@ -644,7 +645,7 @@ function returnsUndeclared(node) {
644
645
  * may have its body read out of view, so an agreement here would claim reads
645
646
  * the diff cannot see.
646
647
  */
647
- function bodyReadsOf(call) {
648
+ function bodyReadsOf(call, isBodyRead) {
648
649
  if (isBodyRead(call))
649
650
  return checkedBodyReads([call]);
650
651
  let top = call;
@@ -652,7 +653,7 @@ function bodyReadsOf(call) {
652
653
  Node.isParenthesizedExpression(top.getParentOrThrow())) {
653
654
  top = top.getParentOrThrow();
654
655
  }
655
- const chained = bodyReadOn(top);
656
+ const chained = bodyReadOn(top, isBodyRead);
656
657
  if (chained)
657
658
  return checkedBodyReads([chained]);
658
659
  const name = responseBinding(top);
@@ -661,7 +662,7 @@ function bodyReadsOf(call) {
661
662
  const reads = [];
662
663
  let handedOn = false;
663
664
  for (const ref of name.findReferencesAsNodes()) {
664
- const read = bodyReadOn(ref);
665
+ const read = bodyReadOn(ref, isBodyRead);
665
666
  if (read) {
666
667
  reads.push(read);
667
668
  continue;
@@ -960,13 +961,13 @@ function carriesBody(status) {
960
961
  * Content, 205 Reset Content).
961
962
  */
962
963
  const NO_CONTENT_STATUSES = new Set([204, 205]);
963
- /** `node.json()` with no arguments, where `node` is the receiver. */
964
- function bodyReadOn(node) {
964
+ /**
965
+ * `node.json()` with no arguments, where `node` is the receiver and
966
+ * `isBodyRead` takes the call as the platform's body read (blueprint row N33).
967
+ */
968
+ function bodyReadOn(node, isBodyRead) {
965
969
  const access = node.getParent();
966
- if (!access ||
967
- !Node.isPropertyAccessExpression(access) ||
968
- access.getExpression() !== node ||
969
- access.getName() !== 'json') {
970
+ if (!access || !Node.isPropertyAccessExpression(access) || access.getExpression() !== node) {
970
971
  return undefined;
971
972
  }
972
973
  const read = access.getParent();
@@ -974,12 +975,6 @@ function bodyReadOn(node) {
974
975
  ? read
975
976
  : undefined;
976
977
  }
977
- function isBodyRead(call) {
978
- const callee = call.getExpression();
979
- return (Node.isPropertyAccessExpression(callee) &&
980
- callee.getName() === 'json' &&
981
- call.getArguments().length === 0);
982
- }
983
978
  function isAssignmentOperator(kind) {
984
979
  return kind >= SyntaxKind.FirstAssignment && kind <= SyntaxKind.LastAssignment;
985
980
  }
@@ -150,6 +150,12 @@ export declare class StatedParams {
150
150
  private payloadTypeParameters;
151
151
  /** The type the call signature takes at the payload slot, read at `at`. */
152
152
  private payloadAt;
153
+ /**
154
+ * The called member's declaration is one the labels name a request body
155
+ * (blueprint row N33): a framework's own `json()` on its request, read as
156
+ * the body where the store says so. Matched by declaration, never by name.
157
+ */
158
+ readsLabelledBody(call: Node): boolean;
153
159
  /**
154
160
  * What the labels say about one call (carrick#2472 C2): the payload slot
155
161
  * when the called member's declaration is a labelled send; `'setter'` when
@@ -600,6 +600,19 @@ export class StatedParams {
600
600
  }
601
601
  return type;
602
602
  }
603
+ /**
604
+ * The called member's declaration is one the labels name a request body
605
+ * (blueprint row N33): a framework's own `json()` on its request, read as
606
+ * the body where the store says so. Matched by declaration, never by name.
607
+ */
608
+ readsLabelledBody(call) {
609
+ if (this.labels.bodies.size === 0 || !Node.isCallExpression(call))
610
+ return false;
611
+ const callee = call.getExpression();
612
+ if (!Node.isPropertyAccessExpression(callee))
613
+ return false;
614
+ return (callee.getNameNode().getSymbol()?.getDeclarations() ?? []).some((d) => this.labels.bodies.has(declarationKey(d.compilerNode)));
615
+ }
603
616
  /**
604
617
  * What the labels say about one call (carrick#2472 C2): the payload slot
605
618
  * when the called member's declaration is a labelled send; `'setter'` when
@@ -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 says which it is, so the same walk runs again with
361
- * that callee taken as a sender: every success body the handler returns
362
- * through it, error branches dropped as before. The located expression's
363
- * own type is never what is published here.
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
- /** `call` is `<receiver>.text()` with no arguments, and `accept` takes its receiver. */
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 receiver,
1013
- * `res.json()` or `res.text()`, or `undefined`. A text read is a body read
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`. It is lifted for a
1551
- * callee a caller has its own evidence for (`serialisers`).
1584
+ * annotates; see `recoverPayloadFromReturnStatements`.
1552
1585
  */
1553
1586
  private responseHelperPayloadNode;
1554
1587
  /**