carrick 0.3.145 → 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 (85) 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 +1 -56
  20. package/dist/hook/reuse.js +12 -110
  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 +14 -36
  30. package/dist/hook/stop.js.map +1 -1
  31. package/dist/hook/user-prompt.js +13 -30
  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 +6 -2
  37. package/dist/init/agents-section.js +11 -7
  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 +3 -2
  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/native.js +1 -9
  58. package/dist/native.js.map +1 -1
  59. package/dist/render.d.ts +21 -1
  60. package/dist/render.js +83 -2
  61. package/dist/render.js.map +1 -1
  62. package/dist/root.d.ts +1 -2
  63. package/dist/root.js +1 -9
  64. package/dist/root.js.map +1 -1
  65. package/dist/surfaces.js +1 -3
  66. package/dist/surfaces.js.map +1 -1
  67. package/package.json +6 -6
  68. package/plugin/.claude-plugin/plugin.json +1 -1
  69. package/sidecar/dist/src/bundler.js +30 -28
  70. package/sidecar/dist/src/platform-body-read.d.ts +46 -0
  71. package/sidecar/dist/src/platform-body-read.js +82 -0
  72. package/sidecar/dist/src/response-modes.d.ts +5 -4
  73. package/sidecar/dist/src/response-modes.js +21 -25
  74. package/sidecar/dist/src/retype.js +11 -16
  75. package/sidecar/dist/src/stated-params.d.ts +6 -0
  76. package/sidecar/dist/src/stated-params.js +13 -0
  77. package/sidecar/dist/src/type-inferrer.d.ts +47 -14
  78. package/sidecar/dist/src/type-inferrer.js +119 -62
  79. package/sidecar/dist/src/types.d.ts +20 -3
  80. package/templates/skills/carrick-census.md +24 -3
  81. package/templates/skills/carrick-drift.md +11 -3
  82. package/templates/skills/carrick-impact.md +8 -3
  83. package/dist/hook/edited.d.ts +0 -22
  84. package/dist/hook/edited.js +0 -84
  85. package/dist/hook/edited.js.map +0 -1
@@ -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
  /**