Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions s12_task_system/README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,23 @@ Automatically calls `save_task` on creation to write `.tasks/{id}.json`. `blocke
A task can only start after all its `blockedBy` dependencies are **completed**:

```python
def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False # missing dependency = blocked
dep = load_task(dep_id)
if dep.status != "completed":
Expand All @@ -106,8 +119,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s12_task_system/README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,23 @@ def create_task(subject: str, description: str = "",
タスクは `blockedBy` が**すべて completed** になってからでないと開始できない:

```python
def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False # missing dependency = blocked
dep = load_task(dep_id)
if dep.status != "completed":
Expand All @@ -106,8 +119,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s12_task_system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,23 @@ def create_task(subject: str, description: str = "",
一个任务只能在它的 `blockedBy` **全部 completed** 之后才能开始:

```python
def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False # missing dependency = blocked
dep = load_task(dep_id)
if dep.status != "completed":
Expand All @@ -106,8 +119,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s12_task_system/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,25 @@ def get_task(task_id: str) -> str:
return json.dumps(asdict(task), indent=2)


def _build_task_index() -> dict[str, str]:
"""Build a {id: id, subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
"""Check if all blockedBy dependencies are completed.
Missing dependencies are treated as blocked."""
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False
if load_task(dep_id).status != "completed":
return False
Expand All @@ -113,8 +126,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if not _task_path(d).exists() or load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s13_background_tasks/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,25 @@ def get_task(task_id: str) -> str:
return json.dumps(asdict(task), indent=2)


def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
"""Check if all blockedBy dependencies are completed.
Missing dependencies are treated as blocked."""
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False
if load_task(dep_id).status != "completed":
return False
Expand All @@ -112,8 +125,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if not _task_path(d).exists() or load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s14_cron_scheduler/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,25 @@ def get_task(task_id: str) -> str:
return json.dumps(asdict(task), indent=2)


def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
"""Check if all blockedBy dependencies are completed.
Missing dependencies are treated as blocked."""
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False
if load_task(dep_id).status != "completed":
return False
Expand All @@ -114,8 +127,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if not _task_path(d).exists() or load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s15_agent_teams/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,25 @@ def get_task(task_id: str) -> str:
return json.dumps(asdict(task), indent=2)


def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
"""Check if all blockedBy dependencies are completed.
Missing dependencies are treated as blocked."""
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False
if load_task(dep_id).status != "completed":
return False
Expand All @@ -112,8 +125,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if not _task_path(d).exists() or load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
25 changes: 21 additions & 4 deletions s16_team_protocols/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,25 @@ def get_task(task_id: str) -> str:
return json.dumps(asdict(task), indent=2)


def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
"""Check if all blockedBy dependencies are completed.
Missing dependencies are treated as blocked."""
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False
if load_task(dep_id).status != "completed":
return False
Expand All @@ -116,8 +129,12 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.status != "pending":
return f"Task {task_id} is {task.status}, cannot claim"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if not _task_path(d).exists() or load_task(d).status != "completed"]
idx = _build_task_index()
deps = []
for d in task.blockedBy:
did = idx.get(d)
if did is None or load_task(did).status != "completed":
deps.append(d)
return f"Blocked by: {deps}"
task.owner = owner
task.status = "in_progress"
Expand Down
29 changes: 24 additions & 5 deletions s17_autonomous_agents/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,23 @@ def get_task(task_id: str) -> str:
return json.dumps(asdict(task), indent=2)


def _build_task_index() -> dict[str, str]:
"""Build a {subject: id} lookup for resolving refs to task IDs."""
lookup = {}
for f in TASKS_DIR.glob("task_*.json"):
t = json.loads(f.read_text())
lookup[t["subject"]] = t["id"]
return lookup


def can_start(task_id: str) -> bool:
task = load_task(task_id)
for dep_id in task.blockedBy:
if not _task_path(dep_id).exists():
if not task.blockedBy:
return True
idx = _build_task_index()
for dep_ref in task.blockedBy:
dep_id = idx.get(dep_ref)
if dep_id is None:
return False
if load_task(dep_id).status != "completed":
return False
Expand All @@ -108,9 +121,15 @@ def claim_task(task_id: str, owner: str = "agent") -> str:
if task.owner:
return f"Task {task_id} already owned by {task.owner}"
if not can_start(task_id):
deps = [d for d in task.blockedBy
if _task_path(d).exists() and load_task(d).status != "completed"]
missing = [d for d in task.blockedBy if not _task_path(d).exists()]
idx = _build_task_index()
deps = []
missing = []
for d in task.blockedBy:
did = idx.get(d)
if did is None:
missing.append(d)
elif load_task(did).status != "completed":
deps.append(d)
parts = []
if deps: parts.append(f"blocked by: {deps}")
if missing: parts.append(f"missing deps: {missing}")
Expand Down
Loading