Skip to content

symfonic.diagnostics.native_cli

native_cli

Scoped, composition-only diagnostics for a generated AgentHost project.

inspect_environment

inspect_environment(*, no_network: bool, json_output: bool = False) -> AuditReport

Inspect process environment only; a pathless doctor constructs no agent.

Source code in src/symfonic/diagnostics/native_cli.py
def inspect_environment(*, no_network: bool, json_output: bool = False) -> AuditReport:
    """Inspect process environment only; a pathless doctor constructs no agent."""
    results = [
        _unknown("native.composition", "No PROJECT_PATH was supplied; no Agent was composed."),
        *_legacy_unknowns(),
    ]
    if no_network:
        results.append(_unknown("postgres_dsn.probe", "Network probe skipped by --no-network."))
    else:
        from symfonic.diagnostics.checks.check_postgres_dsn import check_postgres_dsn

        progress = redirect_stderr(io.StringIO()) if json_output else nullcontext()
        try:
            with progress:
                results.extend(asyncio.run(check_postgres_dsn(None)))
        except Exception as exc:  # noqa: BLE001 -- fail closed, never echo a DSN
            results.append(
                CheckResult(
                    "postgres_dsn.probe", Severity.ERROR,
                    f"Environment probe failed ({type(exc).__name__}).",
                )
            )
    return AuditReport(results)

inspect_project

inspect_project(project_path: Path, *, scope: str, no_network: bool, json_output: bool = False) -> AuditReport

Inspect only the named scope; never open shared resources or run a turn.

--no-network avoids importing the project entirely. A normal inspection invokes adopter import, build_agent and scoped composition, whose custom code may perform I/O; the framework cannot promise those calls are pure.

Source code in src/symfonic/diagnostics/native_cli.py
def inspect_project(
    project_path: Path,
    *,
    scope: str,
    no_network: bool,
    json_output: bool = False,
) -> AuditReport:
    """Inspect only the named scope; never open shared resources or run a turn.

    ``--no-network`` avoids importing the project entirely. A normal inspection
    invokes adopter import, ``build_agent`` and scoped composition, whose custom
    code may perform I/O; the framework cannot promise those calls are pure.
    """
    if no_network:
        return AuditReport(
            [
                _unknown(
                    "native.composition",
                    "Project import and scoped composition skipped by --no-network.",
                ),
                *_legacy_unknowns(),
                _unknown("postgres_dsn.probe", "Network probe skipped by --no-network."),
            ]
        )

    root = str(project_path.resolve())
    previous_cwd = Path.cwd()
    previous = {
        name: module
        for name, module in sys.modules.items()
        if name == "app" or name.startswith("app.")
    }
    for name in previous:
        del sys.modules[name]
    previous_path = sys.path[:]
    sys.path.insert(0, root)
    try:
        os.chdir(root)
        output = redirect_stdout(io.StringIO()) if json_output else nullcontext()
        errors = redirect_stderr(io.StringIO()) if json_output else nullcontext()
        with output, errors:
            return asyncio.run(_inspect_scoped(scope, json_output=json_output))
    except (Exception, SystemExit) as exc:  # noqa: BLE001 -- opaque project boundary
        return AuditReport(
            [
                CheckResult(
                    "native.composition",
                    Severity.ERROR,
                    f"Project import or scoped composition failed ({type(exc).__name__}).",
                    "Check app.setup.agent.build_agent() and the requested --scope.",
                ),
            ]
        )
    finally:
        os.chdir(previous_cwd)
        sys.path[:] = previous_path
        for name in [key for key in sys.modules if key == "app" or key.startswith("app.")]:
            del sys.modules[name]
        sys.modules.update(previous)