chore: adopt the project template and add the Kotlin/Compose skeleton
Period was a bare directory holding one 2,527-line specification, with no git
repository, no tracker and no documentation convention. This is the adoption
from Projects/Template/START-HERE-New-Project.md, plus a project that compiles
so the hooks and future guards have something real to run against.
Documents. scaffold.sh created 19 paths, 0 skipped. The specification moved to
docs/planning/PRODUCT_PLAN.md unchanged in substance, with a status header; the
capitalised Docs/ is gone. Every scaffolded document was filled in for Period.
docs/OPERATIONS.md deleted — an offline app is not a deployed service.
DOC_TRUST_MAP.md written last, describing what is actually here, including what
this project deliberately does not have.
Code. Four Gradle modules. domain/cycle and domain/prediction are kotlin("jvm")
and cannot see the Android SDK, so the engine is testable without an emulator —
17 tests pass, 12 of them the acceptance cases from PRODUCT_PLAN.md §51.
BaselinePredictionEngine is a robust-median prototype and explicitly not the
product; it exists so Batch 02's replacement can be shown to be better rather
than merely different.
Versions verified against their official sources today rather than inherited
from the specification's own numbers, which that document asks for: Kotlin
2.4.10, AGP 9.3.1, Gradle 9.7.0, Compose BOM 2026.08.00, Room 2.8.4, Hilt
2.60.1. AGP 9 ships Kotlin built in, so org.jetbrains.kotlin.android is no
longer applied. compileSdk is 37 because current AndroidX requires it; targetSdk
stays 36, Play's floor from 2026-08-31, and the difference is deliberate.
Six scripts taken into scripts/; the rest declined and named in docs/TOOLS.md.
Three hooks in .githooks/, with pre-commit adapted to Gradle.
closes #1
closes #2
2026-08-18 02:16:47 -05:00
|
|
|
// AGP 9 has built-in Kotlin support, so there is no org.jetbrains.kotlin.android
|
|
|
|
|
// plugin here — applying it is now an error rather than a redundancy.
|
|
|
|
|
// The Compose compiler plugin is still applied separately.
|
|
|
|
|
// See https://developer.android.com/build/migrate-to-built-in-kotlin
|
|
|
|
|
plugins {
|
|
|
|
|
alias(libs.plugins.android.application) apply false
|
|
|
|
|
alias(libs.plugins.android.library) apply false
|
|
|
|
|
alias(libs.plugins.kotlin.jvm) apply false
|
|
|
|
|
alias(libs.plugins.kotlin.compose) apply false
|
|
|
|
|
alias(libs.plugins.ksp) apply false
|
|
|
|
|
alias(libs.plugins.hilt) apply false
|
feat: module boundary guard, and two API-level bugs it uncovered
checkModuleBoundaries holds the dependency tables in docs/architecture/README.md
as a check: every module's permitted project dependencies, plus the rule that
domain:cycle and domain:prediction must never apply an Android plugin. core:ads
is already in the map with an empty permitted set, before the module exists —
PRODUCT_PLAN.md §34 is non-negotiable, and a guard written alongside the code it
constrains is one shaped around whatever exception somebody wanted at the time.
It lists every violation rather than the first, and refuses to report a pass
when it examined no modules at all.
THE GUARD FAILED ITS OWN FIRST PROOF
prove-guard.sh injected a forbidden dependency into :domain:prediction and the
guard reported "7 modules checked, no violations". The root project is
configured before its subprojects, so reading subprojects.configurations from
the root script saw every configuration empty — it had been green over an empty
map since the moment it was written, and would have been trusted for months.
Collection moved into afterEvaluate, and the task now throws rather than passing
if it ends up with no modules. Three proofs recorded in the architecture doc,
all re-run and all red: a domain module reaching upward, :app reaching past the
repository straight to Room, and a module with no rule being reported as
unmeasured rather than assumed fine.
TWO REAL BUGS FROM WIRING IT INTO `check`
Running the whole check for the first time turned up Android lint errors that
would have shipped:
NewApi: java.time.LocalDate#ofInstant requires API 34 (minSdk is 26)
NewApi: java.time.LocalDate#EPOCH requires API 34 (minSdk is 26)
Both are on the recalculation path. On any device below Android 14 — most of
the install base this app targets — that is a crash. Neither the unit tests nor
the API 36 emulator could see it; lint is the only thing that could.
Replaced with atZone().toLocalDate() and ofEpochDay(0), which are API 26.
Also cleared the lint warnings that were real: a redundant activity label, and
a round launcher icon declared but never referenced. The two that remain are
deliberate and now say so where the warning is read — targetSdk 36 is Play's
floor and raising it opts into untested runtime behaviour, and the -v26 mipmap
qualifier stays because removing it makes AAPT fail to resolve the icon at all.
./gradlew check now passes with 0 lint errors across all seven modules.
70 unit tests, all passing.
closes #7
2026-08-18 03:00:11 -05:00
|
|
|
alias(libs.plugins.room) apply false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// Module boundaries
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
//
|
|
|
|
|
// The dependency table in docs/architecture/README.md, as a check.
|
|
|
|
|
//
|
|
|
|
|
// Two boundaries in this project are load-bearing and neither can be held up by
|
|
|
|
|
// people remembering them:
|
|
|
|
|
//
|
|
|
|
|
// 1. `domain:*` must not see the Android SDK. It is why the prediction
|
|
|
|
|
// engine's tests run in a second instead of on an emulator, and one
|
|
|
|
|
// contributor reaching for a convenient Android API would end that with no
|
|
|
|
|
// test failing.
|
|
|
|
|
// 2. The advertising subsystem must never reach cycle data. PRODUCT_PLAN.md
|
|
|
|
|
// §34 states it as non-negotiable: no menstrual date, cycle length,
|
|
|
|
|
// fertility status, ovulation estimate, prediction confidence, prediction
|
|
|
|
|
// history or spotting record may reach advertising, ever.
|
|
|
|
|
//
|
|
|
|
|
// The second is written down before `core:ads` exists on purpose. A guard added
|
|
|
|
|
// alongside the code it constrains is a guard that was shaped around whatever
|
|
|
|
|
// exception somebody wanted at the time.
|
|
|
|
|
//
|
|
|
|
|
// Run: ./gradlew checkModuleBoundaries (also wired into `check`)
|
|
|
|
|
// Prove it fails: bash scripts/prove-guard.sh
|
|
|
|
|
//
|
|
|
|
|
// Exit is non-zero with every violation listed, not just the first — a guard
|
|
|
|
|
// that reports one problem per run turns a five-minute fix into five runs.
|
|
|
|
|
|
|
|
|
|
/** Project dependencies each module is permitted. Anything else fails. */
|
|
|
|
|
val allowedProjectDependencies: Map<String, Set<String>> = mapOf(
|
feat: reminders that stay quiet on a lock screen
§28, §29, §30 and §31. NotificationCopy is a pure function — privacy mode plus
kind plus day count in, two versions of the text out — so every combination is
tested exhaustively without an emulator. This is the one surface whose mistakes
are visible to somebody who is not the user, so the tests are exhaustive rather
than representative: every kind × every mode asserts that no health word reaches
a lock screen outside Direct, and that includes the ACTION LABELS, which §31
points out are visible text too. A perfectly discreet body under a button
reading "Started my period" leaks anyway.
TWO ANDROID BEHAVIOURS THAT LEAK IF YOU TRUST THE DOCS
A private notification with no public version does not blank the lock screen —
it shows the private text. NotificationText therefore has no nullable title and
an instrumented test asserts every kind attaches one.
And a notification channel is IMMUTABLE after creation: importance and
lock-screen visibility cannot be changed. One shared channel would have kept
whatever the user's first privacy mode set, forever — switching from Direct to
Maximum privacy would have appeared to work and changed nothing. There is now
one channel per mode. Found by an instrumented test on a device; nothing in the
unit tests could have seen it.
§30's stopping rule is a test of its own: the app asks a bounded number of times,
says "We'll stop checking for now. Log your period whenever it begins.", and
then says nothing more — while the engine keeps learning, which is the sentence
§30 puts right after it.
WorkManager, and no exact alarms. §31 rules them out and the new checkPermissions
task fails the build if one ever appears in the merged manifest — from here or
from a dependency. That guard also failed its own first proof, reading a stale
manifest because it did not depend on the task that writes one.
ReminderCoordinator reschedules whenever the forecast moves, which §31 asks for
and is the requirement most likely to be missed: a "Not yet" moves the forecast,
so work queued against the old one is aimed at a day that no longer means
anything.
188 unit tests and 6 instrumented, all passing. ./gradlew check green.
closes #24
closes #25
closes #26
closes #27
2026-08-18 15:26:59 -05:00
|
|
|
":app" to setOf(
|
|
|
|
|
":core:designsystem", ":core:data", ":core:datastore", ":core:notifications",
|
|
|
|
|
":domain:cycle", ":domain:prediction",
|
|
|
|
|
),
|
feat: module boundary guard, and two API-level bugs it uncovered
checkModuleBoundaries holds the dependency tables in docs/architecture/README.md
as a check: every module's permitted project dependencies, plus the rule that
domain:cycle and domain:prediction must never apply an Android plugin. core:ads
is already in the map with an empty permitted set, before the module exists —
PRODUCT_PLAN.md §34 is non-negotiable, and a guard written alongside the code it
constrains is one shaped around whatever exception somebody wanted at the time.
It lists every violation rather than the first, and refuses to report a pass
when it examined no modules at all.
THE GUARD FAILED ITS OWN FIRST PROOF
prove-guard.sh injected a forbidden dependency into :domain:prediction and the
guard reported "7 modules checked, no violations". The root project is
configured before its subprojects, so reading subprojects.configurations from
the root script saw every configuration empty — it had been green over an empty
map since the moment it was written, and would have been trusted for months.
Collection moved into afterEvaluate, and the task now throws rather than passing
if it ends up with no modules. Three proofs recorded in the architecture doc,
all re-run and all red: a domain module reaching upward, :app reaching past the
repository straight to Room, and a module with no rule being reported as
unmeasured rather than assumed fine.
TWO REAL BUGS FROM WIRING IT INTO `check`
Running the whole check for the first time turned up Android lint errors that
would have shipped:
NewApi: java.time.LocalDate#ofInstant requires API 34 (minSdk is 26)
NewApi: java.time.LocalDate#EPOCH requires API 34 (minSdk is 26)
Both are on the recalculation path. On any device below Android 14 — most of
the install base this app targets — that is a crash. Neither the unit tests nor
the API 36 emulator could see it; lint is the only thing that could.
Replaced with atZone().toLocalDate() and ofEpochDay(0), which are API 26.
Also cleared the lint warnings that were real: a redundant activity label, and
a round launcher icon declared but never referenced. The two that remain are
deliberate and now say so where the warning is read — targetSdk 36 is Play's
floor and raising it opts into untested runtime behaviour, and the -v26 mipmap
qualifier stays because removing it makes AAPT fail to resolve the icon at all.
./gradlew check now passes with 0 lint errors across all seven modules.
70 unit tests, all passing.
closes #7
2026-08-18 03:00:11 -05:00
|
|
|
":core:designsystem" to emptySet(),
|
|
|
|
|
":core:database" to setOf(":domain:cycle", ":domain:prediction"),
|
|
|
|
|
":core:datastore" to emptySet(),
|
|
|
|
|
":core:data" to setOf(":core:database", ":domain:cycle", ":domain:prediction"),
|
feat: reminders that stay quiet on a lock screen
§28, §29, §30 and §31. NotificationCopy is a pure function — privacy mode plus
kind plus day count in, two versions of the text out — so every combination is
tested exhaustively without an emulator. This is the one surface whose mistakes
are visible to somebody who is not the user, so the tests are exhaustive rather
than representative: every kind × every mode asserts that no health word reaches
a lock screen outside Direct, and that includes the ACTION LABELS, which §31
points out are visible text too. A perfectly discreet body under a button
reading "Started my period" leaks anyway.
TWO ANDROID BEHAVIOURS THAT LEAK IF YOU TRUST THE DOCS
A private notification with no public version does not blank the lock screen —
it shows the private text. NotificationText therefore has no nullable title and
an instrumented test asserts every kind attaches one.
And a notification channel is IMMUTABLE after creation: importance and
lock-screen visibility cannot be changed. One shared channel would have kept
whatever the user's first privacy mode set, forever — switching from Direct to
Maximum privacy would have appeared to work and changed nothing. There is now
one channel per mode. Found by an instrumented test on a device; nothing in the
unit tests could have seen it.
§30's stopping rule is a test of its own: the app asks a bounded number of times,
says "We'll stop checking for now. Log your period whenever it begins.", and
then says nothing more — while the engine keeps learning, which is the sentence
§30 puts right after it.
WorkManager, and no exact alarms. §31 rules them out and the new checkPermissions
task fails the build if one ever appears in the merged manifest — from here or
from a dependency. That guard also failed its own first proof, reading a stale
manifest because it did not depend on the task that writes one.
ReminderCoordinator reschedules whenever the forecast moves, which §31 asks for
and is the requirement most likely to be missed: a "Not yet" moves the forecast,
so work queued against the old one is aimed at a day that no longer means
anything.
188 unit tests and 6 instrumented, all passing. ./gradlew check green.
closes #24
closes #25
closes #26
closes #27
2026-08-18 15:26:59 -05:00
|
|
|
":core:notifications" to setOf(":core:data", ":core:datastore", ":domain:cycle", ":domain:prediction"),
|
feat: module boundary guard, and two API-level bugs it uncovered
checkModuleBoundaries holds the dependency tables in docs/architecture/README.md
as a check: every module's permitted project dependencies, plus the rule that
domain:cycle and domain:prediction must never apply an Android plugin. core:ads
is already in the map with an empty permitted set, before the module exists —
PRODUCT_PLAN.md §34 is non-negotiable, and a guard written alongside the code it
constrains is one shaped around whatever exception somebody wanted at the time.
It lists every violation rather than the first, and refuses to report a pass
when it examined no modules at all.
THE GUARD FAILED ITS OWN FIRST PROOF
prove-guard.sh injected a forbidden dependency into :domain:prediction and the
guard reported "7 modules checked, no violations". The root project is
configured before its subprojects, so reading subprojects.configurations from
the root script saw every configuration empty — it had been green over an empty
map since the moment it was written, and would have been trusted for months.
Collection moved into afterEvaluate, and the task now throws rather than passing
if it ends up with no modules. Three proofs recorded in the architecture doc,
all re-run and all red: a domain module reaching upward, :app reaching past the
repository straight to Room, and a module with no rule being reported as
unmeasured rather than assumed fine.
TWO REAL BUGS FROM WIRING IT INTO `check`
Running the whole check for the first time turned up Android lint errors that
would have shipped:
NewApi: java.time.LocalDate#ofInstant requires API 34 (minSdk is 26)
NewApi: java.time.LocalDate#EPOCH requires API 34 (minSdk is 26)
Both are on the recalculation path. On any device below Android 14 — most of
the install base this app targets — that is a crash. Neither the unit tests nor
the API 36 emulator could see it; lint is the only thing that could.
Replaced with atZone().toLocalDate() and ofEpochDay(0), which are API 26.
Also cleared the lint warnings that were real: a redundant activity label, and
a round launcher icon declared but never referenced. The two that remain are
deliberate and now say so where the warning is read — targetSdk 36 is Play's
floor and raising it opts into untested runtime behaviour, and the -v26 mipmap
qualifier stays because removing it makes AAPT fail to resolve the icon at all.
./gradlew check now passes with 0 lint errors across all seven modules.
70 unit tests, all passing.
closes #7
2026-08-18 03:00:11 -05:00
|
|
|
":domain:cycle" to emptySet(),
|
|
|
|
|
":domain:prediction" to setOf(":domain:cycle"),
|
|
|
|
|
// Batch 07. Empty, and that is the whole point: the ads module may reach
|
|
|
|
|
// NOTHING in this project. It talks to the UI through an AdProvider
|
|
|
|
|
// interface owned by :app.
|
|
|
|
|
":core:ads" to emptySet(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/** Modules that must never see the Android SDK, by never applying an Android plugin. */
|
|
|
|
|
val mustStayPureJvm = setOf(":domain:cycle", ":domain:prediction")
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configurations that describe what SHIPS. Test-only dependencies are not a
|
|
|
|
|
* product boundary — a test may reach for a fake or an in-memory database that
|
|
|
|
|
* production must not — so they are deliberately not examined here.
|
|
|
|
|
*/
|
|
|
|
|
val shippingConfigurations = setOf("implementation", "api", "compileOnly", "runtimeOnly", "ksp")
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// Collected in afterEvaluate, and that is not a detail.
|
|
|
|
|
//
|
|
|
|
|
// The first version of this read `subprojects.configurations` directly in the
|
|
|
|
|
// root build script. The root project is configured BEFORE its subprojects, so
|
|
|
|
|
// every configuration was empty, every module had no dependencies, and the task
|
|
|
|
|
// printed "7 modules checked, no violations" while checking nothing at all.
|
|
|
|
|
//
|
|
|
|
|
// It was caught by `scripts/prove-guard.sh` on the first run — a deliberate
|
|
|
|
|
// forbidden dependency was added to :domain:prediction and the guard stayed
|
|
|
|
|
// green. That is precisely the failure GUARDS.md §1 exists for, and it is why
|
|
|
|
|
// no guard here is believed until it has been watched failing.
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
val observedProjectDependencies = mutableMapOf<String, Set<String>>()
|
|
|
|
|
val observedAndroidPlugins = mutableMapOf<String, List<String>>()
|
|
|
|
|
val containerProjects = mutableSetOf<String>()
|
|
|
|
|
|
|
|
|
|
subprojects {
|
|
|
|
|
afterEvaluate {
|
|
|
|
|
if (!buildFile.exists()) {
|
|
|
|
|
// `include(":core:database")` makes Gradle create an intermediate
|
|
|
|
|
// `:core` project with nothing to build. Containers, not modules —
|
|
|
|
|
// named in the output rather than dropped, because "skipped" and
|
|
|
|
|
// "passed" must not look the same.
|
|
|
|
|
containerProjects += path
|
|
|
|
|
return@afterEvaluate
|
|
|
|
|
}
|
|
|
|
|
observedProjectDependencies[path] = configurations
|
|
|
|
|
.filter { it.name in shippingConfigurations }
|
|
|
|
|
.flatMap { conf -> conf.dependencies.filterIsInstance<ProjectDependency>() }
|
|
|
|
|
.map { it.path }
|
|
|
|
|
.toSet()
|
|
|
|
|
observedAndroidPlugins[path] = plugins.mapNotNull { plugin ->
|
|
|
|
|
plugin::class.qualifiedName?.takeIf { it.contains("com.android.build") }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tasks.register("checkModuleBoundaries") {
|
|
|
|
|
group = "verification"
|
|
|
|
|
description = "Every module's project dependencies must match docs/architecture/README.md."
|
|
|
|
|
|
|
|
|
|
val allowed = allowedProjectDependencies
|
|
|
|
|
val observed = observedProjectDependencies
|
|
|
|
|
val androidPlugins = observedAndroidPlugins
|
|
|
|
|
val pureJvm = mustStayPureJvm
|
|
|
|
|
val containers = containerProjects
|
|
|
|
|
|
|
|
|
|
// Providers, not values: these maps are filled during afterEvaluate, which
|
|
|
|
|
// has not run when this task is being registered. Reading them eagerly here
|
|
|
|
|
// is the same mistake as reading them in the root script.
|
|
|
|
|
inputs.property("allowed", allowed.toString())
|
|
|
|
|
inputs.property("observed", provider { observed.toString() })
|
|
|
|
|
inputs.property("androidPlugins", provider { androidPlugins.toString() })
|
|
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
|
val violations = mutableListOf<String>()
|
|
|
|
|
|
|
|
|
|
val modules = observed.keys
|
|
|
|
|
|
|
|
|
|
// Refuse to report a pass over nothing. An empty map here means the
|
|
|
|
|
// collection above did not run, which is exactly how this guard was
|
|
|
|
|
// green while checking nothing.
|
|
|
|
|
if (modules.isEmpty()) {
|
|
|
|
|
throw GradleException(
|
|
|
|
|
"no modules were examined, so nothing was checked. This is not a pass — " +
|
|
|
|
|
"see the afterEvaluate note in build.gradle.kts.",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A module nobody declared a rule for is not "allowed anything" — it is
|
|
|
|
|
// unmeasured, and reporting it as a pass is how a boundary quietly stops
|
|
|
|
|
// covering half the project.
|
|
|
|
|
(modules - allowed.keys).sorted().forEach {
|
|
|
|
|
violations += "$it has no entry in allowedProjectDependencies, so its dependencies were never checked."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
observed.forEach { (module, deps) ->
|
|
|
|
|
if (module in containers) return@forEach
|
|
|
|
|
val permitted = allowed[module] ?: return@forEach
|
|
|
|
|
(deps - permitted).sorted().forEach { dep ->
|
|
|
|
|
violations += "$module depends on $dep, which the architecture does not permit."
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pureJvm.forEach { module ->
|
|
|
|
|
androidPlugins[module]?.takeIf { it.isNotEmpty() }?.let { plugins ->
|
|
|
|
|
violations += "$module applies an Android plugin (${plugins.first()}). " +
|
|
|
|
|
"It must stay pure JVM so the prediction engine is testable without an emulator."
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (violations.isNotEmpty()) {
|
|
|
|
|
logger.error("")
|
|
|
|
|
logger.error("Module boundary violations:")
|
|
|
|
|
violations.forEach { logger.error(" - $it") }
|
|
|
|
|
logger.error("")
|
|
|
|
|
logger.error("These are the rules in docs/architecture/README.md. If the architecture")
|
|
|
|
|
logger.error("changed on purpose, change that table and the map in build.gradle.kts in")
|
|
|
|
|
logger.error("the same commit. If it did not, this dependency is the mistake.")
|
|
|
|
|
throw GradleException("${violations.size} module boundary violation(s).")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.lifecycle(
|
|
|
|
|
"module boundaries: ${modules.size} module(s) checked, " +
|
|
|
|
|
"${pureJvm.size} required to stay pure JVM, no violations.",
|
|
|
|
|
)
|
|
|
|
|
if (containers.isNotEmpty()) {
|
|
|
|
|
logger.lifecycle(
|
|
|
|
|
" (skipped ${containers.size} container project(s) with no build file: " +
|
|
|
|
|
"${containers.sorted().joinToString(", ")})",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: reminders that stay quiet on a lock screen
§28, §29, §30 and §31. NotificationCopy is a pure function — privacy mode plus
kind plus day count in, two versions of the text out — so every combination is
tested exhaustively without an emulator. This is the one surface whose mistakes
are visible to somebody who is not the user, so the tests are exhaustive rather
than representative: every kind × every mode asserts that no health word reaches
a lock screen outside Direct, and that includes the ACTION LABELS, which §31
points out are visible text too. A perfectly discreet body under a button
reading "Started my period" leaks anyway.
TWO ANDROID BEHAVIOURS THAT LEAK IF YOU TRUST THE DOCS
A private notification with no public version does not blank the lock screen —
it shows the private text. NotificationText therefore has no nullable title and
an instrumented test asserts every kind attaches one.
And a notification channel is IMMUTABLE after creation: importance and
lock-screen visibility cannot be changed. One shared channel would have kept
whatever the user's first privacy mode set, forever — switching from Direct to
Maximum privacy would have appeared to work and changed nothing. There is now
one channel per mode. Found by an instrumented test on a device; nothing in the
unit tests could have seen it.
§30's stopping rule is a test of its own: the app asks a bounded number of times,
says "We'll stop checking for now. Log your period whenever it begins.", and
then says nothing more — while the engine keeps learning, which is the sentence
§30 puts right after it.
WorkManager, and no exact alarms. §31 rules them out and the new checkPermissions
task fails the build if one ever appears in the merged manifest — from here or
from a dependency. That guard also failed its own first proof, reading a stale
manifest because it did not depend on the task that writes one.
ReminderCoordinator reschedules whenever the forecast moves, which §31 asks for
and is the requirement most likely to be missed: a "Not yet" moves the forecast,
so work queued against the old one is aimed at a day that no longer means
anything.
188 unit tests and 6 instrumented, all passing. ./gradlew check green.
closes #24
closes #25
closes #26
closes #27
2026-08-18 15:26:59 -05:00
|
|
|
// ===========================================================================
|
|
|
|
|
// Permissions
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
//
|
|
|
|
|
// The Play listing shows this list, the Data Safety form has to describe it, and
|
|
|
|
|
// a privacy-first period tracker is judged on it before anybody opens the app.
|
|
|
|
|
//
|
|
|
|
|
// It is also the list most likely to grow without anyone deciding to grow it: a
|
|
|
|
|
// dependency added for one feature brings its own <uses-permission>, the merge
|
|
|
|
|
// is silent, and it appears in the store listing months later. Adding
|
|
|
|
|
// WorkManager to this project added four in one line — WAKE_LOCK,
|
|
|
|
|
// ACCESS_NETWORK_STATE, RECEIVE_BOOT_COMPLETED and FOREGROUND_SERVICE — none of
|
|
|
|
|
// them typed by anybody.
|
|
|
|
|
//
|
|
|
|
|
// So the set is declared here and checked. Growing it is allowed; growing it by
|
|
|
|
|
// accident is not.
|
|
|
|
|
|
|
|
|
|
val allowedPermissions: Set<String> = setOf(
|
|
|
|
|
// Asked for when a reminder is switched on, never on first launch (§31).
|
|
|
|
|
"android.permission.POST_NOTIFICATIONS",
|
|
|
|
|
|
|
|
|
|
// The four WorkManager brings. None is requested by this project's own code.
|
|
|
|
|
// RECEIVE_BOOT_COMPLETED is the one that earns its place: it is how a
|
|
|
|
|
// reminder survives a restart.
|
|
|
|
|
"android.permission.WAKE_LOCK",
|
|
|
|
|
"android.permission.ACCESS_NETWORK_STATE",
|
|
|
|
|
"android.permission.RECEIVE_BOOT_COMPLETED",
|
|
|
|
|
"android.permission.FOREGROUND_SERVICE",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permissions this app must NEVER declare, whatever else changes.
|
|
|
|
|
*
|
|
|
|
|
* Separate from "not in the allowlist" because these deserve their own message.
|
|
|
|
|
* §31 rules out exact alarms specifically: a period reminder does not need
|
|
|
|
|
* alarm-clock precision, and the permission costs Play scrutiny for nothing.
|
|
|
|
|
*/
|
|
|
|
|
val forbiddenPermissions: Set<String> = setOf(
|
|
|
|
|
"android.permission.SCHEDULE_EXACT_ALARM",
|
|
|
|
|
"android.permission.USE_EXACT_ALARM",
|
|
|
|
|
"android.permission.ACCESS_FINE_LOCATION",
|
|
|
|
|
"android.permission.ACCESS_COARSE_LOCATION",
|
|
|
|
|
"android.permission.READ_CONTACTS",
|
|
|
|
|
"android.permission.READ_CALENDAR",
|
|
|
|
|
"android.permission.CAMERA",
|
|
|
|
|
"android.permission.RECORD_AUDIO",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
tasks.register("checkPermissions") {
|
|
|
|
|
group = "verification"
|
|
|
|
|
description = "The merged manifest may declare only the permissions listed in build.gradle.kts."
|
|
|
|
|
|
|
|
|
|
val allowed = allowedPermissions
|
|
|
|
|
val forbidden = forbiddenPermissions
|
|
|
|
|
val intermediates = layout.projectDirectory.dir("app/build/intermediates").asFile
|
|
|
|
|
|
|
|
|
|
// The manifest has to exist and be CURRENT before this reads it.
|
|
|
|
|
//
|
|
|
|
|
// Without this the task ran happily against whatever was left on disk from
|
|
|
|
|
// a previous build. prove-guard.sh caught it: a deliberate
|
|
|
|
|
// SCHEDULE_EXACT_ALARM was added to the manifest and the check stayed green,
|
|
|
|
|
// because it read the merged file from before the edit. The second guard in
|
|
|
|
|
// this project to be confidently green over exactly its own target.
|
|
|
|
|
// Both variants, and release is the one that matters: the Play listing and
|
|
|
|
|
// the Data Safety form describe the shipped manifest, not the debug one.
|
|
|
|
|
dependsOn(":app:processDebugMainManifest", ":app:processReleaseMainManifest")
|
|
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
|
// Walked at execution time, not configuration time — a file tree
|
|
|
|
|
// resolved during configuration does not see a manifest written later
|
|
|
|
|
// in the same build.
|
|
|
|
|
// Only the outputs of the tasks above. AGP also leaves a legacy
|
|
|
|
|
// `merged_manifests` (plural) tree that nothing here regenerates, and
|
|
|
|
|
// reading it meant a stale file from an earlier build failing the check
|
|
|
|
|
// — a guard that cries wolf gets switched off.
|
|
|
|
|
val files = intermediates.resolve("merged_manifest").walkTopDown()
|
|
|
|
|
.filter { it.isFile && it.name == "AndroidManifest.xml" }
|
|
|
|
|
.toList()
|
|
|
|
|
if (files.isEmpty()) {
|
|
|
|
|
// Never a silent pass: no manifest means the check did not run.
|
|
|
|
|
throw GradleException(
|
|
|
|
|
"no merged manifest found, so no permission was checked. Build :app first.",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Comments are stripped before parsing. This file's own comment names
|
|
|
|
|
// SCHEDULE_EXACT_ALARM to explain why it is absent, and a naive grep
|
|
|
|
|
// reported the explanation as the violation.
|
|
|
|
|
val commentRe = Regex("<!--.*?-->", RegexOption.DOT_MATCHES_ALL)
|
|
|
|
|
val permissionRe = Regex("""<uses-permission[^>]*android:name="([^"]+)"""")
|
|
|
|
|
|
|
|
|
|
val found = files.flatMap { file ->
|
|
|
|
|
permissionRe.findAll(commentRe.replace(file.readText(), ""))
|
|
|
|
|
.map { it.groupValues[1] }
|
|
|
|
|
}.toSet().filterNot { it.endsWith("DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION") }
|
|
|
|
|
|
|
|
|
|
val bad = found.filter { it in forbidden }
|
|
|
|
|
val unexpected = found.filterNot { it in allowed || it in forbidden }
|
|
|
|
|
|
|
|
|
|
if (bad.isNotEmpty() || unexpected.isNotEmpty()) {
|
|
|
|
|
logger.error("")
|
|
|
|
|
bad.forEach {
|
|
|
|
|
logger.error(" FORBIDDEN permission in the merged manifest: $it")
|
|
|
|
|
}
|
|
|
|
|
unexpected.forEach {
|
|
|
|
|
logger.error(" Undeclared permission in the merged manifest: $it")
|
|
|
|
|
}
|
|
|
|
|
logger.error("")
|
|
|
|
|
logger.error("A permission nobody typed usually arrives with a dependency. Find which,")
|
|
|
|
|
logger.error("decide whether this app should have it, and either remove it with")
|
|
|
|
|
logger.error("tools:node='remove' or add it to allowedPermissions with a reason.")
|
|
|
|
|
logger.error("Whatever you do, update docs/security/SECURITY.md — the Play listing and")
|
|
|
|
|
logger.error("the Data Safety form both describe this list.")
|
|
|
|
|
throw GradleException("${bad.size + unexpected.size} unapproved permission(s).")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.lifecycle("permissions: ${found.size} declared, all approved.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: module boundary guard, and two API-level bugs it uncovered
checkModuleBoundaries holds the dependency tables in docs/architecture/README.md
as a check: every module's permitted project dependencies, plus the rule that
domain:cycle and domain:prediction must never apply an Android plugin. core:ads
is already in the map with an empty permitted set, before the module exists —
PRODUCT_PLAN.md §34 is non-negotiable, and a guard written alongside the code it
constrains is one shaped around whatever exception somebody wanted at the time.
It lists every violation rather than the first, and refuses to report a pass
when it examined no modules at all.
THE GUARD FAILED ITS OWN FIRST PROOF
prove-guard.sh injected a forbidden dependency into :domain:prediction and the
guard reported "7 modules checked, no violations". The root project is
configured before its subprojects, so reading subprojects.configurations from
the root script saw every configuration empty — it had been green over an empty
map since the moment it was written, and would have been trusted for months.
Collection moved into afterEvaluate, and the task now throws rather than passing
if it ends up with no modules. Three proofs recorded in the architecture doc,
all re-run and all red: a domain module reaching upward, :app reaching past the
repository straight to Room, and a module with no rule being reported as
unmeasured rather than assumed fine.
TWO REAL BUGS FROM WIRING IT INTO `check`
Running the whole check for the first time turned up Android lint errors that
would have shipped:
NewApi: java.time.LocalDate#ofInstant requires API 34 (minSdk is 26)
NewApi: java.time.LocalDate#EPOCH requires API 34 (minSdk is 26)
Both are on the recalculation path. On any device below Android 14 — most of
the install base this app targets — that is a crash. Neither the unit tests nor
the API 36 emulator could see it; lint is the only thing that could.
Replaced with atZone().toLocalDate() and ofEpochDay(0), which are API 26.
Also cleared the lint warnings that were real: a redundant activity label, and
a round launcher icon declared but never referenced. The two that remain are
deliberate and now say so where the warning is read — targetSdk 36 is Play's
floor and raising it opts into untested runtime behaviour, and the -v26 mipmap
qualifier stays because removing it makes AAPT fail to resolve the icon at all.
./gradlew check now passes with 0 lint errors across all seven modules.
70 unit tests, all passing.
closes #7
2026-08-18 03:00:11 -05:00
|
|
|
// Wired into `check` so it runs with the tests rather than only when remembered.
|
|
|
|
|
subprojects {
|
|
|
|
|
tasks.matching { it.name == "check" }.configureEach {
|
|
|
|
|
dependsOn(rootProject.tasks.named("checkModuleBoundaries"))
|
feat: reminders that stay quiet on a lock screen
§28, §29, §30 and §31. NotificationCopy is a pure function — privacy mode plus
kind plus day count in, two versions of the text out — so every combination is
tested exhaustively without an emulator. This is the one surface whose mistakes
are visible to somebody who is not the user, so the tests are exhaustive rather
than representative: every kind × every mode asserts that no health word reaches
a lock screen outside Direct, and that includes the ACTION LABELS, which §31
points out are visible text too. A perfectly discreet body under a button
reading "Started my period" leaks anyway.
TWO ANDROID BEHAVIOURS THAT LEAK IF YOU TRUST THE DOCS
A private notification with no public version does not blank the lock screen —
it shows the private text. NotificationText therefore has no nullable title and
an instrumented test asserts every kind attaches one.
And a notification channel is IMMUTABLE after creation: importance and
lock-screen visibility cannot be changed. One shared channel would have kept
whatever the user's first privacy mode set, forever — switching from Direct to
Maximum privacy would have appeared to work and changed nothing. There is now
one channel per mode. Found by an instrumented test on a device; nothing in the
unit tests could have seen it.
§30's stopping rule is a test of its own: the app asks a bounded number of times,
says "We'll stop checking for now. Log your period whenever it begins.", and
then says nothing more — while the engine keeps learning, which is the sentence
§30 puts right after it.
WorkManager, and no exact alarms. §31 rules them out and the new checkPermissions
task fails the build if one ever appears in the merged manifest — from here or
from a dependency. That guard also failed its own first proof, reading a stale
manifest because it did not depend on the task that writes one.
ReminderCoordinator reschedules whenever the forecast moves, which §31 asks for
and is the requirement most likely to be missed: a "Not yet" moves the forecast,
so work queued against the old one is aimed at a day that no longer means
anything.
188 unit tests and 6 instrumented, all passing. ./gradlew check green.
closes #24
closes #25
closes #26
closes #27
2026-08-18 15:26:59 -05:00
|
|
|
if (project.path == ":app") dependsOn(rootProject.tasks.named("checkPermissions"))
|
feat: module boundary guard, and two API-level bugs it uncovered
checkModuleBoundaries holds the dependency tables in docs/architecture/README.md
as a check: every module's permitted project dependencies, plus the rule that
domain:cycle and domain:prediction must never apply an Android plugin. core:ads
is already in the map with an empty permitted set, before the module exists —
PRODUCT_PLAN.md §34 is non-negotiable, and a guard written alongside the code it
constrains is one shaped around whatever exception somebody wanted at the time.
It lists every violation rather than the first, and refuses to report a pass
when it examined no modules at all.
THE GUARD FAILED ITS OWN FIRST PROOF
prove-guard.sh injected a forbidden dependency into :domain:prediction and the
guard reported "7 modules checked, no violations". The root project is
configured before its subprojects, so reading subprojects.configurations from
the root script saw every configuration empty — it had been green over an empty
map since the moment it was written, and would have been trusted for months.
Collection moved into afterEvaluate, and the task now throws rather than passing
if it ends up with no modules. Three proofs recorded in the architecture doc,
all re-run and all red: a domain module reaching upward, :app reaching past the
repository straight to Room, and a module with no rule being reported as
unmeasured rather than assumed fine.
TWO REAL BUGS FROM WIRING IT INTO `check`
Running the whole check for the first time turned up Android lint errors that
would have shipped:
NewApi: java.time.LocalDate#ofInstant requires API 34 (minSdk is 26)
NewApi: java.time.LocalDate#EPOCH requires API 34 (minSdk is 26)
Both are on the recalculation path. On any device below Android 14 — most of
the install base this app targets — that is a crash. Neither the unit tests nor
the API 36 emulator could see it; lint is the only thing that could.
Replaced with atZone().toLocalDate() and ofEpochDay(0), which are API 26.
Also cleared the lint warnings that were real: a redundant activity label, and
a round launcher icon declared but never referenced. The two that remain are
deliberate and now say so where the warning is read — targetSdk 36 is Play's
floor and raising it opts into untested runtime behaviour, and the -v26 mipmap
qualifier stays because removing it makes AAPT fail to resolve the icon at all.
./gradlew check now passes with 0 lint errors across all seven modules.
70 unit tests, all passing.
closes #7
2026-08-18 03:00:11 -05:00
|
|
|
}
|
chore: adopt the project template and add the Kotlin/Compose skeleton
Period was a bare directory holding one 2,527-line specification, with no git
repository, no tracker and no documentation convention. This is the adoption
from Projects/Template/START-HERE-New-Project.md, plus a project that compiles
so the hooks and future guards have something real to run against.
Documents. scaffold.sh created 19 paths, 0 skipped. The specification moved to
docs/planning/PRODUCT_PLAN.md unchanged in substance, with a status header; the
capitalised Docs/ is gone. Every scaffolded document was filled in for Period.
docs/OPERATIONS.md deleted — an offline app is not a deployed service.
DOC_TRUST_MAP.md written last, describing what is actually here, including what
this project deliberately does not have.
Code. Four Gradle modules. domain/cycle and domain/prediction are kotlin("jvm")
and cannot see the Android SDK, so the engine is testable without an emulator —
17 tests pass, 12 of them the acceptance cases from PRODUCT_PLAN.md §51.
BaselinePredictionEngine is a robust-median prototype and explicitly not the
product; it exists so Batch 02's replacement can be shown to be better rather
than merely different.
Versions verified against their official sources today rather than inherited
from the specification's own numbers, which that document asks for: Kotlin
2.4.10, AGP 9.3.1, Gradle 9.7.0, Compose BOM 2026.08.00, Room 2.8.4, Hilt
2.60.1. AGP 9 ships Kotlin built in, so org.jetbrains.kotlin.android is no
longer applied. compileSdk is 37 because current AndroidX requires it; targetSdk
stays 36, Play's floor from 2026-08-31, and the difference is deliberate.
Six scripts taken into scripts/; the rest declined and named in docs/TOOLS.md.
Three hooks in .githooks/, with pre-commit adapted to Gradle.
closes #1
closes #2
2026-08-18 02:16:47 -05:00
|
|
|
}
|