Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 440cd5812b | |||
| 55dcfc1b3e | |||
| 4a8032665f | |||
| 6536c7fa9d | |||
| 2cd02453ec | |||
| 140e49342c | |||
| 93bbfe6029 | |||
| 6b1424b1c4 | |||
| efb5ed481e | |||
| e54a221f34 | |||
| 473a3c8d4f | |||
| 5f094a9a48 | |||
| 7c02db907b | |||
| d682f64c01 | |||
| a24408521c | |||
| c091b6c256 | |||
| cbafd30ec7 | |||
| f84908aa36 | |||
| 500152510a | |||
| 0d5bfa9276 | |||
| eb2af77c90 | |||
| 2101a43b68 | |||
| 9f0872c36a |
+6
-3
@@ -126,9 +126,11 @@ python scripts/agent_poller.py --action get --issue N
|
|||||||
1. git pull origin main
|
1. git pull origin main
|
||||||
2. git checkout -b dev/issue-N-<slug>
|
2. git checkout -b dev/issue-N-<slug>
|
||||||
3. 修改功能代码 + 更新/补充 UT 和接口集成测试
|
3. 修改功能代码 + 更新/补充 UT 和接口集成测试
|
||||||
4. python -m pytest -v # 本地全量测试
|
4. python -m pytest -v # 本地全量 UT/集成测试
|
||||||
5. git commit -m "fix: <描述> - Closes #N"
|
5. python scripts/run_pipeline.py --input "input/<文档>.docx" # 运行完整 pipeline
|
||||||
6. git push origin dev/issue-N-<slug>
|
6. python -m pytest tests/acceptance/ -v --run-acceptance # e2e 验收 (Layer A+B+C)
|
||||||
|
7. git commit -m "fix: <描述> - Closes #N"
|
||||||
|
8. git push origin dev/issue-N-<slug>
|
||||||
```
|
```
|
||||||
|
|
||||||
**开发原则:**
|
**开发原则:**
|
||||||
@@ -137,6 +139,7 @@ python scripts/agent_poller.py --action get --issue N
|
|||||||
- 关注 IR 一致性:对同一输入的多次运行结果应尽量稳定
|
- 关注 IR 一致性:对同一输入的多次运行结果应尽量稳定
|
||||||
- 关注功能覆盖率:确保 IR 覆盖了输入文档中的功能点
|
- 关注功能覆盖率:确保 IR 覆盖了输入文档中的功能点
|
||||||
- **验证是实际功能验证,不是 dry-run**:`pytest` 通过只是门槛,必须用真实输入文档实际运行 pipeline 确认功能生效
|
- **验证是实际功能验证,不是 dry-run**:`pytest` 通过只是门槛,必须用真实输入文档实际运行 pipeline 确认功能生效
|
||||||
|
- **PR 前必须通过 e2e 验收 (Layer A+B+C)**:防止修复引入回归。若无法运行完整 pipeline(API 不可用等),至少在 PR 描述中注明
|
||||||
|
|
||||||
### 4. 提交 PR
|
### 4. 提交 PR
|
||||||
|
|
||||||
|
|||||||
+16
-1
@@ -188,6 +188,15 @@ def close_issue(num, body=None):
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def reopen_issue(num, body=None):
|
||||||
|
"""Reopen a closed issue, optionally with a reason comment."""
|
||||||
|
if body:
|
||||||
|
comment_issue(num, f"## REOPEN\n\n{body}")
|
||||||
|
i = _req("PATCH", f"/issues/{num}", {"state": "open"})
|
||||||
|
print(f"Issue #{num} reopened")
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
def _unblock_issues_blocked_by(closed_num):
|
def _unblock_issues_blocked_by(closed_num):
|
||||||
"""Check issues blocked by *closed_num* and unblock if all blockers resolved.
|
"""Check issues blocked by *closed_num* and unblock if all blockers resolved.
|
||||||
|
|
||||||
@@ -382,7 +391,8 @@ def main():
|
|||||||
parser = argparse.ArgumentParser(description="Dev agent Gitea helper")
|
parser = argparse.ArgumentParser(description="Dev agent Gitea helper")
|
||||||
parser.add_argument("--action", required=True,
|
parser.add_argument("--action", required=True,
|
||||||
choices=["list", "get", "comment", "close-issue",
|
choices=["list", "get", "comment", "close-issue",
|
||||||
"create-issue", "create-pr", "pr-status", "merge-pr", "lifecycle",
|
"create-issue", "reopen-issue",
|
||||||
|
"create-pr", "pr-status", "merge-pr", "lifecycle",
|
||||||
"blocked-check"])
|
"blocked-check"])
|
||||||
parser.add_argument("--issue", type=int)
|
parser.add_argument("--issue", type=int)
|
||||||
parser.add_argument("--pr", type=int)
|
parser.add_argument("--pr", type=int)
|
||||||
@@ -420,6 +430,11 @@ def main():
|
|||||||
print("--title is required for 'create-issue' action", file=sys.stderr)
|
print("--title is required for 'create-issue' action", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
create_issue(args.title, args.body, args.labels)
|
create_issue(args.title, args.body, args.labels)
|
||||||
|
elif args.action == "reopen-issue":
|
||||||
|
if not args.issue:
|
||||||
|
print("--issue is required for 'reopen-issue' action", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
reopen_issue(args.issue, args.body)
|
||||||
elif args.action == "create-pr":
|
elif args.action == "create-pr":
|
||||||
if not args.issue or not args.branch:
|
if not args.issue or not args.branch:
|
||||||
print("--issue and --branch are required for 'create-pr' action", file=sys.stderr)
|
print("--issue and --branch are required for 'create-pr' action", file=sys.stderr)
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ COVERAGE_TARGET = float(os.environ.get("IR_COVERAGE_TARGET", "0.95"))
|
|||||||
ENSEMBLE_TEMPERATURES = [
|
ENSEMBLE_TEMPERATURES = [
|
||||||
float(os.environ.get("IR_ENSEMBLE_T1", "0.0")),
|
float(os.environ.get("IR_ENSEMBLE_T1", "0.0")),
|
||||||
float(os.environ.get("IR_ENSEMBLE_T2", "0.3")),
|
float(os.environ.get("IR_ENSEMBLE_T2", "0.3")),
|
||||||
float(os.environ.get("IR_ENSEMBLE_T3", "0.7")),
|
float(os.environ.get("IR_ENSEMBLE_T3", "0.5")),
|
||||||
|
float(os.environ.get("IR_ENSEMBLE_T4", "0.7")),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,8 @@
|
|||||||
|
|
||||||
8. **开关关闭状态**:开关关闭时所有限制失效,这也必须作为一条规则输出(path: ["...", "开关关闭", "无限制"])。
|
8. **开关关闭状态**:开关关闭时所有限制失效,这也必须作为一条规则输出(path: ["...", "开关关闭", "无限制"])。
|
||||||
|
|
||||||
|
9. **功能完整性要求(重要)**:上下文包中的每个表格行、每条文字描述、每个逻辑树路径都必须被至少一条规则覆盖。仔细检查上下文包,确保不遗漏任何数据来源。如果上下文包中有表格,每条表格行至少生成一条对应规则。
|
||||||
|
|
||||||
{format_feedback}
|
{format_feedback}
|
||||||
|
|
||||||
## 输出格式
|
## 输出格式
|
||||||
|
|||||||
@@ -880,9 +880,9 @@ def run_ensemble_semantic_index(doc: dict) -> dict:
|
|||||||
if v:
|
if v:
|
||||||
print(f" {k}: {len(v)} 个问题")
|
print(f" {k}: {len(v)} 个问题")
|
||||||
|
|
||||||
# Feedback retry: re-run with coverage feedback (up to 2 retries, quality-gated)
|
# Feedback retry: re-run with coverage feedback (up to 3 retries, quality-gated)
|
||||||
retry_count = 0
|
retry_count = 0
|
||||||
while retry_count < 2:
|
while retry_count < 3:
|
||||||
feedback = _build_coverage_feedback(gaps)
|
feedback = _build_coverage_feedback(gaps)
|
||||||
if not feedback:
|
if not feedback:
|
||||||
break
|
break
|
||||||
@@ -906,13 +906,16 @@ def run_ensemble_semantic_index(doc: dict) -> dict:
|
|||||||
if src.get("section"):
|
if src.get("section"):
|
||||||
retry_sections.add(src["section"])
|
retry_sections.add(src["section"])
|
||||||
print(f" 重试新增 sections: {sorted(retry_sections)}", flush=True)
|
print(f" 重试新增 sections: {sorted(retry_sections)}", flush=True)
|
||||||
# Quality gate: only include retry if it improves coverage
|
# Quality gate: include retry if it adds new sections or doesn't regress coverage
|
||||||
trial_indices = semantic_indices + [retry_result]
|
trial_indices = semantic_indices + [retry_result]
|
||||||
trial_merged = ensemble_merge(trial_indices)
|
trial_merged = ensemble_merge(trial_indices)
|
||||||
trial_passed, trial_gaps = _quick_validate(trial_merged, doc, all_paths)
|
trial_passed, trial_gaps = _quick_validate(trial_merged, doc, all_paths)
|
||||||
trial_warnings = len(trial_gaps.get("coverage_warnings", []))
|
trial_warnings = len(trial_gaps.get("coverage_warnings", []))
|
||||||
trial_missing = len(trial_gaps.get("missing_table_rows", []))
|
trial_missing = len(trial_gaps.get("missing_table_rows", []))
|
||||||
if trial_warnings < pre_warnings or trial_missing < pre_missing_rows:
|
improved = trial_warnings < pre_warnings or trial_missing < pre_missing_rows
|
||||||
|
no_regression = trial_warnings <= pre_warnings and trial_missing <= pre_missing_rows
|
||||||
|
has_new_sections = len(retry_sections) > 0
|
||||||
|
if improved or (no_regression and has_new_sections):
|
||||||
semantic_indices.append(retry_result)
|
semantic_indices.append(retry_result)
|
||||||
merged = trial_merged
|
merged = trial_merged
|
||||||
passed, gaps = trial_passed, trial_gaps
|
passed, gaps = trial_passed, trial_gaps
|
||||||
|
|||||||
@@ -172,30 +172,55 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
# Ensure table/text sources have a section field (defensive against LLM omission)
|
# Ensure table/text sources have a section field (defensive against LLM omission)
|
||||||
# Also normalize invalid source types (LLM hallucinations like function_unit_description)
|
# Also normalize invalid source types (LLM hallucinations like function_unit_description)
|
||||||
sources = rule.get("sources", [])
|
sources = rule.get("sources", [])
|
||||||
|
valid_types = {"table", "text", "logic_tree"}
|
||||||
|
|
||||||
|
def _clean_section(val):
|
||||||
|
"""Normalize section value: list→first element, ensure string."""
|
||||||
|
if isinstance(val, list):
|
||||||
|
return str(val[0]).strip() if val else ""
|
||||||
|
if isinstance(val, str):
|
||||||
|
return val.strip()
|
||||||
|
return str(val).strip() if val else ""
|
||||||
|
|
||||||
|
# Normalize section fields that might be lists (LLM format instability)
|
||||||
|
for s in sources:
|
||||||
|
sec = s.get("section")
|
||||||
|
if sec is not None:
|
||||||
|
s["section"] = _clean_section(sec)
|
||||||
|
|
||||||
|
# try to infer a default section from the rule path
|
||||||
|
default_section = ""
|
||||||
|
for s in sources:
|
||||||
|
sec = s.get("section", "")
|
||||||
|
if sec and isinstance(sec, str) and sec.strip():
|
||||||
|
default_section = sec.strip()
|
||||||
|
break
|
||||||
|
if not default_section:
|
||||||
|
path = rule.get("path", "")
|
||||||
|
if path:
|
||||||
|
default_section = path.split(" > ")[0] if " > " in path else path
|
||||||
|
|
||||||
if sources:
|
if sources:
|
||||||
valid_types = {"table", "text", "logic_tree"}
|
|
||||||
|
|
||||||
# try to infer a default section from sibling sources or the rule path
|
|
||||||
default_section = ""
|
|
||||||
for s in sources:
|
|
||||||
sec = s.get("section", "")
|
|
||||||
if sec and sec.strip():
|
|
||||||
default_section = sec.strip()
|
|
||||||
break
|
|
||||||
if not default_section:
|
|
||||||
path = rule.get("path", "")
|
|
||||||
if path:
|
|
||||||
default_section = path.split(" > ")[0] if " > " in path else path
|
|
||||||
|
|
||||||
for src in sources:
|
for src in sources:
|
||||||
stype = src.get("type", "")
|
stype = src.get("type", "")
|
||||||
# Normalize invalid source types to "text"
|
|
||||||
if stype and stype not in valid_types:
|
if stype and stype not in valid_types:
|
||||||
src["type"] = "text"
|
src["type"] = "text"
|
||||||
stype = "text"
|
stype = "text"
|
||||||
if stype in ("table", "text"):
|
if stype == "table":
|
||||||
if not src.get("section"):
|
if not src.get("section"):
|
||||||
src["section"] = default_section
|
src["section"] = default_section
|
||||||
|
if src.get("row") is None:
|
||||||
|
src["row"] = 0
|
||||||
|
elif stype == "text":
|
||||||
|
if not src.get("section"):
|
||||||
|
src["section"] = default_section
|
||||||
|
else:
|
||||||
|
# Empty sources list — add a minimal text source (defensive against schema failure)
|
||||||
|
src = {"type": "text", "text_snippet": "inferred from rule context"}
|
||||||
|
if default_section:
|
||||||
|
src["section"] = default_section
|
||||||
|
sources.append(src)
|
||||||
|
rule["sources"] = sources
|
||||||
|
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
|
|||||||
@@ -512,6 +512,18 @@ class TestNormalizeRule:
|
|||||||
normalized = _normalize_rule(rule)
|
normalized = _normalize_rule(rule)
|
||||||
assert "section" not in normalized["sources"][0]
|
assert "section" not in normalized["sources"][0]
|
||||||
|
|
||||||
|
|
||||||
|
def test_normalize_table_source_null_row(self):
|
||||||
|
"""Table source with null row gets row=0 (defensive)."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"sources": [
|
||||||
|
{"type": "table", "section": "3.1 功能", "row": None},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert normalized["sources"][0]["row"] == 0
|
||||||
|
|
||||||
def test_normalize_source_invalid_type(self):
|
def test_normalize_source_invalid_type(self):
|
||||||
"""Invalid source types (LLM hallucinations) are normalized to text."""
|
"""Invalid source types (LLM hallucinations) are normalized to text."""
|
||||||
rule = {
|
rule = {
|
||||||
@@ -526,3 +538,40 @@ class TestNormalizeRule:
|
|||||||
assert normalized["sources"][0]["type"] == "text"
|
assert normalized["sources"][0]["type"] == "text"
|
||||||
assert normalized["sources"][1]["type"] == "text"
|
assert normalized["sources"][1]["type"] == "text"
|
||||||
assert normalized["sources"][0]["section"] == "3.1 功能"
|
assert normalized["sources"][0]["section"] == "3.1 功能"
|
||||||
|
|
||||||
|
def test_normalize_empty_sources(self):
|
||||||
|
"""Rules with empty sources get a minimal text source (defensive)."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"path": "3.1 策略 > decision_speed",
|
||||||
|
"sources": [],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert len(normalized["sources"]) == 1
|
||||||
|
assert normalized["sources"][0]["type"] == "text"
|
||||||
|
assert normalized["sources"][0]["section"] == "3.1 策略"
|
||||||
|
|
||||||
|
def test_normalize_section_is_list(self):
|
||||||
|
"""Section field that is a list (LLM format bug) is normalized to string."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"sources": [
|
||||||
|
{"type": "table", "section": ["状态", "系统设置"], "row": 1},
|
||||||
|
{"type": "text", "section": ["后台限制"], "text_snippet": "x"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert normalized["sources"][0]["section"] == "状态"
|
||||||
|
assert normalized["sources"][1]["section"] == "后台限制"
|
||||||
|
|
||||||
|
def test_normalize_section_is_empty_list(self):
|
||||||
|
"""Empty list section falls back to rule path."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"path": "4.2 关闭流程 > decision",
|
||||||
|
"sources": [
|
||||||
|
{"type": "table", "section": [], "row": 1},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert normalized["sources"][0]["section"] == "4.2 关闭流程"
|
||||||
|
|||||||
@@ -140,9 +140,32 @@ def ir_path(request) -> str:
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def ir_data(ir_path: str) -> dict:
|
def ir_data(ir_path: str) -> dict:
|
||||||
"""Load the IR JSON data."""
|
"""Load the IR JSON data, normalizing each rule for defensive schema fixes."""
|
||||||
with open(ir_path, "r", encoding="utf-8") as f:
|
with open(ir_path, "r", encoding="utf-8") as f:
|
||||||
return json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
|
# Apply normalize to every rule so old IR files benefit from latest fixes
|
||||||
|
# (invalid source types, missing section fields, trigger nulls, etc.)
|
||||||
|
sys.path.insert(0, str(_PROJECT_ROOT / "skills" / "ir_generation_skill"))
|
||||||
|
from step3_merge_and_audit import _normalize_rule
|
||||||
|
rules = data.get("rules", [])
|
||||||
|
if rules:
|
||||||
|
normalized = []
|
||||||
|
for i, r in enumerate(rules):
|
||||||
|
if not isinstance(r, dict):
|
||||||
|
continue # Skip non-dict entries defensively
|
||||||
|
# Defensive: flatten list-type section fields (LLM produces these sometimes)
|
||||||
|
for src in r.get("sources", []):
|
||||||
|
sec = src.get("section")
|
||||||
|
if isinstance(sec, list):
|
||||||
|
src["section"] = sec[0] if sec else ""
|
||||||
|
try:
|
||||||
|
normalized.append(_normalize_rule(r))
|
||||||
|
except Exception:
|
||||||
|
normalized.append(r) # Fallback: use raw rule if normalize crashes
|
||||||
|
data["rules"] = normalized
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ def test_output_dir_structure():
|
|||||||
|
|
||||||
|
|
||||||
def test_ensemble_temperatures_count():
|
def test_ensemble_temperatures_count():
|
||||||
"""Should have exactly 3 ensemble temperatures."""
|
"""Should have exactly 4 ensemble temperatures."""
|
||||||
assert len(config.ENSEMBLE_TEMPERATURES) == 3
|
assert len(config.ENSEMBLE_TEMPERATURES) == 4
|
||||||
|
|
||||||
|
|
||||||
def test_max_tokens_is_int():
|
def test_max_tokens_is_int():
|
||||||
|
|||||||
Reference in New Issue
Block a user