看到这个介绍:两天时间,AI协助我把OpenAI开源的Codex CLI重构成Python 版本——Codexy! - 知乎
官网:GitHub - AndersonBY/codexy: Lightweight coding agent that runs in your terminal
codexy就是一个可以在终端中运行的轻量级的AI编程助手。codexy主要致力于在本地模拟Codex那种“读懂你的指令并用代码实现”的体验,特别聚焦于Python生态。Codexy并非OpenAI官方产品,而是灵感来源于OpenAI Codex,并努力向其Python代码生成和理解能力靠近。
重要提示: Python 版本 (codexy
) 目前缺少原始 TypeScript 版本中的平台特定沙盒机制(如 macOS Seatbelt 或 Docker/iptables)。在 full-auto
模式下,命令会在您的系统上直接执行,工具本身不会施加网络或文件系统限制。dangerous-auto
模式明确地在非沙盒环境中运行所有操作。请极其谨慎地使用自动批准模式,尤其是在不受信任的环境或未受版本控制的仓库中。
我感觉这个安全问题确实要特别注意!
安装和使用
windows下安装和使用
pip安装
pip install -U codexy
设置
E:\work\codexy>set OPENAI_API_KEY="你的硅基流动密钥"
E:\work\codexy>set OPENAI_BASE_URL="http:/192.168.1.5:1337/v1"
(怪不得这里调试了很多时间,原来url写错了啊,应该是OPENAI_BASE_URL="http://192.168.1.5:1337/v1",重写设置:
E:\work\codexy>set OPENAI_API_KEY="你的硅基流动密钥"
E:\work\codexy>set OPENAI_BASE_URL="http://192.168.1.5:1337/v1"
codexy启动
codexy "帮我分析一下这个 Python 项目的核心逻辑" -m deepseek-v3
说明书写的配置:
$Env:OPENAI_API_KEY="你的硅基流动密钥"
$Env:OPENAI_BASE_URL="https://api.siliconflow.cn/v1"
# 或者在项目根目录创建 .env 文件写入:
OPENAI_API_KEY=你的硅基流动密钥
OPENAI_BASE_URL=https://api.siliconflow.cn/v1
set OPENAI_API_KEY="你的硅基流动密钥"
set OPENAI_BASE_URL="http://192.168.1.5:1337/v1"
问题
发现window10下无法输入中文,这个...有点问题啊。
FreeBSD下安装和使用
安装和配置
在192.168.0.109机器的普通用户下,直接:
$ python3.11 -m pip install codexy
bash切换到bash shell
配置环境变量
export OPENAI_API_KEY="yourkey"
export OPENAI_BASE_URL="http://192.168.1.5:1337/v1"
也可以写.env文件:
OPENAI_API_KEY="hello"
OPENAI_BASE_URL="http://192.168.1.5:1337/v1"
这里使用了自建的AI 模型。
执行
python3.11 -m codexy "帮我写一个hello word" -m deepseek-v3
运行成功
哇塞,太不容易了,这几天一直调试codex和codexy,这是第一次看到输出结果:
问题
FreeBSD 下可以使用中文,但是测试自动编辑等功能,没有成功。
Ubuntu22下安装和使用
安装和配置
source py312/bin/activate
pip install codexy
创建一个工作目录,比如work/codexy
在目录里创建一个.env文件,输入:
OPENAI_API_KEY="hello"
OPENAI_BASE_URL="http://192.168.1.5:1337/v1"
启动codexy
codexy -m gpt-4o
问题
尝试自动执行,但是没成功!
codexy -m gpt-4o --approval-mode full-auto
codexy -m gpt-4o --approval-mode dangerous-auto
其他功能
工具调用
- 文件操作: 读取文件 (
read_file
)、写入文件 (write_to_file
)、列出文件 (list_files
)。 - 代码修改: 应用
diff
格式的补丁 (apply_diff
)、应用更灵活的apply_patch
格式的补丁。 - 命令执行: 在你的终端环境(或未来可能的沙箱环境)中执行 Shell 命令 (
execute_command
)。
自动化
通过 --approval-mode
来控制 Codexy 的自主程度,决定哪些操作(文件修改、命令执行)需要你手动批准。
suggest
(默认): 只自动执行已知的安全只读命令,其他都需要你确认。auto-edit
: 自动批准文件修改,但执行命令前会询问。full-auto
: 尝试自动批准所有操作(警告:当前 Python 版本暂无沙箱,此模式需谨慎!)。dangerous-auto
: 完全不推荐! 跳过所有确认,直接执行所有操作,风险自负。
prompt:帮我写一个python的hello world文件,存盘到test.py文件里
但是这个没执行成功。
总结
个人对这个工具非常认可!
但是自动运行在几个系统下都没有测试成功,不明白原因。
调试
退出是Ctrl+q ,确认输入是Ctrl+回车或者Ctrl+j
报错:Failed after unexpected error: 'ascii' codec
Agent Error: Error: Failed after unexpected error: 'ascii' codec can't encode characters in ▊
▎ position 8-15: ordinal not in range(128)
明白了,原来是key里面带了中文,改掉:
export OPENAI_API_KEY="test"
报错: Agent Error: Error: Failed after unexpected error:
大约是模型的问题,毕竟自建的服务器,有时候不太稳定。
换成gpt-4o模型
现在无法写入文件,无法执行命令
已报issue 可以像普通ai软件那样交互,但是命令无法执行 · Issue #1 · AndersonBY/codexy,作者升级到0.0.9版本了,说已经解决了,但是我这边试下来还是不行。
我用的另一款终端软件,用的同样的gpt-4o模型,就能写和改文件。事实上其它AI软件如VScode 插件里那几款Clne等,都是可以写和改文件的。
新版本的copy命令报错
│
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │ text = '当然可以!我可以帮你创建和写文件。你刚才说要一个名为 test.py 的文件,里面写上 "hello world" 的 Python │ │
│ │ 代码,对吗?我这就给你写好'+1 │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ /home/skywalk/py312/lib/python3.12/site-packages/pyperclip/__init__.py:295 in __call__ │
│ │
│ 292 │ │ │ additionalInfo = '' │
│ 293 │ │ │ if sys.platform == 'linux': │
│ 294 │ │ │ │ additionalInfo = '\nOn Linux, you can run `sudo apt-get install xclip` o │
│ ❱ 295 │ │ │ raise PyperclipException('Pyperclip could not find a copy/paste mechanism fo │
│ 296 │ │ │
│ 297 │ │ if _IS_RUNNING_PYTHON_2: │
│ 298 │ │ │ def __nonzero__(self): │
│ │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │ additionalInfo = '\nOn Linux, you can run `sudo apt-get install xclip` or `sudo apt-get install xse'+40 │ │
│ │ args = ( │ │
│ │ │ '当然可以!我可以帮你创建和写文件。你刚才说要一个名为 test.py 的文件,里面写上 "hello │ │
│ │ world" 的 Python 代码,对吗?我这就给你写好'+1, │ │
│ │ ) │ │
│ │ kwargs = {} │ │
│ │ self = <pyperclip.init_no_clipboard.<locals>.ClipboardUnavailable object at 0x7fad2b50b350> │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
PyperclipException: Pyperclip could not find a copy/paste mechanism for your system. For more information, please visit
https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error
On Linux, you can run `sudo apt-get install xclip` or `sudo apt-get install xselect` to install a copy/paste mechanism.
按照提示的安装包
sudo apt-get install xclip
不行
换这个
sudo apt-get install xsel
也不行,放弃。
继续调试存盘
codexy "帮我用python语言,写个hello world 的例子程序,存盘到test.py文件中 " -m deepseek-v3
终于出现不同的显示了:
codexy "帮我用python语言,写个hello world 的例子程序,存盘到test.py文件中 " -m gpt-4o --approval-mode full-auto