@ttsc/graph 0.18.3 → 0.19.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 (125) hide show
  1. package/README.md +231 -36
  2. package/lib/TtscGraphApplication.d.ts +4 -3
  3. package/lib/TtscGraphApplication.js +54 -19
  4. package/lib/TtscGraphApplication.js.map +1 -1
  5. package/lib/index.d.ts +9 -4
  6. package/lib/index.js +24 -5
  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.d.ts +36 -0
  11. package/lib/model/TtscGraphSession.js +457 -0
  12. package/lib/model/TtscGraphSession.js.map +1 -0
  13. package/lib/model/loadGraph.d.ts +3 -3
  14. package/lib/model/loadGraph.js +94 -141
  15. package/lib/model/loadGraph.js.map +1 -1
  16. package/lib/resolveGraphBinary.d.ts +4 -2
  17. package/lib/resolveGraphBinary.js +7 -3
  18. package/lib/resolveGraphBinary.js.map +1 -1
  19. package/lib/server/createServer.d.ts +16 -9
  20. package/lib/server/createServer.js +286 -190
  21. package/lib/server/createServer.js.map +1 -1
  22. package/lib/server/exportSurface.d.ts +26 -0
  23. package/lib/server/exportSurface.js +44 -0
  24. package/lib/server/exportSurface.js.map +1 -0
  25. package/lib/server/resolveHandle.d.ts +26 -1
  26. package/lib/server/resolveHandle.js +124 -4
  27. package/lib/server/resolveHandle.js.map +1 -1
  28. package/lib/server/resultAudit.d.ts +74 -0
  29. package/lib/server/resultAudit.js +110 -0
  30. package/lib/server/resultAudit.js.map +1 -0
  31. package/lib/server/resultNext.d.ts +9 -0
  32. package/lib/server/resultNext.js +11 -0
  33. package/lib/server/resultNext.js.map +1 -0
  34. package/lib/server/runDetails.d.ts +15 -3
  35. package/lib/server/runDetails.js +105 -23
  36. package/lib/server/runDetails.js.map +1 -1
  37. package/lib/server/runEntrypoints.d.ts +2 -1
  38. package/lib/server/runEntrypoints.js +17 -10
  39. package/lib/server/runEntrypoints.js.map +1 -1
  40. package/lib/server/runLookup.d.ts +2 -1
  41. package/lib/server/runLookup.js +21 -9
  42. package/lib/server/runLookup.js.map +1 -1
  43. package/lib/server/runOverview.d.ts +2 -1
  44. package/lib/server/runOverview.js +5 -4
  45. package/lib/server/runOverview.js.map +1 -1
  46. package/lib/server/runTour.d.ts +2 -1
  47. package/lib/server/runTour.js +707 -331
  48. package/lib/server/runTour.js.map +1 -1
  49. package/lib/server/runTrace.d.ts +2 -1
  50. package/lib/server/runTrace.js +234 -54
  51. package/lib/server/runTrace.js.map +1 -1
  52. package/lib/server/startServer.d.ts +3 -2
  53. package/lib/server/startServer.js +13 -7
  54. package/lib/server/startServer.js.map +1 -1
  55. package/lib/structures/ITtscGraphApplication.d.ts +122 -114
  56. package/lib/structures/ITtscGraphDecorator.d.ts +4 -7
  57. package/lib/structures/ITtscGraphDetails.d.ts +51 -43
  58. package/lib/structures/ITtscGraphDump.d.ts +36 -11
  59. package/lib/structures/ITtscGraphEdge.d.ts +4 -6
  60. package/lib/structures/ITtscGraphEntrypoints.d.ts +10 -27
  61. package/lib/structures/ITtscGraphEscape.d.ts +6 -16
  62. package/lib/structures/ITtscGraphEvidence.d.ts +5 -8
  63. package/lib/structures/ITtscGraphLookup.d.ts +9 -20
  64. package/lib/structures/ITtscGraphNext.d.ts +10 -7
  65. package/lib/structures/ITtscGraphNode.d.ts +17 -8
  66. package/lib/structures/ITtscGraphOverview.d.ts +10 -14
  67. package/lib/structures/ITtscGraphSpan.d.ts +29 -0
  68. package/lib/structures/{ITtscGraphDiagnostic.js → ITtscGraphSpan.js} +1 -1
  69. package/lib/structures/ITtscGraphSpan.js.map +1 -0
  70. package/lib/structures/ITtscGraphTour.d.ts +65 -23
  71. package/lib/structures/ITtscGraphTrace.d.ts +72 -49
  72. package/lib/structures/TtscGraphEdgeKind.d.ts +7 -1
  73. package/lib/structures/index.d.ts +1 -1
  74. package/lib/structures/index.js +1 -1
  75. package/lib/structures/index.js.map +1 -1
  76. package/lib/view.js +3 -1
  77. package/lib/view.js.map +1 -1
  78. package/package.json +4 -4
  79. package/src/TtscGraphApplication.ts +66 -31
  80. package/src/index.ts +23 -5
  81. package/src/model/TtscGraphMemory.ts +86 -22
  82. package/src/model/TtscGraphSession.ts +204 -0
  83. package/src/model/loadGraph.ts +6 -4
  84. package/src/resolveGraphBinary.ts +7 -3
  85. package/src/server/createServer.ts +24 -17
  86. package/src/server/exportSurface.ts +40 -0
  87. package/src/server/resolveHandle.ts +141 -4
  88. package/src/server/resultAudit.ts +109 -0
  89. package/src/server/resultNext.ts +22 -0
  90. package/src/server/runDetails.ts +112 -28
  91. package/src/server/runEntrypoints.ts +26 -17
  92. package/src/server/runLookup.ts +29 -18
  93. package/src/server/runOverview.ts +9 -10
  94. package/src/server/runTour.ts +764 -363
  95. package/src/server/runTrace.ts +265 -71
  96. package/src/server/startServer.ts +13 -8
  97. package/src/structures/ITtscGraphApplication.ts +124 -114
  98. package/src/structures/ITtscGraphDecorator.ts +4 -7
  99. package/src/structures/ITtscGraphDetails.ts +60 -46
  100. package/src/structures/ITtscGraphDump.ts +41 -11
  101. package/src/structures/ITtscGraphEdge.ts +4 -6
  102. package/src/structures/ITtscGraphEntrypoints.ts +10 -30
  103. package/src/structures/ITtscGraphEscape.ts +6 -19
  104. package/src/structures/ITtscGraphEvidence.ts +5 -8
  105. package/src/structures/ITtscGraphLookup.ts +9 -22
  106. package/src/structures/ITtscGraphNext.ts +10 -7
  107. package/src/structures/ITtscGraphNode.ts +18 -8
  108. package/src/structures/ITtscGraphOverview.ts +10 -17
  109. package/src/structures/ITtscGraphSpan.ts +33 -0
  110. package/src/structures/ITtscGraphTour.ts +70 -28
  111. package/src/structures/ITtscGraphTrace.ts +82 -51
  112. package/src/structures/TtscGraphEdgeKind.ts +7 -0
  113. package/src/structures/index.ts +1 -1
  114. package/src/view.ts +3 -1
  115. package/lib/server/accessAliases.d.ts +0 -8
  116. package/lib/server/accessAliases.js +0 -53
  117. package/lib/server/accessAliases.js.map +0 -1
  118. package/lib/server/resultGuide.d.ts +0 -3
  119. package/lib/server/resultGuide.js +0 -16
  120. package/lib/server/resultGuide.js.map +0 -1
  121. package/lib/structures/ITtscGraphDiagnostic.d.ts +0 -27
  122. package/lib/structures/ITtscGraphDiagnostic.js.map +0 -1
  123. package/src/server/accessAliases.ts +0 -55
  124. package/src/server/resultGuide.ts +0 -20
  125. package/src/structures/ITtscGraphDiagnostic.ts +0 -34
@@ -2,20 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.startServer = startServer;
4
4
  const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
5
- const loadGraph_1 = require("../model/loadGraph");
5
+ const TtscGraphSession_1 = require("../model/TtscGraphSession");
6
6
  const createServer_1 = require("./createServer");
7
7
  /**
8
8
  * Serve the graph tools over MCP on stdio. The server answers the MCP handshake
9
- * immediately and builds the resident graph on the first tool call, so a large
10
- * project cannot make the client give up before tools are advertised.
9
+ * immediately and opens the resident incremental graph session on the first
10
+ * real tool call, so a large project cannot make the client give up before
11
+ * tools are advertised and an escape request still performs no graph work.
11
12
  */
12
13
  async function startServer(options) {
13
- let graph;
14
- const server = (0, createServer_1.createServer)(() => {
15
- graph ??= (0, loadGraph_1.loadGraph)({ cwd: options.cwd, tsconfig: options.tsconfig });
16
- return graph;
14
+ const cwd = options.cwd ?? process.cwd();
15
+ const tsconfig = options.tsconfig ?? "tsconfig.json";
16
+ let session;
17
+ const server = (0, createServer_1.createServer)(async () => {
18
+ session ??= new TtscGraphSession_1.TtscGraphSession({ cwd, tsconfig });
19
+ return session.graph();
17
20
  }, options.version);
18
21
  const transport = new stdio_js_1.StdioServerTransport();
22
+ const closeSession = () => session?.close();
23
+ transport.onclose = closeSession;
24
+ process.stdin.once("end", closeSession);
19
25
  await server.connect(transport);
20
26
  }
21
27
  //# sourceMappingURL=startServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/server/startServer.ts"],"names":[],"mappings":";;;AAAA,wEAAiF;AAGjF,kDAA+C;AAC/C,iDAA8C;AAE9C;;;;GAIG;AACI,KAAK,sBAAsB,OAKjC;IACC,IAAI,KAAkC,CAAC;IACvC,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,GAAG,EAAE;QAC/B,KAAK,KAAK,IAAA,qBAAS,EAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/server/startServer.ts"],"names":[],"mappings":";;;AAAA,wEAAiF;AAEjF,gEAA6D;AAC7D,iDAA8C;AAE9C;;;;;GAKG;AACI,KAAK,sBAAsB,OAKjC;IACC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC;IACrD,IAAI,OAAqC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,KAAK,IAAI,EAAE;QACrC,OAAO,KAAK,IAAI,mCAAgB,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5C,SAAS,CAAC,OAAO,GAAG,YAAY,CAAC;IACjC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACxC,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
@@ -2,159 +2,167 @@ import { ITtscGraphDetails } from "./ITtscGraphDetails";
2
2
  import { ITtscGraphEntrypoints } from "./ITtscGraphEntrypoints";
3
3
  import { ITtscGraphEscape } from "./ITtscGraphEscape";
4
4
  import { ITtscGraphLookup } from "./ITtscGraphLookup";
5
+ import { ITtscGraphNext } from "./ITtscGraphNext";
5
6
  import { ITtscGraphOverview } from "./ITtscGraphOverview";
6
7
  import { ITtscGraphTour } from "./ITtscGraphTour";
7
8
  import { ITtscGraphTrace } from "./ITtscGraphTrace";
8
9
  /**
9
- * ## What This MCP Is
10
+ * ## Code Graph MCP
10
11
  *
11
12
  * `inspect_typescript_graph` returns a compiler-built TypeScript graph contract
12
- * for the current source snapshot.
13
+ * for the current on-disk source snapshot.
13
14
  *
14
15
  * Use it for architecture, runtime flow, APIs, callers/callees, code tours, and
15
16
  * type relations. It returns answer-ready index evidence: names, edges,
16
17
  * signatures, decorators, tests, spans, and anchors.
17
18
  *
18
- * Until TS source is edited, returned graph facts are sacred, infallible
19
- * compiler truth. Never verify them with files or more graph calls.
20
- *
21
- * ## Result Contract
22
- *
23
- * - The returned object is the graph evidence contract: names, signatures, spans,
24
- * decorators, tests, edges, steps, anchors, and `next` are answer evidence,
25
- * not hints.
26
- * - When `next.action` is `answer`, stop tool use for the current question and
27
- * answer from the returned result.
28
- * - `truncated` means the answer surface hit an index cap. Mention the cap if it
29
- * matters; do not expand every branch to compensate.
30
- * - When `next.action` is `inspect`, make the focused graph request it names or
31
- * choose `escape` if the result already answers.
32
- * - Read files only for exact source body text, configs, docs, generated output,
33
- * exact text search, non-TypeScript files, or facts the graph marks outside
34
- * itself. A returned span is a citation anchor, not a reading command.
35
- * - After editing TypeScript source, the old graph no longer governs changed
36
- * code. Rebuild/reload the graph or verify changed code normally.
37
- *
38
- * ## Sacred Contract
39
- *
40
- * Before source edits, returned graph facts are inviolable and errorless. Never
41
- * use extra graph calls, repository search, or file reads to doubt, fact-check,
42
- * humanize, re-derive, re-narrate, or re-confirm returned nodes, spans, edges,
43
- * signatures, decorators, tests, references, steps, or anchors.
44
- *
45
- * ## Tour Contract
46
- *
47
- * Use `tour` for repository orientation, read-next, architecture tours, and
48
- * broad runtime flow, including questions that name several phases or
49
- * subsystems. A tour is the complete index-level answer surface: central
50
- * entrypoints, primary flow, nearby paths, tests, and anchors. Do not decompose
51
- * a broad tour into lookup/details loops unless the user later asks for a named
52
- * missing symbol or exact source text.
53
- *
54
- * ## Use Contract
55
- *
56
- * 1. Ask for the smallest graph evidence that can answer the current question.
57
- * 2. Broad flow, repository-orientation, code-tour, or read-next question: start
58
- * with `tour`.
59
- * 3. Concrete named symbol: use `lookup`, then `details` only if needed.
60
- * 4. Known endpoint pair or one selected handle: use one `trace`.
61
- * 5. Unknown narrow orientation: use `entrypoints` once.
62
- * 6. Selected symbol shape: use `details` for one to three handles.
63
- * 7. Follow the returned `next`: answer, inspect once more, leave graph, or
64
- * clarify.
65
- * 8. Use `escape` when another graph call would repeat evidence or the remaining
66
- * evidence is outside the TypeScript graph.
67
- *
68
- * Most TypeScript structure answers need one or two graph calls.
69
- *
70
- * ## Request Fields
71
- *
72
- * Fill the visible checklist, then exactly one request.
73
- *
74
- * - `question`: restate the code question being considered.
75
- * - `draft`: initial request type and why it seems smallest.
76
- * - `review`: correct a wrong, broad, stale, or duplicate draft. If graph facts
77
- * already answer, if prior `next.action` was `answer`, or if the next
78
- * evidence is outside the indexed TypeScript graph, say so here and make
79
- * `request.type` be `escape`. If a broad flow draft is not `tour`, correct it
80
- * here.
81
- * - `request`: final request after review.
82
- *
83
- * ## How to answer from graph evidence
84
- *
85
- * - Use returned node names, signatures, edges, references, evidence, and
86
- * `sourceSpan` ranges directly.
87
- * - Explain the central path first, then mention important branches.
88
- * - For tests, impact, or reading lists, returned nodes and ranges are the answer
89
- * evidence, not search keywords.
90
- * - A returned range is a sacred citation anchor, not permission to open the
91
- * file.
19
+ * Every returned fact each name, edge, signature, and span is
20
+ * compiler-resolved and verified for the snapshot that call synchronized, so
21
+ * trust it without re-checking against files. Where an operation ranks a
22
+ * shortlist against your question (`lookup`, `entrypoints`, `tour`), the facts
23
+ * stay verified but the selection is heuristic: judge whether its coverage
24
+ * answers you, and a follow-up request or a read of a cited span is fair when
25
+ * it does not.
26
+ *
27
+ * ## Requests
28
+ *
29
+ * A request is a union: pick the single type below that best fits the question,
30
+ * and submit exactly that one.
31
+ *
32
+ * - `tour`: architecture, runtime flow, orientation, or a code tour. One call is
33
+ * the whole answer; do not split it. Name the machinery you expect it to be
34
+ * made of in its `reinterpretations`, or send none.
35
+ * - `entrypoints`: find where execution starts when entry points are unknown.
36
+ * - `lookup`: locate a named symbol.
37
+ * - `trace`: follow calls or data flow forward or backward from a symbol, or —
38
+ * with `to` — the path between two symbols when both ends are known, which is
39
+ * the one call that answers "how does A reach B".
40
+ * - `details`: signatures, members, and relations of named symbols — including
41
+ * the classes that implement an interface, which is the one call that answers
42
+ * "what actually implements this".
43
+ * - `overview`: project layers and folder structure.
44
+ * - `escape`: the answer is outside the graph (source body text, non-TypeScript
45
+ * files, exact search).
46
+ *
47
+ * ## Chain of Thought
48
+ *
49
+ * Fill these fields in order before the call; each one narrows the reasoning
50
+ * toward the single request you submit.
51
+ *
52
+ * - `question`: the code question, in the user's own words.
53
+ * - `draft`: `{ reason, type }` — why the smallest request that could answer it,
54
+ * then that request's `type`.
55
+ * - `review`: fix a broad, stale, or duplicate draft. If the graph already
56
+ * answered, or the evidence is outside it, escape.
57
+ * - `request`: the final choice. Each branch documents its own fields; fill them
58
+ * from what the branch says, not from what another branch wanted.
59
+ *
60
+ * ## What to trust
61
+ *
62
+ * Before source edits, every returned fact is compiler-resolved and verified.
63
+ * Never use extra graph calls, repository search, or file reads to doubt,
64
+ * fact-check, re-derive, re-narrate, or re-confirm a returned node, span, edge,
65
+ * signature, decorator, test, reference, step, or anchor. The server resolved
66
+ * each one to the type-checked program for the snapshot the call synced to, and
67
+ * `audit` says so on every result.
68
+ *
69
+ * Selection is the separate question. `lookup`, `entrypoints`, and `tour` match
70
+ * your question and return a scored, ranked, per-file-capped, limited
71
+ * shortlist; their facts are still verified, but whether the shortlist covers
72
+ * what you asked is yours to judge, and their `audit` says that instead of
73
+ * claiming completeness. A follow-up request or a read of a cited span for
74
+ * missed coverage is legitimate — re-confirming a fact the graph already
75
+ * resolved is not.
76
+ *
77
+ * ## Stop
78
+ *
79
+ * Let the result's `next` set the pace, and do not re-confirm what the graph
80
+ * resolved.
81
+ *
82
+ * - A span is a citation, not a cue to open the file to re-check a fact.
83
+ * - Follow the result's `next`: `answer` means stop and answer from it, `inspect`
84
+ * means make exactly the one request it names, `outside` means escape,
85
+ * `clarify` means restate the request.
86
+ * - For a ranked shortlist (`lookup`, `entrypoints`, `tour`), `next` and
87
+ * `truncated` say whether coverage is settled; when it is not, one more
88
+ * request is the right move not a file read to re-verify facts already
89
+ * given.
92
90
  */
93
91
  export interface ITtscGraphApplication {
94
92
  /**
95
- * Inspect the TypeScript compiler graph contract.
93
+ * Answer a TypeScript question from the compiler's own index of this
94
+ * repository.
95
+ *
96
+ * The graph holds every symbol, call, type, decorator and test, each with its
97
+ * file and line, resolved from the source on disk now. Submit exactly one
98
+ * request:
96
99
  *
97
- * Use this before repository search when an answer depends on TypeScript
98
- * symbols, calls, types, decorators, references, ranges, or runtime/source
99
- * relationships. For repository orientation, read-next, architecture, and
100
- * broad runtime flow questions, use `tour`.
100
+ * - `tour`: architecture, the runtime flow from the public API to the code that
101
+ * does the work, nearby paths, and the tests to read — a whole orientation
102
+ * in one call
103
+ * - `trace`: what a symbol calls, what calls it, or the path from A to B
104
+ * - `details`: signatures, members, and what implements an interface
105
+ * - `lookup`: where a named symbol is declared
106
+ * - `entrypoints`: where execution starts, when the entry is unknown
107
+ * - `overview`: the project's layers and folder structure
101
108
  *
102
- * Returned nodes, edges, signatures, spans, tests, anchors, and `next` are
103
- * the answer surface. If `next.action` is `answer`, stop tool use and answer
104
- * from that result. Before source edits, graph facts are sacred, inviolable,
105
- * complete, and infallible.
109
+ * Every fact in a result is the checker's own resolution, audited before
110
+ * return, so no fact needs verifying; for the ranked operations (`lookup`,
111
+ * `entrypoints`, `tour`), judge whether the shortlist covers your question.
112
+ * Read a file for what the graph does not carry: a body, the text in a span.
106
113
  *
107
114
  * @param props Reasoning plus one graph request
108
115
  * @returns Matching `result` union member
109
116
  */
110
- inspect_typescript_graph(props: ITtscGraphApplication.IProps): ITtscGraphApplication.IResult;
117
+ inspect_typescript_graph(props: ITtscGraphApplication.IProps): Promise<ITtscGraphApplication.IOutput>;
111
118
  }
112
119
  export declare namespace ITtscGraphApplication {
113
120
  /** Draft, review, then submit exactly one graph request or escape. */
114
121
  interface IProps {
115
122
  /**
116
- * User's TypeScript code question.
123
+ * The code question, in the user's own words.
117
124
  *
118
- * Restate the code question being considered. If the next evidence is a
119
- * script, config, doc, generated output, exact text, non-TypeScript file,
120
- * or source body text, choose `escape`.
125
+ * Cut a long message down to the sentences that state the ask, but keep
126
+ * their terms: the graph ranks against these words, so a rewrite ranks a
127
+ * different answer.
121
128
  */
122
129
  question: string;
123
- /**
124
- * Initial request plan before final arguments are filled.
125
- *
126
- * Name the intended request type in `type` and why it seems smallest in
127
- * `reason`. Broad flow, architecture, repository-orientation, and read-next
128
- * questions should normally draft `tour`; narrow named symbols can draft
129
- * `lookup`, `trace`, or `details`.
130
- */
130
+ /** The smallest request that could answer, and why. */
131
131
  draft: IDraft;
132
132
  /**
133
- * Final self-review before calling.
134
- *
135
- * Correct a stale, broad, duplicate, or wrong draft here. If broad flow was
136
- * split into search/detail steps, switch to `tour`. If graph facts already
137
- * answer, or prior `next.action` was `answer`, make `request.type` be
138
- * `escape`; do not call graph or read files to re-confirm returned facts.
133
+ * Correct the draft. Escape if the graph already answered, or the next
134
+ * evidence is outside the graph.
139
135
  */
140
136
  review: string;
141
- /** Final graph operation chosen after review, or a no-op escape. */
137
+ /** Final graph request chosen after review, or a no-op escape. */
142
138
  request: ITtscGraphEntrypoints.IRequest | ITtscGraphLookup.IRequest | ITtscGraphTrace.IRequest | ITtscGraphDetails.IRequest | ITtscGraphOverview.IRequest | ITtscGraphTour.IRequest | ITtscGraphEscape.IRequest;
143
139
  }
144
- /**
145
- * First-pass request plan, filled before the final `request` arguments.
146
- *
147
- * `reason` comes before `type` so the justification is written before the
148
- * choice it justifies.
149
- */
140
+ /** First-pass plan; `reason` precedes `type` so it is written first. */
150
141
  interface IDraft {
151
- /** Why this request type looks like the smallest useful next step. */
142
+ /** Why this is the smallest useful next step. */
152
143
  reason: string;
153
- /** The request type being considered, corrected later in `review`. */
144
+ /** The request type being considered. */
154
145
  type: IProps["request"]["type"];
155
146
  }
156
147
  /** The selected request's output. `result.type` mirrors `request.type`. */
157
- interface IResult {
148
+ interface IOutput {
149
+ /**
150
+ * What the server audited this result against before returning it, in its
151
+ * own words: every node, span, edge, signature, member, and step in it
152
+ * resolves to the type-checked program for the snapshot the call synced to,
153
+ * so opening a file it cites only returns a fact already in it.
154
+ *
155
+ * The audit is operation-aware. For the exact operations (`trace`,
156
+ * `details`, `overview`) it reports the result as the structure the graph
157
+ * holds for the handles named, bounded only where `truncated` says. For the
158
+ * ranked operations (`lookup`, `entrypoints`, `tour`) it adds that the
159
+ * selection is heuristic — matched, scored, ranked, and limited against the
160
+ * question — so the facts are verified but the shortlist's coverage is the
161
+ * caller's to judge.
162
+ */
163
+ audit: string;
164
+ /** What to do with `result`: answer, inspect one named request, or escape. */
165
+ next: ITtscGraphNext;
158
166
  /** Result branch matching the submitted `request.type`. */
159
167
  result: ITtscGraphEntrypoints | ITtscGraphLookup | ITtscGraphTrace | ITtscGraphDetails | ITtscGraphOverview | ITtscGraphTour | ITtscGraphEscape;
160
168
  }
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * A decorator as written on a declaration, carried on the decorated
3
- * {@link ITtscGraphNode}'s `decorators`.
4
- *
5
- * The graph reports the decorator faithfully rather than interpreting any
6
- * framework's convention: the `name` is the decorator as written (`Controller`,
7
- * `Get`, `TypedRoute.Get`, ...), and statically resolvable literal arguments
8
- * are preserved so a consumer can apply its own meaning without re-parsing
9
- * source.
3
+ * {@link ITtscGraphNode}'s `decorators`. Reported faithfully, not interpreted
4
+ * per framework: `name` is the decorator as written (`Controller`, `Get`,
5
+ * `TypedRoute.Get`, ...), and statically resolvable literal arguments are
6
+ * preserved so a consumer applies its own meaning without re-parsing source.
10
7
  */
11
8
  export interface ITtscGraphDecorator {
12
9
  /**
@@ -1,24 +1,27 @@
1
1
  import { ITtscGraphDecorator } from "./ITtscGraphDecorator";
2
2
  import { ITtscGraphEvidence } from "./ITtscGraphEvidence";
3
- import { ITtscGraphNext } from "./ITtscGraphNext";
4
3
  /**
5
- * The source-free facts for a few selected handles.
6
- *
7
- * This is not a file reader. It returns signatures, member outlines, direct
8
- * calls, direct types, implementation candidates, dependency summaries, and
9
- * sourceSpan citation anchors.
4
+ * Source-free facts for a few selected handles, not a file reader: signatures,
5
+ * member outlines, direct calls and types, implementation candidates,
6
+ * dependency summaries, and sourceSpan citation anchors.
10
7
  */
11
8
  export interface ITtscGraphDetails {
12
9
  /** Discriminator for selected symbol inspection. */
13
10
  type: "details";
14
11
  /** Selected node facts, in the same order as resolved handles when possible. */
15
12
  nodes: ITtscGraphDetails.INode[];
16
- /** How to use this source-free result next. */
17
- next: ITtscGraphNext;
18
- /** Human-readable compatibility note mirroring `next`. */
19
- guide: string;
20
- /** Handles that resolved to no node, or that were ambiguous. */
13
+ /** Handles the graph holds no node for. */
21
14
  unknown: string[];
15
+ /**
16
+ * Handles that name more than one node, with the nodes they name.
17
+ *
18
+ * A name the graph knows twice is not a name the graph does not know: two
19
+ * classes called `Workbench` are two facts, and answering "unknown" to a
20
+ * handle the checker resolved twice sends the caller to the files for what is
21
+ * already here. Re-call `details` with the `id` of the one the question
22
+ * means.
23
+ */
24
+ ambiguous?: ITtscGraphDetails.IAmbiguity[];
22
25
  }
23
26
  export declare namespace ITtscGraphDetails {
24
27
  /** Which selected handles to inspect, and how much of each to return. */
@@ -26,56 +29,66 @@ export declare namespace ITtscGraphDetails {
26
29
  /** Discriminator for selected symbol inspection. */
27
30
  type: "details";
28
31
  /**
29
- * Node ids from another tool, or dotted symbol handles such as
30
- * `OrderService.create`. Pass the few handles you need for source-free
31
- * details. Prefer one to three handles. Use `trace` when you need a path
32
- * instead of widening this call.
32
+ * Node ids or dotted symbol handles (`OrderService.create`). Prefer one to
33
+ * three; use `trace` for a path instead of widening this call.
33
34
  */
34
35
  handles: string[];
35
36
  /**
36
- * Also list each node's direct dependencies and dependents (the symbols it
37
- * uses and the symbols that use it). The list is capped; raise
38
- * `neighborLimit` when the first slice is truncated and the missing
39
- * relation is named. This remains a relationship summary, not a file body.
37
+ * Also list each node's direct dependencies and dependents (symbols it uses
38
+ * and symbols that use it), capped. A relationship summary, not a file
39
+ * body.
40
40
  *
41
41
  * @default false
42
42
  */
43
43
  neighbors?: boolean;
44
44
  /**
45
- * Maximum dependencies and dependents to return per side when
46
- * `neighbors:true`.
47
- *
48
- * Prefer the default. Values above a few neighbors are usually overfetch;
49
- * call `trace` for flow instead.
45
+ * Maximum dependencies and dependents per side when `neighbors:true`. Above
46
+ * a few is usually overfetch; call `trace` for flow instead.
50
47
  *
51
48
  * @default 2
52
49
  */
53
50
  neighborLimit?: number;
54
51
  /**
55
- * Maximum owned members to return for a container or object literal. Raise
56
- * only when the first outline is truncated and the missing member is
57
- * named.
52
+ * Maximum owned members for a container or object literal.
58
53
  *
59
54
  * @default 6
60
55
  */
61
56
  memberLimit?: number;
62
57
  /**
63
- * Maximum direct execution and type references to return per group. Raise
64
- * only when the first dependency slice is truncated and the missing
65
- * dependency is named.
58
+ * Maximum direct execution and type references per group.
66
59
  *
67
60
  * @default 1
68
61
  */
69
62
  dependencyLimit?: number;
70
63
  /**
71
64
  * Include dependency-boundary references from node_modules or bundled
72
- * `.d.ts` libraries. Leave false for source-architecture answers; enable
73
- * only when external type/API boundaries are the question.
65
+ * `.d.ts` libraries. Enable only when external type/API boundaries are the
66
+ * question.
74
67
  *
75
68
  * @default false
76
69
  */
77
70
  includeExternal?: boolean;
78
71
  }
72
+ /** One handle and the several nodes it names. */
73
+ interface IAmbiguity {
74
+ /** The handle as submitted. */
75
+ handle: string;
76
+ /** Every node the handle names, each with the id to re-call `details` on. */
77
+ candidates: ICandidate[];
78
+ }
79
+ /** One node a handle could mean: enough to choose, not to answer from. */
80
+ interface ICandidate {
81
+ /** Stable node id: submit this as the handle to select this one. */
82
+ id: string;
83
+ /** Qualified symbol name when available, otherwise the simple name. */
84
+ name: string;
85
+ /** Declaration kind (`class`, `method`, `function`, ...). */
86
+ kind: string;
87
+ /** Project-relative path of the file that declares this node. */
88
+ file: string;
89
+ /** 1-based declaration line, when known. */
90
+ line?: number;
91
+ }
79
92
  /** One inspected node: its declared shape and graph coordinates. */
80
93
  interface INode {
81
94
  /** Stable node id for subsequent `details` or `trace` calls. */
@@ -90,6 +103,8 @@ export declare namespace ITtscGraphDetails {
90
103
  line?: number;
91
104
  /** The declaration signature: its first line(s) up to the body. */
92
105
  signature?: string;
106
+ /** The first sentence of the doc comment above the declaration. */
107
+ doc?: string;
93
108
  /** Decorators written on this declaration, when any. */
94
109
  decorators?: ITtscGraphDecorator[];
95
110
  /** Assigned implementation span, when source comes from one. */
@@ -103,8 +118,8 @@ export declare namespace ITtscGraphDetails {
103
118
  /** String literal values from the signature. */
104
119
  literals?: string[];
105
120
  /**
106
- * For a container or object-literal variable: the owned symbol or top-level
107
- * property outline a consumer reaches for, without bodies.
121
+ * Owned symbol or top-level property outline a consumer reaches for on a
122
+ * container or object-literal variable, without bodies.
108
123
  */
109
124
  members?: IMember[];
110
125
  /** Declaration or implementation citation range, when known. */
@@ -142,16 +157,9 @@ export declare namespace ITtscGraphDetails {
142
157
  /** The edge kind connecting the two (`calls`, `type_ref`, ...). */
143
158
  relation: string;
144
159
  /**
145
- * Source span for the expression that produced this relationship. It is
146
- * repository evidence for the edge, not a file-read instruction.
160
+ * Source span that produced the edge: citation evidence, not a file-read
161
+ * cue.
147
162
  */
148
163
  evidence?: ITtscGraphEvidence;
149
- /**
150
- * Stable access-path aliases derived from edge evidence. For example, an
151
- * edge to `Owner.member` through `obj.slot.member` may expose
152
- * `Owner.slot.member` so answers can preserve both the resolved symbol and
153
- * the source access path.
154
- */
155
- aliases?: string[];
156
164
  }
157
165
  }
@@ -1,17 +1,18 @@
1
- import { ITtscGraphDiagnostic } from "./ITtscGraphDiagnostic";
2
1
  import { ITtscGraphEdge } from "./ITtscGraphEdge";
3
2
  import { ITtscGraphNode } from "./ITtscGraphNode";
3
+ import { ITtscGraphSpan } from "./ITtscGraphSpan";
4
4
  /**
5
5
  * The whole-graph export `ttscgraph dump` writes and the MCP server loads — the
6
6
  * wire contract between the Go fact-builder and the TypeScript graph engine.
7
7
  *
8
8
  * It is the complete graph with none of the per-response caps the MCP tools
9
- * apply: every node and edge the build resolved. The server parses it once at
10
- * startup (typia-validated) into an in-memory resident graph and answers every
11
- * tool call from that warm model; the bundled 3D viewer reduces the same dump.
9
+ * apply: every node and edge the build resolved. The server parses each changed
10
+ * native snapshot (typia-validated) into an in-memory resident graph and reuses
11
+ * that warm model while project inputs stay unchanged; the bundled 3D viewer
12
+ * reduces the same dump.
12
13
  *
13
- * Paths in `project` and `tsconfig` are absolute; `file` fields on nodes,
14
- * edges, and diagnostics are project-relative.
14
+ * Paths in `project` and `tsconfig` are absolute; `file` fields on nodes and
15
+ * edges are project-relative.
15
16
  */
16
17
  export interface ITtscGraphDump {
17
18
  /** Absolute path of the project root the graph was built for. */
@@ -19,12 +20,36 @@ export interface ITtscGraphDump {
19
20
  /** The tsconfig the program was loaded from, relative to `project`. */
20
21
  tsconfig: string;
21
22
  /** Every node the build recorded. */
22
- nodes: ITtscGraphNode[];
23
+ nodes: ITtscGraphDump.INode[];
23
24
  /** Every edge the build resolved. */
24
- edges: ITtscGraphEdge[];
25
+ edges: ITtscGraphDump.IEdge[];
26
+ }
27
+ export declare namespace ITtscGraphDump {
28
+ /**
29
+ * A node as the builder sends it: the graph node, minus the file paths inside
30
+ * its spans, which the loader puts back from the node's own `file`.
31
+ *
32
+ * A node's declaration span is in the node's file, always — the path in the
33
+ * span was the same string a second time, once per node. It is the reader's
34
+ * to reconstruct, and {@link TtscGraphMemory} does, so nothing downstream of
35
+ * the loader sees a span without its file.
36
+ */
37
+ interface INode extends Omit<ITtscGraphNode, "evidence" | "implementation"> {
38
+ /** Declaration span; its file is this node's `file`. */
39
+ evidence?: ITtscGraphSpan;
40
+ /**
41
+ * Implementation span. This one keeps its file when it has one: an
42
+ * implementation genuinely can live in another file from its declaration.
43
+ */
44
+ implementation?: ITtscGraphSpan;
45
+ }
25
46
  /**
26
- * Fused compiler and plugin diagnostics, when diagnostics were collected.
27
- * Absent when the dump was built without a diagnostics pass.
47
+ * An edge as the builder sends it. Its span is in the file its `from` id
48
+ * names the id is `path#Qualified.Name:kind` so the path rode the wire a
49
+ * second time on every edge, and edges outnumber nodes several times over.
28
50
  */
29
- diagnostics?: ITtscGraphDiagnostic[];
51
+ interface IEdge extends Omit<ITtscGraphEdge, "evidence"> {
52
+ /** Expression span; its file is the one embedded in `from`. */
53
+ evidence?: ITtscGraphSpan;
54
+ }
30
55
  }
@@ -1,12 +1,10 @@
1
1
  import { ITtscGraphEvidence } from "./ITtscGraphEvidence";
2
2
  import { TtscGraphEdgeKind } from "./TtscGraphEdgeKind";
3
3
  /**
4
- * A directed relationship from one {@link ITtscGraphNode} to another, both named
5
- * by `id`. The triple `(from, to, kind)` is unique; a repeated relationship
6
- * keeps the first source-order evidence.
7
- *
8
- * Every edge is resolved by the compiler, so there is no per-edge trust flag to
9
- * carry — the whole graph is checker-resolved fact.
4
+ * A directed relationship between two {@link ITtscGraphNode}s, both named by
5
+ * `id`. The triple `(from, to, kind)` is unique; a repeat keeps the first
6
+ * source-order evidence. Every edge is compiler-resolved, so there is no
7
+ * per-edge trust flag: the whole graph is checker-resolved fact.
10
8
  */
11
9
  export interface ITtscGraphEdge {
12
10
  /** Node id the relationship originates from. */