codegpt-ai 1.20.0 → 1.21.0

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.
Files changed (2) hide show
  1. package/chat.py +83 -24
  2. package/package.json +1 -1
package/chat.py CHANGED
@@ -28,6 +28,21 @@ from prompt_toolkit.styles import Style as PtStyle
28
28
 
29
29
  # --- Config ---
30
30
 
31
+ # Fix PATH for Termux and pip --user installs
32
+ _extra_paths = [
33
+ os.path.expanduser("~/.local/bin"),
34
+ os.path.expanduser("~/bin"),
35
+ ]
36
+ if os.path.exists("/data/data/com.termux"):
37
+ _extra_paths.extend([
38
+ "/data/data/com.termux/files/usr/bin",
39
+ "/data/data/com.termux/files/home/.local/bin",
40
+ os.path.expanduser("~/.npm-global/bin"),
41
+ ])
42
+ for _p in _extra_paths:
43
+ if _p not in os.environ.get("PATH", "") and os.path.isdir(_p):
44
+ os.environ["PATH"] = _p + os.pathsep + os.environ.get("PATH", "")
45
+
31
46
  OLLAMA_URL = os.environ.get("OLLAMA_URL", "http://localhost:11434/api/chat")
32
47
  MODEL = "llama3.2"
33
48
  CHATS_DIR = Path.home() / ".codegpt" / "conversations"
@@ -223,7 +238,7 @@ AI_TOOLS = {
223
238
  "install": ["npm", "i", "-g", "@openai/codex"],
224
239
  "default_args": [],
225
240
  "needs_key": "OPENAI_API_KEY",
226
- "termux": True, # Has linux-arm64 build
241
+ "termux": False, # ARM64 build fails on Termux
227
242
  },
228
243
  "gemini": {
229
244
  "name": "Gemini CLI",
@@ -5804,10 +5819,6 @@ def main():
5804
5819
  print_sys("Use a desktop/PC for this tool.")
5805
5820
  continue
5806
5821
 
5807
- if not ask_permission("tool_install", f"Install {tool['name']} via {' '.join(install_cmd[:3])}"):
5808
- continue
5809
- print_sys(f"Installing {tool['name']}...")
5810
-
5811
5822
  # Pick platform-specific install command
5812
5823
  if is_termux and "install_termux" in tool:
5813
5824
  install_cmd = list(tool["install_termux"])
@@ -5816,6 +5827,10 @@ def main():
5816
5827
  else:
5817
5828
  install_cmd = list(tool["install"])
5818
5829
 
5830
+ if not ask_permission("tool_install", f"Install {tool['name']} via {' '.join(install_cmd[:3])}"):
5831
+ continue
5832
+ print_sys(f"Installing {tool['name']}...")
5833
+
5819
5834
  is_npm = install_cmd[0] in ("npm", "npm.cmd")
5820
5835
 
5821
5836
  if is_npm and os.name == "nt":
@@ -5833,11 +5848,14 @@ def main():
5833
5848
  )
5834
5849
  install_ok[0] = r.returncode == 0
5835
5850
  if not install_ok[0]:
5836
- install_err[0] = r.stderr[:200] if r.stderr else "Unknown"
5851
+ # Show both stderr and stdout for better debugging
5852
+ err = r.stderr.strip() if r.stderr else ""
5853
+ out = r.stdout.strip() if r.stdout else ""
5854
+ install_err[0] = err[:300] or out[:300] or f"Exit code {r.returncode}"
5837
5855
  except subprocess.TimeoutExpired:
5838
5856
  install_err[0] = "Timed out (5min)"
5839
5857
  except Exception as e:
5840
- install_err[0] = str(e)
5858
+ install_err[0] = str(e)[:300]
5841
5859
  install_done[0] = True
5842
5860
 
5843
5861
  thr = threading.Thread(target=do_tool_install, daemon=True)
@@ -5867,25 +5885,66 @@ def main():
5867
5885
  ))
5868
5886
  time.sleep(0.1)
5869
5887
 
5870
- if install_ok[0] and shutil.which(tool_bin):
5888
+ if install_ok[0]:
5871
5889
  elapsed = time.time() - start_t
5872
- print_sys(f"Installed in {elapsed:.1f}s. Launching...")
5873
- audit_log(f"TOOL_INSTALL", tool_key)
5874
5890
 
5875
- tool_sandbox = Path.home() / ".codegpt" / "sandbox" / tool_key
5876
- tool_sandbox.mkdir(parents=True, exist_ok=True)
5877
- safe_env = os.environ.copy()
5878
- for key in ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "GROQ_API_KEY",
5879
- "AWS_SECRET_ACCESS_KEY", "GITHUB_TOKEN", "GH_TOKEN",
5880
- "CODEGPT_BOT_TOKEN", "SSH_AUTH_SOCK"]:
5881
- safe_env.pop(key, None)
5882
-
5883
- launch_cmd = [tool_bin] + tool.get("default_args", [])
5884
- subprocess.run(launch_cmd, shell=True, cwd=str(tool_sandbox), env=safe_env)
5885
- print_sys("Back to CodeGPT.")
5886
- elif install_ok[0]:
5887
- print_err(f"Installed but '{tool_bin}' not found in PATH.")
5888
- print_sys("Try restarting your terminal, then run the command again.")
5891
+ # Rehash PATH find newly installed binaries
5892
+ for _p in [
5893
+ os.path.expanduser("~/.local/bin"),
5894
+ os.path.expanduser("~/.npm-global/bin"),
5895
+ "/data/data/com.termux/files/usr/bin",
5896
+ os.path.expanduser("~/bin"),
5897
+ ]:
5898
+ if os.path.isdir(_p) and _p not in os.environ.get("PATH", ""):
5899
+ os.environ["PATH"] = _p + os.pathsep + os.environ["PATH"]
5900
+
5901
+ # Try to find the binary
5902
+ found_bin = shutil.which(tool_bin)
5903
+
5904
+ # Fallback: search common install locations
5905
+ if not found_bin:
5906
+ search_dirs = [
5907
+ os.path.expanduser("~/.local/bin"),
5908
+ os.path.expanduser("~/.npm-global/bin"),
5909
+ "/data/data/com.termux/files/usr/bin",
5910
+ ]
5911
+ for sd in search_dirs:
5912
+ candidate = os.path.join(sd, tool_bin)
5913
+ if os.path.isfile(candidate):
5914
+ found_bin = candidate
5915
+ break
5916
+
5917
+ # Fallback: try python -m for pip packages
5918
+ pip_module_map = {
5919
+ "sgpt": "sgpt",
5920
+ "llm": "llm",
5921
+ "litellm": "litellm",
5922
+ "gorilla": "gorilla_cli",
5923
+ "chatgpt": "chatgpt",
5924
+ "aider": "aider",
5925
+ "interpreter": "interpreter",
5926
+ "gpte": "gpt_engineer",
5927
+ "mentat": "mentat",
5928
+ }
5929
+
5930
+ if found_bin:
5931
+ print_sys(f"Installed in {elapsed:.1f}s. Launching...")
5932
+ audit_log(f"TOOL_INSTALL", tool_key)
5933
+ launch_cmd = [found_bin] + tool.get("default_args", [])
5934
+ subprocess.run(launch_cmd, shell=True)
5935
+ print_sys("Back to CodeGPT.")
5936
+ elif tool_bin in pip_module_map:
5937
+ # Try python -m fallback
5938
+ mod = pip_module_map[tool_bin]
5939
+ print_sys(f"Installed in {elapsed:.1f}s. Launching via python -m {mod}...")
5940
+ audit_log(f"TOOL_INSTALL", tool_key)
5941
+ launch_cmd = [sys.executable, "-m", mod] + tool.get("default_args", [])
5942
+ subprocess.run(launch_cmd)
5943
+ print_sys("Back to CodeGPT.")
5944
+ else:
5945
+ print_err(f"Installed but '{tool_bin}' not found in PATH.")
5946
+ print_sys(f"Try: which {tool_bin}")
5947
+ print_sys("Or restart your terminal and try again.")
5889
5948
  else:
5890
5949
  print_err(f"Install failed: {install_err[0]}")
5891
5950
  manual = " ".join(tool["install"])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codegpt-ai",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Local AI Assistant Hub — 80+ commands, 29 tools, 8 agents, training, security",
5
5
  "author": "ArukuX",
6
6
  "license": "MIT",