From fcfb076723f8336b9f70228172401cc8dda6a678 Mon Sep 17 00:00:00 2001 From: Atelier-Nocte Date: Mon, 13 Jul 2026 03:01:04 +1000 Subject: [PATCH] Add --cxml flag: write the LLM view straight to a file or stdout The CXML payload already exists (generate_cxml_text) but was only reachable by opening the HTML page and copying the textarea. --cxml emits it directly for scripting/pipelines; default HTML behavior is unchanged. Co-Authored-By: Claude Fable 5 --- rendergit.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/rendergit.py b/rendergit.py index 03e05f5..71bd4c8 100644 --- a/rendergit.py +++ b/rendergit.py @@ -476,10 +476,13 @@ def main() -> int: ap.add_argument("-o", "--out", help="Output HTML file path (default: temporary file derived from repo name)") ap.add_argument("--max-bytes", type=int, default=MAX_DEFAULT_BYTES, help="Max file size to render (bytes); larger files are listed but skipped") ap.add_argument("--no-open", action="store_true", help="Don't open the HTML file in browser after generation") + ap.add_argument("--cxml", nargs="?", const="-", metavar="PATH", + help="Emit CXML (LLM view) instead of HTML. PATH, or '-'/omitted for stdout. " + "Never builds or opens HTML — safe for untrusted repos.") args = ap.parse_args() - # Set default output path if not provided - if args.out is None: + # Set default output path if not provided (HTML mode only) + if args.out is None and args.cxml is None: args.out = str(derive_temp_output_path(args.repo_url)) tmpdir = tempfile.mkdtemp(prefix="flatten_repo_") @@ -497,6 +500,22 @@ def main() -> int: skipped_count = len(infos) - rendered_count print(f"✓ Found {len(infos)} files total ({rendered_count} will be rendered, {skipped_count} skipped)", file=sys.stderr) + if args.cxml is not None: + cxml_out = generate_cxml_text(infos, repo_dir) + if args.cxml == "-": + # Windows consoles default to cp1252; repo text routinely contains + # emoji/box-drawing, which would raise UnicodeEncodeError mid-pipe. + try: + sys.stdout.reconfigure(encoding="utf-8", errors="replace") + except Exception: + pass + sys.stdout.write(cxml_out) + else: + cxml_path = pathlib.Path(args.cxml) + cxml_path.write_text(cxml_out, encoding="utf-8") + print(f"✓ Wrote {bytes_human(len(cxml_out.encode('utf-8')))} of CXML to {cxml_path}", file=sys.stderr) + return 0 # temp dir still cleaned by the enclosing finally: + print(f"🔨 Generating HTML...", file=sys.stderr) html_out = build_html(args.repo_url, repo_dir, head, infos)