mini-code-cli 0.0.8.1__py3-none-any.whl → 0.0.8.2__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.
@@ -61,7 +61,6 @@ def parse_args():
61
61
  # Other settings:
62
62
  parser.add_argument("--cache-dir", type=str, help="The cache dir for the session histories.")
63
63
 
64
-
65
64
  # Agent behaviour related
66
65
  parser.add_argument("--system-prompt", type=str, help="Replace system prompt, with a custom system prompt.")
67
66
  parser.add_argument("--auto-mode", action="store_true", help="Whether to run the agent in `auto-mode'. Or default: `manual-mode'.")
@@ -208,141 +207,154 @@ def main():
208
207
  user_input = args.prompt
209
208
 
210
209
  while True:
210
+ try:
211
211
 
212
- if llm_tool_response_flag and args.auto_mode: #skip user input and try to call the model again until there no more tool calls.
213
- print(f"{BOLD}{YELLOW}System:{RESET} Skipping user input. Continuing with LLM calls until no more tool calls. [Tool count={tool_count}]")
214
- llm_repeat_flag = True
215
- else:
216
- # get user input
217
- if llm_repeat_flag:
218
- print(f"{BOLD}{YELLOW}System:{RESET} Called {tool_count} tools in total. Exiting tool loop.")
219
-
220
- tool_count = 0
221
- if not user_input:
222
- try:
223
- print("-"*30)
224
- user_input = input(f"{BOLD}{CYAN}You:{RESET} ")
225
- if user_input.lower() in ["quit", "exit", "/quit", "/exit"]:
226
- print("\nThank you. Goodbye! Saving history...")
212
+ if llm_tool_response_flag and args.auto_mode: #skip user input and try to call the model again until there no more tool calls.
213
+ print(f"{BOLD}{YELLOW}System:{RESET} Skipping user input. Continuing with LLM calls until no more tool calls. [Tool count={tool_count}]")
214
+ llm_repeat_flag = True
215
+ else:
216
+ # get user input
217
+ if llm_repeat_flag:
218
+ print(f"{BOLD}{YELLOW}System:{RESET} Called {tool_count} tools in total. Exiting tool loop.")
219
+
220
+ tool_count = 0
221
+ if not user_input:
222
+ try:
223
+ print("-"*30)
224
+ user_input = input(f"{BOLD}{CYAN}You:{RESET} ")
225
+ if user_input.lower() in ["quit", "exit", "/quit", "/exit"]:
226
+ print("\nThank you. Goodbye!")
227
+ print(f"Saving history to: {cache_dir}/{unique_id}")
228
+ save_history(messages, args, unique_id)
229
+ break
230
+ except KeyboardInterrupt:
231
+ print("\nThank you. Goodbye!")
232
+ print(f"Saving history to: {cache_dir}/{unique_id}")
227
233
  save_history(messages, args, unique_id)
228
234
  break
229
- except KeyboardInterrupt:
230
- print("\nThank you. Goodbye! Saving history...")
231
- save_history(messages, args, unique_id)
232
- break
233
- else:
234
- print("-"*30)
235
- print(f"{BOLD}{CYAN}You (preset): {RESET}{user_input}")
236
-
237
- if user_input == "/help":
238
- print_help(allowed_dir, server_url, args, unique_id, cache_dir)
239
- user_input = ""
240
- continue
241
-
242
- messages.append({"role": "user", "content": user_input})
243
- user_input = ""
244
-
245
- llm_response_flag = False
246
- llm_tool_response_flag = False
247
-
248
- response_text, tool_calls = utils.call_openai_server(
249
- messages,
250
- max_tokens=args.max_tokens,
251
- temperature=args.temperature,
252
- model=args.model,
253
- server_url=server_url,
254
- tools=llm_tools_dict,
255
- api_key=api_key,
256
- )
257
-
258
- if response_text:
259
- llm_response_flag = True
260
- print(f"{BOLD}{GREEN}Assistant:{RESET} {response_text}")
261
-
262
- if tool_calls:
263
- llm_tool_response_flag = True
264
-
265
- messages.append({
266
- "role": "assistant",
267
- "content": response_text,
268
- "tool_calls": tool_calls
269
- })
270
- # Tool call parsing and execution
271
- print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call {len(tool_calls)} tools.")
272
-
273
- for call in tool_calls:
274
- tool_count += 1
275
-
276
- call_id = call.get("id", "")
277
- name = call.get("function", {}).get("name", "")
278
- params_str = call.get("function", {}).get("arguments", "{}")
279
- try:
280
- tool_params = json.loads(params_str)
281
- except json.JSONDecodeError:
282
- print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
235
+ else:
236
+ print("-"*30)
237
+ print(f"{BOLD}{CYAN}You (preset): {RESET}{user_input}")
238
+
239
+ if user_input == "/help":
240
+ print_help(allowed_dir, server_url, args, unique_id, cache_dir)
241
+ user_input = ""
283
242
  continue
284
243
 
285
- if name in tools_dict:
286
- # Check allowed directory for file operations
287
- if name in ["read_file", "write_file", "grep", "glob"]:
288
- filepath = tool_params.get("filepath", "")
289
- if name == "write_file":
244
+ messages.append({"role": "user", "content": user_input})
245
+ user_input = ""
246
+
247
+ llm_response_flag = False
248
+ llm_tool_response_flag = False
249
+
250
+ response_text, tool_calls = utils.call_openai_server(
251
+ messages,
252
+ max_tokens=args.max_tokens,
253
+ temperature=args.temperature,
254
+ model=args.model,
255
+ server_url=server_url,
256
+ tools=llm_tools_dict,
257
+ api_key=api_key,
258
+ )
259
+
260
+ if response_text:
261
+ llm_response_flag = True
262
+ print(f"{BOLD}{GREEN}Assistant:{RESET} {response_text}")
263
+
264
+ if tool_calls:
265
+ llm_tool_response_flag = True
266
+
267
+ messages.append({
268
+ "role": "assistant",
269
+ "content": response_text,
270
+ "tool_calls": tool_calls
271
+ })
272
+ # Tool call parsing and execution
273
+ print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call {len(tool_calls)} tools.")
274
+
275
+ for call in tool_calls:
276
+ tool_count += 1
277
+
278
+ call_id = call.get("id", "")
279
+ name = call.get("function", {}).get("name", "")
280
+ params_str = call.get("function", {}).get("arguments", "{}")
281
+ try:
282
+ tool_params = json.loads(params_str)
283
+ except json.JSONDecodeError:
284
+ print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
285
+ continue
286
+
287
+ if name in tools_dict:
288
+ # Check allowed directory for file operations
289
+ if name in ["read_file", "write_file", "grep", "glob"]:
290
290
  filepath = tool_params.get("filepath", "")
291
- if filepath and not os.path.abspath(filepath).startswith(allowed_dir):
292
- print(f"{BOLD}{RED}Warning:{RESET} File operation not allowed outside allowed directory: {allowed_dir}")
293
- continue
294
-
295
- func = tools_dict[name]["function"]
296
- # asking permissions
297
- if args.ask_permission:
298
- print(f"{BOLD}{YELLOW}Tool permission:{RESET} Are you sure you want to call the tool?")
299
- print(f"name: {name}, parameters: {params_str}")
300
- try:
301
- permission_input = input("Type: 'y' or 'yes'\n")
302
- except KeyboardInterrupt:
303
- print("\nThank you. Goodbye! Saving history...")
304
- save_history(messages, args, unique_id)
305
- sys.exit(0)
306
-
307
- if not permission_input in ['y', 'yes']:
308
- print(f"{BOLD}{YELLOW}Tool permission denied:{RESET}.")
309
- messages.append({
310
- "role": "user",
311
- "content": f"User denied permission for tool {name} and params {params_str}."
312
- })
313
- continue
314
-
315
- print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call: {name} with {tool_params}.")
316
- result = call_function_with_timeout(func, tool_params, name)
317
- # Limiting output to 300 characters for readability
318
- result_str = str(result)
319
- if len(result_str) > 300:
320
- result_str = result_str[:300] + "... (truncated to 300 chars)"
321
- print(f"{BOLD}{MAGENTA}Tool '{name}' returned:{RESET} {result_str}")
322
-
323
- messages.append({
324
- "role": "tool",
325
- "tool_call_id": call_id,
326
- "content": str(result)
327
- })
328
- else:
329
- print(f"{BOLD}{RED}Error:{RESET} Unknown tool: {name}, params {params_str}")
330
- messages.append({
331
- "role": "tool",
332
- "tool_call_id": call_id,
333
- "content": f"Error: Unknown tool: {name}, params {params_str}"
334
- })
335
- else:
336
- messages.append({
337
- "role": "assistant",
338
- "content": response_text,
339
- # "tool_calls": tool_calls
340
- })
341
-
342
- if not llm_response_flag and not llm_tool_response_flag:
343
- print(f"{BOLD}{RED}Warning:{RESET} No response was given by the LLM.")
291
+ if name == "write_file":
292
+ filepath = tool_params.get("filepath", "")
293
+ if filepath and not os.path.abspath(filepath).startswith(allowed_dir):
294
+ print(f"{BOLD}{RED}Warning:{RESET} File operation not allowed outside allowed directory: {allowed_dir}")
295
+ continue
296
+
297
+ func = tools_dict[name]["function"]
298
+ # asking permissions
299
+ if args.ask_permission:
300
+ print(f"{BOLD}{YELLOW}Tool permission:{RESET} Are you sure you want to call the tool?")
301
+ print(f"name: {name}, parameters: {params_str}")
302
+ try:
303
+ permission_input = input("Type: 'y' or 'yes'\n")
304
+ except KeyboardInterrupt:
305
+ print("\nThank you. Goodbye! Saving history...")
306
+ save_history(messages, args, unique_id)
307
+ sys.exit(0)
308
+
309
+ if not permission_input in ['y', 'yes']:
310
+ print(f"{BOLD}{YELLOW}Tool permission denied:{RESET}.")
311
+ messages.append({
312
+ "role": "user",
313
+ "content": f"User denied permission for tool {name} and params {params_str}."
314
+ })
315
+ continue
316
+
317
+ print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call: {name} with {tool_params}.")
318
+ result = call_function_with_timeout(func, tool_params, name)
319
+ # Limiting output to 300 characters for readability
320
+ result_str = str(result)
321
+ if len(result_str) > 300:
322
+ result_str = result_str[:300] + "... (truncated to 300 chars)"
323
+ print(f"{BOLD}{MAGENTA}Tool '{name}' returned:{RESET} {result_str}")
324
+
325
+ messages.append({
326
+ "role": "tool",
327
+ "tool_call_id": call_id,
328
+ "content": str(result)
329
+ })
330
+ else:
331
+ print(f"{BOLD}{RED}Error:{RESET} Unknown tool: {name}, params {params_str}")
332
+ messages.append({
333
+ "role": "tool",
334
+ "tool_call_id": call_id,
335
+ "content": f"Error: Unknown tool: {name}, params {params_str}"
336
+ })
337
+ else:
338
+ messages.append({
339
+ "role": "assistant",
340
+ "content": response_text,
341
+ # "tool_calls": tool_calls
342
+ })
343
+
344
+ if not llm_response_flag and not llm_tool_response_flag:
345
+ print(f"{BOLD}{RED}Warning:{RESET} No response was given by the LLM.")
346
+
347
+ save_history(messages, args, unique_id)
344
348
 
345
- save_history(messages, args, unique_id)
349
+ except KeyboardInterrupt:
350
+ print(f"{BOLD}{RED}INTERRUPTING:{RESET} Mini Code Exiting...")
351
+
352
+ except Exception as e:
353
+ print(f"{BOLD}{RED}FATAL ERROR:{RESET} Mini Code Crashed...:\n{e}")
354
+
355
+ finally:
356
+ print(f"Saving history to: {cache_dir}/{unique_id}")
357
+ save_history(messages, args, unique_id)
346
358
 
347
359
  if __name__ == "__main__":
348
360
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mini-code-cli
3
- Version: 0.0.8.1
3
+ Version: 0.0.8.2
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=iNgHmKSHOuH99obGjnUMoS2JP4Gw4AOrIfu68EYaZQM,77
2
+ mini_code_cli/agent_loop.py,sha256=V74UYHU9y4ZYV_OtYkDpFWJnuEgmTRP36Uxc4AP89y0,14783
3
+ mini_code_cli/prompts.py,sha256=hIX-A_F7RBuTAAwYaLaDA6JMC1lhv9Fkx1WkS5v83TU,1992
4
+ mini_code_cli/tools.py,sha256=R8DWRu0zij2Xwioldd6tDeMtVfSaZhqcWAsjvskOxvw,5627
5
+ mini_code_cli/utils.py,sha256=HlmuLH0V4AxZTg0_ZGzlxffqRqs7T3W6FQXaBhioGdk,3647
6
+ mini_code_cli-0.0.8.2.dist-info/licenses/LICENSE,sha256=WCkMINUFi--UtEg_alEE2FBKPtNKkzi7dGzaxzchifc,1088
7
+ mini_code_cli-0.0.8.2.dist-info/METADATA,sha256=GpP0D_izk9dRFw7i3qUzV_2AatFQPsBceunIU1qmFbc,4284
8
+ mini_code_cli-0.0.8.2.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
9
+ mini_code_cli-0.0.8.2.dist-info/entry_points.txt,sha256=MwDp5UbXpI7wodSmOSYL8_nKutnBiyp96ZDDtaX7x14,60
10
+ mini_code_cli-0.0.8.2.dist-info/top_level.txt,sha256=3Hb6PpNkJYXvzDKXuuFJRvzCdsTRh0TuRWz-ScJ6qV0,14
11
+ mini_code_cli-0.0.8.2.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- mini_code_cli/__init__.py,sha256=iNgHmKSHOuH99obGjnUMoS2JP4Gw4AOrIfu68EYaZQM,77
2
- mini_code_cli/agent_loop.py,sha256=ZGEKIMD0N3pGp2kyykckv4mAo26yxyCvJaB3h5Xwj4s,13804
3
- mini_code_cli/prompts.py,sha256=hIX-A_F7RBuTAAwYaLaDA6JMC1lhv9Fkx1WkS5v83TU,1992
4
- mini_code_cli/tools.py,sha256=R8DWRu0zij2Xwioldd6tDeMtVfSaZhqcWAsjvskOxvw,5627
5
- mini_code_cli/utils.py,sha256=HlmuLH0V4AxZTg0_ZGzlxffqRqs7T3W6FQXaBhioGdk,3647
6
- mini_code_cli-0.0.8.1.dist-info/licenses/LICENSE,sha256=WCkMINUFi--UtEg_alEE2FBKPtNKkzi7dGzaxzchifc,1088
7
- mini_code_cli-0.0.8.1.dist-info/METADATA,sha256=WojKEfioIJyR4ATsC5-5MtO19DvyJcrVH7zeaY4zwRs,4284
8
- mini_code_cli-0.0.8.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
9
- mini_code_cli-0.0.8.1.dist-info/entry_points.txt,sha256=MwDp5UbXpI7wodSmOSYL8_nKutnBiyp96ZDDtaX7x14,60
10
- mini_code_cli-0.0.8.1.dist-info/top_level.txt,sha256=3Hb6PpNkJYXvzDKXuuFJRvzCdsTRh0TuRWz-ScJ6qV0,14
11
- mini_code_cli-0.0.8.1.dist-info/RECORD,,