Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRootCmd(out, _ io.Writer) *cobra.Command {
root.PersistentFlags().StringVar(&params.Soutput, "stats-output", "stats", "Output path for statistics")
root.PersistentFlags().BoolVar(&params.Colorless, "no-colors", false, "Disable colored output")
root.PersistentFlags().StringVarP(&params.Model, "model", "m", "", "Model to use (if supported by the AI provider)")
root.PersistentFlags().IntVar(&params.Attempts, "attempts", 3, "How many attempts the AI has to make a valid refactoring")
root.AddCommand(
newRefactorCmd(&params),
newStartCmd(),
Expand Down
2 changes: 2 additions & 0 deletions internal/client/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Params struct {
Checks []string
Colorless bool
Model string
Attempts int
}

// NewMockParams creates a new Params object with mock settings.
Expand All @@ -39,5 +40,6 @@ func NewMockParams() *Params {
Checks: []string{"mvn clean test"},
Colorless: false,
Model: "gpt-3.5-turbo",
Attempts: 3,
}
}
2 changes: 1 addition & 1 deletion internal/client/refrax_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
if err != nil {
return nil, fmt.Errorf("failed to find free port for facilitator: %w", err)
}
fclttor := facilitator.NewFacilitator(facilitatorBrain, ctc, fxr, rvwr, facilitatorPort, c.params.Colorless)
fclttor := facilitator.NewFacilitator(facilitatorBrain, ctc, fxr, rvwr, facilitatorPort, c.params.Colorless, c.params.Attempts)
fclttor.Handler(countStats(facilitatorStats))

go func() {
Expand Down
11 changes: 10 additions & 1 deletion internal/facilitator/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type agent struct {
fixer domain.Fixer
reviewer domain.Reviewer
frounds int
attempts int
}

type fix struct {
Expand All @@ -45,7 +46,14 @@ func (a *agent) Refactor(job *domain.Job) (*domain.Artifacts, error) {
}
diff := 0
result := make([]domain.Class, 0)
for diff < size {
attempts := a.attempts
if attempts <= 0 {
a.log.Info("Number of attempts less or equal zero (%d), skipping refactoring", attempts)
} else {
a.log.Info("Starting refactoring with max-size=%d and attempts=%d", size, attempts)
}
for diff < size && attempts > 0 {
a.log.Info("Refactoring attempt %d/%d, current diff %d/%d", a.attempts-attempts+1, a.attempts, diff, size)
c, err := a.criticizeAll(job.Classes, size)
if err != nil {
return nil, fmt.Errorf("failed to criticize classes: %w", err)
Expand Down Expand Up @@ -81,6 +89,7 @@ func (a *agent) Refactor(job *domain.Job) (*domain.Artifacts, error) {
if err != nil {
return nil, fmt.Errorf("failed to stabilize refactored classes: %w", err)
}
attempts--
}
res := &domain.Artifacts{
Descr: &domain.Description{Text: "refactored classes"},
Expand Down
3 changes: 2 additions & 1 deletion internal/facilitator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type A2AFacilitator struct {
}

// NewFacilitator creates a new instance of Facilitator to manage communication between agents.
func NewFacilitator(ai brain.Brain, critic domain.Critic, fixer domain.Fixer, reviewer domain.Reviewer, port int, colorless bool) *A2AFacilitator {
func NewFacilitator(ai brain.Brain, critic domain.Critic, fixer domain.Fixer, reviewer domain.Reviewer, port int, colorless bool, attempts int) *A2AFacilitator {
logger := log.New("facilitator", log.Yellow, colorless)
logger.Debug("preparing server on port %d with ai provider %s", port, ai)
server := protocol.NewServer(agentCard(port), port)
Expand All @@ -35,6 +35,7 @@ func NewFacilitator(ai brain.Brain, critic domain.Critic, fixer domain.Fixer, re
fixer: fixer,
reviewer: reviewer,
frounds: 3,
attempts: attempts,
},
}
server.MsgHandler(facilitator.think)
Expand Down