chore: save current work

This commit is contained in:
2026-09-01 16:37:27 +08:00
parent bc87bd6d2d
commit 97a03c290b
24 changed files with 1380 additions and 5073 deletions
@@ -49,8 +49,8 @@ class SqliteTaskRepository:
repair_required INTEGER NOT NULL DEFAULT 0,
last_error TEXT,
retry_from_phase TEXT NOT NULL DEFAULT '',
requirements_draft_path TEXT NOT NULL DEFAULT '',
requirements_review_path TEXT NOT NULL DEFAULT '',
requirements_spec_path TEXT NOT NULL DEFAULT '',
clarification_path TEXT NOT NULL DEFAULT '',
requirements_contract_path TEXT NOT NULL DEFAULT '',
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
@@ -100,15 +100,6 @@ class SqliteTaskRepository:
);
"""
)
columns = {str(row["name"]) for row in connection.execute("PRAGMA table_info(tasks)").fetchall()}
if "requirements_draft_path" not in columns:
connection.execute("ALTER TABLE tasks ADD COLUMN requirements_draft_path TEXT NOT NULL DEFAULT ''")
if "requirements_review_path" not in columns:
connection.execute("ALTER TABLE tasks ADD COLUMN requirements_review_path TEXT NOT NULL DEFAULT ''")
if "requirements_contract_path" not in columns:
connection.execute("ALTER TABLE tasks ADD COLUMN requirements_contract_path TEXT NOT NULL DEFAULT ''")
if "retry_from_phase" not in columns:
connection.execute("ALTER TABLE tasks ADD COLUMN retry_from_phase TEXT NOT NULL DEFAULT ''")
def create_task(self, task_id: str, request: str) -> TaskState:
with self._lock, self._connection() as connection:
@@ -143,21 +134,17 @@ class SqliteTaskRepository:
verification_warnings = [
str(item) for item in frozen.get("verification_warnings") or () if str(item)
] if isinstance(frozen, dict) else []
applied_normalizations = [
item for item in frozen.get("applied_normalizations") or () if isinstance(item, dict)
] if isinstance(frozen, dict) else []
status_event = next((
item for item in reversed(events)
if item.get("event") in {
"requirements_waiting_for_user", "waiting_retry", "call_budget_exhausted",
"requirements_review_limit_reached", "no_progress_limit",
"no_progress_limit",
"candidate_runtime_execution_failure", "candidate_recovery_runtime_execution_failure",
"failed_author_format", "runtime_contract_invalid",
}
), {}) if state.phase in {TaskPhase.FAILED, TaskPhase.WAITING_RETRY, TaskPhase.WAITING_FOR_USER} else {}
questions = [str(item) for item in status_event.get("questions") or () if str(item)] if isinstance(status_event, dict) else []
findings = [item for item in status_event.get("findings") or () if isinstance(item, dict)] if isinstance(status_event, dict) else []
issues = [str(item.get("description") or "") for item in findings if item.get("description")]
issues = [str(item) for item in status_event.get("issues") or () if str(item)] if isinstance(status_event, dict) else []
return {
"schema_version": "3.0",
"task_id": state.task_id,
@@ -172,12 +159,15 @@ class SqliteTaskRepository:
"repair_required": state.repair_required,
"last_error": state.last_error.value if state.last_error else "",
"retry_from_phase": state.retry_from_phase.value if state.retry_from_phase else "",
"requirements_draft_path": state.requirements_draft_path,
"requirements_review_path": state.requirements_review_path,
"requirements_spec_path": state.requirements_spec_path,
"clarification_path": state.clarification_path,
"requirements_contract_path": state.requirements_contract_path,
"verification_status": "completed_with_risks" if verification_warnings else "verified",
"verification_status": (
"completed_with_risks" if state.phase == TaskPhase.COMPLETED and verification_warnings
else "verified" if state.phase == TaskPhase.COMPLETED
else "pending"
),
"verification_warnings": verification_warnings,
"applied_normalizations": applied_normalizations,
"message": str(status_event.get("message") or "") if isinstance(status_event, dict) else "",
"questions": questions,
"issues": issues,
@@ -228,16 +218,16 @@ class SqliteTaskRepository:
try:
cursor = connection.execute(
"""UPDATE tasks SET phase = ?, state_version = ?, active_revision = ?, pending_action_json = ?,
candidate_id = ?, candidate_stage_id = ?, repair_required = ?, last_error = ?, retry_from_phase = ?, requirements_draft_path = ?,
requirements_review_path = ?, requirements_contract_path = ?, updated_at = CURRENT_TIMESTAMP
candidate_id = ?, candidate_stage_id = ?, repair_required = ?, last_error = ?, retry_from_phase = ?, requirements_spec_path = ?,
clarification_path = ?, requirements_contract_path = ?, updated_at = CURRENT_TIMESTAMP
WHERE task_id = ? AND state_version = ?""",
(
state.phase.value, state.version, state.active_revision,
json.dumps(self._pending_payload(state.pending_action), ensure_ascii=True) if state.pending_action else None,
state.candidate_id, state.candidate_stage_id,
int(state.repair_required), state.last_error.value if state.last_error else None,
state.retry_from_phase.value if state.retry_from_phase else "", state.requirements_draft_path,
state.requirements_review_path, state.requirements_contract_path,
state.retry_from_phase.value if state.retry_from_phase else "", state.requirements_spec_path,
state.clarification_path, state.requirements_contract_path,
state.task_id, previous_version,
),
)
@@ -386,8 +376,8 @@ class SqliteTaskRepository:
repair_required=bool(row["repair_required"]),
last_error=ErrorCode(str(row["last_error"])) if row["last_error"] else None,
retry_from_phase=TaskPhase(str(row["retry_from_phase"])) if row["retry_from_phase"] else None,
requirements_draft_path=str(row["requirements_draft_path"] or ""),
requirements_review_path=str(row["requirements_review_path"] or ""),
requirements_spec_path=str(row["requirements_spec_path"] or ""),
clarification_path=str(row["clarification_path"] or ""),
requirements_contract_path=str(row["requirements_contract_path"] or ""),
)