Something went wrong. Try again.
Integrated repository, worktree, git stacker, and project manager
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445"""Agent source adapters: one async `fetch` per agent, sharing `SessionEntry`.
Each adapter reads one vendor's on-disk session store (Claude Code's`~/.claude/projects/`, Codex CLI's `state_5.sqlite`, Cursor CLI's chatDBs) and returns the top-N sessions whose recorded cwd is in the givenowned-paths set. All adapters are `async` so the orchestrator in`agent.ls` can fan them out with `asyncio.gather`; internally they wrapblocking I/O in `asyncio.to_thread` so real concurrency applies."""
from collections.abc import Callable, Coroutinefrom pathlib import Pathfrom typing import Any
from project_manager.agent.sources import claude, codex, cursorfrom project_manager.agent.sources._entry import SessionEntry
__all__ = ["REGISTRY", "SessionEntry", "parse_agents"]
FetchFn = Callable[[set[Path], int], Coroutine[Any, Any, list[SessionEntry]]]
REGISTRY: dict[str, FetchFn] = { "claude": claude.fetch, "codex": codex.fetch, "cursor": cursor.fetch,}
def parse_agents(raw: str | None) -> frozenset[str]: """Resolve `--agent` flag to a set of source names.
`None` means every registered source. A comma-separated string picks a subset. Unknown names raise `ValueError` so `pm agent ls --agent claud` surfaces a typo immediately instead of silently returning nothing. """ if raw is None: return frozenset(REGISTRY) selected = {s.strip() for s in raw.split(",") if s.strip()} unknown = selected - REGISTRY.keys() if unknown: raise ValueError(f"unknown agent: {sorted(unknown)[0]}") return frozenset(selected)