Skip to content
Open
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
23 changes: 21 additions & 2 deletions rendergit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_")
Expand All @@ -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)

Expand Down