mini-code-cli 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,17 +23,40 @@ def save_history(messages):
23
23
  with open("history.json", "w") as f:
24
24
  json.dump(messages, f, indent=2)
25
25
 
26
+
26
27
  def parse_args():
27
28
  parser = argparse.ArgumentParser(description="Agent loop for interacting with a language model")
28
29
  parser.add_argument("--url", type=str, default="http://0.0.0.0:30000", help="API host")
30
+ parser.add_argument("--system_prompt", type=str, help="API host")
29
31
  parser.add_argument("--api-key", type=str, default=None, help="API key for authentication")
30
32
  parser.add_argument("--allowed-dir", type=str, default=".", help="Allowed directory for file operations")
31
- parser.add_argument("--max-tokens", type=int, default=2048, help="Maximum tokens for LLM response")
33
+ parser.add_argument("--max-tokens", type=int, help="Maximum tokens for LLM response")
32
34
  parser.add_argument("--temperature", type=float, default=0.0, help="Temperature for LLM")
33
35
  parser.add_argument("--model", type=str, default="default", help="Model name")
34
36
  args = parser.parse_args()
35
37
  return args
36
38
 
39
+ def print_welcome(allowed_dir, server_url):
40
+ # Calculate the length of the longest line inside the box
41
+ lines = [
42
+ " Coding Agent Loop Started",
43
+ " Type 'quit' or 'exit' to exit the loop.",
44
+ f" Allowed dir: {allowed_dir}",
45
+ f" Server URL: {server_url}"
46
+ ]
47
+ max_len = max(len(line) for line in lines)
48
+ margin = 2 # Space on each side inside the box
49
+ inner_width = max_len + 2 * margin
50
+ # Build the box
51
+ top_bottom = "╔" + "═" * inner_width + "╗"
52
+ print(top_bottom)
53
+ for line in lines:
54
+ # Pad the line to inner_width characters
55
+ padded = line.ljust(inner_width)
56
+ print(f"║{padded}║")
57
+ bottom = "╚" + "═" * inner_width + "╝"
58
+ print(bottom)
59
+
37
60
  def main():
38
61
  args = parse_args()
39
62
 
@@ -43,17 +66,14 @@ def main():
43
66
  tools_dict = tools.util_get_tools_dict()
44
67
  llm_tools_dict = tools.util_get_tools()
45
68
 
46
- system_prompt = prompts.system_prompt(tools_dict=tools_dict, allowed_dir=allowed_dir)
69
+ if args.system_prompt:
70
+ system_prompt = args.system_prompt
71
+ else:
72
+ system_prompt = prompts.system_prompt(tools_dict=tools_dict, allowed_dir=allowed_dir)
47
73
 
48
74
  messages = [{"role": "system", "content": system_prompt}]
49
75
 
50
- print(f"""
51
- ╔═══════════════════════════════════════════════════════════════════╗
52
- ║ Coding Agent Loop Started\t\t\t\t\t║
53
- ║ Type 'quit' or 'exit' to exit the loop.\t\t\t\t║
54
- ║ Allowed dir: {allowed_dir}\t║
55
- ╚═══════════════════════════════════════════════════════════════════╝
56
- """)
76
+ print_welcome(allowed_dir, server_url)
57
77
 
58
78
  while True:
59
79
  llm_response_flag = False
@@ -90,42 +110,42 @@ def main():
90
110
  if tool_calls:
91
111
  # Tool call parsing and execution
92
112
  print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call {len(tool_calls)} tools.")
93
- if tool_calls:
94
- for call in tool_calls:
95
- call_id = call.get("id", "")
96
- name = call.get("function", {}).get("name", "")
97
- params_str = call.get("function", {}).get("arguments", "{}")
98
- try:
99
- tool_params = json.loads(params_str)
100
- except json.JSONDecodeError:
101
- print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
102
- continue
103
-
104
- if name in tools_dict:
105
- # Check allowed directory for file operations
106
- if name in ["read_file", "write_file", "grep", "glob"]:
113
+
114
+ for call in tool_calls:
115
+ call_id = call.get("id", "")
116
+ name = call.get("function", {}).get("name", "")
117
+ params_str = call.get("function", {}).get("arguments", "{}")
118
+ try:
119
+ tool_params = json.loads(params_str)
120
+ except json.JSONDecodeError:
121
+ print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
122
+ continue
123
+
124
+ if name in tools_dict:
125
+ # Check allowed directory for file operations
126
+ if name in ["read_file", "write_file", "grep", "glob"]:
127
+ filepath = tool_params.get("filepath", "")
128
+ if name == "write_file":
107
129
  filepath = tool_params.get("filepath", "")
108
- if name == "write_file":
109
- filepath = tool_params.get("filepath", "")
110
- if filepath and not os.path.abspath(filepath).startswith(allowed_dir):
111
- print(f"{BOLD}{RED}Warning:{RESET} File operation not allowed outside allowed directory: {allowed_dir}")
112
- continue
113
-
114
- func = tools_dict[name]["function"]
115
- result = func(**tool_params)
116
- # Limiting output to 300 characters for readability
117
- result_str = str(result)
118
- if len(result_str) > 300:
119
- result_str = result_str[:300] + "... (truncated to 300 chars)"
120
- print(f"{BOLD}{MAGENTA}Tool '{name}' returned:{RESET} {result_str}")
121
-
122
- messages.append({
123
- "role": "tool",
124
- "tool_call_id": call_id,
125
- "content": str(result)
126
- })
127
- else:
128
- print(f"{BOLD}{RED}Warning:{RESET} Unknown tool: {name}")
130
+ if filepath and not os.path.abspath(filepath).startswith(allowed_dir):
131
+ print(f"{BOLD}{RED}Warning:{RESET} File operation not allowed outside allowed directory: {allowed_dir}")
132
+ continue
133
+
134
+ func = tools_dict[name]["function"]
135
+ result = func(**tool_params)
136
+ # Limiting output to 300 characters for readability
137
+ result_str = str(result)
138
+ if len(result_str) > 300:
139
+ result_str = result_str[:300] + "... (truncated to 300 chars)"
140
+ print(f"{BOLD}{MAGENTA}Tool '{name}' returned:{RESET} {result_str}")
141
+
142
+ messages.append({
143
+ "role": "tool",
144
+ "tool_call_id": call_id,
145
+ "content": str(result)
146
+ })
147
+ else:
148
+ print(f"{BOLD}{RED}Warning:{RESET} Unknown tool: {name}")
129
149
  else:
130
150
  llm_tool_response_flag = True
131
151
 
mini_code_cli/prompts.py CHANGED
@@ -3,22 +3,30 @@ def system_prompt(tools_dict=None, allowed_dir=None):
3
3
  """
4
4
  Takes a list of tool names and returns a system prompt string.
5
5
  """
6
- allowed_dir_prompt = ""
7
- if allowed_dir:
8
- allowed_dir_prompt = f"\nThe path you are allowed to operate in is called: {allowed_dir}"
6
+
9
7
  if tools_dict:
10
8
  tool_descriptions = "\n".join([f"{name} : {data['description']}" for name, data in tools_dict.items()])
11
- base_prompt = "You are a helpful AI coding assistant with access to the following tools:\n"
12
- end_prompt = "\n\nWhen answering, first use available tools if needed, then provide a compact summary of the results."
9
+ base_prompt = "You are a helpful AI assistant with access to the following tools:\n"
10
+ end_prompt = (
11
+ "Choose the most appropriate tool for the task at hand. "
12
+ "If a tool fails or you hit a limit, analyze the error and try a different approach. "
13
+ "Be concise and efficient in your tool usage."
14
+ )
13
15
  else:
14
16
  tool_descriptions = ""
15
- base_prompt = "You are a helpful AI coding assistant without any tools."
17
+ base_prompt = "You are a helpful AI assistant without any tools."
16
18
  end_prompt = ""
19
+
20
+
21
+ allowed_dir_prompt = ""
22
+ if allowed_dir:
23
+ allowed_dir_prompt = f"\nThe path you are allowed to operate in is called: {allowed_dir}"
24
+
17
25
 
18
26
  prompt = f"""
19
27
  {base_prompt}
20
28
  {tool_descriptions}{end_prompt}{allowed_dir_prompt}
21
- Keep responses concise and focused.
29
+ Important: Only follow the user instruction. Do not create additional .md files (unless asked to do so). Do not create unit tests (unless asked to do so), etc.
22
30
  """
23
31
  return prompt.strip()
24
32
 
mini_code_cli/tools.py CHANGED
@@ -31,7 +31,7 @@ def grep(pattern, filepath):
31
31
  except Exception as e:
32
32
  return f"Error: {e}"
33
33
 
34
- def glob(pattern):
34
+ def glob(pattern="./"):
35
35
  """Return list of file paths matching the given glob pattern. Param: pattern"""
36
36
  try:
37
37
  return glob_module.glob(pattern)
mini_code_cli/utils.py CHANGED
@@ -19,9 +19,9 @@ def call_openai_server(messages, max_tokens=2048, temperature=0.0, top_p=0.95, m
19
19
  payload = {
20
20
  "model": model,
21
21
  "messages": messages,
22
- "max_tokens": max_tokens,
23
22
  "temperature": temperature,
24
- "top_p": top_p
23
+ # "max_tokens": max_tokens,
24
+ # "top_p": top_p
25
25
  }
26
26
 
27
27
  if tools:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mini-code-cli
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: Minimal Coding CLI
5
5
  Author-email: Nikolai Rozanov <nikolai.rozanov@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -0,0 +1,11 @@
1
+ mini_code_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ mini_code_cli/agent_loop.py,sha256=IC02Hs2oBx4C1apFXmJ2E3ESmJLP8v2Z6_0ApLDdZo4,5877
3
+ mini_code_cli/prompts.py,sha256=1dY5f7pSvfDnjhA-uDmi0Rw66_JFQGfooF699pATO0E,1985
4
+ mini_code_cli/tools.py,sha256=RO51ZJ61NV_R8KqsW9me4-0HPhjgS3DMoKrASLBvYJI,4931
5
+ mini_code_cli/utils.py,sha256=HlmuLH0V4AxZTg0_ZGzlxffqRqs7T3W6FQXaBhioGdk,3647
6
+ mini_code_cli-0.0.7.dist-info/licenses/LICENSE,sha256=WCkMINUFi--UtEg_alEE2FBKPtNKkzi7dGzaxzchifc,1088
7
+ mini_code_cli-0.0.7.dist-info/METADATA,sha256=6_sPZqA8K3sMvMSufEi6__6favkr6O63yBdq17ZC5S0,1943
8
+ mini_code_cli-0.0.7.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
9
+ mini_code_cli-0.0.7.dist-info/entry_points.txt,sha256=MwDp5UbXpI7wodSmOSYL8_nKutnBiyp96ZDDtaX7x14,60
10
+ mini_code_cli-0.0.7.dist-info/top_level.txt,sha256=3Hb6PpNkJYXvzDKXuuFJRvzCdsTRh0TuRWz-ScJ6qV0,14
11
+ mini_code_cli-0.0.7.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- mini_code_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mini_code_cli/agent_loop.py,sha256=qrrPAdVZY02xAXNYZGb5s_JhdKPgQdXmunC0Is6nidY,5704
3
- mini_code_cli/prompts.py,sha256=A8nLnYuCWFuge-H5g7hYdRwXJPnRCg4uH__yYq4PzIU,1737
4
- mini_code_cli/tools.py,sha256=i46l8IvsrXJgqt7r8rKAMTGKNGAGffxKTFlwmAuWoD0,4926
5
- mini_code_cli/utils.py,sha256=qQk0RurNeWYoyRj-QmQ81Pq1pytJO87SUzm-XzDz9s4,3643
6
- mini_code_cli-0.0.6.dist-info/licenses/LICENSE,sha256=WCkMINUFi--UtEg_alEE2FBKPtNKkzi7dGzaxzchifc,1088
7
- mini_code_cli-0.0.6.dist-info/METADATA,sha256=43JAsEkm4zknm4jKtMDyjbTLTIG8d3XPGCSb2KUWRy8,1943
8
- mini_code_cli-0.0.6.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
9
- mini_code_cli-0.0.6.dist-info/entry_points.txt,sha256=MwDp5UbXpI7wodSmOSYL8_nKutnBiyp96ZDDtaX7x14,60
10
- mini_code_cli-0.0.6.dist-info/top_level.txt,sha256=3Hb6PpNkJYXvzDKXuuFJRvzCdsTRh0TuRWz-ScJ6qV0,14
11
- mini_code_cli-0.0.6.dist-info/RECORD,,