feat: Introduce analyze Command for Deep Educational Codebase Analysis
#6
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/analyze_cmd"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Introduce
analyzeCommand for Codebase AnalysisDescription
This PR adds a new
analyzecommand to Grokkit, enabling users to generate clean, educational Markdown reports that deeply analyze a codebase. The feature is designed as a didactic tool for learning developers, hobbyists, and teams onboarding to projects. It supports polyglot codebases through customizable, language-specific prompts (e.g., for Go, Python, C90, Rexx, Perl, etc.), automatically detecting the primary language and loading prompts from project-local or global locations.Key highlights:
--yes).grok,git,linter, andlogger, with minimal changes to core files.This enhances Grokkit's value as a learning and exploration tool, complementing commands like
reviewandlint.Closes # [if applicable, link to any related issues].
Changes
Added
.grokkit/prompts/go.md:Added
cmd/analyze.go:analyzeCobra command.--dir,--output,--yes,--model).discoverSourceFiles,previewLines, andbuildProjectContextfor file walking, previewing, and context building.Modified
cmd/root.go:analyzeCmdto the root command for CLI integration.Added
docs/user-guide/analyze.md:Modified
docs/user-guide/index.md:analyze.mdin the command list.Added
internal/linter/language.go:DetectPrimaryLanguage(counts languages across files and picks the dominant one, with Go bias) andSupportedLanguages(lists known languages for future use).Added
internal/prompts/analyze.go:LoadAnalysisPromptfunction to search for and load language-specific prompts, preferring project-local over global paths. Returns an error if none found for clear user feedback.No breaking changes; this is a pure addition. Code follows existing style (e.g., using package-level logger, Cobra patterns, and error handling).
Motivation
Grokkit already excels at targeted tasks like linting and reviews, but users often need a high-level, educational overview of an entire project—especially when learning a new codebase, language, or legacy system (e.g., C90 or Rexx). This command fills that gap by:
This aligns with Grokkit's goal of being a helpful, developer-focused CLI, and the prompt system empowers users to tailor it (e.g., focusing on security for C or concurrency for Go).
Testing Notes
Prerequisites
go buildorgo install).~/.config/grokkit/config.yamlor env vars).Manual Testing Steps
Basic Run:
grokkit analyze.grokkit/prompts/go.mdif present), generates report preview, prompts for confirmation, and writes toanalyze.md.Custom Directory and Output:
grokkit analyze --dir ./path/to/project --output custom-report.md --yescat custom-report.mdto inspect.Stdout Output:
grokkit analyze --output -Language Detection:
grokkit analyze.~/.config/grokkit/prompts/python.mdwith sample content, run in a Python project, confirm it loads.Edge Cases:
grokkit analyze --dir /empty→ Exits with "No supported source files found".--model grok-4-minifor speed; verify streaming works without live output (usesStreamSilent).Documentation:
analyze.mdrenders correctly and links work inindex.md.Automated Tests (if added in future)
DetectPrimaryLanguage(e.g., mock file lists returning "go", "python", "unknown").LoadAnalysisPrompt(mock fs for local/global paths, error on missing).