读取 git status 快照
(cwd: str)
| 188 | # 这样 AI 就知道你当前改了哪些文件、有没有未提交的修改。 |
| 189 | |
| 190 | def read_git_status(cwd: str) -> Optional[str]: |
| 191 | """读取 git status 快照""" |
| 192 | try: |
| 193 | result = subprocess.run( |
| 194 | ["git", "--no-optional-locks", "status", "--short", "--branch"], |
| 195 | cwd=cwd, capture_output=True, text=True, timeout=5, |
| 196 | ) |
| 197 | if result.returncode != 0: |
| 198 | return None |
| 199 | output = result.stdout.strip() |
| 200 | return output if output else None |
| 201 | except (subprocess.TimeoutExpired, FileNotFoundError): |
| 202 | return None |
| 203 | |
| 204 | |
| 205 | def read_git_diff(cwd: str) -> Optional[str]: |