@@ -266,11 +266,37 @@ export const PathInstructionsPlugin: Plugin = async (ctx) => {
266266
267267 if ( matching . length > 0 ) {
268268 for ( const instr of matching ) injected . add ( instr . filePath )
269- pendingInjections . set ( input . callID , { instructions : matching , relativePath } )
270- log (
271- `Queued ${ matching . length } instruction(s) for ${ relativePath } : ${ matching . map ( i => i . name ) . join ( ', ' ) } ` ,
272- 'debug' ,
273- )
269+
270+ if ( input . tool === 'write' || input . tool === 'edit' ) {
271+ const names = matching . map ( i => i . name )
272+ const instructionBlocks = matching
273+ . map ( instr => {
274+ const patterns = instr . applyTo . join ( ', ' )
275+ return [
276+ makeOpenMarker ( instr . name ) ,
277+ `Path Instructions: ${ instr . name } (applies to: ${ patterns } )` ,
278+ '' ,
279+ instr . content . trimEnd ( ) ,
280+ makeCloseMarker ( instr . name ) ,
281+ ] . join ( '\n' )
282+ } )
283+ . join ( '\n\n' )
284+
285+ log ( `Interrupting ${ input . tool } for ${ relativePath } to inject instructions: ${ names . join ( ', ' ) } ` )
286+ toast ( `Injected: ${ names . join ( ', ' ) } (for ${ relativePath } )` , 'info' , 3000 )
287+
288+ throw new Error (
289+ `Operation interrupted. New path-specific instructions apply to this file.\n` +
290+ `Please review the instructions below and retry your \`${ input . tool } \` operation taking them into account:\n\n` +
291+ instructionBlocks
292+ )
293+ } else {
294+ pendingInjections . set ( input . callID , { instructions : matching , relativePath } )
295+ log (
296+ `Queued ${ matching . length } instruction(s) for ${ relativePath } : ${ matching . map ( i => i . name ) . join ( ', ' ) } ` ,
297+ 'debug' ,
298+ )
299+ }
274300 }
275301 } ,
276302
@@ -348,12 +374,15 @@ export const PathInstructionsPlugin: Plugin = async (ctx) => {
348374
349375 for ( const message of output . messages ) {
350376 for ( const part of message . parts ) {
351- if ( part . type === 'tool' ) {
352- const toolState = part . state as { output ?: string }
353- if ( toolState ?. output ) {
354- for ( const name of extractMarkerNames ( toolState . output ) ) {
355- presentNames . add ( name )
356- }
377+ if ( part . type === 'tool' && part . state ) {
378+ const state = part . state as any
379+ let text = ''
380+ if ( typeof state . output === 'string' ) text += state . output + '\n'
381+ if ( typeof state . error === 'string' ) text += state . error + '\n'
382+ else if ( typeof state . error ?. message === 'string' ) text += state . error . message + '\n'
383+
384+ for ( const name of extractMarkerNames ( text ) ) {
385+ presentNames . add ( name )
357386 }
358387 }
359388 }
0 commit comments