The compare_tools.py module#
Summary#
Return a new ephemeral PyFluent backend for file comparison. |
|
Read a deterministic slice of session state for diffing. |
|
Recursively diff two snapshot dictionaries. |
|
Render a diff value compactly for table cells. |
|
Split a diff path into |
|
Render a hierarchical markdown summary of a diff list. |
|
Compare two Fluent case/mesh files in ephemeral PyFluent sessions. |
Description#
Shared, stateless implementation for the compare_files tool.
This module owns the pure-domain pieces of the compare_files tool:
An ephemeral PyFluent backend factory
A deterministic snapshot collection over the
BackendcontractA recursive dictionary diff with stable named-object handling
Compact rendering helpers used by the markdown summary
The leaf-side DomainTool entry point is
compare_files_impl(). The agent’s in-process handler delegates
to the same coroutine so both surfaces share one source of truth.
There is no state parameter and no reference to LoopState
on purpose. By the time this module is reached, all path validation
and same-file checks have already passed in compare_files_impl()
itself, using only the public ansys.fluent.mcp.common.file_handlers
registry. The handler spawns its own ephemeral sessions so the live
workspace (if any) is never touched.
Module detail#
- compare_tools.ephemeral_pyfluent_backend(label: str = 'PyFluent (compare)') ansys.fluent.mcp.common.backend.Backend#
Return a new ephemeral PyFluent backend for file comparison.
Lazy-imported so the test suite (which monkey-patches this symbol) does not need PyFluent installed. The
labelflows into PyFluent log lines so each ephemeral session is identifiable per file in compare output.- Parameters:
- label
str Label to supply to the function.
- label
- Returns:
BackendResult produced by the function.
- async compare_tools.collect_compare_snapshot(backend: ansys.fluent.mcp.common.backend.Backend) dict[str, Any]#
Read a deterministic slice of session state for diffing.
Combines the global-state slice (energy, viscous, solver, methods, operating conditions) with named-object name lists per family. Returns a dictionary shaped like this:
{"global": {<path>: <state-or-marker>}, "named": {<family>: [<names>]}}
- compare_tools.diff_snapshots(a: dict[str, Any], b: dict[str, Any], *, prefix: str = '') list[dict[str, Any]]#
Recursively diff two snapshot dictionaries.
Emits one record per leaf-level difference with shape:
{"path": "global.setup/models/energy.enabled", "change": "changed" | "only_in_a" | "only_in_b", "a": <value or None>, "b": <value or None>}
- compare_tools.shorten_value(v: Any, *, limit: int = 80) str#
Render a diff value compactly for table cells.
Lists are rendered as comma-separated values rather than
reprso a list of named-object names reads naturally in the summary.
- compare_tools.split_diff_path(path: str) tuple[str, str]#
Split a diff path into
(section, leaf)for hierarchical rendering.Strips the leading
global./named.scope and splits trailing[name]brackets or.fieldsuffixes off as the leaf. The section is shown as a heading. The leaf is the table row name.
- compare_tools.format_compare_summary(diffs: list[dict[str, Any]], *, name_a: str, name_b: str) str#
Render a hierarchical markdown summary of a diff list.
Groups rows by their parent path (rendered as a section heading with
/separators) and emits one table per section with columns:Setting |. The change kind is implicit:| —in either column means “not present in that file”.
- async compare_tools.compare_files_impl(backend: ansys.fluent.mcp.common.backend.Backend, *, path_a: str, path_b: str) dict[str, Any]#
Compare two Fluent case/mesh files in ephemeral PyFluent sessions.
Open two Fluent case/mesh files in two SEPARATE ephemeral PyFluent sessions and summarize the differences between them.
Both sessions are launched headless (no GUI) and the cases are read with
lightweight_setup=Truefor speed. The live workspace session, if any, is NOT touched. Returns a structured diff of global model state and per-family named-object name lists plus a pre-rendered markdown summary in thesummaryfield.The
backendargument from the leaf framework is intentionally unused. The tool spawns its own ephemeral backends per file so that the diff is reproducible regardless of whether a live session is attached.