File size: 5,632 Bytes
0d3f7cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""VGTC CLI entry point."""

from __future__ import annotations

import asyncio
import logging
import sys

import click

from hermes.config.settings import get_settings


@click.group()
@click.option("--debug", is_flag=True, help="Enable debug mode")
@click.option("--config", type=str, help="Config file path")
@click.pass_context
def main(ctx: click.Context, debug: bool, config: str | None) -> None:
    """VGTC — AI-powered Global Trade Compliance Platform."""
    ctx.ensure_object(dict)
    ctx.obj["debug"] = debug

    settings = get_settings()
    if debug:
        settings.debug = True
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)


@main.command()
@click.option("--host", default="0.0.0.0", help="Host to bind to")
@click.option("--port", default=8000, type=int, help="Port to bind to")
@click.pass_context
def serve(ctx: click.Context, host: str, port: int) -> None:
    """Start the API server."""
    import uvicorn

    settings = get_settings()
    settings.debug = ctx.obj.get("debug", False)

    uvicorn.run(
        "hermes.api.app:create_app",
        host=host,
        port=port,
        reload=settings.debug,
        factory=True,
    )


@main.command()
@click.argument("query")
@click.option("--output", "-o", type=str, help="Output file path")
@click.pass_context
def research(ctx: click.Context, query: str, output: str | None) -> None:
    """Conduct research on a topic."""
    from hermes.agents.orchestrator.agent import OrchestratorAgent

    async def _run() -> None:
        orchestrator = OrchestratorAgent()
        report = await orchestrator.execute_research(query)

        click.echo(f"\n{'='*60}")
        click.echo(f"Research: {report.title}")
        click.echo(f"{'='*60}")
        click.echo(f"Summary: {report.summary}")
        click.echo("")
        if report.findings:
            for i, finding in enumerate(report.findings, 1):
                click.echo(f"--- Finding {i} ({finding.category}) ---")
                safe_desc = finding.description[:600].encode(sys.stdout.encoding, errors='replace').decode(sys.stdout.encoding)
                click.echo(safe_desc)
                click.echo("")

        if output:
            with open(output, "w", encoding="utf-8") as f:
                f.write(report.content)
            click.echo(f"Report saved to: {output}")

    asyncio.run(_run())


@main.command()
@click.argument("owner")
@click.argument("repo")
@click.option("--output", "-o", type=str, help="Output file path")
@click.pass_context
def analyze(ctx: click.Context, owner: str, repo: str, output: str | None) -> None:
    """Analyze a GitHub repository."""

    async def _run() -> None:
        from hermes.agents.orchestrator.agent import OrchestratorAgent

        orchestrator = OrchestratorAgent()
        report = await orchestrator.execute_repo_analysis(owner, repo)

        click.echo(f"\nAnalysis: {report.title}")
        click.echo(f"Summary: {report.summary}")
        click.echo(f"Findings: {len(report.findings)}")

        if output:
            with open(output, "w", encoding="utf-8") as f:
                f.write(report.content)
            click.echo(f"\nReport saved to: {output}")

    asyncio.run(_run())


@main.command()
@click.argument("path")
@click.option("--output", "-o", type=str, help="Output file path")
@click.pass_context
def scan(ctx: click.Context, path: str, output: str | None) -> None:
    """Perform security scan."""

    async def _run() -> None:
        from hermes.agents.orchestrator.agent import OrchestratorAgent

        orchestrator = OrchestratorAgent()
        report = await orchestrator.execute_security_scan(path)

        click.echo(f"\nSecurity Scan: {report.title}")
        click.echo(f"Summary: {report.summary}")
        click.echo(f"Findings: {len(report.findings)}")

        if output:
            with open(output, "w", encoding="utf-8") as f:
                f.write(report.content)
            click.echo(f"\nReport saved to: {output}")

    asyncio.run(_run())


@main.command()
@click.pass_context
def tools(ctx: click.Context) -> None:
    """List available MCP tools."""
    from hermes.tools.base.registry import tool_registry
    from hermes.tools.register import register_default_tools

    register_default_tools()

    click.echo("\nAvailable MCP Tools:")
    click.echo("-" * 60)

    for schema in tool_registry.list_schemas():
        click.echo(f"\n{schema['name']}")
        click.echo(f"  Description: {schema['description']}")
        params = schema.get("inputSchema", {}).get("properties", {})
        if params:
            click.echo("  Parameters:")
            for param, info in params.items():
                click.echo(f"    - {param}: {info.get('description', '')}")


@main.command()
@click.pass_context
def status(ctx: click.Context) -> None:
    """Show system status."""
    from hermes.tools.base.registry import tool_registry
    from hermes.tools.register import register_default_tools

    register_default_tools()

    settings = get_settings()

    click.echo("\nVGTC Platform Status")
    click.echo("=" * 40)
    click.echo(f"Environment: {settings.environment}")
    click.echo(f"Debug: {settings.debug}")
    click.echo(f"MCP Port: {settings.mcp.port}")
    click.echo(f"Tools Registered: {len(tool_registry.list_tools())}")
    click.echo(f"Model: {settings.model.name}")


if __name__ == "__main__":
    main()