cc-codeconductor 0.2.10 → 0.3.1

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 (63) hide show
  1. package/README.md +5 -4
  2. package/dist/index.js +1636 -1078
  3. package/package.json +1 -1
  4. package/presets/agy/AGENTS.md +46 -2
  5. package/presets/claude/CLAUDE.md +62 -2
  6. package/presets/claude/skills/android/SKILL.md +119 -0
  7. package/presets/claude/skills/laravel-specialist/SKILL.md +264 -0
  8. package/presets/claude/skills/laravel-specialist/references/eloquent.md +351 -0
  9. package/presets/claude/skills/laravel-specialist/references/livewire.md +512 -0
  10. package/presets/claude/skills/laravel-specialist/references/queues.md +423 -0
  11. package/presets/claude/skills/laravel-specialist/references/routing.md +362 -0
  12. package/presets/claude/skills/laravel-specialist/references/testing.md +522 -0
  13. package/presets/claude/skills/php-pro/SKILL.md +208 -0
  14. package/presets/claude/skills/php-pro/references/async-patterns.md +412 -0
  15. package/presets/claude/skills/php-pro/references/laravel-patterns.md +377 -0
  16. package/presets/claude/skills/php-pro/references/modern-php-features.md +323 -0
  17. package/presets/claude/skills/php-pro/references/symfony-patterns.md +466 -0
  18. package/presets/claude/skills/php-pro/references/testing-quality.md +466 -0
  19. package/presets/codex/AGENTS.md +47 -2
  20. package/presets/codex/skills/android/SKILL.md +119 -0
  21. package/presets/codex/skills/laravel-specialist/SKILL.md +264 -0
  22. package/presets/codex/skills/laravel-specialist/references/eloquent.md +351 -0
  23. package/presets/codex/skills/laravel-specialist/references/livewire.md +512 -0
  24. package/presets/codex/skills/laravel-specialist/references/queues.md +423 -0
  25. package/presets/codex/skills/laravel-specialist/references/routing.md +362 -0
  26. package/presets/codex/skills/laravel-specialist/references/testing.md +522 -0
  27. package/presets/codex/skills/php-pro/SKILL.md +208 -0
  28. package/presets/codex/skills/php-pro/references/async-patterns.md +412 -0
  29. package/presets/codex/skills/php-pro/references/laravel-patterns.md +377 -0
  30. package/presets/codex/skills/php-pro/references/modern-php-features.md +323 -0
  31. package/presets/codex/skills/php-pro/references/symfony-patterns.md +466 -0
  32. package/presets/codex/skills/php-pro/references/testing-quality.md +466 -0
  33. package/presets/opencode/agents/implementer.md +2 -2
  34. package/presets/opencode/agents/orchestrator.md +132 -5
  35. package/presets/opencode/agents/reviewer.md +33 -0
  36. package/presets/opencode/prompts/v0.3.0/architect.md +221 -0
  37. package/presets/opencode/prompts/v0.3.0/docs.md +189 -0
  38. package/presets/opencode/prompts/v0.3.0/implementer.md +162 -0
  39. package/presets/opencode/prompts/v0.3.0/orchestrator.md +360 -0
  40. package/presets/opencode/prompts/v0.3.0/repo-explorer.md +110 -0
  41. package/presets/opencode/prompts/v0.3.0/reviewer.md +225 -0
  42. package/presets/opencode/prompts/v0.3.0/task-coach.md +155 -0
  43. package/presets/opencode/prompts/v0.3.0/tester.md +251 -0
  44. package/presets/opencode/skills/android/SKILL.md +119 -0
  45. package/presets/opencode/skills/laravel-specialist/SKILL.md +264 -0
  46. package/presets/opencode/skills/laravel-specialist/references/eloquent.md +351 -0
  47. package/presets/opencode/skills/laravel-specialist/references/livewire.md +512 -0
  48. package/presets/opencode/skills/laravel-specialist/references/queues.md +423 -0
  49. package/presets/opencode/skills/laravel-specialist/references/routing.md +362 -0
  50. package/presets/opencode/skills/laravel-specialist/references/testing.md +522 -0
  51. package/presets/opencode/skills/php-pro/SKILL.md +208 -0
  52. package/presets/opencode/skills/php-pro/references/async-patterns.md +412 -0
  53. package/presets/opencode/skills/php-pro/references/laravel-patterns.md +377 -0
  54. package/presets/opencode/skills/php-pro/references/modern-php-features.md +323 -0
  55. package/presets/opencode/skills/php-pro/references/symfony-patterns.md +466 -0
  56. package/presets/opencode/skills/php-pro/references/testing-quality.md +466 -0
  57. package/src/presets/manifests/agy.yml +3 -2
  58. package/src/presets/manifests/claude.yml +3 -2
  59. package/src/presets/manifests/codex.yml +3 -2
  60. package/src/presets/manifests/cursor.yml +3 -2
  61. package/src/presets/manifests/gemini.yml +3 -2
  62. package/src/presets/manifests/opencode.yml +3 -2
  63. package/src/presets/models/opencode.yml +6 -6
@@ -0,0 +1,466 @@
1
+ # Testing & Quality Assurance
2
+
3
+ ## PHPUnit with Strict Types
4
+
5
+ ```php
6
+ <?php
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Tests\Unit\Service;
11
+
12
+ use App\Repository\UserRepositoryInterface;
13
+ use App\Service\UserService;
14
+ use App\Service\EmailService;
15
+ use PHPUnit\Framework\TestCase;
16
+ use PHPUnit\Framework\MockObject\MockObject;
17
+
18
+ final class UserServiceTest extends TestCase
19
+ {
20
+ private UserRepositoryInterface&MockObject $userRepository;
21
+ private EmailService&MockObject $emailService;
22
+ private UserService $userService;
23
+
24
+ protected function setUp(): void
25
+ {
26
+ $this->userRepository = $this->createMock(UserRepositoryInterface::class);
27
+ $this->emailService = $this->createMock(EmailService::class);
28
+ $this->userService = new UserService(
29
+ $this->userRepository,
30
+ $this->emailService
31
+ );
32
+ }
33
+
34
+ public function testCreateUserSuccessfully(): void
35
+ {
36
+ $email = 'test@example.com';
37
+ $password = 'SecurePass123!';
38
+
39
+ $this->userRepository
40
+ ->expects($this->once())
41
+ ->method('findByEmail')
42
+ ->with($email)
43
+ ->willReturn(null);
44
+
45
+ $this->userRepository
46
+ ->expects($this->once())
47
+ ->method('create')
48
+ ->willReturn($this->createUser($email));
49
+
50
+ $this->emailService
51
+ ->expects($this->once())
52
+ ->method('sendWelcomeEmail');
53
+
54
+ $user = $this->userService->createUser($email, $password);
55
+
56
+ $this->assertSame($email, $user->email);
57
+ }
58
+
59
+ public function testCreateUserThrowsExceptionWhenEmailExists(): void
60
+ {
61
+ $this->expectException(\DomainException::class);
62
+ $this->expectExceptionMessage('Email already exists');
63
+
64
+ $this->userRepository
65
+ ->method('findByEmail')
66
+ ->willReturn($this->createUser('test@example.com'));
67
+
68
+ $this->userService->createUser('test@example.com', 'password');
69
+ }
70
+
71
+ private function createUser(string $email): User
72
+ {
73
+ return new User(
74
+ id: 1,
75
+ email: $email,
76
+ password: password_hash('password', PASSWORD_ARGON2ID),
77
+ );
78
+ }
79
+ }
80
+ ```
81
+
82
+ ## Data Providers
83
+
84
+ ```php
85
+ <?php
86
+
87
+ declare(strict_types=1);
88
+
89
+ namespace Tests\Unit\Validator;
90
+
91
+ use App\Validator\EmailValidator;
92
+ use PHPUnit\Framework\Attributes\DataProvider;
93
+ use PHPUnit\Framework\Attributes\Test;
94
+ use PHPUnit\Framework\TestCase;
95
+
96
+ final class EmailValidatorTest extends TestCase
97
+ {
98
+ #[Test]
99
+ #[DataProvider('validEmailProvider')]
100
+ public function itValidatesCorrectEmails(string $email): void
101
+ {
102
+ $validator = new EmailValidator();
103
+ $this->assertTrue($validator->isValid($email));
104
+ }
105
+
106
+ #[Test]
107
+ #[DataProvider('invalidEmailProvider')]
108
+ public function itRejectsInvalidEmails(string $email): void
109
+ {
110
+ $validator = new EmailValidator();
111
+ $this->assertFalse($validator->isValid($email));
112
+ }
113
+
114
+ public static function validEmailProvider(): array
115
+ {
116
+ return [
117
+ ['user@example.com'],
118
+ ['john.doe@company.co.uk'],
119
+ ['test+filter@domain.org'],
120
+ ];
121
+ }
122
+
123
+ public static function invalidEmailProvider(): array
124
+ {
125
+ return [
126
+ ['invalid'],
127
+ ['@example.com'],
128
+ ['user@'],
129
+ ['user space@example.com'],
130
+ ];
131
+ }
132
+ }
133
+ ```
134
+
135
+ ## Laravel Feature Tests
136
+
137
+ ```php
138
+ <?php
139
+
140
+ declare(strict_types=1);
141
+
142
+ namespace Tests\Feature;
143
+
144
+ use App\Models\User;
145
+ use Illuminate\Foundation\Testing\RefreshDatabase;
146
+ use Illuminate\Foundation\Testing\WithFaker;
147
+ use Tests\TestCase;
148
+
149
+ final class UserControllerTest extends TestCase
150
+ {
151
+ use RefreshDatabase, WithFaker;
152
+
153
+ public function testUserCanViewTheirProfile(): void
154
+ {
155
+ $user = User::factory()->create();
156
+
157
+ $response = $this->actingAs($user)->get('/api/users/me');
158
+
159
+ $response->assertOk()
160
+ ->assertJson([
161
+ 'data' => [
162
+ 'id' => $user->id,
163
+ 'email' => $user->email,
164
+ ],
165
+ ]);
166
+ }
167
+
168
+ public function testUserCanUpdateTheirProfile(): void
169
+ {
170
+ $user = User::factory()->create();
171
+ $newName = $this->faker->name();
172
+
173
+ $response = $this->actingAs($user)->putJson('/api/users/me', [
174
+ 'name' => $newName,
175
+ ]);
176
+
177
+ $response->assertOk();
178
+
179
+ $this->assertDatabaseHas('users', [
180
+ 'id' => $user->id,
181
+ 'name' => $newName,
182
+ ]);
183
+ }
184
+
185
+ public function testUnauthorizedUserCannotAccessProfile(): void
186
+ {
187
+ $response = $this->getJson('/api/users/me');
188
+
189
+ $response->assertUnauthorized();
190
+ }
191
+
192
+ public function testValidationFailsWithInvalidData(): void
193
+ {
194
+ $user = User::factory()->create();
195
+
196
+ $response = $this->actingAs($user)->putJson('/api/users/me', [
197
+ 'email' => 'not-an-email',
198
+ ]);
199
+
200
+ $response->assertUnprocessable()
201
+ ->assertJsonValidationErrors(['email']);
202
+ }
203
+ }
204
+ ```
205
+
206
+ ## Pest Testing (Modern Alternative)
207
+
208
+ ```php
209
+ <?php
210
+
211
+ declare(strict_types=1);
212
+
213
+ use App\Models\User;
214
+ use App\Services\UserService;
215
+
216
+ beforeEach(function () {
217
+ $this->userService = app(UserService::class);
218
+ });
219
+
220
+ it('creates a user successfully', function () {
221
+ $user = $this->userService->createUser(
222
+ email: 'test@example.com',
223
+ password: 'SecurePass123!'
224
+ );
225
+
226
+ expect($user)
227
+ ->toBeInstanceOf(User::class)
228
+ ->email->toBe('test@example.com');
229
+ });
230
+
231
+ it('validates email format', function (string $email, bool $valid) {
232
+ $validator = new EmailValidator();
233
+
234
+ expect($validator->isValid($email))->toBe($valid);
235
+ })->with([
236
+ ['test@example.com', true],
237
+ ['invalid', false],
238
+ ['@example.com', false],
239
+ ]);
240
+
241
+ test('authenticated user can view profile', function () {
242
+ $user = User::factory()->create();
243
+
244
+ $this->actingAs($user)
245
+ ->get('/api/users/me')
246
+ ->assertOk()
247
+ ->assertJson(['data' => ['email' => $user->email]]);
248
+ });
249
+
250
+ test('guest cannot access protected routes', function () {
251
+ $this->getJson('/api/users/me')
252
+ ->assertUnauthorized();
253
+ });
254
+ ```
255
+
256
+ ## PHPStan Configuration
257
+
258
+ ```neon
259
+ # phpstan.neon
260
+ parameters:
261
+ level: 9
262
+ paths:
263
+ - src
264
+ - tests
265
+ excludePaths:
266
+ - src/bootstrap.php
267
+ - vendor
268
+ checkMissingIterableValueType: true
269
+ checkGenericClassInNonGenericObjectType: true
270
+ reportUnmatchedIgnoredErrors: true
271
+ tmpDir: var/cache/phpstan
272
+
273
+ ignoreErrors:
274
+ # Ignore specific Laravel magic
275
+ - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder#'
276
+
277
+ type_coverage:
278
+ return_type: 100
279
+ param_type: 100
280
+ property_type: 100
281
+
282
+ includes:
283
+ - vendor/phpstan/phpstan-strict-rules/rules.neon
284
+ - vendor/phpstan/phpstan-deprecation-rules/rules.neon
285
+ ```
286
+
287
+ ## PHPStan Annotations
288
+
289
+ ```php
290
+ <?php
291
+
292
+ declare(strict_types=1);
293
+
294
+ namespace App\Repository;
295
+
296
+ use App\Entity\User;
297
+ use Doctrine\ORM\EntityRepository;
298
+
299
+ /**
300
+ * @extends EntityRepository<User>
301
+ */
302
+ final class UserRepository extends EntityRepository
303
+ {
304
+ /**
305
+ * @return User[]
306
+ */
307
+ public function findActive(): array
308
+ {
309
+ return $this->createQueryBuilder('u')
310
+ ->where('u.status = :status')
311
+ ->setParameter('status', 'active')
312
+ ->getQuery()
313
+ ->getResult();
314
+ }
315
+
316
+ /**
317
+ * @param int[] $ids
318
+ * @return User[]
319
+ */
320
+ public function findByIds(array $ids): array
321
+ {
322
+ return $this->createQueryBuilder('u')
323
+ ->where('u.id IN (:ids)')
324
+ ->setParameter('ids', $ids)
325
+ ->getQuery()
326
+ ->getResult();
327
+ }
328
+ }
329
+
330
+ /**
331
+ * @template T
332
+ */
333
+ final readonly class Result
334
+ {
335
+ /**
336
+ * @param T $data
337
+ */
338
+ public function __construct(
339
+ public mixed $data,
340
+ public bool $success,
341
+ ) {}
342
+
343
+ /**
344
+ * @return T
345
+ */
346
+ public function getData(): mixed
347
+ {
348
+ return $this->data;
349
+ }
350
+ }
351
+ ```
352
+
353
+ ## Mockery (Advanced Mocking)
354
+
355
+ ```php
356
+ <?php
357
+
358
+ declare(strict_types=1);
359
+
360
+ namespace Tests\Unit\Service;
361
+
362
+ use App\Repository\UserRepository;
363
+ use App\Service\NotificationService;
364
+ use Mockery;
365
+ use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
366
+ use PHPUnit\Framework\TestCase;
367
+
368
+ final class NotificationServiceTest extends TestCase
369
+ {
370
+ use MockeryPHPUnitIntegration;
371
+
372
+ public function testSendsNotificationToActiveUsers(): void
373
+ {
374
+ $repository = Mockery::mock(UserRepository::class);
375
+ $repository->shouldReceive('findActive')
376
+ ->once()
377
+ ->andReturn([
378
+ $this->createUser('user1@example.com'),
379
+ $this->createUser('user2@example.com'),
380
+ ]);
381
+
382
+ $service = new NotificationService($repository);
383
+ $result = $service->notifyActiveUsers('Important message');
384
+
385
+ $this->assertSame(2, $result->count());
386
+ }
387
+
388
+ public function testHandlesEmailServiceFailure(): void
389
+ {
390
+ $emailService = Mockery::mock(EmailService::class);
391
+ $emailService->shouldReceive('send')
392
+ ->once()
393
+ ->andThrow(new \RuntimeException('Email service down'));
394
+
395
+ $service = new NotificationService($emailService);
396
+
397
+ $this->expectException(\RuntimeException::class);
398
+ $service->sendNotification('test@example.com', 'Hello');
399
+ }
400
+
401
+ private function createUser(string $email): User
402
+ {
403
+ return new User(id: 1, email: $email, password: 'hashed');
404
+ }
405
+ }
406
+ ```
407
+
408
+ ## Code Coverage
409
+
410
+ ```xml
411
+ <!-- phpunit.xml -->
412
+ <?xml version="1.0" encoding="UTF-8"?>
413
+ <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
414
+ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
415
+ bootstrap="vendor/autoload.php"
416
+ colors="true"
417
+ failOnRisky="true"
418
+ failOnWarning="true"
419
+ stopOnFailure="false">
420
+ <testsuites>
421
+ <testsuite name="Unit">
422
+ <directory>tests/Unit</directory>
423
+ </testsuite>
424
+ <testsuite name="Feature">
425
+ <directory>tests/Feature</directory>
426
+ </testsuite>
427
+ </testsuites>
428
+ <coverage>
429
+ <include>
430
+ <directory suffix=".php">src</directory>
431
+ </include>
432
+ <exclude>
433
+ <directory>src/bootstrap</directory>
434
+ <file>src/Kernel.php</file>
435
+ </exclude>
436
+ <report>
437
+ <html outputDirectory="coverage/html"/>
438
+ <clover outputFile="coverage/clover.xml"/>
439
+ </report>
440
+ </coverage>
441
+ <php>
442
+ <env name="APP_ENV" value="testing"/>
443
+ <env name="DB_CONNECTION" value="sqlite"/>
444
+ <env name="DB_DATABASE" value=":memory:"/>
445
+ </php>
446
+ </phpunit>
447
+ ```
448
+
449
+ ## Quick Reference
450
+
451
+ | Tool | Purpose | Command |
452
+ |------|---------|---------|
453
+ | PHPUnit | Unit/Feature tests | `./vendor/bin/phpunit` |
454
+ | Pest | Modern testing | `./vendor/bin/pest` |
455
+ | PHPStan | Static analysis | `./vendor/bin/phpstan analyse` |
456
+ | Psalm | Alternative static analysis | `./vendor/bin/psalm` |
457
+ | PHP-CS-Fixer | Code style | `./vendor/bin/php-cs-fixer fix` |
458
+ | PHPMD | Mess detector | `./vendor/bin/phpmd src text cleancode` |
459
+
460
+ | Assertion | PHPUnit | Pest |
461
+ |-----------|---------|------|
462
+ | Equality | `$this->assertSame()` | `expect()->toBe()` |
463
+ | Type | `$this->assertInstanceOf()` | `expect()->toBeInstanceOf()` |
464
+ | Array | `$this->assertContains()` | `expect()->toContain()` |
465
+ | Exception | `$this->expectException()` | `expect()->toThrow()` |
466
+ | Count | `$this->assertCount()` | `expect()->toHaveCount()` |
@@ -8,6 +8,24 @@ project root as `AGENTS.md` (or merge it into an existing `AGENTS.md`).
8
8
  Codex reads `AGENTS.md` recursively from the project root. All agent roles are
9
9
  embedded here as workflow instructions.
10
10
 
11
+ ## Behavioral Discipline
12
+
13
+ These principles apply to **all agents** in every workflow. They reduce common
14
+ LLM coding mistakes and bias toward caution over speed.
15
+
16
+ 1. **Think Before Coding** — State assumptions explicitly. If uncertain, ask. If
17
+ multiple interpretations exist, present them — don't pick silently. If a
18
+ simpler approach exists, say so.
19
+ 2. **Simplicity First** — Minimum code that solves the problem. No features
20
+ beyond what was asked. No abstractions for single-use code. No speculative
21
+ "flexibility." Ask: "Would a senior engineer say this is overcomplicated?"
22
+ 3. **Surgical Changes** — Touch only what you must. Don't "improve" adjacent
23
+ code. Match existing style. Remove only what YOUR changes made unused. Every
24
+ changed line must trace directly to the user's request.
25
+ 4. **Goal-Driven Execution** — Transform tasks into verifiable goals with
26
+ success criteria. For multi-step tasks, state a plan with verification
27
+ checks. Loop until verified.
28
+
11
29
  ---
12
30
 
13
31
  ## Workflow Contract
@@ -111,8 +129,13 @@ a complete plan before implementation.
111
129
  1. Validate the Task Card before doing anything else.
112
130
  2. Classify the risk level using the table above.
113
131
  3. Select and document the agent route.
114
- 4. Surface blockers rather than working around them.
115
- 5. Declare completion only when all Deliverables are produced and verified.
132
+ 4. Enforce **Behavioral Discipline Gates**:
133
+ - **Think Before Coding Checkpoint**: Verify assumptions are explicitly documented before architect starts.
134
+ - **Simplicity Gate**: Review Technical Plan to ensure no speculative code or abstractions are planned.
135
+ - **Surgical Changes Audit**: Audit reviewer report and diff to verify only planned files were modified.
136
+ - **Goal-Driven Verification**: Confirm all acceptance criteria have passing tests.
137
+ 5. Surface blockers rather than working around them.
138
+ 6. Declare completion only when all Deliverables are produced and verified.
116
139
 
117
140
  **Task Card validation — required fields before routing:**
118
141
 
@@ -400,6 +423,7 @@ tests.
400
423
  module structure already present in the codebase.
401
424
  - **No scope creep.** If the plan says "add one endpoint," add one endpoint.
402
425
  - **Run tests before declaring done.** If any test fails, investigate and fix.
426
+ - **Surgical Changes.** Modify ONLY planned files. Do not improve adjacent code, comments, or formatting. Match existing style. Remove imports/variables/functions made unused by YOUR changes. Do not touch existing dead code.
403
427
 
404
428
  **Completion Summary format:**
405
429
 
@@ -527,6 +551,8 @@ changes.
527
551
  | Error handling | Are failure cases handled explicitly and safely? |
528
552
  | Test coverage | Do the tests verify all acceptance criteria? |
529
553
  | Technical debt | Does the implementation introduce debt without acknowledging it? |
554
+ | Simplicity | Flag overcomplicated or speculative code (overbuilt patterns). |
555
+ | Surgical | Verify that NO adjacent or unrelated code/comments were changed. |
530
556
 
531
557
  **Finding categories:**
532
558
 
@@ -819,6 +845,13 @@ Available skills:
819
845
  | `django-testing` | Django test patterns, tenant-aware testing |
820
846
  | `python-fastapi-stack` | FastAPI routers, endpoints, schemas |
821
847
  | `sqlalchemy` | SQLAlchemy models, sessions, Alembic migrations |
848
+ | `nextjs-typescript` | Next.js components, Server Actions, App Router |
849
+ | `astro` | Astro pages, islands, content collections |
850
+ | `android` | Android Kotlin, Jetpack Compose, Media3 components |
851
+ | `laravel-specialist` | Laravel models, routes, API resources, Livewire |
852
+ | `php-pro` | PHPStan static analysis, modern PHP 8.3+ features |
853
+ | `security` | Backend security, authorization, data validation |
854
+ | `a11y-debugging` | Debugging frontend accessibility and web standards |
822
855
 
823
856
  To activate a skill, include in your request:
824
857
 
@@ -831,6 +864,18 @@ or, in a combined setup:
831
864
 
832
865
  ---
833
866
 
867
+ ## Loop Agent & Monorepo Workspaces
868
+
869
+ ### Loop Agent Mode (Intense Workflows)
870
+ - If tests fail during verification, route the logs back to the Implementer.
871
+ - Run the cycle: Implementer (applies fix) -> Tester (verifies suite) up to 3 times.
872
+ - If still failing, stop and report back with findings.
873
+
874
+ ### Monorepo Workspaces
875
+ - Note that this is a monorepo. Focus operations strictly within the specified sub-package or workspace directory in the Task Card scope. Avoid modifying files or running commands outside this package directory.
876
+
877
+ ---
878
+
834
879
  ## Scorecard Format
835
880
 
836
881
  Every Deliverable should be evaluated against a Scorecard before it is accepted.
@@ -0,0 +1,119 @@
1
+ ---
2
+ id: android
3
+ version: 1.0.0
4
+ name: Android + Kotlin (Jetpack Compose & Media3)
5
+ description: >
6
+ Provides expert knowledge for building modern native Android apps using Kotlin, Jetpack Compose, Material Design 3, MVI architecture, Hilt dependency injection, and Media3/ExoPlayer.
7
+
8
+ user-invokable: true
9
+ license: MIT
10
+ metadata:
11
+ author: lgzarturo
12
+ category: mobile
13
+
14
+ compatibility:
15
+ tools: [claude, codex, gemini, agy, opencode]
16
+ stacks:
17
+ languages: [kotlin, java]
18
+ frameworks: [android]
19
+
20
+ risk:
21
+ level: medium
22
+ can_execute_shell: true
23
+ can_modify_files: true
24
+ requires_network: false
25
+
26
+ inputs: []
27
+
28
+ outputs: []
29
+
30
+ quality:
31
+ reviewed_by: codeconductor-core
32
+ version: 0.1.0
33
+ ---
34
+
35
+ # Android + Kotlin (Jetpack Compose & Media3)
36
+
37
+ This playbook defines the architecture, UI design system, performance guidelines, and testing strategy for native Android applications.
38
+
39
+ ---
40
+
41
+ ## 1. Lead Architect & Modularization
42
+
43
+ ### Architecture (MVI / MVVM with Clean Architecture)
44
+ - Prefer **MVI (Model-View-Intent)** for state management. Ensure a strict unidirectional data flow:
45
+ - **UiState**: Single source of truth for the UI state.
46
+ - **UiIntent**: Actions initiated by the user or system.
47
+ - **UiEffect**: One-time events (navigation, toasts, snackbars).
48
+ - Separate the project into clean logical modules:
49
+ - `app`: Application entry point, launcher activity, global dependency injection configuration.
50
+ - `core`: Shared resources, network layer, media playback logic (ExoPlayer/Media3), storage.
51
+ - `feature`: Individual business features (isolated and independent of other features).
52
+
53
+ ### Dependency Injection (Hilt)
54
+ - Annotate the Application class with `@HiltAndroidApp`.
55
+ - Annotate Activities and Fragments with `@AndroidEntryPoint`.
56
+ - Use constructor injection for ViewModels with `@HiltViewModel`.
57
+
58
+ ---
59
+
60
+ ## 2. Jetpack Compose UI/UX
61
+
62
+ ### Recomposition & State Management
63
+ - Consume `StateFlow` from ViewModels safely using `collectAsStateWithLifecycle()` to respect the activity lifecycle.
64
+ - Keep data models immutable. Mark configuration classes with `@Immutable` or `@Stable` to prevent redundant recompositions.
65
+ - Use `contentType` and `key` in `LazyColumn` and `LazyRow` to optimize item recycling and rendering performance.
66
+ - Avoid fixed hardcoded margins. Apply `WindowInsets` to support modern edge-to-edge screens.
67
+
68
+ ---
69
+
70
+ ## 3. Performance & Multimedia (Media3 / ExoPlayer)
71
+
72
+ ### Playback & Services
73
+ - Run `ExoPlayer` / `Media3` inside a robust `Foreground Service` (using `MediaSessionService`) to ensure playback continues when the app is in the background.
74
+ - Clean up resources: release player instances in `onDestroy` or when the service is stopped.
75
+ - Control wake locks strictly to avoid draining the user's battery when playback is paused.
76
+
77
+ ### Kotlin Coroutines & Threading
78
+ - Always inject `CoroutineDispatcher` instances instead of hardcoding them:
79
+ - `Dispatchers.IO`: Database access, network operations, file reading.
80
+ - `Dispatchers.Default`: CPU-intensive operations (parsing JSON, filtering large lists).
81
+ - `Dispatchers.Main`: UI modifications and light interactions.
82
+
83
+ ### R8 & Resource Optimization
84
+ - Enable shrinking and obfuscation in production builds:
85
+ - `isMinifyEnabled = true`
86
+ - `isShrinkResources = true`
87
+ - Convert all static images to the modern `WebP` format to minimize the application binary size.
88
+
89
+ ---
90
+
91
+ ## 4. Quality Assurance & Automated Testing
92
+
93
+ ### Unit Testing
94
+ - Use JUnit 5 and MockK for mocking dependencies.
95
+ - Test ViewModels and Reducers by asserting StateFlow updates. Use `Turbine` to easily test Kotlin Flows.
96
+ - Mock all multimedia/ExoPlayer components to avoid loading actual audio/video resources in unit tests.
97
+
98
+ ### UI Testing
99
+ - Create UI tests using Compose test rules: `createComposeRule()` or `createAndroidComposeRule<MainActivity>()`.
100
+ - Assert correct rendering, visibility states, and user interactions without executing real network calls.
101
+
102
+ ---
103
+
104
+ ## 5. Key Gradle & ADB Commands
105
+
106
+ Use these commands for building, checking code style, running tests, and profiling performance:
107
+
108
+ | Command | Action |
109
+ | ------- | ------ |
110
+ | `./gradlew init` | Initialize a new Gradle project structure. |
111
+ | `./gradlew app:dependencies` | List all dependencies of the application module. |
112
+ | `./gradlew assembleDebug` | Validate compilation and generate debug APK. |
113
+ | `./gradlew ktlintCheck` | Run KtLint check to enforce Kotlin style guidelines. |
114
+ | `./gradlew lintDebug` | Run Android Lint tool to inspect code quality and UI issues. |
115
+ | `./gradlew testDebugUnitTest` | Run unit tests for debug build variant. |
116
+ | `./gradlew connectedAndroidTest` | Run instrumented UI tests on connected emulator or device. |
117
+ | `./gradlew assembleRelease` | Generate release build variant with R8 optimizations. |
118
+ | `adb shell dumpsys batterystats` | Profile system battery consumption metrics. |
119
+ | `adb shell am dumpheap <package> heap.hprof` | Dump application heap memory file for profiling. |