@ttsc/graph 0.23.0 → 0.25.0

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 (70) hide show
  1. package/README.md +1 -1
  2. package/lib/index.js +36 -0
  3. package/lib/index.js.map +1 -1
  4. package/lib/model/TtscGraphMemory.d.ts +1 -1
  5. package/lib/model/TtscGraphMemory.js +16 -13
  6. package/lib/model/TtscGraphMemory.js.map +1 -1
  7. package/lib/model/TtscGraphSession.d.ts +2 -6
  8. package/lib/model/TtscGraphSession.js +414 -235
  9. package/lib/model/TtscGraphSession.js.map +1 -1
  10. package/lib/model/TtscGraphShardStore.d.ts +16 -0
  11. package/lib/model/TtscGraphShardStore.js +272 -0
  12. package/lib/model/TtscGraphShardStore.js.map +1 -0
  13. package/lib/model/loadGraph.js +68 -61
  14. package/lib/model/loadGraph.js.map +1 -1
  15. package/lib/nativeExecutable.d.ts +22 -0
  16. package/lib/nativeExecutable.js +76 -0
  17. package/lib/nativeExecutable.js.map +1 -1
  18. package/lib/server/runDetails.js +4 -9
  19. package/lib/server/runDetails.js.map +1 -1
  20. package/lib/server/runEntrypoints.js +4 -7
  21. package/lib/server/runEntrypoints.js.map +1 -1
  22. package/lib/server/runLookup.js +1 -1
  23. package/lib/server/runLookup.js.map +1 -1
  24. package/lib/server/runOverview.js +3 -3
  25. package/lib/server/runOverview.js.map +1 -1
  26. package/lib/server/runTour.js +7 -11
  27. package/lib/server/runTour.js.map +1 -1
  28. package/lib/server/runTrace.d.ts +4 -5
  29. package/lib/server/runTrace.js +10 -19
  30. package/lib/server/runTrace.js.map +1 -1
  31. package/lib/structures/ITtscGraphDump.d.ts +8 -2
  32. package/lib/structures/ITtscGraphNode.d.ts +1 -2
  33. package/lib/structures/ITtscGraphSnapshot.d.ts +37 -1
  34. package/lib/structures/TtscGraphDumpEdgeKind.d.ts +2 -0
  35. package/lib/structures/TtscGraphDumpEdgeKind.js +3 -0
  36. package/lib/structures/TtscGraphDumpEdgeKind.js.map +1 -0
  37. package/lib/structures/TtscGraphDumpNodeKind.d.ts +2 -0
  38. package/lib/structures/TtscGraphDumpNodeKind.js +3 -0
  39. package/lib/structures/TtscGraphDumpNodeKind.js.map +1 -0
  40. package/lib/structures/TtscGraphEdgeKind.d.ts +8 -6
  41. package/lib/structures/TtscGraphNodeKind.d.ts +5 -6
  42. package/lib/structures/TtscGraphNodeModifier.d.ts +1 -1
  43. package/lib/structures/index.d.ts +2 -0
  44. package/lib/structures/index.js +2 -0
  45. package/lib/structures/index.js.map +1 -1
  46. package/lib/view.js +17 -2
  47. package/lib/view.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/index.ts +40 -0
  50. package/src/model/TtscGraphMemory.ts +10 -8
  51. package/src/model/TtscGraphSession.ts +64 -47
  52. package/src/model/TtscGraphShardStore.ts +371 -0
  53. package/src/model/loadGraph.ts +20 -13
  54. package/src/nativeExecutable.ts +83 -0
  55. package/src/server/runDetails.ts +5 -10
  56. package/src/server/runEntrypoints.ts +4 -7
  57. package/src/server/runLookup.ts +1 -1
  58. package/src/server/runOverview.ts +3 -3
  59. package/src/server/runTour.ts +8 -14
  60. package/src/server/runTrace.ts +10 -19
  61. package/src/structures/ITtscGraphDump.ts +10 -2
  62. package/src/structures/ITtscGraphNode.ts +1 -2
  63. package/src/structures/ITtscGraphSnapshot.ts +42 -1
  64. package/src/structures/TtscGraphDumpEdgeKind.ts +11 -0
  65. package/src/structures/TtscGraphDumpNodeKind.ts +10 -0
  66. package/src/structures/TtscGraphEdgeKind.ts +8 -9
  67. package/src/structures/TtscGraphNodeKind.ts +5 -11
  68. package/src/structures/TtscGraphNodeModifier.ts +1 -2
  69. package/src/structures/index.ts +2 -0
  70. package/src/view.ts +21 -7
@@ -29,11 +29,7 @@ const MAX_STEPS = 12;
29
29
  const DISPATCH_KINDS = new Set<string>(["overrides", "implements"]);
30
30
  // A declaration whose kind is a type surface never carries a body, and an
31
31
  // external leaf carries one the graph deliberately does not hold.
32
- const BODYLESS_KINDS = new Set<string>([
33
- "interface",
34
- "type",
35
- "external_symbol",
36
- ]);
32
+ const BODYLESS_KINDS = new Set<string>(["interface", "type"]);
37
33
  // `abstract` and `declare` are the two keywords that take the body away from a
38
34
  // declaration that would otherwise have to have one.
39
35
  const BODYLESS_MODIFIERS = new Set<string>(["abstract", "declare"]);
@@ -48,11 +44,10 @@ const BODYLESS_MODIFIERS = new Set<string>(["abstract", "declare"]);
48
44
  const DISPATCH_HUB = 12;
49
45
 
50
46
  /**
51
- * Breadth-first trace along the dependency graph. Structural
52
- * (contains/exports/imports) edges are excluded so the path is real call/type
53
- * flow; forward walks callees, reverse and impact walk callers. Impact
54
- * additionally tags each reached node's role so the blast radius on the public
55
- * surface is legible.
47
+ * Breadth-first trace along the dependency graph. Structural (contains/exports)
48
+ * edges are excluded so the path is real call/type flow; forward walks callees,
49
+ * reverse and impact walk callers. Impact additionally tags each reached node's
50
+ * role so the blast radius on the public surface is legible.
56
51
  */
57
52
  export function runTrace(
58
53
  graph: TtscGraphMemory,
@@ -946,7 +941,7 @@ function traversable(
946
941
  kind: string,
947
942
  focus: ITtscGraphTrace.IRequest["focus"],
948
943
  ): boolean {
949
- if (kind === "contains" || kind === "exports" || kind === "imports") {
944
+ if (kind === "contains" || kind === "exports") {
950
945
  return false;
951
946
  }
952
947
  if (kind === "dispatches") return focus !== "types";
@@ -963,8 +958,7 @@ function traversable(
963
958
  kind === "type_ref" ||
964
959
  kind === "extends" ||
965
960
  kind === "implements" ||
966
- kind === "overrides" ||
967
- kind === "decorates"
961
+ kind === "overrides"
968
962
  );
969
963
  }
970
964
  return true;
@@ -985,16 +979,13 @@ function edgeKindRank(kind: string): number {
985
979
  return 2;
986
980
  case "accesses":
987
981
  return 3;
988
- case "tests":
989
- return 4;
990
982
  case "overrides":
991
- case "decorates":
992
- return 5;
983
+ return 4;
993
984
  case "extends":
994
985
  case "implements":
995
- return 6;
986
+ return 5;
996
987
  case "type_ref":
997
- return 7;
988
+ return 6;
998
989
  default:
999
990
  return 10;
1000
991
  }
@@ -1,6 +1,8 @@
1
1
  import { ITtscGraphEdge } from "./ITtscGraphEdge";
2
2
  import { ITtscGraphNode } from "./ITtscGraphNode";
3
3
  import { ITtscGraphSpan } from "./ITtscGraphSpan";
4
+ import { TtscGraphDumpEdgeKind } from "./TtscGraphDumpEdgeKind";
5
+ import { TtscGraphDumpNodeKind } from "./TtscGraphDumpNodeKind";
4
6
 
5
7
  /**
6
8
  * The whole-graph export `ttscgraph dump` writes and the MCP server loads — the
@@ -229,8 +231,11 @@ export namespace ITtscGraphDump {
229
231
  */
230
232
  export interface INode extends Omit<
231
233
  ITtscGraphNode,
232
- "evidence" | "implementation"
234
+ "evidence" | "implementation" | "kind"
233
235
  > {
236
+ /** Declaration kind written by the native producer. */
237
+ kind: TtscGraphDumpNodeKind;
238
+
234
239
  /** Declaration span; its file is this node's `file`. */
235
240
  evidence?: ITtscGraphSpan;
236
241
 
@@ -246,7 +251,10 @@ export namespace ITtscGraphDump {
246
251
  * names — the id is `path#Qualified.Name:kind` — so the path rode the wire a
247
252
  * second time on every edge, and edges outnumber nodes several times over.
248
253
  */
249
- export interface IEdge extends Omit<ITtscGraphEdge, "evidence"> {
254
+ export interface IEdge extends Omit<ITtscGraphEdge, "evidence" | "kind"> {
255
+ /** Relationship kind written by the native producer. */
256
+ kind: TtscGraphDumpEdgeKind;
257
+
250
258
  /** Expression span; its file is the one embedded in `from`. */
251
259
  evidence?: ITtscGraphSpan;
252
260
  }
@@ -4,8 +4,7 @@ import { TtscGraphNodeKind } from "./TtscGraphNodeKind";
4
4
  import { TtscGraphNodeModifier } from "./TtscGraphNodeModifier";
5
5
 
6
6
  /**
7
- * One node in the graph: a declared symbol or a structural container (file,
8
- * package).
7
+ * One node in the graph: a declared symbol or a synthesized file container.
9
8
  *
10
9
  * The `id` is position-invariant: `path#qualifiedName:kind` (e.g.
11
10
  * `src/order.ts#OrderService.create:method`), so inserting a line above a
@@ -44,11 +44,52 @@ export interface ITtscGraphSnapshot {
44
44
  /** The snapshot, present exactly when `changed` is true. */
45
45
  dump?: ITtscGraphDump;
46
46
 
47
+ /** Native graph-shard transaction, present for an opted-in changed request. */
48
+ snapshot?: ITtscGraphSnapshot.ITransaction;
49
+
47
50
  /** Set when the request produced no snapshot; `mode` is then `"error"`. */
48
51
  error?: string;
49
52
  }
50
53
 
51
54
  export namespace ITtscGraphSnapshot {
55
+ /** Versioned content-addressed transaction emitted by `ttscgraph serve`. */
56
+ export interface ITransaction {
57
+ protocolVersion: number;
58
+ schemaVersion: number;
59
+ project: string;
60
+ tsconfig: string;
61
+ producer: ITtscGraphDump.IProducer;
62
+ capabilities: string[];
63
+ universe: ITtscGraphDump.IUniverse;
64
+ sequence: number;
65
+ generation: string;
66
+ baseSequence?: number;
67
+ baseGeneration?: string;
68
+ upserts: IShardUpsert[];
69
+ deletes: string[];
70
+ manifest: IShardReference[];
71
+ }
72
+
73
+ export interface IShardUpsert {
74
+ digest: string;
75
+ shard: IShard;
76
+ }
77
+
78
+ export interface IShardReference {
79
+ key: string;
80
+ digest: string;
81
+ }
82
+
83
+ /** One source/config or metadata-owned raw compiler fact shard. */
84
+ export interface IShard {
85
+ key: string;
86
+ source?: ITtscGraphDump.ISourceDigest;
87
+ config?: ITtscGraphDump.IFileDigest;
88
+ nodes: ITtscGraphDump.INode[];
89
+ edges: ITtscGraphDump.IEdge[];
90
+ diagnostics: ITtscGraphDump.IDiagnostic[];
91
+ }
92
+
52
93
  /**
53
94
  * The computation modes the producer reports, plus the transport's `error`.
54
95
  *
@@ -56,7 +97,7 @@ export namespace ITtscGraphSnapshot {
56
97
  * - `reload`: the build universe moved, so the program was reloaded whole.
57
98
  * - `unchanged`: nothing moved; no dump rides it and the last one still holds.
58
99
  * - `incremental`: edits applied onto the reused resident program.
59
- * - `rebuild`: edits applied, but the program could not be reused.
100
+ * - `rebuild`: edits applied, but graph projection required a complete build.
60
101
  * - `error`: no snapshot was produced.
61
102
  */
62
103
  export type Mode =
@@ -0,0 +1,11 @@
1
+ /** Relationship kinds the native Go dump producer can write. */
2
+ export type TtscGraphDumpEdgeKind =
3
+ | "exports"
4
+ | "calls"
5
+ | "accesses"
6
+ | "instantiates"
7
+ | "type_ref"
8
+ | "extends"
9
+ | "implements"
10
+ | "overrides"
11
+ | "renders";
@@ -0,0 +1,10 @@
1
+ /** Declaration kinds the native Go dump producer can write. */
2
+ export type TtscGraphDumpNodeKind =
3
+ | "module"
4
+ | "function"
5
+ | "class"
6
+ | "interface"
7
+ | "type"
8
+ | "enum"
9
+ | "variable"
10
+ | "method";
@@ -1,22 +1,23 @@
1
1
  /**
2
2
  * The relationship a directed edge encodes between two {@link ITtscGraphNode}s.
3
3
  *
4
- * Structural edges (`contains`, `exports`, `imports`) come from the declaration
5
- * pass. Value and type edges (`calls`, `accesses`, `instantiates`, `type_ref`,
4
+ * Structural `exports` edges come from the native declaration pass, while the
5
+ * TypeScript memory layer synthesizes `contains` ownership. Value and type
6
+ * edges (`calls`, `accesses`, `instantiates`, `type_ref`,
6
7
  * `extends`, `implements`, `overrides`, `renders`) are resolved by the checker
7
- * — `renders` is a JSX component use. `decorates` carries a decorator fact and
8
- * `tests` a test-to-subject relationship.
8
+ * — `renders` is a JSX component use. Decorators are facts on their target node,
9
+ * not edges.
9
10
  *
10
11
  * `dispatches` is the runtime counterpart of `overrides`/`implements`: the
11
12
  * checker resolves a call to the declaration it names, and where that
12
13
  * declaration is abstract or an interface member, the code that runs is its
13
14
  * implementation. It carries the implementation's declaration span, and a
14
- * traversal that follows what executes emits it in place of the dead end.
15
+ * traversal that follows what executes emits it in place of the dead end. It is
16
+ * trace-only and never appears in a native dump.
15
17
  */
16
18
  export type TtscGraphEdgeKind =
17
19
  | "contains"
18
20
  | "exports"
19
- | "imports"
20
21
  | "calls"
21
22
  | "accesses"
22
23
  | "instantiates"
@@ -25,6 +26,4 @@ export type TtscGraphEdgeKind =
25
26
  | "implements"
26
27
  | "overrides"
27
28
  | "dispatches"
28
- | "decorates"
29
- | "renders"
30
- | "tests";
29
+ | "renders";
@@ -1,19 +1,15 @@
1
1
  /**
2
2
  * What a graph node represents.
3
3
  *
4
- * The symbol kinds (`file` through `parameter`) are declarations the TypeScript
5
- * program owns and the checker resolves. `external_symbol` is a
6
- * dependency-boundary leaf the workspace references but does not declare. The
7
- * graph keeps it as a named endpoint without walking into the dependency's
8
- * internals.
4
+ * The native builder emits declaration kinds from `module` through `method`.
5
+ * The TypeScript memory layer replaces each module with a `file` container and
6
+ * refines class/interface member variables to `property`. An external boundary
7
+ * leaf keeps its real declaration kind and sets `external: true`.
9
8
  *
10
9
  * Used as the `kind` discriminant on {@link ITtscGraphNode}.
11
10
  */
12
11
  export type TtscGraphNodeKind =
13
12
  | "file"
14
- | "package"
15
- | "namespace"
16
- | "module"
17
13
  | "function"
18
14
  | "class"
19
15
  | "interface"
@@ -21,6 +17,4 @@ export type TtscGraphNodeKind =
21
17
  | "enum"
22
18
  | "variable"
23
19
  | "method"
24
- | "property"
25
- | "parameter"
26
- | "external_symbol";
20
+ | "property";
@@ -15,5 +15,4 @@ export type TtscGraphNodeModifier =
15
15
  | "const"
16
16
  | "public"
17
17
  | "private"
18
- | "protected"
19
- | "optional";
18
+ | "protected";
@@ -21,5 +21,7 @@ export * from "./ITtscGraphSnapshot";
21
21
  export * from "./ITtscGraphSpan";
22
22
  export * from "./ITtscGraphTour";
23
23
  export * from "./TtscGraphEdgeKind";
24
+ export * from "./TtscGraphDumpEdgeKind";
25
+ export * from "./TtscGraphDumpNodeKind";
24
26
  export * from "./TtscGraphNodeKind";
25
27
  export * from "./TtscGraphNodeModifier";
package/src/view.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  projectOptions,
11
11
  } from "./launcherArgs";
12
12
  import { parseDump } from "./model/loadGraph";
13
- import { ensureExecutable } from "./nativeExecutable";
13
+ import { captureProcessOutput, ensureExecutable } from "./nativeExecutable";
14
14
  import { reduce } from "./reduce";
15
15
  import { resolveGraphBinary } from "./resolveGraphBinary";
16
16
 
@@ -70,11 +70,25 @@ export function runView(argv: readonly string[]): number | void {
70
70
  process.stderr.write(
71
71
  `@ttsc/graph: building the graph for ${opts.cwd} (${opts.tsconfig})...\n`,
72
72
  );
73
- const dump = spawnSync(
74
- binary,
75
- ["dump", "--cwd", opts.cwd, "--tsconfig", opts.tsconfig],
76
- { encoding: "utf8", maxBuffer: 1024 * 1024 * 1024 },
77
- );
73
+ // The dump goes to a file rather than a pipe, so no output ceiling applies.
74
+ const capture = captureProcessOutput();
75
+ let dump;
76
+ let dumpStdout: string;
77
+ let dumpStderr: string;
78
+ try {
79
+ dump = spawnSync(
80
+ binary,
81
+ ["dump", "--cwd", opts.cwd, "--tsconfig", opts.tsconfig],
82
+ {
83
+ stdio: ["ignore", capture.stdoutFd, capture.stderrFd],
84
+ windowsHide: true,
85
+ },
86
+ );
87
+ dumpStdout = capture.read("stdout");
88
+ dumpStderr = capture.read("stderr");
89
+ } finally {
90
+ capture.dispose();
91
+ }
78
92
  if (dump.error) {
79
93
  process.stderr.write(`@ttsc/graph: ${dump.error.message}\n`);
80
94
  return 1;
@@ -86,7 +100,7 @@ export function runView(argv: readonly string[]): number | void {
86
100
 
87
101
  let raw: ReturnType<typeof parseDump>;
88
102
  try {
89
- raw = parseDump(dump.stdout);
103
+ raw = parseDump(dumpStdout);
90
104
  } catch (error) {
91
105
  const message = error instanceof Error ? error.message : String(error);
92
106
  process.stderr.write(