Clean-Room Reimplementation of Mobile Apps: A Low-Cost Practical Guide

    This guide explains how to use an AI agent to reimplement a mobile app through clean-room observation of its public UI and interactions. It covers fidelity grading from L0 to L3, connecting a physical device over standard debugging channels, dual-channel parsing of UI hierarchy and screenshots, structured specification tables, layered client-server rebuilding with asynchronous task APIs, same-device acceptance testing, common pitfalls, and packaging the workflow into a reusable skill package. The original practice completed the work in about 7 hours at a model-call cost of roughly 21 RMB.

    1. Background: Why Rebuilding an App Is More Controllable Than It Seems

    As AI coding tools and large language model (LLM) agents advance quickly, developers often ask whether an agent can take over a physical device, observe an app’s public interface and interaction results, and then rebuild a functionally equivalent product from scratch. In the original practice, the author completed the interface and interaction reimplementation of an AI product with image generation, video generation, video editing, and duration extension capabilities in about 7 hours, at a model-call cost of roughly 21 RMB. The result was packaged into a reusable skill package and an engineering skeleton ready for further development.

    A boundary needs to be clarified first: the “reimplementation” discussed here is not decompilation and not packet capture of private protocols. It is clean-room reimplementation—observing only publicly visible interfaces, control structures, and observable results after interactions, without touching any non-public implementation details, and writing all code from scratch. This is both a technical route choice and a compliance baseline.

    Three reasons explain why the cost can be pushed so low:

    • Observation costs far less than reading: Screenshots and control trees are highly structured inputs, consuming far fewer tokens than reading decompiled output or a large source codebase.
    • Tasks are decomposable and cacheable: Splitting a long task into per-screen observation, spec tabulation, module-by-module rebuilding, and same-device verification lets intermediate artifacts be saved and reused, avoiding repeated reasoning.
    • The acceptance loop is well defined: Using same-device comparison against the original as the sole criterion reduces wasted rework.

    2. Step 1: Grade Fidelity First and Define What “Done” Means

    Most reimplementation projects fail not because the code cannot be written, but because “how close is close enough” was never defined at the start. Before starting, split the goal into six levels and lock the default at L3:

    Level Meaning Acceptance Criterion
    L0 Similar information architecture only Page hierarchy and navigation structure match
    L1 Static visual similarity Colors, font sizes, corner radii, and spacing are close
    L2 Interactions work end to end Key paths are clickable and navigable
    L3 Consistent results (default) Real model calls produce comparable output
    L4 Consistent boundaries and exceptions Empty, failure, and permission states match
    L5 Consistent performance and experience Startup time and list smoothness are close

    The key principle: L3 rejects static fake data. If a key path returns hardcoded placeholder content, “looking similar” is worthless. The grading table should be written into the project documentation as the basis for all later trade-offs.

    3. Step 2: Connect Directly to a Physical Device So the Agent Has “Eyes” and “Hands”

    No extra reverse-engineering framework is needed. A standard debugging channel plus terminal access forms the minimum loop:

    1. Enable developer options and the debugging switch on the phone, then connect it to the workstation via a data cable.
    2. The agent runs standard debugging commands through the terminal to gain three capabilities:
      • See structure: Dump the control hierarchy and coordinates of the current screen (view hierarchy dump).
      • See appearance: Capture screenshots to extract colors, corner radii, font sizes, and whitespace.
      • Perform actions: Simulate taps, swipes, text input, and back navigation.

    An illustrative operation sequence (pseudocode, expressing flow only):

    1. connect_device()
    2. for screen in screens:
    3. dump_ui_hierarchy(screen) # control tree + coordinates
    4. capture_screenshot(screen) # visual baseline
    5. tap(center_of(node)) # single-step interaction
    6. observe_state_delta() # record state changes

    Three engineering points are mandatory: first, the single-step principle—perform one action at a time and then observe, avoiding state drift that leads to misjudgment; second, baseline archiving—save screenshots and control trees by “screen ID + timestamp”; third, prefer reversible operations—explore paths involving submission, payment, or deletion only under test accounts.

    4. Step 3: Parse Through Two Channels: Semantic Tree and Screenshots

    The control tree provides the “skeleton” and the screenshot provides the “skin.” The two must be aligned to the same coordinate system to produce usable specs.

    • Structure channel: Extract clickable nodes, text nodes, input fields, and list items from the control tree, recording each one’s unique identifier, hierarchy path, and bounding coordinates to form an “interactive element inventory.”
    • Visual channel: Sample primary and secondary colors from screenshots, measure corner radii, estimate font size hierarchy (heading/body/auxiliary text), and count spacing rhythm and grid columns.
    • Alignment rule: Use control bounding boxes as anchors and attach visual attributes to structure nodes. For purely drawn areas with no corresponding control, mark them separately as “custom-drawn blocks” and fill them in later with native drawing capabilities.

    The output of this step is not code but a structured intermediate representation, which is the key to controlling cost: once the intermediate representation stabilizes, rebuilding can proceed in parallel by module and support incremental changes without re-observation.

    5. Step 4: Turn Observations into an Executable Spec Sheet

    Produce two tables as the sole input for rebuilding:

    Per-Screen UI Difference Table (example structure)

    Screen Element Target Attribute Current Implementation Difference Priority
    Home Primary action button Saturated primary color, full width, radius 12 Default button Color/radius mismatch P0
    Project page Card list Two-column grid, spacing 8 Single column Layout mismatch P1

    Behavior Audit Table (example structure)

    Trigger Precondition Result State Failure Branch Idempotent
    Tap Generate Prompt entered Enters task queue and shows progress Insufficient quota message No
    Extend video A completed clip exists Appends duration and keeps original ownership Duration limit exceeded message No

    The value of the behavior audit table is making implicit business rules explicit, such as multi-version retention, original ownership, and retryable failures. These often affect usability more than visual details do.

    6. Step 5: Rebuild in Layers Across Client and Server

    A clear two-layer structure is recommended, avoiding hardcoding business logic into the UI layer:

    • Client (native layer): Responsible for interface restoration, interaction orchestration, local state, and task progress display. Describe the UI declaratively and centralize visual constants to make batch alignment of palettes and spacing easier.
    • Server (capability layer): Responsible for authentication, task orchestration, quotas, asynchronous queues, result storage, and callback notifications. Generation tasks have unstable durations and must be implemented as asynchronous tasks with status polling or callbacks; never wait synchronously on the client.

    An illustrative task API (pseudocode, not any real API):

    1. POST /tasks { type, params } -> { task_id }
    2. GET /tasks/{id} -> { status, progress, result_ref }
    3. POST /tasks/{id}/cancel

    Supporting engineering conventions:

    1. Externalized configuration: Model endpoints, timeouts, retry counts, and concurrency limits all go through configuration.
    2. Observability: Structured logs plus metrics plus alerts; task failure rate and end-to-end latency must be visible.
    3. Layered storage: Metadata in relational storage, large files in object storage, long-running tasks decoupled through a message queue.
    4. Cost control: Set budget caps and degradation strategies per task type to prevent uncontrolled consumption while the agent debugs.

    7. Step 6: Same-Device Acceptance Using One Device for Comparison

    Acceptance must be performed on the same physical device and the same network environment, comparing screenshots and control trees screen by screen to form a difference list and regression pass:

    • Visual layer: color deviation, font size hierarchy, corner radii and shadows, dark mode adaptation.
    • Interaction layer: navigation paths, back stack behavior, keyboard show/hide, rotation and split screen.
    • Result layer: real capability calls, comparing output type, duration, resolution, and multi-version management against expectations.
    • Exception layer: whether weak network, timeout, exhausted quota, and permission denial all produce clear feedback.

    After acceptance passes, do one round of “de-branding” cleanup to ensure the output is an independent implementation with no residual third-party identifiers, assets, or traces of private protocols.

    8. Common Pitfalls and How to Avoid Them

    • Multiple actions in one step: Causes state confusion; strictly follow single step plus observation.
    • Looking only at screenshots, not structure: The visuals are restored but taps do nothing; the two channels must be aligned.
    • Passing acceptance with fake data: Looks good short term, unusable long term; forbidden from L3 onward.
    • Ignoring asynchronous semantics: Writing long-running tasks as synchronous calls inevitably freezes the UI.
    • No budget guardrails: Agent debug loops keep consuming; set call limits and timeouts.
    • Not persisting intermediate artifacts: Repeated observation doubles cost; spec tables and screenshots must be versioned.

    9. Distilling the Flow into a Reusable Skill Package

    Solidify the above flow into a skill package whose input is “target app package name + target fidelity level” and whose output is the spec sheet, engineering skeleton, and acceptance report. The package should include a grading template, observation scripts, parsing rules, a difference table template, a code scaffold, and an acceptance checklist. The next project then only needs to swap the input, with the main flow unchanged, so marginal cost drops significantly.

    On the deployment side, if you need to serve externally, you can use a container platform to host stateless services, object storage to hold generated results, a message queue for peak shaving, and logging plus monitoring alerts for observability. These are common industry capability combinations, independent of any specific vendor.

    10. Conclusion

    The essence of low-cost reimplementation is not finding some “magic tool” but turning vague requirements into an engineering process that is gradeable, observable, tabulatable, and acceptable. Once observation is structured, rules are made explicit, and acceptance is done on the same device, the agent’s reasoning cost drops sharply and output quality becomes more stable. For teams that want to quickly validate a product shape, build an interaction baseline comparison, or build a similar generative app, this clean-room method is worth adding to the toolbox. At the same time, always hold the compliance line: implement independently based only on public information, and never reuse non-public code or private protocols.