package planflow import ( "encoding/json" "unicode/utf8" "amadan.net/oficina/equipo/internal/equipo/team" "amadan.net/oficina/equipo/internal/runnerproto" ) var ErrPromptTooLarge = runnerproto.ErrPromptTooLarge const MaxPromptBytes = 24 << 10 // LegacyStep preserves only the original fixed bug protocol. func LegacyStep(key string) runnerproto.StepBrief { action := key if key == "verify" { action = "checks" } specialist := "engineering" if key == "review" || key == "verify" { specialist = "review" } return runnerproto.StepBrief{PlanRevision: 1, StepKey: key, Action: action, SpecialistKey: specialist, SpecialistRevision: 1} } type promptFile struct { Path string `json:"path"` Text string `json:"text"` } type turnPrompt struct { RenderAvailable bool `json:"render_available,omitempty"` Action string Sources []runnerproto.SourceSnapshot `json:"sources,omitempty"` Step string Instructions string `json:"instructions"` StandingInstructions string `json:"standing_instructions"` Target team.TargetBinding `json:"target"` ExpectedSymptom string `json:"expected_symptom,omitempty"` Files []promptFile `json:"reproduction_files,omitempty"` Tests []team.TestIdentity `json:"reproduction_tests,omitempty"` CandidateCommit string `json:"candidate_commit,omitempty"` } func Prompt(assignment runnerproto.Assignment, brief runnerproto.RunnerBrief, artifacts []team.Artifact) (string, error) { p := turnPrompt{RenderAvailable: brief.RenderRecipe != nil, Action: brief.Step.Action, Sources: brief.Sources, Step: assignment.StepKey, Instructions: brief.Instructions, StandingInstructions: brief.StandingInstructions, Target: brief.Target} if brief.Target.Kind == team.TargetProjectRead && p.Action == "scope" { p.Action = "recommend" } for _, a := range artifacts { switch a.Role { case team.RoleReproduction, team.RoleAcceptance: var r runnerproto.Reproduction if err := json.Unmarshal(a.Payload, &r); err != nil { return "", err } p.ExpectedSymptom, p.Tests = r.ExpectedSymptom, r.TestNames for _, f := range r.Files { if !utf8.Valid(f.Bytes) { return "", runnerproto.ErrInvalid } p.Files = append(p.Files, promptFile{f.Path, string(f.Bytes)}) } case team.RoleCandidate: var candidate team.GitCandidate if err := json.Unmarshal(a.Payload, &candidate); err != nil { return "", err } p.CandidateCommit = candidate.Commit } } raw, err := json.Marshal(p) if err != nil { return "", err } if len(raw) > MaxPromptBytes { return "", ErrPromptTooLarge } return string(raw), nil }