droidguard 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. droidguard-2.0.0/LICENSE +21 -0
  2. droidguard-2.0.0/PKG-INFO +280 -0
  3. droidguard-2.0.0/README.md +244 -0
  4. droidguard-2.0.0/pyproject.toml +107 -0
  5. droidguard-2.0.0/setup.cfg +4 -0
  6. droidguard-2.0.0/src/droidguard/__init__.py +17 -0
  7. droidguard-2.0.0/src/droidguard/__main__.py +7 -0
  8. droidguard-2.0.0/src/droidguard/_compat.py +176 -0
  9. droidguard-2.0.0/src/droidguard/_errors.py +63 -0
  10. droidguard-2.0.0/src/droidguard/_logging.py +161 -0
  11. droidguard-2.0.0/src/droidguard/adapters/__init__.py +24 -0
  12. droidguard-2.0.0/src/droidguard/adapters/antigravity.py +54 -0
  13. droidguard-2.0.0/src/droidguard/adapters/base.py +28 -0
  14. droidguard-2.0.0/src/droidguard/adapters/claude.py +60 -0
  15. droidguard-2.0.0/src/droidguard/adapters/cline.py +38 -0
  16. droidguard-2.0.0/src/droidguard/adapters/codex.py +90 -0
  17. droidguard-2.0.0/src/droidguard/adapters/copilot.py +50 -0
  18. droidguard-2.0.0/src/droidguard/adapters/cursor.py +59 -0
  19. droidguard-2.0.0/src/droidguard/adapters/qwen.py +38 -0
  20. droidguard-2.0.0/src/droidguard/adapters/windsurf.py +42 -0
  21. droidguard-2.0.0/src/droidguard/android/__init__.py +19 -0
  22. droidguard-2.0.0/src/droidguard/android/gradle.py +129 -0
  23. droidguard-2.0.0/src/droidguard/android/manifest.py +107 -0
  24. droidguard-2.0.0/src/droidguard/android/modules.py +118 -0
  25. droidguard-2.0.0/src/droidguard/android/project.py +62 -0
  26. droidguard-2.0.0/src/droidguard/android/variants.py +51 -0
  27. droidguard-2.0.0/src/droidguard/checks/__init__.py +34 -0
  28. droidguard-2.0.0/src/droidguard/checks/compose.py +122 -0
  29. droidguard-2.0.0/src/droidguard/checks/dagp.py +42 -0
  30. droidguard-2.0.0/src/droidguard/checks/detekt.py +49 -0
  31. droidguard-2.0.0/src/droidguard/checks/gradle_doctor.py +39 -0
  32. droidguard-2.0.0/src/droidguard/checks/konsist.py +88 -0
  33. droidguard-2.0.0/src/droidguard/checks/lint.py +86 -0
  34. droidguard-2.0.0/src/droidguard/checks/models.py +47 -0
  35. droidguard-2.0.0/src/droidguard/checks/perf.py +93 -0
  36. droidguard-2.0.0/src/droidguard/checks/room.py +174 -0
  37. droidguard-2.0.0/src/droidguard/checks/runner.py +164 -0
  38. droidguard-2.0.0/src/droidguard/checks/screenshot.py +60 -0
  39. droidguard-2.0.0/src/droidguard/checks/strings.py +153 -0
  40. droidguard-2.0.0/src/droidguard/cli/__init__.py +5 -0
  41. droidguard-2.0.0/src/droidguard/cli/cmd_deliver.py +152 -0
  42. droidguard-2.0.0/src/droidguard/cli/cmd_doctor.py +88 -0
  43. droidguard-2.0.0/src/droidguard/cli/cmd_explain.py +58 -0
  44. droidguard-2.0.0/src/droidguard/cli/cmd_init.py +118 -0
  45. droidguard-2.0.0/src/droidguard/cli/cmd_preflight.py +88 -0
  46. droidguard-2.0.0/src/droidguard/cli/cmd_rollback.py +92 -0
  47. droidguard-2.0.0/src/droidguard/cli/cmd_selftest.py +105 -0
  48. droidguard-2.0.0/src/droidguard/cli/cmd_status.py +57 -0
  49. droidguard-2.0.0/src/droidguard/cli/cmd_sync.py +81 -0
  50. droidguard-2.0.0/src/droidguard/cli/cmd_verify.py +69 -0
  51. droidguard-2.0.0/src/droidguard/cli/main.py +118 -0
  52. droidguard-2.0.0/src/droidguard/config/__init__.py +35 -0
  53. droidguard-2.0.0/src/droidguard/config/discovery.py +104 -0
  54. droidguard-2.0.0/src/droidguard/config/loader.py +239 -0
  55. droidguard-2.0.0/src/droidguard/config/schema.py +222 -0
  56. droidguard-2.0.0/src/droidguard/device/__init__.py +14 -0
  57. droidguard-2.0.0/src/droidguard/device/logcat.py +151 -0
  58. droidguard-2.0.0/src/droidguard/device/runner.py +117 -0
  59. droidguard-2.0.0/src/droidguard/device/screenshot.py +42 -0
  60. droidguard-2.0.0/src/droidguard/doctor/__init__.py +17 -0
  61. droidguard-2.0.0/src/droidguard/doctor/engine.py +302 -0
  62. droidguard-2.0.0/src/droidguard/doctor/models.py +59 -0
  63. droidguard-2.0.0/src/droidguard/gradle_runner/__init__.py +13 -0
  64. droidguard-2.0.0/src/droidguard/gradle_runner/error_parser.py +105 -0
  65. droidguard-2.0.0/src/droidguard/gradle_runner/executor.py +105 -0
  66. droidguard-2.0.0/src/droidguard/gradle_runner/process.py +97 -0
  67. droidguard-2.0.0/src/droidguard/pm/__init__.py +24 -0
  68. droidguard-2.0.0/src/droidguard/pm/gateway.py +86 -0
  69. droidguard-2.0.0/src/droidguard/pm/github/client.py +110 -0
  70. droidguard-2.0.0/src/droidguard/pm/jira/client.py +133 -0
  71. droidguard-2.0.0/src/droidguard/pm/linear/client.py +131 -0
  72. droidguard-2.0.0/src/droidguard/pm/policy.py +43 -0
  73. droidguard-2.0.0/src/droidguard/pm/zoho/client.py +187 -0
  74. droidguard-2.0.0/src/droidguard/pm/zoho/formatter.py +78 -0
  75. droidguard-2.0.0/src/droidguard/pm/zoho/server.py +159 -0
  76. droidguard-2.0.0/src/droidguard/py.typed +1 -0
  77. droidguard-2.0.0/src/droidguard/review/__init__.py +24 -0
  78. droidguard-2.0.0/src/droidguard/review/adjudicator.py +97 -0
  79. droidguard-2.0.0/src/droidguard/review/consensus.py +118 -0
  80. droidguard-2.0.0/src/droidguard/review/fingerprint.py +117 -0
  81. droidguard-2.0.0/src/droidguard/review/subagents.py +111 -0
  82. droidguard-2.0.0/src/droidguard/safety/__init__.py +20 -0
  83. droidguard-2.0.0/src/droidguard/safety/adb_guard.py +58 -0
  84. droidguard-2.0.0/src/droidguard/safety/git_guard.py +115 -0
  85. droidguard-2.0.0/src/droidguard/safety/hook_bridge.py +120 -0
  86. droidguard-2.0.0/src/droidguard/safety/policy.py +134 -0
  87. droidguard-2.0.0/src/droidguard/safety/shell_guard.py +120 -0
  88. droidguard-2.0.0/src/droidguard/state/__init__.py +18 -0
  89. droidguard-2.0.0/src/droidguard/state/db.py +257 -0
  90. droidguard-2.0.0/src/droidguard/state/ledger.py +126 -0
  91. droidguard-2.0.0/src/droidguard/state/models.py +133 -0
  92. droidguard-2.0.0/src/droidguard/state/trajectory.py +103 -0
  93. droidguard-2.0.0/src/droidguard.egg-info/PKG-INFO +280 -0
  94. droidguard-2.0.0/src/droidguard.egg-info/SOURCES.txt +117 -0
  95. droidguard-2.0.0/src/droidguard.egg-info/dependency_links.txt +1 -0
  96. droidguard-2.0.0/src/droidguard.egg-info/entry_points.txt +3 -0
  97. droidguard-2.0.0/src/droidguard.egg-info/requires.txt +7 -0
  98. droidguard-2.0.0/src/droidguard.egg-info/top_level.txt +1 -0
  99. droidguard-2.0.0/tests/test_adapters.py +119 -0
  100. droidguard-2.0.0/tests/test_android_project.py +75 -0
  101. droidguard-2.0.0/tests/test_checks_compose.py +53 -0
  102. droidguard-2.0.0/tests/test_checks_lint.py +48 -0
  103. droidguard-2.0.0/tests/test_checks_perf.py +53 -0
  104. droidguard-2.0.0/tests/test_checks_room.py +88 -0
  105. droidguard-2.0.0/tests/test_checks_strings.py +81 -0
  106. droidguard-2.0.0/tests/test_cli.py +116 -0
  107. droidguard-2.0.0/tests/test_cli_deliver.py +28 -0
  108. droidguard-2.0.0/tests/test_cli_rollback.py +41 -0
  109. droidguard-2.0.0/tests/test_cli_sync.py +40 -0
  110. droidguard-2.0.0/tests/test_config.py +119 -0
  111. droidguard-2.0.0/tests/test_device.py +53 -0
  112. droidguard-2.0.0/tests/test_e2e_integration.py +71 -0
  113. droidguard-2.0.0/tests/test_gradle_runner.py +71 -0
  114. droidguard-2.0.0/tests/test_pm_gateway.py +50 -0
  115. droidguard-2.0.0/tests/test_pm_zoho.py +60 -0
  116. droidguard-2.0.0/tests/test_review.py +144 -0
  117. droidguard-2.0.0/tests/test_safety.py +227 -0
  118. droidguard-2.0.0/tests/test_state.py +151 -0
  119. droidguard-2.0.0/tests/test_trajectory.py +51 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rabee Elkholy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,280 @@
1
+ Metadata-Version: 2.4
2
+ Name: droidguard
3
+ Version: 2.0.0
4
+ Summary: Deterministic Android Verification & AI Agent Governance Engine
5
+ Author: DroidGuard Contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/rabee-elkholy/droidguard
8
+ Project-URL: Documentation, https://github.com/rabee-elkholy/droidguard#readme
9
+ Project-URL: Repository, https://github.com/rabee-elkholy/droidguard.git
10
+ Project-URL: Issues, https://github.com/rabee-elkholy/droidguard/issues
11
+ Project-URL: Changelog, https://github.com/rabee-elkholy/droidguard/blob/main/CHANGELOG.md
12
+ Keywords: android,ai-agents,agentic-coding,gradle,governance,roborazzi,konsist,compose,claude-code,cursor,codex
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Build Tools
24
+ Classifier: Topic :: Software Development :: Quality Assurance
25
+ Classifier: Topic :: Software Development :: Testing
26
+ Requires-Python: >=3.11
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
32
+ Requires-Dist: ruff>=0.5.0; extra == "dev"
33
+ Requires-Dist: mypy>=1.10.0; extra == "dev"
34
+ Requires-Dist: build>=1.0.0; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # 🛡️ DroidGuard 2.0
38
+
39
+ <p align="center">
40
+ <strong>Deterministic Android Verification & AI Agent Governance Engine</strong><br>
41
+ <em>Protect your Android codebase from agent hallucinations, unauthorized Git mutations, ANRs, broken Room migrations, and untranslated strings.</em>
42
+ </p>
43
+
44
+ <p align="center">
45
+ <a href="https://pypi.org/project/droidguard/"><img src="https://img.shields.io/pypi/v/droidguard?color=blue&style=flat-square" alt="PyPI Version"></a>
46
+ <a href="https://pypi.org/project/droidguard/"><img src="https://img.shields.io/pypi/pyversions/droidguard?style=flat-square" alt="Python Versions"></a>
47
+ <a href="https://github.com/rabee-elkholy/droidguard/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green?style=flat-square" alt="License"></a>
48
+ <a href="https://github.com/rabee-elkholy/droidguard/actions"><img src="https://img.shields.io/github/actions/workflow/status/rabee-elkholy/droidguard/ci.yml?branch=main&style=flat-square" alt="CI Build"></a>
49
+ <a href="https://github.com/rabee-elkholy/droidguard/actions"><img src="https://img.shields.io/badge/coverage-80%25-brightgreen?style=flat-square" alt="Test Coverage"></a>
50
+ </p>
51
+
52
+ ---
53
+
54
+ ## ⚡ The Problem DroidGuard Solves
55
+
56
+ Autonomous AI coding agents (**Claude Code, Cursor, OpenAI Codex, Antigravity, Copilot, Windsurf**) are transforming software development. However, Android engineering has strict platform-specific constraints that general LLMs frequently violate:
57
+
58
+ - ❌ **Destructive Git Mutations**: AI agents committing directly to `main`, force-pushing, resetting HEAD, or modifying Git branches without human developer review.
59
+ - ❌ **Broken Room SQLite Migrations**: Modifying entity schemas without incrementing database version numbers or writing SQLite `Migration` classes, causing production crashes on user devices.
60
+ - ❌ **Missing Localization Strings**: Adding hardcoded strings or updating `values/strings.xml` while forgetting Arabic (`values-ar`), French (`values-fr`), or other locale parity, breaking multi-language users.
61
+ - ❌ **Compose Recomposition Freezes & ANRs**: Using unstable parameters (`List<T>`) causing UI jank, or wrapping background tasks in `runBlocking` / `Thread.sleep()` on the Android Main thread.
62
+ - ❌ **Orphaned Gradle Daemons**: Child compiler processes locking files on Windows and Unix systems during AI task interruption.
63
+
64
+ **DroidGuard 2.0** sits between your AI coding agents and your Android codebase as a **deterministic, fail-closed governance firewall and quality verification engine**.
65
+
66
+ ---
67
+
68
+ ## 🚀 Key Features
69
+
70
+ ```
71
+ ┌──────────────────────────────────────────────┐
72
+ │ AI Coding Agents │
73
+ │ (Claude Code, Cursor, Codex, Copilot, etc.) │
74
+ └──────────────────────┬───────────────────────┘
75
+
76
+ [ Universal PreToolUse Hook ]
77
+
78
+ ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐
79
+ │ 🛡️ DROIDGUARD 2.0 │
80
+ ├──────────────────────────────┬───────────────────────────────┬────────────────────────────────────────┤
81
+ │ 1. Safety & Policy │ 2. Android Intelligence │ 3. Governance & Delivery │
82
+ ├──────────────────────────────┼───────────────────────────────┼────────────────────────────────────────┤
83
+ │ • Git Mutation Blocker │ • Multi-Locale String Parity │ • N-Leaf Subagent Review Consensus │
84
+ │ • Shell / Base64 Unwrapping │ • Room Schema JSON Validator │ • SQLite Relational State Engine │
85
+ │ • ADB Hardware Protection │ • Compose Stability Metrics │ • Win32 Job Object Process Supervisor │
86
+ │ • Trojan Source Bidi Defense │ • Konsist Architecture Rules │ • Unified PM Gateway (Zoho, Jira, etc.)│
87
+ │ • Path Traversal Shield │ • StrictMode / ANR Sentinel │ • AgentLens / SWE-bench Tracing │
88
+ └──────────────────────────────┴───────────────────────────────┴────────────────────────────────────────┘
89
+
90
+
91
+ ┌──────────────────────────────────────────────┐
92
+ │ Android Project │
93
+ │ (Gradle, Kotlin DSL, AGP 8+, Compose, Room) │
94
+ └──────────────────────────────────────────────┘
95
+ ```
96
+
97
+ ### 1. Fail-Closed Safety Engine
98
+ - **Absolute Git Authority**: Blocks all forms of `git commit`, `git push`, `git reset`, `git checkout -b`, and disguised flags (`-C`, `--git-dir`). Only the human developer holds commit authority.
99
+ - **Shell Indirection & Obfuscation Guard**: Unwraps PowerShell base64 (`-EncodedCommand`), backtick escaping (``g`i`t``), nested execution (`bash -c`, `cmd /c`, `python -c`), and blocks dynamic `iex` execution.
100
+ - **ADB Hardware Guard**: Blocks destructive device commands (`adb monkey`, `pm clear`, `uninstall`, `reboot recovery`), while permitting safe telemetry (`logcat`, `install -r`, `screencap`).
101
+ - **Trojan Source Defense**: Detects and blocks bidirectional Unicode override characters (RLO, LRO, PDF).
102
+
103
+ ### 2. Android 7-Layer Verification Engine (`dg preflight`)
104
+ 1. **Multi-Locale String Parity**: Validates key parity across all `values-*/strings.xml`, `<plurals>`, `<string-array>`, and positional format specifiers (`%1$s`, `%2$d`).
105
+ 2. **Room Database Schema JSON Diff**: Inspects `schemas/<DbClass>/<version>.json`, detects added/removed/renamed tables and columns, and enforces matching `Migration(N, N+1)` code in Kotlin/Java.
106
+ 3. **Jetpack Compose Compiler Metrics**: Parses `*-composables.txt` and `*-classes.txt`, detecting unstable parameters and non-skippable composable functions.
107
+ 4. **Konsist Architecture Rules**: Enforces Clean Architecture domain layer isolation, `@Immutable` on MVI state models, and forbids inline FQCNs.
108
+ 5. **Performance & ANR Sentinel**: Scans for `runBlocking`, blocking `Thread.sleep()`, and ViewModel Context memory leaks.
109
+ 6. **Roborazzi Headless JVM Visual Tests**: Validates Compose screenshot reports for visual regressions across RTL Arabic and Dark Mode.
110
+ 7. **Android Lint CLI Incremental Runner**: Enforces baseline compliance and zero fatal errors.
111
+
112
+ ### 3. Multi-Agent Review Consensus (`dg verify`)
113
+ - Calculates a 12-character SHA-256 extended code fingerprint covering Kotlin, Java, XML, Gradle Kotlin DSL, `proguard-rules.pro`, Room schema JSONs, and `CMakeLists.txt`.
114
+ - Gated build authorization requiring configurable quorum (3, 5, 7 subagent approvals recorded in SQLite `ReviewLedger` across 5 specialized personas: `security`, `convention`, `perf-anr`, `regression-impact`, `qa-diagnostics`).
115
+
116
+ ### 4. Supervised Gradle Runner
117
+ - Uses **Win32 Job Objects** on Windows and **process groups** on Linux/macOS to terminate child compiler and daemon processes with zero orphan leaks.
118
+ - Structured compiler error extraction for Kotlin (`file:line:col`), Java, Manifest merger conflicts, and Room schemas.
119
+
120
+ ### 5. Unified Project Management Gateway
121
+ - Single vendor-agnostic adapter interface supporting **Zoho Sprints (multi-region .com, .eu, .in, .sa, .au), Jira Cloud v3, Linear GraphQL, and GitHub Projects**.
122
+ - Enforces security policy forbidding AI agents from marking tasks as `Done` or `Solved` (restricting transitions to `In Review` or `Ready for QA`).
123
+ - Theme-resilient HTML formatting preserving Kotlin Generics (`List<UserProfile>`) with automatic Arabic RTL direction.
124
+
125
+ ### 6. Universal AI IDE & Assistant Adapters (`dg sync`)
126
+ - Seamlessly synchronizes project rules and configuration across **8 AI environments**:
127
+ * **OpenAI Codex CLI & `AGENTS.md`** (`CODEX.md`, `AGENTS.md`, `.codex/prompts/*`)
128
+ * **Google Antigravity** (`.agents/rules/droidguard-rules.md`)
129
+ * **Anthropic Claude Code** (`CLAUDE.md`)
130
+ * **Cursor IDE** (`.cursor/rules/droidguard.mdc`)
131
+ * **GitHub Copilot** (`.github/copilot-instructions.md`)
132
+ * **Windsurf IDE** (`.windsurfrules`)
133
+ * **Cline & Roo Code** (`.clinerules`)
134
+ * **Qwen Code** (`QWEN.md`)
135
+
136
+ ---
137
+
138
+ ## 📦 Installation
139
+
140
+ Install DroidGuard via pip (requires Python 3.11+):
141
+
142
+ ```bash
143
+ pip install droidguard
144
+ ```
145
+
146
+ Or install with development dependencies:
147
+
148
+ ```bash
149
+ pip install "droidguard[dev]"
150
+ ```
151
+
152
+ Verify installation:
153
+
154
+ ```bash
155
+ dg --version
156
+ ```
157
+
158
+ ---
159
+
160
+ ## 🛠️ CLI Quickstart
161
+
162
+ ### 1. Initialize an Android Project
163
+ Run inside your Android project root:
164
+
165
+ ```bash
166
+ dg init
167
+ ```
168
+ *Auto-detects your Android project configuration (Compose/XML, Hilt/Koin, SDK levels, locales), generates `droidguard.toml`, creates `.agents/state/droidguard.db`, and configures `.githooks/pre-commit`.*
169
+
170
+ ### 2. Run Environment Diagnostics
171
+ ```bash
172
+ dg doctor
173
+ ```
174
+ *Validates JDK 17+, Android SDK, Gradle Wrapper, ADB, Git hooks, and static analysis tools.*
175
+
176
+ ### 3. Run Preflight Verification Checks
177
+ ```bash
178
+ dg preflight
179
+ ```
180
+ *Executes Strings, Room, Compose, Konsist, Lint, and Performance sentinels with graceful degradation in milliseconds.*
181
+
182
+ ### 4. Verify Review Consensus & Code Fingerprint
183
+ ```bash
184
+ dg verify
185
+ ```
186
+ *Inspects SHA-256 package hash and verifies if required subagent review consensus has unlocked the build gate.*
187
+
188
+ ### 5. Execute Multi-Stage QA Delivery Pipeline
189
+ ```bash
190
+ dg deliver --task ZOHO-101
191
+ ```
192
+ *Coordinates: preflight checks ➔ consensus validation ➔ supervised Gradle build ➔ PM status & QA handoff report update.*
193
+
194
+ ### 6. Synchronize Rules Across All AI IDEs
195
+ ```bash
196
+ dg sync
197
+ ```
198
+ *Generates and updates `CLAUDE.md`, `CODEX.md`, `AGENTS.md`, `.cursor/rules/`, `.agents/`, and Copilot instructions.*
199
+
200
+ ### 7. Rollback Session State
201
+ ```bash
202
+ dg rollback --clean-temp
203
+ ```
204
+
205
+ ---
206
+
207
+ ## ⚙️ Configuration (`droidguard.toml`)
208
+
209
+ DroidGuard is configured via a single documented `droidguard.toml` at the project root:
210
+
211
+ ```toml
212
+ version = "2.0.0"
213
+
214
+ [project]
215
+ name = "MyAndroidApp"
216
+ di_framework = "hilt" # auto | hilt | koin | dagger | anvil | manual
217
+ ui_toolkit = "compose" # auto | compose | xml | hybrid | kmp
218
+ default_build_type = "debug"
219
+
220
+ [review]
221
+ enabled = true
222
+ leaf_count = 5 # 3, 5, 7 consensus reviewers
223
+ require_unanimous = false
224
+
225
+ [checks.strings]
226
+ enabled = true
227
+ base_locale = "values"
228
+ enforce_all_locales = true
229
+
230
+ [checks.room]
231
+ enabled = true
232
+ schema_dir = "schemas"
233
+ verify_migrations = true
234
+
235
+ [checks.compose]
236
+ enabled = true
237
+ enforce_immutable_state = true
238
+ fail_on_unstable_params = false
239
+
240
+ [checks.konsist]
241
+ enabled = true
242
+ enforce_clean_architecture = true
243
+ forbid_inline_fqcn = true
244
+
245
+ [checks.perf]
246
+ enabled = true
247
+ forbid_main_thread_queries = true
248
+ forbid_sleep = true
249
+ check_viewmodel_leaks = true
250
+
251
+ [pm]
252
+ provider = "zoho" # zoho | jira | linear | github | none
253
+ domain = "sa" # com | eu | in | sa | au
254
+ enforce_qa_handoff = true
255
+ forbid_done_status = true
256
+ ```
257
+
258
+ ---
259
+
260
+ ## 🧪 Testing & Verification
261
+
262
+ DroidGuard includes an exhaustive test suite with over 85 unit, integration, and penetration test cases:
263
+
264
+ ```bash
265
+ # Run pytest test suite
266
+ pytest tests/ -v
267
+
268
+ # Run type checker
269
+ mypy src/
270
+
271
+ # Run linter & formatter
272
+ ruff check src/ tests/
273
+ ruff format src/ tests/
274
+ ```
275
+
276
+ ---
277
+
278
+ ## 📄 License
279
+
280
+ DroidGuard is licensed under the [Apache-2.0 License](LICENSE).
@@ -0,0 +1,244 @@
1
+ # 🛡️ DroidGuard 2.0
2
+
3
+ <p align="center">
4
+ <strong>Deterministic Android Verification & AI Agent Governance Engine</strong><br>
5
+ <em>Protect your Android codebase from agent hallucinations, unauthorized Git mutations, ANRs, broken Room migrations, and untranslated strings.</em>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://pypi.org/project/droidguard/"><img src="https://img.shields.io/pypi/v/droidguard?color=blue&style=flat-square" alt="PyPI Version"></a>
10
+ <a href="https://pypi.org/project/droidguard/"><img src="https://img.shields.io/pypi/pyversions/droidguard?style=flat-square" alt="Python Versions"></a>
11
+ <a href="https://github.com/rabee-elkholy/droidguard/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green?style=flat-square" alt="License"></a>
12
+ <a href="https://github.com/rabee-elkholy/droidguard/actions"><img src="https://img.shields.io/github/actions/workflow/status/rabee-elkholy/droidguard/ci.yml?branch=main&style=flat-square" alt="CI Build"></a>
13
+ <a href="https://github.com/rabee-elkholy/droidguard/actions"><img src="https://img.shields.io/badge/coverage-80%25-brightgreen?style=flat-square" alt="Test Coverage"></a>
14
+ </p>
15
+
16
+ ---
17
+
18
+ ## ⚡ The Problem DroidGuard Solves
19
+
20
+ Autonomous AI coding agents (**Claude Code, Cursor, OpenAI Codex, Antigravity, Copilot, Windsurf**) are transforming software development. However, Android engineering has strict platform-specific constraints that general LLMs frequently violate:
21
+
22
+ - ❌ **Destructive Git Mutations**: AI agents committing directly to `main`, force-pushing, resetting HEAD, or modifying Git branches without human developer review.
23
+ - ❌ **Broken Room SQLite Migrations**: Modifying entity schemas without incrementing database version numbers or writing SQLite `Migration` classes, causing production crashes on user devices.
24
+ - ❌ **Missing Localization Strings**: Adding hardcoded strings or updating `values/strings.xml` while forgetting Arabic (`values-ar`), French (`values-fr`), or other locale parity, breaking multi-language users.
25
+ - ❌ **Compose Recomposition Freezes & ANRs**: Using unstable parameters (`List<T>`) causing UI jank, or wrapping background tasks in `runBlocking` / `Thread.sleep()` on the Android Main thread.
26
+ - ❌ **Orphaned Gradle Daemons**: Child compiler processes locking files on Windows and Unix systems during AI task interruption.
27
+
28
+ **DroidGuard 2.0** sits between your AI coding agents and your Android codebase as a **deterministic, fail-closed governance firewall and quality verification engine**.
29
+
30
+ ---
31
+
32
+ ## 🚀 Key Features
33
+
34
+ ```
35
+ ┌──────────────────────────────────────────────┐
36
+ │ AI Coding Agents │
37
+ │ (Claude Code, Cursor, Codex, Copilot, etc.) │
38
+ └──────────────────────┬───────────────────────┘
39
+
40
+ [ Universal PreToolUse Hook ]
41
+
42
+ ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐
43
+ │ 🛡️ DROIDGUARD 2.0 │
44
+ ├──────────────────────────────┬───────────────────────────────┬────────────────────────────────────────┤
45
+ │ 1. Safety & Policy │ 2. Android Intelligence │ 3. Governance & Delivery │
46
+ ├──────────────────────────────┼───────────────────────────────┼────────────────────────────────────────┤
47
+ │ • Git Mutation Blocker │ • Multi-Locale String Parity │ • N-Leaf Subagent Review Consensus │
48
+ │ • Shell / Base64 Unwrapping │ • Room Schema JSON Validator │ • SQLite Relational State Engine │
49
+ │ • ADB Hardware Protection │ • Compose Stability Metrics │ • Win32 Job Object Process Supervisor │
50
+ │ • Trojan Source Bidi Defense │ • Konsist Architecture Rules │ • Unified PM Gateway (Zoho, Jira, etc.)│
51
+ │ • Path Traversal Shield │ • StrictMode / ANR Sentinel │ • AgentLens / SWE-bench Tracing │
52
+ └──────────────────────────────┴───────────────────────────────┴────────────────────────────────────────┘
53
+
54
+
55
+ ┌──────────────────────────────────────────────┐
56
+ │ Android Project │
57
+ │ (Gradle, Kotlin DSL, AGP 8+, Compose, Room) │
58
+ └──────────────────────────────────────────────┘
59
+ ```
60
+
61
+ ### 1. Fail-Closed Safety Engine
62
+ - **Absolute Git Authority**: Blocks all forms of `git commit`, `git push`, `git reset`, `git checkout -b`, and disguised flags (`-C`, `--git-dir`). Only the human developer holds commit authority.
63
+ - **Shell Indirection & Obfuscation Guard**: Unwraps PowerShell base64 (`-EncodedCommand`), backtick escaping (``g`i`t``), nested execution (`bash -c`, `cmd /c`, `python -c`), and blocks dynamic `iex` execution.
64
+ - **ADB Hardware Guard**: Blocks destructive device commands (`adb monkey`, `pm clear`, `uninstall`, `reboot recovery`), while permitting safe telemetry (`logcat`, `install -r`, `screencap`).
65
+ - **Trojan Source Defense**: Detects and blocks bidirectional Unicode override characters (RLO, LRO, PDF).
66
+
67
+ ### 2. Android 7-Layer Verification Engine (`dg preflight`)
68
+ 1. **Multi-Locale String Parity**: Validates key parity across all `values-*/strings.xml`, `<plurals>`, `<string-array>`, and positional format specifiers (`%1$s`, `%2$d`).
69
+ 2. **Room Database Schema JSON Diff**: Inspects `schemas/<DbClass>/<version>.json`, detects added/removed/renamed tables and columns, and enforces matching `Migration(N, N+1)` code in Kotlin/Java.
70
+ 3. **Jetpack Compose Compiler Metrics**: Parses `*-composables.txt` and `*-classes.txt`, detecting unstable parameters and non-skippable composable functions.
71
+ 4. **Konsist Architecture Rules**: Enforces Clean Architecture domain layer isolation, `@Immutable` on MVI state models, and forbids inline FQCNs.
72
+ 5. **Performance & ANR Sentinel**: Scans for `runBlocking`, blocking `Thread.sleep()`, and ViewModel Context memory leaks.
73
+ 6. **Roborazzi Headless JVM Visual Tests**: Validates Compose screenshot reports for visual regressions across RTL Arabic and Dark Mode.
74
+ 7. **Android Lint CLI Incremental Runner**: Enforces baseline compliance and zero fatal errors.
75
+
76
+ ### 3. Multi-Agent Review Consensus (`dg verify`)
77
+ - Calculates a 12-character SHA-256 extended code fingerprint covering Kotlin, Java, XML, Gradle Kotlin DSL, `proguard-rules.pro`, Room schema JSONs, and `CMakeLists.txt`.
78
+ - Gated build authorization requiring configurable quorum (3, 5, 7 subagent approvals recorded in SQLite `ReviewLedger` across 5 specialized personas: `security`, `convention`, `perf-anr`, `regression-impact`, `qa-diagnostics`).
79
+
80
+ ### 4. Supervised Gradle Runner
81
+ - Uses **Win32 Job Objects** on Windows and **process groups** on Linux/macOS to terminate child compiler and daemon processes with zero orphan leaks.
82
+ - Structured compiler error extraction for Kotlin (`file:line:col`), Java, Manifest merger conflicts, and Room schemas.
83
+
84
+ ### 5. Unified Project Management Gateway
85
+ - Single vendor-agnostic adapter interface supporting **Zoho Sprints (multi-region .com, .eu, .in, .sa, .au), Jira Cloud v3, Linear GraphQL, and GitHub Projects**.
86
+ - Enforces security policy forbidding AI agents from marking tasks as `Done` or `Solved` (restricting transitions to `In Review` or `Ready for QA`).
87
+ - Theme-resilient HTML formatting preserving Kotlin Generics (`List<UserProfile>`) with automatic Arabic RTL direction.
88
+
89
+ ### 6. Universal AI IDE & Assistant Adapters (`dg sync`)
90
+ - Seamlessly synchronizes project rules and configuration across **8 AI environments**:
91
+ * **OpenAI Codex CLI & `AGENTS.md`** (`CODEX.md`, `AGENTS.md`, `.codex/prompts/*`)
92
+ * **Google Antigravity** (`.agents/rules/droidguard-rules.md`)
93
+ * **Anthropic Claude Code** (`CLAUDE.md`)
94
+ * **Cursor IDE** (`.cursor/rules/droidguard.mdc`)
95
+ * **GitHub Copilot** (`.github/copilot-instructions.md`)
96
+ * **Windsurf IDE** (`.windsurfrules`)
97
+ * **Cline & Roo Code** (`.clinerules`)
98
+ * **Qwen Code** (`QWEN.md`)
99
+
100
+ ---
101
+
102
+ ## 📦 Installation
103
+
104
+ Install DroidGuard via pip (requires Python 3.11+):
105
+
106
+ ```bash
107
+ pip install droidguard
108
+ ```
109
+
110
+ Or install with development dependencies:
111
+
112
+ ```bash
113
+ pip install "droidguard[dev]"
114
+ ```
115
+
116
+ Verify installation:
117
+
118
+ ```bash
119
+ dg --version
120
+ ```
121
+
122
+ ---
123
+
124
+ ## 🛠️ CLI Quickstart
125
+
126
+ ### 1. Initialize an Android Project
127
+ Run inside your Android project root:
128
+
129
+ ```bash
130
+ dg init
131
+ ```
132
+ *Auto-detects your Android project configuration (Compose/XML, Hilt/Koin, SDK levels, locales), generates `droidguard.toml`, creates `.agents/state/droidguard.db`, and configures `.githooks/pre-commit`.*
133
+
134
+ ### 2. Run Environment Diagnostics
135
+ ```bash
136
+ dg doctor
137
+ ```
138
+ *Validates JDK 17+, Android SDK, Gradle Wrapper, ADB, Git hooks, and static analysis tools.*
139
+
140
+ ### 3. Run Preflight Verification Checks
141
+ ```bash
142
+ dg preflight
143
+ ```
144
+ *Executes Strings, Room, Compose, Konsist, Lint, and Performance sentinels with graceful degradation in milliseconds.*
145
+
146
+ ### 4. Verify Review Consensus & Code Fingerprint
147
+ ```bash
148
+ dg verify
149
+ ```
150
+ *Inspects SHA-256 package hash and verifies if required subagent review consensus has unlocked the build gate.*
151
+
152
+ ### 5. Execute Multi-Stage QA Delivery Pipeline
153
+ ```bash
154
+ dg deliver --task ZOHO-101
155
+ ```
156
+ *Coordinates: preflight checks ➔ consensus validation ➔ supervised Gradle build ➔ PM status & QA handoff report update.*
157
+
158
+ ### 6. Synchronize Rules Across All AI IDEs
159
+ ```bash
160
+ dg sync
161
+ ```
162
+ *Generates and updates `CLAUDE.md`, `CODEX.md`, `AGENTS.md`, `.cursor/rules/`, `.agents/`, and Copilot instructions.*
163
+
164
+ ### 7. Rollback Session State
165
+ ```bash
166
+ dg rollback --clean-temp
167
+ ```
168
+
169
+ ---
170
+
171
+ ## ⚙️ Configuration (`droidguard.toml`)
172
+
173
+ DroidGuard is configured via a single documented `droidguard.toml` at the project root:
174
+
175
+ ```toml
176
+ version = "2.0.0"
177
+
178
+ [project]
179
+ name = "MyAndroidApp"
180
+ di_framework = "hilt" # auto | hilt | koin | dagger | anvil | manual
181
+ ui_toolkit = "compose" # auto | compose | xml | hybrid | kmp
182
+ default_build_type = "debug"
183
+
184
+ [review]
185
+ enabled = true
186
+ leaf_count = 5 # 3, 5, 7 consensus reviewers
187
+ require_unanimous = false
188
+
189
+ [checks.strings]
190
+ enabled = true
191
+ base_locale = "values"
192
+ enforce_all_locales = true
193
+
194
+ [checks.room]
195
+ enabled = true
196
+ schema_dir = "schemas"
197
+ verify_migrations = true
198
+
199
+ [checks.compose]
200
+ enabled = true
201
+ enforce_immutable_state = true
202
+ fail_on_unstable_params = false
203
+
204
+ [checks.konsist]
205
+ enabled = true
206
+ enforce_clean_architecture = true
207
+ forbid_inline_fqcn = true
208
+
209
+ [checks.perf]
210
+ enabled = true
211
+ forbid_main_thread_queries = true
212
+ forbid_sleep = true
213
+ check_viewmodel_leaks = true
214
+
215
+ [pm]
216
+ provider = "zoho" # zoho | jira | linear | github | none
217
+ domain = "sa" # com | eu | in | sa | au
218
+ enforce_qa_handoff = true
219
+ forbid_done_status = true
220
+ ```
221
+
222
+ ---
223
+
224
+ ## 🧪 Testing & Verification
225
+
226
+ DroidGuard includes an exhaustive test suite with over 85 unit, integration, and penetration test cases:
227
+
228
+ ```bash
229
+ # Run pytest test suite
230
+ pytest tests/ -v
231
+
232
+ # Run type checker
233
+ mypy src/
234
+
235
+ # Run linter & formatter
236
+ ruff check src/ tests/
237
+ ruff format src/ tests/
238
+ ```
239
+
240
+ ---
241
+
242
+ ## 📄 License
243
+
244
+ DroidGuard is licensed under the [Apache-2.0 License](LICENSE).
@@ -0,0 +1,107 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "droidguard"
7
+ version = "2.0.0"
8
+ description = "Deterministic Android Verification & AI Agent Governance Engine"
9
+ readme = "README.md"
10
+ authors = [{ name = "DroidGuard Contributors" }]
11
+ license = { text = "Apache-2.0" }
12
+ classifiers = [
13
+ "Development Status :: 5 - Production/Stable",
14
+ "Environment :: Console",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: Apache Software License",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Topic :: Software Development :: Build Tools",
24
+ "Topic :: Software Development :: Quality Assurance",
25
+ "Topic :: Software Development :: Testing",
26
+ ]
27
+ keywords = [
28
+ "android",
29
+ "ai-agents",
30
+ "agentic-coding",
31
+ "gradle",
32
+ "governance",
33
+ "roborazzi",
34
+ "konsist",
35
+ "compose",
36
+ "claude-code",
37
+ "cursor",
38
+ "codex",
39
+ ]
40
+ requires-python = ">=3.11"
41
+ dependencies = []
42
+
43
+ [project.optional-dependencies]
44
+ dev = [
45
+ "pytest>=8.0",
46
+ "pytest-cov>=5.0",
47
+ "ruff>=0.5.0",
48
+ "mypy>=1.10.0",
49
+ "build>=1.0.0",
50
+ ]
51
+
52
+ [project.scripts]
53
+ dg = "droidguard.cli.main:entrypoint"
54
+ droidguard = "droidguard.cli.main:entrypoint"
55
+
56
+ [project.urls]
57
+ Homepage = "https://github.com/rabee-elkholy/droidguard"
58
+ Documentation = "https://github.com/rabee-elkholy/droidguard#readme"
59
+ Repository = "https://github.com/rabee-elkholy/droidguard.git"
60
+ Issues = "https://github.com/rabee-elkholy/droidguard/issues"
61
+ Changelog = "https://github.com/rabee-elkholy/droidguard/blob/main/CHANGELOG.md"
62
+
63
+ [tool.setuptools.packages.find]
64
+ where = ["src"]
65
+ include = ["droidguard*"]
66
+
67
+ [tool.setuptools.package-data]
68
+ droidguard = ["py.typed", "config/templates/*"]
69
+
70
+ [tool.ruff]
71
+ line-length = 120
72
+ target-version = "py311"
73
+
74
+ [tool.ruff.lint]
75
+ select = [
76
+ "E", # pycodestyle errors
77
+ "W", # pycodestyle warnings
78
+ "F", # pyflakes
79
+ "I", # isort
80
+ "B", # flake8-bugbear
81
+ "C4", # flake8-comprehensions
82
+ "UP", # pyupgrade
83
+ ]
84
+ ignore = [
85
+ "E501", # line too long (handled by formatter)
86
+ "B008", # do not perform function calls in argument defaults
87
+ ]
88
+
89
+ [tool.mypy]
90
+ python_version = "3.11"
91
+ warn_return_any = true
92
+ warn_unused_configs = true
93
+ disallow_untyped_defs = true
94
+ disallow_incomplete_defs = true
95
+ check_untyped_defs = true
96
+ disallow_untyped_decorators = false
97
+ no_implicit_optional = true
98
+ warn_redundant_casts = true
99
+ warn_unused_ignores = true
100
+ warn_no_return = true
101
+
102
+
103
+ [tool.pytest.ini_options]
104
+ minversion = "8.0"
105
+ addopts = "-ra -q --strict-markers"
106
+ testpaths = ["tests"]
107
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ """DroidGuard — Deterministic Android Verification & AI Agent Governance Engine.
2
+
3
+ Provides fail-closed tool inspection, multi-agent review consensus, supervised
4
+ Gradle execution, multi-locale parity validation, Room schema diff checks,
5
+ Jetpack Compose stability analysis, and unified PM gateways.
6
+ """
7
+
8
+ __version__ = "2.0.0"
9
+ __author__ = "DroidGuard Contributors"
10
+ __license__ = "Apache-2.0"
11
+
12
+ from droidguard._errors import DroidGuardError
13
+
14
+ __all__ = [
15
+ "DroidGuardError",
16
+ "__version__",
17
+ ]