Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
Feature/polish pipe builder usex (#446)
Louis Choquelfa7403801e85
diff --git a/.vscode/launch.json b/.vscode/launch.jsonindex def33534c..a03eb1287 100644--- a/.vscode/launch.json+++ b/.vscode/launch.json@@ -59,9 +59,9 @@"program": "${workspaceFolder}/.venv/bin/pipelex","args": ["run",- "results/test_1.plx",+ "results/pipeline_01/bundle.plx","--inputs",- "results/inputs_2.json",+ "results/pipeline_01/inputs.json",],"console": "integratedTerminal","justMyCode": falsediff --git a/pipelex/builder/bundle_header_spec.py b/pipelex/builder/bundle_header_spec.pyindex 39fa49fca..92c391eb0 100644--- a/pipelex/builder/bundle_header_spec.py+++ b/pipelex/builder/bundle_header_spec.py@@ -14,12 +14,12 @@ class BundleHeaderSpec(StructuredContent):main_pipe: str = Field(description="The main pipe of the domain.")@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:bundle_group = Group()if title:bundle_group.renderables.append(Text(title, style="bold"))bundle_group.renderables.append(Text.from_markup(f"Domain: [yellow]{self.domain}[/yellow]\n", style="bold"))- bundle_group.renderables.append(Text.from_markup(f"Description: [italic]{self.description}[/italic]\n"))+ bundle_group.renderables.append(Text.from_markup(f"Description: [yellow italic]{self.description}[/yellow italic]\n"))bundle_group.renderables.append(Text.from_markup(f"Main Pipe: [red]{self.main_pipe}[/red]\n"))if self.system_prompt:bundle_group.renderables.append(Text(f"System Prompt: {self.system_prompt}", style="dim"))diff --git a/pipelex/builder/bundle_spec.py b/pipelex/builder/bundle_spec.pyindex a198c5a59..e23d4a6f9 100644--- a/pipelex/builder/bundle_spec.py+++ b/pipelex/builder/bundle_spec.py@@ -130,7 +130,7 @@ class PipelexBundleSpec(StructuredContent):)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:bundle_group = Group()# Bundle header info@@ -138,7 +138,7 @@ class PipelexBundleSpec(StructuredContent):bundle_group.renderables.append(Text(title, style="bold"))bundle_group.renderables.append(Text.from_markup(f"Domain: [yellow]{self.domain}[/yellow]\n", style="bold"))if self.description:- bundle_group.renderables.append(Text.from_markup(f"Description: [italic]{self.description}[/italic]\n"))+ bundle_group.renderables.append(Text.from_markup(f"Description: [yellow italic]{self.description}[/yellow italic]\n"))bundle_group.renderables.append(Text.from_markup(f"Main Pipe: [red]{self.main_pipe}[/red]\n"))if self.system_prompt:bundle_group.renderables.append(Text(f"System Prompt: {self.system_prompt}\n", style="dim"))@@ -153,7 +153,7 @@ class PipelexBundleSpec(StructuredContent):for concept_code, concept_spec_or_name in self.concept.items():if isinstance(concept_spec_or_name, ConceptSpec):- concept_rendered = concept_spec_or_name.rendered_for_rich()+ concept_rendered = concept_spec_or_name.rendered_pretty()concepts_table.add_row(concept_rendered)else:# Simple string concept reference@@ -168,7 +168,7 @@ class PipelexBundleSpec(StructuredContent):pipes_table.add_column("Pipe", style="white")for pipe_spec in self.pipe.values():- pipe_rendered = pipe_spec.rendered_for_rich()+ pipe_rendered = pipe_spec.rendered_pretty()pipes_table.add_row(pipe_rendered)bundle_group.renderables.append(pipes_table)diff --git a/pipelex/builder/concept/concept_spec.py b/pipelex/builder/concept/concept_spec.pyindex 0a4f9f272..75eeed0a4 100644--- a/pipelex/builder/concept/concept_spec.py+++ b/pipelex/builder/concept/concept_spec.py@@ -221,14 +221,14 @@ class ConceptSpec(StructuredContent):return ConceptBlueprint(description=self.description, structure=converted_structure, refines=self.refines)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:concept_group = Group()if title:concept_group.renderables.append(Text(title, style="bold"))concept_group.renderables.append(Text.from_markup(f"Concept: [green]{self.the_concept_code}[/green]", style="bold"))if self.refines:concept_group.renderables.append(Text.from_markup(f"Refines: [green]{self.refines}[/green]"))- concept_group.renderables.append(Text.from_markup(f"\nDescription: [italic]{self.description}[/italic]\n"))+ concept_group.renderables.append(Text.from_markup(f"\nDescription: [yellow italic]{self.description}[/yellow italic]\n"))if self.structure:# Check if any field has a default valuehas_default_values = any(field_spec.default_value is not None for field_spec in self.structure.values())diff --git a/pipelex/builder/pipe/pipe_batch_spec.py b/pipelex/builder/pipe/pipe_batch_spec.pyindex 48d430d72..9cdb7576b 100644--- a/pipelex/builder/pipe/pipe_batch_spec.py+++ b/pipelex/builder/pipe/pipe_batch_spec.py@@ -37,9 +37,9 @@ class PipeBatchSpec(PipeSpec):)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with batch-specific detailsbatch_group = Group()diff --git a/pipelex/builder/pipe/pipe_compose_spec.py b/pipelex/builder/pipe/pipe_compose_spec.pyindex 27a4ab352..14891b4da 100644--- a/pipelex/builder/pipe/pipe_compose_spec.py+++ b/pipelex/builder/pipe/pipe_compose_spec.py@@ -91,9 +91,9 @@ class PipeComposeSpec(PipeSpec):return TargetFormat(target_format_value)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with compose-specific detailscompose_group = Group()diff --git a/pipelex/builder/pipe/pipe_condition_spec.py b/pipelex/builder/pipe/pipe_condition_spec.pyindex 065dcfd7e..87afeb99e 100644--- a/pipelex/builder/pipe/pipe_condition_spec.py+++ b/pipelex/builder/pipe/pipe_condition_spec.py@@ -32,9 +32,9 @@ class PipeConditionSpec(PipeSpec):default_outcome: str | SpecialOutcome = Field(description="The fallback outcome if the expression result does not match any key in outcome map.")@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with condition-specific detailscondition_group = Group()diff --git a/pipelex/builder/pipe/pipe_extract_spec.py b/pipelex/builder/pipe/pipe_extract_spec.pyindex 2722cbf7e..65c0baafd 100644--- a/pipelex/builder/pipe/pipe_extract_spec.py+++ b/pipelex/builder/pipe/pipe_extract_spec.py@@ -63,9 +63,9 @@ class PipeExtractSpec(PipeSpec):return inputs_value@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with extract-specific detailsextract_group = Group()diff --git a/pipelex/builder/pipe/pipe_func_spec.py b/pipelex/builder/pipe/pipe_func_spec.pyindex dead94644..c5f99fa48 100644--- a/pipelex/builder/pipe/pipe_func_spec.py+++ b/pipelex/builder/pipe/pipe_func_spec.py@@ -19,9 +19,9 @@ class PipeFuncSpec(PipeSpec):function_name: str = Field(description="The name of the function to call.")@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with func-specific detailsfunc_group = Group()diff --git a/pipelex/builder/pipe/pipe_img_gen_spec.py b/pipelex/builder/pipe/pipe_img_gen_spec.pyindex f6169b0b8..41bb9440a 100644--- a/pipelex/builder/pipe/pipe_img_gen_spec.py+++ b/pipelex/builder/pipe/pipe_img_gen_spec.py@@ -46,9 +46,9 @@ class PipeImgGenSpec(PipeSpec):return ImgGenSkill(img_gen_skill_value)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with img_gen-specific detailsimg_gen_group = Group()diff --git a/pipelex/builder/pipe/pipe_llm_spec.py b/pipelex/builder/pipe/pipe_llm_spec.pyindex 582115b34..a838afe7b 100644--- a/pipelex/builder/pipe/pipe_llm_spec.py+++ b/pipelex/builder/pipe/pipe_llm_spec.py@@ -73,9 +73,9 @@ So, don't have to write a bullet-list of all the attributes definitions yourselfreturn LLMSkill(llm_value)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with LLM-specific detailsllm_group = Group()diff --git a/pipelex/builder/pipe/pipe_parallel_spec.py b/pipelex/builder/pipe/pipe_parallel_spec.pyindex 5fff49735..ceab29cdd 100644--- a/pipelex/builder/pipe/pipe_parallel_spec.py+++ b/pipelex/builder/pipe/pipe_parallel_spec.py@@ -58,9 +58,9 @@ class PipeParallelSpec(PipeSpec):return self@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with parallel-specific detailsparallel_group = Group()diff --git a/pipelex/builder/pipe/pipe_sequence_spec.py b/pipelex/builder/pipe/pipe_sequence_spec.pyindex 915a55b81..73b3f76f9 100644--- a/pipelex/builder/pipe/pipe_sequence_spec.py+++ b/pipelex/builder/pipe/pipe_sequence_spec.py@@ -26,9 +26,9 @@ class PipeSequenceSpec(PipeSpec):)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:# Get base pipe information from parent- base_group = super().rendered_for_rich(title=title, number=number)+ base_group = super().rendered_pretty(title=title, depth=depth)# Create a group combining base info with sequence-specific detailssequence_group = Group()diff --git a/pipelex/builder/pipe/pipe_signature.py b/pipelex/builder/pipe/pipe_signature.pyindex 9649f9361..51d8e2338 100644--- a/pipelex/builder/pipe/pipe_signature.py+++ b/pipelex/builder/pipe/pipe_signature.py@@ -69,14 +69,14 @@ class PipeSignature(StructuredContent):return AllowedPipeTypes(type_value)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:pipe_group = Group()if title:pipe_group.renderables.append(Text(title, style="bold"))pipe_group.renderables.append(Text.from_markup(f"Pipe Signature: [red]{self.code}[/red]\n", style="bold"))pipe_type = self.type.value if isinstance(self.type, AllowedPipeTypes) else str(self.type)pipe_group.renderables.append(Text.from_markup(f"Type: [bold magenta]{pipe_type}[/bold magenta] ({self.pipe_category.value})\n"))- pipe_group.renderables.append(Text.from_markup(f"Description: [italic]{self.description}[/italic]\n"))+ pipe_group.renderables.append(Text.from_markup(f"Description: [yellow italic]{self.description}[/yellow italic]\n"))# Create inputs sectionif not self.inputs:diff --git a/pipelex/builder/pipe/pipe_spec.py b/pipelex/builder/pipe/pipe_spec.pyindex fab73d608..8499becc2 100644--- a/pipelex/builder/pipe/pipe_spec.py+++ b/pipelex/builder/pipe/pipe_spec.py@@ -136,14 +136,14 @@ class PipeSpec(StructuredContent):)@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:pipe_group = Group()if title:pipe_group.renderables.append(Text(title, style="bold"))pipe_group.renderables.append(Text.from_markup(f"Pipe: [bold red]{self.pipe_code}[/bold red]\n"))pipe_group.renderables.append(Text.from_markup(f"Type: [bold magenta]{self.type}[/bold magenta] ({self.pipe_category})\n"))if self.description:- pipe_group.renderables.append(Text.from_markup(f"Description: [italic]{self.description}[/italic]\n"))+ pipe_group.renderables.append(Text.from_markup(f"Description: [yellow italic]{self.description}[/yellow italic]\n"))# Create inputs sectionif not self.inputs:diff --git a/pipelex/cli/_cli.py b/pipelex/cli/_cli.pyindex 5bd23183e..9861a4c2c 100644--- a/pipelex/cli/_cli.py+++ b/pipelex/cli/_cli.py@@ -63,7 +63,7 @@ def app_callback(ctx: typer.Context) -> None:░██ ░██░███ ░██ ░██ ░██ ░██ ░██ ░██░██ ░██░██░█████ ░███████ ░██ ░███████ ░██ ░██░██- ░██ v{package_version}+ ░██ v[cyan]{package_version}[/cyan]""")# Skip checks if no command is being run (e.g., just --help) or if running init/doctor commanddiff --git a/pipelex/cli/commands/build_cmd.py b/pipelex/cli/commands/build_cmd.pyindex 921f30233..91ee4324e 100644--- a/pipelex/cli/commands/build_cmd.py+++ b/pipelex/cli/commands/build_cmd.py@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Annotatedimport clickimport typerfrom posthog import tag+from rich.console import Consolefrom pipelex import pretty_printfrom pipelex.builder.builder import PipelexBundleSpec, load_and_validate_bundle@@ -39,6 +40,7 @@ from pipelex.tools.misc.file_utils import (save_text_to_path,)from pipelex.tools.misc.json_utils import load_json_dict_from_path, save_as_json_to_path+from pipelex.tools.misc.pretty import PrettyPrinterif TYPE_CHECKING:from pipelex.client.protocol import PipelineInputs@@ -119,6 +121,7 @@ def build_pipe_cmd(typer.secho("🔥 Starting pipe builder... 🚀\n", fg=typer.colors.GREEN)async def run_pipeline():+ start_time = time.time()# Get builder configbuilder_config = get_config().pipelex.builder_config@@ -178,13 +181,26 @@ def build_pipe_cmd(ensure_directory_for_file_path(file_path=plx_file_path)plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())save_text_to_path(text=plx_content, path=plx_file_path)- typer.secho(f"✅ Bundle saved to: {plx_file_path}", fg=typer.colors.GREEN)+ typer.secho(f"✅ Pipelex bundle saved to: {plx_file_path}", fg=typer.colors.GREEN)# Generate extras (inputs and runner) if requestedif not no_extras:main_pipe_code = pipelex_bundle_spec.main_pipeif main_pipe_code:try:+ pretty = pipelex_bundle_spec.rendered_pretty()+ # Generate pretty HTML+ pretty_html = PrettyPrinter.pretty_html(pretty=pretty)+ html_path = os.path.join(extras_output_dir, "bundle_view.html")+ save_text_to_path(text=pretty_html, path=html_path)+ typer.secho(f"✅ Pretty HTML saved to: {html_path}", fg=typer.colors.GREEN)++ # Generate pretty SVG+ pretty_svg = PrettyPrinter.pretty_svg(pretty=pretty)+ svg_path = os.path.join(extras_output_dir, "bundle_view.svg")+ save_text_to_path(text=pretty_svg, path=svg_path)+ typer.secho(f"✅ Pretty SVG saved to: {svg_path}", fg=typer.colors.GREEN)+# Load the bundle from the file we just saved to register the pipe_ = await load_and_validate_bundle(plx_file_path)pipe = get_required_pipe(pipe_code=main_pipe_code)@@ -193,13 +209,24 @@ def build_pipe_cmd(inputs_json_str = generate_input_memory_json_string(pipe.inputs, indent=2)inputs_json_path = os.path.join(extras_output_dir, "inputs.json")save_text_to_path(text=inputs_json_str, path=inputs_json_path)- typer.secho(f"✅ Inputs saved to: {inputs_json_path}", fg=typer.colors.GREEN)+ typer.secho(f"✅ Inputs template saved to: {inputs_json_path}", fg=typer.colors.GREEN)# Generate runner.pyrunner_code = generate_runner_code(pipe)runner_path = os.path.join(extras_output_dir, f"run_{main_pipe_code}.py")save_text_to_path(text=runner_code, path=runner_path)- typer.secho(f"✅ Runner saved to: {runner_path}", fg=typer.colors.GREEN)+ typer.secho(f"✅ Python runner script saved to: {runner_path}", fg=typer.colors.GREEN)++ end_time = time.time()+ typer.secho(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds\n", fg=typer.colors.WHITE)++ get_report_delegate().generate_report()++ # Show how to run the pipe+ console = Console()+ console.print("\n📋 [cyan]To run your pipeline:[/cyan]")+ console.print(f" [cyan]• Execute the runner:[/cyan] python {runner_path}")+ console.print(f" [cyan]• Or use CLI:[/cyan] pipelex run {plx_file_path} --inputs {inputs_json_path}\n")except Exception as exc:typer.secho(f"⚠️ Warning: Could not generate extras: {exc}", fg=typer.colors.YELLOW)@@ -210,12 +237,7 @@ def build_pipe_cmd(tag(name=EventProperty.PIPELEX_VERSION, value=PACKAGE_VERSION)tag(name=EventProperty.CLI_COMMAND, value=f"{COMMAND} {SUB_COMMAND_PIPE}")- start_time = time.time()asyncio.run(run_pipeline())- end_time = time.time()- typer.secho(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds", fg=typer.colors.GREEN)-- get_report_delegate().generate_report()except PipeOperatorModelChoiceError as exc:handle_model_choice_error(exc, context=ErrorContext.BUILD)diff --git a/pipelex/cli/commands/run_cmd.py b/pipelex/cli/commands/run_cmd.pyindex 04ce39a5d..c4b5f0ce9 100644--- a/pipelex/cli/commands/run_cmd.py+++ b/pipelex/cli/commands/run_cmd.py@@ -9,7 +9,7 @@ import typerfrom posthog import tagfrom rich.console import Console-from pipelex import log, pretty_print_md+from pipelex import logfrom pipelex.builder.builder import load_and_validate_bundlefrom pipelex.builder.exceptions import PipelexBundleErrorfrom pipelex.cli.error_handlers import (@@ -181,9 +181,9 @@ def run_cmd(# Pretty print main_stuff unless disabledif not no_pretty_print:- typer.echo("")- pretty_print_md(content=pipe_output.main_stuff.content.rendered_markdown(), title=f"Main output of '{pipe_code}'")- typer.echo("")+ title = f"Final output of pipe [red]{pipe_code}[/red]"+ pipe_output.main_stuff.pretty_print_stuff(title=title)+ # TODO: no_pretty_print should also disable the pretty printing of each pipe operator step# Save working memory to JSON unless disabledif not no_output:diff --git a/pipelex/core/stuffs/image_content.py b/pipelex/core/stuffs/image_content.pyindex 2c08a98cd..175a35f23 100644--- a/pipelex/core/stuffs/image_content.py+++ b/pipelex/core/stuffs/image_content.py@@ -50,7 +50,11 @@ class ImageContent(StuffContent):@classmethoddef make_from_extracted_image(cls, extracted_image: ExtractedImage) -> Self:if base_64 := extracted_image.base_64:- prefixed_base64_str = prefixed_base64_str_from_base64_str(b64_str=base_64)+ # Check if it's already a prefixed base64 string+ if base_64.startswith("data:"):+ prefixed_base64_str = base_64+ else:+ prefixed_base64_str = prefixed_base64_str_from_base64_str(b64_str=base_64)return cls(url=prefixed_base64_str,base_64=extracted_image.base_64,diff --git a/pipelex/core/stuffs/list_content.py b/pipelex/core/stuffs/list_content.pyindex bf6df0268..4b2ab2e4b 100644--- a/pipelex/core/stuffs/list_content.py+++ b/pipelex/core/stuffs/list_content.py@@ -1,12 +1,13 @@from typing import Any, Genericfrom json2html import json2html+from rich.pretty import Prettyfrom rich.table import Tablefrom typing_extensions import overridefrom pipelex.cogt.templating.templating_style import TextFormatfrom pipelex.core.stuffs.stuff_content import StuffContent, StuffContentType-from pipelex.tools.misc.pretty import PrettyPrintable, pretty_width+from pipelex.tools.misc.pretty import MAX_RENDER_DEPTH, PrettyPrintable, PrettyPrinterclass ListContent(StuffContent, Generic[StuffContentType]):@@ -82,14 +83,26 @@ class ListContent(StuffContent, Generic[StuffContentType]):return rendered@override- def rendered_for_rich(self, title: str | None = None, number: int | None = None) -> PrettyPrintable:- table = Table(title=title, show_header=False, show_edge=False, show_lines=True, border_style="white", width=pretty_width(factor=0.8))+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:+ # Check if we've exceeded maximum depth - fall back to Pretty rendering+ # Pretty shows the Python object structure beautifully, just like when calling pretty_print(stuff)+ if depth >= MAX_RENDER_DEPTH:+ return Pretty(self)++ table = Table(+ title=title,+ show_header=False,+ show_edge=False,+ show_lines=True,+ border_style="white",+ width=PrettyPrinter.pretty_width(depth=depth),+ )table.add_column("No.", style="yellow", justify="center", width=6)table.add_column("Content", style="white")for item_index, item in enumerate(self.items):item_number = str(item_index + 1)- item_content = item.rendered_for_rich()+ item_content = item.rendered_pretty(depth=depth + 1)table.add_row(item_number, item_content)return tablediff --git a/pipelex/core/stuffs/page_content.py b/pipelex/core/stuffs/page_content.pyindex c8957007d..2b4909b54 100644--- a/pipelex/core/stuffs/page_content.py+++ b/pipelex/core/stuffs/page_content.py@@ -1,13 +1,38 @@+from rich.console import Group+from rich.markdown import Markdown+from rich.text import Text+from typing_extensions import override+from pipelex.core.stuffs.image_content import ImageContentfrom pipelex.core.stuffs.structured_content import StructuredContentfrom pipelex.core.stuffs.text_and_images_content import TextAndImagesContentfrom pipelex.tools.misc.file_utils import ensure_directory_exists+from pipelex.tools.misc.pretty import PrettyPrintableclass PageContent(StructuredContent):text_and_images: TextAndImagesContentpage_view: ImageContent | None = None+ @override+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:+ # If there's no page_view, just return the text_and_images rendering+ if self.page_view is None:+ return self.text_and_images.rendered_pretty(depth=depth)++ # If there's a page_view, create a group with both+ group = Group()++ # Add the text and images content+ group.renderables.append(self.text_and_images.rendered_pretty(depth=depth))++ # Add the page view section+ group.renderables.append(Text("\nPage View:", style="bold cyan"))+ url_markdown = Markdown(f"[{self.page_view.url}…]({self.page_view.url})")+ group.renderables.append(url_markdown)++ return group+def save_to_directory(self, directory: str):ensure_directory_exists(directory)self.text_and_images.save_to_directory(directory=directory)diff --git a/pipelex/core/stuffs/structured_content.py b/pipelex/core/stuffs/structured_content.pyindex 16a4b9978..95ce50620 100644--- a/pipelex/core/stuffs/structured_content.py+++ b/pipelex/core/stuffs/structured_content.py@@ -1,8 +1,11 @@from json2html import json2html+from rich.pretty import Pretty+from rich.table import Tablefrom typing_extensions import overridefrom pipelex.core.stuffs.stuff_content import StuffContentfrom pipelex.tools.misc.markdown_utils import convert_to_markdown+from pipelex.tools.misc.pretty import MAX_RENDER_DEPTH, PrettyPrintable, PrettyPrinterfrom pipelex.tools.typing.pydantic_utils import clean_model_to_dict@@ -31,3 +34,34 @@ class StructuredContent(StuffContent):def rendered_markdown(self, level: int = 1, is_pretty: bool = False) -> str:dict_dump = clean_model_to_dict(obj=self)return convert_to_markdown(data=dict_dump, level=level, is_pretty=is_pretty)++ @override+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:+ # Check if we've exceeded maximum depth - fall back to Pretty rendering+ # Pretty shows the Python object structure beautifully, just like when calling pretty_print(stuff)+ if depth >= MAX_RENDER_DEPTH:+ return Pretty(self)++ table = Table(+ title=title,+ show_header=True,+ show_edge=False,+ show_lines=True,+ border_style="white",+ width=PrettyPrinter.pretty_width(depth=depth),+ )+ table.add_column("Attribute", style="cyan", justify="left")+ table.add_column("Value", style="white")++ # Get all fields from the model+ for field_name, field_value in self:+ # Skip None values and empty lists+ if field_value is None:+ continue+ if isinstance(field_value, list) and len(field_value) == 0: # type: ignore[arg-type]+ continue++ pretty = PrettyPrinter.make_pretty(value=field_value, depth=depth + 1)+ table.add_row(field_name, pretty)++ return tablediff --git a/pipelex/core/stuffs/stuff_content.py b/pipelex/core/stuffs/stuff_content.pyindex 39018ac9d..f012a9d93 100644--- a/pipelex/core/stuffs/stuff_content.py+++ b/pipelex/core/stuffs/stuff_content.py@@ -7,7 +7,7 @@ from typing_extensions import overridefrom pipelex.cogt.templating.templating_style import TextFormatfrom pipelex.tools.misc.json_utils import remove_none_values-from pipelex.tools.misc.pretty import PrettyPrintable, pretty_print, pretty_width+from pipelex.tools.misc.pretty import PrettyPrintable, PrettyPrinter, pretty_printfrom pipelex.tools.typing.pydantic_utils import CustomBaseModelStuffContentType = TypeVar("StuffContentType", bound="StuffContent")@@ -55,9 +55,17 @@ class StuffContent(ABC, CustomBaseModel):def rendered_json(self) -> str:return kajson.dumps(self.smart_dump(), indent=4)- def rendered_for_rich(self) -> PrettyPrintable:+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable: # noqa: ARG002+ """Render content for pretty printing.++ Args:+ title: Optional title for the rendering+ depth: Current nesting depth, used to prevent nesting too many sub-tables which would end up too narrow in the console+ """json_content = remove_none_values(json_content=self.smart_dump())return JSON.from_data(json_content, indent=4)- def pretty_print_content(self, title: str | None = None, number: int | None = None) -> None: # noqa: ARG002- pretty_print(self.rendered_for_rich(), title=title, width=pretty_width())+ def pretty_print_content(self, title: str | None = None) -> None:+ pretty = self.rendered_pretty()+ width = PrettyPrinter.pretty_width()+ pretty_print(pretty, title=title, width=width)diff --git a/pipelex/core/stuffs/text_and_images_content.py b/pipelex/core/stuffs/text_and_images_content.pyindex 03eab91a1..ded5bdb97 100644--- a/pipelex/core/stuffs/text_and_images_content.py+++ b/pipelex/core/stuffs/text_and_images_content.py@@ -1,9 +1,14 @@+from rich.console import Group+from rich.markdown import Markdown+from rich.table import Table+from rich.text import Textfrom typing_extensions import overridefrom pipelex.core.stuffs.image_content import ImageContentfrom pipelex.core.stuffs.stuff_content import StuffContentfrom pipelex.core.stuffs.text_content import TextContentfrom pipelex.tools.misc.file_utils import ensure_directory_exists+from pipelex.tools.misc.pretty import PrettyPrintableclass TextAndImagesContent(StuffContent):@@ -33,6 +38,56 @@ class TextAndImagesContent(StuffContent):rendered = ""return rendered+ @override+ def rendered_pretty(self, title: str | None = None, depth: int = 0) -> PrettyPrintable:+ # If neither text nor images are present+ if not self.text and not self.images:+ return Text("(empty)", style="dim italic")++ # If only text is present, render as Markdown+ if self.text and not self.images:+ return Markdown(self.text.text)++ group = Group()++ # Add text section if present+ if self.text:+ group.renderables.append(Text("Text:", style="bold cyan"))+ group.renderables.append(Markdown(self.text.text))+ if self.images:+ group.renderables.append(Text()) # Add spacing++ # Add images section if present+ if self.images:+ # Check if any image has a caption (for table column headers)+ has_captions = any(image.caption for image in self.images)++ table = Table(+ title=f"Images ({len(self.images)}):",+ title_style="bold cyan",+ title_justify="left",+ show_header=True,+ header_style="dim",+ border_style="dim",+ )+ table.add_column("Index")+ table.add_column("URL", width=36)+ if has_captions:+ table.add_column("Caption", style="yellow italic")++ for idx, image in enumerate(self.images):+ index_text = Text.from_markup(f"[dim]img-[/dim][yellow]{idx}[/yellow]")+ display_url = f"{image.url[:35]}…" if len(image.url) > 36 else image.url+ url_markdown = Markdown(f"[{display_url}]({image.url})")+ if has_captions:+ table.add_row(index_text, url_markdown, image.caption or "/")+ else:+ table.add_row(index_text, url_markdown)++ group.renderables.append(table)++ return group+def save_to_directory(self, directory: str):ensure_directory_exists(directory)if text_content := self.text:diff --git a/pipelex/core/stuffs/text_content.py b/pipelex/core/stuffs/text_content.pyindex 3fa630459..42ddf34c7 100644--- a/pipelex/core/stuffs/text_content.py+++ b/pipelex/core/stuffs/text_content.py@@ -48,5 +48,5 @@ class TextContent(StuffContent):save_text_to_path(text=self.text, path=f"{directory}/{filename}")@override- def pretty_print_content(self, title: str | None = None, number: int | None = None) -> None:+ def pretty_print_content(self, title: str | None = None) -> None:pretty_print_md(self.text, title=title)diff --git a/pipelex/pipe_controllers/pipe_controller.py b/pipelex/pipe_controllers/pipe_controller.pyindex 267ad4c30..8fd00d651 100644--- a/pipelex/pipe_controllers/pipe_controller.py+++ b/pipelex/pipe_controllers/pipe_controller.py@@ -54,7 +54,9 @@ class PipeController(PipeAbstract):self._validate_inputs_in_memory(working_memory=working_memory)pipe_run_info = self._format_pipe_run_info(pipe_run_params=pipe_run_params)- log.info(pipe_run_info)+ # log.info(pipe_run_info)+ if pipe_run_params.run_mode == PipeRunMode.LIVE:+ log.info(pipe_run_info)match pipe_run_params.run_mode:case PipeRunMode.LIVE:pipe_output = await self._run_controller_pipe(diff --git a/pipelex/pipe_operators/pipe_operator.py b/pipelex/pipe_operators/pipe_operator.pyindex cdb4794b1..7f2fb56ac 100644--- a/pipelex/pipe_operators/pipe_operator.py+++ b/pipelex/pipe_operators/pipe_operator.py@@ -44,7 +44,9 @@ class PipeOperator(PipeAbstract, Generic[PipeOperatorOutputType]):job_metadata.update(updated_metadata=updated_metadata)pipe_run_info = self._format_pipe_run_info(pipe_run_params=pipe_run_params)- log.info(pipe_run_info)+ # log.info(pipe_run_info)+ if pipe_run_params.run_mode == PipeRunMode.LIVE:+ log.info(pipe_run_info)try:match pipe_run_params.run_mode:case PipeRunMode.LIVE:@@ -60,8 +62,11 @@ class PipeOperator(PipeAbstract, Generic[PipeOperatorOutputType]):if main_stuff.is_list:list_content: ListContent[StuffContent] = main_stuff.as_list_content() # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType]nb_items = len(list_content.items)- output_concept_with_multiplicity = f" ({nb_items} items)"- title = f"Output of pipe [red]{self.code}[/red]: {output_concept_with_multiplicity}"+ if nb_items == 1:+ output_concept_with_multiplicity += " [1 item]"+ else:+ output_concept_with_multiplicity += f" [{nb_items} items]"+ title = f"Output of pipe [red]{self.code}[/red] [yellow]→[/yellow] {output_concept_with_multiplicity}"main_stuff.pretty_print_stuff(title=title)case PipeRunMode.DRY:pipe_output = await self._dry_run_operator_pipe(diff --git a/pipelex/tools/misc/pretty.py b/pipelex/tools/misc/pretty.pyindex 4815bfad0..f07fd58fa 100644--- a/pipelex/tools/misc/pretty.py+++ b/pipelex/tools/misc/pretty.py@@ -1,9 +1,10 @@import shutil+from io import StringIOfrom typing import Any, ClassVarfrom kajson import kajsonfrom rich import print as rich_print-from rich.console import Group+from rich.console import Console, Groupfrom rich.json import JSONfrom rich.markdown import Markdownfrom rich.panel import Panel@@ -11,6 +12,7 @@ from rich.pretty import Prettyfrom rich.style import StyleTypefrom rich.syntax import Syntaxfrom rich.table import Table+from rich.terminal_theme import TerminalThemefrom rich.text import Text, TextTypefrom pipelex.tools.misc.terminal_utils import BOLD_FONT, RESET_FONT, TerminalColor@@ -20,17 +22,41 @@ TEXT_COLOR = TerminalColor.WHITETITLE_COLOR = TerminalColor.CYANBORDER_COLOR = TerminalColor.YELLOW-PRETTY_WIDTH_MIN = 125+# TODO: Make PrettyPrinter a manager so we can init it with a proper config+PRETTY_WIDTH_MIN: int = 125+PRETTY_WIDTH_FOR_EXPORT: int = 100+MAX_RENDER_DEPTH = 6+EXPORT_THEME = TerminalTheme(+ (0, 0, 0),+ (197, 200, 198),+ [+ (75, 78, 85),+ (204, 85, 90),+ (152, 168, 75),+ (208, 179, 68),+ (96, 138, 177),+ (152, 114, 159),+ (104, 160, 179),+ (197, 200, 198),+ (154, 155, 153),+ ],+ [+ (255, 38, 39),+ (0, 130, 61),+ (208, 132, 66),+ (25, 132, 233),+ (255, 44, 122),+ (57, 130, 128),+ (253, 253, 197),+ ],+)-PrettyPrintable = Markdown | Text | JSON | Table | Group+PrettyPrintable = Markdown | Text | JSON | Table | Group | Syntax | Pretty-def pretty_width(width: int | None = None, factor: float | None = None) -> int:- terminal_width = shutil.get_terminal_size().columns- absolute_width = width or min(max(PRETTY_WIDTH_MIN, int(terminal_width / 2)), terminal_width)- if factor:- return int(absolute_width * factor)- return absolute_width+class PrettyPrintMode(StrEnum):+ RICH = "rich"+ POOR = "poor"def pretty_print(@@ -52,16 +78,11 @@ def pretty_print_md(border_style: StyleType | None = None,width: int | None = None,):- width = width or pretty_width()+ width = width or PrettyPrinter.pretty_width()md_content = Markdown(content)PrettyPrinter.pretty_print(content=md_content, title=title, subtitle=subtitle, inner_title=inner_title, border_style=border_style, width=width)-class PrettyPrintMode(StrEnum):- RICH = "rich"- POOR = "poor"--class PrettyPrinter:mode: ClassVar[PrettyPrintMode] = PrettyPrintMode.RICH@@ -98,28 +119,48 @@ class PrettyPrinter:border_style: StyleType | None = None,width: int | None = None,):- if isinstance(content, str):- if content.startswith(("http://", "https://")):- content = Text(content, style="link " + content, no_wrap=True)- else:- content = Text(str(content)) # Treat all other strings as plain text- elif isinstance(content, (Pretty, JSON, Table, Markdown, Group)):- pass- elif isinstance(content, dict):- try:- content = JSON.from_data(content, indent=4)- except TypeError:- json_string = kajson.dumps(content, indent=4)- content = Syntax(json_string, "json", theme="monokai")+ panel = cls.make_pretty_panel(+ content=content, title=title, subtitle=subtitle, inner_title=inner_title, border_style=border_style, width=width+ )++ rich_print("", panel, "", sep="\n")++ @classmethod+ def pretty_width(cls, width: int | None = None, depth: int | None = None) -> int:+ terminal_width = shutil.get_terminal_size().columns+ absolute_width = width or min(max(PRETTY_WIDTH_MIN, terminal_width // 2), terminal_width)+ if depth is not None:+ # Calculate adaptive width factor based on depth to prevent excessive narrowing+ # Factor decreases slowly: depth 0->1.0, depth 1->0.9, depth 2->0.8, etc., min 0.5+ width_factor = max(0.5, 1.0 - (depth * 0.1))+ return int(absolute_width * width_factor)else:- content = Pretty(content)+ return absolute_width- if inner_title:- inner_title_text = Text(str(inner_title), style="dim")- content = Group(inner_title_text, content)- rich_print()- panel = Panel(- content,+ @classmethod+ def make_pretty_panel(+ cls,+ content: str | Any,+ title: TextType | None = None,+ subtitle: TextType | None = None,+ inner_title: str | None = None,+ border_style: StyleType | None = None,+ width: int | None = None,+ ) -> Panel:+ pretty = cls.make_pretty(content, inner_title=inner_title, depth=0)+ return cls.wrap_in_panel(pretty=pretty, title=title, subtitle=subtitle, border_style=border_style, width=width)++ @classmethod+ def wrap_in_panel(+ cls,+ pretty: PrettyPrintable,+ title: TextType | None = None,+ subtitle: TextType | None = None,+ border_style: StyleType | None = None,+ width: int | None = None,+ ) -> Panel:+ return Panel(+ pretty,title=title,subtitle=subtitle,expand=False,@@ -130,8 +171,76 @@ class PrettyPrinter:highlight=True,width=width,)- rich_print(panel)- rich_print()++ @classmethod+ def pretty_html(+ cls,+ pretty: PrettyPrintable,+ width: int = PRETTY_WIDTH_FOR_EXPORT,+ ) -> str:+ buf = StringIO()+ console = Console(record=True, file=buf, width=width, force_terminal=False)+ console.print(pretty)+ return console.export_html(inline_styles=False, clear=False, theme=EXPORT_THEME)++ @classmethod+ def pretty_svg(cls, pretty: PrettyPrintable, width: int = PRETTY_WIDTH_FOR_EXPORT) -> str:+ buf = StringIO()+ console = Console(record=True, file=buf, width=width, force_terminal=False)+ console.print(pretty)+ return console.export_svg()++ @classmethod+ def make_pretty(cls, value: Any, inner_title: str | None = None, depth: int = 0) -> PrettyPrintable:+ pretty: PrettyPrintable+ # Format the value+ if isinstance(value, PrettyPrintable):+ pretty = value+ elif isinstance(value, dict):+ # For dicts, use JSON rendering+ try:+ pretty = JSON.from_data(value, indent=4)+ except TypeError:+ json_string = kajson.dumps(value, indent=4)+ pretty = Syntax(json_string, "json", theme="monokai")+ elif isinstance(value, list):+ # For lists, build a table without headers+ list_table = Table(+ show_header=False,+ show_edge=False,+ show_lines=True,+ border_style="dim",+ padding=(0, 1),+ )+ list_table.add_column("No.", style="yellow", justify="center", width=4)+ list_table.add_column("Item", style="white")++ for idx, item in enumerate(value, start=1): # type: ignore[arg-type]+ pretty_item = cls.make_pretty(item, inner_title=None, depth=depth + 1)+ list_table.add_row(str(idx), pretty_item)++ pretty = list_table+ elif isinstance(value, str):+ # Handle URLs specially, otherwise use Text for simple strings+ if value.startswith(("http://", "https://")):+ pretty = Text(value, style="link " + value, no_wrap=True)+ else:+ # Use Text instead of Markdown to allow proper auto-sizing+ pretty = Text(value)+ elif isinstance(value, (int, float, bool)):+ # For primitive types, convert to string+ pretty = Text(str(value))+ elif hasattr(value, "rendered_pretty"):+ pretty = value.rendered_pretty(depth=depth)+ else:+ # For other types, use Pretty+ pretty = Pretty(value)++ if inner_title:+ inner_title_text = Text(str(inner_title), style="dim")+ pretty = Group(inner_title_text, pretty)++ return pretty@classmethoddef pretty_print_without_rich(diff --git a/tests/integration/pipelex/conftest.py b/tests/integration/pipelex/conftest.pyindex d82896fb8..371ff9a5b 100644--- a/tests/integration/pipelex/conftest.py+++ b/tests/integration/pipelex/conftest.py@@ -20,7 +20,7 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:params=[# "o1",# "gpt-4o",- # "gpt-4o-mini",+ "gpt-4o-mini",# "gpt-4-5-preview",# "o1-mini",# "o3-mini",@@ -49,7 +49,7 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:# "gpt-5-chat",# "claude-4.5-sonnet",# "claude-4.1-opus",- "claude-4.5-haiku",+ # "claude-4.5-haiku",# "claude-4.5-sonnet",# "grok-3",# "grok-3-mini",@@ -57,6 +57,10 @@ def llm_preset_id(request: pytest.FixtureRequest) -> str:# "gemini-2.5-flash-lite",# "gemini-2.5-flash",# "gemini-2.5-pro",+ # "openai/gpt-oss-120b",+ # "meta-llama/llama-4-scout-17b-16e-instruct",+ # "meta-llama/llama-4-maverick-17b-128e-instruct",+ # "moonshotai/kimi-k2-instruct-0905",],)def llm_handle(request: pytest.FixtureRequest) -> str:@@ -231,6 +235,7 @@ def extract_handle_from_image(request: pytest.FixtureRequest) -> str:@pytest.fixture(params=["extract_text_from_visuals",+ "extract_text_from_pdf",],)def extract_choice_for_pdf(request: pytest.FixtureRequest) -> str:diff --git a/tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.py b/tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.pyindex e616ad175..b0ae7ea8e 100644--- a/tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.py+++ b/tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.py@@ -74,11 +74,13 @@ class TestPipeExtract:pretty_print(list_result, title="list_result")@pytest.mark.parametrize("pdf_url", PipeExtractTestCases.PIPE_OCR_PDF_TEST_CASES)+ @pytest.mark.parametrize("page_image_captions", [False]) # TODO: add True when captioning is implementedasync def test_pipe_extract_from_pdf(self,extract_choice_for_pdf: str,pipe_run_mode: PipeRunMode,pdf_url: str,+ page_image_captions: bool,):input_name = "arbitrary_name"blueprint = PipeExtractBlueprint(@@ -87,7 +89,7 @@ class TestPipeExtract:output=NativeConceptCode.TEXT_AND_IMAGES,model=extract_choice_for_pdf,page_images=True,- page_image_captions=False,+ page_image_captions=page_image_captions,page_views=True,page_views_dpi=72,)diff --git a/tests/unit/core/stuffs/test_list_content_rendering.py b/tests/unit/core/stuffs/test_list_content_rendering.pynew file mode 100644index 000000000..f7bd77cec--- /dev/null+++ b/tests/unit/core/stuffs/test_list_content_rendering.py@@ -0,0 +1,108 @@+import re++from pytest import CaptureFixture++from pipelex.core.stuffs.list_content import ListContent+from pipelex.core.stuffs.structured_content import StructuredContent+from pipelex.core.stuffs.text_content import TextContent+from pipelex.tools.misc.pretty import MAX_RENDER_DEPTH, pretty_print+++def remove_ansi_escape_codes(text: str) -> str:+ """Remove ANSI color codes from terminal output."""+ ansi_escape = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")+ return ansi_escape.sub("", text)+++# Test Models+++class SimpleData(StructuredContent):+ """Simple structured content for testing."""++ name: str+ value: int+++class DeeplyNestedData(StructuredContent):+ """Deeply nested structure for depth limit testing."""++ level: int+ nested: "DeeplyNestedData | None" = None+++class TestListContentRendering:+ """Test ListContent.rendered_pretty()"""++ def test_simple_list_content(self, capsys: CaptureFixture[str]):+ """Test rendering simple list of text content."""+ text_list = ListContent[TextContent](+ items=[+ TextContent(text="First item"),+ TextContent(text="Second item"),+ TextContent(text="Third item"),+ ]+ )+ pretty_print(text_list.rendered_pretty(title="Text List"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Text List" in output+ assert "First item" in output+ assert "Second item" in output+ assert "Third item" in output+ # Should show item numbers+ assert "1" in output+ assert "2" in output+ assert "3" in output++ def test_list_of_structured_content(self, capsys: CaptureFixture[str]):+ """Test rendering list of structured content."""+ data_list = ListContent[SimpleData](+ items=[+ SimpleData(name="alpha", value=1),+ SimpleData(name="beta", value=2),+ SimpleData(name="gamma", value=3),+ ]+ )+ pretty_print(data_list.rendered_pretty(title="Data List"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Data List" in output+ assert "alpha" in output+ assert "beta" in output+ assert "gamma" in output+ assert "1" in output+ assert "2" in output+ assert "3" in output++ def test_empty_list_content(self, capsys: CaptureFixture[str]):+ """Test rendering empty list."""+ empty_list = ListContent[TextContent](items=[])+ pretty_print(empty_list.rendered_pretty(title="Empty List"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Empty List" in output+ # Empty list should still render, just without items++ def test_list_content_depth_limit(self, capsys: CaptureFixture[str]):+ """Test that deeply nested lists fall back to JSON when depth exceeds limit."""+ # Create a deeply nested structure using DeeplyNestedData+ current = DeeplyNestedData(level=MAX_RENDER_DEPTH + 1, nested=None)+ for level in range(MAX_RENDER_DEPTH, 0, -1):+ current = DeeplyNestedData(level=level, nested=current)++ # Put it in a list and render at a depth that will trigger fallback+ deep_list = ListContent[DeeplyNestedData](items=[current])+ pretty_print(deep_list.rendered_pretty(title="Deep List", depth=MAX_RENDER_DEPTH - 1))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Deep List" in output+ # At max depth, inner items should fall back to JSON/Pretty renderingdiff --git a/tests/unit/core/stuffs/test_page_content_rendering.py b/tests/unit/core/stuffs/test_page_content_rendering.pynew file mode 100644index 000000000..22e7e4af9--- /dev/null+++ b/tests/unit/core/stuffs/test_page_content_rendering.py@@ -0,0 +1,54 @@+import re++from pytest import CaptureFixture++from pipelex.core.stuffs.image_content import ImageContent+from pipelex.core.stuffs.page_content import PageContent+from pipelex.core.stuffs.text_and_images_content import TextAndImagesContent+from pipelex.core.stuffs.text_content import TextContent+from pipelex.tools.misc.pretty import pretty_print+++def remove_ansi_escape_codes(text: str) -> str:+ """Remove ANSI color codes from terminal output."""+ ansi_escape = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")+ return ansi_escape.sub("", text)+++class TestPageContentRendering:+ """Test PageContent.rendered_pretty()"""++ def test_page_content_without_view(self, capsys: CaptureFixture[str]):+ """Test rendering page content without page view."""+ page = PageContent(+ text_and_images=TextAndImagesContent(+ text=TextContent(text="Page text"),+ images=None,+ ),+ page_view=None,+ )+ pretty_print(page.rendered_pretty(title="Page"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Page" in output+ assert "Page text" in output++ def test_page_content_with_view(self, capsys: CaptureFixture[str]):+ """Test rendering page content with page view."""+ page = PageContent(+ text_and_images=TextAndImagesContent(+ text=TextContent(text="Page text"),+ images=None,+ ),+ page_view=ImageContent(url="https://example.com/page_screenshot.png"),+ )+ pretty_print(page.rendered_pretty())++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Page text" in output+ assert "Page View" in output+ assert "page_screenshot.png" in outputdiff --git a/tests/unit/core/stuffs/test_rendered_pretty_depth.py b/tests/unit/core/stuffs/test_rendered_pretty_depth.pynew file mode 100644index 000000000..c27dd9722--- /dev/null+++ b/tests/unit/core/stuffs/test_rendered_pretty_depth.py@@ -0,0 +1,114 @@+import re++from pytest import CaptureFixture++from pipelex.core.stuffs.structured_content import StructuredContent+from pipelex.tools.misc.pretty import MAX_RENDER_DEPTH, pretty_print+++def remove_ansi_escape_codes(text: str) -> str:+ """Remove ANSI color codes from terminal output."""+ ansi_escape = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")+ return ansi_escape.sub("", text)+++# Test Models+++class SimpleData(StructuredContent):+ """Simple structured content for testing."""++ name: str+ value: int+++class NestedData(StructuredContent):+ """Nested structured content for testing."""++ label: str+ simple: SimpleData+++class DeeplyNestedData(StructuredContent):+ """Deeply nested structure for depth limit testing."""++ level: int+ nested: "DeeplyNestedData | None" = None+++class TestDepthParameterPropagation:+ """Test that depth parameter is properly propagated through nested structures."""++ def test_depth_propagation_in_nested_structures(self):+ """Test that depth increments properly in nested calls."""+ # Create a structure that tracks depth calls+ nested = NestedData(label="level1", simple=SimpleData(name="level2", value=42))++ # Call with explicit depth+ result = nested.rendered_pretty(depth=0)+ assert result is not None++ # Call at max depth - should fall back to Pretty/JSON+ result_at_max = nested.rendered_pretty(depth=MAX_RENDER_DEPTH)+ assert result_at_max is not None++ def test_depth_at_limit_triggers_fallback(self, capsys: CaptureFixture[str]):+ """Test that rendering at MAX_RENDER_DEPTH triggers JSON fallback."""+ data = SimpleData(name="test", value=42)++ # Render at exactly MAX_RENDER_DEPTH+ pretty_print(data.rendered_pretty(depth=MAX_RENDER_DEPTH))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ # Should use Pretty fallback, which shows the object representation+ # or JSON format instead of table+ assert output # Just verify it renders something+++class TestAdaptiveWidthFactorRendering:+ """Test that width factor adapts based on depth."""++ def test_width_decreases_with_depth(self):+ """Test that nested structures get progressively narrower."""+ # Create nested structure using DeeplyNestedData which allows self-nesting+ level3 = DeeplyNestedData(level=3, nested=None)+ level2 = DeeplyNestedData(level=2, nested=level3)+ level1 = DeeplyNestedData(level=1, nested=level2)++ # Render at different depths - just verify no crashes+ result_depth0 = level1.rendered_pretty(depth=0)+ result_depth3 = level1.rendered_pretty(depth=3)++ assert result_depth0 is not None+ assert result_depth3 is not None+++class TestTitleParameter:+ """Test that title parameter is properly used."""++ def test_title_appears_in_output(self, capsys: CaptureFixture[str]):+ """Test that custom title appears in rendered output."""+ data = SimpleData(name="test", value=42)+ custom_title = "Custom Title for Data"++ pretty_print(data.rendered_pretty(title=custom_title))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert custom_title in output++ def test_no_title(self, capsys: CaptureFixture[str]):+ """Test rendering without title."""+ data = SimpleData(name="test", value=42)++ pretty_print(data.rendered_pretty(title=None))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ # Should still render content+ assert "test" in output+ assert "42" in outputdiff --git a/tests/unit/core/stuffs/test_structured_content_rendering.py b/tests/unit/core/stuffs/test_structured_content_rendering.pynew file mode 100644index 000000000..fe8cdd56d--- /dev/null+++ b/tests/unit/core/stuffs/test_structured_content_rendering.py@@ -0,0 +1,142 @@+import re++from pydantic import BaseModel+from pytest import CaptureFixture+from rich.text import Text++from pipelex.core.stuffs.structured_content import StructuredContent+from pipelex.tools.misc.pretty import MAX_RENDER_DEPTH, pretty_print+++def remove_ansi_escape_codes(text: str) -> str:+ """Remove ANSI color codes from terminal output."""+ ansi_escape = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")+ return ansi_escape.sub("", text)+++# Test Models+++class SimpleData(StructuredContent):+ """Simple structured content for testing."""++ name: str+ value: int+++class NestedData(StructuredContent):+ """Nested structured content for testing."""++ label: str+ simple: SimpleData+++class DeeplyNestedData(StructuredContent):+ """Deeply nested structure for depth limit testing."""++ level: int+ nested: "DeeplyNestedData | None" = None+++class SomeBaseModel(BaseModel):+ """Simple structured content for testing."""++ name: str+ value: int+++class TestStructuredContentRendering:+ """Test StructuredContent.rendered_pretty()"""++ def test_simple_structured_content(self, capsys: CaptureFixture[str]):+ """Test rendering simple structured content."""+ data = SimpleData(name="test", value=42)+ pretty_print(data.rendered_pretty(title="Simple Data"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ # Should contain table with attribute-value pairs+ assert "Simple Data" in output+ assert "name" in output+ assert "test" in output+ assert "value" in output+ assert "42" in output++ def test_nested_structured_content(self, capsys: CaptureFixture[str]):+ """Test rendering nested structured content."""+ data = NestedData(label="outer", simple=SimpleData(name="inner", value=123))+ pretty_print(data.rendered_pretty(title="Nested Data"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Nested Data" in output+ assert "label" in output+ assert "outer" in output+ assert "simple" in output+ assert "name" in output+ assert "inner" in output+ assert "value" in output+ assert "123" in output++ def test_structured_content_depth_limit(self, capsys: CaptureFixture[str]):+ """Test that deeply nested structures fall back to JSON when depth exceeds limit."""+ # Create a structure that exceeds MAX_RENDER_DEPTH+ excessive_depth = MAX_RENDER_DEPTH + 3+ current = DeeplyNestedData(level=excessive_depth, nested=None)+ for level in range(excessive_depth - 1, 0, -1):+ current = DeeplyNestedData(level=level, nested=current)++ pretty_print(current.rendered_pretty(title="Deep Structure"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ # At max depth, should fall back to JSON rendering (Pretty display)+ # At max depth, should fall back to JSON rendering with syntax highlighting+ # The deepest levels should show as JSON/dict format+ assert "Deep Structure" in output+ # Should contain some level indicators+ assert "level" in output++ def test_base_model(self):+ data = SomeBaseModel(name="test", value=42)+ pretty_print(data)+ pretty = Text(f"{data}")+ pretty_print(pretty)++ def test_structured_content_with_none_values(self, capsys: CaptureFixture[str]):+ """Test that None values are skipped in rendering."""+ data = DeeplyNestedData(level=1, nested=None)+ pretty_print(data.rendered_pretty(title="With None"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "With None" in output+ assert "level" in output+ assert "1" in output+ # "nested" field should not appear since it's None+ # This is implementation detail - None values are skipped++ def test_structured_content_with_list_field(self, capsys: CaptureFixture[str]):+ """Test structured content containing a list field."""++ class DataWithList(StructuredContent):+ name: str+ items: list[str]++ data = DataWithList(name="test", items=["apple", "banana", "cherry"])+ pretty_print(data.rendered_pretty(title="With List"))++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "With List" in output+ assert "name" in output+ assert "test" in output+ assert "items" in output+ assert "apple" in output+ assert "banana" in output+ assert "cherry" in outputdiff --git a/tests/unit/core/stuffs/test_text_and_images_content_rendering.py b/tests/unit/core/stuffs/test_text_and_images_content_rendering.pynew file mode 100644index 000000000..13852e380--- /dev/null+++ b/tests/unit/core/stuffs/test_text_and_images_content_rendering.py@@ -0,0 +1,73 @@+import re++from pytest import CaptureFixture++from pipelex.core.stuffs.image_content import ImageContent+from pipelex.core.stuffs.text_and_images_content import TextAndImagesContent+from pipelex.core.stuffs.text_content import TextContent+from pipelex.tools.misc.pretty import pretty_print+++def remove_ansi_escape_codes(text: str) -> str:+ """Remove ANSI color codes from terminal output."""+ ansi_escape = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")+ return ansi_escape.sub("", text)+++class TestTextAndImagesContentRendering:+ """Test TextAndImagesContent.rendered_pretty()"""++ def test_text_only(self, capsys: CaptureFixture[str]):+ """Test rendering text without images."""+ content = TextAndImagesContent(text=TextContent(text="Hello world"), images=None)+ # Note: title is passed to pretty_print, not rendered_pretty for TextAndImagesContent+ pretty_print(content.rendered_pretty())++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Hello world" in output++ def test_text_and_images(self, capsys: CaptureFixture[str]):+ """Test rendering text with images."""+ content = TextAndImagesContent(+ text=TextContent(text="Document content"),+ images=[+ ImageContent(url="https://example.com/image1.png"),+ ImageContent(url="https://example.com/image2.png", caption="Second image"),+ ],+ )+ pretty_print(content.rendered_pretty())++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "Document content" in output+ assert "Images" in output+ assert "image1.png" in output+ assert "image2.png" in output+ assert "Second image" in output++ def test_images_only(self, capsys: CaptureFixture[str]):+ """Test rendering images without text."""+ content = TextAndImagesContent(+ text=None,+ images=[ImageContent(url="https://example.com/photo.jpg")],+ )+ pretty_print(content.rendered_pretty())++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ assert "photo.jpg" in output++ def test_empty_text_and_images(self, capsys: CaptureFixture[str]):+ """Test rendering empty text and images."""+ content = TextAndImagesContent(text=None, images=None)+ pretty_print(content.rendered_pretty())++ captured = capsys.readouterr()+ output = remove_ansi_escape_codes(captured.out)++ # TextAndImagesContent returns a Text object with "(empty)"+ assert "empty" in output.lower()