@@ -27,6 +27,7 @@ use std::{
2727} ;
2828
2929use anyhow:: { Result , bail} ;
30+ use but_action:: cli:: get_cli_path;
3031use but_core:: ref_metadata:: StackId ;
3132use but_ctx:: { Context , ThreadSafeContext } ;
3233use gitbutler_stack:: VirtualBranchesHandle ;
@@ -505,7 +506,7 @@ async fn spawn_command(
505506 let mut ctx = sync_ctx. clone ( ) . into_thread_local ( ) ;
506507 format_branch_info ( & mut ctx, stack_id)
507508 } ;
508- let system_prompt = format ! ( "{}\n \n {}" , SYSTEM_PROMPT , branch_info) ;
509+ let system_prompt = format ! ( "{}\n \n {}" , system_prompt ( ) , branch_info) ;
509510 command. args ( [ "--append-system-prompt" , & system_prompt] ) ;
510511
511512 if !user_params. add_dirs . is_empty ( ) {
@@ -538,18 +539,44 @@ async fn spawn_command(
538539 Ok ( command. spawn ( ) ?)
539540}
540541
541- const SYSTEM_PROMPT : & str = "<git-usage>
542- You are working on a project that is managed by GitButler.
542+ fn system_prompt ( ) -> String {
543+ let but_path = get_cli_path ( )
544+ . map ( |p| p. to_string_lossy ( ) . into_owned ( ) )
545+ . unwrap_or_else ( |_| "but" . to_string ( ) ) ;
543546
544- This means that you MUST NOT run git commands that checkout branches or update heads.
547+ format ! (
548+ "<git-usage>
549+ CRITICAL: You are working on a project that is managed by GitButler.
545550
546- For example you MUST NOT run the following git commands:
547- - git commit
551+ ## PROHIBITED Git Commands
552+
553+ You MUST NOT run the following git commands:
554+ - git status (file change info is provided in <branch-info> below)
555+ - git commit (use `{0}` instead)
548556- git checkout
557+ - git squash
549558- git rebase
550559- git cherry-pick
551560
552- You MAY run git commands that give you information about the current git state.
561+ These commands modify branches or provide information already available to you.
562+
563+ ## What You CAN Do
564+
565+ - Run git commands that give read-only information about the repository (git log, git diff, etc.)
566+ - Use the GitButler CLI (`{0}`) to perform disallowed actions
567+ - Reference file changes and uncommitted changes from the <branch-info> section provided below
568+
569+ ## Using the GitButler CLI
570+
571+ Disallowed actions can instead be performed using `{0}`.
572+ For help with available commands, consult `{0} --help`.
573+
574+ Common commands:
575+ - `{0} status` - View changes assigned to this branch
576+ - `{0} commit -m \" message\" ` - Commit changes to this branch
577+ - `{0} rub <source> <target>` - Amend, squash, assign files, etc.
578+
579+ ## Communication Guidelines
553580
554581DO NOT mention GitButler unless the user asks you to perform a disallowed git action.
555582
@@ -570,7 +597,25 @@ Can you pull in the latest changes
570597Sorry, this project is managed by GitButler so you must integrate upstream upstream changes through the GitButler interface.
571598</response>
572599</example>
573- </git-usage>" ;
600+
601+ <example>
602+ <user>
603+ What files have changed?
604+ </user>
605+ <response>
606+ Based on the branch-info provided, the following files have been modified in this branch:
607+
608+ Committed changes (in branch commits):
609+ [Lists files that were changed in the commits shown in the branch]
610+
611+ Uncommitted changes (assigned to this stack):
612+ [Lists files from the uncommitted files section]
613+ </response>
614+ </example>
615+ </git-usage>" ,
616+ but_path
617+ )
618+ }
574619
575620/// Formats branch information for the system prompt
576621fn format_branch_info ( ctx : & mut Context , stack_id : StackId ) -> String {
@@ -584,7 +629,9 @@ fn format_branch_info(ctx: &mut Context, stack_id: StackId) -> String {
584629 branch listed below, not the workspace branch itself.\n \n \
585630 Changes and diffs should be understood relative to the target branch (upstream), as that\n \
586631 represents the integration point for this work.\n \n \
587- When asked about uncommitted changes you must only consider changes assigned to the stack.\n \n ",
632+ IMPORTANT: This section includes both COMMITTED changes (in branch commits below) and\n \
633+ UNCOMMITTED changes (in the assigned files section). When asked about file changes,\n \
634+ consider both committed and uncommitted changes.\n \n ",
588635 ) ;
589636
590637 append_target_branch_info ( & mut output, ctx) ;
@@ -673,7 +720,7 @@ fn append_assigned_files_info(output: &mut String, stack_id: StackId, ctx: &mut
673720 let mut file_paths: Vec < _ > = file_assignments. keys ( ) . copied ( ) . collect ( ) ;
674721 file_paths. sort ( ) ;
675722
676- output. push_str ( "\n Files currently assigned to this stack:\n " ) ;
723+ output. push_str ( "\n Uncommitted files assigned to this stack:\n " ) ;
677724 for file_path in file_paths {
678725 format_file_with_line_ranges ( output, file_path, & file_assignments[ file_path] ) ;
679726 }
0 commit comments