Skip to content

Commit 80fbbed

Browse files
committed
Update ctx.py
1 parent 46d77fb commit 80fbbed

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

scripts/ctx.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@
55
Context-aware prompt enhancer CLI.
66
77
Retrieves relevant code context from the Context-Engine MCP server and enhances
8-
your prompts with it. Perfect for piping to LLMs or getting quick context.
8+
your prompts with it using a local LLM decoder. Works with both questions and
9+
commands/instructions. Outputs at least two detailed paragraphs.
910
1011
Usage:
11-
ctx "how does hybrid search work?"
12-
ctx --language python "explain the caching logic"
13-
ctx --under scripts/ "how is the watcher implemented?"
14-
ctx --limit 3 "authentication onboarding flow"
12+
ctx "how does hybrid search work?" # Question → enhanced question
13+
ctx "refactor the caching logic" # Command → enhanced instructions
14+
ctx --language python "explain the indexer" # Filter by language
15+
ctx --detail "add error handling to ctx.py" # Include code snippets
1516
1617
Examples:
17-
# Enhance prompt with context
18+
# Enhance questions with context
1819
ctx "how does the indexer work?"
20+
# Output: Two detailed question paragraphs with file/line references
21+
22+
# Enhance commands with specific details
23+
ctx "refactor ctx.py to improve modularity"
24+
# Output: Two detailed instruction paragraphs with concrete steps
25+
26+
# Detail mode: include short code snippets (slower but richer)
27+
ctx --detail "explain the caching logic"
1928
2029
# Pipe to LLM
2130
ctx "fix the bug in watcher.py" | llm
@@ -24,9 +33,12 @@
2433
ctx --language python --under scripts/ "caching implementation"
2534
2635
Environment:
27-
MCP_INDEXER_URL - MCP indexer endpoint (default: http://localhost:8003/mcp)
28-
CTX_LIMIT - Default result limit (default: 5)
29-
CTX_CONTEXT_LINES - Context lines for snippets (default: 0)
36+
MCP_INDEXER_URL - MCP indexer endpoint (default: http://localhost:8003/mcp)
37+
CTX_LIMIT - Default result limit (default: 5)
38+
CTX_CONTEXT_LINES - Context lines for snippets (default: 0)
39+
CTX_REWRITE_MAX_TOKENS - Max tokens for LLM rewrite (default: 320)
40+
DECODER_URL - Override decoder endpoint
41+
USE_GPU_DECODER - Use GPU decoder on port 8081 (default: 0)
3042
"""
3143

3244
import sys
@@ -454,17 +466,26 @@ def build_final_output(
454466

455467
def main():
456468
parser = argparse.ArgumentParser(
457-
description="Context-aware prompt enhancer for Context-Engine",
469+
description="Context-aware prompt enhancer - rewrites questions and commands with codebase context",
458470
formatter_class=argparse.RawDescriptionHelpFormatter,
459471
epilog="""
460472
Examples:
473+
# Questions: enhanced with specific details
461474
ctx "how does hybrid search work?"
475+
476+
# Commands: enhanced with concrete implementation steps
477+
ctx "refactor ctx.py to improve modularity"
478+
479+
# Detail mode: include code snippets (slower but richer)
480+
ctx --detail "explain the caching logic"
481+
482+
# Pipe to LLM or clipboard
462483
ctx --cmd llm "explain the caching logic"
463484
ctx --cmd pbcopy --language python "fix bug in watcher"
464485
"""
465486
)
466487

467-
parser.add_argument("query", help="Your question or prompt")
488+
parser.add_argument("query", help="Your question or command to enhance")
468489

469490
# Command execution
470491
parser.add_argument("--cmd", "-c", help="Command to pipe enhanced prompt to (e.g., llm, pbcopy)")
@@ -492,7 +513,7 @@ def main():
492513

493514
# Detail mode
494515
parser.add_argument("--detail", action="store_true",
495-
help="Include short code snippets in the retrieved context for richer rewrites (slower)")
516+
help="Include short code snippets for richer rewrites (slower but more specific; auto-clamps to limit=4, per_path=1)")
496517

497518
args = parser.parse_args()
498519

0 commit comments

Comments
 (0)