Files
giza-kmp/docs/scripts/m3-spacing-positions.py
T
Kgothatso NgakoandClaude Opus 5 e6aee79282 refactor: rebrand curated to curare, and the one name that stays on disk
`com.it.curated.{compose,android,desktop}` becomes `to.curare.{compose,android,desktop}`
across 700 file moves, and the app is Curare everywhere a user can read it. This is the
third rename this tree has been through, so the question was never how to spell the new
name but which of the 5074 occurrences of the old one were the brand. `3bc8be53` and
`d26cf6c7` had already sorted most of that, which is why this rename is mechanical where
those two were not -- and why the interesting part is the one place it is still not.

**`APP_DIR_NAME` keeps the old brand, and is the only thing that does.** It names the
desktop app's data directory -- `~/.local/share/curated`, `Application Support/curated`,
`%LOCALAPPDATA%\curated` -- and that single directory holds the Room database, the marmot
group state and the phoenix wallet. Renaming it does not move an install: it silently
starts an empty one beside it and leaves the old chat history and the old seed sitting
where nothing reads them any more. That is the same class of silent failure as the
`mantra/` hash prefixes, so it gets the same treatment -- it stays, with a comment saying
what renaming it would cost and that doing it properly is a first-run migration rather
than a rebrand. The desktop app is `curated` on disk and `Curare` everywhere a user can
read.

**The applicationId and the namespace are one value again, at `to.curare.android`.**
`3bc8be53` split them precisely so `com.it.curated` could land verbatim as the store
identity while the namespace kept `.android`; the decision here was to collapse them, so
both read `to.curare.android` and the manifest's relative `android:name=".CurareApplication"`
and `BuildConfig` resolve against the same package they always did. Debug is
`to.curare.android.debug` through the existing suffix. Worth stating plainly because
nothing in the build will: an applicationId *is* the app's identity to Play, so this is a
new listing rather than an update, and no installed Curated can update into it.

**`CuratedDatabase` -> `CurareDatabase` moves a directory, never a table.** The `@Database`
class name picks the schema *directory*, so
`composeApp/schemas/com.it.curated.compose.database.CuratedDatabase/` becomes
`to.curare.compose.database.CurareDatabase/` and its 19 files move unmodified. What makes
that safe has not changed since last time: the 12 entity classes are still `Mantra*` and
still declare no `tableName`, so Room still takes their class names as the SQLite table
names -- and this rename does not touch one of them. The check is that Room found all 19
schemas at the new directory and generated no twentieth.

**The generated resources package moved because `rootProject.name` did, again.** Compose
Resources derives it from the root project, so `Curated` -> `Curare` silently turns
`curated.composeapp.generated.resources` into `curare.composeapp.generated.resources` and
breaks 72 files' imports at once. Rewritten with them: the two string keys that carried
the brand -- `curated` and `sign_in_is_not_yet_available_while_curated_is` -- their three
call sites, and the eight `docs/scripts/` tools that hardcode the UI source path. The
audit reporting 582 `stringResource` sites and 178 `Icon(` call sites is the evidence
those tools still see the whole tree rather than an empty directory.

**A global rename edits the sentences that describe the previous rename, and two of them
came out false.** `material-design-conformance.md` recorded that `TorchTheme` became
`CuratedTheme` and that `UserAgent` was moved off Torch "when the app was rebranded to
Curated" -- which a blanket sweep turns into a claim about a change that had not happened
when it was written. Same in `HomeScreen`, where "the brand before that one" meant Torch
while Curated was current, and quietly came to mean Curated while still naming
`TorchTheme`. Both now say what happened, in order. The three deliberate Torch records --
the finding at :278, that note, and `NavigationRoutingTest`'s fixture -- are intact.

**What was protected stays protected, and now says "two rebrands".** `TWEAK_TAG`,
`HOST_KEY_DERIVATION_TAG` and `wss://ephemeral.mantra.press` are byte-identical; only the
prose around them moved, because "survived the rebrand to Curated" had stopped being the
whole story. The tree's 1668 `Mantra` and 17 `Torch` tokens differ from the 1666 and 16
before this change only by the words those comments added.

**iOS is `Curare` / `to.curare.ios`**, with the three pbxproj product references renamed
to match, and is unverified here for the same reason as last time -- the build gates the
ios targets behind `isMacOsX` and this was built on linux. The bundle id takes a platform
segment rather than the bare base it translates from, so that it reads alongside an
android applicationId that now carries one: `to.curare.android` and `to.curare.ios`, and
`to.curare` left as the base neither store claims.

1226 tests pass -- 787 in `:composeApp:jvmTest`, 439 in `:composeApp:testDebugUnitTest` --
`:composeApp:compileDebugKotlinAndroid` is clean, and `m3Audit` meets every budget.

Three stale things are left alone, because none of them is branding.
`.gitea/workflows/material-design-conformance.yml` still triggers on `branches: [mantra]`,
which stopped naming a branch that exists somewhere before this change and is now two
brands out; the three `torch_*` string keys still carry a brand two renames old, though
every value they hold reads Curare; and `androidMain/res/values/strings.xml` has opened
`<resources>a` since well before this. Each wants its own change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 13:33:47 +02:00

111 lines
3.9 KiB
Python
Executable File

#!/usr/bin/env python3
"""Count .dp literals by whether they sit in a spacing position or a dimension one.
m3-audit.sh used to split them by value, exempting a list of numbers that "looked like"
dimensions -- which is wrong twice over. 16.dp is a spacing stop *and* a plausible icon
size, and 50.dp was a Spacer height in 53 places and a divider width in one. Only the call
shape says which, so this reads the shape.
spacing padding(...), PaddingValues(...), Arrangement.spacedBy(...), and a
.height()/.width() whose enclosing call is Spacer(
dimension .size(), a non-Spacer .height()/.width(), RoundedCornerShape(),
BorderStroke(), a `size =` argument
Spacing positions are what phase 2 drives to zero; dimensions are out of its scope and are
reported so the number is visible rather than exempted.
Usage: m3-spacing-positions.py [--list]
"""
import os, re, sys
UI = 'composeApp/src/commonMain/kotlin/to/curare/compose/ui'
THEME = os.path.join(UI, 'theme')
def _spans(text, opener):
"""Brace-matched character ranges of every call matching `opener`."""
spans = []
for m in re.finditer(opener, text):
depth, i = 0, m.end() - 1
while i < len(text):
if text[i] == '(':
depth += 1
elif text[i] == ')':
depth -= 1
if depth == 0:
spans.append((m.start(), i))
break
i += 1
return spans
def classify(path):
text = open(path, encoding='utf-8').read()
pads = _spans(text, r'\.?\bpadding\s*\(|\bPaddingValues\s*\(')
gaps = _spans(text, r'\bspacedBy\s*\(')
spacers = _spans(text, r'\bSpacer\s*\(')
def inside(pos, spans):
return any(a <= pos <= b for a, b in spans)
hw = [
(m.start(1), m.end(1))
for m in re.finditer(r'\.(?:height|width)\s*\(\s*(\d+\.dp)\s*\)', text)
if inside(m.start(), spacers)
]
spacing, dimension = [], []
for m in re.finditer(r'\b(\d+)\.dp\b', text):
pos = m.start()
line_start = text.rfind('\n', 0, pos) + 1
line = text[line_start:text.find('\n', pos)]
if re.match(r'\s*(//|\*|/\*)', line):
continue
# An explicit, reasoned opt-out. A value that is genuinely not a step in the
# spacing rhythm -- room reserved below a list, say -- is marked at the site
# rather than exempted by value in this file, so the reason travels with it
# and a reviewer sees it in the diff.
# Walk back over the unbroken run of comment lines directly above.
exempt = False
prev = text[:line_start].rstrip('\n').split('\n')
for candidate in reversed(prev[-8:]):
stripped = candidate.strip()
if not stripped.startswith('//'):
break
if 'm3-spacing-exempt' in stripped:
exempt = True
break
if exempt:
continue
entry = (path, text[:pos].count('\n') + 1, m.group(0), line.strip()[:90])
if inside(pos, pads) or inside(pos, gaps) or any(a <= pos < b for a, b in hw):
spacing.append(entry)
else:
dimension.append(entry)
return spacing, dimension
def main():
spacing, dimension = [], []
for root, _, files in os.walk(UI):
if root.startswith(THEME):
continue
for f in sorted(files):
if f.endswith('.kt'):
s, d = classify(os.path.join(root, f))
spacing += s
dimension += d
print(f' {"dp literals in spacing positions":42s} {len(spacing):6d}')
print(f' {"dp literals in dimension positions":42s} {len(dimension):6d} (out of scope)')
if '--list' in sys.argv:
for path, line, lit, ctx in spacing:
print(f' {path.replace(UI + "/", "")}:{line} {lit:>7s} {ctx}')
return 1 if spacing else 0
if __name__ == '__main__':
sys.exit(main())