# gnhf - 睡前设定目标,让 AI Agent 在你睡觉时持续工作 > 自主 AI Agent 编排器,支持 Claude Code/Codex/Rovo Dev/OpenCode/Copilot CLI,每次迭令一个小改动,成功 commit 失败 rollback ## 项目简介 gnhf(good night, have fun)是一个受 [ralph](https://ghuntley.com/ralph/) 和 [autoresearch](https://github.com/karpathy/autoresearch) 启发的自主 AI Agent 编排器。核心理念很简单:**睡前设定目标,让 Agent 在你睡觉时持续工作,每次迭代做一个小改动,醒来时分支上已经满是干净的提交和完整日志。** ## 核心特性 - **极简**:一条命令启动自主循环,Ctrl+C 或达到配置上限时自动停止 - **长时运行**:每次迭代成功则 commit,失败则 `git reset --hard` 回滚;硬错误指数退避,Agent 报告的失败立即进入下一迭代 - **实时状态**:交互式运行时更新终端标题,显示当前状态、token 总量和 commit 数 - **Agent 无关**:默认支持 Claude Code、Codex、Rovo Dev、OpenCode、GitHub Copilot CLI - **Worktree 并行**:同一仓库同时跑多个 Agent,每个独立工作目录和分支 - **Resume 恢复**:在已有的 `gnhf/` 分支上继续之前的运行 - **共享记忆**:Agent 通过 `notes.md` 跨迭代传递上下文 ## 快速使用 ```sh # 睡前设定目标,让 Agent 自动工作 $ gnhf "reduce complexity of the codebase without changing functionality" # 限制迭代次数和 token 上限 $ gnhf "reduce complexity" --max-iterations 10 --max-tokens 5000000 # 多个 Agent 并行运行 $ gnhf --worktree "implement feature X" & $ gnhf --worktree "add tests for module Y" & ``` ## 安装 ```sh npm install -g gnhf ``` 或从源码构建: ```sh git clone https://github.com/kunchenguid/gnhf.git cd gnhf npm install && npm run build && npm link ``` ## 配置 配置文件位于 `~/.gnhf/config.yml`: ```yaml agent: claude # 默认 Agent preventSleep: true # 运行时防止系统休眠 maxConsecutiveFailures: 3 # 连续失败 3 次后中止 agentPathOverride: # 自定义 Agent 路径 claude: ~/bin/claude-code-switch agentArgsOverride: # 传递额外 CLI 参数 codex: - -m - gpt-5.4 ``` ## 支持的 Agent | Agent | 说明 | |-------|------| | Claude Code | Anthropic 官方 CLI | | Codex | OpenAI 官方 CLI | | Rovo Dev | Atlassian AI 开发助手 | | OpenCode | 开源 AI 编码助手 | | GitHub Copilot CLI | GitHub 官方 CLI | ## 平台 macOS | Linux | Windows(防止休眠机制分别使用 `caffeinate` / `systemd-inhibit` / PowerShell) ## Stars ⭐ GitHub 星标数持续增长中 | TypeScript/Node.js | npm 可直接安装 --- **分类**:软件 **标签**:Agent · CLI · gnhf **作者**:Xiao.Xi **链接**:https://octohz.com/p/1577