@@ -266,6 +266,31 @@ func (r *REPL) loadRCFile() error {
266266 return nil
267267}
268268
269+ func (r * REPL ) findMaiMD () (string , error ) {
270+ if ! r .config .options .GetBool ("usemaimd" ) {
271+ return "" , nil
272+ }
273+ currentDir , err := os .Getwd ()
274+ if err != nil {
275+ return "" , err
276+ }
277+ for {
278+ maiPath := filepath .Join (currentDir , "MAI.md" )
279+ if _ , err := os .Stat (maiPath ); err == nil {
280+ content , err := os .ReadFile (maiPath )
281+ if err != nil {
282+ return "" , err
283+ }
284+ return string (content ), nil
285+ }
286+ parentDir := filepath .Dir (currentDir )
287+ if parentDir == currentDir {
288+ return "" , nil
289+ }
290+ currentDir = parentDir
291+ }
292+ }
293+
269294func (r * REPL ) Run () error {
270295 defer r .cleanup ()
271296
@@ -295,6 +320,7 @@ func (r *REPL) Run() error {
295320 return nil
296321}
297322
323+
298324func (r * REPL ) setupHistory () error {
299325 if ! r .config .options .GetBool ("history" ) {
300326 return nil
@@ -1422,8 +1448,20 @@ func (r *REPL) sendToAI(input string) error {
14221448
14231449 // Add system prompt if present
14241450 messages := []Message {}
1425- if r .systemPrompt != "" {
1426- messages = append (messages , Message {Role : "system" , Content : r .systemPrompt })
1451+ maiMdPrompt , err := r .findMaiMD ()
1452+ if err != nil {
1453+ fmt .Fprintf (os .Stderr , "Error finding MAI.md: %v\r \n " , err )
1454+ }
1455+ finalSystemPrompt := r .systemPrompt
1456+ if maiMdPrompt != "" {
1457+ if finalSystemPrompt != "" {
1458+ finalSystemPrompt += "\n \n " + maiMdPrompt
1459+ } else {
1460+ finalSystemPrompt = maiMdPrompt
1461+ }
1462+ }
1463+ if finalSystemPrompt != "" {
1464+ messages = append (messages , Message {Role : "system" , Content : finalSystemPrompt })
14271465 }
14281466
14291467 // Handle conversation history based on logging and reply settings
0 commit comments