|
3 | 3 | import json |
4 | 4 | import shlex |
5 | 5 | from pathlib import Path |
6 | | -from typing import Callable, Optional |
| 6 | +from typing import Any, Callable, Optional |
7 | 7 |
|
8 | 8 | from teaagent import __version__ |
9 | 9 | from teaagent.chat_agent import ChatAgentConfig, run_chat_agent |
@@ -294,13 +294,22 @@ def handle_command(self, raw_command: str) -> bool: |
294 | 294 | if len(args) != 1: |
295 | 295 | self.output_fn("error: resume requires a run id") |
296 | 296 | return True |
| 297 | + store = RunStore(self.root) |
297 | 298 | try: |
298 | | - original_task = RunStore(self.root).task_for_run(args[0]) |
| 299 | + original_task = store.task_for_run(args[0]) |
| 300 | + observations = store.observations_for_run(args[0]) |
| 301 | + pending = store.pending_approval_for_run(args[0]) |
299 | 302 | except (FileNotFoundError, ValueError) as exc: |
300 | 303 | self.output_fn(f"error: {exc}") |
301 | 304 | return True |
| 305 | + if pending: |
| 306 | + self.approved_call_ids.add(pending["call_id"]) |
| 307 | + self.output_fn(f"auto-approved pending call: {pending['call_id']}") |
302 | 308 | self.output_fn(f"resume: {args[0]}") |
303 | | - self._run_agent_task(original_task) |
| 309 | + self._run_agent_task( |
| 310 | + original_task, |
| 311 | + initial_observations=observations if observations else None, |
| 312 | + ) |
304 | 313 | return True |
305 | 314 | if action == "use": |
306 | 315 | if len(args) != 1: |
@@ -355,7 +364,7 @@ def _handle_memory(self, args: list[str]) -> None: |
355 | 364 | return |
356 | 365 | self.output_fn(f"error: unknown memory command '{action}'") |
357 | 366 |
|
358 | | - def _run_agent_task(self, task: str, *, clarify_first: bool = False) -> None: |
| 367 | + def _run_agent_task(self, task: str, *, clarify_first: bool = False, initial_observations: Optional[list[dict[str, Any]]] = None) -> None: |
359 | 368 | task_spec = None |
360 | 369 | if clarify_first: |
361 | 370 | clarification = clarify_task(task) |
@@ -388,9 +397,13 @@ def _run_agent_task(self, task: str, *, clarify_first: bool = False) -> None: |
388 | 397 | ), |
389 | 398 | audit=audit, |
390 | 399 | task_spec=task_spec, |
| 400 | + initial_observations=initial_observations, |
391 | 401 | ) |
392 | 402 | store.logger_for_result(result, audit) |
393 | | - self._print_json(self._run_result_payload(result, routing=routing.to_dict() if routing else None)) |
| 403 | + payload = self._run_result_payload(result, routing=routing.to_dict() if routing else None) |
| 404 | + if initial_observations: |
| 405 | + payload["replayed_observations"] = len(initial_observations) |
| 406 | + self._print_json(payload) |
394 | 407 |
|
395 | 408 | def _approval_handler(self, request: ApprovalRequest) -> bool: |
396 | 409 | self._print_json({"status": "approval_required", "approval": request.to_dict()}) |
|
0 commit comments