Core Implementation (BAT-010):
- Add daemon registry schema and CRUD operations (req-023)
- Implement single-daemon asset assignment constraint (one asset per daemon)
- Add daemon_id field to service_token for daemon identification
- Add daemon.py CLI module for daemon management commands
- Add 20260513_0016_daemon_model.py migration for daemon tables
API Changes:
- GET /v1/assets: include daemon_id in AssetResponse
- POST /v1/assets/{asset_id}/ledger/trades: require daemon token binding
- GET /v1/user_info: include daemon metadata
- Enhanced service-token rotate to preserve daemon bindings
CLI Commands:
- pfhub daemon register --name <name> --runtime-id <runtime-id>
- pfhub daemon list
- pfhub daemon get <daemon-id>
- pfhub daemon revoke <daemon-id>
Requirements (REQ-023, REQ-028):
- REQ-023: Daemon Registry and Service Token Daemon Binding (Interface, Approved)
* AC-1: daemon CRUD operations
* AC-2: service token daemon binding for POST /v1/assets/{asset_id}/ledger/trades
* AC-3: single daemon per asset (exact-one assignment model)
- REQ-028: README.md Daemon Provisioning Runbook update (Documentation, Approved)
Documentation:
- Add dcy-006 Discovery for daemon-id and single-daemon asset assignment
- Update README.md with Daemon Provisioning Runbook section
- Add BAT-010 batch documentation with planning, implementation, verification
- Update rel-006 release document (daemon model implementation)
- Update data-model.md with daemon and daemon_asset_assignment tables
- Update interface-contract.md with daemon registry APIs
- Update runtime-flows.md with daemon lifecycle flows
Breaking Changes:
- REQ-005~009, REQ-011~012 status reverted to Approved due to revised contract
* daemon_id field addition and exact-one asset assignment requirement
* Existing Implemented evidence invalidated by contract revision
* BAT-001/002/008 re-verification required
Testing:
- Add test_daemon_registry.py for daemon CRUD operations
- Add test_daemon_assignment.py for single-asset assignment constraints
- Update test_auth.py, test_cli.py, test_v1.py for daemon support
- Verify daemon token binding in trade endpoint authorization
Impact:
- Database: 2 new tables (daemons, daemon_asset_assignments)
- Migration: 20260513_0016 creates daemon model schema
- CLI: 4 new daemon subcommands
- API: daemon_id propagation through v1 endpoints
- Verification: BAT-001/002/008 re-verification gates next release
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
"""Typer entrypoint for PortfolioHub."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Callable
|
|
|
|
import typer
|
|
from rich.console import Console
|
|
|
|
from app.cli.commands.daemon import daemon_app
|
|
from app.cli.commands.health import register_health_commands
|
|
from app.cli.commands.service_tokens import token_app
|
|
from app.cli.commands.portfolio import portfolio_app
|
|
from app.cli.commands.strategy import strategy_app
|
|
from app.cli.commands.user import user_app
|
|
from app.cli.commands.credential import credential_app
|
|
from app.core.config import Settings, get_settings
|
|
from app.repositories.factory import get_portfolio_repository_from_settings
|
|
from app.repositories.portfolio_repository import PortfolioRepository
|
|
|
|
|
|
@dataclass
|
|
class AppContext:
|
|
settings: Settings
|
|
output_format: str
|
|
console: Console
|
|
repository_factory: Callable[[Settings], PortfolioRepository]
|
|
|
|
|
|
def create_app(
|
|
*,
|
|
settings_factory: Callable[[], Settings] = get_settings,
|
|
repository_factory: Callable[[Settings], PortfolioRepository] = get_portfolio_repository_from_settings,
|
|
) -> typer.Typer:
|
|
app = typer.Typer(help="PortfolioHub command line interface.", no_args_is_help=True)
|
|
|
|
@app.callback()
|
|
def main_callback(
|
|
ctx: typer.Context,
|
|
output_format: str = typer.Option("table", "--format", help="Output format: table or json."),
|
|
) -> None:
|
|
settings = settings_factory()
|
|
console = Console(no_color=True, width=160)
|
|
ctx.obj = AppContext(
|
|
settings=settings,
|
|
output_format=output_format,
|
|
console=console,
|
|
repository_factory=repository_factory,
|
|
)
|
|
|
|
app.add_typer(portfolio_app, name="portfolio")
|
|
app.add_typer(strategy_app, name="strategy")
|
|
app.add_typer(user_app, name="user")
|
|
app.add_typer(token_app, name="service-token")
|
|
app.add_typer(credential_app, name="credential")
|
|
app.add_typer(daemon_app, name="daemon")
|
|
register_health_commands(app)
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
def main() -> None:
|
|
app() |