@@ -10,12 +10,24 @@ class TemplateLoader {
1010 await this . loadTemplateFromUrl ( template ) :
1111 await this . loadTemplateFromPath ( template )
1212 }
13+ const expandedPrompt = await this . parseTemplate ( prompt , context )
1314 const engine = new Liquid ( )
1415 engine . registerFilter ( "jsonToObject" , ( json ) => JSON . parse ( json ) )
15- const tpl = engine . parse ( templateText )
16+ const tpl = engine . parse ( templateText )
1617 const content = await engine . render ( tpl , {
1718 context : context ,
18- prompt : prompt
19+ prompt : expandedPrompt
20+ } )
21+ return content
22+ }
23+
24+ static async parseTemplate ( text , context ) {
25+ const engine = new Liquid ( )
26+ engine . registerFilter ( "jsonToObject" , ( json ) => JSON . parse ( json ) )
27+ const tpl = engine . parse ( text )
28+ const content = await engine . render ( tpl , {
29+ context : context ,
30+ prompt : text
1931 } )
2032 return content
2133 }
@@ -38,7 +50,7 @@ class TemplateLoader {
3850
3951 static getTemplateText ( template ) {
4052 if ( template === 'refactor' ) {
41- return `The user's request is: {{prompt}}
53+ return `{{prompt}}
4254{% if context.files.size > 0 %}
4355###
4456The following are file paths and content related to this request.
@@ -54,9 +66,9 @@ File: {{ item.filename }} """
5466 if ( template === 'empty' ) {
5567 return `{% if context.files.size > 0 %}You will be provided the contents of some files.
5668The contents of each file begin with "--BEGIN-FILE:" followed by the file path.
57- The contents of each file end with "--END-FILE--".{% endif %}
58-
59- Your instructions are: {{prompt}}
69+ The contents of each file end with "--END-FILE--".
70+ {% endif %}
71+ {{prompt}}
6072{% if context.files.size > 0 %}The file contents are below:{% endif %}
6173{% for item in context.files %}
6274--BEGIN-FILE: {{ item.filename }}
0 commit comments