Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
492 changes: 465 additions & 27 deletions .circleci/config.yml

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions .claude/agent-memory/code-reviewer/MEMORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Code Reviewer Memory

## Key Patterns Confirmed

- `AapsSpacing` object: `extraSmall`(2), `small`(4), `medium`(8), `large`(12), `extraLarge`(16),
`xxLarge`(24). Use instead of hardcoded `.dp` literals.
- `clearFocusOnTap` in `app.aaps.core.ui.compose.Modifiers.kt`. Required for screens with text
fields.
- `ComposablePluginContent` in
`core/ui/src/main/kotlin/app/aaps/core/ui/compose/ComposablePluginContent.kt`.
- `PluginBase.scope` is private; plugins must declare their own `CoroutineScope`.
- Previews MUST use `MaterialTheme` wrapper (NOT `AapsTheme` — crashes in preview tool).

## DI Patterns

- **One framework everywhere: Metro.** A view model is registered with
`@ContributesIntoMap(AppScope::class, binding = binding<ViewModel>())` + `@ViewModelKey`, and read
in Compose with `metroViewModel()`.
- `ComposablePluginContent` receives `viewModelFactory` and calls
`ViewModelProvider(viewModelStoreOwner, viewModelFactory)[...]`. Instantiating via `remember {}`
is a latent lifecycle bug (viewModelScope never cancelled correctly).
- **ComposeContent constructor**: Always constructed manually in the plugin, receives only
non-ViewModel deps (e.g., `protectionCheck`, `blePreCheck`) as constructor params.
non-ViewModel deps (e.g., `protectionCheck`, `blePreCheck`) as constructor params.

## Recurring Bugs Across Pump Compose Migrations

- `BlePreCheckHost` + wizard screen render simultaneously — wizard shows before BLE check completes.
Need a separate `isCheckingBle` state to gate wizard rendering. (EOPatch2, Equil) — STILL OPEN in
Equil.
- `SharedFlow` event branches left empty (`// handled inline`) when they are actually NOT handled.
(Equil: `ShowMessage` in `EquilComposeContent` swallows unpair errors)
- Public `val rh: ResourceHelper` on ViewModels — should always be `private val`. (EOPatch2,
Equil) — FIXED in Equil.
- `canGoBack` implemented as a plain Kotlin computed property reading `StateFlow.value` instead of
a derived `StateFlow` — not reactive in Compose. (Equil) — FIXED.
- Step composables accessing ViewModel data via plain function calls instead of `StateFlow`. (
Equil) — FIXED.
- Step count (`totalSteps`) mismatch when shared steps (AIR, CONFIRM) are reused across workflows
without updating the workflow's declared `totalSteps`. (Equil: CHANGE_INSULIN declares 4 but
runs 6 steps) — FIXED (count correct), but comment in EquilWizardStep.kt line 15 not updated.
- Duplicate therapy event insertion in activation confirm step — check all `insertTherapyEvent`
calls when porting confirm logic. (Equil: double CANNULA_CHANGE event) — RESOLVED, not duplicated.
- Air removal step: "Finish" button must be disabled until the removal command has been sent and
succeeded. Easy to forget when porting from XML (button was initially disabled via alpha). (
Equil) — FIXED.
- Callback.run() in commandQueue executes on background HandlerThread — all MutableStateFlow.value
assignments from callbacks are safe (StateFlow is thread-safe), but plain `var` fields (
autoFillActive,
fillStepCount) accessed from callbacks are NOT safe without @Volatile.
- Empty password allowed through SerialNumberStep — `isPasswordValid = password.isEmpty() || ...`
lets user pair with no password, which is stored and used for future unpair.
- Resource strings with embedded stray characters: equil_install has trailing `"`,
equil_unbind_content
has full-width `!`. Always check string values not just keys.
- `GIF_MAX_HEIGHT = 300.dp` duplicated in 4 step files — WizardGifImage.kt was planned but not
created.

## Architecture Notes

- `WizardGifImage.kt` / `WizardImage` in `core/ui/compose/pump/` — shared GIF/image wrapper for
wizards. Step composables should use this instead of copy-pasting `GlideImage` boilerplate.
- `WizardStepLayout`, `StepProgressIndicator`, `WizardButton` in `core/ui/compose/pump/` — shared
wizard chrome components.
- `BlePreCheckHost` in `core/ui/compose/pump/BlePreCheckHost.kt` — async, renders wizard at same
time unless guarded.

## See Also

- Earlier migration reviews (NSClient, Tidepool, Wear, SMS, Preferences, EOPatch2): see conversation
history from 2026-03-01 and 2026-03-02.
45 changes: 45 additions & 0 deletions .claude/agent-memory/design-reviewer/MEMORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Design Reviewer Memory

## Key Files
- Theme spacing: `core/ui/src/main/kotlin/app/aaps/core/ui/compose/AapsSpacing.kt`
- Shared icon component: `core/ui/src/main/kotlin/app/aaps/core/ui/compose/TonalIcon.kt` (40dp box, 24dp icon)
- Core composables: `core/ui/src/main/kotlin/app/aaps/core/ui/compose/` (AapsTopAppBar, AapsCard, etc.)

## Sizing Conventions
- Standard icon in icon button (toolbar/list): 24dp
- TonalIcon container: 40dp box, 24dp icon inside
- ConfigPluginItem (expanded plugin rows): 40dp tonal icon container, 24dp icon
- Category row leading icon: 24dp (no container)
- Material minimum touch target: 48dp (use `minimumInteractiveComponentSize` or ensure 48dp hit area)
- IconButton default size: 48dp touch area, but visually can be constrained with `.size()`

## Color Conventions
- All icon tints use `MaterialTheme.colorScheme.onSurfaceVariant` for secondary/decorative icons
- Primary/active plugin icons use `MaterialTheme.colorScheme.primary`
- Do NOT use hardcoded colors; use `MaterialTheme.colorScheme.*` or `AapsTheme.colors.*`

## ConfigurationScreen Patterns (ui module)
- Category rows: custom Row with clickable modifier, 24dp start padding, 16dp end padding
- Expanded plugin rows: ListItem with rounded card + secondaryContainer tinted background
- Chevron: `KeyboardArrowRight` (24dp), animated rotation 0→90° on expand
- Shortcut icon buttons use `.size(36dp)` constraint on IconButton with 20dp inner icon
- See: `ui/src/main/kotlin/app/aaps/ui/compose/configuration/ConfigurationScreen.kt`

## Accessibility Patterns
- Decorative icons that are part of a labeled row: `contentDescription = null` is acceptable
- Action icons (IconButton) MUST have meaningful contentDescription
- ConfigurationScreen Settings cog IconButton uses `contentDescription = null` — this is a known bug (line 321)
- Disabled alpha convention: `0.38f` (matches Material spec) — used inline as a local val, no shared constant in core/ui yet

## ConfigPluginItem Interaction Patterns
- Card is only clickable when plugin is enabled (line 337: `.then(if (isEnabled) Modifier.clickable {...} else Modifier)`)
- This creates an interaction gap: disabled plugins have no tap feedback at all — users may tap and think the app froze
- Switch `onCheckedChange = null` correctly disables it when `canToggle = false` (renders as non-interactive)
- The Settings cog is hidden when plugin is disabled (correct) — avoids dead-end navigation
- Trailing Row contains both cog + switch with no spacer between them — they sit very close together (touch target collision risk)
- `vertical = 2.dp` card margin is tight — cards stack with minimal breathing room

## Patterns Seen
- QuickLaunchConfigScreen uses `OutlinedIconButton` for add/remove row actions
- DrawerMenuItem uses full-width clickable rows with icon + label + description
- ListItem trailing content uses default IconButton (48dp touch target, no size constraint)
24 changes: 24 additions & 0 deletions .claude/agent-memory/ui-to-common/MEMORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Memory Index — ui-to-common

## Module migration state

- [androidMain Compose backlog survey](project_androidmain-compose-backlog-survey.md) — every non-pump module counted and its blockers classified; :ui leads with 12 proven-mechanical files.
- [Constraints objectives move](project_constraints-objectives-move.md) — ObjectivesScreen is in commonMain; the 14 remaining files are pinned by exactly 3 root causes and have no movable subset.
- [Configuration setup wizard blocked](project_configuration-setupwizard-blocked.md) — all 3 remaining Compose files pinned by SWDefinition and CryptoUtil; needs a :core:* decision first.

- [APS Loop move](project_aps-loop-move.md) — Loop screen+VM+ComposeContent are in commonMain with no build file edit; the duplicated `constraints` string trap.
- [:ui 12-file batch moved](project_ui-twelve-file-batch-moved.md) — done and kept with 46 mutation-proven tests; :ui 36→24, and the Robolectric setup that survives a move.
- [Overview three variants covered](project_overview-three-variants-covered.md) — 10 mutation-proven tests pin what differs between the stacked/split/tablet layouts; what is still only rendered.

## Reference

- [What crosses to CMP unchanged](reference_cmp-what-crosses-unchanged.md) — extended icons, LocalUriHandler, rememberSaveable, Canvas all move with zero edits; grep for the real blockers instead.
- [A move breaks two test harnesses](reference_move-breaks-two-test-harnesses.md) — every commonMain screen move reds Robolectric string lookups and mocked-ResourceHelper tests; both fixes, and how to write a test that is immune.
- [metroViewModel is NOT a blocker](reference_metroviewmodel-is-not-a-blocker.md) — the expect/actual has a working iOS actual and 37 users; two earlier runs stopped on this wrongly.
- [No plural API in commonMain](reference_no-plural-api-in-commonmain.md) — `rh.gq` has no shared counterpart at all; 11 call sites repo-wide, and replacing plurals with format strings breaks ~30 locales.
- [:ui screen test fixture](reference_ui-screen-test-fixture.md) — the shared Robolectric host for commonMain screens; the three locals a screen needs, and the null-in-a-TextField and write-then-reread traps.
- [Three-stage probe move](reference_probe-move-three-stage.md) — how to size a blocked move honestly: raw file, raw cluster, then cluster + mechanical fixes; the last one is the only informative compile.

## Working style

- [Prove the mutation restore](feedback_mutation-restore-proof.md) — after breaking code to test a test, show the diff proving it is back.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: feedback-mutation-restore-proof
description: Mutation testing must be ONE atomic bash call that restores unconditionally - never break in one step and restore in a later step
metadata:
type: feedback
---

Break-and-restore must happen **inside a single Bash call**, so the file is back before the call
returns. Never break production code in one step and restore it in a later step.

**Why:** a run announced "Round 1: mutating X" and hit its turn cap immediately after applying the
mutation. It left live sabotage in the tree - `preferences.put(key, value.toString())` instead of
`cryptoUtil.hashPassword(...)`, i.e. the user's master password stored in plaintext - and no report
existed to say it was there. The coordinator found and reverted it. You can be stopped between any
two steps, so a two-step mutation is unsafe by construction.

**How to apply:** one call, `;`-separated so the restore runs whatever gradle returns:

```
S=<scratchpad>; f=<path/to/Target.kt>
cp "$f" "$S/mut-backup.kt"
sed -i 's/<original>/<mutation>/' "$f"
./gradlew.bat :<module>:testAndroidHostTest --no-daemon > "$S/mut.log" 2>&1
cp "$S/mut-backup.kt" "$f"
git -C E:/GitHub/AndroidAPS diff HEAD -- "$f" # must print nothing
grep -E "BUILD SUCCESSFUL|BUILD FAILED" "$S/mut.log"
```

Restore with `cp` from the backup, not by reversing the `sed`. Then read the **test names** that went
red from the results XML - a failure *count* does not prove the right test caught it. Parse the XML
with a PowerShell `[xml]` cast over `testsuite.testcase` and print `$tc.failure` entries; the
regex-over-XML one-liner only gives totals.

Batch several mutations into one round when each breaks a distinct test and none masks another.
Never end a turn with production code modified, except by the real move itself. If turns are short,
restore first and report second.

Related: [[constraints-objectives-move]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
name: androidmain-compose-backlog-survey
description: 2026-08-30 survey of every non-pump module's remaining androidMain Compose files, with each module's blockers grouped by root cause and classified mechanical / needs-a-port / needs-a-decision
metadata:
type: project
---

Counts of files containing `@Composable` under `src/androidMain` (2026-08-30, non-pump):
`:ui` 36, `:plugins:sync` 21, `:core:ui` 8, `:plugins:automation` 6, `:plugins:aps` 3,
`:plugins:configuration` 3, `:plugins:constraints` 1, `:implementation` 1, `:appshell` 1,
`:plugins:calibration` 1. `:plugins:main`, `:plugins:source`, `:core:graph`, `:core:objects`,
`:wear` and `:shared:impl` have **zero** - do not spend a probe on them.

Three of the eight `:core:ui` files and one of the 21 `:plugins:sync` files are `*.android.kt`
**actual** declarations (`MetroViewModel`, `PlatformTheme`, `TextRefResource`, `ScreenshotBlocking`).
They belong in androidMain; never count them as backlog.

**Ranked by "Compose files whose only blockers are mechanical", measured by probe compiles:**

1. `:ui` - **12 files proven, and MOVED on 2026-08-30** - see [[ui-twelve-file-batch-moved]].
TempTargetCarouselCard, TempTargetManagementScreen, BgInfoSection(+Previews),
OverviewScreenSplit/Stacked/Tablet, ProfileHelperScreen(+Previews, + its ViewModel),
UserEntryScreen, TreatmentsScreen, QuickLaunchConfigScreen are now in commonMain.
The counts at the top of this note are the **pre-move** ones: `:ui` is now **24**, not 36.
2. `:plugins:sync` - **3 files proven** (the whole `xdrip/compose` cluster, 6 files incl. VM and
repository). Stage-3 probe green, 0 errors.
3. `:plugins:automation` - 2 files at best, and one needs an `android.R.string.ok/cancel` decision.
4. `:core:ui` - 0. Every remaining file is a platform capability.
5. `:plugins:aps` - 0. Autotune is one cluster pinned by its engine.

**The mechanical fixes that were actually needed** (all verified by a green iosArm64 compile):
`java.util.concurrent.atomic.AtomicLong` -> `kotlin.concurrent.atomics` (`getAndIncrement` ->
`fetchAndIncrement`); `System.currentTimeMillis()` -> `Clock.System.now().toEpochMilliseconds()`;
`java.time` -> `kotlin.time.Instant` + `kotlinx.datetime.toLocalDateTime`; `Dispatchers.IO` ->
`aapsIoDispatcher`; `ResourceHelper` -> `TextResolver`; `java.lang.Math.toDegrees/toRadians` ->
`* 180.0 / PI`; deleting a dead `androidx.compose.ui.res.stringResource` import; deleting an unused
`LocalContext.current`; dropping `@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)`.

**Two blockers that look like libraries and are really one line of build file.** `:ui` declares
`libs.sh.calvin.reorderable` in androidMain only, while `:plugins:automation` already declares the
same artifact in **commonMain** with a comment saying it works everywhere - so
`QuickLaunchConfigScreen` needs a dependency moved, not a rewrite. Same shape in `:plugins:aps`,
which reaches `app.aaps.core.graph.profile.*` (already commonMain) but declares `:core:graph` in
androidMain only. Check the build file before calling a third-party import a blocker.

**`rh.gq(` plurals block NONE of these modules.** Still 11 sites in 5 files, all in
`:core:interfaces`, `:implementation`, `:plugins:constraints` and `pump/*`. See
[[no-plural-api-in-commonmain]].

**Blockers that need a decision, with what they pin:**

- `@StringRes Int` already sitting in `:core:interfaces` **commonMain**: `CustomAction.name: Int`
pins `ManageBottomSheet`; `PrefsMetadataKey.label: Int` pins `:core:ui` `ImportSummaryComponents`.
Changing either touches every pump driver.
- `FileListProvider` pins the whole `:ui` maintenance cluster - ImportSettingsScreen,
MaintenanceDialogs, MaintenanceBottomSheet, CloudDirectorySheet, and both maintenance ViewModels.
A probe that moves any maintenance file alone will fail on `MaintenanceViewModel`.
- `:ui` search: OkHttp + `org.json` + `java.text.Normalizer` in `WikiSearchRepository` /
`SearchIndexBuilder`. Pins `MainScreen` and `MainTopBar` through `SearchUiState`.
- `android.R.string.ok` / `android.R.string.cancel` used as real UI text - 4 sites in
`AutomationComposeContent`, 1 in `:core:ui` `ImportSummaryComponents`. `CoreUiStrings.ok/cancel`
exist, but swapping changes which catalogue translates the button in ~30 locales.
- `is24HourFormat`: a `DateFormatPlatform` port **already exists** but lives in `:shared:impl`
commonMain, and `:ui` does not depend on `:shared:impl`. Pins `ProfileActivationScreen`.

**Blockers that need a port designed, with what they pin:** window size class
(`LocalConfiguration.orientation` + `smallestScreenWidthDp`) pins `OverviewScreen` and
`SmsCommunicatorOtpScreen`; screen control (orientation lock, keep-screen-on, FLAG_SECURE) pins
`SiteRotationManagementScreen`, `:core:ui` `KeepScreenOnEffect` and the existing
`ScreenshotBlocking` actual; runtime permissions and BLE pre-check pin `:core:ui`
`BluetoothPermissionsHost` / `BlePreCheckHost` and `:ui` `PermissionsViewModel`; biometrics
(`FragmentActivity`) pins `:core:ui` `ProtectionHost`; `Build.MANUFACTURER` pins `AboutDialog`; Glance pins the three widget files, permanently.

**Dead code found while surveying, worth confirming before deleting:**
`AutomationComposeContent` threads `activity: FragmentActivity?` through three routes and then does
`@Suppress("UNUSED_EXPRESSION") activity` with the comment "kept for future use" - it is the only
reason that file needs `LocalContext`. `ProfileHelperScreen` has a bare `LocalContext.current` whose
result is discarded, `UserEntryScreen` has an unused `val context`, `AboutDialogPreviews` has an
unused `import app.aaps.core.ui.R`, and `TempTargetCarouselCard` imports the androidx
`stringResource` although its helper already returns a `TextRef`.

Related: [[probe-move-three-stage]], [[cmp-what-crosses-unchanged]], [[constraints-objectives-move]],
[[configuration-setupwizard-blocked]]
37 changes: 37 additions & 0 deletions .claude/agent-memory/ui-to-common/project_aps-loop-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: aps-loop-move
description: plugins/aps Loop feature (screen + ViewModel + ComposeContent) is in commonMain; the module needs no build file change and no expect/actual
metadata:
type: project
---

The Loop feature - `LoopViewModel.kt` (holds `LoopUiState`), `LoopScreen.kt`, `LoopComposeContent.kt`
- moved to `plugins/aps/src/commonMain/kotlin/app/aaps/plugins/aps/loop/compose/` and compiles for
iosArm64. Nothing was left behind and no `expect`/`actual` was needed.

**Why it was easy, for the next module:**

- **No build file edit.** `:core:ui` exports the whole Compose stack with `api(libs.cmp.*)`, so a
module with `implementation(project(":core:ui"))` already has material3, foundation and
`jetbrains.lifecycle.viewmodel.compose` on its commonMain classpath. `plugins/aps/build.gradle.kts`
lists only `libs.cmp.runtime` and still compiled - do not add cmp dependencies reflexively.
- `PullToRefreshBox` and `collectAsStateWithLifecycle` both cross unchanged.
- `LoopComposeContent` was *not* pinned by any view model factory: it builds its view model with a
plain `remember { }` over a `rememberCoroutineScope()`. Check for that shape before assuming a
ComposeContent is blocked - `OpenAPSComposeContent` in the same module is the template.
- The only caller, `LoopPlugin`, needed **no change**: its `rh` is a `ResourceHelper`, which is a
`TextResolver`, so widening the parameter is source compatible.

**A string trap specific to this module.** `constraints` is declared in *both*
`plugins/aps/.../res/values/strings.xml` and `core/ui/.../res/values/strings.xml`. Android resource
merging gives the local module priority, so `R.string.constraints` inside `:plugins:aps` was always
the aps one - `ApsStrings.constraints` is the faithful replacement, not `CoreUiStrings.constraints`.
The English text is identical, so picking wrong would only show up as a wrong translation.

**Done and green.** The move initially left 8 tests red for harness reasons only - see
[[move-breaks-two-test-harnesses]]. The user approved four bootstrap lines (registry registration in
the two Robolectric tests, `stubTextRefResolution(rh)` in the two mock based ones); with those the
suite is 300 tests / 0 failures, and no assertion, expected value or test name was touched.

Related: [[move-breaks-two-test-harnesses]], [[metroviewmodel-is-not-a-blocker]],
[[cmp-what-crosses-unchanged]]
Loading