grokkit/.grokkit/recipes/result-refactor.md
Greg Gauthier 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

2.1 KiB

name description version parameters project_languages extensions search_pattern allowed_shell_commands
result-refactor Convert traditional Go error handling to Result[T] monadic style 1.0
package_path dry_run
type default description
string internal/git Package to refactor
type default description
bool true If true, only generate patches
go
go
.go
if err != nil
go test ./...
go fmt ./...
go vet ./...
rg --files
git diff --name-only
jq

Result[T] Refactoring Recipe

Overview
Refactors all error handling in the target package to use the new Result[T] pattern.

Execution Steps

Step 1: Explore project structure

Objective: Get a clear view of the current project layout.
Instructions: Use safe read-only shell commands to show the directory tree and key files. Expected output: A tree view and relevant file contents.

Step 2: Discover files

Objective: Find every file that needs changing.
Instructions: Recursively scan {{.package_path}} for .go files containing if err != nil.
Expected output: A clean list of full file paths (one per line). If none, say "No files found matching the criteria."

Step 3: Refactor each file

Objective: Generate the updated code.
Instructions: For each file from Step 1:

  • Read the full original content.
  • Refactor it to use Result[T] instead of naked errors (follow existing style, preserve all comments).
  • Return ONLY a single JSON array in this exact format (no extra text, no markdown):
[
  {
    "file": "internal/example.go",
    "content": "the complete refactored file here"
  }
]

Step 4: Apply or patch

Objective: Safely write changes or create reviewable output. Instructions:

  • If dry_run is true → create a unified diff patch file for review.
  • If false → write the new files (backup originals as .bak). Expected output: Confirmation of what was written + full path to any patch file.

Final Summary

Give me a concise executive summary: number of files changed, any warnings or patterns you noticed, and your recommended next step.