Skip to content

Commit 819af39

Browse files
committed
#113 reverted
1 parent 5d163fe commit 819af39

File tree

11 files changed

+59
-61
lines changed

11 files changed

+59
-61
lines changed

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ linters:
1818
- unused
1919
- goconst
2020
settings:
21-
staticcheck:
22-
checks: ["all", "-ST1005"]
2321
goconst:
2422
min-len: 2
2523
min-occurrences: 2

internal/brain/deepseek.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (d *deepSeek) send(system, user string) (answer string, err error) {
6969
}
7070
data, err := json.Marshal(body)
7171
if err != nil {
72-
return "", fmt.Errorf("Error marshaling request body: %w", err)
72+
return "", fmt.Errorf("error marshaling request body: %w", err)
7373
}
7474
req, err := http.NewRequest("POST", d.url, bytes.NewBuffer(data))
7575
if err != nil {
@@ -79,23 +79,23 @@ func (d *deepSeek) send(system, user string) (answer string, err error) {
7979
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", d.token))
8080
resp, err := http.DefaultClient.Do(req)
8181
if err != nil {
82-
return "", fmt.Errorf("Error making request to deepseek api: %w", err)
82+
return "", fmt.Errorf("error making request to deepseek api: %w", err)
8383
}
8484
defer func() {
8585
if cerr := resp.Body.Close(); cerr != nil {
86-
err = fmt.Errorf("Error closing response body: %w", cerr)
86+
err = fmt.Errorf("error closing response body: %w", cerr)
8787
}
8888
}()
8989
if resp.StatusCode != 200 {
9090
content, _ := io.ReadAll(resp.Body)
91-
return "", fmt.Errorf("API error: %s", content)
91+
return "", fmt.Errorf("api error: %s", content)
9292
}
9393
var parsed deepseekResp
9494
if err = json.NewDecoder(resp.Body).Decode(&parsed); err != nil {
95-
return "", fmt.Errorf("Error decoding response: %w", err)
95+
return "", fmt.Errorf("error decoding response: %w", err)
9696
}
9797
if len(parsed.Choices) == 0 {
98-
return "", errors.New("No choices in response")
98+
return "", errors.New("no choices in response")
9999
}
100100
answer = parsed.Choices[0].Message.Content
101101
return answer, err

internal/brain/openai.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (o *openAI) send(system, user string) (answer string, err error) {
7171
req.Header.Set("Authorization", "Bearer "+o.token)
7272
resp, err := http.DefaultClient.Do(req)
7373
if err != nil {
74-
return "", fmt.Errorf("API request failed: %w", err)
74+
return "", fmt.Errorf("api request failed: %w", err)
7575
}
7676
defer func() {
7777
if cerr := resp.Body.Close(); cerr != nil {
@@ -80,7 +80,7 @@ func (o *openAI) send(system, user string) (answer string, err error) {
8080
}()
8181
if resp.StatusCode != http.StatusOK {
8282
body, _ := io.ReadAll(resp.Body)
83-
return "", fmt.Errorf("API error: %s", body)
83+
return "", fmt.Errorf("api error: %s", body)
8484
}
8585
var response openaiResp
8686
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {

internal/client/refrax_client.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewRefraxClient(params *Params) *RefraxClient {
3838
func Refactor(params *Params) (domain.Project, error) {
3939
proj, err := proj(*params)
4040
if err != nil {
41-
return nil, fmt.Errorf("Failed to create project from params: %w", err)
41+
return nil, fmt.Errorf("failed to create project from params: %w", err)
4242
}
4343
return NewRefraxClient(params).Refactor(proj)
4444
}
@@ -48,10 +48,10 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
4848
log.Debug("Starting refactoring for project %s", proj)
4949
classes, err := proj.Classes()
5050
if err != nil {
51-
return nil, fmt.Errorf("Failed to get classes from project %s: %w", proj, err)
51+
return nil, fmt.Errorf("failed to get classes from project %s: %w", proj, err)
5252
}
5353
if len(classes) == 0 {
54-
return proj, fmt.Errorf("No java classes found in the project %s, add java files to the appropriate directory", proj)
54+
return proj, fmt.Errorf("no java classes found in the project %s, add java files to the appropriate directory", proj)
5555
}
5656
log.Debug("Found %d classes in the project: %v", len(classes), classes)
5757

@@ -74,11 +74,11 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
7474
}
7575
criticBrain, err := mind(c.params, &criticSystemPrompt, criticStats)
7676
if err != nil {
77-
return nil, fmt.Errorf("Failed to create AI instance: %w", err)
77+
return nil, fmt.Errorf("failed to create AI instance: %w", err)
7878
}
7979
criticPort, err := util.FreePort()
8080
if err != nil {
81-
return nil, fmt.Errorf("Failed to find free port for critic: %w", err)
81+
return nil, fmt.Errorf("failed to find free port for critic: %w", err)
8282
}
8383
ctc := critic.NewCritic(criticBrain, criticPort)
8484
ctc.Handler(countStats(criticStats))
@@ -100,11 +100,11 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
100100
}
101101
fixerBrain, err := mind(c.params, &fixerSystemPrompt, fixerStats)
102102
if err != nil {
103-
return nil, fmt.Errorf("Failed to create AI instance: %w", err)
103+
return nil, fmt.Errorf("failed to create AI instance: %w", err)
104104
}
105105
fixerPort, err := util.FreePort()
106106
if err != nil {
107-
return nil, fmt.Errorf("Failed to find free port for fixer: %w", err)
107+
return nil, fmt.Errorf("failed to find free port for fixer: %w", err)
108108
}
109109
fxr := fixer.NewFixer(fixerBrain, fixerPort)
110110
fxr.Handler(countStats(fixerStats))
@@ -125,11 +125,11 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
125125
}
126126
reviewerBrain, err := mind(c.params, &reviewerSystemPrompt, reviewerStats)
127127
if err != nil {
128-
return nil, fmt.Errorf("Failed to create AI instance for reviewer: %w", err)
128+
return nil, fmt.Errorf("failed to create AI instance for reviewer: %w", err)
129129
}
130130
reviewerPort, err := util.FreePort()
131131
if err != nil {
132-
return nil, fmt.Errorf("Failed to find free port for reviewer: %w", err)
132+
return nil, fmt.Errorf("failed to find free port for reviewer: %w", err)
133133
}
134134
rvwr := reviewer.NewReviewer(reviewerBrain, reviewerPort, c.params.Checks...)
135135
rvwr.Handler(countStats(reviewerStats))
@@ -148,11 +148,11 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
148148
}
149149
facilitatorBrain, err := mind(c.params, &facilitatorSystemPrompt, facilitatorStats)
150150
if err != nil {
151-
return nil, fmt.Errorf("Failed to create AI instance: %w", err)
151+
return nil, fmt.Errorf("failed to create AI instance: %w", err)
152152
}
153153
facilitatorPort, err := util.FreePort()
154154
if err != nil {
155-
return nil, fmt.Errorf("Failed to find free port for facilitator: %w", err)
155+
return nil, fmt.Errorf("failed to find free port for facilitator: %w", err)
156156
}
157157
fclttor := facilitator.NewFacilitator(facilitatorBrain, ctc, fxr, rvwr, facilitatorPort)
158158
fclttor.Handler(countStats(facilitatorStats))
@@ -205,7 +205,7 @@ func (c *RefraxClient) Refactor(proj domain.Project) (domain.Project, error) {
205205
log.Info("Refactoring is finished")
206206
err = printStats(c.params, criticStats, fixerStats, facilitatorStats)
207207
if err != nil {
208-
return nil, fmt.Errorf("Failed to print statistics: %w", err)
208+
return nil, fmt.Errorf("failed to print statistics: %w", err)
209209
}
210210
return proj, err
211211
}
@@ -220,7 +220,7 @@ func refactor(f domain.Facilitator, p domain.Project, size int, ch chan<- refact
220220
log.Debug("Refactoring project %q", p)
221221
all, err := p.Classes()
222222
if err != nil {
223-
ch <- refactoring{err: fmt.Errorf("Failed to get classes from project %s: %w", p, err)}
223+
ch <- refactoring{err: fmt.Errorf("failed to get classes from project %s: %w", p, err)}
224224
close(ch)
225225
return
226226
}
@@ -240,7 +240,7 @@ func refactor(f domain.Facilitator, p domain.Project, size int, ch chan<- refact
240240
artifacts, err := f.Refactor(&job)
241241
if err != nil {
242242
log.Error("Failed to refactor project %s: %v", p, err)
243-
ch <- refactoring{err: fmt.Errorf("Failed to refactor project %s: %w", p, err)}
243+
ch <- refactoring{err: fmt.Errorf("failed to refactor project %s: %w", p, err)}
244244
close(ch)
245245
return
246246
}
@@ -349,24 +349,24 @@ func countStats(s *stats.Stats) protocol.Handler {
349349
start := time.Now()
350350
resp, err := next(nil, r)
351351
if err != nil {
352-
return nil, fmt.Errorf("Failed to process request: %w", err)
352+
return nil, fmt.Errorf("failed to process request: %w", err)
353353
}
354354
duration := time.Since(start)
355355
jsonresp, err := json.Marshal(resp)
356356
if err != nil {
357-
return nil, fmt.Errorf("Failed to marshal response: %w", err)
357+
return nil, fmt.Errorf("failed to marshal response: %w", err)
358358
}
359359
jsonreq, err := json.Marshal(r)
360360
if err != nil {
361-
return nil, fmt.Errorf("Failed to marshal request: %w", err)
361+
return nil, fmt.Errorf("failed to marshal request: %w", err)
362362
}
363363
reqt, err := stats.Tokens(string(jsonreq))
364364
if err != nil {
365-
return nil, fmt.Errorf("Failed to count tokens for request: %w", err)
365+
return nil, fmt.Errorf("failed to count tokens for request: %w", err)
366366
}
367367
respt, err := stats.Tokens(string(jsonresp))
368368
if err != nil {
369-
return nil, fmt.Errorf("Failed to count tokens for response: %w", err)
369+
return nil, fmt.Errorf("failed to count tokens for response: %w", err)
370370
}
371371
s.A2AReq(duration, reqt, respt, len(jsonreq), len(jsonresp))
372372
return resp, err

internal/critic/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (c *agent) Review(job *domain.Job) (*domain.Artifacts, error) {
4343
c.log.Debug("Rendered prompt for class %s: %s", class.Name(), prompt)
4444
answer, err := c.brain.Ask(prompt.String())
4545
if err != nil {
46-
return nil, fmt.Errorf("Failed to get answer from brain: %w", err)
46+
return nil, fmt.Errorf("failed to get answer from brain: %w", err)
4747
}
4848
suggestions := c.associated(parseAnswer(answer), class.Path())
4949
logSuggestions(c.log, suggestions)

internal/critic/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *Critic) ListenAndServe() error {
4141
c.log.Info("Starting critic server on port %d...", c.port)
4242
var err error
4343
if err = c.server.ListenAndServe(); err != nil && http.ErrServerClosed != err {
44-
return fmt.Errorf("Failed to start critic server: %w", err)
44+
return fmt.Errorf("failed to start critic server: %w", err)
4545
}
4646
return err
4747
}
@@ -53,7 +53,7 @@ func (c *Critic) Review(job *domain.Job) (*domain.Artifacts, error) {
5353
critic := protocol.NewClient(address)
5454
resp, err := critic.SendMessage(job.Marshal())
5555
if err != nil {
56-
return nil, fmt.Errorf("Failed to send message to critic: %w", err)
56+
return nil, fmt.Errorf("failed to send message to critic: %w", err)
5757
}
5858
return domain.UnmarshalArtifacts(resp.Result.(*protocol.Message))
5959
}
@@ -62,7 +62,7 @@ func (c *Critic) Review(job *domain.Job) (*domain.Artifacts, error) {
6262
func (c *Critic) Shutdown() error {
6363
c.log.Info("Stopping critic server...")
6464
if err := c.server.Shutdown(); err != nil {
65-
return fmt.Errorf("Failed to stop critic server: %w", err)
65+
return fmt.Errorf("failed to stop critic server: %w", err)
6666
}
6767
c.log.Info("Critic server stopped successfully")
6868
return nil
@@ -81,7 +81,7 @@ func (c *Critic) Ready() <-chan bool {
8181
func (c *Critic) think(ctx context.Context, m *protocol.Message) (*protocol.Message, error) {
8282
select {
8383
case <-ctx.Done():
84-
return nil, fmt.Errorf("Context canceled: %w", ctx.Err())
84+
return nil, fmt.Errorf("context canceled: %w", ctx.Err())
8585
default:
8686
return c.thinkLong(m)
8787
}
@@ -91,7 +91,7 @@ func (c *Critic) thinkLong(m *protocol.Message) (*protocol.Message, error) {
9191
c.log.Debug("Received message: #%s", m.MessageID)
9292
tsk, err := domain.UnmarshalJob(m)
9393
if err != nil {
94-
return nil, fmt.Errorf("Failed to parse task from message: %w", err)
94+
return nil, fmt.Errorf("failed to parse task from message: %w", err)
9595
}
9696
artifacts, err := c.agent.Review(tsk)
9797
return artifacts.Marshal().Message, err

internal/facilitator/agent.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ type agent struct {
2424
func (a *agent) Refactor(job *domain.Job) (*domain.Artifacts, error) {
2525
size, err := maxSize(job)
2626
if err != nil {
27-
return nil, fmt.Errorf("Failed to get max size limit: %w", err)
27+
return nil, fmt.Errorf("failed to get max size limit: %w", err)
2828
}
2929
if job.Descr.Text != "refactor the project" {
3030
a.log.Warn("Received a message that is not related to refactoring, ignoring")
31-
return nil, fmt.Errorf("Received a message that is not related to refactoring")
31+
return nil, fmt.Errorf("received a message that is not related to refactoring")
3232
}
3333
classes := job.Classes
3434
nclasses := len(classes)
@@ -53,7 +53,7 @@ func (a *agent) Refactor(job *domain.Job) (*domain.Artifacts, error) {
5353
for range nreviewed {
5454
impr := <-ch
5555
if impr.err != nil {
56-
return nil, fmt.Errorf("Failed to review class: %w", impr.err)
56+
return nil, fmt.Errorf("failed to review class: %w", impr.err)
5757
}
5858
improvements = append(improvements, impr.important)
5959
}
@@ -67,7 +67,7 @@ func (a *agent) Refactor(job *domain.Job) (*domain.Artifacts, error) {
6767
}
6868
mostImportant, err := a.mostFrequent(improvements)
6969
if err != nil {
70-
return nil, fmt.Errorf("Failed to get most frequent suggestions: %w", err)
70+
return nil, fmt.Errorf("failed to get most frequent suggestions: %w", err)
7171
}
7272
a.log.Info("Received %d most frequent suggestions from brain", len(mostImportant))
7373
refactored := make([]domain.Class, 0)
@@ -104,12 +104,12 @@ func (a *agent) Refactor(job *domain.Job) (*domain.Artifacts, error) {
104104
err = class.SetContent(c.Content())
105105
a.log.Info("Setting content for class %s (%s)", class.Name(), class.Path())
106106
if err != nil {
107-
return nil, fmt.Errorf("Failed to set content for class %s: %w", class.Name(), err)
107+
return nil, fmt.Errorf("failed to set content for class %s: %w", class.Name(), err)
108108
}
109109
}
110110
err = a.stabilize(refactored)
111111
if err != nil {
112-
return nil, fmt.Errorf("Failed to stabilize refactored classes: %w", err)
112+
return nil, fmt.Errorf("failed to stabilize refactored classes: %w", err)
113113
}
114114
res := &domain.Artifacts{
115115
Descr: &domain.Description{Text: "refactored classes"},
@@ -129,7 +129,7 @@ func (a *agent) stabilize(refactored []domain.Class) error {
129129
counter := 3
130130
for len(improvements) > 0 && counter > 0 {
131131
if err != nil {
132-
return fmt.Errorf("Failed to review project: %w", err)
132+
return fmt.Errorf("failed to review project: %w", err)
133133
}
134134
perclass := a.understandClasses(refactored, improvements)
135135
for k, v := range perclass {
@@ -142,14 +142,14 @@ func (a *agent) stabilize(refactored []domain.Class) error {
142142
}
143143
fixed, uerr := a.fixer.Fix(&job)
144144
if uerr != nil {
145-
return fmt.Errorf("Failed to fix project: %w", uerr)
145+
return fmt.Errorf("failed to fix project: %w", uerr)
146146
}
147147
updated := fixed.Classes[0]
148148
class := domain.NewFSClass(k.Name(), k.Path())
149149
a.log.Info("Updating class %s (%s) with new content", class.Name(), class.Path())
150150
uerr = class.SetContent(updated.Content())
151151
if uerr != nil {
152-
return fmt.Errorf("Failed to set content for class %s: %w", class.Name(), uerr)
152+
return fmt.Errorf("failed to set content for class %s: %w", class.Name(), uerr)
153153
}
154154
}
155155
counter--
@@ -188,7 +188,7 @@ func (a *agent) fix(imp improvement, example domain.Class, ch chan<- fixResult)
188188
}
189189
modified, err := a.fixer.Fix(&job)
190190
if err != nil {
191-
ch <- fixResult{fmt.Errorf("Failed to ask fixer: %w", err), nil}
191+
ch <- fixResult{fmt.Errorf("failed to ask fixer: %w", err), nil}
192192
return
193193
}
194194
ch <- fixResult{nil, modified.Classes[0]}
@@ -204,7 +204,7 @@ func (a *agent) review(class domain.Class, ch chan<- improvementResult) {
204204
}
205205
suggestions, err := a.critic.Review(&job)
206206
if err != nil {
207-
ch <- improvementResult{err: fmt.Errorf("Failed to ask critic: %w", err), important: improvement{class: class}}
207+
ch <- improvementResult{err: fmt.Errorf("failed to ask critic: %w", err), important: improvement{class: class}}
208208
return
209209
}
210210
a.log.Info("Received %d suggestions from critic", len(suggestions.Suggestions))
@@ -259,7 +259,7 @@ func (a *agent) mostFrequent(improvements []improvement) ([]improvement, error)
259259
}
260260
important, err := a.brain.Ask(prompt.String())
261261
if err != nil {
262-
return nil, fmt.Errorf("Failed to ask the brain to group suggestions: %w", err)
262+
return nil, fmt.Errorf("failed to ask the brain to group suggestions: %w", err)
263263
}
264264

265265
prompt = prompts.User{
@@ -271,7 +271,7 @@ func (a *agent) mostFrequent(improvements []improvement) ([]improvement, error)
271271
a.log.Info("Choosing the most important suggestions...")
272272
important, err = a.brain.Ask(prompt.String())
273273
if err != nil {
274-
return nil, fmt.Errorf("Failed to ask brain for most frequent suggestion: %w", err)
274+
return nil, fmt.Errorf("failed to ask brain for most frequent suggestion: %w", err)
275275
}
276276
classSuggestions := make(map[string][]string, 0)
277277
for s := range strings.SplitSeq(strings.ReplaceAll(important, "\r\n", "\n"), "\n") {
@@ -294,7 +294,7 @@ func (a *agent) mostFrequent(improvements []improvement) ([]improvement, error)
294294
for k, v := range classSuggestions {
295295
class, err := findClass(improvements, k)
296296
if err != nil {
297-
return nil, fmt.Errorf("Failed to find class %s in improvements: %w", k, err)
297+
return nil, fmt.Errorf("failed to find class %s in improvements: %w", k, err)
298298
}
299299
var suggetions []domain.Suggestion
300300
for _, s := range v {
@@ -314,7 +314,7 @@ func findClass(improvements []improvement, path string) (domain.Class, error) {
314314
return imp.class, nil
315315
}
316316
}
317-
return nil, fmt.Errorf("Class %s not found in improvements", path)
317+
return nil, fmt.Errorf("class %s not found in improvements", path)
318318
}
319319

320320
func maxSize(t *domain.Job) (int, error) {

0 commit comments

Comments
 (0)