@@ -17,17 +17,11 @@ export interface PromptData {
1717 max_tokens ?: number
1818}
1919
20- /**
21- * Get the prompts directory path
22- */
2320export function getPromptsDir ( ) : string {
2421 const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
2522 return path . join ( __dirname , '../prompts' )
2623}
2724
28- /**
29- * Dynamically discover available editor types from prompt files
30- */
3125export function getAvailableEditorTypes ( promptDir : string ) : string [ ] {
3226 const editorTypes : string [ ] = [ ]
3327
@@ -46,16 +40,10 @@ export function getAvailableEditorTypes(promptDir: string): string[] {
4640 return editorTypes
4741}
4842
49- /**
50- * Get formatted description of available refinement types
51- */
5243export function getRefinementDescriptions ( editorTypes : string [ ] ) : string {
5344 return editorTypes . join ( ', ' )
5445}
5546
56- /**
57- * Enrich context for intro prompt on index.md files
58- */
5947export function enrichIndexContext ( filePath : string , content : string ) : string {
6048 if ( ! filePath . endsWith ( 'index.md' ) ) return content
6149
@@ -72,7 +60,6 @@ export function enrichIndexContext(filePath: string, content: string): string {
7260 . join ( ' ' )
7361 : ''
7462
75- // Get child article titles
7663 const titles : string [ ] = [ ]
7764 if ( data . children && Array . isArray ( data . children ) ) {
7865 const dir = path . dirname ( filePath )
@@ -94,7 +81,6 @@ export function enrichIndexContext(filePath: string, content: string): string {
9481 }
9582 }
9683
97- // Build context note
9884 const parts : string [ ] = [ ]
9985 if ( productName ) parts . push ( `Product: ${ productName } ` )
10086 if ( titles . length > 0 ) parts . push ( `Child articles: ${ titles . join ( ', ' ) } ` )
@@ -114,24 +100,19 @@ export function enrichIndexContext(filePath: string, content: string): string {
114100 return content
115101}
116102
117- /**
118- * Call an editor with the given content and options
119- */
120103export async function callEditor (
121104 editorType : string ,
122105 content : string ,
123106 promptDir : string ,
124107 writeMode : boolean ,
125108 verbose = false ,
126- promptContent ?: string , // Optional: use this instead of reading from file
109+ promptContent ?: string , // Use this instead of reading a prompt file
127110) : Promise < string > {
128111 let markdownPrompt : string
129112
130113 if ( promptContent ) {
131- // Use provided prompt content (e.g., from Copilot Space)
132114 markdownPrompt = promptContent
133115 } else {
134- // Read from file
135116 const markdownPromptPath = path . join ( promptDir , `${ editorType } .md` )
136117
137118 if ( ! fs . existsSync ( markdownPromptPath ) ) {
@@ -144,15 +125,15 @@ export async function callEditor(
144125
145126 const prompt = load ( fs . readFileSync ( promptTemplatePath , 'utf8' ) ) as PromptData
146127
147- // Validate the prompt template has required properties
148128 if ( ! prompt . messages || ! Array . isArray ( prompt . messages ) ) {
149129 throw new Error ( 'Invalid prompt template: missing or invalid messages array' )
150130 }
151131
152132 for ( const msg of prompt . messages ) {
153133 msg . content = msg . content . replace ( '{{markdownPrompt}}' , markdownPrompt )
154134 msg . content = msg . content . replace ( '{{input}}' , content )
155- // Replace writeMode template variable with simple string replacement
135+ // Resolve the write-mode markers, then strip whatever they marked
136+ // for removal.
156137 msg . content = msg . content . replace (
157138 / < ! - - I F _ W R I T E _ M O D E - - > / g,
158139 writeMode ? '' : '<!-- REMOVE_START -->' ,
@@ -166,7 +147,6 @@ export async function callEditor(
166147 writeMode ? '' : '<!-- REMOVE_END -->' ,
167148 )
168149
169- // Remove sections marked for removal
170150 msg . content = msg . content . replace ( / < ! - - R E M O V E _ S T A R T - - > [ \s \S ] * ?< ! - - R E M O V E _ E N D - - > / g, '' )
171151 }
172152
0 commit comments