Skip to content

Fix refrag GLM mode, add GLM support to CTX, ctx based Claude Code hook to enhance user prompts#21

Merged
m1rl0k merged 3 commits intoContext-Engine-AI:testfrom
voarsh2:ctx-glm-claude-hook-refrag
Nov 20, 2025
Merged

Fix refrag GLM mode, add GLM support to CTX, ctx based Claude Code hook to enhance user prompts#21
m1rl0k merged 3 commits intoContext-Engine-AI:testfrom
voarsh2:ctx-glm-claude-hook-refrag

Conversation

@voarsh2
Copy link
Contributor

@voarsh2 voarsh2 commented Nov 17, 2025

This PR:

  • Adds GLM support to ReFrag (without LLM sidecar)
  • Allows CTX to use GLM to rewrite prompts, extra relevance gating flags (which can just return original query/prompt)
    -- ctx config can set collection and gating/relevance knobs, with example provided)
  • Adds a Claude Code hook script and hook example, to rewrite the users prompt and give Claude Code the enhanced input.
    -- hook can be bypassed with adding "<" to msg, or "noctx:" - planning to add "only enhance IF (a condition is met) - right now it's enhance unless opt-out

Sample CTX prompt rewrite in Claude Code:

echo '{"user_message":"Describe how the quest progression system in Pirates Online Classic is implemented. How are quest states represented, how are objectives registered and updated, and where do we validate that a quest step is complete before advancing to the next stage?"}' | ./ctx-hook-simple.sh
{
  "user_message": "Analyze the quest state representation in QuestStepIndicator by examining the specific methods and attributes defined between lines 33-43 in /work/pirates-online-classic/pirates/quest/QuestStepIndicator.py. How do these components track quest progress, and what data structures are used to maintain quest state? Compare this with the quest registration mechanisms in QuestManagerAI (lines 454-483), focusing on how objectives are registered and updated. How does QuestManagerAI establish communication with DistributedBuriedTreasureAI (lines 30-49) to synchronize quest progress, and what specific message passing or event handling patterns are employed?\n\nInvestigate the quest step validation process by analyzing the conditional checks in DistributedBuriedTreasureAI (lines 30-49) and DistributedSearchableContainerAI (lines 23-36). What specific criteria determine quest step completion in buried treasure quests, and how are these conditions evaluated? How does QuestManagerAI (lines 454-483) process validation results from DistributedBuriedTreasureAI to advance quest stages, and what error handling or edge cases are considered? What role does DistributedSearchableContainerAI play in this?"
}```

Add support for GLM API as an alternative decoder runtime alongside llama.cpp, including:
- New ctx-hook-simple.sh script for Claude Code UserPromptSubmit integration
- GLM configuration options in ctx_config.example.json and environment variables
- Updated Dockerfiles to use shared requirements.txt for dependency management
- Enhanced ctx.py with GLM client support and collection parameter
- Modified MCP indexer server to support GLM runtime selection
- Added GLM timeout configuration and improved error handling
Add configurable context quality controls and execution modes to improve context retrieval reliability:
- Configure default execution mode (unicorn/detail) via ctx_config.json
- Add require_context flag to fallback to original query when no relevant context found
- Implement relevance gate to filter low-quality search results based on token overlap
- Add draft similarity gate for unicorn mode to ensure meaningful query refinement
- Extend hook script to export new environment variables and build context command dynamically
- Add fuzzy matching for near-duplicate paragraphs using difflib
- Implement deterministic paragraph deduplication function
- Cap paragraphs to maximum of 3 for consistency
- Update fallback text to be more specific about system details
- Resolve collection name filter logic for better parameter handling
@voarsh2 voarsh2 changed the title Ctx glm claude hook refrag Fix refrag GLM mode, add GLM support to CTX, ctx based Claude Code hook to enhance user prompts Nov 17, 2025
@m1rl0k m1rl0k marked this pull request as ready for review November 20, 2025 16:51
@m1rl0k m1rl0k merged commit 357da65 into Context-Engine-AI:test Nov 20, 2025
1 check passed
@voarsh2
Copy link
Contributor Author

voarsh2 commented Nov 20, 2025

@m1rl0k lol I wasn't done yet - I forgot to provide the example Claude hook docs and finish testing

m1rl0k added a commit that referenced this pull request Mar 1, 2026
Fix refrag GLM mode, add GLM support to CTX, ctx based Claude Code hook to enhance user prompts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants