@team-agent/installer 0.1.10 → 0.2.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.
- package/crates/team-agent-core/src/lib.rs +50 -5
- package/package.json +1 -1
- package/schemas/team.schema.json +1 -0
- package/skills/team-agent/SKILL.md +1 -1
- package/src/team_agent/approvals/__init__.py +65 -0
- package/src/team_agent/approvals/constants.py +6 -0
- package/src/team_agent/approvals/parsing.py +176 -0
- package/src/team_agent/approvals/runtime_prompts.py +171 -0
- package/src/team_agent/approvals/status.py +165 -0
- package/src/team_agent/cli/__init__.py +135 -0
- package/src/team_agent/cli/commands.py +335 -0
- package/src/team_agent/cli/e2e.py +202 -0
- package/src/team_agent/cli/helpers.py +137 -0
- package/src/team_agent/cli/parser.py +470 -0
- package/src/team_agent/compiler.py +98 -33
- package/src/team_agent/coordinator/__init__.py +53 -0
- package/src/team_agent/{coordinator.py → coordinator/__main__.py} +3 -1
- package/src/team_agent/coordinator/lifecycle.py +319 -0
- package/src/team_agent/coordinator/metadata.py +61 -0
- package/src/team_agent/coordinator/paths.py +17 -0
- package/src/team_agent/diagnose/__init__.py +48 -0
- package/src/team_agent/diagnose/checks.py +101 -0
- package/src/team_agent/diagnose/health.py +241 -0
- package/src/team_agent/diagnose/preflight.py +194 -0
- package/src/team_agent/diagnose/quick_start.py +233 -0
- package/src/team_agent/display/__init__.py +61 -0
- package/src/team_agent/display/close.py +147 -0
- package/src/team_agent/display/ghostty.py +77 -0
- package/src/team_agent/display/worker_window.py +110 -0
- package/src/team_agent/display/workspace.py +473 -0
- package/src/team_agent/launch/__init__.py +41 -0
- package/src/team_agent/launch/bootstrap.py +85 -0
- package/src/team_agent/launch/config.py +106 -0
- package/src/team_agent/launch/core.py +291 -0
- package/src/team_agent/launch/requirements.py +57 -0
- package/src/team_agent/leader/__init__.py +320 -0
- package/src/team_agent/lifecycle/__init__.py +5 -0
- package/src/team_agent/lifecycle/agents.py +226 -0
- package/src/team_agent/lifecycle/operations.py +321 -0
- package/src/team_agent/lifecycle/start.py +360 -0
- package/src/team_agent/mcp_server/__init__.py +42 -0
- package/src/team_agent/mcp_server/__main__.py +7 -0
- package/src/team_agent/mcp_server/contracts.py +148 -0
- package/src/team_agent/mcp_server/normalize.py +257 -0
- package/src/team_agent/mcp_server/server.py +150 -0
- package/src/team_agent/mcp_server/tools.py +205 -0
- package/src/team_agent/message_store/__init__.py +23 -0
- package/src/team_agent/message_store/agent_health.py +109 -0
- package/src/team_agent/{message_store.py → message_store/core.py} +188 -245
- package/src/team_agent/message_store/result_watchers.py +102 -0
- package/src/team_agent/message_store/schema.py +266 -0
- package/src/team_agent/messaging/__init__.py +1 -0
- package/src/team_agent/messaging/activity_detector.py +190 -0
- package/src/team_agent/messaging/delivery.py +128 -0
- package/src/team_agent/messaging/deps.py +263 -0
- package/src/team_agent/messaging/idle_alerts.py +217 -0
- package/src/team_agent/messaging/internal_delivery.py +46 -0
- package/src/team_agent/messaging/leader.py +317 -0
- package/src/team_agent/messaging/leader_panes.py +343 -0
- package/src/team_agent/messaging/result_delivery.py +300 -0
- package/src/team_agent/messaging/results.py +456 -0
- package/src/team_agent/messaging/scheduler.py +418 -0
- package/src/team_agent/messaging/send.py +493 -0
- package/src/team_agent/messaging/tmux_io.py +337 -0
- package/src/team_agent/messaging/tmux_prompt.py +229 -0
- package/src/team_agent/orchestrator/__init__.py +376 -0
- package/src/team_agent/orchestrator/plan.py +122 -0
- package/src/team_agent/orchestrator/state.py +128 -0
- package/src/team_agent/profiles/__init__.py +82 -0
- package/src/team_agent/profiles/constants.py +19 -0
- package/src/team_agent/profiles/core.py +407 -0
- package/src/team_agent/profiles/helpers.py +69 -0
- package/src/team_agent/profiles/provider_env.py +188 -0
- package/src/team_agent/profiles/smoke.py +201 -0
- package/src/team_agent/provider_cli/__init__.py +43 -0
- package/src/team_agent/provider_cli/adapter.py +167 -0
- package/src/team_agent/provider_cli/base.py +48 -0
- package/src/team_agent/provider_cli/claude.py +457 -0
- package/src/team_agent/provider_cli/codex.py +319 -0
- package/src/team_agent/provider_cli/copilot.py +8 -0
- package/src/team_agent/provider_cli/fake.py +39 -0
- package/src/team_agent/provider_cli/gemini.py +95 -0
- package/src/team_agent/provider_cli/opencode.py +8 -0
- package/src/team_agent/provider_cli/prompt.py +62 -0
- package/src/team_agent/provider_cli/registry.py +18 -0
- package/src/team_agent/provider_cli/unsupported.py +32 -0
- package/src/team_agent/providers.py +67 -949
- package/src/team_agent/quality_gates.py +104 -0
- package/src/team_agent/restart/__init__.py +34 -0
- package/src/team_agent/restart/orchestration.py +328 -0
- package/src/team_agent/restart/selection.py +89 -0
- package/src/team_agent/restart/snapshot.py +70 -0
- package/src/team_agent/runtime.py +802 -5740
- package/src/team_agent/rust_core.py +22 -5
- package/src/team_agent/sessions/__init__.py +25 -0
- package/src/team_agent/sessions/capture.py +93 -0
- package/src/team_agent/sessions/inventory.py +44 -0
- package/src/team_agent/sessions/resume.py +135 -0
- package/src/team_agent/spec.py +3 -1
- package/src/team_agent/state.py +204 -4
- package/src/team_agent/status/__init__.py +63 -0
- package/src/team_agent/status/approvals.py +52 -0
- package/src/team_agent/status/compact.py +158 -0
- package/src/team_agent/status/constants.py +18 -0
- package/src/team_agent/status/inbox.py +28 -0
- package/src/team_agent/status/peek.py +117 -0
- package/src/team_agent/status/queries.py +168 -0
- package/src/team_agent/terminal.py +57 -0
- package/src/team_agent/cli.py +0 -857
- package/src/team_agent/mcp_server.py +0 -579
- package/src/team_agent/profiles.py +0 -882
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from team_agent import runtime
|
|
9
|
+
from team_agent.events import EventLog
|
|
10
|
+
from team_agent.message_store import MessageStore
|
|
11
|
+
from team_agent.state import load_runtime_state, save_runtime_state, write_team_state
|
|
12
|
+
|
|
13
|
+
from team_agent.mcp_server.normalize import _compact_tool_result, _normalize_report_envelope, _text
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _requires_ack_for_target(to: str | list[str]) -> bool:
|
|
17
|
+
if isinstance(to, list):
|
|
18
|
+
return any(target not in {"leader", "Leader"} for target in to)
|
|
19
|
+
return to not in {"leader", "Leader"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TeamOrchestratorTools:
|
|
23
|
+
def __init__(self, workspace: Path):
|
|
24
|
+
self.workspace = workspace.resolve()
|
|
25
|
+
self.agent_id = _text(os.environ.get("TEAM_AGENT_ID"))
|
|
26
|
+
|
|
27
|
+
def assign_task(self, task: dict[str, Any], message: str | None = None) -> dict[str, Any]:
|
|
28
|
+
state = load_runtime_state(self.workspace)
|
|
29
|
+
tasks = state.setdefault("tasks", [])
|
|
30
|
+
existing = next((item for item in tasks if item.get("id") == task.get("id")), None)
|
|
31
|
+
if existing:
|
|
32
|
+
existing.update(task)
|
|
33
|
+
else:
|
|
34
|
+
tasks.append(task)
|
|
35
|
+
save_runtime_state(self.workspace, state)
|
|
36
|
+
content = message or task.get("description") or task.get("title") or json.dumps(task)
|
|
37
|
+
return _compact_tool_result(runtime.send_message(self.workspace, task.get("assignee"), content, task_id=task["id"]))
|
|
38
|
+
|
|
39
|
+
def send_message(
|
|
40
|
+
self,
|
|
41
|
+
to: str | list[str],
|
|
42
|
+
content: str,
|
|
43
|
+
task_id: str | None = None,
|
|
44
|
+
sender: str | None = None,
|
|
45
|
+
requires_ack: bool | None = None,
|
|
46
|
+
) -> dict[str, Any]:
|
|
47
|
+
inferred_target = to if isinstance(to, str) else None
|
|
48
|
+
effective_sender = sender or self._infer_agent_id(task_id=task_id, target=inferred_target) or "unknown"
|
|
49
|
+
effective_requires_ack = requires_ack if requires_ack is not None else _requires_ack_for_target(to)
|
|
50
|
+
return _compact_tool_result(
|
|
51
|
+
runtime.send_message(
|
|
52
|
+
self.workspace,
|
|
53
|
+
to,
|
|
54
|
+
content,
|
|
55
|
+
task_id=task_id,
|
|
56
|
+
sender=effective_sender,
|
|
57
|
+
requires_ack=effective_requires_ack,
|
|
58
|
+
block_until_delivered=False,
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def report_result(
|
|
63
|
+
self,
|
|
64
|
+
envelope: dict[str, Any] | None = None,
|
|
65
|
+
summary: str | None = None,
|
|
66
|
+
status: str = "success",
|
|
67
|
+
changes: list[dict[str, Any]] | None = None,
|
|
68
|
+
tests: list[dict[str, Any]] | None = None,
|
|
69
|
+
risks: list[dict[str, Any]] | None = None,
|
|
70
|
+
artifacts: list[dict[str, Any]] | None = None,
|
|
71
|
+
next_actions: list[dict[str, Any]] | None = None,
|
|
72
|
+
task_id: str | None = None,
|
|
73
|
+
agent_id: str | None = None,
|
|
74
|
+
) -> dict[str, Any]:
|
|
75
|
+
env = dict(envelope or {})
|
|
76
|
+
effective_task = self._infer_task_id(
|
|
77
|
+
agent_id or _text(env.get("agent_id")) or self.agent_id,
|
|
78
|
+
task_id or _text(env.get("task_id")),
|
|
79
|
+
)
|
|
80
|
+
effective_agent = agent_id or _text(env.get("agent_id")) or self._infer_agent_id(task_id=effective_task) or "unknown"
|
|
81
|
+
env.setdefault("schema_version", "result_envelope_v1")
|
|
82
|
+
env.setdefault("agent_id", effective_agent)
|
|
83
|
+
env.setdefault("task_id", effective_task)
|
|
84
|
+
env.setdefault("status", status)
|
|
85
|
+
env.setdefault("summary", summary or env.get("summary") or "completed")
|
|
86
|
+
env.setdefault("changes", changes if changes is not None else [])
|
|
87
|
+
env.setdefault("tests", tests if tests is not None else [])
|
|
88
|
+
env.setdefault("risks", risks if risks is not None else [])
|
|
89
|
+
env.setdefault("artifacts", artifacts if artifacts is not None else [])
|
|
90
|
+
env.setdefault("next_actions", next_actions if next_actions is not None else [])
|
|
91
|
+
env = _normalize_report_envelope(env)
|
|
92
|
+
return _compact_tool_result(runtime.report_result(self.workspace, env))
|
|
93
|
+
|
|
94
|
+
def _infer_agent_id(self, provided: str | None = None, task_id: str | None = None, target: str | None = None) -> str | None:
|
|
95
|
+
if _text(provided):
|
|
96
|
+
return _text(provided)
|
|
97
|
+
if self.agent_id:
|
|
98
|
+
return self.agent_id
|
|
99
|
+
state = load_runtime_state(self.workspace)
|
|
100
|
+
leader_id = state.get("leader", {}).get("id") or "leader"
|
|
101
|
+
runtime_agents = {str(agent_id) for agent_id in state.get("agents", {})}
|
|
102
|
+
task = self._task_for_id(state, task_id)
|
|
103
|
+
if task and task.get("assignee") in runtime_agents:
|
|
104
|
+
return str(task["assignee"])
|
|
105
|
+
messages = MessageStore(self.workspace).messages()
|
|
106
|
+
if task_id:
|
|
107
|
+
for row in reversed(messages):
|
|
108
|
+
if row.get("task_id") != task_id:
|
|
109
|
+
continue
|
|
110
|
+
for key in ("recipient", "sender"):
|
|
111
|
+
candidate = row.get(key)
|
|
112
|
+
if candidate in runtime_agents and candidate not in {leader_id, "leader", "Leader"}:
|
|
113
|
+
return str(candidate)
|
|
114
|
+
active_assignees = {
|
|
115
|
+
str(task_item.get("assignee"))
|
|
116
|
+
for task_item in state.get("tasks", [])
|
|
117
|
+
if task_item.get("assignee") in runtime_agents and task_item.get("status") not in {"done", "failed"}
|
|
118
|
+
}
|
|
119
|
+
if len(active_assignees) == 1:
|
|
120
|
+
return next(iter(active_assignees))
|
|
121
|
+
if len(runtime_agents) == 1:
|
|
122
|
+
return next(iter(runtime_agents))
|
|
123
|
+
for row in reversed(messages):
|
|
124
|
+
for key in ("recipient", "sender"):
|
|
125
|
+
candidate = row.get(key)
|
|
126
|
+
if candidate in runtime_agents and candidate not in {leader_id, "leader", "Leader"}:
|
|
127
|
+
return str(candidate)
|
|
128
|
+
EventLog(self.workspace).write(
|
|
129
|
+
"mcp.identity_inference_failed",
|
|
130
|
+
target=target,
|
|
131
|
+
task_id=task_id,
|
|
132
|
+
runtime_agents=sorted(runtime_agents),
|
|
133
|
+
fallback="unknown",
|
|
134
|
+
)
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
def _infer_task_id(self, agent_id: str | None, provided: str | None = None) -> str:
|
|
138
|
+
if provided:
|
|
139
|
+
return provided
|
|
140
|
+
state = load_runtime_state(self.workspace)
|
|
141
|
+
for task in reversed(state.get("tasks", [])):
|
|
142
|
+
if agent_id and task.get("assignee") == agent_id and task.get("status") not in {"done", "failed"}:
|
|
143
|
+
return str(task["id"])
|
|
144
|
+
active_tasks = [
|
|
145
|
+
task
|
|
146
|
+
for task in state.get("tasks", [])
|
|
147
|
+
if task.get("assignee") and task.get("status") not in {"done", "failed"}
|
|
148
|
+
]
|
|
149
|
+
if len(active_tasks) == 1:
|
|
150
|
+
return str(active_tasks[0]["id"])
|
|
151
|
+
messages = MessageStore(self.workspace).messages()
|
|
152
|
+
for row in reversed(messages):
|
|
153
|
+
if agent_id and row.get("recipient") == agent_id and row.get("task_id"):
|
|
154
|
+
return str(row["task_id"])
|
|
155
|
+
for row in reversed(messages):
|
|
156
|
+
if agent_id and row.get("recipient") == agent_id:
|
|
157
|
+
return str(row["message_id"])
|
|
158
|
+
for row in reversed(messages):
|
|
159
|
+
if row.get("task_id"):
|
|
160
|
+
return str(row["task_id"])
|
|
161
|
+
EventLog(self.workspace).write("mcp.task_inference_failed", agent_id=agent_id, fallback="manual")
|
|
162
|
+
return "manual"
|
|
163
|
+
|
|
164
|
+
def _task_for_id(self, state: dict[str, Any], task_id: str | None) -> dict[str, Any] | None:
|
|
165
|
+
if not task_id:
|
|
166
|
+
return None
|
|
167
|
+
return next((task for task in state.get("tasks", []) if task.get("id") == task_id), None)
|
|
168
|
+
|
|
169
|
+
def update_state(self, note: str) -> dict[str, Any]:
|
|
170
|
+
state = load_runtime_state(self.workspace)
|
|
171
|
+
spec_path = Path(state.get("spec_path", self.workspace / "team.spec.yaml"))
|
|
172
|
+
from team_agent.spec import load_spec
|
|
173
|
+
|
|
174
|
+
spec = load_spec(spec_path)
|
|
175
|
+
state.setdefault("notes", []).append(note)
|
|
176
|
+
save_runtime_state(self.workspace, state)
|
|
177
|
+
path = write_team_state(self.workspace, spec, state)
|
|
178
|
+
return {"ok": True, "state_file": str(path)}
|
|
179
|
+
|
|
180
|
+
def get_team_status(self) -> dict[str, Any]:
|
|
181
|
+
return runtime.status(self.workspace, as_json=True, compact=True)
|
|
182
|
+
|
|
183
|
+
def stop_agent(self, agent_id: str) -> dict[str, Any]:
|
|
184
|
+
return _compact_tool_result(runtime.stop_agent(self.workspace, agent_id))
|
|
185
|
+
|
|
186
|
+
def reset_agent(self, agent_id: str, discard_session: bool = False) -> dict[str, Any]:
|
|
187
|
+
return _compact_tool_result(runtime.reset_agent(self.workspace, agent_id, discard_session=discard_session))
|
|
188
|
+
|
|
189
|
+
def add_agent(self, new_agent_id: str, role_file_path: str) -> dict[str, Any]:
|
|
190
|
+
return _compact_tool_result(runtime.add_agent(self.workspace, new_agent_id, role_file_path=role_file_path))
|
|
191
|
+
|
|
192
|
+
def fork_agent(self, source_agent_id: str, as_agent_id: str, label: str | None = None) -> dict[str, Any]:
|
|
193
|
+
return _compact_tool_result(runtime.fork_agent(self.workspace, source_agent_id, as_agent_id=as_agent_id, label=label))
|
|
194
|
+
|
|
195
|
+
def request_human(self, question: str, task_id: str | None = None, agent_id: str | None = None) -> dict[str, Any]:
|
|
196
|
+
store = MessageStore(self.workspace)
|
|
197
|
+
sender = agent_id or self._infer_agent_id(task_id=task_id, target="leader") or "unknown"
|
|
198
|
+
message_id = store.create_message(task_id, sender, "leader", question, requires_ack=True)
|
|
199
|
+
return {"ok": True, "message_id": message_id, "status": "needs_human"}
|
|
200
|
+
|
|
201
|
+
def stuck_list(self) -> dict[str, Any]:
|
|
202
|
+
return runtime.stuck_list(self.workspace)
|
|
203
|
+
|
|
204
|
+
def stuck_cancel(self, agent_id: str, alert_type: str = "stuck") -> dict[str, Any]:
|
|
205
|
+
return runtime.stuck_cancel(self.workspace, agent_id, alert_type=alert_type, suppressed_by=self.agent_id or "leader")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from team_agent.message_store.agent_health import delete_agent_health, gc_agent_health, upsert_agent_health
|
|
4
|
+
from team_agent.message_store.core import MessageStore
|
|
5
|
+
from team_agent.message_store.result_watchers import create_result_watcher, mark_result_watcher
|
|
6
|
+
from team_agent.message_store.schema import SCHEMA_VERSION, initialize_schema, utcnow
|
|
7
|
+
|
|
8
|
+
_REQUIRED_EXPORTS = (
|
|
9
|
+
"MessageStore",
|
|
10
|
+
"SCHEMA_VERSION",
|
|
11
|
+
"initialize_schema",
|
|
12
|
+
"utcnow",
|
|
13
|
+
"upsert_agent_health",
|
|
14
|
+
"delete_agent_health",
|
|
15
|
+
"gc_agent_health",
|
|
16
|
+
"create_result_watcher",
|
|
17
|
+
"mark_result_watcher",
|
|
18
|
+
)
|
|
19
|
+
for _name in _REQUIRED_EXPORTS:
|
|
20
|
+
if _name not in globals():
|
|
21
|
+
raise ImportError(f"team_agent.message_store missing export: {_name}")
|
|
22
|
+
|
|
23
|
+
__all__ = list(_REQUIRED_EXPORTS)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from contextlib import closing
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from team_agent.message_store.schema import utcnow
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def upsert_agent_health(
|
|
10
|
+
self,
|
|
11
|
+
agent_id: str,
|
|
12
|
+
status: str,
|
|
13
|
+
last_output_at: str | None = None,
|
|
14
|
+
context_usage_pct: int | None = None,
|
|
15
|
+
current_task_id: str | None = None,
|
|
16
|
+
owner_team_id: str | None = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
now = utcnow()
|
|
19
|
+
with closing(self.connect()) as conn:
|
|
20
|
+
with conn:
|
|
21
|
+
if owner_team_id is None:
|
|
22
|
+
updated = conn.execute(
|
|
23
|
+
"""
|
|
24
|
+
update agent_health
|
|
25
|
+
set status = ?,
|
|
26
|
+
last_output_at = coalesce(?, last_output_at),
|
|
27
|
+
context_usage_pct = ?,
|
|
28
|
+
current_task_id = ?,
|
|
29
|
+
updated_at = ?
|
|
30
|
+
where owner_team_id is null and agent_id = ?
|
|
31
|
+
""",
|
|
32
|
+
(status, last_output_at, context_usage_pct, current_task_id, now, agent_id),
|
|
33
|
+
)
|
|
34
|
+
if updated.rowcount:
|
|
35
|
+
return
|
|
36
|
+
conn.execute(
|
|
37
|
+
"""
|
|
38
|
+
insert into agent_health(owner_team_id, agent_id, status, last_output_at, context_usage_pct, current_task_id, updated_at)
|
|
39
|
+
values (?, ?, ?, ?, ?, ?, ?)
|
|
40
|
+
on conflict(owner_team_id, agent_id) do update set
|
|
41
|
+
status = excluded.status,
|
|
42
|
+
last_output_at = coalesce(excluded.last_output_at, agent_health.last_output_at),
|
|
43
|
+
context_usage_pct = excluded.context_usage_pct,
|
|
44
|
+
current_task_id = excluded.current_task_id,
|
|
45
|
+
updated_at = excluded.updated_at
|
|
46
|
+
""",
|
|
47
|
+
(owner_team_id, agent_id, status, last_output_at, context_usage_pct, current_task_id, now),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def agent_health(self, owner_team_id: str | None = None) -> dict[str, dict[str, Any]]:
|
|
51
|
+
with closing(self.connect()) as conn:
|
|
52
|
+
if owner_team_id is None:
|
|
53
|
+
rows = conn.execute("select * from agent_health order by agent_id").fetchall()
|
|
54
|
+
else:
|
|
55
|
+
rows = conn.execute(
|
|
56
|
+
"select * from agent_health where owner_team_id = ? or owner_team_id is null order by agent_id",
|
|
57
|
+
(owner_team_id,),
|
|
58
|
+
).fetchall()
|
|
59
|
+
return {row["agent_id"]: dict(row) for row in rows}
|
|
60
|
+
|
|
61
|
+
def delete_agent_health(self, agent_id: str, owner_team_id: str | None = None) -> bool:
|
|
62
|
+
with closing(self.connect()) as conn:
|
|
63
|
+
with conn:
|
|
64
|
+
if owner_team_id is None:
|
|
65
|
+
cur = conn.execute("delete from agent_health where agent_id = ?", (agent_id,))
|
|
66
|
+
else:
|
|
67
|
+
cur = conn.execute(
|
|
68
|
+
"delete from agent_health where agent_id = ? and (owner_team_id = ? or owner_team_id is null)",
|
|
69
|
+
(agent_id, owner_team_id),
|
|
70
|
+
)
|
|
71
|
+
return cur.rowcount > 0
|
|
72
|
+
|
|
73
|
+
def gc_agent_health(self, valid_agent_ids: Any, owner_team_id: str | None = None) -> list[str]:
|
|
74
|
+
# Caller must pass the workspace-wide set of live agent_ids across every
|
|
75
|
+
# team sharing this team.db. Rows whose agent_id is not in the set are
|
|
76
|
+
# deleted. If two teams share a workspace, the caller is responsible for
|
|
77
|
+
# computing the union before invoking this helper; otherwise live agents
|
|
78
|
+
# from a sibling team will be swept. Input is validated before any DB
|
|
79
|
+
# mutation so a derivation bug that silently produces None or non-str
|
|
80
|
+
# entries cannot delete sibling-team rows by accident.
|
|
81
|
+
valid: set[str] = set()
|
|
82
|
+
for entry in valid_agent_ids:
|
|
83
|
+
if not isinstance(entry, str):
|
|
84
|
+
raise TypeError(
|
|
85
|
+
f"gc_agent_health requires str agent_ids; got {type(entry).__name__}"
|
|
86
|
+
)
|
|
87
|
+
if not entry:
|
|
88
|
+
raise ValueError("gc_agent_health does not accept empty agent_ids")
|
|
89
|
+
valid.add(entry)
|
|
90
|
+
with closing(self.connect()) as conn:
|
|
91
|
+
with conn:
|
|
92
|
+
if owner_team_id is None:
|
|
93
|
+
rows = conn.execute("select agent_id from agent_health").fetchall()
|
|
94
|
+
else:
|
|
95
|
+
rows = conn.execute(
|
|
96
|
+
"select agent_id from agent_health where owner_team_id = ? or owner_team_id is null",
|
|
97
|
+
(owner_team_id,),
|
|
98
|
+
).fetchall()
|
|
99
|
+
stale = [row["agent_id"] for row in rows if row["agent_id"] not in valid]
|
|
100
|
+
if stale:
|
|
101
|
+
placeholders = ",".join("?" for _ in stale)
|
|
102
|
+
if owner_team_id is None:
|
|
103
|
+
conn.execute(f"delete from agent_health where agent_id in ({placeholders})", stale)
|
|
104
|
+
else:
|
|
105
|
+
conn.execute(
|
|
106
|
+
f"delete from agent_health where agent_id in ({placeholders}) and (owner_team_id = ? or owner_team_id is null)",
|
|
107
|
+
[*stale, owner_team_id],
|
|
108
|
+
)
|
|
109
|
+
return stale
|