agentleFS
JetBrainsKnown publisherJetBrains/android/designer/AGENTS.md

android / designer

AGENTS.md1.1k starsChanged 3 months agoApache-2.0View on GitHub

This document describes how an AI agent can interact with the Layout Editor (Designer).

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository2 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use NlWriteCommandActionUtil.run() to perform atomic updates.

    line 9
  2. Very specific:

    Attributes: Use NlComponent.setAttribute() for simple changes.

    line 23
  3. Very specific:

    Clean-up: Always call backend.reformatAndRearrange() after significant XML edits to maintain file style and consistent indentation.

    line 25
  4. Distinctive:

    Use Bazel for the core designer tests:

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Designer Agent Guide

This document describes how an AI agent can interact with the Layout Editor (Designer).

Key Entry Points

1. Structural Changes and Undo

Structural changes to the layout (adding/removing/reordering components) MUST be wrapped in an NlWriteCommandAction.

  • Use NlWriteCommandActionUtil.run() to perform atomic updates.
  • Example:
    NlWriteCommandActionUtil.run(component, "Add Widget", () -> {
        model.addComponent(newComponent, parent, null);
    });

2. Scene vs Model

  • NlModel: Represents the "Source of Truth" (the XML). Use this for data-driven changes (attributes, hierarchy).
  • Scene: Represents the "Interaction Layer". Use SceneManager to calculate layout positions or handle constraints without touching the XML immediately.
  • NlComponentBackend: (NlComponentBackend.kt) Agents should use the backend to perform low-level XML operations. NlComponent.tag provides the underlying XmlTag.

3. View Modification

  • Attributes: Use NlComponent.setAttribute() for simple changes. This maintains the internal cache.
  • Transactions: For multiple attribute changes, use AttributesTransaction (AttributesTransaction.java) to batch PSI events and improve performance.
  • Clean-up: Always call backend.reformatAndRearrange() after significant XML edits to maintain file style and consistent indentation.

Interaction Handling

  • InteractionHandler: (InteractionHandler.java) The entry point for mouse/keyboard events. Agents can simulate user input by invoking createInteractionOn() for specific ViewHandlers.

Important Considerations for Agents

  • Dumb Mode: Many operations (like finding a View's handler based on its FQN) require indices. Check DumbService.isDumb(project) before performing actions that depend on symbol resolution.
  • Asynchronous Rendering: Previews are rendered in-process using Layoutlib. Use RenderService.getLastRenderResult() to check if the current view is up-to-date. If renderResult.isValid() returns false, the image may be stale.

Examples and Testing

  • Integration Tests: com.android.tools.idea.uibuilder.surface.NlDesignSurfaceTest shows how to mock user interactions (clicks, drags) on the surface.
  • Constraint Layout: com.android.tools.idea.uibuilder.handlers.constraint.ConstraintLayoutHandlerTest demonstrates how to test complex auto-connect logic.

How to run tests

Use Bazel for the core designer tests:

bazel test //tools/adt/idea/designer:intellij.android.designer_tests

Related Documentation

  • Layout Editor Architecture

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.