@ttsc/graph 0.18.4 → 0.19.1

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 (119) hide show
  1. package/README.md +231 -37
  2. package/lib/TtscGraphApplication.d.ts +1 -1
  3. package/lib/TtscGraphApplication.js +50 -17
  4. package/lib/TtscGraphApplication.js.map +1 -1
  5. package/lib/index.d.ts +5 -0
  6. package/lib/index.js +20 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/model/TtscGraphMemory.js +80 -22
  9. package/lib/model/TtscGraphMemory.js.map +1 -1
  10. package/lib/model/TtscGraphSession.js +92 -138
  11. package/lib/model/TtscGraphSession.js.map +1 -1
  12. package/lib/model/loadGraph.js +91 -138
  13. package/lib/model/loadGraph.js.map +1 -1
  14. package/lib/resolveGraphBinary.d.ts +4 -2
  15. package/lib/resolveGraphBinary.js +7 -3
  16. package/lib/resolveGraphBinary.js.map +1 -1
  17. package/lib/server/createServer.d.ts +16 -9
  18. package/lib/server/createServer.js +286 -190
  19. package/lib/server/createServer.js.map +1 -1
  20. package/lib/server/exportSurface.d.ts +26 -0
  21. package/lib/server/exportSurface.js +44 -0
  22. package/lib/server/exportSurface.js.map +1 -0
  23. package/lib/server/resolveHandle.d.ts +26 -1
  24. package/lib/server/resolveHandle.js +124 -4
  25. package/lib/server/resolveHandle.js.map +1 -1
  26. package/lib/server/resultAudit.d.ts +74 -0
  27. package/lib/server/resultAudit.js +110 -0
  28. package/lib/server/resultAudit.js.map +1 -0
  29. package/lib/server/resultNext.d.ts +9 -0
  30. package/lib/server/resultNext.js +11 -0
  31. package/lib/server/resultNext.js.map +1 -0
  32. package/lib/server/runDetails.d.ts +15 -3
  33. package/lib/server/runDetails.js +105 -23
  34. package/lib/server/runDetails.js.map +1 -1
  35. package/lib/server/runEntrypoints.d.ts +2 -1
  36. package/lib/server/runEntrypoints.js +17 -10
  37. package/lib/server/runEntrypoints.js.map +1 -1
  38. package/lib/server/runLookup.d.ts +2 -1
  39. package/lib/server/runLookup.js +21 -9
  40. package/lib/server/runLookup.js.map +1 -1
  41. package/lib/server/runOverview.d.ts +2 -1
  42. package/lib/server/runOverview.js +5 -4
  43. package/lib/server/runOverview.js.map +1 -1
  44. package/lib/server/runTour.d.ts +2 -1
  45. package/lib/server/runTour.js +707 -331
  46. package/lib/server/runTour.js.map +1 -1
  47. package/lib/server/runTrace.d.ts +2 -1
  48. package/lib/server/runTrace.js +234 -54
  49. package/lib/server/runTrace.js.map +1 -1
  50. package/lib/structures/ITtscGraphApplication.d.ts +122 -118
  51. package/lib/structures/ITtscGraphDecorator.d.ts +4 -7
  52. package/lib/structures/ITtscGraphDetails.d.ts +51 -43
  53. package/lib/structures/ITtscGraphDump.d.ts +32 -8
  54. package/lib/structures/ITtscGraphEdge.d.ts +4 -6
  55. package/lib/structures/ITtscGraphEntrypoints.d.ts +10 -27
  56. package/lib/structures/ITtscGraphEscape.d.ts +6 -16
  57. package/lib/structures/ITtscGraphEvidence.d.ts +5 -8
  58. package/lib/structures/ITtscGraphLookup.d.ts +9 -20
  59. package/lib/structures/ITtscGraphNext.d.ts +10 -7
  60. package/lib/structures/ITtscGraphNode.d.ts +17 -8
  61. package/lib/structures/ITtscGraphOverview.d.ts +10 -14
  62. package/lib/structures/ITtscGraphSpan.d.ts +29 -0
  63. package/lib/structures/{ITtscGraphDiagnostic.js → ITtscGraphSpan.js} +1 -1
  64. package/lib/structures/ITtscGraphSpan.js.map +1 -0
  65. package/lib/structures/ITtscGraphTour.d.ts +65 -23
  66. package/lib/structures/ITtscGraphTrace.d.ts +72 -49
  67. package/lib/structures/TtscGraphEdgeKind.d.ts +7 -1
  68. package/lib/structures/index.d.ts +1 -1
  69. package/lib/structures/index.js +1 -1
  70. package/lib/structures/index.js.map +1 -1
  71. package/lib/view.js +3 -1
  72. package/lib/view.js.map +1 -1
  73. package/package.json +4 -4
  74. package/src/TtscGraphApplication.ts +58 -27
  75. package/src/index.ts +19 -1
  76. package/src/model/TtscGraphMemory.ts +86 -22
  77. package/src/model/TtscGraphSession.ts +5 -1
  78. package/src/model/loadGraph.ts +3 -1
  79. package/src/resolveGraphBinary.ts +7 -3
  80. package/src/server/createServer.ts +24 -17
  81. package/src/server/exportSurface.ts +40 -0
  82. package/src/server/resolveHandle.ts +141 -4
  83. package/src/server/resultAudit.ts +109 -0
  84. package/src/server/resultNext.ts +22 -0
  85. package/src/server/runDetails.ts +112 -28
  86. package/src/server/runEntrypoints.ts +26 -17
  87. package/src/server/runLookup.ts +29 -18
  88. package/src/server/runOverview.ts +9 -10
  89. package/src/server/runTour.ts +764 -363
  90. package/src/server/runTrace.ts +265 -71
  91. package/src/structures/ITtscGraphApplication.ts +124 -118
  92. package/src/structures/ITtscGraphDecorator.ts +4 -7
  93. package/src/structures/ITtscGraphDetails.ts +60 -46
  94. package/src/structures/ITtscGraphDump.ts +37 -8
  95. package/src/structures/ITtscGraphEdge.ts +4 -6
  96. package/src/structures/ITtscGraphEntrypoints.ts +10 -30
  97. package/src/structures/ITtscGraphEscape.ts +6 -19
  98. package/src/structures/ITtscGraphEvidence.ts +5 -8
  99. package/src/structures/ITtscGraphLookup.ts +9 -22
  100. package/src/structures/ITtscGraphNext.ts +10 -7
  101. package/src/structures/ITtscGraphNode.ts +18 -8
  102. package/src/structures/ITtscGraphOverview.ts +10 -17
  103. package/src/structures/ITtscGraphSpan.ts +33 -0
  104. package/src/structures/ITtscGraphTour.ts +70 -28
  105. package/src/structures/ITtscGraphTrace.ts +82 -51
  106. package/src/structures/TtscGraphEdgeKind.ts +7 -0
  107. package/src/structures/index.ts +1 -1
  108. package/src/view.ts +3 -1
  109. package/lib/server/accessAliases.d.ts +0 -8
  110. package/lib/server/accessAliases.js +0 -53
  111. package/lib/server/accessAliases.js.map +0 -1
  112. package/lib/server/resultGuide.d.ts +0 -3
  113. package/lib/server/resultGuide.js +0 -16
  114. package/lib/server/resultGuide.js.map +0 -1
  115. package/lib/structures/ITtscGraphDiagnostic.d.ts +0 -27
  116. package/lib/structures/ITtscGraphDiagnostic.js.map +0 -1
  117. package/src/server/accessAliases.ts +0 -55
  118. package/src/server/resultGuide.ts +0 -20
  119. package/src/structures/ITtscGraphDiagnostic.ts +0 -34
@@ -1,8 +1,9 @@
1
1
  import { TtscGraphMemory } from "../model/TtscGraphMemory";
2
2
  import { ITtscGraphLookup } from "../structures/ITtscGraphLookup";
3
3
  import { ITtscGraphNode } from "../structures/ITtscGraphNode";
4
+ import { exportFanIn } from "./exportSurface";
4
5
  import { isExternalNode, isSupportPath } from "./pathPolicy";
5
- import { resultGuide, resultNext } from "./resultGuide";
6
+ import { IRunnerOutput, resultNext } from "./resultNext";
6
7
  import { decoratorsOf, signatureOf } from "./runDetails";
7
8
 
8
9
  // One file should not crowd out the rest of the ranking, so cap hits per file.
@@ -20,7 +21,7 @@ const MAX_LIMIT = 6;
20
21
  export function runLookup(
21
22
  graph: TtscGraphMemory,
22
23
  props: ITtscGraphLookup.IRequest,
23
- ): ITtscGraphLookup {
24
+ ): IRunnerOutput<ITtscGraphLookup> {
24
25
  const terms = subwords(props.query);
25
26
  const codeTerms = exactCodeTerms(props.query);
26
27
  const requestedKinds = requestedSymbolKinds(props.query);
@@ -30,14 +31,13 @@ export function runLookup(
30
31
  const includeExternal = props.includeExternal === true;
31
32
  if (terms.length === 0)
32
33
  return {
33
- type: "lookup",
34
- hits: [],
34
+ result: {
35
+ type: "lookup",
36
+ hits: [],
37
+ },
35
38
  next: resultNext(
36
39
  "clarify",
37
- "No symbol matched; ask for a concrete symbol or scope.",
38
- ),
39
- guide: resultGuide(
40
- "No symbol matched; answer that the graph did not resolve this name or ask for a more concrete symbol.",
40
+ "The query carries no searchable terms, so no symbol could be matched.",
41
41
  ),
42
42
  };
43
43
 
@@ -92,16 +92,20 @@ export function runLookup(
92
92
  if (sig !== undefined) hit.signature = sig;
93
93
  }
94
94
  return {
95
- type: "lookup",
96
- hits,
97
- next: resultNext(
98
- "inspect",
99
- "Use one returned id for trace/details when the answer needs flow or shape.",
100
- "details",
101
- ),
102
- guide: resultGuide(
103
- "Use ranked hits and signatures as symbol evidence. If the target is clear, answer or make one focused trace/details call; do not search files to verify the match.",
104
- ),
95
+ result: {
96
+ type: "lookup",
97
+ hits,
98
+ },
99
+ next:
100
+ hits.length === 0
101
+ ? resultNext(
102
+ "outside",
103
+ "No symbol matched, so the graph did not resolve this name.",
104
+ )
105
+ : resultNext(
106
+ "answer",
107
+ "The ranked hits and their signatures resolve the name.",
108
+ ),
105
109
  };
106
110
  }
107
111
 
@@ -168,6 +172,13 @@ function scoreNode(
168
172
  const fan = degree(graph, node.id);
169
173
  score += Math.min(8, Math.log2(1 + fan) * 2);
170
174
 
175
+ // How many modules put this symbol on the wire. Two symbols can match a name
176
+ // equally well while one is what a consumer imports and the other is a leftover
177
+ // major the package still ships behind a subpath; the re-export chain is what
178
+ // tells them apart, so it breaks the tie.
179
+ const surface = exportFanIn(graph, node.id);
180
+ if (surface > 0) score *= 1 + Math.min(0.4, Math.log2(1 + surface) * 0.14);
181
+
171
182
  // Dampen what is rarely the intended target.
172
183
  if (node.ignored) score *= 0.3;
173
184
  if (isTestFile(node.file)) score *= 0.7;
@@ -2,7 +2,7 @@ import { TtscGraphMemory } from "../model/TtscGraphMemory";
2
2
  import { ITtscGraphNode } from "../structures/ITtscGraphNode";
3
3
  import { ITtscGraphOverview } from "../structures/ITtscGraphOverview";
4
4
  import { isPublicApiNoisePath, isSupportPath } from "./pathPolicy";
5
- import { resultGuide, resultNext } from "./resultGuide";
5
+ import { IRunnerOutput, resultNext } from "./resultNext";
6
6
 
7
7
  /** Edges that express nesting/packaging, not code dependency. */
8
8
  const STRUCTURAL_KINDS = new Set<string>(["contains", "exports", "imports"]);
@@ -17,7 +17,7 @@ const STRUCTURAL_KINDS = new Set<string>(["contains", "exports", "imports"]);
17
17
  export function runOverview(
18
18
  graph: TtscGraphMemory,
19
19
  props: ITtscGraphOverview.IRequest,
20
- ): ITtscGraphOverview {
20
+ ): IRunnerOutput<ITtscGraphOverview> {
21
21
  const aspect = props.aspect ?? "all";
22
22
  const want = (a: ITtscGraphOverview.IRequest["aspect"]): boolean =>
23
23
  aspect === "all" || aspect === a;
@@ -38,18 +38,17 @@ export function runOverview(
38
38
  edges: graph.edges.length,
39
39
  byKind,
40
40
  },
41
- next: resultNext(
42
- "answer",
43
- "Counts, layers, hotspots, and public API are sufficient for broad orientation.",
44
- ),
45
- guide: resultGuide(
46
- "Use counts, layers, hotspots, and public API as a broad orientation map. Do not expand it into file reads unless the user needs exact source body text.",
47
- ),
48
41
  };
49
42
  if (want("layers")) result.layers = layers(graph);
50
43
  if (want("hotspots")) result.hotspots = hotspots(graph);
51
44
  if (want("publicApi")) result.publicApi = publicApi(graph);
52
- return result;
45
+ return {
46
+ result,
47
+ next: resultNext(
48
+ "answer",
49
+ "Counts, layers, hotspots, and public API are what the graph holds about the project's shape.",
50
+ ),
51
+ };
53
52
  }
54
53
 
55
54
  /** Folder-level layering: how source and its export surface spread by directory. */