@team-agent/installer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +201 -0
  2. package/crates/team-agent-core/Cargo.toml +12 -0
  3. package/crates/team-agent-core/src/lib.rs +287 -0
  4. package/crates/team-agent-core/src/main.rs +152 -0
  5. package/examples/team.spec.yaml +206 -0
  6. package/examples/team_state.md +35 -0
  7. package/npm/install.mjs +266 -0
  8. package/package.json +28 -0
  9. package/pyproject.toml +18 -0
  10. package/schemas/result-envelope.schema.json +76 -0
  11. package/schemas/team.schema.json +241 -0
  12. package/scripts/install.py +88 -0
  13. package/scripts/run_regression_tests.py +79 -0
  14. package/skills/team-agent/SKILL.md +173 -0
  15. package/src/team_agent/__init__.py +3 -0
  16. package/src/team_agent/__main__.py +5 -0
  17. package/src/team_agent/cli.py +857 -0
  18. package/src/team_agent/compiler.py +269 -0
  19. package/src/team_agent/coordinator.py +62 -0
  20. package/src/team_agent/errors.py +10 -0
  21. package/src/team_agent/events.py +37 -0
  22. package/src/team_agent/fake_worker.py +80 -0
  23. package/src/team_agent/mcp_server.py +579 -0
  24. package/src/team_agent/message_store.py +497 -0
  25. package/src/team_agent/paths.py +45 -0
  26. package/src/team_agent/permissions.py +123 -0
  27. package/src/team_agent/profiles.py +882 -0
  28. package/src/team_agent/providers.py +1045 -0
  29. package/src/team_agent/routing.py +84 -0
  30. package/src/team_agent/runtime.py +5213 -0
  31. package/src/team_agent/rust_core.py +156 -0
  32. package/src/team_agent/simple_yaml.py +236 -0
  33. package/src/team_agent/spec.py +308 -0
  34. package/src/team_agent/state.py +112 -0
  35. package/src/team_agent/task_graph.py +80 -0
  36. package/templates/team_state.md +32 -0
@@ -0,0 +1,84 @@
1
+ from __future__ import annotations
2
+
3
+ import fnmatch
4
+ import re
5
+ from typing import Any
6
+
7
+
8
+ def route_task(spec: dict[str, Any], task: dict[str, Any]) -> dict[str, Any]:
9
+ leader_id = spec.get("leader", {}).get("id", "leader")
10
+ valid_agents = {leader_id, *(a["id"] for a in spec.get("agents", []))}
11
+ explicit = task.get("assignee")
12
+ if explicit:
13
+ if explicit in valid_agents:
14
+ return {"agent_id": explicit, "reason": "explicit assignee on task"}
15
+ return {"agent_id": leader_id, "reason": f"unknown explicit assignee {explicit!r}"}
16
+
17
+ rules = sorted(
18
+ spec.get("routing", {}).get("rules", []),
19
+ key=lambda rule: rule.get("priority", 0),
20
+ reverse=True,
21
+ )
22
+ for rule in rules:
23
+ if _rule_matches(rule, task):
24
+ return {
25
+ "agent_id": rule["assign_to"],
26
+ "reason": f"matched routing rule {rule.get('id', '<unnamed>')}",
27
+ }
28
+
29
+ default = spec.get("routing", {}).get("default_assignee", leader_id)
30
+ return {"agent_id": default, "reason": "no routing rule matched"}
31
+
32
+
33
+ def _rule_matches(rule: dict[str, Any], task: dict[str, Any]) -> bool:
34
+ match = rule.get("match")
35
+ if isinstance(match, dict) and not _structured_match(match, task):
36
+ return False
37
+ when = rule.get("when")
38
+ if when and not _when_match(str(when), task):
39
+ return False
40
+ return True
41
+
42
+
43
+ def _structured_match(match: dict[str, Any], task: dict[str, Any]) -> bool:
44
+ if "type" in match and task.get("type") not in _as_list(match["type"]):
45
+ return False
46
+ if "risk" in match and task.get("risk") not in _as_list(match["risk"]):
47
+ return False
48
+ if "requires_tools" in match:
49
+ required = set(_as_list(match["requires_tools"]))
50
+ actual = set(task.get("requires_tools", []))
51
+ if not required.issubset(actual):
52
+ return False
53
+ if "files" in match:
54
+ patterns = _as_list(match["files"])
55
+ files = task.get("files", [])
56
+ if not any(fnmatch.fnmatch(path, pattern) for path in files for pattern in patterns):
57
+ return False
58
+ return True
59
+
60
+
61
+ def _when_match(expr: str, task: dict[str, Any]) -> bool:
62
+ type_match = re.fullmatch(r"task\.type\s+in\s+\[(.*)\]", expr.strip())
63
+ if type_match:
64
+ values = _quoted_values(type_match.group(1))
65
+ return task.get("type") in values
66
+
67
+ eq_match = re.fullmatch(r"task\.(type|risk)\s*==\s*['\"]([^'\"]+)['\"]", expr.strip())
68
+ if eq_match:
69
+ return task.get(eq_match.group(1)) == eq_match.group(2)
70
+
71
+ files_match = re.fullmatch(r"task\.files\s+matches\s+\[(.*)\]", expr.strip())
72
+ if files_match:
73
+ patterns = _quoted_values(files_match.group(1))
74
+ return any(fnmatch.fnmatch(path, pattern) for path in task.get("files", []) for pattern in patterns)
75
+
76
+ return False
77
+
78
+
79
+ def _quoted_values(raw: str) -> list[str]:
80
+ return re.findall(r"['\"]([^'\"]+)['\"]", raw)
81
+
82
+
83
+ def _as_list(value: Any) -> list[Any]:
84
+ return value if isinstance(value, list) else [value]