Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dependencies = [
"httpx>=0.24",
"pathspec>=0.11",
"platformdirs>=4.0",
"rich>=13.0",
"pyyaml>=6.0",
]

[project.optional-dependencies]
Expand Down
20 changes: 17 additions & 3 deletions scripts/generate_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ def generate_command_code(
query_params = extract_query_params(operation)
body_props = extract_json_body_properties(operation)

is_table = cmd_name in ("list", "search")

lines: list[str] = [f'@{group_name}_group.command("{cmd_name}")']

for pp in path_params:
Expand Down Expand Up @@ -382,9 +384,15 @@ def generate_command_code(
f'@click.option("--{opt}", "{var}"{required_arg}, help={_quote(desc)})'
)

if is_table:
lines.append('@click.option("-o", "--output", "output_format", type=click.Choice(["table", "yaml", "json"]), default="table", help="Output format.")')
else:
lines.append('@click.option("-o", "--output", "output_format", type=click.Choice(["yaml", "json"]), default="yaml", help="Output format.")')

lines.append("@click.pass_context")

sig_parts = ["ctx"] + path_params + [py_var_name(q["name"]) for q in query_params]
sig_parts.append("output_format")
if method != "GET":
sig_parts += [py_var_name(prop["name"]) for prop in body_props]
lines.append(f"def {func_name}({', '.join(sig_parts)}):")
Expand Down Expand Up @@ -412,7 +420,10 @@ def generate_command_code(
lines.append(
f' result = ctx.obj["client"].request({", ".join(call_args)})'
)
lines.append(" _output(result)")
if is_table:
lines.append(" _table_output(result, output_format=output_format)")
else:
lines.append(" _yaml_output(result, output_format=output_format)")
return lines

lines.append(" body = {}")
Expand All @@ -437,7 +448,10 @@ def generate_command_code(
lines.append(
f' result = ctx.obj["client"].request("{method}", url, json_body=body)'
)
lines.append(" _output(result)")
if is_table:
lines.append(" _table_output(result, output_format=output_format)")
else:
lines.append(" _yaml_output(result, output_format=output_format)")

return lines

Expand Down Expand Up @@ -467,7 +481,7 @@ def generate_all(spec: dict) -> str:

import click

from judgment_cli.ui import output as _output
from judgment_cli.ui import table_output as _table_output, yaml_output as _yaml_output
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Generator emits references to _output which is no longer imported, producing broken code on re-generation

The import template at scripts/generate_cli.py:488 was changed to only import table_output and yaml_output, removing the output as _output import. However, the else branches at lines 428 and 458 still emit _output(result) for any command whose cmd_name is neither "list" nor "get". This affects the majority of commands (create, delete, update, search, tag, models, etc. — roughly 30 commands). If the generator is re-run, the resulting generated_commands.py will contain _output(result) calls that raise NameError at runtime because _output is undefined.

Additionally, --json flag is missing for non-list/non-get commands in the generator

Lines 388-389 and 394-395 only add the --json option decorator and json_output function parameter for commands named exactly "list" or "get". The current generated file has --json on ALL commands (e.g. automations create, docs search, judges models), but the generator cannot reproduce this. Re-running the generator would also strip the --json flag from those commands.

Prompt for agents
The root cause is that generate_cli.py was only partially updated: the import template was changed to drop `output as _output`, and `--json`/`json_output` plus the new output functions were only added for commands named 'list' or 'get'. But the generated_commands.py file was manually updated to add --json to ALL commands and use _yaml_output for non-list commands (not just 'get').

To fix, update generate_command_code() in scripts/generate_cli.py:

1. Add the --json flag and json_output parameter to ALL commands, not just list/get. Remove the `if is_list or is_get:` guards around the --json option (line 388) and the json_output sig_parts append (line 394).

2. Replace the else branches at lines 427-428 and 456-458 that emit `_output(result)` to instead emit `_yaml_output(result, json_mode=json_output)` — matching what the generated file currently does.

3. Also handle 'search' commands: the current generated file uses `_table_output` for search commands (docs search, sessions search, traces search). Either add `is_search = cmd_name == 'search'` and route it to _table_output, or adopt a broader heuristic.

4. The import line at line 488 should also import `output as _output` if any commands still need it, OR ensure all branches use the new functions.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


""")

Expand Down
Loading
Loading