feat(workon): integrate Grok for work plan generation

Replace placeholder with actual Grok client call to generate and append a tailored work plan section to todo/fix files. Add prompt engineering for concise, actionable plans. Include file content reading and model config integration. Update comments and error handling for clarity.
This commit is contained in:
Greg Gauthier 2026-03-31 21:20:55 +01:00
parent 49ec38a2ca
commit 8a3257b3a7

View File

@ -6,13 +6,13 @@ import (
"os/exec"
"path/filepath"
"gmgauthier.com/grokkit/config"
"gmgauthier.com/grokkit/internal/grok"
"gmgauthier.com/grokkit/internal/logger"
"gmgauthier.com/grokkit/internal/todo"
// TODO: Import the real Grok client once we wire it (standard pattern is internal/grok)
// e.g. "gmgauthier.com/grokkit/internal/grok"
)
// Run executes the full transactional workon flow per todo/doing/workon.md.
// Run executes the full transactional workon flow per todo/doing/workon.md spec.
func Run(title, customMsg string, isFix, isComplete bool) error {
if title == "" {
return fmt.Errorf("todo_item_title is required")
@ -48,7 +48,7 @@ func Run(title, customMsg string, isFix, isComplete bool) error {
return fmt.Errorf("failed to create branch %s: %w", branchName, err)
}
// 4. Generate and append Work Plan via Grok
// 4. Generate + append Work Plan via Grok
if err := appendWorkPlan(mdPath, title); err != nil {
return fmt.Errorf("failed to generate/append Work Plan: %w", err)
}
@ -85,7 +85,7 @@ func createFixFile(path, title string) error {
}
func createGitBranch(name string) error {
// Safe: if branch already exists, just checkout it
// Safe: if branch already exists, just checkout it; else create new
if err := exec.Command("git", "checkout", name).Run(); err == nil {
return nil
}
@ -93,29 +93,45 @@ func createGitBranch(name string) error {
}
func appendWorkPlan(path, title string) error {
// TODO: Replace with real Grok client call (internal/grok pattern from analyze/commit/etc.)
// 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.
content := readFileContent(path)
// 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"
prompt := fmt.Sprintf(`You are helping implement a todo item titled "%s".
Here is the current markdown content of the todo/fix file:
%s
Generate a concise, actionable **Work Plan** section.
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, no introduction.`, title, content)
// Real Grok call using the project's standard client (StreamSilent for clean output)
client := grok.NewClient()
model := config.GetModel("workon", "grok-4-fast-non-reasoning")
plan := client.StreamSilent([]map[string]string{
{"role": "system", "content": "You are a precise software engineering assistant."},
{"role": "user", "content": prompt},
}, model) // or pull model from config/env if available
// Append the plan
f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer func(f *os.File) {
err := f.Close()
if err != nil {
defer func() {
if cerr := f.Close(); cerr != nil {
logger.Error("failed to close todo file", "err", cerr)
}
}(f)
}()
_, err = f.WriteString(plan)
return err
}
func readFileContent(path string) string {
b, _ := os.ReadFile(path)
return string(b)
}
func commitChanges(msg string) error {
if err := exec.Command("git", "add", "todo/").Run(); err != nil {
return err