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,