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:
parent
49ec38a2ca
commit
8a3257b3a7
@ -6,13 +6,13 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"gmgauthier.com/grokkit/config"
|
||||||
|
"gmgauthier.com/grokkit/internal/grok"
|
||||||
"gmgauthier.com/grokkit/internal/logger"
|
"gmgauthier.com/grokkit/internal/logger"
|
||||||
"gmgauthier.com/grokkit/internal/todo"
|
"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 {
|
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")
|
||||||
@ -48,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 and append Work Plan via Grok
|
// 4. Generate + 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)
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ func createFixFile(path, title string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createGitBranch(name 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 {
|
if err := exec.Command("git", "checkout", name).Run(); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -93,29 +93,45 @@ func createGitBranch(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func appendWorkPlan(path, title string) error {
|
func appendWorkPlan(path, title string) error {
|
||||||
// TODO: Replace with real Grok client call (internal/grok pattern from analyze/commit/etc.)
|
content := readFileContent(path)
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Temporary placeholder (keeps it functional)
|
prompt := fmt.Sprintf(`You are helping implement a todo item titled "%s".
|
||||||
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"
|
|
||||||
|
|
||||||
|
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)
|
f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func(f *os.File) {
|
defer func() {
|
||||||
err := f.Close()
|
if cerr := f.Close(); cerr != nil {
|
||||||
if err != nil {
|
logger.Error("failed to close todo file", "err", cerr)
|
||||||
|
|
||||||
}
|
}
|
||||||
}(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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user