NEP框架重构00阶段
This commit is contained in:
31
src/state.py
Normal file
31
src/state.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# src/state.py
|
||||
import os
|
||||
import json
|
||||
|
||||
class StateTracker:
|
||||
def __init__(self, workspace_dir):
|
||||
self.state_file = os.path.join(workspace_dir, "workflow_status.json")
|
||||
self.completed_tasks = set()
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
if os.path.exists(self.state_file):
|
||||
try:
|
||||
with open(self.state_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
self.completed_tasks = set(data.get("completed", []))
|
||||
except:
|
||||
self.completed_tasks = set()
|
||||
|
||||
def mark_done(self, task_id):
|
||||
"""标记任务完成并保存"""
|
||||
self.completed_tasks.add(task_id)
|
||||
self.save()
|
||||
|
||||
def is_done(self, task_id):
|
||||
"""检查任务是否已完成"""
|
||||
return task_id in self.completed_tasks
|
||||
|
||||
def save(self):
|
||||
with open(self.state_file, 'w') as f:
|
||||
json.dump({"completed": list(self.completed_tasks)}, f, indent=2)
|
||||
Reference in New Issue
Block a user