mini-code-cli 0.0.7.1__tar.gz → 0.0.8.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mini-code-cli
3
- Version: 0.0.7.1
3
+ Version: 0.0.8.0
4
4
  Summary: Minimal Coding CLI
5
5
  Author-email: Nikolai Rozanov <nikolai.rozanov@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -20,23 +20,46 @@ Dynamic: license-file
20
20
 
21
21
  # A minimal coding agent cli
22
22
 
23
- > No bloat, no dependencies, no tracking...
23
+ > No bloat, no dependencies, no tracking, no telemetry...
24
24
 
25
25
  Purpose: A no bloat, minimal coding cli, to enjoy experimenting and researching...
26
26
 
27
27
  ## Getting started:
28
- 1. Installation (from pypi)
28
+
29
+ ### Installation (from pypi)
29
30
  ```bash
30
31
  pip3 install mini-code-cli
31
32
  ```
32
33
 
33
- 2. Run agent: (get LLM running via SGLang or Vllm)
34
+ ### Run agent:
35
+
36
+ 1. Basic usage: (get local LLM running (e.g. via SGLang or Vllm))
34
37
  ```bash
35
- mini-code #run the agent loop
36
- mini-code --url "https://api.deepseek.com" --model "deepseek-v4-flash" --api-key "sk-dummy" --allowed-dir ./experiments/
38
+ mini-code #run the agent using `localhost:30000/v1` model
39
+ ```
40
+ 2. Custom API based model:
41
+ ```bash
42
+ export MINI_CODE_API_KEY="sk-YOUR_API_KEY"
43
+ mini-code --url "https://api.deepseek.com" --model "deepseek-v4-flash"
44
+ ```
45
+
46
+ Auto-mode, Agent.md, Shell Enabled mode and a specific allowed dir:
47
+ ```bash
48
+ mini-code --enable-shell --auto-mode --agent-md "./skill.md" --allowed-dir "./" --ask-permission --system-prompt "Your awesome new system prompt..."
49
+ ```
50
+ - auto-mode: the agent will continue querying the LLM and executing tools, until no more tool calls are possible
51
+ - agent.md: this will read an agent.md file with the specified name (e.g. ./skill.md)
52
+ - shell-enabled: **Be careful**: This will allow the agent to execute shell commands. Specifically, there is no permission checks.
53
+ - allowed-dir: this specifies which dirs the agent can read and write from, that does not stop the shell comands!
54
+ - ask-permission: asks user permission before every tool call.
55
+ - system-prompt: you can override the default prompt by using a string. (Not Agent.md is always appended after the system prompt.)
56
+
57
+ 3. Try a prompt:
58
+ ```txt
59
+ Write an agent.md file for me that helps an LLM write efficient triton kernels, given a reference implementation.
37
60
  ```
38
61
 
39
- 3. Get help:
62
+ 4. Get help:
40
63
  ```bash
41
64
  mini-code --help
42
65
  ```
@@ -0,0 +1,48 @@
1
+ # A minimal coding agent cli
2
+
3
+ > No bloat, no dependencies, no tracking, no telemetry...
4
+
5
+ Purpose: A no bloat, minimal coding cli, to enjoy experimenting and researching...
6
+
7
+ ## Getting started:
8
+
9
+ ### Installation (from pypi)
10
+ ```bash
11
+ pip3 install mini-code-cli
12
+ ```
13
+
14
+ ### Run agent:
15
+
16
+ 1. Basic usage: (get local LLM running (e.g. via SGLang or Vllm))
17
+ ```bash
18
+ mini-code #run the agent using `localhost:30000/v1` model
19
+ ```
20
+ 2. Custom API based model:
21
+ ```bash
22
+ export MINI_CODE_API_KEY="sk-YOUR_API_KEY"
23
+ mini-code --url "https://api.deepseek.com" --model "deepseek-v4-flash"
24
+ ```
25
+
26
+ Auto-mode, Agent.md, Shell Enabled mode and a specific allowed dir:
27
+ ```bash
28
+ mini-code --enable-shell --auto-mode --agent-md "./skill.md" --allowed-dir "./" --ask-permission --system-prompt "Your awesome new system prompt..."
29
+ ```
30
+ - auto-mode: the agent will continue querying the LLM and executing tools, until no more tool calls are possible
31
+ - agent.md: this will read an agent.md file with the specified name (e.g. ./skill.md)
32
+ - shell-enabled: **Be careful**: This will allow the agent to execute shell commands. Specifically, there is no permission checks.
33
+ - allowed-dir: this specifies which dirs the agent can read and write from, that does not stop the shell comands!
34
+ - ask-permission: asks user permission before every tool call.
35
+ - system-prompt: you can override the default prompt by using a string. (Not Agent.md is always appended after the system prompt.)
36
+
37
+ 3. Try a prompt:
38
+ ```txt
39
+ Write an agent.md file for me that helps an LLM write efficient triton kernels, given a reference implementation.
40
+ ```
41
+
42
+ 4. Get help:
43
+ ```bash
44
+ mini-code --help
45
+ ```
46
+
47
+
48
+ ## (C) Nikolai Rozanov, 2026 - Present
@@ -10,6 +10,8 @@ write a similar model.py file but for a LSTM based language model. Make it minim
10
10
 
11
11
  import os
12
12
  import json
13
+ import signal
14
+
13
15
 
14
16
  from . import prompts
15
17
  from . import tools
@@ -36,25 +38,35 @@ def save_history(messages):
36
38
 
37
39
  def parse_args():
38
40
  parser = argparse.ArgumentParser(description="Agent loop for interacting with a language model")
41
+ # MODEL / LLM related
39
42
  parser.add_argument("--url", type=str, default="http://0.0.0.0:30000", help="API host")
40
- parser.add_argument("--system_prompt", type=str, help="API host")
41
- parser.add_argument("--api-key", type=str, default=None, help="API key for authentication")
42
- parser.add_argument("--allowed-dir", type=str, default=".", help="Allowed directory for file operations")
43
43
  parser.add_argument("--max-tokens", type=int, help="Maximum tokens for LLM response")
44
44
  parser.add_argument("--temperature", type=float, default=0.0, help="Temperature for LLM")
45
45
  parser.add_argument("--model", type=str, default="default", help="Model name")
46
- parser.add_argument("--step_by_step", action="store_true", help="Whether to run the agent step by step. Default is to run in 'Permission' mode.")
47
- parser.add_argument("--ask_permission", action="store_true", help="Ask for permission before any tool call.")
46
+ parser.add_argument("--api-key", type=str, default=None, help="API key for authentication. If not set, it tries to find it in env variable: MINI_CODE_API_KEY.")
47
+
48
+ # Agent behaviour related
49
+ parser.add_argument("--system-prompt", type=str, help="Replace system prompt, with a custom system prompt.")
50
+ parser.add_argument("--auto-mode", action="store_true", help="Whether to run the agent in `auto-mode'. Or default: `manual-mode'.")
51
+ parser.add_argument("--agent-md", type=str, help="If the agent should use an agent-md file... (it will added after system message.)")
52
+
53
+ # Agent permissions related
54
+ parser.add_argument("--ask-permission", action="store_true", help="Ask for permission before any tool call.")
55
+ parser.add_argument("--allowed-dir", type=str, default=".", help="Allowed directory for file operations")
56
+ parser.add_argument("--enable-shell", action="store_true", help="Allow shell execution. Default: False") #todo
57
+
48
58
 
49
59
  args = parser.parse_args()
50
60
  return args
51
61
 
62
+
52
63
  def print_welcome(allowed_dir, server_url, args):
53
64
  # Calculate the length of the longest line inside the box
54
65
  version = __import__('mini_code_cli').__version__
55
66
 
56
67
  permission_mode = "All tool calls require permission." if args.ask_permission else "Tool calls will execute without asking for permission."
57
- agent_mode = "Agent is in manual-mode." if args.step_by_step else "Agent is in auto-mode."
68
+ agent_mode = "Agent is in manual-mode." if not args.auto_mode else "Agent is in auto-mode."
69
+ shell_mode = "Shell disabled." if not args.enable_shell else "Shell enabled."
58
70
 
59
71
  lines = [
60
72
  f" MiniCodeCLI (v{version})",
@@ -63,7 +75,7 @@ def print_welcome(allowed_dir, server_url, args):
63
75
  f" Server URL: {server_url}",
64
76
  f" {permission_mode}",
65
77
  f" {agent_mode}",
66
- " Shell disabled."
78
+ f" {shell_mode}"
67
79
  ]
68
80
  max_len = max(len(line) for line in lines)
69
81
  margin = 2 # Space on each side inside the box
@@ -82,19 +94,62 @@ def print_help(allowed_dir, server_url, args):
82
94
  print_welcome(allowed_dir, server_url, args)
83
95
 
84
96
  help_message = ""
85
- help_message += "Manual-mode means the agent will ask for user input after each LLM prediction." if args.step_by_step else "Auto-mode means the agent will keep calling the LLM until no further LLM calls are possible."
97
+ help_message += "Manual-mode means the agent will ask for user input after each LLM prediction." if not args.auto_mode else "Auto-mode means the agent will keep calling the LLM until no further LLM calls are possible."
86
98
 
87
99
  print(f"{BOLD}{GREEN}HELP:{RESET} {help_message}")
88
100
 
101
+ def call_function_with_timeout(func, tool_params, name):
102
+ """calls function with params"""
103
+ class TimeoutError(Exception):
104
+ pass
105
+
106
+ def timeout_handler(signum, frame):
107
+ raise TimeoutError("Function call timed out")
108
+
109
+ timeout_seconds = 30 # Set your desired timeout in seconds
110
+ signal.signal(signal.SIGALRM, timeout_handler)
111
+ signal.alarm(timeout_seconds)
112
+ try:
113
+ result = func(**tool_params)
114
+ except TimeoutError:
115
+ print(f"{BOLD}{RED}Error:{RESET} Function {name} timed out after {timeout_seconds} seconds.")
116
+ result = "Error:Function {name} timed out after {timeout_seconds} seconds."
117
+ finally:
118
+ signal.alarm(0) # Disable the alarm
119
+
120
+ return result
121
+
89
122
  def main():
90
123
  args = parse_args()
91
124
 
92
- allowed_dir = os.path.abspath(args.allowed_dir)
125
+
126
+ # LLM Related
93
127
  server_url = f"{args.url}"
128
+ api_key = None
129
+ if args.api_key:
130
+ api_key = args.api_key
131
+ else:
132
+ api_key = os.environ.get("MINI_CODE_API_KEY", "")
133
+ if api_key:
134
+ print(f"{YELLOW}API Key found at MINI_CODE_API_KEY{RESET}")
135
+ else:
136
+ print(f"{YELLOW}NO API Key found at MINI_CODE_API_KEY. Set it with export MINI_CODE_API_KEY='sk-api-key'{RESET}")
137
+
138
+
139
+ # Permissions related
140
+ allowed_dir = os.path.abspath(args.allowed_dir)
141
+
142
+ if not args.enable_shell:
143
+ forbidden_tools = tools.shell_tools
144
+ else:
145
+ forbidden_tools = None
94
146
 
95
- tools_dict = tools.util_get_tools_dict()
96
- llm_tools_dict = tools.util_get_tools()
147
+ # TOOLs
148
+ tools_dict = tools.util_get_tools_dict(forbidden_tools=forbidden_tools)
149
+ llm_tools_dict = tools.util_get_tools(forbidden_tools=forbidden_tools)
97
150
 
151
+
152
+ # System Message and Agent.md
98
153
  if args.system_prompt:
99
154
  system_prompt = args.system_prompt
100
155
  else:
@@ -102,16 +157,32 @@ def main():
102
157
 
103
158
  messages = [{"role": "system", "content": system_prompt}]
104
159
 
160
+ if args.agent_md:
161
+ print(f"{YELLOW}AGENT.md '{args.agent_md}' specified.{RESET}")
162
+
163
+ # Check if the file exists
164
+ if not os.path.isfile(args.agent_md):
165
+ print(f"{RED}Error: The AGENT.md '{args.agent_md}' does not exist.{RESET}")
166
+ else:
167
+ # Load the content of agent-md file and add it after system message
168
+ with open(args.agent_md, 'r', encoding='utf-8') as f:
169
+ agent_md_content = f.read()
170
+ print(f"{YELLOW}AGENT.md '{args.agent_md}' loaded.{RESET}")
171
+
172
+ # Append the content as a user message after the system prompt
173
+ messages.append({"role": "user", "content": agent_md_content})
174
+
105
175
  print_welcome(allowed_dir, server_url, args)
106
176
 
177
+ # Agent Logic Flags
107
178
  llm_response_flag = False
108
179
  llm_tool_response_flag = False
109
180
  llm_repeat_flag = False
110
181
  tool_count = 0
111
182
 
112
183
  while True:
113
- if llm_tool_response_flag and not args.step_by_step: #skip user input and try to call the model again until there no more tool calls.
114
- print(f"{BOLD}{YELLOW}System:{RESET} Skipping user input. Continuing with LLM calls until no more tool calls.")
184
+ 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.
185
+ print(f"{BOLD}{YELLOW}System:{RESET} Skipping user input. Continuing with LLM calls until no more tool calls. [Tool count={tool_count}]")
115
186
  llm_repeat_flag = True
116
187
  else:
117
188
  # get user input
@@ -146,7 +217,8 @@ def main():
146
217
  temperature=args.temperature,
147
218
  model=args.model,
148
219
  server_url=server_url,
149
- tools=llm_tools_dict
220
+ tools=llm_tools_dict,
221
+ api_key=api_key,
150
222
  )
151
223
 
152
224
  if response_text:
@@ -205,7 +277,9 @@ def main():
205
277
  "content": f"User denied permission for tool {name} and params {params_str}."
206
278
  })
207
279
  continue
208
- result = func(**tool_params)
280
+
281
+ print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call: {name} with {tool_params}.")
282
+ result = call_function_with_timeout(func, tool_params, name)
209
283
  # Limiting output to 300 characters for readability
210
284
  result_str = str(result)
211
285
  if len(result_str) > 300:
@@ -65,14 +65,27 @@ def read_website(url):
65
65
  except Exception as e:
66
66
  return f"Error: {e}"
67
67
 
68
- def util_get_tools(tool_names=None):
68
+ def run_shell_command(command):
69
+ """Run a shell command and return its output. Param: command (string)"""
70
+ try:
71
+ result = subprocess.run(command, shell=True, capture_output=True, text=True, check=False)
72
+ output = result.stdout
73
+ if result.stderr:
74
+ output += "\nSTDERR:\n" + result.stderr
75
+ return output
76
+ except Exception as e:
77
+ return f"Error: {e}"
78
+
79
+ def util_get_tools(allowed_tools=None, forbidden_tools=None):
69
80
  """Return a JSON string describing all tool functions in this file for LLM usage."""
70
81
  import inspect
71
82
  tools = []
72
- if tool_names:
73
- func_names = [name for name, obj in globals().items() if callable(obj) and obj.__module__ == __name__ and not name.startswith('util_') and not name.startswith("_") and name in tool_names]
74
- else:
75
- func_names = [name for name, obj in globals().items() if callable(obj) and obj.__module__ == __name__ and not name.startswith('util_') and not name.startswith("_")]
83
+ func_names = [name for name, obj in globals().items() if callable(obj) and obj.__module__ == __name__ and not name.startswith('util_') and not name.startswith("_")]
84
+
85
+ if allowed_tools:
86
+ func_names = [name for name in func_names if name in allowed_tools]
87
+ if forbidden_tools:
88
+ func_names = [name for name in func_names if name not in forbidden_tools]
76
89
 
77
90
  for name in func_names:
78
91
  func = globals()[name]
@@ -108,17 +121,25 @@ def util_get_tools(tool_names=None):
108
121
  return tools
109
122
 
110
123
 
111
- def util_get_tools_dict():
124
+ def util_get_tools_dict(allowed_tools=None, forbidden_tools=None):
112
125
  """Return a dictionary mapping tool names to their function objects."""
113
126
  result = {}
114
127
  func_names = [name for name, obj in globals().items() if callable(obj) and obj.__module__ == __name__ and not name.startswith('util_') and not name.startswith("_")]
128
+ if allowed_tools:
129
+ func_names = [name for name in func_names if name in allowed_tools]
130
+ if forbidden_tools:
131
+ func_names = [name for name in func_names if name not in forbidden_tools]
132
+
115
133
  for name in func_names:
116
134
  func = globals()[name]
117
135
  desc = func.__doc__ if func.__doc__ else f"Function {name}"
118
136
  result[name] = {"function": func, "description": desc}
119
137
  return result
120
138
 
139
+ shell_tools = [
140
+ "run_shell_command"
141
+ ]
121
142
 
122
143
  if __name__=="__main__":
123
- # print(util_get_tools())
124
- print(json.dumps(tools_dict, indent=4))
144
+ print(util_get_tools())
145
+ # print(json.dumps(tools_dict, indent=4))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mini-code-cli
3
- Version: 0.0.7.1
3
+ Version: 0.0.8.0
4
4
  Summary: Minimal Coding CLI
5
5
  Author-email: Nikolai Rozanov <nikolai.rozanov@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -20,23 +20,46 @@ Dynamic: license-file
20
20
 
21
21
  # A minimal coding agent cli
22
22
 
23
- > No bloat, no dependencies, no tracking...
23
+ > No bloat, no dependencies, no tracking, no telemetry...
24
24
 
25
25
  Purpose: A no bloat, minimal coding cli, to enjoy experimenting and researching...
26
26
 
27
27
  ## Getting started:
28
- 1. Installation (from pypi)
28
+
29
+ ### Installation (from pypi)
29
30
  ```bash
30
31
  pip3 install mini-code-cli
31
32
  ```
32
33
 
33
- 2. Run agent: (get LLM running via SGLang or Vllm)
34
+ ### Run agent:
35
+
36
+ 1. Basic usage: (get local LLM running (e.g. via SGLang or Vllm))
34
37
  ```bash
35
- mini-code #run the agent loop
36
- mini-code --url "https://api.deepseek.com" --model "deepseek-v4-flash" --api-key "sk-dummy" --allowed-dir ./experiments/
38
+ mini-code #run the agent using `localhost:30000/v1` model
39
+ ```
40
+ 2. Custom API based model:
41
+ ```bash
42
+ export MINI_CODE_API_KEY="sk-YOUR_API_KEY"
43
+ mini-code --url "https://api.deepseek.com" --model "deepseek-v4-flash"
44
+ ```
45
+
46
+ Auto-mode, Agent.md, Shell Enabled mode and a specific allowed dir:
47
+ ```bash
48
+ mini-code --enable-shell --auto-mode --agent-md "./skill.md" --allowed-dir "./" --ask-permission --system-prompt "Your awesome new system prompt..."
49
+ ```
50
+ - auto-mode: the agent will continue querying the LLM and executing tools, until no more tool calls are possible
51
+ - agent.md: this will read an agent.md file with the specified name (e.g. ./skill.md)
52
+ - shell-enabled: **Be careful**: This will allow the agent to execute shell commands. Specifically, there is no permission checks.
53
+ - allowed-dir: this specifies which dirs the agent can read and write from, that does not stop the shell comands!
54
+ - ask-permission: asks user permission before every tool call.
55
+ - system-prompt: you can override the default prompt by using a string. (Not Agent.md is always appended after the system prompt.)
56
+
57
+ 3. Try a prompt:
58
+ ```txt
59
+ Write an agent.md file for me that helps an LLM write efficient triton kernels, given a reference implementation.
37
60
  ```
38
61
 
39
- 3. Get help:
62
+ 4. Get help:
40
63
  ```bash
41
64
  mini-code --help
42
65
  ```
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "mini-code-cli"
3
3
  # version = { file = "mini_code_cli/__init__.py", attr = "__version__" }
4
- version = "0.0.7.1"
4
+ version = "0.0.8.0"
5
5
  description = "Minimal Coding CLI"
6
6
  readme = "README.md"
7
7
  requires-python = ">=3.10"
@@ -1,25 +0,0 @@
1
- # A minimal coding agent cli
2
-
3
- > No bloat, no dependencies, no tracking...
4
-
5
- Purpose: A no bloat, minimal coding cli, to enjoy experimenting and researching...
6
-
7
- ## Getting started:
8
- 1. Installation (from pypi)
9
- ```bash
10
- pip3 install mini-code-cli
11
- ```
12
-
13
- 2. Run agent: (get LLM running via SGLang or Vllm)
14
- ```bash
15
- mini-code #run the agent loop
16
- mini-code --url "https://api.deepseek.com" --model "deepseek-v4-flash" --api-key "sk-dummy" --allowed-dir ./experiments/
17
- ```
18
-
19
- 3. Get help:
20
- ```bash
21
- mini-code --help
22
- ```
23
-
24
-
25
- ## (C) Nikolai Rozanov, 2026 - Present
File without changes