|
9 | 9 | from typing_extensions import override |
10 | 10 |
|
11 | 11 | from pipelex.cli.agent_cli.commands.accept_gateway_terms_cmd import agent_accept_gateway_terms_cmd |
| 12 | +from pipelex.cli.agent_cli.commands.agent_cli_factory import silence_logging_for_agent_cli |
12 | 13 | from pipelex.cli.agent_cli.commands.agent_output import CliOutputFormat, agent_error, set_agent_cli_error_format |
13 | 14 | from pipelex.cli.agent_cli.commands.check_model_cmd import agent_check_model_cmd |
14 | 15 | from pipelex.cli.agent_cli.commands.concept_cmd import concept_cmd |
|
21 | 22 | from pipelex.cli.agent_cli.commands.pipe_cmd import pipe_cmd |
22 | 23 | from pipelex.cli.agent_cli.commands.run.app import run_app |
23 | 24 | from pipelex.cli.agent_cli.commands.validate.app import validate_app |
24 | | -from pipelex.tools.log.log_levels import LogLevel |
25 | 25 | from pipelex.tools.misc.package_utils import get_package_version |
26 | 26 |
|
27 | 27 |
|
@@ -91,31 +91,35 @@ def app_callback( |
91 | 91 | is_eager=True, |
92 | 92 | ), |
93 | 93 | ] = False, |
94 | | - log_level: Annotated[ |
95 | | - str, |
96 | | - typer.Option("--log-level", help="Log verbosity level (debug, verbose, info, warning, error, critical)."), |
97 | | - ] = "warning", |
98 | 94 | runner: Annotated[ |
99 | 95 | str, |
100 | 96 | typer.Option("--runner", help="Runner to use: 'pipelex' (local) or 'api' (remote MTHDS API)."), |
101 | 97 | ] = "pipelex", |
102 | 98 | ) -> None: |
103 | | - """Agent CLI callback - no logo, minimal output.""" |
| 99 | + """Agent CLI callback - no logo, minimal output. |
| 100 | +
|
| 101 | + Note: there is no ``--log-level`` flag. ``pipelex-agent`` is machine-consumed: |
| 102 | + stdout is reserved for the success envelope and stderr for the error envelope. |
| 103 | + Free-floating logs would corrupt those channels, so Python's logging system is |
| 104 | + cut off process-wide via ``silence_logging_for_agent_cli`` as the very first |
| 105 | + action in this callback — covering every subcommand invocation (including ones |
| 106 | + like ``init`` and ``accept-gateway-terms`` that bypass |
| 107 | + ``make_pipelex_for_agent_cli``). The ``--version`` eager option short-circuits |
| 108 | + before this body runs, but its callback only does ``typer.echo`` + ``Exit`` and |
| 109 | + touches no log path. For verbose debugging, use the human ``pipelex`` CLI instead. |
| 110 | + """ |
| 111 | + # Process-global logging cutoff, armed BEFORE any command body runs and BEFORE any |
| 112 | + # error-format / runner-validation code below can route through ``log.*``. This is the |
| 113 | + # primary armor for the stdout/stderr discipline; the per-call invocations inside |
| 114 | + # ``make_pipelex_for_agent_cli`` and ``agent_doctor_cmd`` are kept as defense-in-depth |
| 115 | + # for direct library callers that bypass this Typer entry point. |
| 116 | + silence_logging_for_agent_cli() |
104 | 117 | # Reset the error-format ContextVar at the single choke point every command passes through, so |
105 | 118 | # a markdown command cannot leak markdown into a later JSON-only command in the same process. |
106 | 119 | # --format / --error-format commands override this afterwards; JSON-only commands keep the JSON default. |
107 | 120 | set_agent_cli_error_format(CliOutputFormat.JSON) |
108 | 121 |
|
109 | 122 | ctx.ensure_object(dict) |
110 | | - try: |
111 | | - ctx.obj["log_level"] = LogLevel(log_level.upper()) |
112 | | - except ValueError: |
113 | | - valid_values = ", ".join(level.value.lower() for level in LogLevel) |
114 | | - agent_error( |
115 | | - f"Invalid log level '{log_level}'. Valid values: {valid_values}", |
116 | | - "ArgumentError", |
117 | | - ) |
118 | | - |
119 | 123 | try: |
120 | 124 | ctx.obj["runner"] = RunnerType(runner) |
121 | 125 | except ValueError: |
|
0 commit comments