Files
ai4se-harness-suite/agents-workflow-engine/agents_workflow_engine/state.py
ning-inspire 69cfaea7dc feat: 引入 agents-workflow-engine 与 5 个 SDD skill
新增 agents-workflow-engine:主会话按泳道图调度子 agent 到提测,
含 schema、preset、CLI、单测,并接入 verify.sh。

agile-team-sdd 新增 5 个模板:ba-write-prototype、ba-requirement-review、
dev-plan-review、dev-plan-amend、pm-start-iteration,已登记 catalog
并同步安装到 example-project;README/AGENTS.md 同步 skill 数量 21→26。

验证:./.agents/verify.sh 全绿(67 项,含 AWE 14 个单测)。
文档同步检查:已更新 README、AGENTS.md、agile-team-sdd/README.md 与 SKILL.md。
2026-11-19 10:05:10 +08:00

103 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""一个迭代一条 workflow,进度落在 state.json。"""
from __future__ import annotations
import json
import os
import re
from .errors import GraphError
_NAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$")
def check_iteration(name: str) -> str:
if not name or not _NAME.match(name):
raise GraphError("迭代名不合法:%s。只用字母、数字、点、下划线和连字符" % name)
return name
def instance_dir(project: str, iteration: str) -> str:
return os.path.join(project, ".agents", "workflow", "iterations", check_iteration(iteration))
def state_path(project: str, iteration: str) -> str:
return os.path.join(instance_dir(project, iteration), "state.json")
def decisions_path(project: str, iteration: str) -> str:
return os.path.join(instance_dir(project, iteration), "decisions.jsonl")
def load_state(project: str, iteration: str) -> dict:
path = state_path(project, iteration)
if not os.path.isfile(path):
return {}
with open(path, "r", encoding="utf-8") as handle:
data = json.load(handle)
if not isinstance(data, dict):
raise GraphError("进度文件损坏:%s" % path)
return data
def save_state(project: str, iteration: str, state: dict) -> str:
path = state_path(project, iteration)
os.makedirs(os.path.dirname(path), exist_ok=True)
temporary = path + ".tmp"
with open(temporary, "w", encoding="utf-8") as handle:
json.dump(state, handle, ensure_ascii=False, indent=2)
handle.write("\n")
os.replace(temporary, path)
logged = int(state.get("logged") or 0)
progress = state.get("progress") or []
fresh = progress[logged:]
if fresh:
with open(decisions_path(project, iteration), "a", encoding="utf-8") as handle:
for item in fresh:
handle.write(json.dumps(item, ensure_ascii=False) + "\n")
state["logged"] = len(progress)
with open(temporary, "w", encoding="utf-8") as handle:
json.dump(state, handle, ensure_ascii=False, indent=2)
handle.write("\n")
os.replace(temporary, path)
return path
def list_states(project: str) -> list:
root = os.path.join(project, ".agents", "workflow", "iterations")
if not os.path.isdir(root):
return []
found = []
for name in sorted(os.listdir(root)):
path = os.path.join(root, name, "state.json")
if os.path.isfile(path):
with open(path, "r", encoding="utf-8") as handle:
found.append(json.load(handle))
return found
def open_instance(project: str, iteration: str, entry: str) -> dict:
"""没有记录就创建。已有记录就返回它,用来接着跑。已到提测则拒绝再开一条。"""
check_iteration(iteration)
existing = load_state(project, iteration)
if not existing:
state = {
"iteration": iteration,
"status": "running",
"current": entry,
"visits": {},
"loopCounts": {},
"tasks": [],
"taskIndex": 0,
"progress": [],
"logged": 0,
}
save_state(project, iteration, state)
return state
if existing.get("status") == "completed":
raise GraphError(
"迭代 %s 已经有一条 workflow,并且已经到提测。不能再创建一条。用 status --iteration %s 查看"
% (iteration, iteration)
)
return existing