From 587331cbb82bc469b80d28e5238ae01b32fc830b Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 10 Apr 2026 20:34:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(PHASE-03):=20=E7=8E=AF=E5=A2=83=E6=84=9F?= =?UTF-8?q?=E7=9F=A5=20+=20=E7=A8=B3=E5=AE=9A=E6=80=A7=E7=BA=A6=E6=9D=9F?= =?UTF-8?q?=20+=20Windows=20=E9=98=B2=E9=87=8D=E5=A4=8D=E8=AF=95=E9=94=99?= =?UTF-8?q?=20+=20max=5Fturns=3D12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 12 +++++++++++- SKILLS/cli-core.md | 1 + pyproject.toml | 2 +- src/cc_slim/engine.py | 28 ++++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 65d1be1..ecf646d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,6 +21,10 @@ 4. 使用工具后重新判断结果。 5. 持续循环,直到得到最终答案或出现必须由用户补充的信息。 +当前 harness 是极简实现,优先最小动作,不做不必要的重复试错。 + +行动时必须以运行时注入的环境信息为准,特别是平台、shell、工作目录和可用工具列表。 + 未明确说明时,使用以下默认值: - 工作目录:当前进程目录 @@ -35,6 +39,12 @@ - `Read`:用于读取文件内容。 - `Glob`:用于按模式查找文件。 - `Bash`:用于执行必须通过 shell 完成的最小命令。 +- 只有在 Bash 确实必要时才使用 Bash。 +- Windows 环境下优先使用兼容写法,不默认使用 `cat < Config: @@ -40,7 +42,7 @@ def resolve_config(workspace: Path, cli: dict[str, Any]) -> Config: "", ) base_url = _pick(cli.get("base_url"), os.getenv("CC_SLIM_BASE_URL"), file_cfg.get("base_url"), None) - max_turns_raw = _pick(cli.get("max_turns"), os.getenv("CC_SLIM_MAX_TURNS"), file_cfg.get("max_turns"), 8) + max_turns_raw = _pick(cli.get("max_turns"), os.getenv("CC_SLIM_MAX_TURNS"), file_cfg.get("max_turns"), 12) if not api_key: raise ValueError("缺少 API key,请通过 CLI、环境变量或 .cc-slim.toml 提供。") @@ -120,6 +122,8 @@ class Agent: def _build_system_prompt(self, workspace: Path) -> str: parts: list[str] = [] + parts.append(self._build_runtime_summary(workspace)) + agents = workspace / "AGENTS.md" if agents.exists(): parts.append(agents.read_text(encoding="utf-8")) @@ -131,6 +135,26 @@ class Agent: return "\n\n".join(part.strip() for part in parts if part.strip()) + def _build_runtime_summary(self, workspace: Path) -> str: + tool_names = ", ".join(self.tools.keys()) or "(none)" + shell_name = self._detect_shell() + return "\n".join( + [ + "## 运行环境", + f"- 平台: {platform.system() or 'Unknown'}", + f"- sys.platform: {sys.platform}", + f"- shell: {shell_name}", + f"- workspace: {workspace}", + f"- 可用工具: {tool_names}", + "- 行动时必须以以上运行环境信息为准,不要默认套用 Unix/Linux 命令习惯。", + ] + ) + + def _detect_shell(self) -> str: + if os.name == "nt": + return os.getenv("COMSPEC", "Windows shell (likely PowerShell or cmd.exe)") + return os.getenv("SHELL", "unknown shell") + def _call_openai(self) -> dict[str, Any]: response = self.client.chat.completions.create( model=self.config.model,