78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
package author
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/draft"
|
|
"git.a-wan.net/alan/pipelines/internal/harness"
|
|
)
|
|
|
|
//go:embed skill/SKILL.md skill/references/*.md manager/SKILL.md
|
|
var content embed.FS
|
|
|
|
// Command launches the normal CLI directly. Skill loading and questions belong
|
|
// to OpenCode; no session/API/backend discovery is performed before launch.
|
|
func Command(ctx context.Context, executable string, d draft.Draft, request, cli string) (*exec.Cmd, error) {
|
|
dir, err := SkillDirectory()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if _, err := os.Stat(filepath.Join(dir, "SKILL.md")); err != nil {
|
|
return nil, fmt.Errorf("pipelines skill is not installed; run pipelines skill install: %w", err)
|
|
}
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cmd := exec.CommandContext(ctx, executable, cwd, "--prompt", Prompt(d, request, cli))
|
|
cmd.Dir = cwd
|
|
return cmd, nil
|
|
}
|
|
|
|
func Prompt(d draft.Draft, request, command string) string {
|
|
prompt := fmt.Sprintf("@pipelines\nDraft context: %q\nCLI: %s", d.Path+".json", command)
|
|
if strings.TrimSpace(request) != "" {
|
|
prompt += "\nRequest: " + request
|
|
prompt += "\nFirst response: briefly acknowledge the request, then read only the draft and relevant authoring references."
|
|
} else {
|
|
task := "What should this pipeline do?"
|
|
if !d.CreateOnly && d.BaseVersion > 0 {
|
|
task = "What would you like to change in this pipeline?"
|
|
}
|
|
prompt += "\nFirst response: ask the user " + fmt.Sprintf("%q", task) + " before reading files or running commands. Load the skill if needed; do not investigate before asking."
|
|
}
|
|
return prompt
|
|
}
|
|
|
|
func HarnessCommand(ctx context.Context, name string, d draft.Draft, request, cli string) (*exec.Cmd, error) {
|
|
skill, err := SkillDirectory()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if _, err := os.Stat(filepath.Join(skill, "SKILL.md")); err != nil {
|
|
return nil, fmt.Errorf("pipelines skill is not installed; run pipelines skill install: %w", err)
|
|
}
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
prompt := Prompt(d, request, cli)
|
|
config, err := harness.Load()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if name == "" {
|
|
name = config.Default
|
|
}
|
|
if name == "pi" {
|
|
prompt = strings.Replace(prompt, "@pipelines", "/skill:pipelines", 1)
|
|
}
|
|
return harness.Command(ctx, name, cwd, prompt, skill)
|
|
}
|