feat: extend daemon model with daemon status tracking and list support

- Add daemon status tracking with state and metrics (idle, running, error)
- Implement pfhub daemon list CLI command for viewing registered daemons
- Extend auth schema and service for daemon lifecycle management
- Add postgres repository queries for daemon state persistence
- Expand test coverage for daemon registry and status transitions
- Update rel-006 release document with daemon model verification results
- Support daemon graceful shutdown and error recovery patterns
This commit is contained in:
2026-05-14 06:29:52 +00:00
parent e6b6a8715b
commit 3bb3ff547d
9 changed files with 298 additions and 17 deletions
+28 -2
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
import hashlib
import uuid
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timezone
from typing import Any
import psycopg
@@ -633,7 +633,7 @@ class PostgresPortfolioRepository:
self.ensure_schema()
with self._connect().cursor() as cur:
cur.execute(
_SELECT_AUTH_TOKEN + "WHERE name = %s AND token_type = 'service'",
_SELECT_AUTH_TOKEN + "WHERE name = %s AND token_type = 'service' AND revoked_at IS NULL ORDER BY created_at DESC LIMIT 1",
(name,),
)
row = cur.fetchone()
@@ -1399,6 +1399,32 @@ class PostgresPortfolioRepository:
row = cur.fetchone()
return new_raw, self._row_to_auth_token(row)
def rebind_service_token(self, name: str, daemon_id: str) -> AuthToken:
self.ensure_schema()
with self._connect().cursor() as cur:
cur.execute(
_SELECT_AUTH_TOKEN + "WHERE name = %s AND token_type = 'service' AND revoked_at IS NULL ORDER BY created_at DESC LIMIT 1",
(name,),
)
existing_row = cur.fetchone()
if existing_row is None:
raise ValueError(f"서비스 토큰을 찾을 수 없습니다: {name}")
existing = self._row_to_auth_token(existing_row)
cur.execute(
"""
UPDATE auth_tokens
SET daemon_id = %s
WHERE id = %s
RETURNING
id, user_id, name, token_prefix, permission, token_type,
expires_at, last_used_at, revoked_at, created_at, runtime_id, daemon_id
""",
(daemon_id, existing.id),
)
row = cur.fetchone()
return self._row_to_auth_token(row)
@staticmethod
def _row_to_daemon(row: Any) -> Daemon:
if row is None: