@ttsc/graph 0.16.6 → 0.16.8

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 (59) hide show
  1. package/README.md +45 -25
  2. package/lib/TtscGraphApplication.js +39 -16
  3. package/lib/TtscGraphApplication.js.map +1 -1
  4. package/lib/model/TtscGraphMemory.js +43 -4
  5. package/lib/model/TtscGraphMemory.js.map +1 -1
  6. package/lib/model/loadGraph.js +74 -90
  7. package/lib/model/loadGraph.js.map +1 -1
  8. package/lib/reduce.js +34 -3
  9. package/lib/reduce.js.map +1 -1
  10. package/lib/server/createServer.js +650 -247
  11. package/lib/server/createServer.js.map +1 -1
  12. package/lib/server/pathPolicy.js +35 -0
  13. package/lib/server/pathPolicy.js.map +1 -0
  14. package/lib/server/resultGuide.js +16 -0
  15. package/lib/server/resultGuide.js.map +1 -0
  16. package/lib/server/runDetails.js +71 -10
  17. package/lib/server/runDetails.js.map +1 -1
  18. package/lib/server/runEntrypoints.js +3 -4
  19. package/lib/server/runEntrypoints.js.map +1 -1
  20. package/lib/server/runLookup.js +21 -9
  21. package/lib/server/runLookup.js.map +1 -1
  22. package/lib/server/runOverview.js +13 -6
  23. package/lib/server/runOverview.js.map +1 -1
  24. package/lib/server/runTour.js +737 -0
  25. package/lib/server/runTour.js.map +1 -0
  26. package/lib/server/runTrace.js +108 -22
  27. package/lib/server/runTrace.js.map +1 -1
  28. package/lib/structures/ITtscGraphNext.js +3 -0
  29. package/lib/structures/ITtscGraphNext.js.map +1 -0
  30. package/lib/structures/ITtscGraphTour.js +3 -0
  31. package/lib/structures/ITtscGraphTour.js.map +1 -0
  32. package/lib/structures/index.js +2 -0
  33. package/lib/structures/index.js.map +1 -1
  34. package/package.json +3 -8
  35. package/src/TtscGraphApplication.ts +49 -16
  36. package/src/model/TtscGraphMemory.ts +46 -4
  37. package/src/reduce.ts +37 -5
  38. package/src/server/createServer.ts +7 -2
  39. package/src/server/pathPolicy.ts +43 -0
  40. package/src/server/resultGuide.ts +20 -0
  41. package/src/server/runDetails.ts +90 -6
  42. package/src/server/runEntrypoints.ts +9 -4
  43. package/src/server/runLookup.ts +33 -6
  44. package/src/server/runOverview.ts +24 -8
  45. package/src/server/runTour.ts +881 -0
  46. package/src/server/runTrace.ts +151 -23
  47. package/src/structures/ITtscGraphApplication.ts +126 -57
  48. package/src/structures/ITtscGraphDetails.ts +74 -11
  49. package/src/structures/ITtscGraphEntrypoints.ts +46 -15
  50. package/src/structures/ITtscGraphEscape.ts +19 -9
  51. package/src/structures/ITtscGraphLookup.ts +36 -15
  52. package/src/structures/ITtscGraphNext.ts +23 -0
  53. package/src/structures/ITtscGraphOverview.ts +20 -5
  54. package/src/structures/ITtscGraphTour.ts +150 -0
  55. package/src/structures/ITtscGraphTrace.ts +58 -21
  56. package/src/structures/index.ts +2 -0
  57. package/lib/server/instructions.js +0 -80
  58. package/lib/server/instructions.js.map +0 -1
  59. package/src/server/instructions.ts +0 -76
@@ -0,0 +1,150 @@
1
+ import { ITtscGraphDecorator } from "./ITtscGraphDecorator";
2
+ import { ITtscGraphNext } from "./ITtscGraphNext";
3
+
4
+ /** Answer-ready, source-free tour evidence for broad code-flow questions. */
5
+ export interface ITtscGraphTour {
6
+ /** Discriminator for code-tour indexing. */
7
+ type: "tour";
8
+
9
+ /** Natural code question this tour was built for. */
10
+ query: string;
11
+
12
+ /** Central entrypoints selected for the tour. */
13
+ entrypoints: ITtscGraphTour.INode[];
14
+
15
+ /** Selected primary runtime flows; sufficient for an index-level tour. */
16
+ primaryFlow: ITtscGraphTour.IFlow[];
17
+
18
+ /** Nearby dependency anchors around the selected entrypoints. */
19
+ nearby: ITtscGraphTour.IAnchor[];
20
+
21
+ /** Test or usage anchors reached through graph impact edges. */
22
+ tests: ITtscGraphTour.IAnchor[];
23
+
24
+ /** Ordered file/line anchors to cite in the final answer, not file reads. */
25
+ answerAnchors: ITtscGraphTour.IAnchor[];
26
+
27
+ /** How to use this source-free result next. */
28
+ next: ITtscGraphNext;
29
+
30
+ /** Human-readable compatibility note mirroring `next`. */
31
+ guide: string;
32
+
33
+ /** True when any internal slice hit its cap. */
34
+ truncated?: boolean;
35
+ }
36
+
37
+ export namespace ITtscGraphTour {
38
+ /**
39
+ * Build the complete index-level answer surface for broad code tours: central
40
+ * entrypoints, primary flow, nearby paths, tests, and answer anchors. Use
41
+ * this instead of decomposing repository-orientation, read-next,
42
+ * architecture, or multi-phase runtime-flow questions into many
43
+ * lookup/details/trace calls.
44
+ */
45
+ export interface IRequest {
46
+ /** Discriminator for code-tour indexing. */
47
+ type: "tour";
48
+
49
+ /** The user's natural code-tour question. */
50
+ query: string;
51
+
52
+ /**
53
+ * Maximum central entrypoints to seed the tour.
54
+ *
55
+ * Prefer the default. Raise only when the question names several distinct
56
+ * public paths that must all appear in one answer.
57
+ *
58
+ * @default 4
59
+ */
60
+ limit?: number;
61
+
62
+ /**
63
+ * Include graph-reached test or usage anchors when available.
64
+ *
65
+ * @default true
66
+ */
67
+ includeTests?: boolean;
68
+ }
69
+
70
+ /** A compact symbol coordinate for a tour. */
71
+ export interface INode {
72
+ /** Stable node id for later graph calls. */
73
+ id: string;
74
+
75
+ /** Qualified symbol name when available, otherwise the simple name. */
76
+ name: string;
77
+
78
+ /** Declaration kind (`class`, `method`, `function`, ...). */
79
+ kind: string;
80
+
81
+ /** Project-relative declaration file. */
82
+ file: string;
83
+
84
+ /** 1-based declaration line, when known. */
85
+ line?: number;
86
+
87
+ /** Declaration or implementation range, when known. */
88
+ sourceSpan?: ITtscGraphTour.ISpan;
89
+
90
+ /** Declaration head, when available. */
91
+ signature?: string;
92
+
93
+ /** Decorators written on the declaration, when any. */
94
+ decorators?: ITtscGraphDecorator[];
95
+ }
96
+
97
+ /** A primary flow slice from one selected entrypoint. */
98
+ export interface IFlow {
99
+ /** Flow start node. */
100
+ start: ITtscGraphTour.INode;
101
+
102
+ /** Compact edge summaries in graph order. */
103
+ steps: string[];
104
+
105
+ /** Nodes reached by this flow. */
106
+ reached: ITtscGraphTour.INode[];
107
+
108
+ /** Edge and node anchors that explain the flow. */
109
+ anchors: ITtscGraphTour.IAnchor[];
110
+
111
+ /** True when the flow hit graph caps. */
112
+ truncated?: boolean;
113
+ }
114
+
115
+ /** A file/line citation chosen by the graph, not source body text. */
116
+ export interface IAnchor {
117
+ /** Why this anchor matters in the tour. */
118
+ reason: string;
119
+
120
+ /** Stable node id when the anchor belongs to a node. */
121
+ id?: string;
122
+
123
+ /** Symbol, edge, or test name to show in the answer. */
124
+ name: string;
125
+
126
+ /** Declaration kind, when this anchor belongs to a node. */
127
+ kind?: string;
128
+
129
+ /** Project-relative file. */
130
+ file: string;
131
+
132
+ /** 1-based start line. */
133
+ startLine: number;
134
+
135
+ /** 1-based end line, when known. */
136
+ endLine?: number;
137
+ }
138
+
139
+ /** Source coordinates without source text. */
140
+ export interface ISpan {
141
+ /** Project-relative file. */
142
+ file: string;
143
+
144
+ /** 1-based start line. */
145
+ startLine: number;
146
+
147
+ /** 1-based end line, when known. */
148
+ endLine?: number;
149
+ }
150
+ }
@@ -1,6 +1,7 @@
1
1
  import { ITtscGraphEvidence } from "./ITtscGraphEvidence";
2
+ import { ITtscGraphNext } from "./ITtscGraphNext";
2
3
 
3
- /** The ordered dependency flow returned from a start symbol. */
4
+ /** The compact dependency or caller flow returned from a selected start symbol. */
4
5
  export interface ITtscGraphTrace {
5
6
  /** Discriminator for dependency tracing. */
6
7
  type: "trace";
@@ -8,6 +9,7 @@ export interface ITtscGraphTrace {
8
9
  /** The resolved start node, or undefined when `from` matched nothing. */
9
10
  start?: ITtscGraphTrace.INode;
10
11
 
12
+ /** Trace direction actually used by this result. */
11
13
  direction: string;
12
14
 
13
15
  /** Edges traversed, in breadth-first order. */
@@ -32,8 +34,11 @@ export interface ITtscGraphTrace {
32
34
  /** Compact hop summaries preserving node names and edge evidence, capped. */
33
35
  steps?: string[];
34
36
 
35
- /** Follow-up handles for inspecting or continuing the trace. */
36
- next?: ITtscGraphTrace.INext;
37
+ /** How to use this source-free result next. */
38
+ next: ITtscGraphNext;
39
+
40
+ /** Human-readable compatibility note mirroring `next`. */
41
+ guide: string;
37
42
 
38
43
  /** When `from` was an ambiguous name, the matches to disambiguate with. */
39
44
  candidates?: ITtscGraphTrace.INode[];
@@ -55,14 +60,16 @@ export namespace ITtscGraphTrace {
55
60
  * A target symbol: node id, simple symbol name, or dotted member name. When
56
61
  * given, the tool returns the dependency path from `from` to this target,
57
62
  * the one-call answer for "how does A reach B", instead of an open-ended
58
- * trace.
63
+ * trace. Prefer this path mode whenever both ends are known.
59
64
  */
60
65
  to?: string;
61
66
 
62
67
  /**
63
68
  * `forward` follows what the start uses (callees, instantiations, renders);
64
69
  * `reverse` follows what uses the start (callers); `impact` is a reverse
65
- * trace that flags the public API and tests a change would reach.
70
+ * trace that prioritizes public API and test nodes a change would reach.
71
+ * Its test nodes are semantic usage edges, not a text-search inventory.
72
+ * Caller questions usually fit `reverse`.
66
73
  *
67
74
  * @default "forward"
68
75
  */
@@ -71,15 +78,19 @@ export namespace ITtscGraphTrace {
71
78
  /**
72
79
  * Which non-structural edge family to follow: `execution` follows runtime
73
80
  * calls, instantiations, property access, and JSX renders; `types` follows
74
- * type references and inheritance; `all` preserves the full graph.
81
+ * type references and inheritance; `all` preserves the full graph. Flow
82
+ * questions should usually choose `execution` rather than `all`.
75
83
  *
76
84
  * @default "all"
77
85
  */
78
86
  focus?: "all" | "execution" | "types";
79
87
 
80
88
  /**
81
- * How many hops deep to follow. Open traces are capped at 2; path mode is
82
- * capped at 12.
89
+ * How many hops deep to follow. Open forward/reverse traces are capped at
90
+ * 2; impact traces at 4; path mode at 12.
91
+ *
92
+ * Prefer the default for open traces. Raise only for path mode or when the
93
+ * previous trace named the missing next hop.
83
94
  *
84
95
  * @default 2
85
96
  */
@@ -87,27 +98,45 @@ export namespace ITtscGraphTrace {
87
98
 
88
99
  /**
89
100
  * Cap on reached nodes; the trace stops and marks itself truncated past it.
90
- * Open traces are capped at 10 nodes so a broad graph cannot flood
91
- * context.
101
+ * Open forward/reverse traces are capped at 8 nodes, impact at 16 nodes.
102
+ *
103
+ * Prefer the default; use larger open traces only when a named missing edge
104
+ * requires it.
92
105
  *
93
106
  * @default 6
94
107
  */
95
108
  maxNodes?: number;
109
+
110
+ /**
111
+ * Include dependency-boundary nodes from node_modules or bundled `.d.ts`
112
+ * libraries. Leave false for source-flow tours; enable only when the user
113
+ * asks about external type/API boundaries.
114
+ *
115
+ * @default false
116
+ */
117
+ includeExternal?: boolean;
96
118
  }
97
119
 
98
120
  /** One traversed edge, with its depth from the start. */
99
121
  export interface IHop {
122
+ /** Source node id for this traversed edge. */
100
123
  from: string;
124
+
125
+ /** Target node id for this traversed edge. */
101
126
  to: string;
127
+
128
+ /** Edge kind (`calls`, `type_ref`, `accesses`, ...). */
102
129
  kind: string;
130
+
103
131
  /** Hops from the start (1 = direct). */
104
132
  depth: number;
133
+
105
134
  /**
106
- * Source span for the expression that produced this hop. It lets an agent
107
- * explain why the trace moves from one symbol to the next without opening
108
- * the file.
135
+ * Source span for the expression that produced this hop. It is repository
136
+ * evidence for the hop and can be cited without opening the file.
109
137
  */
110
138
  evidence?: ITtscGraphEvidence;
139
+
111
140
  /**
112
141
  * Stable access-path aliases derived from edge evidence. These preserve a
113
142
  * resolved member's owner and the concrete property path used at the call
@@ -118,23 +147,31 @@ export namespace ITtscGraphTrace {
118
147
 
119
148
  /** A node on the trace: the start, a reached node, or a candidate. */
120
149
  export interface INode {
150
+ /** Stable node id for subsequent graph calls. */
121
151
  id: string;
152
+
153
+ /** Qualified symbol name when available, otherwise the simple name. */
122
154
  name: string;
155
+
156
+ /** Declaration kind (`class`, `method`, `function`, ...). */
123
157
  kind: string;
158
+
159
+ /** Project-relative path of the declaration file. */
124
160
  file: string;
161
+
162
+ /** 1-based declaration line, when known. */
163
+ line?: number;
164
+
165
+ /** Declaration or implementation citation range, when known. */
166
+ sourceSpan?: Pick<ITtscGraphEvidence, "file" | "startLine" | "endLine">;
167
+
125
168
  /** Hops from the start, on a reached node. */
126
169
  depth?: number;
170
+
127
171
  /** The node's signature, carried on path nodes so the path explains itself. */
128
172
  signature?: string;
173
+
129
174
  /** Why this node matters to an impact trace: `exported`, `test`. */
130
175
  roles?: string[];
131
176
  }
132
-
133
- /** Tool-call handles suggested by this trace. */
134
- export interface INext {
135
- /** Pass these ids to `details` for selected symbol details. */
136
- details: string[];
137
- /** Continue tracing from these ids when the current result is intermediate. */
138
- traceFrom: string[];
139
- }
140
177
  }
@@ -16,7 +16,9 @@ export * from "./ITtscGraphEntrypoints";
16
16
  export * from "./ITtscGraphNode";
17
17
  export * from "./ITtscGraphOverview";
18
18
  export * from "./ITtscGraphLookup";
19
+ export * from "./ITtscGraphNext";
19
20
  export * from "./ITtscGraphTrace";
21
+ export * from "./ITtscGraphTour";
20
22
  export * from "./TtscGraphEdgeKind";
21
23
  export * from "./TtscGraphNodeKind";
22
24
  export * from "./TtscGraphNodeModifier";
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instructions = void 0;
4
- /**
5
- * The guidance delivered in the MCP initialize response. It is the only place
6
- * the agent is told how to use the graph; nothing is written to its config
7
- * files. Keep it short; the per-tool descriptions carry the detail.
8
- */
9
- exports.instructions = `
10
- Before answering a TypeScript codebase question, call query. It is the
11
- code-evidence path:
12
- symbols, dependency paths, edge evidence ranges, and sourceSpan line anchors
13
- from the resident project graph. Do not answer from assumptions, ls, rg, cat,
14
- or Get-Content when graph evidence can answer the code question.
15
-
16
- The graph is a resident TypeScript fact map, not an answer writer. Fill
17
- arguments in order: question, graphNeed, draft, review, request. Write
18
- draft.reason before draft.type, review it for overfetch and non-graph fallback,
19
- then choose one final request.type:
20
- entrypoints, lookup, trace, details, overview, or escape. If the review shows the
21
- question is about scripts, config, generated output, prose docs, or evidence
22
- already in hand, choose escape instead of spending a graph
23
- operation. If more TypeScript evidence is needed, make another graph request
24
- instead of switching to shell search.
25
-
26
- Budget graph calls before the first request. Most answers need 1-3 calls, and
27
- four calls is the hard stop for one answer. A fifth graph call means the tool is
28
- being used as a source reader; answer from returned handles/ranges or choose
29
- escape and report the missing span.
30
-
31
- For behavior, lifecycle, request-flow, rendering-flow, or validation-flow
32
- questions, start with one default entrypoints call, then one trace from the best
33
- handle, then answer. Use overview only for broad architecture or public API
34
- orientation.
35
-
36
- The graph already knows resolved symbols, dependency edges, evidence spans,
37
- decorators, stable handles, and sourceSpan line anchors. Use returned ranges and
38
- handles as the evidence. If implementation text is required to decide a detail,
39
- report the gap and the smallest sourceSpan instead of opening files during the
40
- graph answer.
41
-
42
- For caller or call-site questions, do not use rg. Use trace with direction:
43
- "reverse" or details with neighbors: true; both return edge evidence and line
44
- anchors for the call expression.
45
-
46
- Request types:
47
-
48
- - entrypoints: compact shortlist for behavior-specific code questions. It returns
49
- ranked symbols, direct mentions, and small dependency orientation without
50
- implementation text. Do not use it as the first broad public API map.
51
- - lookup: targeted symbol search for a class, method, function, property, or
52
- type when you do not already have its handle.
53
- - trace: call/type/dependency flow for "how A reaches B", lifecycle,
54
- request-flow, rendering-flow, validation-flow, and impact questions.
55
- - details: signatures, members, direct calls, direct types, dependency
56
- neighbors, and sourceSpan anchors for selected handles.
57
- - overview: source-free architecture map for layers, hotspots, counts, and
58
- public API. Use it to choose a central exported TypeScript API or entry point
59
- without reading package scripts.
60
- - escape: no-op route when the review decides this tool was the wrong evidence
61
- source or the previous graph result is enough.
62
-
63
- For a flow question, use entrypoints once, then trace before details. Keep
64
- dependency maps compact: default limits first, one to three handles in details,
65
- and no larger limits unless the previous result was truncated and the missing
66
- piece is named. Do not spend graph calls only to find tests; mention tests only
67
- when the returned graph slice already exposes them. Stop once file/symbol/range
68
- evidence is enough to answer.
69
-
70
- Copy exact names from returned nodes, references, aliases, evidence ranges,
71
- sourceSpan anchors, and trace steps. Do not use shell to recover TypeScript line
72
- numbers, call targets, or branch details not already returned by graph evidence;
73
- name the missing detail and give the returned range.
74
-
75
- Package scripts, config files, generated output, prose documentation, and exact
76
- text searches are separate evidence sources. Use them only when the user asks
77
- about those sources directly; do not use them to answer a TypeScript API or
78
- call-path question.
79
- `.trim();
80
- //# sourceMappingURL=instructions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/server/instructions.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACU,QAAA,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsE3B,CAAC,IAAI,EAAE,CAAC"}
@@ -1,76 +0,0 @@
1
- /**
2
- * The guidance delivered in the MCP initialize response. It is the only place
3
- * the agent is told how to use the graph; nothing is written to its config
4
- * files. Keep it short; the per-tool descriptions carry the detail.
5
- */
6
- export const instructions = `
7
- Before answering a TypeScript codebase question, call query. It is the
8
- code-evidence path:
9
- symbols, dependency paths, edge evidence ranges, and sourceSpan line anchors
10
- from the resident project graph. Do not answer from assumptions, ls, rg, cat,
11
- or Get-Content when graph evidence can answer the code question.
12
-
13
- The graph is a resident TypeScript fact map, not an answer writer. Fill
14
- arguments in order: question, graphNeed, draft, review, request. Write
15
- draft.reason before draft.type, review it for overfetch and non-graph fallback,
16
- then choose one final request.type:
17
- entrypoints, lookup, trace, details, overview, or escape. If the review shows the
18
- question is about scripts, config, generated output, prose docs, or evidence
19
- already in hand, choose escape instead of spending a graph
20
- operation. If more TypeScript evidence is needed, make another graph request
21
- instead of switching to shell search.
22
-
23
- Budget graph calls before the first request. Most answers need 1-3 calls, and
24
- four calls is the hard stop for one answer. A fifth graph call means the tool is
25
- being used as a source reader; answer from returned handles/ranges or choose
26
- escape and report the missing span.
27
-
28
- For behavior, lifecycle, request-flow, rendering-flow, or validation-flow
29
- questions, start with one default entrypoints call, then one trace from the best
30
- handle, then answer. Use overview only for broad architecture or public API
31
- orientation.
32
-
33
- The graph already knows resolved symbols, dependency edges, evidence spans,
34
- decorators, stable handles, and sourceSpan line anchors. Use returned ranges and
35
- handles as the evidence. If implementation text is required to decide a detail,
36
- report the gap and the smallest sourceSpan instead of opening files during the
37
- graph answer.
38
-
39
- For caller or call-site questions, do not use rg. Use trace with direction:
40
- "reverse" or details with neighbors: true; both return edge evidence and line
41
- anchors for the call expression.
42
-
43
- Request types:
44
-
45
- - entrypoints: compact shortlist for behavior-specific code questions. It returns
46
- ranked symbols, direct mentions, and small dependency orientation without
47
- implementation text. Do not use it as the first broad public API map.
48
- - lookup: targeted symbol search for a class, method, function, property, or
49
- type when you do not already have its handle.
50
- - trace: call/type/dependency flow for "how A reaches B", lifecycle,
51
- request-flow, rendering-flow, validation-flow, and impact questions.
52
- - details: signatures, members, direct calls, direct types, dependency
53
- neighbors, and sourceSpan anchors for selected handles.
54
- - overview: source-free architecture map for layers, hotspots, counts, and
55
- public API. Use it to choose a central exported TypeScript API or entry point
56
- without reading package scripts.
57
- - escape: no-op route when the review decides this tool was the wrong evidence
58
- source or the previous graph result is enough.
59
-
60
- For a flow question, use entrypoints once, then trace before details. Keep
61
- dependency maps compact: default limits first, one to three handles in details,
62
- and no larger limits unless the previous result was truncated and the missing
63
- piece is named. Do not spend graph calls only to find tests; mention tests only
64
- when the returned graph slice already exposes them. Stop once file/symbol/range
65
- evidence is enough to answer.
66
-
67
- Copy exact names from returned nodes, references, aliases, evidence ranges,
68
- sourceSpan anchors, and trace steps. Do not use shell to recover TypeScript line
69
- numbers, call targets, or branch details not already returned by graph evidence;
70
- name the missing detail and give the returned range.
71
-
72
- Package scripts, config files, generated output, prose documentation, and exact
73
- text searches are separate evidence sources. Use them only when the user asks
74
- about those sources directly; do not use them to answer a TypeScript API or
75
- call-path question.
76
- `.trim();