Repository navigation
Conversation
…e mode AggressiveFilter decides what is "implementation" by tracking brace depth. Python has no braces, so every line after a `class`/`def` signature closed the body immediately: class-level assignments and decorators were dropped and replaced with a single marker. For ORM-style models that removes the half of the file that defines the model, so an agent re-reads the raw file anyway. Route indentation-scoped languages to a separate walk that keeps imports, signatures, decorators and module/class-level bindings, elides only statements nested inside a function body, and holds multi-line declarations together so the skeleton stays valid syntax. Also derive the elision marker from the language's own comment syntax instead of hard-coding `//`, which was being emitted into Python, Ruby and Shell. Refs rtk-ai#3260
Closing a docstring on either delimiter meant a ''' inside a """ block ended the block early, so the filter lost its place and dropped the code that followed. Track which delimiter opened the string, and carry the enclosing line's keep decision through its continuation lines so a multi-line binding survives whole.
Protocol-zero-0
left a comment
There was a problem hiding this comment.
The new indentation path preserves ordinary class assignments and decorators, but I found two gaps in the class/function skeleton on 95ed02b855c937e441ccc4001fab88b7ba2c3045:
- A normal string containing three single quotes inside a function puts the scanner into a false multiline-string state. The compiled CLI then drops every subsequent function and class in the file. The same input retains those declarations on the PR base, and replacing the literal with
"plain"restores them on this head. - Annotation-only class fields are still removed. For a real
@dataclasswithuser_id: int,payload: str, andenabled: bool = True, the filtered class exposes onlyenabled. This is an existing gap rather than a new base-to-head regression, but it affects the required-field declarations this Python path is intended to preserve.
Both minimal reproductions and suggested regression checks are inline. Please make triple-quote detection aware of surrounding ordinary strings, and recognize annotation-only declarations independently of assignment operators.
Validation: built the exact PR base 8a24ce2e2828117f69ffc31134ed12f36d33fac4 and head; ran 13 valid Python inputs through both binaries at none, minimal, and aggressive (78 CLI executions), including plain-string, multiline declaration/decorator, async-function and genuine triple-string controls. Python 3.14 parsed every input; executing the filtered dataclass confirmed the field loss. All 23 core-filter unit tests, fmt, and warnings-denied clippy passed. Linux only; I did not run the full suite or merge this head onto current develop.
| result.push_str(&elision_marker(lang, body_indent + 4)); | ||
| body_elided = true; | ||
| } | ||
| open_string = unterminated_triple_quote(line).map(|d| (d, false)); |
There was a problem hiding this comment.
[P1] Skip ordinary quoted literals before opening a triple string
unterminated_triple_quote counts ''' inside an ordinary double-quoted string as an opening delimiter. This call records (delim, false) while eliding a function body, so all later declarations are silently consumed as string contents:
def first():
marker = "'''"
return marker
def second():
return 2
class Config:
enabled = TrueWith the compiled head, rtk read -l aggressive example.py emits only:
def first():
# ... implementationThe compiled PR base retains second and Config (its CLI falls back to raw for this fixture). On this head, changing "'''" to "plain" also restores both declarations. Please skip complete ordinary string literals and escapes before recognizing a triple-string opener, and add a regression asserting both later declarations survive. The same delimiter inside a kept module assignment instead makes subsequent function bodies leak through.
| || IMPORT_PATTERN.is_match(trimmed) | ||
| || PY_CLASS.is_match(trimmed) | ||
| || trimmed.starts_with('@') | ||
| || is_assignment(trimmed); |
There was a problem hiding this comment.
[P2] Keep annotation-only class fields as declarations
The new path only recognizes these fields through is_assignment, which requires =. Required dataclass/Pydantic fields commonly have no default:
from dataclasses import dataclass
@dataclass
class Request:
user_id: int
payload: str
enabled: bool = TrueThe compiled head's rtk read -l aggressive example.py keeps the decorator and class, but only enabled: bool = True remains in its body. Executing that filtered dataclass gives dataclasses.fields(Request) == ['enabled'] by name, versus ['user_id', 'payload', 'enabled'] for the input. The required schema is therefore missing even though the optional field survives.
This omission also exists on the PR base; it is an incomplete declaration-preservation case rather than a new regression. Please recognize a simple annotated binding without = and pin a regression that keeps both required fields while still eliding method bodies.
Summary
rtk read -l aggressivedrops class-level assignments and decorators from Python files.AggressiveFilterdecides what counts as an implementation body by tracking brace depth. Python has no braces, so after aclassordefsignaturebrace_depthis already 0 and the very next line closes the body and emits a marker. The only fallthrough that keeps declarations matchesconst/static/let, none of which are Python.For ORM-style models the field declarations are the model, so the output describes nothing and the agent re-reads the raw file anyway.
Before:
After:
What changed:
Language::is_indentation_based()routes Python to a walk that scopes bodies by indentation instead of braces. Ruby and Shell are block-delimited (end,fi), not indentation-scoped, so they stay on the existing path.class/defsignatures, decorators and every module- or class-level binding, and elides only statements nested inside a function body.lang.comment_patterns().lineinstead of a hard-coded//. A C-style marker inside Python, Ruby or Shell violated the Transparency rule that filtered output must read as a shorter version of the real file.No change to
noneorminimal, no change to brace-language behaviour beyond the marker character, no new dependency.Measured on real files with the release-profile binary:
json/decoder.py(3.14 stdlib)argparse.py(3.14 stdlib)A field-heavy ORM model lands lower (roughly 40%) because the declarations are exactly what has to be kept. That is the intended trade: the previous 4.2% average came with output that was not usable.
Test plan
cargo fmt --all -- --check,cargo clippy --all-targetsandcargo test --allare green locally (2522 unit tests, 0 failures).bash scripts/check-test-presence.sh origin/developpasses.Ten unit tests added in
src/core/filter.rs:#for Python and stays//for Rustis_assignmentaccepts_inherit = "...",total: int = 0,count += 1and rejectsif x == "draft":,assert a != b,check(threshold=3)bracket_deltaignores brackets inside string literals and trailing commentsScope
This is the Python half of #3260. The issue also asks for a structural XML level, which is a new capability rather than a bug fix, so per the single-purpose PR rule in CONTRIBUTING I have left it for a follow-up rather than growing this diff. Happy to open that separately if you want it.
Refs #3260
🤖 Opened with Superhuman, an open-source contribution agent.