Something went wrong. Try again.
Integrated repository, worktree, git stacker, and project manager
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354"""`pm agent serve` — run the session-tracking daemon (foreground)."""
import threadingfrom typing import Annotated
from cyclopts import Parameter
from project_manager import configfrom project_manager.agent.serve import fallbackfrom project_manager.agent.serve.server import SessionServerfrom project_manager.agent.serve.store import Store
from . import agent_app
@agent_app.commanddef serve( *, port: Annotated[int | None, Parameter(help="override [serve].port")] = None,) -> int: """Run the agent-session tracking daemon in the foreground.
Binds a loopback HTTP server that ingests best-effort lifecycle-hook events (`POST /api/status`), keeps live state in an ephemeral WAL SQLite store, backfills via a transcript-tailing poller, and pushes updates over SSE (`GET /api/stream`). Lifecycle is meant to be owned by systemd (see integrations/systemd/pm-serve.service); this command just runs until interrupted. """ paths = config.load() cfg = config.serve() bind_port = port if port is not None else cfg.port
store = Store(cfg.db_path, reset=True) server = SessionServer(store, paths, bind_port)
stop = threading.Event() poller = threading.Thread( target=fallback.run_loop, args=(server, cfg.fallback_interval, stop), name="pm-serve-fallback", daemon=True, ) poller.start()
print(f"pm agent serve: listening on 127.0.0.1:{bind_port} (db {cfg.db_path})") try: server.serve_forever() except KeyboardInterrupt: print("pm agent serve: shutting down") finally: stop.set() return 0