refactor(workon): clean up stubs and add TODOs for Grok integration

- Remove temporary grokClient interface and prompt logic.
- Add TODOs for real Grok client import and calls.
- Placeholder work plan for functionality.
- TODOs for README index update and IDE config support.
- Minor comment and logging tweaks for clarity.
This commit is contained in:
Greg Gauthier 2026-03-31 21:04:40 +01:00
parent 9694d72463
commit 49ec38a2ca

View File

@ -8,16 +8,11 @@ import (
"gmgauthier.com/grokkit/internal/logger" "gmgauthier.com/grokkit/internal/logger"
"gmgauthier.com/grokkit/internal/todo" "gmgauthier.com/grokkit/internal/todo"
// Grok client will be imported from the project's main Grok package (adjust if needed based on existing cmds) // TODO: Import the real Grok client once we wire it (standard pattern is internal/grok)
// Example: assuming a client in internal/grok or similar; replace with actual import from master pattern // e.g. "gmgauthier.com/grokkit/internal/grok"
) )
// TODO: replace with actual Grok client import from the codebase (e.g. internal/grok or wherever analyze/chat uses it) // Run executes the full transactional workon flow per todo/doing/workon.md.
type grokClient interface {
Generate(prompt string) (string, error)
}
// Run executes the full transactional workon flow per todo/doing/workon.md spec.
func Run(title, customMsg string, isFix, isComplete bool) error { func Run(title, customMsg string, isFix, isComplete bool) error {
if title == "" { if title == "" {
return fmt.Errorf("todo_item_title is required") return fmt.Errorf("todo_item_title is required")
@ -25,7 +20,7 @@ func Run(title, customMsg string, isFix, isComplete bool) error {
logger.Info("workon starting", "title", title, "fix", isFix, "complete", isComplete) logger.Info("workon starting", "title", title, "fix", isFix, "complete", isComplete)
// 1. Bootstrap // 1. Bootstrap todo structure if missing
if err := todo.Bootstrap(); err != nil { if err := todo.Bootstrap(); err != nil {
return fmt.Errorf("todo bootstrap failed: %w", err) return fmt.Errorf("todo bootstrap failed: %w", err)
} }
@ -34,7 +29,7 @@ func Run(title, customMsg string, isFix, isComplete bool) error {
return completeItem(title, isFix) return completeItem(title, isFix)
} }
// 2. Todo or Fix mode // 2. Handle todo or fix mode
branchName := title branchName := title
mdPath := filepath.Join("todo", "doing", title+".md") mdPath := filepath.Join("todo", "doing", title+".md")
@ -53,7 +48,7 @@ func Run(title, customMsg string, isFix, isComplete bool) error {
return fmt.Errorf("failed to create branch %s: %w", branchName, err) return fmt.Errorf("failed to create branch %s: %w", branchName, err)
} }
// 4. Generate + append Work Plan via Grok // 4. Generate and append Work Plan via Grok
if err := appendWorkPlan(mdPath, title); err != nil { if err := appendWorkPlan(mdPath, title); err != nil {
return fmt.Errorf("failed to generate/append Work Plan: %w", err) return fmt.Errorf("failed to generate/append Work Plan: %w", err)
} }
@ -90,27 +85,22 @@ func createFixFile(path, title string) error {
} }
func createGitBranch(name string) error { func createGitBranch(name string) error {
// Safe: if branch exists, just checkout; else create // Safe: if branch already exists, just checkout it
if err := exec.Command("git", "checkout", name).Run(); err == nil { if err := exec.Command("git", "checkout", name).Run(); err == nil {
return nil // already exists return nil
} }
return exec.Command("git", "checkout", "-b", name).Run() return exec.Command("git", "checkout", "-b", name).Run()
} }
func appendWorkPlan(path, title string) error { func appendWorkPlan(path, title string) error {
// Real Grok call (stub client shown; replace with actual from codebase) // TODO: Replace with real Grok client call (internal/grok pattern from analyze/commit/etc.)
prompt := fmt.Sprintf(`You are helping implement a todo item titled "%s". // Example:
// client := grok.NewClient()
// plan, err := client.Query(prompt) // or Generate, etc.
// Use the full todo content + a clean prompt asking only for "## Work Plan" section.
Here is the current markdown content of the todo/fix file: // Temporary placeholder (keeps it functional)
plan := "\n## Work Plan\n\n1. Review the todo/fix requirements.\n2. Implement the changes in the appropriate package.\n3. Add or update tests if applicable.\n4. Verify with `go test` and `grokkit lint`.\n5. Commit and push the branch.\n"
%s
Generate a concise, actionable **Work Plan** section to append under the heading "## Work Plan".
Use numbered steps, be specific to this item, include testing and commit notes where relevant.
Output ONLY the markdown starting with "## Work Plan" no extra text.`, title, readFileContent(path))
// TODO: call actual Grok client here (e.g. client.Generate(prompt))
plan := "\n## Work Plan\n\n1. Review requirements in the todo file.\n2. Implement the changes.\n3. Add tests if applicable.\n4. Commit and push.\n" // replace with real response
f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644) f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil { if err != nil {
@ -119,18 +109,13 @@ Output ONLY the markdown starting with "## Work Plan" — no extra text.`, title
defer func(f *os.File) { defer func(f *os.File) {
err := f.Close() err := f.Close()
if err != nil { if err != nil {
logger.Error("failed to close file", "err", err)
} }
}(f) }(f)
_, err = f.WriteString(plan) _, err = f.WriteString(plan)
return err return err
} }
func readFileContent(path string) string {
b, _ := os.ReadFile(path)
return string(b)
}
func commitChanges(msg string) error { func commitChanges(msg string) error {
if err := exec.Command("git", "add", "todo/").Run(); err != nil { if err := exec.Command("git", "add", "todo/").Run(); err != nil {
return err return err
@ -145,10 +130,9 @@ func completeItem(title string, isFix bool) error {
return fmt.Errorf("move to completed failed: %w", err) return fmt.Errorf("move to completed failed: %w", err)
} }
// Update index README for todos only // TODO: update todo/README.md index under ## Completed (for non-fixes)
if !isFix { if !isFix {
// TODO: append to ## Completed section in todo/README.md logger.Info("TODO: update index README for completed todo")
logger.Info("index README updated for completed todo")
} }
commitMsg := fmt.Sprintf("Complete work on %s", title) commitMsg := fmt.Sprintf("Complete work on %s", title)
@ -165,6 +149,7 @@ func runCnaddIfAvailable(title string) {
} }
func openIDEIfConfigured() { func openIDEIfConfigured() {
// TODO: implement once minimal internal/config supports IDE.command // TODO: implement via config once internal/config or root config supports IDE command
// For now, silent graceful fallback per spec
logger.Debug("IDE open skipped (config support pending)") logger.Debug("IDE open skipped (config support pending)")
} }