mobile-ai-agents 1.0.23

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 (194) hide show
  1. package/AGENTS.md +228 -0
  2. package/CLAUDE.md +236 -0
  3. package/LICENSE +21 -0
  4. package/README.md +652 -0
  5. package/agents/android/android-crash-analyzer/README.md +134 -0
  6. package/agents/android/android-crash-analyzer/agent.md +206 -0
  7. package/agents/android/android-crash-analyzer/example-input.md +138 -0
  8. package/agents/android/android-crash-analyzer/example-output.md +225 -0
  9. package/agents/android/anr-investigation/README.md +78 -0
  10. package/agents/android/anr-investigation/agent.md +117 -0
  11. package/agents/android/anr-investigation/example-input.md +62 -0
  12. package/agents/android/anr-investigation/example-output.md +103 -0
  13. package/agents/android/axiom/agent.md +197 -0
  14. package/agents/android/code-reviewer/README.md +108 -0
  15. package/agents/android/code-reviewer/agent.md +210 -0
  16. package/agents/android/code-reviewer/example-input.md +116 -0
  17. package/agents/android/code-reviewer/example-output.md +115 -0
  18. package/agents/android/compose-navigation/README.md +76 -0
  19. package/agents/android/compose-navigation/agent.md +121 -0
  20. package/agents/android/compose-navigation/example-input.md +49 -0
  21. package/agents/android/compose-navigation/example-output.md +325 -0
  22. package/agents/android/compose-screen-builder/README.md +95 -0
  23. package/agents/android/compose-screen-builder/agent.md +170 -0
  24. package/agents/android/compose-screen-builder/example-input.md +40 -0
  25. package/agents/android/compose-screen-builder/example-output.md +568 -0
  26. package/agents/android/compose-ui-reviewer/README.md +73 -0
  27. package/agents/android/compose-ui-reviewer/agent.md +253 -0
  28. package/agents/android/compose-ui-reviewer/example-input.md +84 -0
  29. package/agents/android/compose-ui-reviewer/example-output.md +102 -0
  30. package/agents/android/crash-analyzer/README.md +53 -0
  31. package/agents/android/crash-analyzer/agent.md +295 -0
  32. package/agents/android/memory-leak-analyzer/README.md +79 -0
  33. package/agents/android/memory-leak-analyzer/agent.md +116 -0
  34. package/agents/android/memory-leak-analyzer/example-input.md +78 -0
  35. package/agents/android/memory-leak-analyzer/example-output.md +128 -0
  36. package/agents/cross-platform/accessibility-auditor/README.md +47 -0
  37. package/agents/cross-platform/accessibility-auditor/agent.md +268 -0
  38. package/agents/cross-platform/accessibility-auditor/example-input.md +84 -0
  39. package/agents/cross-platform/accessibility-auditor/example-output.md +132 -0
  40. package/agents/cross-platform/appforge/agent.md +303 -0
  41. package/agents/cross-platform/ci-cd-generator/README.md +65 -0
  42. package/agents/cross-platform/ci-cd-generator/agent.md +422 -0
  43. package/agents/cross-platform/ci-cd-generator/example-input.md +69 -0
  44. package/agents/cross-platform/ci-cd-generator/example-output.md +261 -0
  45. package/agents/cross-platform/crasher/agent.md +221 -0
  46. package/agents/cross-platform/figma/agent.md +247 -0
  47. package/agents/cross-platform/launchpad/agent.md +330 -0
  48. package/agents/cross-platform/mobile-harness/agent.md +422 -0
  49. package/agents/cross-platform/mobile-memory/agent.md +429 -0
  50. package/agents/cross-platform/perf/agent.md +261 -0
  51. package/agents/cross-platform/pipeline/agent.md +288 -0
  52. package/agents/cross-platform/release-notes-generator/README.md +63 -0
  53. package/agents/cross-platform/release-notes-generator/agent.md +218 -0
  54. package/agents/cross-platform/release-notes-generator/example-input.md +71 -0
  55. package/agents/cross-platform/release-notes-generator/example-output.md +96 -0
  56. package/agents/cross-platform/scribe/agent.md +180 -0
  57. package/agents/cross-platform/security-scanner/README.md +61 -0
  58. package/agents/cross-platform/security-scanner/agent.md +287 -0
  59. package/agents/cross-platform/security-scanner/example-input.md +77 -0
  60. package/agents/cross-platform/security-scanner/example-output.md +141 -0
  61. package/agents/cross-platform/sentinel/agent.md +217 -0
  62. package/agents/cross-platform/store-listing-writer/README.md +58 -0
  63. package/agents/cross-platform/store-listing-writer/agent.md +380 -0
  64. package/agents/cross-platform/store-listing-writer/example-input.md +67 -0
  65. package/agents/cross-platform/store-listing-writer/example-output.md +131 -0
  66. package/agents/flutter/bloc-feature-builder/README.md +101 -0
  67. package/agents/flutter/bloc-feature-builder/agent.md +225 -0
  68. package/agents/flutter/bloc-feature-builder/example-input.md +47 -0
  69. package/agents/flutter/bloc-feature-builder/example-output.md +838 -0
  70. package/agents/flutter/dart/agent.md +223 -0
  71. package/agents/flutter/widget-generator/README.md +66 -0
  72. package/agents/flutter/widget-generator/agent.md +264 -0
  73. package/agents/flutter/widget-generator/example-input.md +71 -0
  74. package/agents/flutter/widget-generator/example-output.md +163 -0
  75. package/agents/gaming/forge/agent.md +197 -0
  76. package/agents/gaming/unreal/agent.md +200 -0
  77. package/agents/ios/crash-analyzer/README.md +69 -0
  78. package/agents/ios/crash-analyzer/agent.md +300 -0
  79. package/agents/ios/crash-analyzer/example-input.md +83 -0
  80. package/agents/ios/crash-analyzer/example-output.md +126 -0
  81. package/agents/ios/swift/agent.md +206 -0
  82. package/agents/ios/swift-reviewer/README.md +68 -0
  83. package/agents/ios/swift-reviewer/agent.md +231 -0
  84. package/agents/ios/swift-reviewer/example-input.md +100 -0
  85. package/agents/ios/swift-reviewer/example-output.md +127 -0
  86. package/agents/react-native/bridge/agent.md +212 -0
  87. package/agents/react-native/performance-optimizer/README.md +81 -0
  88. package/agents/react-native/performance-optimizer/agent.md +284 -0
  89. package/agents/react-native/performance-optimizer/example-input.md +104 -0
  90. package/agents/react-native/performance-optimizer/example-output.md +132 -0
  91. package/agents/unity/shader-generator/README.md +77 -0
  92. package/agents/unity/shader-generator/agent.md +270 -0
  93. package/agents/unity/shader-generator/example-input.md +70 -0
  94. package/agents/unity/shader-generator/example-output.md +160 -0
  95. package/agents/unreal/blueprint-advisor/README.md +71 -0
  96. package/agents/unreal/blueprint-advisor/agent.md +311 -0
  97. package/agents/unreal/blueprint-advisor/example-input.md +73 -0
  98. package/agents/unreal/blueprint-advisor/example-output.md +217 -0
  99. package/cli/index.js +1091 -0
  100. package/docs/agent-guide.md +138 -0
  101. package/docs/chatgpt-integration.md +219 -0
  102. package/docs/core-loops.md +143 -0
  103. package/docs/cursor-integration.md +143 -0
  104. package/docs/getting-started.md +132 -0
  105. package/docs/index.html +711 -0
  106. package/docs/installation.md +271 -0
  107. package/docs/mobile-harness.md +160 -0
  108. package/docs/mobile-mcp.md +172 -0
  109. package/docs/mobile-memory.md +349 -0
  110. package/docs/release-process.md +85 -0
  111. package/docs/releases/release-v1.0.0.md +165 -0
  112. package/docs/roadmap/github-issues.md +239 -0
  113. package/docs/skill-categories.md +125 -0
  114. package/docs/vscode-copilot-integration.md +104 -0
  115. package/docs/wiki.md +615 -0
  116. package/install.sh +507 -0
  117. package/mobile-karpathy.md +79 -0
  118. package/package.json +57 -0
  119. package/skills/android/README.md +31 -0
  120. package/skills/android/android-tdd.md +89 -0
  121. package/skills/android/anr-investigation.md +251 -0
  122. package/skills/android/code-review.md +98 -0
  123. package/skills/android/compose-migration.md +48 -0
  124. package/skills/android/compose-review.md +78 -0
  125. package/skills/android/kotlin-modernize.md +51 -0
  126. package/skills/android/memory-leak-investigation.md +256 -0
  127. package/skills/android/proguard-rules.md +48 -0
  128. package/skills/cross-platform/accessibility-audit.md +63 -0
  129. package/skills/cross-platform/api-versioning.md +59 -0
  130. package/skills/cross-platform/clean-code-audit.md +239 -0
  131. package/skills/cross-platform/crash-triage.md +53 -0
  132. package/skills/cross-platform/deeplink-debug.md +57 -0
  133. package/skills/cross-platform/feature-slice.md +48 -0
  134. package/skills/cross-platform/grill-mobile.md +64 -0
  135. package/skills/cross-platform/mobile-mcp-qa.md +193 -0
  136. package/skills/cross-platform/mobile-memory-graph.md +179 -0
  137. package/skills/cross-platform/mobile-memory-save.md +210 -0
  138. package/skills/cross-platform/mobile-memory-search.md +154 -0
  139. package/skills/cross-platform/perf-audit.md +61 -0
  140. package/skills/cross-platform/prd-verification.md +324 -0
  141. package/skills/cross-platform/release-prep.md +64 -0
  142. package/skills/cross-platform/security-audit.md +281 -0
  143. package/skills/cross-platform/store-listing.md +75 -0
  144. package/skills/flutter/README.md +32 -0
  145. package/skills/flutter/dart-modernize.md +47 -0
  146. package/skills/flutter/flutter-review.md +59 -0
  147. package/skills/flutter/flutter-tdd.md +73 -0
  148. package/skills/flutter/widget-extract.md +41 -0
  149. package/skills/flutter/widget-gen.md +131 -0
  150. package/skills/gaming/blueprint-to-cpp.md +51 -0
  151. package/skills/gaming/game-perf.md +54 -0
  152. package/skills/gaming/shader-gen.md +44 -0
  153. package/skills/gaming/unity-tdd.md +85 -0
  154. package/skills/ios/README.md +45 -0
  155. package/skills/ios/data-persistence.md +151 -0
  156. package/skills/ios/ios-tdd.md +90 -0
  157. package/skills/ios/networking.md +139 -0
  158. package/skills/ios/performance.md +122 -0
  159. package/skills/ios/swift-concurrency.md +57 -0
  160. package/skills/ios/swift-review.md +124 -0
  161. package/skills/ios/swiftui-review.md +49 -0
  162. package/skills/ios/swiftui-state.md +122 -0
  163. package/skills/ios/unit-testing.md +144 -0
  164. package/skills/ios/xcode-warnings.md +37 -0
  165. package/skills/react-native/README.md +42 -0
  166. package/skills/react-native/bridge-audit.md +104 -0
  167. package/skills/react-native/expo-optimize.md +55 -0
  168. package/skills/react-native/new-arch-migrate.md +53 -0
  169. package/skills/react-native/performance.md +124 -0
  170. package/skills/react-native/rn-review.md +53 -0
  171. package/skills/react-native/rn-tdd.md +76 -0
  172. package/skills/shared/README.md +46 -0
  173. package/skills/shared/accessibility-audit.md +132 -0
  174. package/skills/shared/crash-analysis.md +110 -0
  175. package/skills/shared/security-scan.md +149 -0
  176. package/skills/unity/README.md +31 -0
  177. package/skills/unity/shader-review.md +110 -0
  178. package/templates/agent-template.md +88 -0
  179. package/templates/prompt-template.md +50 -0
  180. package/templates/skill-template.md +64 -0
  181. package/templates/workflow-template.md +48 -0
  182. package/workflows/app-launch.md +66 -0
  183. package/workflows/appforge-workflow.md +232 -0
  184. package/workflows/ci-setup.md +77 -0
  185. package/workflows/crash-to-fix.md +71 -0
  186. package/workflows/feature-ship.md +61 -0
  187. package/workflows/game-level.md +72 -0
  188. package/workflows/mobile-harness.md +319 -0
  189. package/workflows/mobile-mcp-qa.md +228 -0
  190. package/workflows/mobile-memory-workflow.md +243 -0
  191. package/workflows/new-project-setup.md +93 -0
  192. package/workflows/new-screen.md +68 -0
  193. package/workflows/perf-sprint.md +78 -0
  194. package/workflows/release-cycle.md +71 -0
@@ -0,0 +1,134 @@
1
+ # Android Crash Analyzer Agent
2
+
3
+ > Paste a crash log. Get a root-cause analysis, a production-ready fix, and a testing checklist — in seconds.
4
+
5
+ ---
6
+
7
+ ## What This Agent Does
8
+
9
+ The Android Crash Analyzer reads raw crash logs, ANR traces, and Firebase Crashlytics exports and returns a structured 9-section report:
10
+
11
+ 1. **Crash Summary** — type, severity, reproducibility
12
+ 2. **Root Cause** — what actually went wrong, not just which line
13
+ 3. **Why This Happens** — plain-English explanation for any team member
14
+ 4. **Risk Level** — Critical / High / Medium / Low + affected user estimate
15
+ 5. **Recommended Fix** — step-by-step, lifecycle-aware solution
16
+ 6. **Updated Code** — before/after Kotlin snippets with inline comments
17
+ 7. **Edge Cases** — other places the same bug can hide
18
+ 8. **Testing Checklist** — concrete steps to verify the fix
19
+ 9. **Prevention Tips** — architecture, lint rules, tooling
20
+
21
+ ---
22
+
23
+ ## Supported Crash Types
24
+
25
+ | Category | Examples |
26
+ |---|---|
27
+ | Null & Type | NullPointerException, ClassCastException, IllegalArgumentException |
28
+ | Lifecycle | Fragment not attached, Activity after finish(), View after onDestroyView |
29
+ | Concurrency | GlobalScope leak, UI update off main thread, race condition on shared state |
30
+ | Coroutines | Unhandled exception, wrong dispatcher, missing CoroutineExceptionHandler |
31
+ | RecyclerView | Invalid adapter position, DiffUtil conflict, view holder type mismatch |
32
+ | Memory | OOM from bitmap, leak from static context reference, Handler not cleared |
33
+ | ANR | Main thread blocked by I/O, lock contention, broadcast timeout |
34
+ | Firebase / Crashlytics | Symbolicated and unsymbolicated exports |
35
+ | Custom | Any stack trace you paste — the agent infers the crash type |
36
+
37
+ ---
38
+
39
+ ## Files
40
+
41
+ | File | Purpose |
42
+ |---|---|
43
+ | [`agent.md`](agent.md) | Full agent spec: input format, output format, system prompt |
44
+ | [`example-input.md`](example-input.md) | Real Android crash log ready to paste |
45
+ | [`example-output.md`](example-output.md) | Full 9-section analysis of that crash |
46
+
47
+ ---
48
+
49
+ ## Quick Start
50
+
51
+ ### Claude Code
52
+
53
+ ```
54
+ # In your Claude Code session:
55
+ Use the system prompt from agents/android/android-crash-analyzer/agent.md
56
+ Then paste the input from example-input.md — or replace it with your own crash log.
57
+ ```
58
+
59
+ ### ChatGPT / Cursor
60
+
61
+ 1. Open `agent.md`
62
+ 2. Copy the **System Prompt** section
63
+ 3. Paste it as your first message
64
+ 4. Follow with your crash log using the input format
65
+
66
+ ### Cursor `.cursorrules`
67
+
68
+ The agent rules are already loaded via `.cursorrules` at the repo root. In Cursor Chat:
69
+
70
+ ```
71
+ @agents/android/android-crash-analyzer/agent.md
72
+ Analyze this crash: [paste log]
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Input Format
78
+
79
+ ```
80
+ PLATFORM: Android
81
+ APP_VERSION: <version>
82
+ OS_VERSION: <Android version>
83
+ DEVICE: <device model>
84
+ USER_ACTION: <what the user was doing>
85
+ CRASH_LOG:
86
+ <full stack trace or ANR trace>
87
+ RELATED_CODE: <optional — paste the code around the crash site>
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Output Example
93
+
94
+ See [`example-output.md`](example-output.md) for the full 9-section report.
95
+
96
+ **Preview:**
97
+
98
+ ```
99
+ ## Crash Summary
100
+ IllegalStateException in ProfileFragment.kt:88 when a coroutine posts to a
101
+ LiveData observer after the Fragment is detached. HIGH severity — reproducible
102
+ on slow networks when the user navigates back during a request.
103
+
104
+ ## Root Cause
105
+ viewModelScope survives the Fragment's view lifecycle. When the coroutine
106
+ completes and sets _profile.value, the LiveData observer fires. By then,
107
+ requireContext() throws because the Fragment has no attached context.
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Best Practices
113
+
114
+ - Paste the **full** stack trace — truncated traces miss the first app frame
115
+ - Include `USER_ACTION` — it is the single most useful field for lifecycle crashes
116
+ - For Firebase exports, paste the full event (not just the stack) — metadata matters
117
+ - For ANR traces, paste the complete `traces.txt` file from `/data/anr/`
118
+ - For LeakCanary output, paste the full reference chain
119
+
120
+ ---
121
+
122
+ ## Related Agents
123
+
124
+ - [`agents/android/code-reviewer`](../code-reviewer/) — pre-crash code quality review
125
+ - [`agents/android/compose-ui-reviewer`](../compose-ui-reviewer/) — Compose-specific issues
126
+ - [`agents/ios/crash-analyzer`](../../ios/crash-analyzer/) — same workflow for iOS
127
+
128
+ ---
129
+
130
+ ## Contributing
131
+
132
+ Found a crash type this agent handles poorly? Open an issue using the
133
+ [Bug Report template](../../../.github/ISSUE_TEMPLATE/bug_report.md) and paste the
134
+ anonymized crash log. We'll improve the system prompt and add it as a new example.
@@ -0,0 +1,206 @@
1
+ # Agent — Android Crash Analyzer
2
+
3
+ **Platform:** Android (Kotlin / Java)
4
+ **Category:** Debugging & Crash Analysis
5
+ **Complexity:** Medium
6
+ **Tested With:** Claude Sonnet 4.6, GPT-4o, Gemini 1.5 Pro
7
+
8
+ ---
9
+
10
+ ## Purpose
11
+
12
+ Analyzes Android crash logs, ANR traces, Firebase Crashlytics exports, and LeakCanary reports to produce a structured root-cause analysis with a production-ready fix, before/after code, edge-case coverage, a concrete testing checklist, and prevention tips.
13
+
14
+ ---
15
+
16
+ ## Supported Crash Types
17
+
18
+ - `NullPointerException` — null reference, async result used before load
19
+ - `IllegalStateException` — Fragment not attached, invalid state machine transition
20
+ - `IllegalArgumentException` — bad parameter, mismatched View IDs
21
+ - `IndexOutOfBoundsException` — list modified during iteration, RecyclerView position
22
+ - `ClassCastException` — wrong ViewHolder type, mismatched Parcelable
23
+ - `OutOfMemoryError` — bitmap cache, retained context, large allocation
24
+ - `StackOverflowError` — recursive composable, infinite recomposition trigger
25
+ - `ANR (Application Not Responding)` — main thread blocked by I/O, lock, or broadcast
26
+ - Coroutine crashes — unhandled exception in `launch { }`, wrong dispatcher
27
+ - ViewModel observer bugs — duplicate observers, observer after `onDestroyView`
28
+ - RecyclerView crashes — `RecyclerView.NO_ID`, async list update conflict
29
+ - Memory leaks — LeakCanary reference chains, static Activity context
30
+
31
+ ---
32
+
33
+ ## Input Format
34
+
35
+ ```
36
+ PLATFORM: Android
37
+ APP_VERSION: <e.g. 4.1.2 (build 314)>
38
+ OS_VERSION: <e.g. Android 14 — API 34>
39
+ DEVICE: <e.g. Samsung Galaxy S24 Ultra>
40
+ USER_ACTION: <what the user was doing when the crash occurred>
41
+ CRASH_LOG:
42
+ <paste the full logcat output, Firebase Crashlytics export, ANR trace, or LeakCanary report>
43
+ RELATED_CODE:
44
+ <optional — paste the Kotlin/Java code at or near the crash site>
45
+ ```
46
+
47
+ **Field notes:**
48
+
49
+ | Field | Required | Notes |
50
+ |---|---|---|
51
+ | `PLATFORM` | Yes | Always `Android` |
52
+ | `APP_VERSION` | Yes | Correlate with release history |
53
+ | `OS_VERSION` | No | Narrows OS-specific and API-level bugs |
54
+ | `DEVICE` | No | Narrows OEM-specific bugs (Samsung, Xiaomi, etc.) |
55
+ | `USER_ACTION` | Yes | The single most useful field for lifecycle crashes |
56
+ | `CRASH_LOG` | Yes | Full output — never truncate |
57
+ | `RELATED_CODE` | No | Speeds up analysis; paste the class around the crash line |
58
+
59
+ ---
60
+
61
+ ## Output Format
62
+
63
+ The agent always returns exactly these 9 sections, in order:
64
+
65
+ ```
66
+ ## Crash Summary
67
+ ## Root Cause
68
+ ## Why This Happens
69
+ ## Risk Level
70
+ ## Recommended Fix
71
+ ## Updated Code
72
+ ## Edge Cases
73
+ ## Testing Checklist
74
+ ## Prevention Tips
75
+ ```
76
+
77
+ ### Section Definitions
78
+
79
+ **## Crash Summary**
80
+ 2–3 sentences. Crash type, where it happened, severity, reproducibility.
81
+
82
+ **## Root Cause**
83
+ Precise technical explanation. Not just the crashing line — the sequence of events and state that led to it.
84
+
85
+ **## Why This Happens**
86
+ Plain-English explanation for any developer on the team, including juniors. Analogies encouraged.
87
+
88
+ **## Risk Level**
89
+ One of: `CRITICAL` / `HIGH` / `MEDIUM` / `LOW`
90
+ Include reproducibility (`Always` / `Intermittent` / `Rare`) and an affected-user estimate if volume data is provided.
91
+
92
+ **## Recommended Fix**
93
+ Step-by-step. Every step is a concrete code change, not vague advice. Prefer lifecycle-aware patterns.
94
+
95
+ **## Updated Code**
96
+ ```kotlin
97
+ // Before — problematic code with the issue annotated
98
+ ...
99
+
100
+ // After — corrected code with inline comments explaining key decisions
101
+ ...
102
+ ```
103
+
104
+ **## Edge Cases**
105
+ Bullet list of other scenarios where the same root cause could appear — beyond the specific crash site.
106
+
107
+ **## Testing Checklist**
108
+ Checkboxes. Each step is a specific scenario a developer can reproduce manually or automate.
109
+
110
+ **## Prevention Tips**
111
+ Architectural practices, lint rules, static analysis tools, and code review items that prevent this crash class from recurring.
112
+
113
+ ---
114
+
115
+ ## System Prompt
116
+
117
+ ```
118
+ You are a senior Android crash debugging agent with deep expertise in Kotlin, Java,
119
+ Android lifecycle, Jetpack Architecture Components (ViewModel, LiveData, Navigation),
120
+ Jetpack Compose, Coroutines, Flow, RecyclerView, Room, Hilt, and Firebase Crashlytics.
121
+
122
+ Your job is to analyze Android crash logs and related code exactly as an experienced
123
+ Android principal engineer would in a production incident post-mortem.
124
+
125
+ ANALYSIS PROCESS:
126
+ 1. Identify the exception type or signal (NPE, ISE, ANR, OOM, coroutine exception, etc.)
127
+ 2. Find the FIRST APPLICATION FRAME — skip all system frames:
128
+ android.*, java.*, kotlin.*, kotlinx.*, androidx.*, com.google.*
129
+ The first frame with the app's package name is the origin.
130
+ 3. Read the call chain from bottom (entry point) to top (crash site).
131
+ 4. Identify the USER ACTION or lifecycle event that started the chain.
132
+ 5. Determine the ROOT CAUSE — not just the faulting line, but WHY that state was reached.
133
+ 6. Write a plain-English explanation (Why This Happens) suitable for a junior developer.
134
+ 7. Produce the safest, most lifecycle-aware fix — never suggest workarounds that mask bugs.
135
+ 8. Write BEFORE/AFTER Kotlin code with inline comments on every non-obvious line.
136
+ 9. List EDGE CASES — other places in a typical codebase where the same root cause hides.
137
+ 10. Write a TESTING CHECKLIST with specific, reproducible steps.
138
+ 11. Add PREVENTION TIPS — lint rules, architecture patterns, tooling.
139
+
140
+ PLATFORM-SPECIFIC RULES:
141
+
142
+ Fragment / Activity lifecycle:
143
+ - requireContext() / requireActivity() throws if Fragment is not attached
144
+ - Accessing views after onDestroyView() causes NPE (ViewBinding not nulled out)
145
+ - registering observers in onViewCreated() without removing them accumulates duplicates
146
+ across configuration changes if the LifecycleOwner used is the Fragment (not viewLifecycleOwner)
147
+
148
+ Coroutines:
149
+ - GlobalScope is ALWAYS wrong in Android — use viewModelScope or lifecycleScope
150
+ - launch { } without try/catch or CoroutineExceptionHandler silently crashes the coroutine
151
+ - Posting to LiveData/StateFlow from a non-Main dispatcher crashes with CalledFromWrongThreadException
152
+ - Cancellation exceptions must NOT be caught generically — use catch (e: Exception) { if (e is CancellationException) throw e }
153
+
154
+ RecyclerView:
155
+ - Accessing adapter.getItem(position) inside an onClick that fires after async list update = IOOB
156
+ - ViewHolder types must match: onCreateViewHolder returns type T, onBindViewHolder binds to T
157
+ - DiffUtil running async while adapter is replaced = inconsistency crash
158
+
159
+ Memory:
160
+ - Static reference to Context, View, or Activity = guaranteed leak
161
+ - Inner class (non-static) holds implicit reference to outer Activity
162
+ - Handler posted with postDelayed holds a reference chain to Activity
163
+
164
+ ANR:
165
+ - ANY disk/network I/O on the main thread, even tiny reads, can ANR under load
166
+ - Broadcast receivers have a 10-second execution budget on the main thread
167
+ - ContentProvider.query() on the main thread blocks the UI
168
+
169
+ RULES:
170
+ - Never guess without stating the assumption explicitly
171
+ - If information is missing from the log, state exactly what is missing and what to collect
172
+ - Prefer Kotlin null-safety (?., ?:, let, run) over !! or defensive null checks
173
+ - Prefer repeatOnLifecycle(STARTED) + StateFlow over LiveData observers in new code
174
+ - For coroutine issues: always check scope, dispatcher, exception handling, and cancellation
175
+ - Production fixes must be safe to ship without hotfix risk
176
+
177
+ OUTPUT MUST follow the exact 9-section structure:
178
+ Crash Summary | Root Cause | Why This Happens | Risk Level | Recommended Fix |
179
+ Updated Code | Edge Cases | Testing Checklist | Prevention Tips
180
+
181
+ Do not add extra sections. Do not omit any section. If a section has nothing relevant
182
+ (e.g., no related code for Updated Code), explain why and skip the code block.
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Best Practices for Users
188
+
189
+ 1. **Paste the full stack trace.** Every line matters. Truncated logs miss the origin frame.
190
+ 2. **Always fill `USER_ACTION`.** "The user tapped the back button while the image was uploading" is worth 10 lines of code.
191
+ 3. **Include the `RELATED_CODE` field** when you already know which class is crashing — the agent produces far more accurate `Updated Code` output.
192
+ 4. **For Firebase Crashlytics:** Export the full event JSON, not just the stack. The OS version, memory state, and session ID narrow the root cause significantly.
193
+ 5. **For ANR:** Paste the complete `traces.txt` dump. A single-thread excerpt hides the blocking call.
194
+ 6. **For LeakCanary:** Paste the full reference chain, not just the leaked object.
195
+
196
+ ---
197
+
198
+ ## Common Pitfalls
199
+
200
+ | Pitfall | Effect | Solution |
201
+ |---|---|---|
202
+ | Pasting only the exception line | Agent can't trace the call chain | Paste the full stack including thread header |
203
+ | Omitting `USER_ACTION` | Lifecycle analysis is guesswork | Always describe what the user was doing |
204
+ | Truncating after 20 lines | Cuts the origin frame | Paste everything |
205
+ | Pasting unsymbolicated NDK crash | Hex addresses are unresolvable | Symbolicate first with `ndk-stack` or Firebase |
206
+ | Using `try?` in a workaround | Hides the real bug | Fix the root cause; don't silence exceptions |
@@ -0,0 +1,138 @@
1
+ # Example Input — Android Crash Analyzer
2
+
3
+ This is a real-world crash scenario. Paste this into your LLM session after applying the system prompt from `agent.md`, or replace the `CRASH_LOG` and `RELATED_CODE` sections with your own.
4
+
5
+ ---
6
+
7
+ ```
8
+ PLATFORM: Android
9
+ APP_VERSION: 3.7.1 (build 412)
10
+ OS_VERSION: Android 13 — API 33
11
+ DEVICE: Google Pixel 7
12
+ USER_ACTION: User tapped the back button while the profile photo was uploading. The upload progress dialog was still visible when they navigated back.
13
+
14
+ CRASH_LOG:
15
+ Fatal Exception: java.lang.IllegalStateException: Fragment ProfileFragment{3a1b2c3} (b4c5d6e7-f8a9-0b1c-2d3e-4f5a6b7c8d9e) not attached to a context.
16
+ at androidx.fragment.app.Fragment.requireContext(Fragment.java:947)
17
+ at com.example.socialapp.ui.profile.ProfileFragment.showUploadSuccess(ProfileFragment.kt:124)
18
+ at com.example.socialapp.ui.profile.ProfileFragment$observeViewModel$1.onChanged(ProfileFragment.kt:89)
19
+ at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
20
+ at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
21
+ at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
22
+ at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
23
+ at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
24
+ at android.os.Handler.handleMessage(Handler.java:942)
25
+ at android.os.Looper.loopOnce(Looper.java:201)
26
+ at android.os.Looper.loop(Looper.java:288)
27
+ at android.app.ActivityThread.main(ActivityThread.java:7872)
28
+ at java.lang.reflect.Method.invoke(Method.java)
29
+ at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
30
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
31
+
32
+ RELATED_CODE:
33
+ // ProfileFragment.kt
34
+ class ProfileFragment : Fragment(R.layout.fragment_profile) {
35
+
36
+ private val viewModel: ProfileViewModel by viewModels()
37
+ private var _binding: FragmentProfileBinding? = null
38
+ private val binding get() = _binding!!
39
+
40
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
41
+ super.onViewCreated(view, savedInstanceState)
42
+ _binding = FragmentProfileBinding.bind(view)
43
+
44
+ viewModel.uploadState.observe(this) { state -> // line 89 — observing with 'this' not viewLifecycleOwner
45
+ when (state) {
46
+ is UploadState.Success -> showUploadSuccess(state.photoUrl)
47
+ is UploadState.Error -> showError(state.message)
48
+ else -> Unit
49
+ }
50
+ }
51
+
52
+ binding.uploadButton.setOnClickListener {
53
+ viewModel.uploadPhoto(requireContext(), getSelectedBitmap())
54
+ }
55
+ }
56
+
57
+ private fun showUploadSuccess(photoUrl: String) {
58
+ val ctx = requireContext() // line 124 — throws if Fragment is detached
59
+ Snackbar.make(ctx, binding.root, "Photo updated!", Snackbar.LENGTH_SHORT).show()
60
+ Glide.with(ctx).load(photoUrl).into(binding.avatarImage)
61
+ }
62
+
63
+ override fun onDestroyView() {
64
+ super.onDestroyView()
65
+ _binding = null
66
+ }
67
+ }
68
+
69
+ // ProfileViewModel.kt
70
+ class ProfileViewModel @Inject constructor(
71
+ private val photoRepository: PhotoRepository
72
+ ) : ViewModel() {
73
+
74
+ private val _uploadState = MutableLiveData<UploadState>()
75
+ val uploadState: LiveData<UploadState> = _uploadState
76
+
77
+ fun uploadPhoto(context: Context, bitmap: Bitmap) {
78
+ viewModelScope.launch {
79
+ _uploadState.value = UploadState.Loading
80
+ try {
81
+ val url = photoRepository.uploadPhoto(context, bitmap)
82
+ _uploadState.value = UploadState.Success(url)
83
+ } catch (e: Exception) {
84
+ _uploadState.value = UploadState.Error(e.message ?: "Upload failed")
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ---
92
+
93
+ ## What to Expect
94
+
95
+ Running this input through the crash analyzer agent produces a full 9-section report. See [`example-output.md`](example-output.md) for the complete analysis.
96
+
97
+ **Key issues the agent should identify:**
98
+
99
+ 1. Observer registered with `this` (Fragment) instead of `viewLifecycleOwner` — accumulates duplicate observers across configuration changes and fires after the view is destroyed
100
+ 2. `requireContext()` called inside an observer callback that can fire after the Fragment is detached
101
+ 3. `Context` passed into `ViewModel.uploadPhoto()` — the ViewModel holds a `Context` reference, creating a memory leak
102
+ 4. No `UploadState.Loading` UI feedback cancellation when the user navigates away mid-upload
103
+
104
+ ---
105
+
106
+ ## Variations to Try
107
+
108
+ Replace the crash log to test other scenarios:
109
+
110
+ ### ANR Scenario
111
+ ```
112
+ USER_ACTION: App was open on the home screen. User did nothing for 10 seconds.
113
+ CRASH_LOG:
114
+ ANR in com.example.socialapp (com.example.socialapp/.ui.home.HomeActivity)
115
+ PID: 12345
116
+ Reason: Input dispatching timed out (Waiting to send non-key input event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 2. Wait queue head age: 8510.2ms.)
117
+ ...
118
+ ----- pid 12345 at 2025-05-29 10:30:45 -----
119
+ Cmd line: com.example.socialapp
120
+
121
+ "main" prio=5 tid=1 Blocked
122
+ | group="main" sCount=1 dsCount=0 flags=1 obj=0x71a2b3c4 self=0x71a2b3c5
123
+ | sysTid=12345 nice=-10 cgrp=top-app sched=0/0 handle=0x71a2b3c6
124
+ at com.example.socialapp.data.local.AppDatabase.query(AppDatabase.kt:0)
125
+ - waiting to lock <0x0a1b2c3d> (a com.example.socialapp.data.local.AppDatabase) held by thread 2
126
+ at com.example.socialapp.ui.home.HomeViewModel$loadFeed$1.invokeSuspend(HomeViewModel.kt:45)
127
+ ```
128
+
129
+ ### Coroutine Crash Scenario
130
+ ```
131
+ USER_ACTION: User refreshed the feed by pulling down.
132
+ CRASH_LOG:
133
+ Fatal Exception: kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled
134
+ Caused by: java.net.UnknownHostException: Unable to resolve host "api.socialapp.com": No address associated with hostname
135
+ at com.example.socialapp.data.remote.FeedApi.getFeed(FeedApi.kt:0)
136
+ at com.example.socialapp.data.repository.FeedRepository.refreshFeed(FeedRepository.kt:38)
137
+ at com.example.socialapp.ui.home.HomeViewModel$refresh$1.invokeSuspend(HomeViewModel.kt:52)
138
+ ```