Commit Graph

64 Commits

Author SHA1 Message Date
4603a1ec7a fix(recipe): improve allowed shell command validation
Update the command matching logic to require an exact match or the command followed by a space and arguments. Also normalize case and trim whitespace for safe commands to prevent loose prefix matches that could allow unintended commands.
2026-03-07 19:37:53 +00:00
685b0f40d7 feat(recipe): support numeric arguments in read-only shell commands
Update the executeReadOnlyShell function to handle numbers in command arguments,
such as 'tree -L 3', by changing Args to []interface{} and converting them to strings
before execution. Add strconv import for formatting.
2026-03-07 19:27:15 +00:00
a36f3585f4 refactor(recipe): enhance read-only shell handling and robustness
- Tighten trigger conditions for read-only shell steps to specific phrases
- Add robust JSON extraction with escaped quote handling
- Reorder user confirmation before whitelist check in execution flow
- Relocate FileChange struct and clean up comments
- Update recipe markdown for step title consistency
2026-03-07 19:18:41 +00:00
3d9d1cd722 feat(recipe): add project exploration step with read-only shell support
- Introduce new Step 1 in result-refactor.md for exploring project structure using safe read-only shell commands (e.g., tree, cat).
- Rename subsequent steps accordingly.
- Add handler in runner.go for read-only shell steps triggered by keywords like "explore" or "inspect".
2026-03-07 18:58:40 +00:00
66d52917c0 feat(recipe): add read-only shell execution with user confirmation
Implement executeReadOnlyShell method to safely run whitelisted read-only commands,
prompting for user approval and integrating AI-suggested commands for filesystem context.
2026-03-07 18:50:38 +00:00
d74c613e0f chore(loader): add logging for safe commands config loading
Add debug print statements to indicate when the safe commands config file
is successfully loaded or when falling back to the built-in list.
2026-03-07 18:32:43 +00:00
f9d99527e0 feat(safety): make safe shell commands user-configurable
- Replace hardcoded safeCommands map with sync.OnceValue loading from ~/.config/grokkit/safe_shell_commands.yaml
- Provide fallback built-in safe list if config load fails
- Add safe_shell_commands.yaml.example for user reference
- Update safety check to use loaded map and prefix matching
2026-03-07 18:22:39 +00:00
7e4bdbc21c refactor(recipe/loader): expand safe shell commands and refine validation logic
- Renamed safeReadOnlyCommands to safeCommands for clarity.
- Added support for additional safe commands including GNU utilities (find, grep, which),
  Git commands (diff, branch), and various test runners (go test, make test/lint, pytest, etc.).
- Updated safety check to allow commands prefixed with any safe command for flexibility.
- Improved error message for unsafe commands.
2026-03-07 17:59:59 +00:00
b2172b8546 fix(recipe): improve unsafe shell command error message
Update the error message for unsafe shell commands to be more concise and user-friendly, removing redundant "ERROR:" prefix and "try again" instruction.
2026-03-07 17:41:09 +00:00
64fb748897 refactor(recipe): simplify path resolution and remove shell command execution
- Consolidate resolveWorkDir and remove resolvePackagePath for cleaner path handling.
- Eliminate executeShellCommands and related logic to disable shell execution in recipes.
- Simplify error messaging in loader for unsafe commands.
2026-03-07 17:34:59 +00:00
63e640c022 feat(recipe): add safety whitelist for allowed shell commands
Implement a read-only command whitelist in the recipe loader to reject
potentially dangerous shell commands, ensuring only safe operations like
ls, pwd, cat, etc., are permitted. This enhances security by preventing
execution of unauthorized commands in recipes.
2026-03-07 17:11:13 +00:00
aedf9cdf03 refactor(recipe/runner): enhance working directory resolution and shell command safety
- Rename and expand resolvePackagePath to resolveWorkDir, which now appends project_name if provided
- Update discoverFiles to use workDir and add default search pattern if none specified
- Modify executeShellCommands prompt to include workDir and enforce relative paths only
- Add safety checks to reject shell commands with ".." or absolute paths to prevent directory escapes
- Minor prompt and formatting adjustments for clarity and consistency
2026-03-07 16:18:29 +00:00
8efca62109 refactor(runner): improve package path resolution for consistency
- Introduce resolvePackagePath to handle ~ expansion, relative paths, and absolutization at the start.
- Update discoverFiles and executeShellCommands to use the resolved workDir.
- Remove redundant path logic from discoverFiles and shell execution for better maintainability.
2026-03-07 15:52:56 +00:00
0912aa7b89 feat(recipe): add safe shell command execution
Introduce a new mechanism in the recipe runner to execute whitelisted shell commands for steps like initialization, creation, or running tools (e.g., poetry, git). Commands are generated via AI prompt, parsed from JSON, validated against an allowed list, and executed within a strict working directory to ensure safety.
2026-03-07 15:34:50 +00:00
213a9869e6 docs(internal/recipe): update comment on search pattern default to "Go-style"
Changes the comment to describe the default as "Go-style" instead of the specific string for better generality.
2026-03-07 00:41:39 +00:00
757f422765 refactor(recipe): make search pattern configurable in file discovery
- Add SearchPattern field to Recipe struct
- Update discoverFiles to use configurable search pattern, defaulting to "if err != nil"
- Set default search_pattern in result-refactor.md recipe
2026-03-07 00:34:25 +00:00
ae8a199ece refactor(recipe): make file discovery fully generic using recipe metadata
Update discoverFiles to leverage recipe metadata for extensions and apply smart defaults more cleanly. Generalize logic with comments for future improvements, while retaining err != nil check for now.
2026-03-07 00:22:19 +00:00
8c14977ec6 feat(recipe): add smart defaults for package_path in file discovery
Enhance discoverFiles to respect explicit package_path param if provided.
If no param is given, intelligently default to 'src' directory if it exists,
otherwise fall back to project root (.).
2026-03-07 00:13:57 +00:00
f5c73ab291 refactor(recipe): add ResolvedParams for better param handling
Introduce ResolvedParams field to Recipe struct for storing resolved
parameter values from defaults and user overrides. Update loader to
populate and use it for template rendering. Adjust runner to use
ResolvedParams for root path and generalize file discovery.
2026-03-07 00:07:21 +00:00
1c79abce8d fix(recipe): add error handling to unified patch creation
Handle potential errors from file writes in createUnifiedPatch to prevent silent failures.
2026-03-06 23:57:22 +00:00
0e234419f4 feat(recipe): add fields for generic file discovery
Introduce ProjectLanguages and Extensions fields to the Recipe struct
to support option 2 for generic file discovery. Also update comments
for internal fields populated by the loader.
2026-03-06 23:55:54 +00:00
7ffbf352bc refactor(recipe): make file discovery generic using recipe metadata
- Build allowed extensions from recipe languages and extensions map
- Generalize filepath walking to filter by allowed extensions instead of hardcoding .go
- Retain Go-specific content check for now; can generalize later
- Simplify refactor JSON handling and patch creation by removing redundant comments and error checks
- Adjust comments and minor formatting for clarity
2026-03-06 23:51:42 +00:00
18bbb67789 refactor(recipe): enhance refactor handling with JSON collection and package path
- Introduce refactorJSONs to collect pure JSON from refactor steps for apply.
- Update discoverFiles to respect recipe's package_path parameter.
- Refine handleApplyStep to parse and apply changes more robustly.
- Remove outdated test output files.
2026-03-06 23:22:20 +00:00
a8208da4c1 refactor(recipe): implement one-file-at-a-time refactoring handler
Add refactorFiles to process discovered files individually, generating small JSON responses per file to avoid truncation. Update handleApplyStep to collect and parse multiple single-file JSONs into a unified patch. Switch discoverFiles comment to reflect real scanning. Add fallback default in Run for other steps.
2026-03-06 22:57:07 +00:00
0b5aa5eb57 refactor(recipe): improve error handling and restructure in runner
- Move FileChange struct to top-level for better organization.
- Enhance createUnifiedPatch with proper error handling on writes.
- Remove unused bufio import and update comments.
- Delete obsolete runner_test.go file.
2026-03-06 22:48:15 +00:00
7cb9eb3eb7 refactor(recipe): switch refactor step to strict JSON output
- Update result-refactor.md to output JSON array of file changes instead of code blocks
- Modify runner.go to parse JSON directly, removing regex-based extraction
- Add project_languages and extensions to recipe metadata
- Improve error handling and output consistency in steps
2026-03-06 22:40:29 +00:00
d4f3e3adbc refactor(recipe): update regex for robust Grok output matching
- Blank import bufio to avoid unused warnings.
- Refine regex to handle double-quoted format and fix backtick issues.
- Update comments for clarity on regex changes.
2026-03-06 22:25:39 +00:00
c5bdd44e55 fix(recipe): update regex to match Grok's current output style
Adjust the regex in handleApplyStep to flexibly match both old and new Grok formats for code blocks. Also, remove blank import for bufio as it's now used.
2026-03-06 22:21:58 +00:00
b2b8c1a482 refactor(recipe/runner): improve regex flexibility and simplify patch creation
- Update discoverFiles comment to be more concise.
- Enhance blockRe regex to optionally match leading "// " for filenames, supporting varied Grok output formats.
- Revise handleApplyStep comment to reflect regex changes.
- Simplify createUnifiedPatch by removing unnecessary error checks on fmt.Fprintf and defer closure.
2026-03-06 22:15:33 +00:00
40d40f7669 refactor(recipe): clean up runner implementation
- Adjust bufio import to blank (likely for side effects or pending use)
- Refine comments for clarity and remove unnecessary ones
- Split regex string to avoid backtick collisions in literals
- Add error handling to patch writing in createUnifiedPatch
- Minor formatting and defer close adjustments
2026-03-06 22:07:22 +00:00
7b415f8e26 feat(recipe): add file discovery and special step handling in runner
- Introduce discoverFiles function to scan Go files in 'internal' for error handling patterns.
- Add special case for "discover" or "find" steps to perform filesystem scans.
- Refine LLM prompting to enforce strict output format and shorten system prompt.
- Update apply/patch handling and unified patch creation with simplifications.
- Import bufio for potential future use and adjust regex for code block extraction.
2026-03-06 21:57:35 +00:00
852142730a refactor(recipe): enhance parsing for multi-line step content
Replace regex-based sub-section extraction with label-indexed parsing to
handle multi-line content, blank lines, and ensure reliability without
duplicates. Add clarifying comments for templates and summary extraction.
2026-03-06 21:48:35 +00:00
824bbcb85f refactor(recipe): simplify code block extraction regex
Update the regex in runner.go to use string concatenation for better readability.
Add test output files as fixtures for test verification.
2026-03-06 21:40:03 +00:00
b9de35f48b refactor(recipe): simplify apply step to dry-run only and add extraction tests
- Restrict filesystem interactions to apply/patch steps exclusively.
- Remove real apply logic with user confirmation; default to creating a patch file in dry-run mode.
- Update prompts, comments, and regex for better clarity and precision.
- Add unit tests for the extractCodeBlocks function to ensure reliable parsing.
2026-03-06 21:36:31 +00:00
0ba427aaf6 feat(recipe): add apply/patch step handling with code block extraction and application
- Introduce special case in Runner.Run() for steps containing "apply" or "patch" in title.
- Add handleApplyStep to parse code blocks from previous results, support dry-run patch creation, or real application with user confirmation and backups.
- Implement extractCodeBlocks using regex to identify labelled Go code blocks.
- Add createUnifiedPatch for generating unified diff patches in dry-run mode.
- Remove final summary prompt and streamline recipe completion.
- Adjust system prompt for clarity.
2026-03-06 21:01:01 +00:00
d1ebd2af79 refactor(recipe): improve loading and execution logic
- Enhance recipe parsing in loader.go: extract overview, use split-based step extraction to avoid duplicates, refine final summary handling, and clean up comments/templates.
- Refine runner.go prompts: add Grok system message, simplify user prompts for conciseness, adjust result joining with separators, and remove unnecessary text.
2026-03-06 20:46:30 +00:00
5c67f78c27 feat(recipe): implement LLM-powered recipe execution
Add support for executing recipe steps via Grok API streaming, including parameter defaults from YAML, model selection via flags/config, previous step context, and a final summary prompt. Update runner to handle client and model, and refine loader to apply user params with fallbacks.
2026-03-06 20:32:04 +00:00
2cc728eed4 refactor(recipe): clean up comments, error handling, and output formatting
- Simplify import comments and error handling in cmd/recipe.go
- Streamline regex comment in internal/recipe/loader.go
- Enhance console output and add LLM placeholder in internal/recipe/runner.go
2026-03-06 19:00:16 +00:00
6bd72aad25 refactor(recipe): improve subRe regexp and add explanatory comments
Simplify the subRe regular expression by using a non-capturing group for the section labels instead of alternation, and switch the lookahead to a non-capturing group for consistency. Add comments to document the purpose of stepRe and subRe for better maintainability.
2026-03-06 18:39:56 +00:00
aa38e92fb5 feat(recipe): add recipe system for Result[T] refactoring
Implement recipe loading, parsing, and running infrastructure.
Add initial result-refactor recipe for converting Go error handling to monadic Result[T] style.
Includes markdown recipe definition, YAML frontmatter parsing, step extraction, and basic runner.
2026-03-06 18:35:58 +00:00
f0322a84bd chore(lint): enhance golangci configuration and add security annotations
Some checks failed
CI / Test (push) Successful in 33s
CI / Lint (push) Failing after 17s
CI / Build (push) Successful in 21s
- Expand .golangci.yml with more linters (bodyclose, errcheck, etc.), settings for govet, revive, gocritic, gosec
- Add // nolint:gosec comments for intentional file operations and subprocesses
- Change file write permissions from 0644 to 0600 for better security
- Refactor loops, error handling, and test parallelism with t.Parallel()
- Minor fixes: ignore unused args, use errors.Is, adjust mkdir permissions to 0750
2026-03-04 20:00:32 +00:00
ce5367c3a7 feat(cmd): add changelog command for AI-generated release notes
Some checks failed
CI / Test (push) Failing after 27s
CI / Lint (push) Has been skipped
CI / Build (push) Has been skipped
- Implement `grokkit changelog` command with flags for version, since, stdout, and commit reminder
- Add git helpers for latest/previous tags and formatted log since ref
- Include tests for message building and full changelog construction
2026-03-03 21:59:09 +00:00
ebb0cbcf3a test(cmd): add unit tests for completion, root execution, config, errors, and logger
Some checks failed
CI / Test (push) Failing after 26s
CI / Lint (push) Has been skipped
CI / Build (push) Has been skipped
- Add tests for shell completion generation in completion_test.go
- Add tests for root command execution and flags in root_test.go
- Expand config tests for temperature, timeout, and log level getters
- Add APIError unwrap test in errors_test.go
- Add WithContext tests in logger_test.go
- Stage test output artifact in .output.txt
2026-03-02 22:12:54 +00:00
918ccc01c8 refactor(tests): improve error handling and defer usage
All checks were successful
CI / Test (push) Successful in 31s
CI / Lint (push) Successful in 25s
CI / Build (push) Successful in 22s
Release / Create Release (push) Successful in 36s
- Add error checking for os.Setenv and io operations in test files
- Use anonymous functions in defer to ignore errors from os.Remove, os.Setenv, etc.
- Minor formatting and consistency fixes in tests and client code
2026-03-02 21:33:11 +00:00
99ef10b16b refactor(cmd): extract run funcs and add injectable deps for testability
Some checks failed
CI / Test (push) Successful in 34s
CI / Lint (push) Failing after 19s
CI / Build (push) Successful in 20s
- Introduce newGrokClient and gitRun vars to allow mocking in tests.
- Refactor commit, commitmsg, history, prdescribe, and review cmds into separate run funcs.
- Update docs, lint, and review to use newGrokClient.
- Add comprehensive unit tests in run_test.go covering happy paths, errors, and edge cases.
- Expand grok client tests with SSE server mocks for Stream* methods.
2026-03-02 20:47:16 +00:00
f763976a27 docs(client): add documentation comments to Client struct and methods
Some checks failed
CI / Test (push) Failing after 24s
CI / Lint (push) Has been skipped
CI / Build (push) Has been skipped
Release / Create Release (push) Successful in 36s
Add detailed GoDoc-style comments for the Client struct, NewClient function,
and various streaming methods to improve code readability and documentation.
Also include a comment for CleanCodeResponse and minor formatting adjustments.
2026-03-02 20:20:18 +00:00
68df041a09 test(version): add tests for version information
All checks were successful
CI / Test (push) Successful in 32s
CI / Lint (push) Successful in 25s
CI / Build (push) Successful in 20s
Add unit tests to verify that Version is set and note that Commit and BuildDate may be empty in development builds.

Update .gitignore to ignore the .junie/ directory.
2026-03-02 18:41:27 +00:00
b8482b6fb0 feat(release): add automated release workflow and install script
Some checks failed
CI / Test (push) Successful in 26s
CI / Lint (push) Successful in 20s
CI / Build (push) Successful in 14s
Release / Create Release (push) Failing after 10s
- Embed version info in binaries via ldflags
- Create multi-platform builds, archives, and checksums
- Add Gitea release creation and asset upload in CI
- Introduce GoReleaser config for standardized builds
- Add version command and install script for easy deployment
- Update README with pre-built installation instructions
2026-03-01 23:25:31 +00:00
9f1309ba1a feat(lint): add lint command with AI-powered fixes
Introduce new `grokkit lint` command for automatic language detection,
linting, and AI-suggested fixes. Supports 9 languages including Go, Python,
JavaScript, TypeScript, Rust, Ruby, Java, C/C++, and Shell.

- Add cmd/lint.go for command implementation
- Create internal/linter package with detection and execution logic
- Update README.md with usage examples and workflows
- Enhance docs/ARCHITECTURE.md and docs/TROUBLESHOOTING.md
- Add comprehensive tests for linter functionality
2026-03-01 13:21:44 +00:00
13519438a2 test: add unit tests for chat history, edit helper, and code cleaning
- Introduce tests for chat history file handling, loading/saving, and error cases in cmd/chat_test.go
- Add tests for removeLastModifiedComments in cmd/edit_helper_test.go
- Add comprehensive tests for CleanCodeResponse in internal/grok/cleancode_test.go
- Update Makefile to centralize build artifacts in build/ directory for coverage reports and binary
- Adjust .gitignore to ignore chat_history.json and remove obsolete coverage file entries
2026-03-01 12:44:20 +00:00