@mrciphersmith/keryx 0.4.29 → 0.4.30

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 (123) hide show
  1. package/dist/cli.js +2408 -1369
  2. package/dist/core.js +90 -27
  3. package/dist/keryx-general-worker-entry.js +82 -25
  4. package/package.json +1 -1
  5. package/src/gdskills/bundled/install-manifest.json +2 -0
  6. package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
  7. package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
  8. package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
  9. package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
  10. package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
  11. package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
  12. package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
  13. package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
  14. package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
  15. package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
  16. package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
  17. package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
  18. package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
  19. package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
  20. package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
  21. package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
  22. package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
  23. package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
  24. package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
  25. package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
  26. package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
  27. package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
  28. package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
  29. package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
  30. package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
  31. package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
  32. package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
  33. package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
  34. package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
  35. package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
  36. package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
  37. package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
  38. package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
  39. package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
  40. package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
  41. package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
  42. package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
  43. package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
  44. package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
  45. package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
  46. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
  47. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
  48. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
  49. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
  50. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
  51. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
  52. package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
  53. package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
  54. package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
  55. package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
  56. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
  57. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
  58. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
  59. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
  60. package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
  61. package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
  62. package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
  63. package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
  64. package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
  65. package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
  66. package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
  67. package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
  68. package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
  69. package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
  70. package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
  71. package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
  72. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
  73. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
  74. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
  75. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
  76. package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
  77. package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
  78. package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
  79. package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
  80. package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
  81. package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
  82. package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
  83. package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
  84. package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
  85. package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
  86. package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
  87. package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
  88. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
  89. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
  90. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
  91. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
  92. package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
  93. package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
  94. package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
  95. package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
  96. package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
  97. package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
  98. package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
  99. package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
  100. package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
  101. package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
  102. package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
  103. package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
  104. package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
  105. package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
  106. package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
  107. package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
  108. package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
  109. package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
  110. package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
  111. package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
  112. package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
  113. package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
  114. package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
  115. package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
  116. package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
  117. package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
  118. package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
  119. package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
  120. package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
  121. package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
  122. package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
  123. package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
@@ -7,83 +7,46 @@ metadata:
7
7
 
8
8
  # Kotlin/Android coding style
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic style rules to modern
11
- Kotlin/Android idiom. Applies only to `*.kt`/`*.kts` files — everything
12
- not Kotlin-specific still comes from the common rules this file `extends`.
10
+ Narrows `core-common-rules`' style rules to the Kotlin coding conventions and Android idiom.
13
11
 
14
12
  ## Naming and structure
15
13
 
16
- - `PascalCase` for classes, objects, and composables (a `@Composable`
17
- function that emits UI is named as a noun, `UserProfileCard`, not a verb);
18
- `camelCase` for functions, properties, and local variables; `SCREAMING_SNAKE_CASE`
19
- only for `const val` compile-time constants.
20
- - A `@Composable` function that returns a value instead of emitting UI
21
- (e.g. `rememberX`) still reads as a normal function name, not a noun —
22
- reserve the noun-style name for functions that actually emit UI.
23
- - Keep a file's top-level surface small: one primary class/object per
24
- file named after it, with small private helpers colocated rather than
25
- scattered into a shared `Utils.kt`.
26
- - Package names are all lowercase, no underscores, matching the directory
27
- layout (`com.example.feature.profile`, not `com.example.Feature.Profile`).
14
+ - A `@Composable` that emits UI is named as a noun (`UserProfileCard`); one that
15
+ returns a value (`rememberX`) is named as a normal function.
16
+ - One primary class/object per file named after it, small private helpers
17
+ colocated; no shared `Utils.kt`.
28
18
 
29
19
  ## Data classes vs regular classes
30
20
 
31
- - Use `data class` for a type whose identity is its held values (a DTO, a
32
- UI state holder, a value object needing `equals`/`hashCode`/`copy`) —
33
- never a `data class` for something with real identity or mutable
34
- reference semantics (an Android `Activity`, a repository, a singleton
35
- manager).
36
- - Prefer `copy()` with named parameters to produce a modified instance
37
- over building a fresh constructor call by hand; it keeps every unrelated
38
- field unchanged and the diff at a call site small when a new field is
39
- added later.
40
- - A `data class` holding UI state should default every field to a sane
41
- initial value so `State()` (or `UiState()`) alone is a valid starting
42
- point.
21
+ - `data class` only for a type whose identity is its held values (DTO, UI state,
22
+ value object); never for an `Activity`, repository or singleton manager.
23
+ - Prefer `copy()` with named parameters over a hand-built constructor call.
24
+ - A `data class` holding UI state defaults every field so `UiState()` alone is valid.
43
25
 
44
26
  ## Null-safety idiom
45
27
 
46
- - Prefer a safe call (`?.`) or the Elvis operator (`?:`) over `!!`; a
47
- forced-unwrap should be reserved for a value the type system cannot
48
- express as non-null but that a prior check (or the language, e.g. inside
49
- a `requireNotNull` block) has already proven non-null at that point —
50
- never as a shortcut past a compiler nullability warning.
51
- - Use `let` for a null-checked scope over a nullable receiver
52
- (`value?.let { ... }`) when the block needs the unwrapped value once;
53
- avoid chaining several `?.let` calls where a single `if (value != null)`
54
- smart-cast reads more clearly.
55
- - Prefer `requireNotNull(x) { "why x must be non-null here" }` over `x!!`
56
- at a boundary (constructor, public function entry) — it fails with a
57
- message that explains the invariant instead of a bare
58
- `NullPointerException`.
59
- - Model "value or absent" with a nullable type or a sealed result type,
60
- not a sentinel value (`-1`, `""`) that callers have to remember to check
61
- for.
28
+ - Prefer `?.` or `?:` over `!!`; reserve `!!` for a value a prior check has
29
+ proven non-null, never to get past a nullability warning.
30
+ - Prefer `requireNotNull(x) { "why x must be non-null here" }` over `x!!` at a
31
+ boundary (constructor, public function entry).
32
+ - Use `value?.let { ... }` when the block needs the unwrapped value once; do not
33
+ chain several `?.let` where one `if (value != null)` smart-cast reads better.
34
+ - Model "value or absent" with a nullable or sealed result type, not a sentinel
35
+ (`-1`, `""`).
62
36
 
63
37
  ## Sealed classes/interfaces for state modeling
64
38
 
65
- - Model a UI or domain state with a `sealed interface`/`sealed class`
66
- hierarchy (`Loading`, `Success(data)`, `Error(throwable)`) rather than a
67
- single class with several nullable fields and a separate `isLoading`
68
- boolean — the compiler then forces an exhaustive `when` at every call
69
- site, so a new state can't be silently unhandled.
70
- - Prefer a `sealed interface` over `sealed class` when a variant needs no
71
- shared state or behavior; reach for `sealed class` only when the
72
- variants share a common property or method implementation.
73
- - Keep a sealed hierarchy's variants in the same file (or a `sealed`-file
74
- group) as the parent — Kotlin does not require this, but scattering
75
- variants across files makes the exhaustiveness check hard to audit by
76
- reading.
39
+ - Model UI or domain state as a `sealed interface`/`sealed class`
40
+ (`Loading`, `Success(data)`, `Error(throwable)`), not one class with nullable
41
+ fields and an `isLoading` boolean.
42
+ - `sealed interface` unless the variants share state or behavior; then `sealed class`.
43
+ - Keep a sealed hierarchy's variants in the same file as the parent.
77
44
 
78
45
  ## Extension functions
79
46
 
80
- - Add an extension function to attach behavior to a type this module does
81
- not own (or to keep a small, focused helper out of a growing class) —
82
- not to route around giving a type a proper method when the type is
83
- already yours to edit.
84
- - Keep an extension's receiver type narrow and its name unambiguous
85
- (`String.toDisplayDate()`, not a generic `Any.format()`); an extension
86
- with a vague name invites collisions and surprises at the call site.
87
- - Avoid extension-function sprawl on core types (`String`, `Int`, `List`)
88
- for one-off, feature-specific logic — a feature-scoped extension on a
89
- feature-scoped type keeps the change's blast radius visible.
47
+ - Use an extension for a type this module does not own, or to keep a small helper
48
+ out of a growing class; not in place of a method on a type that is yours to edit.
49
+ - Keep the receiver narrow and the name unambiguous (`String.toDisplayDate()`,
50
+ not `Any.format()`).
51
+ - No extensions on core types (`String`, `Int`, `List`) for one-off,
52
+ feature-specific logic; put them on a feature-scoped type.
@@ -7,90 +7,46 @@ metadata:
7
7
 
8
8
  # Kotlin/Android patterns
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic design guidance to idiomatic
11
- Kotlin coroutines and Jetpack Compose design. Applies only to
12
- `*.kt`/`*.kts` files.
10
+ Narrows `core-common-rules`' design guidance to kotlinx.coroutines structured
11
+ concurrency and Jetpack Compose.
13
12
 
14
13
  ## Coroutines: structured concurrency
15
14
 
16
- - Launch a coroutine from a scope tied to the lifecycle that owns it —
17
- `viewModelScope` inside a `ViewModel`, `lifecycleScope` inside an
18
- `Activity`/`Fragment`, or a plain `coroutineScope { }`/`suspend`
19
- function for work with no lifecycle owner. Never `GlobalScope.launch`/
20
- `GlobalScope.async`: `GlobalScope` is unstructured — nothing cancels it
21
- when the screen or the ViewModel goes away, so it outlives the UI it was
22
- started for and can update state, navigate, or write to a destroyed
23
- view.
24
- - When a function needs to run several suspend calls concurrently, wrap
25
- them in `coroutineScope { }` and use `async`/`await`, not a `launch`
26
- fired without an `await` point — `coroutineScope` waits for every child
27
- to finish (or cancels the rest if one fails) before returning, so a
28
- caller downstream never observes a half-finished fan-out.
29
- - Cancellation is cooperative: a long-running loop or CPU-bound block
30
- inside a coroutine should call `ensureActive()`/check
31
- `coroutineContext.isActive`, or use a cancellable suspending call
32
- (`delay`, `yield`), so cancelling the parent scope actually stops it
33
- instead of running to completion regardless.
34
- - Switch dispatcher with `withContext(Dispatchers.IO)` around a blocking
35
- call (network client without its own suspend API, disk I/O), not by
36
- launching a whole new coroutine on that dispatcher — `withContext`
37
- keeps the call sequential and propagates cancellation and the result
38
- back to the caller.
15
+ - Launch from a scope tied to the owning lifecycle: `viewModelScope` in a
16
+ `ViewModel`, `lifecycleScope` in an `Activity`/`Fragment`, `coroutineScope { }`
17
+ or a `suspend` function otherwise. Never `GlobalScope.launch`/`GlobalScope.async`.
18
+ - Run several suspend calls concurrently with `coroutineScope { }` and
19
+ `async`/`await`, not a `launch` with no `await` point.
20
+ - A long-running loop or CPU-bound block calls `ensureActive()`/checks
21
+ `coroutineContext.isActive`, or uses a cancellable suspending call (`delay`, `yield`).
22
+ - Switch dispatcher with `withContext(Dispatchers.IO)` around a blocking call,
23
+ not by launching a new coroutine on that dispatcher.
39
24
 
40
25
  ## Compose: recomposition correctness
41
26
 
42
- - Strong skipping mode is the Compose compiler default since Kotlin 2.0.20:
43
- every restartable composable is skippable even with an unstable
44
- parameter (a plain `List`/`MutableList`, a mutable var-holding class with
45
- no `@Stable`/`@Immutable` annotation) — the compiler compares unstable
46
- parameters by instance identity instead of refusing to skip. Prefer
47
- stable parameters anyway (a primitive, a `data class` of stable members,
48
- an immutable collection) since identity comparison still recomposes on
49
- every NEW instance (e.g. a `List` rebuilt each call), where a genuinely
50
- stable/immutable type can compare equal and skip.
51
- - Hoist state to the nearest common ancestor that needs it (a caller, or
52
- the owning `ViewModel`) instead of trapping it inside a leaf composable
53
- when a sibling or the caller also needs to read or drive it; a leaf
54
- composable with no external need for its state can still own it locally
55
- via `remember`.
56
- - Use `remember { ... }` for state that should survive recomposition but
57
- not process death or configuration change (a derived value, an
58
- `Animatable`, a coroutine-backed helper); use `rememberSaveable { ... }`
59
- when the value must survive activity recreation (rotation, process
60
- death) — typically UI-only state a `ViewModel` does not already own.
61
- - Never call a suspend function, fire a one-off event (navigation,
62
- `Toast`, analytics), or start a coroutine directly in a composable's
63
- body — route it through `LaunchedEffect(key1, ...) { }` (re-runs when a
64
- key changes) or `DisposableEffect(key) { onDispose { ... } }` (needs
65
- cleanup), never as a bare statement that runs on every recomposition.
66
- - Under strong skipping mode (default since Kotlin 2.0.20), the compiler
67
- auto-memoizes a lambda declared inside a composable by wrapping it in an
68
- implicit `remember`, keyed on its captures — a lambda passed inline to a
69
- hot list item no longer needs manual hoisting for identity stability in
70
- the common case. Reach for `@DontMemoize` only to opt a specific lambda
71
- out (e.g. one that must run fresh every recomposition), and still hoist
72
- a lambda explicitly when it closes over a value from an outer scope that
73
- changes on a schedule the auto-memoization's capture-based keying
74
- wouldn't track correctly.
27
+ - Strong skipping mode is the default since Kotlin 2.0.20. Prefer stable
28
+ parameters anyway (primitive, `data class` of stable members, immutable
29
+ collection): identity comparison still recomposes on every NEW instance.
30
+ - Hoist state to the nearest common ancestor that needs it (a caller or the
31
+ owning `ViewModel`); a leaf with no external need can own it via `remember`.
32
+ - `remember { ... }` for state that survives recomposition only;
33
+ `rememberSaveable { ... }` for state that must survive activity recreation.
34
+ - Never call a suspend function, fire a one-off event (navigation, `Toast`,
35
+ analytics) or start a coroutine in a composable's body; use
36
+ `LaunchedEffect(key1, ...)` or `DisposableEffect(key) { onDispose { ... } }`.
37
+ - Under strong skipping a lambda inside a composable is auto-memoized; use
38
+ `@DontMemoize` only to opt a lambda out, and still hoist a lambda explicitly
39
+ when it closes over an outer-scope value whose changes the capture-based
40
+ keying would not track.
75
41
 
76
42
  ## State exposure from a ViewModel
77
43
 
78
- - Expose state from a `ViewModel` as a read-only `StateFlow`/`SharedFlow`
79
- backed by a private mutable holder — `private val _state =
80
- MutableStateFlow(...)` with `val state = _state.asStateFlow()` — never
81
- the mutable type itself, so only the `ViewModel` can drive state
82
- changes and the UI layer can only observe.
83
- - Prefer `StateFlow` for "current value" UI state (a screen's latest
84
- render state, always has a value) and `SharedFlow`/`Channel` for one-off
85
- events (a snackbar, a navigation trigger) that should not replay a
86
- stale value to a newly-subscribed collector.
87
- - `LiveData` is legacy for new Compose/coroutine-first code: prefer
88
- `StateFlow`/`SharedFlow` exposed from the `ViewModel` and collected with
89
- `collectAsStateWithLifecycle()` in Compose. Keep `LiveData` only where a
90
- project has already standardized on it or where an unconverted
91
- `View`-based screen still consumes it.
92
- - Collect a `ViewModel`'s flow in Compose with
93
- `collectAsStateWithLifecycle()`, not a bare `collectAsState()` — the
94
- lifecycle-aware variant stops collecting while the screen is stopped
95
- instead of continuing to observe (and potentially update state) behind
96
- a backgrounded UI.
44
+ - Expose a read-only `StateFlow`/`SharedFlow` over a private mutable holder
45
+ (`private val _state = MutableStateFlow(...)`, `val state = _state.asStateFlow()`),
46
+ never the mutable type.
47
+ - `StateFlow` for "current value" UI state; `SharedFlow`/`Channel` for one-off
48
+ events (snackbar, navigation) that must not replay.
49
+ - `LiveData` is legacy for new code: use `StateFlow`/`SharedFlow` collected with
50
+ `collectAsStateWithLifecycle()`. Keep `LiveData` only where the project has
51
+ standardized on it or an unconverted `View`-based screen consumes it.
52
+ - Collect in Compose with `collectAsStateWithLifecycle()`, not bare `collectAsState()`.
@@ -7,84 +7,51 @@ metadata:
7
7
 
8
8
  # Kotlin/Android security
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic security rules to Android-
11
- specific, OWASP Mobile-relevant risks. Applies only to `*.kt`/`*.kts`
12
- files.
10
+ Narrows `core-common-rules`' security rules to Android risks in OWASP Mobile Top 10.
13
11
 
14
12
  ## Secrets and credential storage
15
13
 
16
- - Never store a credential, auth token, or API secret in plain
17
- `SharedPreferences` — plain `SharedPreferences` is an unencrypted XML
18
- file readable on a rooted device or via backup extraction. Prefer the
19
- Android Keystore directly (generate/store the key in the Keystore, use
20
- it to encrypt the value yourself) over `EncryptedSharedPreferences`
21
- (Jetpack `androidx.security:security-crypto`) for new code — that
22
- library has known, unresolved reliability issues (a corrupted-keyset
23
- failure mode with no clean recovery path) and Google's own guidance has
24
- moved toward not recommending it for new applications; verify the
25
- library's current status in the Android docs before reaching for it in
26
- an existing codebase that already depends on it.
27
- - Never hard-code an API key, client secret, or signing credential as a
28
- Kotlin string literal or a `BuildConfig` field, whether the value is
29
- committed or injected at build time from a local, untracked properties
30
- file (`local.properties`) or a CI secret — either way, a `BuildConfig`
31
- field is compiled into the APK exactly like a string literal and is
32
- just as recoverable by decompiling it. Keeping the value out of source
33
- control (via `local.properties`/a CI secret) only stops it leaking
34
- through the repository; it does not keep it off the device. For a
35
- value that must actually stay off the device, fetch it from a backend
36
- at runtime instead of baking it into the build at all.
14
+ - Never store a credential, auth token or API secret in plain `SharedPreferences`.
15
+ For new code prefer the Android Keystore directly (store the key there, encrypt
16
+ the value yourself) over `EncryptedSharedPreferences`
17
+ (`androidx.security:security-crypto`), which Google no longer recommends for new
18
+ applications; check its current status in the Android docs before using it in a
19
+ codebase that already depends on it.
20
+ - Never hard-code an API key, client secret or signing credential as a Kotlin
21
+ string literal or a `BuildConfig` field, committed or injected at build time
22
+ from `local.properties` or a CI secret: `BuildConfig` is compiled into the APK.
23
+ A value that must stay off the device is fetched from a backend at runtime.
37
24
  - Generate and store cryptographic keys through `AndroidKeyStore`
38
- (`KeyGenParameterSpec`) rather than deriving or hard-coding a key in
39
- application code — the Keystore keeps key material out of the app's
40
- own process memory and out of extractable storage.
25
+ (`KeyGenParameterSpec`), not derived or hard-coded in application code.
41
26
 
42
27
  ## Manifest and component exposure
43
28
 
44
- - Every `<activity>`, `<service>`, `<receiver>`, and `<provider>` in
45
- `AndroidManifest.xml` that does not need to be reachable from other
46
- apps should have `android:exported="false"` (or no `exported`
47
- attribute with no intent-filter, matching the modern default); a
48
- component left `exported="true"` with no permission check is callable
49
- by any app on the device, including one crafted to pass malformed
50
- input.
51
- - An exported component that must stay exported (a deep-link entry point,
52
- a share target) validates every piece of the incoming `Intent` before
53
- acting on it — never trusts an extra, a URI path segment, or a
54
- `ContentProvider` query purely because the intent-filter matched.
55
- - Guard a `ContentProvider` and any exported component with a
56
- signature-level custom permission when the caller is meant to be your
57
- own other app, not "any app that asks."
29
+ - Every `<activity>`, `<service>`, `<receiver>` and `<provider>` not meant to be
30
+ reachable from other apps has `android:exported="false"` (or no `exported`
31
+ attribute and no intent-filter).
32
+ - An exported component that must stay exported (deep-link entry, share target)
33
+ validates every piece of the incoming `Intent` before acting on it.
34
+ - Guard a `ContentProvider` and any exported component with a signature-level
35
+ custom permission when the caller is meant to be your own other app.
58
36
 
59
37
  ## Secure intent and deep-link handling
60
38
 
61
- - Treat every value pulled from an incoming `Intent` (extras, deep-link
62
- URI segments/query params, a `ClipData` from a share) as untrusted
63
- input — validate its shape and range before using it to navigate, query
64
- a database, or construct a file path; do not assume it matches what
65
- your own app would have sent.
66
- - Prefer an explicit `Intent` (naming the target component) for
67
- inter-component communication within your own app; use an implicit
68
- `Intent` only when you genuinely need another app to handle it, and
69
- set the package (`setPackage`) when you only want your own app to
70
- respond, to avoid intent interception by another installed app.
71
- - Validate a deep-link's scheme/host/path against an allowlist before
72
- using any part of it to load content or trigger an action —
73
- `App Links`/verified `https` deep links reduce but do not eliminate
74
- this: a query parameter or path segment can still carry attacker-
75
- controlled data even through a verified link.
39
+ - Treat every value from an incoming `Intent` (extras, deep-link segments and
40
+ query params, share `ClipData`) as untrusted: validate shape and range before
41
+ using it to navigate, query a database or build a file path.
42
+ - Prefer an explicit `Intent` within your own app; use an implicit `Intent` only
43
+ when another app must handle it, and set `setPackage` when only your own app
44
+ should respond.
45
+ - Validate a deep-link's scheme/host/path against an allowlist before using any
46
+ part of it; verified `https` App Links do not make a query parameter or path
47
+ segment trusted.
76
48
 
77
49
  ## Data and transport
78
50
 
79
- - Use `HttpsURLConnection`/an HTTP client configured to require TLS for
80
- every network call carrying credentials or personal data; do not add a
81
- custom `TrustManager`/`HostnameVerifier` that accepts all certificates
82
- outside of a short-lived local debug build, and never ship one that
83
- way.
84
- - Mark a view/field that must not appear in screenshots or the recent-
85
- apps app-switcher preview (a PIN entry, payment details) with
86
- `FLAG_SECURE` on the window, rather than relying on the OS default.
87
- - Avoid logging PII, tokens, or full request/response bodies with
88
- `Log.d`/`Log.i` in release builds — strip or gate verbose logging
89
- behind a debug-only build flag so production logs (which can be pulled
90
- from a device or bug report) do not leak sensitive data.
51
+ - Require TLS for every network call carrying credentials or personal data; no
52
+ custom `TrustManager`/`HostnameVerifier` that accepts all certificates outside
53
+ a short-lived local debug build, and never shipped.
54
+ - Mark a view/field that must not appear in screenshots or the app-switcher
55
+ preview (PIN entry, payment details) with `FLAG_SECURE`.
56
+ - No PII, tokens or full request/response bodies in `Log.d`/`Log.i` in release
57
+ builds; gate verbose logging behind a debug-only flag.
@@ -7,83 +7,49 @@ metadata:
7
7
 
8
8
  # Kotlin/Android testing
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic testing rules to Kotlin
11
- coroutine testing, Compose UI testing, and idiomatic mocking on Android.
12
- Applies only to `*.kt`/`*.kts` files.
10
+ Narrows `core-common-rules`' testing rules to `kotlinx-coroutines-test`, Compose
11
+ UI testing and mocking on Android.
13
12
 
14
13
  ## Coroutine test dispatchers
15
14
 
16
- - Test a `suspend` function or a `ViewModel`'s coroutine-driven behavior
17
- with `kotlinx-coroutines-test`'s `runTest { }`, not a real `delay` or a
18
- blocking sleep — `runTest` runs on a `TestScope` whose virtual clock
19
- skips real delay time, so a function that internally waits still runs
20
- the test instantly.
21
- - Inject a `TestDispatcher` (`StandardTestDispatcher`/
22
- `UnconfinedTestDispatcher`) in place of `Dispatchers.Main`/
23
- `Dispatchers.IO` for the code under test rather than letting it resolve
24
- the real platform dispatcher — set `Dispatchers.setMain(testDispatcher)`
25
- in a `@Before` and `Dispatchers.resetMain()` in an `@After` (or a JUnit
26
- rule that wraps this) so `viewModelScope`/`Dispatchers.Main` resolves to
27
- the test dispatcher instead of throwing or running on a background
28
- thread the test cannot observe.
29
- - Prefer `StandardTestDispatcher` (queues work, you advance it explicitly
30
- with `advanceUntilIdle()`/`runCurrent()`) when a test needs to assert an
31
- intermediate state (e.g. a loading state before a result arrives); use
32
- `UnconfinedTestDispatcher` when the test only cares about the end state
33
- and wants dispatched work to run eagerly.
34
- - Never synchronize a coroutine test with `Thread.sleep`/a fixed `delay`
35
- in the test body waiting for background work to finish — that is
36
- exactly what `runTest`'s virtual time and `advanceUntilIdle()` replace.
15
+ - Test a `suspend` function or `ViewModel` coroutine behavior with `runTest { }`,
16
+ not a real `delay` or blocking sleep.
17
+ - Inject a `TestDispatcher` (`StandardTestDispatcher`/`UnconfinedTestDispatcher`)
18
+ in place of `Dispatchers.Main`/`Dispatchers.IO`; `Dispatchers.setMain(testDispatcher)`
19
+ in `@Before` and `Dispatchers.resetMain()` in `@After` (or a JUnit rule).
20
+ - `StandardTestDispatcher` (advance with `advanceUntilIdle()`/`runCurrent()`) when
21
+ a test asserts an intermediate state; `UnconfinedTestDispatcher` when only the
22
+ end state matters.
23
+ - Never synchronize a coroutine test with `Thread.sleep` or a fixed `delay`.
37
24
 
38
25
  ## Compose UI testing
39
26
 
40
- - Drive Compose UI assertions through a `ComposeTestRule`
41
- (`createComposeRule()` for a standalone composable, or
42
- `createAndroidComposeRule<Activity>()` when the test needs a hosting
43
- Activity) — never reach into the underlying `View` tree.
44
- - Find nodes with semantics-based finders
45
- (`onNodeWithText`, `onNodeWithContentDescription`,
46
- `onNodeWithTag(testTag)`) rather than a fragile structural/index-based
47
- query; add an explicit `Modifier.testTag("...")` to a composable that
48
- has no stable text/content-description to key off.
49
- - Call `composeTestRule.waitUntil { ... }` (or
50
- `composeTestRule.awaitIdle()`/`mainClock.advanceTimeUntil { }` under
51
- manual clock control) to wait for an async UI update instead of a
52
- fixed-duration sleep in the test.
53
- - Assert both structure and behavior: a node's presence/text via a
54
- semantics finder, and an interaction's effect (`performClick()` then
55
- assert the resulting state/text), not just that a composable rendered
56
- without throwing.
27
+ - Drive assertions through a `ComposeTestRule` (`createComposeRule()`, or
28
+ `createAndroidComposeRule<Activity>()` when a hosting Activity is needed);
29
+ never reach into the `View` tree.
30
+ - Find nodes with `onNodeWithText`, `onNodeWithContentDescription`,
31
+ `onNodeWithTag(testTag)`, not structural/index-based queries; add
32
+ `Modifier.testTag("...")` where there is no stable text or content description.
33
+ - Wait for async UI with `composeTestRule.waitUntil { ... }`, `awaitIdle()` or
34
+ `mainClock.advanceTimeUntil { }`, not a fixed sleep.
35
+ - Assert structure and behavior: presence/text, and an interaction's effect
36
+ (`performClick()` then the resulting state), not just that it rendered.
57
37
 
58
38
  ## Mocking at the interface boundary
59
39
 
60
- - Mock a `Repository`/`ApiService`/`DataSource` interface (or another
61
- clearly-owned collaborator boundary) that the class under test depends
62
- on — never reach inside the class under test to stub its own private
63
- methods or fields; a test that mocks internals stops testing real
64
- behavior and breaks on any internal refactor.
65
- - Prefer MockK for Kotlin code under test — it understands Kotlin
66
- constructs Mockito's Java-first API handles awkwardly (`final` classes
67
- by default, coroutines via `coEvery`/`coVerify`, extension functions,
68
- object mocks via `mockkObject`) — unless a project has already
69
- standardized on Mockito with `mockito-kotlin`; match what the project
70
- already uses rather than introducing a second mocking library.
71
- - Use `coEvery { repo.fetch() } returns result` /
72
- `coVerify { repo.fetch() }` (MockK's coroutine-aware variants) for a
73
- suspend function on a mock, not the plain `every`/`verify` forms, which
74
- do not handle a `suspend` member correctly.
75
- - Fake network/database responses at the repository or data-source
76
- interface (a fake or mocked implementation returning canned data), not
77
- by hitting a real network or an on-device database from a unit test —
78
- reserve a real backing store for an instrumented/integration test.
40
+ - Mock a `Repository`/`ApiService`/`DataSource` interface or other clearly-owned
41
+ collaborator boundary; never stub the class under test's own private methods or fields.
42
+ - Prefer MockK for Kotlin code, unless the project has standardized on Mockito
43
+ with `mockito-kotlin`; match the project, do not add a second mocking library.
44
+ - `coEvery { repo.fetch() } returns result` / `coVerify { repo.fetch() }` for a
45
+ suspend function on a mock, not `every`/`verify`.
46
+ - Fake network/database responses at the repository or data-source interface in
47
+ unit tests; a real backing store belongs in an instrumented/integration test.
79
48
 
80
49
  ## Layout and lifecycle
81
50
 
82
- - Unit tests for a `ViewModel`/plain Kotlin class live under
83
- `src/test/`; instrumented tests needing an Android context or a real
84
- device/emulator (Compose UI tests, `Instrumentation`-backed tests) live
85
- under `src/androidTest/` — match whichever the project's existing
86
- layout uses, do not invent a third location.
87
- - Use JUnit rules (`MainDispatcherRule` for coroutines,
88
- `createComposeRule()` for Compose) to keep dispatcher/UI setup and
89
- teardown out of every individual test method.
51
+ - `ViewModel`/plain Kotlin unit tests under `src/test/`; tests needing an Android
52
+ context or device (Compose UI, `Instrumentation`) under `src/androidTest/`;
53
+ match the project's layout, no third location.
54
+ - Use JUnit rules (`MainDispatcherRule`, `createComposeRule()`) for dispatcher and
55
+ UI setup/teardown.
@@ -7,85 +7,39 @@ metadata:
7
7
 
8
8
  # MobX coding style
9
9
 
10
- Narrows the React/TypeScript common rules to MobX's own idiom for stores,
11
- observables, and observer components. Everything not MobX-specific still
12
- comes from the common and React rules this file `extends`.
10
+ Narrows the React/TypeScript common rules to MobX's idiom for stores,
11
+ observables, and observer components. Everything not MobX-specific comes from
12
+ the common and React rules this file `extends`.
13
13
 
14
14
  ## Store class shape
15
15
 
16
- - Call `makeObservable(this)` (with an explicit annotations map, or
17
- `makeAutoObservable(this)` for a store with no inheritance and no need to
18
- keep some fields non-observable) once, in the constructor, before any
19
- other constructor logic reads `this`.
20
- - Prefer explicit `@observable`/`@computed`/`@action`/`@action.bound`
21
- decorators with `makeObservable` over `makeAutoObservable` for any store
22
- a component subclasses, that mixes injected dependencies with state, or
23
- that needs a field to stay non-observable — `makeAutoObservable` makes
24
- every own enumerable property observable and every method an action,
25
- which is the wrong default once the store has structure to protect.
26
- - Name store classes `XyzStore` and files `xyz.store.ts`/`XyzStore.ts` to
27
- match the project's existing convention; keep one store per file.
16
+ - Call `makeObservable(this)` (explicit annotations map, or `makeAutoObservable(this)` for a store with no inheritance and no field that must stay non-observable) once in the constructor, before other constructor logic reads `this`.
17
+ - Prefer explicit `@observable`/`@computed`/`@action`/`@action.bound` with `makeObservable` over `makeAutoObservable` for a store that is subclassed, mixes injected dependencies with state, or needs a non-observable field.
18
+ - Name store classes `XyzStore`, files `xyz.store.ts`/`XyzStore.ts` per the project's convention; one store per file.
28
19
 
29
20
  ## Actions
30
21
 
31
- - Every method that mutates observable state must be an `action`
32
- (`@action` or `@action.bound`). A public method invoked from a component
33
- event handler must be `@action.bound` so it can be passed as a callback
34
- reference without losing `this`.
35
- - After an `await` inside an async action, re-enter MobX with
36
- `runInAction(() => { ... })` before mutating state — the code after the
37
- `await` runs outside the original action's transaction.
38
- - Do not call a store method that mutates state directly from a component
39
- render body; only from an event handler, effect, or another action.
22
+ - Every method that mutates observable state is an `action`; a public method called from a component event handler is `@action.bound`.
23
+ - After an `await` in an async action, re-enter with `runInAction(() => { ... })` before mutating state.
24
+ - Call a state-mutating store method only from an event handler, effect, or another action, never a component render body.
40
25
 
41
26
  ## Computed values
42
27
 
43
- - Any value derived purely from other observables belongs in a
44
- `@computed get` accessor, not in a component-side calculation repeated
45
- on every render or a store method that recomputes and returns a fresh
46
- value each call. A `@computed` is cached and only re-evaluates when one
47
- of its own observable dependencies changes.
48
- - Keep a `@computed` getter free of side effects; it must be safe to
49
- evaluate speculatively (MobX may read a computed's value to decide
50
- whether it changed).
28
+ - Put a value derived purely from other observables in a `@computed get`, not a per-render component calculation or a store method that recomputes each call.
29
+ - Keep a `@computed` getter free of side effects.
51
30
 
52
31
  ## Observable collections and value types
53
32
 
54
- - Use `@observable.ref` for a value the store treats as an opaque
55
- reference (a large externally-owned object, a DOM/editor instance) it
56
- does not want deeply proxied, `@observable.shallow` for a container
57
- whose items should stay plain, and `@observable.struct` when a reaction
58
- should only fire on a structural (deep-equal) change, not fine-grained.
59
- Reserve the default deep `@observable` for state the store actually
60
- wants MobX to track recursively.
61
- - When you need MobX's own collection API (`.replace()`, `.remove()`,
62
- `.merge()`, `.has()`) on an array or map field, construct it with
63
- `observable([...])` / `observable(new Map())` and type it as
64
- `IObservableArray<T>` / `ObservableMap<K, V>`; a plain array/object
65
- literal assigned to `@observable` is still deeply observed but does not
66
- expose those methods.
33
+ - `@observable.ref` for an opaque reference not to be deeply proxied (large externally-owned object, DOM/editor instance); `@observable.shallow` for a container whose items stay plain; `@observable.struct` when a reaction should fire only on a structural (deep-equal) change. Default deep `@observable` only for state MobX should track recursively.
34
+ - For MobX's collection API (`.replace()`, `.remove()`, `.merge()`, `.has()`), construct with `observable([...])`/`observable(new Map())` and type as `IObservableArray<T>`/`ObservableMap<K, V>`.
67
35
 
68
36
  ## Components
69
37
 
70
- - Wrap any function component that reads observable state in `observer`
71
- from `mobx-react-lite`. A component that reads a store field but is not
72
- wrapped in `observer` will render once and silently never update again
73
- when that field changes.
74
- - Read store instances through a typed React context + hook pair
75
- (`useXyzStore()`), not through a module-level singleton import, so
76
- components stay testable and providers can swap the instance.
77
- - Do not destructure observable fields off a store at the top of a
78
- component body if that breaks fine-grained tracking for a nested
79
- `<Observer>` boundary further down — read the field where it is
80
- actually rendered instead.
38
+ - Wrap every function component that reads observable state in `observer` from `mobx-react-lite`.
39
+ - Read stores through a typed React context + hook pair (`useXyzStore()`), not a module-level singleton import.
40
+ - Do not destructure observable fields at the top of a component body when that breaks fine-grained tracking for a nested `<Observer>`; read the field where it renders.
81
41
 
82
42
  ## Errors and imports
83
43
 
84
- - Import MobX identifiers (`observable`, `action`, `computed`, `reaction`,
85
- `runInAction`, `makeObservable`) from `"mobx"`, and `observer`,
86
- `useLocalObservable` from `"mobx-react-lite"` — do not import from the
87
- deprecated combined `mobx-react` package in new code unless the project
88
- has not migrated off it yet.
89
- - Catch and store errors from an async action's `try/catch` as
90
- `err: unknown`, narrowing before assigning to an observable `error`
91
- field (see `rules/patterns.mdc` for the full async-action shape).
44
+ - Import `observable`, `action`, `computed`, `reaction`, `runInAction`, `makeObservable` from `"mobx"`, and `observer`, `useLocalObservable` from `"mobx-react-lite"`; not from the deprecated `mobx-react` in new code unless the project has not migrated.
45
+ - Catch errors from an async action as `err: unknown`, narrowing before assigning to an observable `error` field (full shape in `rules/patterns.mdc`).