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
@@ -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 says which it is, so the same walk runs again with
1764
- * that callee taken as a sender: every success body the handler returns
1765
- * through it, error branches dropped as before. The located expression's
1766
- * own type is never what is published here.
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
- const identity = sender ? this.calleeIdentity(sender) : undefined;
1814
- if (identity) {
1815
- const recovered = this.recoverPayloadFromResponseExpressions(returned, true, this.wireFormatFor(request), new Set([identity]));
1816
- if (recovered) {
1817
- this.log(`Return type at ${request.file_path}:${request.line_number} resolves to nothing; ` +
1818
- 'the located payload is an argument of a call the handler returns, so that ' +
1819
- "call is a response sender and its success bodies are the route's");
1820
- return this.inferredFromRecoveredPayload(request, recovered);
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
- /** `call` is `<receiver>.text()` with no arguments, and `accept` takes its receiver. */
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
- access.getName() === RAW_TEXT_FORMAT &&
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 receiver,
4795
- * `res.json()` or `res.text()`, or `undefined`. A text read is a body read
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.getArguments().length > 0) {
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, alsoSerialisers) {
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, serialisers);
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(' | '), (symbol) => this.symbolIsLibOrExternalOrigin(symbol));
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`. It is lifted for a
6485
- * callee a caller has its own evidence for (`serialisers`).
6545
+ * annotates; see `recoverPayloadFromReturnStatements`.
6486
6546
  */
6487
- responseHelperPayloadNode(expression, depth, statedOnly, serialisers) {
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, effectiveStatedOnly)) {
6584
+ if (this.nodeCarriesPayloadContract(candidate, statedOnly)) {
6528
6585
  return candidate;
6529
6586
  }
6530
- const nested = this.responseHelperPayloadNode(candidate, depth + 1, statedOnly, serialisers);
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 only: how the type the model
1540
- * named for this row relates to the type read here. Absent where the model
1541
- * named none, or nothing could be compared.
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. Report
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
- ## 6. Act
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. An operation with `verdicts: []`
41
- was never judged, and `verdict_note` says so.
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. Relay `verdict_note`, then read the same
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, not the call-site line.
49
- Raise `depth` to 2 or 3 for transitive callers. Zero recorded callers is not
50
- deletion evidence, because a function passed as a value is unmeasured.
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
 
@@ -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;
@@ -1,84 +0,0 @@
1
- // What one edited file is, shared by the post-edit hook and the background
2
- // re-check runner: whether the scan reads it, which checkout it sits in, and
3
- // which functions a re-check says it newly declares.
4
- //
5
- // Split out of `post-edit.ts` because that file runs `main` on import, so
6
- // nothing else could import from it.
7
- import fs from "node:fs";
8
- import path from "node:path";
9
- /**
10
- * The files `carrick check --changed` judges: the scanner's own source
11
- * extensions (`SOURCE_EXTENSIONS` in `src/file_finder.rs`, carrick#904). An API
12
- * spec file is not counted: the hook cannot tell a spec the scan reads from any
13
- * other `.json` or `.yaml` without reading the repo, and a config file that
14
- * moves no contract is what the line used to be wrong about.
15
- */
16
- const CHECKED_EXTENSIONS = new Set([".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"]);
17
- /** `TEST_FILE_INFIXES` in `src/file_finder.rs`: a test or story file name ends its stem in one. */
18
- const TEST_FILE_INFIXES = [".test", ".spec", ".stories"];
19
- /** `TEST_DIR_NAMES` in `src/file_finder.rs` (plus `.storybook`): trees the scan does not read. */
20
- const TEST_DIR_NAMES = new Set([
21
- "__tests__",
22
- "__mocks__",
23
- "__fixtures__",
24
- "tests",
25
- "test",
26
- "fixtures",
27
- "e2e",
28
- ".storybook",
29
- ]);
30
- /** Whether `carrick check --changed` would judge this edited file: source, and not a test or story. */
31
- export function isCheckedSource(file) {
32
- const extension = path.extname(file).toLowerCase();
33
- if (!CHECKED_EXTENSIONS.has(extension))
34
- return false;
35
- const stem = path.basename(file, extension).toLowerCase();
36
- if (TEST_FILE_INFIXES.some((infix) => stem.endsWith(infix)))
37
- return false;
38
- // Directory names above the file. The scanner reads them relative to the
39
- // scan root; the hook does not know it, so a checkout under a directory
40
- // named `test` hides its source here: the line is then missing, not wrong.
41
- const directories = path.dirname(file).split(/[\\/]/);
42
- return !directories.some((name) => TEST_DIR_NAMES.has(name.toLowerCase()));
43
- }
44
- /**
45
- * What the re-check said this file declares and the index does not
46
- * (carrick#1330).
47
- *
48
- * Nothing is printed about it here. This hook fires on every edit and most
49
- * edits add no function; the one line about the ones that did belongs at the
50
- * end of the task, where it costs one model turn instead of one per edit. All
51
- * this does is put the names somewhere the Stop hook can find them.
52
- */
53
- export function newFunctions(result, file) {
54
- // Test, spec and story files never warrant a reuse check (carrick#2936).
55
- if (!isCheckedSource(file))
56
- return [];
57
- return (result.recheck?.new_functions ?? []).map((entry) => ({
58
- name: entry.name,
59
- // The path this hook computed, not the one the binary echoes: it is the
60
- // checkout-relative path the index holds, whatever root the edit ran from.
61
- file,
62
- indexCommit: result.index_commit ?? "",
63
- }));
64
- }
65
- /**
66
- * `file` relative to the nearest checkout top at or below `root`: the nearest
67
- * directory holding `.git` (a folder, or the file a linked worktree has). An
68
- * edit inside a nested worktree is then keyed as the index keys it, not with
69
- * the worktree's own prefix (carrick#2936). With no nested checkout it is
70
- * relative to `root`, as before.
71
- */
72
- export function checkoutRelative(root, file) {
73
- let dir = path.dirname(file);
74
- while (dir !== root && path.relative(root, dir) && !path.relative(root, dir).startsWith("..")) {
75
- if (fs.existsSync(path.join(dir, ".git")))
76
- return path.relative(dir, file);
77
- const parent = path.dirname(dir);
78
- if (parent === dir)
79
- break;
80
- dir = parent;
81
- }
82
- return path.relative(root, file);
83
- }
84
- //# sourceMappingURL=edited.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"edited.js","sourceRoot":"","sources":["../../src/hook/edited.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,qDAAqD;AACrD,EAAE;AACF,0EAA0E;AAC1E,qCAAqC;AAErC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnG,mGAAmG;AACnG,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,OAAO,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