Metadata-Version: 2.5
Name: droidlock
Version: 0.3.0
Summary: Lease shared devices and emulators to parallel coding agents on one machine.
Project-URL: Homepage, https://github.com/arodriguezvaz/droidlock
Project-URL: Repository, https://github.com/arodriguezvaz/droidlock
Project-URL: Documentation, https://github.com/arodriguezvaz/droidlock/blob/main/docs/PROJECTS.md
Project-URL: Changelog, https://github.com/arodriguezvaz/droidlock/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/arodriguezvaz/droidlock/issues
Author: Andrés Rodríguez Vázquez
Maintainer: Andrés Rodríguez Vázquez
License: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: android,cli,coding-agent,device,emulator,lease,worktree
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# droidlock

**Multi-agent Android emulator & device lease manager: one Android emulator per agent session, for any coding agent, without agents fighting over `adb` or Gradle.**

[![CI](https://github.com/arodriguezvaz/droidlock/actions/workflows/ci.yml/badge.svg)](https://github.com/arodriguezvaz/droidlock/actions/workflows/ci.yml)
[![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)

## Why

When multiple coding agents or parallel sessions run Android builds and tests on the same machine, they collide over `adb`, install conflicting APKs on the same emulator, or kill each other's AVDs.

`droidlock` solves this for parallel sessions and cross-agent work:
- **Session-level isolation** across parallel sessions of the same agent or different agents running side by side.
- A **universal `adb` shim** (`~/.local/bin/adb`) that detects the active agent session when the agent exposes a recognized session variable, acquires or adopts its lease, and delegates to the `droidlock` `adb` guard.
- **Native plugins & hooks** for OpenCode and Antigravity (covering `./gradlew` device tasks, Maestro, Flutter, React Native, Expo, and automatic lease release on turn end).
- **Agent skills (`SKILL.md`)** for 10 popular coding agents, plus native plugins for OpenCode and Antigravity, and `droidlock run` for any other agent or custom workflow.
- An **interactive installer** that auto-detects which agents you have installed and lets you pick which ones to configure.

## Supported Agents

`droidlock` includes built-in auto-detection and tailored integration for 12 popular agents. The universal `adb` shim is installed for every agent; it auto-acquires leases for recognized sessions, and any other agent or script can use `droidlock run`:

| Agent | Auto-detected via | What `droidlock` installs |
|---|---|---|
| **Claude Code** | `~/.claude` / `claude` | `SKILL.md` (uses `CLAUDE_CODE_SESSION_ID` / `CLAUDE_PID`) + universal `adb` shim |
| **Cursor** | `~/.cursor` / `cursor` | `SKILL.md` + universal `adb` shim |
| **Codex CLI** | `~/.codex` / `codex` | `SKILL.md` (uses `CODEX_SESSION_ID`) + universal `adb` shim |
| **OpenCode** | `~/.config/opencode` / `opencode` | TypeScript plugin + universal `adb` shim |
| **Hermes Agent** | `~/.hermes` / `hermes` | `SKILL.md` + universal `adb` shim |
| **Gemini CLI** | `~/.gemini` / `gemini` | `SKILL.md` + universal `adb` shim |
| **Antigravity** | `~/.gemini/config` / `agy` | Native plugin (`plugin.json`, `hooks.json`, `hook.py`, `SKILL.md`) + universal `adb` shim |
| **Kiro** | `~/.kiro` / `kiro` | `SKILL.md` + universal `adb` shim |
| **VS Code (Copilot Chat)** | `~/.vscode` / `code` | `SKILL.md` (`~/.copilot/skills/droidlock/SKILL.md`) + universal `adb` shim |
| **GitHub Copilot CLI** | `~/.copilot` / `copilot` | `SKILL.md` + universal `adb` shim |
| **JetBrains IDEs (Copilot)** | `~/.config/JetBrains` / `~/.config/github-copilot` | `SKILL.md` + universal `adb` shim |
| **Pi** | `~/.pi/agent` / `pi` | `SKILL.md` + universal `adb` shim |
| **Any other agent** | Universal `adb` shim / CLI | Shim installed; use `droidlock run` for device work |

See [docs/agents.md](docs/agents.md) for full details per agent and how to use `droidlock` with any other agent.

## Install

Requirements: Linux or macOS, Python 3.11+ (standard library only, zero external dependencies), and the Android SDK (`platform-tools`, `emulator`) with at least one AVD.

```sh
# Interactive installer (detects installed agents and lets you toggle them):
./install.sh

# Non-interactive options:
./install.sh --dry-run                       # preview what would change
./install.sh --yes                           # install for all detected agents
./install.sh --agents opencode,antigravity,pi --yes
./install.sh --agents all --yes
```

Then allow your AVDs and verify the setup from a normal user terminal:

```sh
droidlock admin discover --all --yes          # or ./install.sh --yes --discover
droidlock admin doctor
```

> Run `droidlock admin` from your own terminal: agent hooks/permissions intentionally block agents from running admin commands.

## How it works

```text
Agent session A ── adb ... ────────> universal adb shim ──> droidlock lease + adb guard ──> emulator-5554
                └─ ./gradlew ... ──> plugin / hook ───────> ANDROID_SERIAL + lease ──────> Gradle guard

Agent session B ── adb ... ────────> universal adb shim ──> "held by session A" (refused)
```

- **Lease**: an exclusive, temporary reservation for one AVD (owner, agent, session, serial, expiry).
- **Universal `adb` shim**: detects the active agent session when the agent exposes a recognized session variable, adopts or acquires a lease, and delegates to the `droidlock` `adb` wrapper. Outside a recognized session it delegates to the wrapper without acquiring a lease.
- **Plugins & hooks**: rewrite Gradle / Maestro / Flutter device commands with `DROIDLOCK_LEASE` and `ANDROID_SERIAL`, block `adb emu kill` / `adb kill-server` / `droidlock admin`, and release the lease on idle/stop without stopping the AVD.
- **Any agent via CLI**: any agent or script can also wrap commands explicitly with `droidlock run --where kind=emulator -- <command>`.

## Limits

This is a guardrail, not a sandbox: absolute-path `adb`, Android Studio's own deploy, and tools that talk to the `adb` server directly bypass it. See [docs/limits.md](docs/limits.md).

## Documentation

- [docs/agents.md](docs/agents.md) — supported agents matrix, paths, per-agent behavior, and using any other agent.
- [docs/install.md](docs/install.md) — options, manual setup, upgrades, and uninstall.
- [docs/troubleshooting.md](docs/troubleshooting.md) — “held by”, plugin, Gradle, and lease issues.
- [docs/architecture.md](docs/architecture.md) — components, request flows, and state.
- [docs/opencode.md](docs/opencode.md) — OpenCode-specific integration details.
- [docs/antigravity.md](docs/antigravity.md) — Antigravity-specific integration details.
- [docs/limits.md](docs/limits.md) — what the guard does not cover.
- [docs/PROJECTS.md](docs/PROJECTS.md) — using droidlock from a project.
- [docs/DESIGN.md](docs/DESIGN.md) — engine design and behavior.

## Upstream and license

`droidlock` is an unofficial downstream distribution based on [banksman](https://github.com/Twinsen81/banksman)
(Apache-2.0), developed by Evgenii Plokhov and contributors. It is not affiliated with or endorsed
by the banksman project. The upstream snapshots are [docs/upstream-README.md](docs/upstream-README.md)
and [docs/upstream-CHANGELOG.md](docs/upstream-CHANGELOG.md); the attribution is in [NOTICE](NOTICE)
and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).

`droidlock` is licensed under the **Apache License 2.0**. See [LICENSE](LICENSE).

---

## Resumen en español

`droidlock` es un gestor multi-agente de emuladores y dispositivos Android (Apache-2.0), basado en
[banksman](https://github.com/Twinsen81/banksman). Garantiza un emulador Android exclusivo por sesión
de agente sin que varios agentes peleen por `adb` o Gradle.

```sh
./install.sh              # selector interactivo de agentes detectados
./install.sh --yes        # instalar automáticamente para los agentes detectados
droidlock admin discover --all --yes
droidlock admin doctor
```

Incluye detección automática e integración para **Claude Code, Cursor, Codex CLI, OpenCode, Hermes Agent,
Gemini CLI, Antigravity, Kiro, VS Code (Copilot Chat), GitHub Copilot CLI, JetBrains IDEs y Pi**:
10 agentes usan `SKILL.md`, y OpenCode y Antigravity usan plugins nativos. El shim universal de `adb`
se instala para todos y auto-adquiere leases para las sesiones reconocidas; cualquier otro agente o
script puede usar `droidlock run`. Es un guardrail, no un sandbox. Licencia Apache-2.0 con atribución
a banksman en [NOTICE](NOTICE) y [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
