1414 * Your instructions here...
1515 */
1616
17+ import type { Plugin } from '@opencode-ai/plugin'
1718import * as fs from 'node:fs'
1819import * as path from 'node:path'
19- import type { Plugin } from '@opencode-ai/plugin'
2020
2121interface InstructionFile {
2222 /** Glob patterns that determine when this instruction applies */
@@ -30,7 +30,7 @@ interface InstructionFile {
3030}
3131
3232/** File tools that operate on file paths */
33- const FILE_TOOLS = new Set ( [ 'edit' , 'write' ] )
33+ const FILE_TOOLS = new Set ( [ 'edit' , 'read' , ' write'] )
3434
3535/** Marker format used to track injected instructions in message history */
3636const MARKER_PREFIX = 'path-instruction'
@@ -221,7 +221,6 @@ export const PathInstructionsPlugin: Plugin = async (ctx) => {
221221 }
222222
223223 const projectDir = directory
224- const instructions = loadAllInstructionFiles ( projectDir )
225224
226225 // -------------------------------------------------------------------------
227226 // Instance-level state (scoped to this plugin invocation)
@@ -243,18 +242,6 @@ export const PathInstructionsPlugin: Plugin = async (ctx) => {
243242 const toast = ( message : string , variant : 'info' | 'success' | 'warning' | 'error' = 'info' , duration = 5000 ) =>
244243 client . tui . showToast ( { body : { title : '📋 Path Instructions' , message, variant, duration } } )
245244
246- if ( instructions . length === 0 ) {
247- log ( 'No path-specific instruction files found in .github/instructions or .opencode/instructions' )
248- toast ( 'No instruction files found' , 'warning' , 3000 )
249- } else {
250- const names = instructions . map ( i => i . name ) . join ( ', ' )
251- log ( `Loaded ${ instructions . length } path instruction file(s):` )
252- for ( const instr of instructions ) {
253- log ( ` ${ getRelativePath ( projectDir , instr . filePath ) } → applyTo: ${ instr . applyTo . join ( ', ' ) } ` )
254- }
255- toast ( `Loaded ${ instructions . length } instruction(s): ${ names } ` , 'success' , 4000 )
256- }
257-
258245 return {
259246 'tool.execute.before' : async ( input , output ) => {
260247 if ( ! FILE_TOOLS . has ( input . tool ) ) return
@@ -269,8 +256,9 @@ export const PathInstructionsPlugin: Plugin = async (ctx) => {
269256 sessionInjected . set ( sessionId , new Set ( ) )
270257 }
271258 const injected = sessionInjected . get ( sessionId ) !
259+ const currentInstructions = loadAllInstructionFiles ( projectDir )
272260
273- const matching = instructions . filter (
261+ const matching = currentInstructions . filter (
274262 instr =>
275263 ! injected . has ( instr . filePath ) &&
276264 instr . applyTo . some ( pattern => matchesGlob ( pattern , relativePath ) ) ,
@@ -320,7 +308,8 @@ export const PathInstructionsPlugin: Plugin = async (ctx) => {
320308 const injected = sessionInjected . get ( sessionId )
321309 if ( ! injected || injected . size === 0 ) return
322310
323- const activeInstructions = instructions . filter ( instr => injected . has ( instr . filePath ) )
311+ const currentInstructions = loadAllInstructionFiles ( projectDir )
312+ const activeInstructions = currentInstructions . filter ( instr => injected . has ( instr . filePath ) )
324313 if ( activeInstructions . length === 0 ) return
325314
326315 const blocks = activeInstructions
0 commit comments