context-builder module turns a KnowledgeGraph and a natural-language query into a focused ChatContext — a subset of the graph most relevant to that query — and formats it as structured markdown ready for an LLM prompt.
ChatContext
The data structure returned bybuildChatContext.
The name of the analyzed project, taken from
graph.project.name.Human-readable description of the project, taken from
graph.project.description.Programming languages detected in the project.
Frameworks and major libraries detected in the project.
Nodes from the knowledge graph that match the query, plus their 1-hop neighbors via edges.
Edges where both endpoints are in the relevant node set.
Architectural layers that contain at least one relevant node.
The original user query passed to
buildChatContext.buildChatContext
Searches the knowledge graph for nodes relevant to the user query, expands 1 hop via edges, and collects the associated layers.The full knowledge graph produced by the analysis pipeline.
Natural-language query string used to search for relevant nodes (e.g.
"authentication flow").Maximum number of nodes to retrieve from the search engine before 1-hop expansion. Defaults to
15.How it works
- Search — A
SearchEngineis instantiated withgraph.nodes. It runsengine.search(query, { limit })to produce ranked results. - 1-hop expansion — Every edge in
graph.edgesis inspected. If either endpoint is in the matched set, the other endpoint is added to the expanded set. - Edge collection — Only edges where both endpoints are in the expanded set are included in
relevantEdges. - Layer collection — A layer is included if any of its
nodeIdsappear in the expanded set.
formatContextForPrompt
Formats aChatContext as a multi-section markdown string ready to be injected into an LLM system prompt.
A
ChatContext produced by buildChatContext.Output structure
The returned string contains the following sections (only non-empty sections are rendered):| Section | Content |
|---|---|
# Project: <name> | Project name, description, languages, frameworks |
## Relevant Layers | One ### heading per layer with its description |
## Code Components | One ### heading per node with file, complexity, summary, tags, language notes |
## Relationships | source --[type]--> target lines for each relevant edge |