feat: context pipeline for structured AI prompt injection#71
Merged
Atharv777 merged 5 commits intokentuckyfriedcode:mainfrom Mar 31, 2026
Merged
feat: context pipeline for structured AI prompt injection#71Atharv777 merged 5 commits intokentuckyfriedcode:mainfrom
Atharv777 merged 5 commits intokentuckyfriedcode:mainfrom
Conversation
Collaborator
|
Great PR @Krishna41357 |
Contributor
Author
|
sure! happy to do any changes if required . |
Collaborator
|
@Krishna41357 Hey sorry for the trouble, I've merged a few PRs that have changed a few things in the app/index.jsx. Can you please look into it and resolve the merge conflicts here? |
Contributor
Author
|
yeah sure ! |
Contributor
Author
|
@Atharv777 here you go !! all cleanly merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #61
What changed
Added a structured pipeline that selects and injects only relevant
project context into AI prompts instead of sending raw full-project data.
New files
server/utils/context_builder.py
Scores and selects files to include based on import references,
directory proximity, language match, and recency. Enforces hard
size budgets: 8k chars for the active file, 4k per related file,
32k total. Skips heavy dirs (node_modules, .git, target).
TTL-based cache with a 200-entry cap and automatic eviction.
server/utils/prompt_builder.py
Assembles the final prompt string from selected context. Three-tier
fallback: truncate related files, truncate current file to 300 chars,
metadata only. Suppresses the explore nudge when file context exists.
test_context_pipeline.py
74 tests covering context selection, budget enforcement, cache TTL
and size cap, prompt assembly, fallback strategies, route endpoints,
and the frontend constant contract.
Updated files
server/utils/init.py
Registers context_builder and prompt_builder as package exports.
server/agent.py
Imports context_builder and prompt_builder. Adds project_context
field to AgentRequestContext. Adds _parse_context_payload() to read
context from POST body. Route now accepts GET and POST. System prompt
built via build_prompt(), task prompt via build_task_prompt(). Adds
PROJECT CONTEXT section to get_prompt() so the model knows to use
injected context instead of re-exploring.
server/project_routes.py
Two new endpoints:
POST /api/projects//context - pre-fetches and returns context
payload for the frontend to attach to agent requests.
POST /api/projects//context/invalidate - clears the cache on
file save. Path traversal guard added.
pages/app/index.jsx
Tracks active file and recently modified files. Fetches context on
file switch (debounced 800ms). Invalidates cache on save. Sends
context payload in POST body instead of query string. Live context
status indicator in toolbar.
System design
Tests
74/74 passing
What this enables
Python and JS (RECENTLY_MODIFIED_BOOST_LIMIT = 5)
System choices
conservative enough (~4 chars per token for code)
file switching