AGENTS.md — calculator/ (':calculator')
Scoped supplement. Global rules in root AGENTS.md apply. Stay inside calculator/ + allowed shared modules. Do not root-scan.
Install: ./install calculator (dev by default).
- Gradle: :calculator / dir: calculator/
- Package roots present: ui, widget, domain, platform, network, intents
- Entry files: MainActivity.kt + Route.kt + Navigation.kt (tab destinations: Calculator, Graph, Units)
- Deps: :library:network, :library:widgets
- Metadata: metadata_data/calculator.md (present)
- Rust: no / screenshotTest: yes
Overview
Purpose: Modern Material You calculator — scientific/basic modes, function graphing with analysis, and a multi-category unit converter with live currency rates. Key features:
- Scientific + basic keypad with multi-line expression history: lines stack above the input, tapping a line reuses its result, long-pressing loads its expression for in-place editing (submitting re-runs that line and every line after it in order), and assigned variables show above the input and survive AC
- Variables instead of an M register: the
varkey opens a dropup listing every assignable single letter with current values; selecting one inserts just its name (variable names are entered only this way — the 2nd layer shifts function/operator keys only and digit keys always emit digits). Variable names are lowercase-only: an uppercase letter in an expression is always a unit symbol, never a variable. Assignable letters area–zexcept the prohibited set inExpression.prohibitedSingleLetterVariableNames, derived case-sensitively from the engine's reserved meanings:e(Euler),x/t(graph free variable) and every single-letter unit token/alias inUnitRegistry.parseTokenswhose exact spelling is lowercase (c/g/h/k/l/m/s); today that leavesa/b/d/f/i/j/n/o/p/q/r/u/v/w/y/zassignable, so a letter whose only reserved form is capital (Aampere,Bbyte,Ffarad,Jjoule,Nnewton,Vvolt,Wwatt) is assignable in lowercase while its capital keeps the unit meaning (athe variable vs2Atwo amperes). A prohibited letter keeps its original meaning everywhere and can never be assigned: it is absent from the dropup and a<letter>=…line is rejected like other invalid assignments (an uppercase<Letter>=…line is likewise never an assignment); a pre-existing assignment to a now-prohibited letter is ignored (its line still evaluates, the variable is dropped) on the next re-evaluation. Picking a name, then the literal=key, a value and Enter assigns (d=5); a name alone plus Enter reads its value; any other line plus Enter evaluates as a plain expression. Only a leading<name>=<expr>line assigns on Enter, and reserved names (e, multi-letterans/pi/tau/phi/theta, functions, multi-letter unit tokens) can never be assigned. The literal=key is a regular key in the top section and never submits; the accent Enter key (filled return icon, bottom-right) submits - Graph page: plots functions with root / intercept / min-max / intersection detection
- Unit converter across many categories incl. live currency rates (
CurrencyApiover:library:network) - Home-screen widgets for both calculator and unit converter (
:library:widgetsGlance)
Architecture / data-flow: Single-screen MainActivity hosting ui/ pages (CalculatorPage, GraphPage, UnitConverterPage) over a platform/ ViewModel + pure domain/ expression/graph/units helpers; widget receivers in widget/ share the same logic. Internet is used only for currency rates. Entry points + reading order: MainActivity.kt → ui/CalculatorPage.kt → platform/CalculatorViewModel.kt + platform/CalculatorUiContract.kt → domain/Expression.kt / domain/GraphAnalysis.kt / domain/UnitRegistry.kt → widget/CalculatorGlanceWidget.kt. Gotchas:
- There is no M memory register and no MC/MR/M+/M- keys; state that must persist across AC lives in assigned variables (
CalculatorTab.variables), re-derived by re-evaluating history lines in order on every Enter - Currency rates are the only network call — everything else must stay offline-safe
Key files
Root — entry
- com/vayunmathur/calculator/MainActivity.kt
- com/vayunmathur/calculator/Route.kt + Navigation.kt
ui/ — keypad, graph, converter pages
- com/vayunmathur/calculator/ui/CalculatorPage.kt
- com/vayunmathur/calculator/ui/CalculatorKeypad.kt
- com/vayunmathur/calculator/ui/CalculatorVariablePicker.kt — the
varkey + variable dropup - com/vayunmathur/calculator/ui/CalculatorDialogs.kt (unit-picker sheet; its absolute-time date/time pickers stay local — see the DIALOG LOCAL EXCEPTION in the file)
- com/vayunmathur/calculator/ui/GraphPage.kt
- com/vayunmathur/calculator/ui/UnitConverterPage.kt
platform/ — ViewModel + UI contract (domain/ — pure engine)
- com/vayunmathur/calculator/platform/CalculatorViewModel.kt
- com/vayunmathur/calculator/platform/CalculatorUiContract.kt —
CalculatorUiState.variables(name → formatted value),CalculatorActions.insertVariable/evaluate - com/vayunmathur/calculator/platform/CalculatorTab.kt — input/history/variables, multi-line re-evaluation, assignment on Enter
- com/vayunmathur/calculator/domain/Expression.kt — expression parsing/eval; named variables,
Expression.assignableVariableNames,Expression.isVariableNameAvailable - com/vayunmathur/calculator/domain/GraphAnalysis.kt — root/intercept/min-max/intersection
- com/vayunmathur/calculator/domain/UnitRegistry.kt
- com/vayunmathur/calculator/network/CurrencyApi.kt — only network call
- com/vayunmathur/calculator/domain/Formatting.kt
intents/ — assistant IPC (validated contracts over the engines above)
- com/vayunmathur/calculator/intents/CalculatorContract.kt — caps + validation (expression ≤200 ch, result ≤100 ch); evaluation reuses
domain/Expression, conversion reusesdomain/UnitRegistry+ live currency category - com/vayunmathur/calculator/intents/EvaluateIntent.kt —
calculator_evaluate(scalar result) - com/vayunmathur/calculator/intents/ConvertUnitIntent.kt —
calculator_convert_unit(the app's one network call, live rates, only for currency pairs)
widget/ — Glance widgets sharing the same logic
- com/vayunmathur/calculator/widget/CalculatorGlanceWidget.kt
- com/vayunmathur/calculator/widget/CalculatorGlanceWidgetReceiver.kt
- com/vayunmathur/calculator/widget/CalculatorKeyAction.kt
- com/vayunmathur/calculator/widget/CalculatorWidgetSettingsActivity.kt
- com/vayunmathur/calculator/widget/UnitsGlanceWidget.kt
- com/vayunmathur/calculator/widget/UnitsGlanceWidgetReceiver.kt
- com/vayunmathur/calculator/widget/UnitsWidgetActions.kt
Verify (this module only)
./gradlew :calculator:compileDevKotlin
./gradlew :calculator:lint :calculator:lintVitalRelease :calculator:testDevUnitTest
./gradlew :calculator:checkMetadata