MCPcopy Create free account
hub / github.com/JordanCoin/codemap / hookPromptSubmit

Function hookPromptSubmit

cmd/hooks.go:670–747  ·  view source on GitHub ↗

hookPromptSubmit analyzes user prompt with code intelligence and shows context

(root string)

Source from the content-addressed store, hash-verified

668
669// hookPromptSubmit analyzes user prompt with code intelligence and shows context
670func hookPromptSubmit(root string) error {
671 input, err := io.ReadAll(os.Stdin)
672 if err != nil {
673 return nil
674 }
675
676 // Extract prompt from JSON
677 var data map[string]interface{}
678 if err := json.Unmarshal(input, &data); err != nil {
679 return nil
680 }
681
682 prompt, ok := data["prompt"].(string)
683 if !ok || prompt == "" {
684 return nil
685 }
686
687 projCfg := config.Load(root)
688 topK := projCfg.RoutingTopKOrDefault()
689 info := getHubInfoNoFallback(root)
690
691 // Extract mentioned files and classify intent
692 filesMentioned := extractMentionedFiles(prompt, topK)
693 intent := classifyIntent(prompt, filesMentioned, info, projCfg)
694
695 // Emit structured intent marker (machine-readable for tools)
696 emitIntentMarker(intent)
697
698 // Human-readable file context (backwards compatible)
699 var output []string
700 if info != nil {
701 for _, file := range filesMentioned {
702 if importers := info.Importers[file]; len(importers) > 0 {
703 if len(importers) >= 3 {
704 output = append(output, fmt.Sprintf(" ⚠️ %s is a HUB (imported by %d files)", file, len(importers)))
705 } else {
706 output = append(output, fmt.Sprintf(" 📍 %s (imported by %d files)", file, len(importers)))
707 }
708 }
709 }
710 }
711
712 if len(output) > 0 {
713 fmt.Println()
714 fmt.Println("📍 Context for mentioned files:")
715 for _, line := range output {
716 fmt.Println(line)
717 }
718 }
719
720 // Show suggestions from intent analysis
721 if len(intent.Suggestions) > 0 {
722 fmt.Println()
723 fmt.Printf("💡 Suggestions (risk: %s):\n", intent.RiskLevel)
724 for _, s := range intent.Suggestions {
725 fmt.Printf(" • [%s] %s — %s\n", s.Type, s.Target, s.Reason)
726 }
727 }

Calls 12

LoadFunction · 0.92
getHubInfoNoFallbackFunction · 0.85
extractMentionedFilesFunction · 0.85
classifyIntentFunction · 0.85
emitIntentMarkerFunction · 0.85
showRouteSuggestionsFunction · 0.85
showMatchedSkillsFunction · 0.85
showDriftWarningsFunction · 0.85
showWorkingSetSummaryFunction · 0.85
showSessionProgressFunction · 0.85
writeStatuslineStateFunction · 0.85
RoutingTopKOrDefaultMethod · 0.80