Skip to content

Commit c0770e9

Browse files
Add the AGENTS.md file to support AI tools (#17)
Co-authored-by: Copilot <[email protected]>
1 parent ee56ee6 commit c0770e9

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

AGENTS.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Repository Guidelines
2+
3+
Guidance for AI coding agents (Copilot, Cursor, Aider, Claude, etc.) working in Stream’s Android Core repo. Humans are welcome too; tone is optimised for tools.
4+
5+
### Repository purpose
6+
This project houses **Stream Android Core**, the shared runtime used by Stream Chat, Video, and Feeds SDKs. It concentrates connection/session lifecycle, auth/token plumbing, job orchestration, retry/backoff logic, batching utilities, logging, and other cross-product primitives. Treat it as infrastructure: focus on correctness, binary compatibility, and low regression risk.
7+
8+
### Tech & toolchain
9+
- Language: Kotlin (JVM target 11 inside Gradle; toolchain 17 for builds)
10+
- Android min/target/compile: see `io.getstream.core.Configuration`
11+
- Coroutines: kotlinx 1.8+
12+
- Networking: OkHttp, Retrofit, Moshi (codegen via KSP)
13+
- Build: Gradle Kotlin DSL, shared logic in `buildSrc/`
14+
- Static analysis: Spotless + ktfmt, Detekt, Kotlin explicit-api, Kover coverage
15+
- Tests: JUnit4, MockK, Robolectric, kotlinx-coroutines-test, MockWebServer
16+
17+
## Project structure
18+
- `stream-android-core/` – main library (models, socket/session, token handling, processors, batching, retry, queueing)
19+
- `stream-android-core-annotations/` – annotations + KSP helpers consumed by core
20+
- `stream-android-core-lint/` – lint checks shipped with the library
21+
- `app/` – demo/debug client used for manual verification
22+
- `buildSrc/` – centralised Gradle plugins & configuration (publishing, dependency versions, coverage)
23+
- `config/` – license templates, detekt rules, formatting configs
24+
- `scripts/` – publishing and tooling helpers
25+
26+
> Modules are published; avoid leaking impl-only types across module boundaries without updating versioning docs.
27+
28+
## Build, test, and validation
29+
- Format & headers: `./gradlew spotlessApply`
30+
- Static analysis: `./gradlew detektAll` (or module-specific `:module:detekt`)
31+
- JVM/unit tests (core module): `./gradlew :stream-android-core:test`
32+
- Full verification: `./gradlew check`
33+
- Sample app install: `./gradlew :app:installDebug` (requires device/emulator)
34+
- Coverage: `./gradlew koverHtmlReport`
35+
36+
Prefer running module-scoped tasks when iterating (`:stream-android-core:test`, `:stream-android-core:detekt`) to keep the cycle fast. All public changes should pass `./gradlew check` before PR.
37+
38+
## Coding principles
39+
- **Threading**: Coroutines wrap most workflows; keep blocking I/O off main thread. Respect existing dispatcher usage and structured concurrency.
40+
- **State propagation**: Connection state, batch processing, and retry flows feed `StreamSubscriptionManager`. Maintain idempotency and guard callback ordering (see `StreamSocketSession`).
41+
- **Binary compatibility**: `explicitApi()` is enabled. Avoid signature breaking changes to public/internal APIs without coordinating version bumps.
42+
- **Logging**: Use tagged `StreamLogger`. Keep error logs actionable; avoid leaking secrets/tokens.
43+
- **Configurability**: Many processors expose factories; prefer adding configuration points over ad-hoc branching.
44+
45+
## Style & conventions
46+
- Kotlin official code style (Spotless enforces). 4 spaces, no wildcard imports.
47+
- Limit `internal` surface area; favour private helpers where possible.
48+
- Backtick test names for clarity (``fun `serial queue delivers items in order`()``).
49+
- Public APIs require KDoc; significant internal flows get concise comments explaining the “why” (avoid narrating what the code already states).
50+
- Keep licence headers intact; regenerate via `./gradlew generateLicense` if the year changes.
51+
52+
## Testing guidance
53+
- Unit tests live under each module’s `src/test/java`. Use MockK and coroutines-test to control timing.
54+
- Networking/socket flows: exercise with MockWebServer or fake listeners; ensure heartbeats, retries, and cleanup happen (see `StreamSocketSessionTest`).
55+
- When touching concurrency tools (batcher, single-flight, retry), add deterministic tests that cover edge cases like cancellation, dedupe, and failure retries.
56+
- Prefer lightweight Robolectric tests only when Android primitives are involved; otherwise keep pure JVM.
57+
- Always run `./gradlew :stream-android-core:test` for touched code; broaden to `./gradlew check` before publishing.
58+
59+
## Documentation & comments
60+
- Update `README.md` if you change major workflows or public setup code.
61+
- Keep processor/queue behaviour documented via KDoc or dedicated docs when semantics evolve.
62+
- For new configuration flags or environment expectations, note them in `config/` or module READMEs.
63+
64+
## Security & configuration
65+
- Never hardcode API keys or tokens; samples rely on local `local.properties`/env vars.
66+
- Sanitise logs: token payloads, JWTs, or user IDs should not leak to release logs.
67+
- Be mindful of TLS/OkHttp settings—core is shared across products; changes ripple widely.
68+
69+
## PR & release hygiene
70+
- Commits should be focused and imperative (e.g., `fix(socket): guard reconnect cleanup`).
71+
- Before PR: run Spotless + relevant tests. Include test/task output in the PR description when significant.
72+
- Coordinate with the release owner before modifying publishing metadata or version numbers.
73+
- New APIs require documentation + unit tests; mention migration notes for behavioural changes.
74+
75+
### Quick checklist for agents
76+
- [ ] Understand which module you’re editing and run its tests.
77+
- [ ] Maintain explicit API boundaries; prefer additive changes.
78+
- [ ] Ensure cleanup/teardown paths handle cancellation and failure (important for sockets, queues, retries).
79+
- [ ] Keep concurrency deterministic—use structured coroutines and avoid global scope.
80+
- [ ] Run Spotless (formatting) before finishing.
81+
- [ ] Add tests for new APIs or behaviour changes.
82+
- [ ] Coordinate with the release owner before modifying versioning metadata.
83+
- [ ] Document new APIs and significant changes in `README.md` or module-specific docs.
84+
- [ ] Sanitise logs to avoid leaking sensitive information.

0 commit comments

Comments
 (0)