@@ -124,43 +124,56 @@ func (a *Agent) processOutput(ctx context.Context, output LinterOutput, ref conf
124124 return newOutput , true
125125}
126126
127- // ApplyTypedMessageByIssueReferences applies the issue references to the lint results with the typed message.
128- func (a * Agent ) ApplyTypedMessageByIssueReferences (ctx context.Context , lintResults map [string ][]LinterOutput ) map [string ][]LinterOutput {
129- log := util .FromContext (ctx )
127+ // EnrichWithIssueReferences applies the issue references to the lint results with the typed message.
128+ func (a * Agent ) EnrichWithIssueReferences (ctx context.Context , lintResults map [string ][]LinterOutput ) map [string ][]LinterOutput {
130129 msgFormat := getMsgFormat (a .LinterConfig .ReportType )
131- newLintResults := make (map [string ][]LinterOutput , len (lintResults ))
130+ enriched := make (map [string ][]LinterOutput , len (lintResults ))
132131
133132 // Process each file's outputs
134133 for file , outputs := range lintResults {
135- newOutputs := make ([]LinterOutput , 0 , len ( outputs ) )
134+ newOutputs := append ([]LinterOutput ( nil ), outputs ... )
136135
137136 // Apply each reference pattern
138- for _ , output := range outputs {
139- processed := false
137+ for i , output := range outputs {
140138 for _ , ref := range a .IssueReferences {
141139 if newOutput , ok := a .processOutput (ctx , output , ref , msgFormat ); ok {
142- newOutputs = append (newOutputs , newOutput )
143- processed = true
140+ newOutputs [i ] = newOutput
144141 break
145142 }
146143 }
147- if ! processed {
144+ }
145+
146+ if len (newOutputs ) > 0 {
147+ enriched [file ] = newOutputs
148+ }
149+ }
150+ return enriched
151+ }
152+
153+ // EnrichWithLLM enriches the lint results with LLM generated content.
154+ func (a * Agent ) EnrichWithLLM (ctx context.Context , lintResults map [string ][]LinterOutput ) map [string ][]LinterOutput {
155+ log := util .FromContext (ctx )
156+ enriched := make (map [string ][]LinterOutput , len (lintResults ))
157+
158+ for file , outputs := range lintResults {
159+ newOutputs := append ([]LinterOutput (nil ), outputs ... )
160+
161+ for i , output := range outputs {
162+ // only enrich the output that is not typed
163+ if output .TypedMessage == "" {
148164 resp , err := llm .QueryForReference (ctx , a .ModelClient , output .Message )
149165 if err != nil {
150166 log .Errorf ("failed to query LLM server: %v" , err )
151167 } else {
152- output .TypedMessage = output .Message + fmt .Sprintf (ReferenceFooter , resp )
168+ newOutputs [ i ] .TypedMessage = newOutputs [ i ] .Message + fmt .Sprintf (ReferenceFooter , resp )
153169 }
154- newOutputs = append (newOutputs , output )
155170 }
156171 }
157-
158172 if len (newOutputs ) > 0 {
159- newLintResults [file ] = newOutputs
173+ enriched [file ] = newOutputs
160174 }
161175 }
162-
163- return newLintResults
176+ return enriched
164177}
165178
166179const ReferenceFooter = `
0 commit comments