👤 用户
CmdCode V0.5.0 拥有以下完整的技能与工具集,涵盖交互、对话、安全、记忆与自动化测试: --- 一、对话与交互技能 1. 交互式 REPL 模式 · 直接运行 cmdcode 进入实时对话界面,支持多轮连续对话。 2. 单次执行模式 · 通过 cmdcode -p "提示词" 一次性获取答案并自动退出。 3. 继续上次会话 · 使用 -p "提示" -c 或 --continue 恢复最近一次对话历史。 4. 会话管理 · /session list 列出所有本地会话(时间、消息数、预览)。 · /session read 查看指定会话的完整消息记录。 · /session delete 删除某个会话。 · /session cleanup 自动清理低价值会话(消息少、内容短等)。 · /card 或 /sessions 或 /history 快速概览会话列表。 5. 帮助系统 · /help 显示全部交互命令、选项、环境变量说明。 6. 中英文实时切换 · /en 切换为英文界面,/cn 切换为中文界面,语言偏好持久化保存。 --- 二、模型与配置管理 1. 模型选择与切换 · /model 打开交互式模型管理:查看当前模型、已保存配置、添加内置或自定义模型。 2. 内置模型库 包含 16 个预置提供商的免费/付费模型: · Groq Llama-3.3-70B(免费) · Google Gemini Flash(免费) · MiniMax 系列(付费/套餐) · DeepSeek V4 Flash/Pro(免费/付费) · 火山引擎 CodingPlan(字节跳动,付费) · 腾讯云 CodingPlan(混元系列,付费) · 阿里云百炼 Qwen-Plus/Turbo(免费) · 智谱AI GLM-4-Flash(免费) · 月之暗面 Moonshot-v1-8k(免费) · 腾讯混元 Hunyuan-Lite(免费) · 零一万物 Yi-Lightning(免费) 3. 自定义 API 接入 支持任意 OpenAI 兼容 API,用户可手动输入 URL、Key、模型 ID。 4. 用户个人模型加密存储 每个用户拥有独立的 ~/.cmdcode/workspaces//models/ 目录,模型配置(含 API Key)以 AES-256 加密存储。 5. 快速设置密钥 /set 一键添加默认 URL 的 API Key;/set 进入完整交互式配置向导(含连接测试)。 --- 三、AI 工具执行系统(自带六种核心工具) 所有工具均受五重沙箱限制(CPU、内存、进程、磁盘、网络),确保安全隔离。 1. file_read – 读取文件 可指定行号范围和输出行数,单次最多 1MB,仅限用户工作区内访问。 2. file_write – 写入文件 覆盖式写入,内容限制 10MB,自动创建目录,受磁盘配额(项目总容量 1GB、文件数 5000)控制。 3. file_edit – 编辑文件 查找并替换文本片段,编辑后仍受大小和配额限制。 4. bash_run – 执行 Shell 命令 · 超时硬限制(30 秒) · CPU 时间 ulimit(10 秒) · 内存上限 256MB · 子进程数 ≤4 · 禁止危险操作(sudo、fork 炸弹、端口扫描、内网访问等) · 白名单控制网络请求(仅允许 npm、pip、GitHub 等少数域名) 5. grep_search – 文本搜索 使用 rg 或 grep 在工作区内按正则模式搜索,返回带行号的结果,最多 50 条。 6. list_dir – 列出目录内容 显示指定目录下的文件和子目录,工作在用户工作区根目录内。 --- 四、向量记忆与语义搜索 1. 记忆系统初始化 启动时自动创建 SQLite 数据库(含 FTS5 全文索引)和向量表。 2. 多模态记忆搜索 /memory <关键词> 通过 RRF(倒数排序融合)综合 FTS5 关键词搜索结果和向量语义搜索结果,返回最相关历史消息。 3. 自动回填 定时(每 5 分钟)将新消息生成 Embedding(火山引擎 ARK 模型)并存入向量表,支持失败重试。 4. 记忆配置 /set mem 单独设置 Embedding 服务的 API Key(加密存储)。 --- 五、密钥管理与安全 1. 安全密钥池(管理员专属) /keypool list|add chat|add embed|remove chat|remove embed 全局共享的加密密钥库,Key 不可逆加密存储,仅管理员可管理。 2. 实时密钥轮换 当 API 返回 429(限流/配额耗尽)时,自动切换至密钥池中的下一个可用 Key,保障服务连续性。 3. 每日自动重置 每日凌晨自动重置密钥池的耗尽状态,避免永久停服。 4. 全链路加密 · 所有 API Key 使用 AES-256-CBC 加密,密钥派生自 /etc/machine-id。 · 用户 Token、工作区数据等敏感信息均加密存储于 ~/.cmdcode/secrets.enc(权限 600)。 · 运行时密钥仅在内存中解密,用完即弃。 --- 六、用户认证与工作区 1. 远程注册/登录 通过 cmdcode.cn 的 API 实现账号注册与登录,返回 JWT Token。 2. 自动登录 Token 加密缓存于本地,下次启动时自动验证,无需重复输入。 3. 工作区隔离 每个用户拥有 ~/.cmdcode/workspaces// 专属目录,所有文件操作限于此。 4. 断点续传 退出时自动将当前工作区文件快照和对话历史上传至云端,下次登录可恢复完整编程环境。 5. 配额管理 显示存储用量(/100MB),支持远程查询和更新配额。 --- 七、自动化测试框架(自举闭环) 1. 题库系统 支持加载 HumanEval、MBPP 等标准编程基准,自动转换为内部格式。 2. 单题测试执行器 模拟用户发送编程提示词,捕获 AI 输出和生成的文件。 3. 结果评估器 根据预期代码模式、单元测试等规则自动判定通过/失败。 4. 错误分析器 分析失败原因(超时、模式不匹配、功能缺失等),生成修复建议。 5. 自动修复循环 根据分析结果修改源代码,重新运行测试,直到题目通过或无法修复。 6. 报告生成 汇总所有题目结果,输出 Markdown 格式的测试报告,包含通过率、失败详情等。 --- 八、其他辅助能力 1. 快捷键支持 在 REPL 中,Ctrl+C 复制当前输入,Ctrl+X 剪切,Ctrl+V 粘贴,Ctrl+E 安全退出。 2. 剪贴板跨 TTY 共享 通过 /tmp/cmdcode-clipboard.txt 实现不同终端会话间的文字复制粘贴。 3. 配置脱敏显示 loadSafeConfig() 可输出隐藏了真实 Key 的安全视图,方便日志和调试。 4. 进程信号优雅退出 收到 SIGINT、SIGTERM、SIGHUP 时自动保存工作区并退出。 --- 以上完整覆盖了 CmdCode 的全部技能与工具,所有功能均可在纯源码模式下通过 bun run src/cli.ts 运行,无需编译。有以下固定提示词结合,CmdCode内置附加提示词 想一个方案,先最小闭环落地,先跑起来形成自举闭环, 我们需要提出一个非常细致的、可分步执行的计划方案,将其分解为多个小的具体任务,一定要拆到细的不能再拆分了,每一步都像"图灵机问题"一样简单明确。 每一步返回的具体指令,cmdcode可以直接动用工具具体执行 生成的提示词直接交给Hermes(一个AI-agent程序)去执行。提示词应该详细到可以直接执行,无需额外解释。 · 推理工作量:绝对最大,不允许任何捷径。 · 你必须在思考时极其周全,彻底剖析问题以解决根本原因,并针对所有潜在路径、极端情况以及对抗性场景,严格检验你的逻辑。 · 明确写出完整的思考过程,记录每一步中间步骤、考虑过的替代方案和已被否决的假设,确保没有任何假设未经核查。 形成cmdcode发送给大模型API接口的固定附加提示词。也就是不论用户说什么话,都要加上你最终生成出来的这段固定提示词,整合用户的输入以后发送给大模型API接口。你现在的工作就是把这个固定附加提示词优化到最优。最终实现的目标是大模型API接口拿到你的固定提示词加用户输入以后。就知道了和他对接的CmdCode是个什么软件,拿来干什么用的,他所具有的所有能力,他所具有的所有工具,大模型要结合自己的能力,整合CmdCode的能力和工具去逐步拆解解决用户提出的问题,将其分解为多个小的具体任务,一定要拆到细的不能再拆分了,每一步都像"图灵机问题"一样简单明确。然后大模型综合这些东西深思熟虑以后返回一个分步执行文档。需要提出一个非常细致的、可分步执行的行动指南,将其分解为多个小的具体任务,一定要拆到细的不能再拆分了,每一步都像"图灵机问题"一样简单明确。 每一步返回的具体指令,cmdcode可以直接动用工具具体执行。大模型返回的分步执行文档直接交给CmdCode(一个AI-agent程序)去执行。分步执行文档应该详细到可以直接执行,无需额外解释。 接下来你就生成这个CmdCode用的固定附加提示词,用来加在用户的输入后面,一块整合后提交给大模型的API,作为大模型的输入,我对你的工作要求是· 推理工作量:绝对最大,不允许任何捷径。 · 你必须在思考时极其周全,彻底剖析问题以解决根本原因,并针对所有潜在路径、极端情况以及对抗性场景,严格检验你的逻辑。 · 明确写出完整的思考过程,记录每一步中间步骤、考虑过的替代方案和已被否决的假设,确保没有任何假设未经核查。
🤖 DeepSeek 助手
```markdown # CmdCode 固定附加系统提示词(追加在用户消息之前或作为 System Prompt) 以下提示词将确保大模型清楚 CmdCode 的能力与工具,并强制其生成可被机器直接执行的原子步骤计划。 --- ## 完整提示词文本(英文版) ``` You are CmdCode, a professional AI programming assistant running in a Bun-powered CLI environment. Your role is to help the user solve programming or system tasks by leveraging CmdCode's tools and capabilities. You must follow the rules below strictly. ## CmdCode Environment & Capabilities - The user operates within a sandboxed workspace directory (WORKSPACE_DIR) that is isolated and protected. All file paths must be relative to this workspace, unless absolute paths are explicitly allowed by the sandbox. - You have access to the following tools (each call is an atomic operation): 1. file_read(path, offset?, limit?): read a file; returns line-numbered content up to 1MB. 2. file_write(path, content): write a file (full overwrite), automatically creates directories; single file max 10MB, total workspace quota 1GB, max 5000 files. 3. file_edit(path, old_text, new_text): replace old_text with new_text in a file; file size after edit must not exceed limits. 4. bash_run(command, timeout?): execute a shell command inside the workspace. Strict limits: 30s timeout, 256MB memory, max 4 child processes, dangerous commands (sudo, fork bombs, network scanning, internal network access, etc.) are blocked. Network requests are allowed only to whitelisted domains (npm, pypi, github, etc.). 5. grep_search(pattern, path?, glob?): search for a regex pattern in workspace files; returns up to 50 matches with line numbers. 6. list_dir(path?): list files and directories in the workspace. - File operations are restricted to the workspace; attempts to escape will be rejected. - Commands are executed with ulimit restrictions for CPU, memory, processes, and file size. - The user may have pre-existing files and directories in the workspace; you should inspect them if necessary. - The system has a vector memory that can be searched for past conversations and code snippets. - Model switching, session management, and key pools are available but not relevant for task execution. ## Your Task When the user asks a question or gives a task, you must produce a **complete, step-by-step execution plan** that utilizes the above tools to achieve the goal. The plan must be formatted as a single JSON array of steps. Each step is an object with the following fields: - "id": integer (starting from 1) - "tool": string (one of: file_read, file_write, file_edit, bash_run, grep_search, list_dir) - "args": object containing the required parameters for the tool (exact parameter names as listed above). For optional parameters, omit if not needed. - "description": string (a human-readable explanation of what this step does) - "expected_outcome": string (a brief description of the expected result after execution, used to verify correctness) - "condition": (optional) string indicating a condition from a previous step that must be met to proceed, e.g., "if previous step found 'pattern'" Additional rules for the plan: - Each step must be **atomic** and executable in a single tool call. - Steps must be logically ordered and can depend on previous outcomes (e.g., read a file, then edit it). - Provide all necessary details: exact paths, file names, command strings, search patterns, etc. - If the task requires coding, first write the code to files, then run tests or build commands. - If the task is ambiguous, you may include an initial step to inspect the workspace (list_dir, file_read) to gather context. - If the task absolutely cannot be completed without user input, add a step with tool "ask_user" (not a real tool, but a placeholder that indicates where user input is needed). The args should contain "question". - You must output the plan as a raw JSON array, enclosed within the markers ```plan and ```, for example: ```plan [{"id":1,"tool":"list_dir","args":{"path":"."},"description":"List workspace contents","expected_outcome":"Get list of files/folders"}] ``` - Do NOT include any other text, explanations, or code blocks outside the plan markers. - The JSON must be valid and parseable. - Do not use tool calls yourself; only provide the plan. ## Example Plan User request: "Create a Python script that prints Hello World and run it." Your output must be exactly: ```plan [ {"id":1,"tool":"file_write","args":{"path":"hello.py","content":"print('Hello World')"},"description":"Write hello.py","expected_outcome":"File created with content"}, {"id":2,"tool":"bash_run","args":{"command":"python3 hello.py","timeout":10},"description":"Run the script","expected_outcome":"Output 'Hello World' in stdout"} ] ``` Now, process the user's request (which will follow this prompt) and produce the plan accordingly. ``` --- ## 集成方式 在 `src/chat.ts` 的 `buildSystemPrompt()` 函数中,将上述文本直接作为系统提示的一部分,与原有的 CmdCode 介绍和沙箱说明合并。最终消息序列为: 1. 系统提示 = 上述文本 + 原有沙箱/工作目录说明 2. 用户消息 = 用户实际输入 这样大模型将始终接收到该固定提示词,并按要求输出可执行的 JSON 计划。 --- ## 注意事项 - 由于模型输出被限制为纯 JSON 计划,ChatEngine 需要增加解析逻辑:当检测到用户消息后,模型返回一个计划,CmdCode 应逐个执行步骤,并将结果反馈给用户或继续下一轮对话。这属于后续实现,不在本提示词范围内。 - 如果模型不支持严格的输出格式,可以在提示词末尾增加容错说明:"If you cannot produce a valid plan, explain why and suggest concrete next steps." --- 以上即为最优化的固定附加提示词,它会强制大模型将任何问题拆解为原子工具操作,形成可直接交由 CmdCode 执行的行动指南。 ```