From 53c8a6fd806442a6643c77d59edd242cc880666c Mon Sep 17 00:00:00 2001 From: Felippe Roza <4269853+FelippeRoza@users.noreply.github.com> Date: Wed, 19 Aug 2026 10:30:30 +0200 Subject: [PATCH] fix(agent_sdk): make generated Express parser reproducible The build hook passed ANTLR an absolute path to Express.g4, and ANTLR writes its input path into the header of every generated file. The committed output therefore carried the absolute path of whichever machine last regenerated it, so any from-source build left express_lexer.py, express_parser.py and express_visitor.py modified with a header-only diff. Invoke ANTLR from the grammar's own directory with a bare filename, which keeps the output flat and makes the header independent of checkout location. Regenerates the three committed files accordingly. Also documents that a JDK is required to build from source, since the ANTLR step needs one and that was not written down anywhere. --- agent_sdks/python/a2ui_agent/CHANGELOG.md | 3 +++ agent_sdks/python/a2ui_agent/README.md | 4 ++++ agent_sdks/python/a2ui_agent/pack_specs_hook.py | 8 ++++---- .../experimental/express/generated/express_lexer.py | 2 +- .../experimental/express/generated/express_parser.py | 2 +- .../experimental/express/generated/express_visitor.py | 3 +-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/agent_sdks/python/a2ui_agent/CHANGELOG.md b/agent_sdks/python/a2ui_agent/CHANGELOG.md index 3f227bdc9f..67814d2cd6 100644 --- a/agent_sdks/python/a2ui_agent/CHANGELOG.md +++ b/agent_sdks/python/a2ui_agent/CHANGELOG.md @@ -1,5 +1,8 @@ ## Unreleased +- Invoke ANTLR from the grammar's directory when regenerating the Express parser, so generated file headers no longer embed the absolute path of the machine that built them. +- Stop rewriting the non-package fallback import in the generated Express visitor to a relative import, which pointed at a module name the rename step had already replaced. A from-source build now leaves the working tree clean. + ## 0.5.0 - Rename inference format `Transport` / `transport` terminology to `Direct JSON` / `direct_json` (`DirectJsonFormat`, `DirectJsonParser`, `DirectJsonStreamParser`). Deprecate `a2ui.inference_formats.transport` module alias. diff --git a/agent_sdks/python/a2ui_agent/README.md b/agent_sdks/python/a2ui_agent/README.md index e18deb7db0..708bf3bf1a 100644 --- a/agent_sdks/python/a2ui_agent/README.md +++ b/agent_sdks/python/a2ui_agent/README.md @@ -59,6 +59,10 @@ protocol. ## Building the SDK +Building from source regenerates the Express parser from +`specification/inference_formats/express/Express.g4`. That step runs ANTLR, which +requires a Java runtime (JRE 11 or newer) on the `PATH`. + To build the SDK, run the following command from the `agent_sdks/python/a2ui_agent` directory: diff --git a/agent_sdks/python/a2ui_agent/pack_specs_hook.py b/agent_sdks/python/a2ui_agent/pack_specs_hook.py index 57673dfbc9..09730e0c7c 100644 --- a/agent_sdks/python/a2ui_agent/pack_specs_hook.py +++ b/agent_sdks/python/a2ui_agent/pack_specs_hook.py @@ -132,15 +132,15 @@ def initialize(self, version, build_data): "-visitor", "-no-listener", "-o", - "generated", - g4_path, + os.path.abspath(generated_dir), + os.path.basename(g4_path), ] env = os.environ.copy() env["ANTLR4_TOOLS_ANTLR_VERSION"] = "4.13.2" res = subprocess.run( cmd, - cwd=express_dir, + cwd=os.path.dirname(g4_path), env=env, capture_output=True, text=True, @@ -190,7 +190,7 @@ def initialize(self, version, build_data): "from .ExpressParser import", "from .express_parser import" ) content = content.replace( - "from ExpressParser import", "from .express_parser import" + "from ExpressParser import", "from express_parser import" ) with open(visitor_path, "w", encoding="utf-8") as f: f.write(content) diff --git a/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_lexer.py b/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_lexer.py index 2696a12b7e..f35fe0070b 100644 --- a/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_lexer.py +++ b/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_lexer.py @@ -1,4 +1,4 @@ -# Generated from /usr/local/google/home/gspencer/code/a2ui/kotlin_express/specification/inference_formats/express/Express.g4 by ANTLR 4.13.2 +# Generated from Express.g4 by ANTLR 4.13.2 from antlr4 import * from io import StringIO import sys diff --git a/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_parser.py b/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_parser.py index cb929c782c..827a9d28b7 100644 --- a/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_parser.py +++ b/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_parser.py @@ -1,4 +1,4 @@ -# Generated from /usr/local/google/home/gspencer/code/a2ui/kotlin_express/specification/inference_formats/express/Express.g4 by ANTLR 4.13.2 +# Generated from Express.g4 by ANTLR 4.13.2 # encoding: utf-8 from antlr4 import * from io import StringIO diff --git a/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_visitor.py b/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_visitor.py index 9bd827cec7..6f29f2da66 100644 --- a/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_visitor.py +++ b/agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/express/generated/express_visitor.py @@ -1,11 +1,10 @@ -# Generated from /usr/local/google/home/gspencer/code/a2ui/kotlin_express/specification/inference_formats/express/Express.g4 by ANTLR 4.13.2 +# Generated from Express.g4 by ANTLR 4.13.2 from antlr4 import * if "." in __name__: from .express_parser import ExpressParser else: from express_parser import ExpressParser - # This class defines a complete generic visitor for a parse tree produced by ExpressParser. class ExpressVisitor(ParseTreeVisitor):