@@ -36,48 +36,61 @@ def get_keypress():
36
36
termios .tcsetattr (fd , termios .TCSADRAIN , old_settings )
37
37
return key
38
38
39
+ def print_response (command : str ):
40
+ print (f"{ BLUE } Command found:" )
41
+ print (f"{ BLUE } =====================" )
42
+ print (f"{ GREEN } { command } { RESET } " ) # Print the command in green
43
+ print (f"{ BLUE } ====================={ RESET } " )
44
+
45
+ print (f"{ BLUE } What do you want to do with this command?{ RESET } " )
46
+ print (f"{ BLUE } [c] Copy [e] Execute [a] Abort{ RESET } " )
47
+ print (f"{ BLUE } Press key: " , end = "" , flush = True )
48
+ choice = get_keypress ().lower ()
49
+ print (f"{ RESET } " ) # Clear the line after the prompt
50
+
51
+ if choice == "e" :
52
+ print (f"{ BLUE } Executing command: { command } { RESET } " )
53
+ result = subprocess .run (command , shell = True , capture_output = True , text = True )
54
+ print (f"{ GREEN } Command output: { result .stdout } { RESET } " )
55
+ if result .stderr :
56
+ print (f"{ RED } Error: { result .stderr } { RESET } " )
57
+
58
+ elif choice == "c" :
59
+ pyperclip .copy (command )
60
+ print (f"{ GREEN } Command copied to clipboard! Paste it manually in your terminal.{ RESET } " )
61
+
62
+ elif choice == "a" :
63
+ print (f"{ BLUE } Aborted.{ RESET } " )
64
+ else :
65
+ print (f"{ RED } Unknown choice. Nothing happened.{ RESET } " )
66
+
39
67
def one_shot_mode (agent : LLMAgent , prompt : str ):
40
68
try :
41
69
response = agent .one_shot_mode (prompt )
42
- print (f"{ GREEN } : { response } { RESET } " )
43
- command = response .strip ()
44
-
45
- print (f"{ BLUE } What do you want to do with this command?{ RESET } " )
46
- print (f"{ BLUE } [c] Copy [e] Execute [a] Abort{ RESET } " )
47
- print (f"{ BLUE } Press key: " , end = "" , flush = True )
48
- choice = get_keypress ().lower ()
49
- print (f"{ RESET } " ) # Clear the line after the prompt
50
-
51
- if choice == "e" :
52
- print (f"{ BLUE } Executing command: { command } { RESET } " )
53
- result = subprocess .run (command , shell = True , capture_output = True , text = True )
54
- print (f"{ GREEN } Command output: { result .stdout } { RESET } " )
55
- if result .stderr :
56
- print (f"{ RED } Error: { result .stderr } { RESET } " )
57
-
58
- elif choice == "c" :
59
- pyperclip .copy (command )
60
- print (f"{ GREEN } Command copied to clipboard! Paste it manually in your terminal.{ RESET } " )
61
-
62
- elif choice == "a" :
63
- print (f"{ BLUE } Aborted.{ RESET } " )
64
- else :
65
- print (f"{ RED } Unknown choice. Nothing happened.{ RESET } " )
66
-
70
+ print_response (response )
67
71
except Exception as e :
68
72
print (f"{ RED } Error: { e } { RESET } " )
69
73
74
+ def print_help_message ():
75
+ """Print help message with usage examples."""
76
+ print (f"{ BLUE } Open Codex - Natural Language to CLI commands{ RESET } " )
77
+ print (f"{ BLUE } Usage examples:{ RESET } " )
78
+ print (f"{ GREEN } open-codex \" list all files in current directory\" " )
79
+ print (f"{ GREEN } open-codex \" find all python files modified in the last week\" " )
80
+ print (f"{ GREEN } open-codex \" create a tarball of the src directory\" " )
81
+ print ()
82
+
70
83
def main ():
71
84
parser = argparse .ArgumentParser (description = "Open Codex - Natural Language to CLI commands" )
72
85
parser .add_argument ("prompt" , nargs = "*" , help = "Optional prompt for one-shot mode" )
73
86
args = parser .parse_args ()
74
-
75
87
prompt = " " .join (args .prompt ).strip ()
76
- if not prompt :
77
- print ( "Please provide a prompt" )
88
+ if not prompt or prompt == "--help" :
89
+ print_help_message ( )
78
90
sys .exit (1 )
79
91
80
92
agent = AgentBuilder .get_agent ()
93
+ print (f"{ BLUE } Using model: phi-4-mini-instruct{ RESET } " )
81
94
one_shot_mode (agent , prompt )
82
95
83
96
if __name__ == "__main__" :
0 commit comments