Skip to content

feat(python): summarize large direct invocations - #3096

Open
lntutor wants to merge 1 commit into
rtk-ai:developfrom
lntutor:feat/2312-python-proxy
Open

lntutor wants to merge 1 commit into
rtk-ai:developfrom
lntutor:feat/2312-python-proxy

Conversation

@lntutor

@lntutor lntutor commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add rtk python / rtk py routing for direct python and python3 invocations
  • preserve the original interpreter and keep interactive, debugger, help, and version modes as passthroughs
  • retain exact output up to 1 KiB, then apply the existing heuristic summary with full-output recovery
  • keep failures verbatim and preserve their exit codes
  • retain specialized pytest and mypy module routing

Verification

  • cargo test --all-targets --all-features
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --check
  • git diff --check
  • compiled CLI smoke tests for short, large, version, and exit-7 failure paths

Closes #2312

@CLAassistant

CLAassistant commented Jul 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lntutor
lntutor force-pushed the feat/2312-python-proxy branch from 71459b5 to 0f4b8ab Compare July 31, 2026 00:12
@lntutor
lntutor force-pushed the feat/2312-python-proxy branch from 0f4b8ab to 44cf0ea Compare July 31, 2026 00:47

@Protocol-zero-0 Protocol-zero-0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently tested 44cf0ea against base 8a24ce2 using real Python 3.14.7. Three behavior changes need attention before the automatic rewrite is safe:

  • python3 -h and python3 --help rewrite to this command but print RTK's Python-subcommand help; Python's own option help never runs.
  • Successful output below 1 KiB is not preserved exactly. python3 -c "import sys; sys.stdout.write('OK')" changes b'OK' to b'OK\n'; python3 -c pass gains a newline. A successful script writing result\n to stdout and warning\n to stderr instead emits both on stdout and leaves stderr empty.
  • python3 -v -c "print('OK')" explicitly requests interpreter import diagnostics, but the proxy summarizes them once they exceed 1 KiB. The native/base run retains the full diagnostics on stderr; head reduces them to a summary/recovery hint on stdout. Please preserve Python's requested verbose modes, including combined short-option forms.

The checks cover 20 scenarios / 60 native-base-head CLI executions: small/large output, both streams, exit 7, help/version, verbose and interactive modes, stdin, script arguments, and interpreter identity. Base leaves these generic invocations unchanged. Large successful output is summarized with a recovery file whose contents match raw output exactly; the tested failure exits and output are preserved. Eight focused unit/routing/CLI tests, fmt, and warnings-denied clippy pass. Linux only; no full suite, Windows, or current-develop integration run. AI-assisted independent review.

Comment thread src/main.rs
},

/// Python with large-output summarization
#[command(visible_alias = "py")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Let native Python help reach the interpreter

The new rewrite sends python3 -h / python3 --help here, but Clap handles both flags before should_passthrough can run. On this head, rtk python --executable python3 -h prints Python with large-output summarization and RTK options instead of Python's usage/options; base leaves the native command unchanged. Disable the generated help flag for this subcommand (or otherwise forward native help) and add a compiled-CLI regression for both spellings.

eprintln!("Running: {}", command_label.trim_end());
}

runner::run_filtered(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve successful small output bytes and stream identity

This captured runner merges stdout/stderr and normally prints a trailing newline, so the advertised exact-output path below 1 KiB is already lossy. Real Python controls: -c pass changes empty stdout into b'\n'; -c "import sys; sys.stdout.write('OK')" changes b'OK' into b'OK\n'; and a successful script writing a result to stdout plus a warning to stderr moves the warning onto stdout. Keep both captured streams and their original bytes for the small-output branch, with process-level regressions; the existing string-only test cannot detect these changes.

return true;
}

if args.iter().any(|arg| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve explicitly requested Python verbose diagnostics

Python's -v is not an ordinary output-producing script mode: it explicitly requests import diagnostics. python3 -v -c "print('OK')" produces full diagnostics on stderr natively, while this head summarizes them and moves the result to stdout once the output exceeds 1 KiB. That hides the import/search-path detail being requested. Treat interpreter verbose forms (-v, -vv, and combined short options) as passthrough, parsing only interpreter options so an unrelated script argument is not mistaken for an interpreter flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk should proxy generic python3 / python (58 unhandled calls/30d)

3 participants