@@ -146,20 +146,150 @@ var promptTemplates = template.Must(template.New("prompt-templates").ParseFS(
146146 "templates/*.md.gotmpl" ,
147147))
148148
149+ func markdownSectionFromView (view * markdownSectionView ) * MarkdownSection {
150+ if view == nil {
151+ return nil
152+ }
153+ return & MarkdownSection {Heading : view .Heading , Body : view .Body }
154+ }
155+
156+ func reviewCommentsFromView (views []reviewCommentView ) []ReviewCommentTemplateContext {
157+ comments := make ([]ReviewCommentTemplateContext , 0 , len (views ))
158+ for _ , view := range views {
159+ comments = append (comments , ReviewCommentTemplateContext (view ))
160+ }
161+ return comments
162+ }
163+
164+ func previousReviewsFromView (views []previousReviewView ) []PreviousReviewTemplateContext {
165+ reviews := make ([]PreviousReviewTemplateContext , 0 , len (views ))
166+ for _ , view := range views {
167+ reviews = append (reviews , PreviousReviewTemplateContext {
168+ Commit : view .Commit ,
169+ Output : view .Output ,
170+ Comments : reviewCommentsFromView (view .Comments ),
171+ Available : view .Available ,
172+ })
173+ }
174+ return reviews
175+ }
176+
177+ func reviewAttemptsFromView (views []reviewAttemptView ) []ReviewAttemptTemplateContext {
178+ attempts := make ([]ReviewAttemptTemplateContext , 0 , len (views ))
179+ for _ , view := range views {
180+ attempts = append (attempts , ReviewAttemptTemplateContext {
181+ Label : view .Label ,
182+ Agent : view .Agent ,
183+ When : view .When ,
184+ Output : view .Output ,
185+ Comments : reviewCommentsFromView (view .Comments ),
186+ })
187+ }
188+ return attempts
189+ }
190+
191+ func reviewOptionalContextFromView (view optionalSectionsView ) ReviewOptionalContext {
192+ return ReviewOptionalContext {
193+ ProjectGuidelines : markdownSectionFromView (view .ProjectGuidelines ),
194+ AdditionalContext : view .AdditionalContext ,
195+ PreviousReviews : previousReviewsFromView (view .PreviousReviews ),
196+ PreviousAttempts : reviewAttemptsFromView (view .PreviousAttempts ),
197+ }
198+ }
199+
200+ func fallbackContextFromDiffSection (view diffSectionView ) FallbackContext {
201+ if view .Fallback == "" {
202+ return FallbackContext {}
203+ }
204+ return FallbackContext {Mode : FallbackModeGeneric , Text : view .Fallback }
205+ }
206+
207+ func templateContextFromSingleView (view singlePromptView ) TemplateContext {
208+ return TemplateContext {
209+ Review : & ReviewTemplateContext {
210+ Kind : ReviewKindSingle ,
211+ Optional : reviewOptionalContextFromView (view .Optional ),
212+ Subject : SubjectContext {Single : & SingleSubjectContext {
213+ Commit : view .Current .Commit ,
214+ Subject : view .Current .Subject ,
215+ Author : view .Current .Author ,
216+ Message : view .Current .Message ,
217+ }},
218+ Diff : DiffContext {Heading : view .Diff .Heading , Body : view .Diff .Body },
219+ Fallback : fallbackContextFromDiffSection (view .Diff ),
220+ },
221+ }
222+ }
223+
224+ func templateContextFromRangeView (view rangePromptView ) TemplateContext {
225+ entries := make ([]RangeEntryContext , 0 , len (view .Current .Entries ))
226+ for _ , entry := range view .Current .Entries {
227+ entries = append (entries , RangeEntryContext (entry ))
228+ }
229+ return TemplateContext {
230+ Review : & ReviewTemplateContext {
231+ Kind : ReviewKindRange ,
232+ Optional : reviewOptionalContextFromView (view .Optional ),
233+ Subject : SubjectContext {Range : & RangeSubjectContext {Count : view .Current .Count , Entries : entries }},
234+ Diff : DiffContext {Heading : view .Diff .Heading , Body : view .Diff .Body },
235+ Fallback : fallbackContextFromDiffSection (view .Diff ),
236+ },
237+ }
238+ }
239+
240+ func templateContextFromDirtyView (view dirtyPromptView ) TemplateContext {
241+ fallback := fallbackContextFromDiffSection (view .Diff )
242+ if fallback .Text != "" {
243+ fallback .Mode = FallbackModeDirty
244+ fallback .Dirty = & DirtyFallbackContext {Body : fallback .Text }
245+ fallback .Text = ""
246+ }
247+ return TemplateContext {
248+ Review : & ReviewTemplateContext {
249+ Kind : ReviewKindDirty ,
250+ Optional : reviewOptionalContextFromView (view .Optional ),
251+ Subject : SubjectContext {Dirty : & DirtySubjectContext {Description : view .Current .Description }},
252+ Diff : DiffContext {Heading : view .Diff .Heading , Body : view .Diff .Body },
253+ Fallback : fallback ,
254+ },
255+ }
256+ }
257+
258+ func templateContextFromAddressView (view addressPromptView ) TemplateContext {
259+ attempts := make ([]AddressAttemptTemplateContext , 0 , len (view .PreviousAttempts ))
260+ for _ , attempt := range view .PreviousAttempts {
261+ attempts = append (attempts , AddressAttemptTemplateContext (attempt ))
262+ }
263+ return TemplateContext {
264+ Address : & AddressTemplateContext {
265+ ProjectGuidelines : markdownSectionFromView (view .ProjectGuidelines ),
266+ PreviousAttempts : attempts ,
267+ SeverityFilter : view .SeverityFilter ,
268+ ReviewFindings : view .ReviewFindings ,
269+ OriginalDiff : view .OriginalDiff ,
270+ JobID : view .JobID ,
271+ },
272+ }
273+ }
274+
275+ func templateContextFromSystemView (view systemPromptView ) TemplateContext {
276+ return TemplateContext {System : & SystemTemplateContext {NoSkillsInstruction : view .NoSkillsInstruction , CurrentDate : view .CurrentDate }}
277+ }
278+
149279func renderSinglePrompt (view singlePromptView ) (string , error ) {
150- return executePromptTemplate ("assembled_single.md.gotmpl" , view )
280+ return executePromptTemplate ("assembled_single.md.gotmpl" , templateContextFromSingleView ( view ) )
151281}
152282
153283func renderRangePrompt (view rangePromptView ) (string , error ) {
154- return executePromptTemplate ("assembled_range.md.gotmpl" , view )
284+ return executePromptTemplate ("assembled_range.md.gotmpl" , templateContextFromRangeView ( view ) )
155285}
156286
157287func renderDirtyPrompt (view dirtyPromptView ) (string , error ) {
158- return executePromptTemplate ("assembled_dirty.md.gotmpl" , view )
288+ return executePromptTemplate ("assembled_dirty.md.gotmpl" , templateContextFromDirtyView ( view ) )
159289}
160290
161291func renderAddressPrompt (view addressPromptView ) (string , error ) {
162- return executePromptTemplate ("assembled_address.md.gotmpl" , view )
292+ return executePromptTemplate ("assembled_address.md.gotmpl" , templateContextFromAddressView ( view ) )
163293}
164294
165295func fitSinglePrompt (limit int , view singlePromptView ) (string , error ) {
@@ -313,7 +443,7 @@ func trimOptionalSections(view *optionalSectionsView) bool {
313443}
314444
315445func renderSystemPrompt (name string , view systemPromptView ) (string , error ) {
316- return executePromptTemplate (name , view )
446+ return executePromptTemplate (name , templateContextFromSystemView ( view ) )
317447}
318448
319449func renderAddressPromptFromSections (view addressPromptView ) (string , error ) {
@@ -357,7 +487,11 @@ func renderDirtyChangesSection(view dirtyChangesSectionView) (string, error) {
357487}
358488
359489func renderDiffBlock (view diffSectionView ) (string , error ) {
360- return executePromptTemplate ("diff_block" , view )
490+ ctx := ReviewTemplateContext {
491+ Diff : DiffContext {Heading : view .Heading , Body : view .Body },
492+ Fallback : fallbackContextFromDiffSection (view ),
493+ }
494+ return executePromptTemplate ("diff_block" , ctx )
361495}
362496
363497func renderInlineDiff (body string ) (string , error ) {
0 commit comments