|
| 1 | +<!-- OPENSPEC:START --> |
| 2 | +# OpenSpec Instructions |
| 3 | + |
| 4 | +These instructions are for AI assistants working in this project. |
| 5 | + |
| 6 | +Always open `@/openspec/AGENTS.md` when the request: |
| 7 | +- Mentions planning or proposals (words like proposal, spec, change, plan) |
| 8 | +- Introduces new capabilities, breaking changes, architecture shifts, or big performance/security work |
| 9 | +- Sounds ambiguous and you need the authoritative spec before coding |
| 10 | + |
| 11 | +Use `@/openspec/AGENTS.md` to learn: |
| 12 | +- How to create and apply change proposals |
| 13 | +- Spec format and conventions |
| 14 | +- Project structure and guidelines |
| 15 | + |
| 16 | +Keep this managed block so 'openspec update' can refresh the instructions. |
| 17 | + |
| 18 | +<!-- OPENSPEC:END --> |
| 19 | + |
| 20 | +## 코드 작성 규칙 |
| 21 | + |
| 22 | +### Comments |
| 23 | +- Comments should be written in English as much as possible. |
| 24 | +- Avoid adding unnecessary comments, only use KDoc format. |
| 25 | + |
| 26 | +### Kotlin |
| 27 | +- `companion object`를 추가할 시 클래스 최하단 영역에 추가한다. |
| 28 | +- `try-catch` 문은 최대한 지양하고 `runCatching` 문을 사용하자. |
| 29 | +- Closable 리소스는 `use` 확장함수를 사용해보자. |
| 30 | + |
| 31 | +### Git Commit |
| 32 | +- Git commit 시에는 message의 body는 비운채로 커밋해야한다. |
| 33 | + |
| 34 | +## 기능 구현 체크리스트 (Feature Implementation Checklist) |
| 35 | + |
| 36 | +- 모든 기능 구현 Spec에 대해 다음 문서들의 최신화 작업을 포함해야 합니다: |
| 37 | + - `@docs/**` (API 문서, 가이드 등) |
| 38 | + - `@README.md` |
| 39 | + - 한국어 문서 (`README-ko.md` 등) |
| 40 | +- 기능 구현 작업 시 `@example/showcase/**` 앱에도 해당 기능을 시연할 수 있도록 업데이트해야 합니다. |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +<!-- Generated: 2026-02-13 --> |
| 45 | + |
| 46 | +# React Native Nitro Device Info - Monorepo Guide |
| 47 | + |
| 48 | +## Purpose |
| 49 | + |
| 50 | +Monorepo for `react-native-nitro-device-info` (v1.5.1), a high-performance React Native library providing 80+ device information properties through Nitro's zero-overhead JSI bindings. Implements native code in Swift (iOS) and Kotlin (Android). |
| 51 | + |
| 52 | +## Key Files |
| 53 | + |
| 54 | +| File | Description | |
| 55 | +|------|-------------| |
| 56 | +| `package.json` | Monorepo root with workspace definitions and shared scripts | |
| 57 | +| `turbo.json` | Turborepo configuration for build caching and task orchestration | |
| 58 | +| `.nvmrc` | Node.js version (20) | |
| 59 | +| `.yarnrc.yml` | Yarn 3.6.1 configuration with PnP mode | |
| 60 | +| `tsconfig.json` | Root TypeScript configuration | |
| 61 | +| `README.md` | Main project documentation | |
| 62 | +| `CONTRIBUTING.md` | Development workflow and guidelines | |
| 63 | +| `CLAUDE.md` | Project-specific AI assistant instructions | |
| 64 | +| `API-REFERENCE.md` | Complete API documentation for all 100+ methods | |
| 65 | + |
| 66 | +## Subdirectories |
| 67 | + |
| 68 | +| Directory | Purpose | |
| 69 | +|-----------|---------| |
| 70 | +| `packages/react-native-nitro-device-info/` | Main library (see `packages/react-native-nitro-device-info/AGENTS.md`) | |
| 71 | +| `packages/mcp-server/` | MCP server for AI tools (see `packages/mcp-server/AGENTS.md`) | |
| 72 | +| `example/showcase/` | Demo app displaying all properties (see `example/showcase/AGENTS.md`) | |
| 73 | +| `example/benchmark/` | Performance benchmark app (see `example/benchmark/AGENTS.md`) | |
| 74 | +| `docs/` | Rspress documentation site (see `docs/AGENTS.md`) | |
| 75 | +| `specs/` | Archived feature specifications (see `specs/AGENTS.md`) | |
| 76 | +| `openspec/` | OpenSpec change management system (see `openspec/AGENTS.md`) | |
| 77 | +| `.github/` | CI/CD workflows (see `.github/AGENTS.md`) | |
| 78 | + |
| 79 | +## For AI Agents |
| 80 | + |
| 81 | +### Working In This Directory |
| 82 | + |
| 83 | +**Architecture Overview**: |
| 84 | +1. This is a **Nitro Module** - uses JSI for zero-overhead native communication |
| 85 | +2. API surface defined in `packages/react-native-nitro-device-info/src/DeviceInfo.nitro.ts` |
| 86 | +3. Native: `ios/DeviceInfo.swift` (iOS) and `android/.../DeviceInfo.kt` (Android) |
| 87 | +4. **Nitrogen codegen**: Always run `yarn nitrogen` after modifying `.nitro.ts` files |
| 88 | + |
| 89 | +**Development Workflow**: |
| 90 | +1. Modify API in `DeviceInfo.nitro.ts` |
| 91 | +2. Run `yarn nitrogen` (generates C++/Java/Swift boilerplate) |
| 92 | +3. Implement native code in Swift (iOS) and Kotlin (Android) |
| 93 | +4. Run `yarn prepare` to build library |
| 94 | +5. Test in showcase/benchmark apps |
| 95 | +6. Update docs (`API-REFERENCE.md`, `docs/`, `README.md`, showcase app) |
| 96 | +7. Verify: `yarn typecheck`, `yarn lint`, `yarn test` |
| 97 | + |
| 98 | +**File Rules**: |
| 99 | +- **Never** edit files in `nitrogen/generated/` or `lib/` (auto-generated) |
| 100 | +- For significant changes, create an OpenSpec proposal first (`openspec/AGENTS.md`) |
| 101 | + |
| 102 | +### Testing Requirements |
| 103 | + |
| 104 | +1. `yarn typecheck` - TypeScript validation |
| 105 | +2. `yarn lint` - oxlint validation |
| 106 | +3. `yarn test` - Jest unit tests |
| 107 | +4. Test in both showcase and benchmark apps |
| 108 | +5. Verify on both iOS and Android if native code changed |
| 109 | + |
| 110 | +### Common Patterns |
| 111 | + |
| 112 | +**Adding a New Property**: |
| 113 | +```typescript |
| 114 | +// 1. DeviceInfo.nitro.ts |
| 115 | +readonly newProperty: string |
| 116 | + |
| 117 | +// 2. yarn nitrogen |
| 118 | + |
| 119 | +// 3. iOS (DeviceInfo.swift) |
| 120 | +public var newProperty: String { return "value" } |
| 121 | + |
| 122 | +// 4. Android (DeviceInfo.kt) |
| 123 | +override val newProperty: String get() = "value" |
| 124 | +``` |
| 125 | + |
| 126 | +**Adding an Async Method**: |
| 127 | +```typescript |
| 128 | +// 1. DeviceInfo.nitro.ts |
| 129 | +getNewInfo(): Promise<string> |
| 130 | + |
| 131 | +// 2. yarn nitrogen |
| 132 | + |
| 133 | +// 3. iOS |
| 134 | +public func getNewInfo() -> Promise<String> { |
| 135 | + return Promise.async { return "value" } |
| 136 | +} |
| 137 | + |
| 138 | +// 4. Android |
| 139 | +override fun getNewInfo(): Promise<String> = Promise.async { "value" } |
| 140 | +``` |
| 141 | + |
| 142 | +### Dependencies |
| 143 | + |
| 144 | +**Runtime**: `react-native-nitro-modules@0.31.2` (peer dependency) |
| 145 | + |
| 146 | +**Development**: `yarn@3.6.1`, `node@20`, `typescript@5.9.2`, `nitrogen@0.31.2`, `turbo@2.6.2`, `oxlint@1.24.0`, `jest@30.0.0`, `commitlint@20.1.0` |
| 147 | + |
| 148 | +**Native**: iOS Swift 5.9+ (UIKit, Foundation, Combine), Android Kotlin 1.9+ (kotlinx-coroutines 1.7.3) |
| 149 | + |
| 150 | +### Common Commands |
| 151 | + |
| 152 | +```bash |
| 153 | +yarn # Install dependencies |
| 154 | +yarn nitrogen # Generate native bindings |
| 155 | +yarn prepare # Build library |
| 156 | +yarn typecheck # TypeScript validation |
| 157 | +yarn lint # Linting |
| 158 | +yarn test # Jest tests |
| 159 | +yarn showcase ios # Run showcase on iOS |
| 160 | +yarn showcase android # Run showcase on Android |
| 161 | +yarn benchmark ios # Run benchmark on iOS |
| 162 | +yarn clean # Clean build artifacts |
| 163 | +``` |
| 164 | + |
| 165 | +### Important Notes |
| 166 | + |
| 167 | +1. **Nitro Codegen**: After any `.nitro.ts` change, run `yarn nitrogen` or build fails |
| 168 | +2. **Documentation is Mandatory**: All features must update API-REFERENCE.md, docs/, README.md, and showcase app |
| 169 | +3. **Platform Support**: iOS 13.4+, Android API 24+ |
| 170 | +4. **Commit Conventions**: Conventional commits with empty body (enforced by commitlint) |
| 171 | +5. **OpenSpec Proposals**: Required for new capabilities, breaking changes, architecture shifts |
| 172 | + |
| 173 | +<!-- MANUAL: Any manually added notes below this line are preserved on regeneration --> |
0 commit comments