Compare commits

..

5 Commits

Author SHA1 Message Date
pzhang_zywl c2affcad42 fix: 移除 hardcode 输入文件路径,完善输入验证 - Closes #8
CI / test (pull_request) Successful in 9s
- 移除 _DEFAULT_INPUT 硬编码默认输入文件路径
- INPUT_JSON 仅从 IR_INPUT_JSON 环境变量获取
- load_input_document() 无输入时给出明确错误提示
- 新增 test_no_hardcoded_input_file / test_set_input_file_accepts_none

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 16:16:49 +08:00
pzhang_zywl 73291803b6 Merge pull request 'docs: DEV_AGENT.md 完善自举能力' (#7) from dev/issue-3-unified-output-dir into main
CI / test (push) Successful in 9s
2026-05-31 15:51:08 +08:00
pzhang_zywl e792fac6c0 docs: DEV_AGENT.md 完善自举能力,新增命令速查表和闭环检查清单
CI / test (pull_request) Successful in 9s
- 新增 agent_poller 8 命令速查表
- 新增闭环完成 12 步检查清单
- 步骤 4 增加 PR 创建后评论 Issue 的步骤
- start_dev_agent.sh 启动提示更新为完整闭环指令

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 15:49:42 +08:00
pzhang_zywl e71ab9715e Merge pull request 'fix: 优化输出文件目录 - Closes #3' (#6) from dev/issue-3-unified-output-dir into main
CI / test (push) Successful in 7s
2026-05-31 14:42:42 +08:00
pzhang_zywl c31ddd0bb3 fix: agent_poller merge-pr 处理 Gitea 空响应体 - Closes #3
CI / test (pull_request) Successful in 7s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 14:41:23 +08:00
5 changed files with 104 additions and 10 deletions
+42
View File
@@ -111,6 +111,18 @@ python scripts/agent_poller.py --action create-pr \
Closes #N" Closes #N"
``` ```
PR 创建后,在 Issue 下评论 PR 链接:
```bash
python scripts/agent_poller.py --action comment --issue N \
--body "PR 已创建: <PR_URL>
变更:
- <摘要>
等待 CI 通过后 merge。"
```
### 5. 等待 CI ### 5. 等待 CI
PR 创建后 CI 自动触发。用 agent_poller 监控状态: PR 创建后 CI 自动触发。用 agent_poller 监控状态:
@@ -166,3 +178,33 @@ QE-Agent 开 Issue (qe-feedback)
- **测试**:每次提交前必须确保 `python -m pytest -v` 全量通过 - **测试**:每次提交前必须确保 `python -m pytest -v` 全量通过
- **范围**:不混入与当前 Issue 无关的改动 - **范围**:不混入与当前 Issue 无关的改动
- **PR**Push 后立即创建 PRCI 通过后 mergePR 信息写入 Issue 后关闭 - **PR**Push 后立即创建 PRCI 通过后 mergePR 信息写入 Issue 后关闭
## agent_poller 命令速查
| 命令 | 用途 | 阶段 |
|------|------|------|
| `--action list` | 列出所有待处理 Issue | 1. 轮询 |
| `--action get --issue N` | 查看 Issue 详情 | 2. 分析 |
| `--action create-pr --issue N --branch X --body "..."` | 创建 PR | 4. 提 PR |
| `--action comment --issue N --body "..."` | 评论 Issue(记录 PR 链接等) | 4. 提 PR |
| `--action pr-status --pr N` | 查看 PR + CI 状态 | 5. 等 CI |
| `--action merge-pr --pr N` | Merge PR(自动检查 CI | 6. Merge |
| `--action close-issue --issue N --body "..."` | 手动关闭 Issue | 6. 关闭 |
| `--action lifecycle --issue N` | 查看 Issue 完整生命周期 | 随时 |
## 闭环完成检查清单
处理每个 Issue 时,确认以下节点全部完成:
- [ ] **分析**`agent_poller.py --action get` 理解 Issue 内容
- [ ] **分支**`git checkout -b dev/issue-N-<slug>`
- [ ] **开发**:修改功能代码 + 同步更新 UT
- [ ] **测试**`python -m pytest -v` 全量通过
- [ ] **提交**`git commit -m "fix: <描述> - Closes #N"`
- [ ] **推送**`git push origin dev/issue-N-<slug>`
- [ ] **PR**`agent_poller.py --action create-pr` 创建 PR
- [ ] **评论**`agent_poller.py --action comment` 在 Issue 下记录 PR 链接
- [ ] **CI**`agent_poller.py --action pr-status` 确认 CI 通过
- [ ] **合并**`agent_poller.py --action merge-pr` 合并 PR
- [ ] **关闭**:确认 Issue 已自动关闭,否则 `--action close-issue`
- [ ] **验证**`agent_poller.py --action lifecycle` 确认全流程完成
+9 -2
View File
@@ -33,7 +33,10 @@ def _req(method, path, data=None):
req.add_header("Content-Type", "application/json") req.add_header("Content-Type", "application/json")
try: try:
with urllib.request.urlopen(req) as resp: with urllib.request.urlopen(req) as resp:
return json.loads(resp.read()) raw = resp.read()
if not raw:
return {} # Gitea merge returns 200 with empty body
return json.loads(raw)
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
body = e.read().decode() body = e.read().decode()
print(f"API Error {e.code}: {body}", file=sys.stderr) print(f"API Error {e.code}: {body}", file=sys.stderr)
@@ -153,7 +156,11 @@ def merge_pr(pr_num):
sys.exit(1) sys.exit(1)
result = _req("POST", f"/pulls/{pr_num}/merge", {"Do": "merge"}) result = _req("POST", f"/pulls/{pr_num}/merge", {"Do": "merge"})
if result.get("merged"): # Verify merge success by re-checking PR state
pr_after = _req("GET", f"/pulls/{pr_num}")
if pr_after.get("merged"):
print(f"PR #{pr_num} merged successfully")
elif result.get("merged"):
print(f"PR #{pr_num} merged successfully") print(f"PR #{pr_num} merged successfully")
else: else:
print(f"Merge result: {result.get('message', 'unknown')}") print(f"Merge result: {result.get('message', 'unknown')}")
+3 -2
View File
@@ -26,19 +26,20 @@ case "$MODE" in
echo "" echo ""
echo "正在执行单次检查..." echo "正在执行单次检查..."
claude -p --agent agents/DEV_AGENT.md \ claude -p --agent agents/DEV_AGENT.md \
"你是 Dev-Agent检查 Gitea 所有打开的 Issue,跳过纯测试相关的,其他全部领取分析并修复,记得同步更新测试。" "你是 Dev-Agent检查 Gitea 所有打开的 Issue--action list),跳过纯测试相关的。对每个负责的 Issue,走完完整闭环:分析 → 分支 → 开发+UT → pytest → commit → push → create-pr → comment Issue → 等 CI → merge-pr → 关闭。"
;; ;;
2) 2)
echo "" echo ""
echo "启动持续轮询模式 (每 10 分钟)..." echo "启动持续轮询模式 (每 10 分钟)..."
echo "按 Ctrl+C 停止" echo "按 Ctrl+C 停止"
claude -p --agent agents/DEV_AGENT.md \ claude -p --agent agents/DEV_AGENT.md \
"你是 Dev-Agent用 loop 模式每 10 分钟检查一次 Gitea 所有打开的 Issue,跳过纯测试相关的,其他全部领取处理。完成后评论进度,push 触发 CI。" "你是 Dev-Agent用 loop 模式每 10 分钟检查一次 Gitea Issue--action list)。跳过纯测试相关的。每个 Issue 走完整闭环:分析→开发→push→create-pr→comment→CI→merge-pr→close。每个步骤用 agent_poller.py 对应命令。"
;; ;;
3) 3)
echo "" echo ""
echo "启动交互模式..." echo "启动交互模式..."
echo "进入后输入: 检查 Gitea Issues 并处理" echo "进入后输入: 检查 Gitea Issues 并处理"
echo "可用命令速查: agent_poller.py --help"
claude --agent agents/DEV_AGENT.md claude --agent agents/DEV_AGENT.md
;; ;;
*) *)
+23 -6
View File
@@ -4,6 +4,7 @@ Reads API keys from a secrets.yaml file, falling back to environment variables.
""" """
import os import os
import sys
import json import json
import yaml import yaml
@@ -23,11 +24,9 @@ PROMPTS_DIR = os.path.join(BASE_DIR, "prompts")
TESTS_DIR = os.path.join(BASE_DIR, "tests") TESTS_DIR = os.path.join(BASE_DIR, "tests")
OUTPUT_DIR = IR_OUTPUT # backward compatibility alias OUTPUT_DIR = IR_OUTPUT # backward compatibility alias
# Input file (the parsed PRD JSON) # Input file (the parsed PRD JSON) — must be set via env var or CLI
_DEFAULT_INPUT = os.path.join( # No hardcoded default to avoid silently processing the wrong document.
PROJECT_OUTPUT, "车机娱乐系统禁止功能文档_脱敏 v0.9_v2_updated.json", INPUT_JSON = os.environ.get("IR_INPUT_JSON", None)
)
INPUT_JSON = os.environ.get("IR_INPUT_JSON", _DEFAULT_INPUT)
def set_input_file(path: str) -> None: def set_input_file(path: str) -> None:
@@ -125,8 +124,26 @@ def llm_client():
def load_input_document(path: str | None = None) -> dict: def load_input_document(path: str | None = None) -> dict:
"""Load the parsed PRD JSON document.""" """Load the parsed PRD JSON document.
Args:
path: Explicit file path. If None, reads from IR_INPUT_JSON env var.
Raises:
FileNotFoundError: If no path is configured.
SystemExit: If the configured path does not exist.
"""
path = path or INPUT_JSON path = path or INPUT_JSON
if not path:
print("错误: 未指定输入文件。请通过以下任一方式指定:", file=sys.stderr)
print(" 1. 设置环境变量: IR_INPUT_JSON=<path>", file=sys.stderr)
print(" 2. 通过 main.py: python main.py --input <path>", file=sys.stderr)
print(" 3. 通过 step 脚本: python step1_semantic_index.py --input <path>", file=sys.stderr)
print(" 4. 程序调用: config.set_input_file(<path>)", file=sys.stderr)
sys.exit(1)
if not os.path.isfile(path):
print(f"错误: 输入文件不存在: {path}", file=sys.stderr)
sys.exit(1)
with open(path, "r", encoding="utf-8") as f: with open(path, "r", encoding="utf-8") as f:
return json.load(f) return json.load(f)
+27
View File
@@ -19,6 +19,33 @@ def test_set_input_file():
config.set_input_file(original) config.set_input_file(original)
def test_no_hardcoded_input_file():
"""INPUT_JSON should not have a hardcoded default — comes from env or None."""
# When IR_INPUT_JSON env is not set, INPUT_JSON should be None
env_val = os.environ.pop("IR_INPUT_JSON", None)
try:
import importlib
importlib.reload(config)
# After reload without env var, INPUT_JSON should be None
assert config.INPUT_JSON is None, \
f"INPUT_JSON should be None when env not set, got: {config.INPUT_JSON}"
finally:
if env_val is not None:
os.environ["IR_INPUT_JSON"] = env_val
importlib.reload(config)
def test_set_input_file_accepts_none():
"""set_input_file(None) should work for resetting."""
original = config.INPUT_JSON
try:
config.set_input_file("/tmp/test.json")
config.set_input_file(None)
assert config.INPUT_JSON is None
finally:
config.set_input_file(original)
def test_config_constants_exist(): def test_config_constants_exist():
"""Verify all expected path constants are defined.""" """Verify all expected path constants are defined."""
assert config.BASE_DIR assert config.BASE_DIR