From b0e4cb5185ee455f85127ce994564911cc477331 Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim Date: Fri, 27 Nov 2026 02:02:33 +0000 Subject: [PATCH 1/5] docs: align glossary with session history --- AGENTS.md | 2 +- CONTEXT.md | 67 ------------------------------------------- GLOSSARY.md | 37 ++++++++++++++++++++++++ docs/ARCHITECTURE.md | 4 ++- docs/agents/domain.md | 18 ++++++------ 5 files changed, 50 insertions(+), 78 deletions(-) delete mode 100644 CONTEXT.md create mode 100644 GLOSSARY.md diff --git a/AGENTS.md b/AGENTS.md index 89d4c8a..7d63e0c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -140,4 +140,4 @@ Issues and specs live as GitHub issues (`mibrahimdev/Sharingan`); use the `gh` C ### Domain docs -Single-context: `CONTEXT.md` + `docs/adr/` at the repo root. See `docs/agents/domain.md`. +Domain docs use `GLOSSARY.md` for a single context or `GLOSSARY-MAP.md` for multiple contexts. See `docs/agents/domain.md`. diff --git a/CONTEXT.md b/CONTEXT.md deleted file mode 100644 index dfe34ea..0000000 --- a/CONTEXT.md +++ /dev/null @@ -1,67 +0,0 @@ -# Sharingan - -The domain language of Sharingan, an on-device multiprotocol debug logger for Kotlin Multiplatform. -This file names the concepts; `docs/ARCHITECTURE.md` explains how they're built. - -## Language - -**Event**: -One captured protocol interaction — an HTTP exchange, an MQTT message, or a BLE operation. Immutable once recorded; `SharinganEvent` is the sealed root. -_Avoid_: log, entry, record (as a noun), request (HTTP-only) - -**Protocol**: -One of the three traffic kinds Sharingan understands — HTTP, MQTT, BLE. Each Protocol is a tab in the browser and a subtype of Event. -_Avoid_: transport, channel, tap - -**Protocol Descriptor**: -The single home for everything Sharingan knows about one Protocol: its filter chips, chip matching, search haystack, row presentation, notification ticker line, per-event export fragments, and detail body. Exactly one exhaustive `when (event)` maps an Event to its Descriptor; adding a Protocol means writing one Descriptor and registering it there. -_Avoid_: handler, strategy, adapter (reserved for things satisfying an interface at a seam) - -**Capture**: -The act of recording an Event into the Store, via a Logger or the Ktor plugin. Header redaction happens at capture — secrets never enter the Store, and redaction applies before disk too. -_Avoid_: logging, tracking, interception - -**Flight Recorder**: -The on-disk SQLite mirror of the Store, written via the Write-Behind Seam. Memory stays the source of truth; the Flight Recorder is a post-mortem log, not a database to query. Request/response bodies are never written to disk. -_Avoid_: database, cache - -**Logger**: -A per-Protocol capture entry point (`Sharingan.http`, `Sharingan.mqtt`, `Sharingan.ble`). Client-agnostic: host apps wire their own MQTT/BLE libraries into it. -_Avoid_: tracker, recorder - -**Run**: -One process lifetime — the Flight Recorder groups all Events captured in a process under a single `session` row. -_Avoid_: session (reserved for the v2 epic) - -**Store**: -The in-memory ring buffer of Events (default 300). The source of truth while the process lives; each Event is mirrored to the Flight Recorder via the Write-Behind Seam. Process death clears the ring buffer, not the Flight Recorder. -_Avoid_: database, cache, repository, buffer (alone) - -**Write-Behind Seam**: -The internal seam (`SharinganStore.onRecord` → `PersistenceController`) that mirrors each accepted Event to the Flight Recorder after the ring-buffer append. It observes Capture, never blocks it. -_Avoid_: listener, hook - -**Capture Notification**: -The Android sticky notification showing per-Protocol counters, a three-event Ticker when expanded, and Pause/Resume. Silent, updated in place, and must never crash the host app. -_Avoid_: status bar entry, foreground notification (it isn't a foreground service) - -**Ticker**: -The last-three-events preview inside the expanded Capture Notification, one line per Event. - -**Agent Markdown**: -The structured Markdown export behind "Copy for AI agent" — the share sheet's primary action and Sharingan's reason for existing. Optimized for LLM parsing. -_Avoid_: AI export, markdown dump - -**Share Action / Share Scope**: -A Share Action is what the share sheet does (copy for agent, copy human-readable, copy raw JSON, system share); a Share Scope is what it covers (the selected Event, or all Events in the current Protocol tab). - -**No-op Twin**: -The `sharingan-noop` artifact: identical public interface to `sharingan`, inert implementations, real Event models. Release builds swap it in so Sharingan has zero release footprint. Every public declaration added to `sharingan` must be mirrored here. -_Avoid_: stub, mock, fake (those are test doubles; the Twin ships to production) - -## Example dialogue - -> **Dev:** A user says the MQTT tab shows "fail" on a publish that succeeded. -> **Maintainer:** That's row presentation, so look at the MQTT **Protocol Descriptor** — presentation, chips, and the **Ticker** line for MQTT all live there. If the **Event** itself has a wrong `error`, that's **Capture** — check the call into the MQTT **Logger**, not the UI. -> **Dev:** And if I fix the Descriptor, do I touch the **No-op Twin**? -> **Maintainer:** No — Descriptors are internal. The Twin only mirrors public declarations, like `SharinganExport` or the Loggers' signatures. diff --git a/GLOSSARY.md b/GLOSSARY.md new file mode 100644 index 0000000..d757588 --- /dev/null +++ b/GLOSSARY.md @@ -0,0 +1,37 @@ +# Sharingan + +Domain vocabulary for Sharingan. See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for system design. + +## Terms + +**Event**: One captured protocol interaction, such as an HTTP exchange, MQTT message, or BLE operation. An event is immutable once recorded. + +**Protocol**: One of the traffic types Sharingan captures: HTTP, MQTT, or BLE. Each **Protocol** has its own view in the browser. + +**Protocol Descriptor**: The description of how a **Protocol** is presented and explored, including its filters, search, rows, details, and exports. + +**Capture**: The act of recording a protocol interaction as an **Event**. Capture follows the active recording state. + +**Flight Recorder**: The persistent history of events from process lifetimes. The **Store** remains the live source of truth for the **Current Session**; the Flight Recorder is queried on demand to list or inspect **Past Sessions**. + +**Logger**: A protocol-specific interface for recording an **Event** from a host app's network or device client. + +**Session**: A collection of events associated with one process lifetime. The **Current Session** is active; previous lifetimes are **Past Sessions**. + +**Current Session**: The live process lifetime backed by the **Store**. + +**Past Session**: A previous process lifetime retrieved on demand from the **Flight Recorder**. + +**Store**: The live collection of captured **Events** for the **Current Session**. It is the source of truth while the process is running. + +**Write-Behind Seam**: The process that mirrors accepted **Events** to the **Flight Recorder** without blocking **Capture**. + +**Capture Notification**: The Android notification that surfaces capture status and recent **Events**. + +**Ticker**: A short preview of recent **Events** shown in the expanded **Capture Notification**. + +**Agent Markdown**: The structured Markdown export intended to help an agent understand and debug captured **Events**. + +**Share Action / Share Scope**: A Share Action chooses how data is shared; a Share Scope chooses whether it covers one **Event** or all **Events** in the current **Protocol**. + +**No-op Twin**: The inert release counterpart of Sharingan, preserving its public API without capturing events or displaying the browser. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 0ef5df0..605c816 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -15,6 +15,8 @@ Sharingan is an on-device debug logger for Kotlin Multiplatform (Android API 24+ :sharingan debug artifact — capture core + Ktor plugin + Compose UI + Android notification/activity + iOS view controller :sharingan-noop release artifact — same public API, inert bodies, no UI payload +:sharingan-db on-device SQLite flight recorder for persisted event sessions +:ktlint-rules custom lint rules for project-specific source conventions :sample:composeApp demo app — deterministic IoT traffic via Ktor MockEngine; can compile against either artifact (-Psharingan.noop) ``` @@ -221,7 +223,7 @@ The design explored three densities — **Terminal / Comfortable / Badged** — ### 5.4 Flight recorder (persistence) -The in-memory ring buffer stays the source of truth. Each accepted Event is also mirrored to an on-device SQLite database by a write-behind seam: `SharinganStore.onRecord` (internal callback, invoked after the ring-buffer CAS append) → `PersistenceController` ([sharingan-db](../sharingan-db), SQLDelight). Persistence ships ON by default in debug. The Flight Recorder is a post-mortem log, never queried back into the UI and never the source of truth; one session row groups the Events of each process lifetime (a Run). Redaction applies before disk, and request/response bodies are never written to disk — persisting bodies would change the security posture and is deliberately out of scope. +The **Store** remains the live source of truth for the **Current Session**. Each accepted Event is also mirrored to the on-device SQLite **Flight Recorder** by a write-behind seam: `SharinganStore.onRecord` (internal callback, invoked after the ring-buffer CAS append) → `PersistenceController` ([sharingan-db](../sharingan-db), SQLDelight). Persistence ships ON by default in debug. The Flight Recorder is queried on demand to list or inspect **Past Sessions**; each session groups the Events of one process lifetime. Redaction applies before disk, and request/response bodies are never written to disk — persisting bodies would change the security posture and is deliberately out of scope. ### 5.5 Sample iosApp Xcode project diff --git a/docs/agents/domain.md b/docs/agents/domain.md index 0fda76f..193866e 100644 --- a/docs/agents/domain.md +++ b/docs/agents/domain.md @@ -4,45 +4,45 @@ How the engineering skills should consume this repo's domain documentation when ## Before exploring, read these -- **`CONTEXT.md`** at the repo root, or -- **`CONTEXT-MAP.md`** at the repo root if it exists: it points at one `CONTEXT.md` per context. Read each one relevant to the topic. +- **`GLOSSARY.md`** at the repo root, or +- **`GLOSSARY-MAP.md`** at the repo root if it exists: it points at one `GLOSSARY.md` per context. Read each one relevant to the topic. - **`docs/adr/`**: read ADRs that touch the area you're about to work in. In multi-context repos, also check `src//docs/adr/` for context-scoped decisions. If any of these files don't exist, **proceed silently**. Don't flag their absence; don't suggest creating them upfront. The `/domain-modeling` skill (reached via `/grill-with-docs` and `/improve-codebase-architecture`) creates them lazily when terms or decisions actually get resolved. ## File structure -This repo is **single-context**: one `CONTEXT.md` + `docs/adr/` at the repo root. +This repo is **single-context**: one `GLOSSARY.md` + `docs/adr/` at the repo root. Single-context repo (most repos): ``` / -├── CONTEXT.md +├── GLOSSARY.md ├── docs/adr/ │ ├── 0001-event-sourced-orders.md │ └── 0002-postgres-for-write-model.md └── src/ ``` -Multi-context repo (presence of `CONTEXT-MAP.md` at the root): +Multi-context repo (presence of `GLOSSARY-MAP.md` at the root): ``` / -├── CONTEXT-MAP.md +├── GLOSSARY-MAP.md ├── docs/adr/ ← system-wide decisions └── src/ ├── ordering/ - │ ├── CONTEXT.md + │ ├── GLOSSARY.md │ └── docs/adr/ ← context-specific decisions └── billing/ - ├── CONTEXT.md + ├── GLOSSARY.md └── docs/adr/ ``` ## Use the glossary's vocabulary -When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `CONTEXT.md`. Don't drift to synonyms the glossary explicitly avoids. +When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `GLOSSARY.md` and keep vocabulary consistent. If the concept you need isn't in the glossary yet, that's a signal: either you're inventing language the project doesn't use (reconsider) or there's a real gap (note it for `/domain-modeling`). From 00f14aaf34f5dd78f1e7e97fd16f532944c4c1a9 Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim Date: Fri, 27 Nov 2026 02:02:54 +0000 Subject: [PATCH 2/5] feat(db): expose current and past session history --- sharingan-db/api/sharingan-db.api | 40 ++++++++++++ sharingan-db/api/sharingan-db.klib.api | 52 ++++++++++++++++ .../dev/sharingan/db/PersistenceController.kt | 38 +++++++++--- .../kotlin/dev/sharingan/db/SessionSummary.kt | 8 +++ .../dev/sharingan/db/SharinganDatabase.sq | 14 +++++ .../sharingan/db/PersistenceControllerTest.kt | 61 +++++++++++++++++++ 6 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt diff --git a/sharingan-db/api/sharingan-db.api b/sharingan-db/api/sharingan-db.api index e4e00d8..f1aaa7a 100644 --- a/sharingan-db/api/sharingan-db.api +++ b/sharingan-db/api/sharingan-db.api @@ -47,11 +47,31 @@ public final class dev/sharingan/db/PersistenceController { public synthetic fun (Lkotlin/jvm/functions/Function1;IJILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun clear ()V public final fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getCurrentSessionId ()Ljava/lang/String; + public final fun pastSessions ()Ljava/util/List; + public final fun sessionEvents (Ljava/lang/String;)Ljava/util/List; public final fun start ()V public final fun stop (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun submit (Ljava/lang/Object;)V } +public final class dev/sharingan/db/SelectPastSessions { + public fun (Ljava/lang/String;JJJ)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()J + public final fun component3 ()J + public final fun component4 ()J + public final fun copy (Ljava/lang/String;JJJ)Ldev/sharingan/db/SelectPastSessions; + public static synthetic fun copy$default (Ldev/sharingan/db/SelectPastSessions;Ljava/lang/String;JJJILjava/lang/Object;)Ldev/sharingan/db/SelectPastSessions; + public fun equals (Ljava/lang/Object;)Z + public final fun getEventCount ()J + public final fun getFailureCount ()J + public final fun getId ()Ljava/lang/String; + public final fun getStarted_at ()J + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class dev/sharingan/db/Session { public fun (Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V public final fun component1 ()Ljava/lang/String; @@ -73,6 +93,23 @@ public final class dev/sharingan/db/Session { public fun toString ()Ljava/lang/String; } +public final class dev/sharingan/db/SessionSummary { + public fun (Ljava/lang/String;JII)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()J + public final fun component3 ()I + public final fun component4 ()I + public final fun copy (Ljava/lang/String;JII)Ldev/sharingan/db/SessionSummary; + public static synthetic fun copy$default (Ldev/sharingan/db/SessionSummary;Ljava/lang/String;JIIILjava/lang/Object;)Ldev/sharingan/db/SessionSummary; + public fun equals (Ljava/lang/Object;)Z + public final fun getEventCount ()I + public final fun getFailureCount ()I + public final fun getId ()Ljava/lang/String; + public final fun getStartedAtMillis ()J + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public abstract interface class dev/sharingan/db/SharinganDatabase : app/cash/sqldelight/Transacter { public static final field Companion Ldev/sharingan/db/SharinganDatabase$Companion; public abstract fun getSharinganDatabaseQueries ()Ldev/sharingan/db/SharinganDatabaseQueries; @@ -86,6 +123,7 @@ public final class dev/sharingan/db/SharinganDatabase$Companion { public final class dev/sharingan/db/SharinganDatabaseQueries : app/cash/sqldelight/TransacterImpl { public fun (Lapp/cash/sqldelight/db/SqlDriver;)V public final fun deleteAllEvents ()V + public final fun deleteEventsForSession (Ljava/lang/String;)V public final fun deleteSession (Ljava/lang/String;)V public final fun insertEvent (Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;JLjava/lang/String;Ljava/lang/String;)V public final fun insertSession (Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V @@ -95,6 +133,8 @@ public final class dev/sharingan/db/SharinganDatabaseQueries : app/cash/sqldelig public final fun selectAllSessions (Lkotlin/jvm/functions/Function6;)Lapp/cash/sqldelight/Query; public final fun selectEventsForSession (Ljava/lang/String;)Lapp/cash/sqldelight/Query; public final fun selectEventsForSession (Ljava/lang/String;Lkotlin/jvm/functions/Function7;)Lapp/cash/sqldelight/Query; + public final fun selectPastSessions (Ljava/lang/String;)Lapp/cash/sqldelight/Query; + public final fun selectPastSessions (Ljava/lang/String;Lkotlin/jvm/functions/Function4;)Lapp/cash/sqldelight/Query; public final fun selectSession (Ljava/lang/String;)Lapp/cash/sqldelight/Query; public final fun selectSession (Ljava/lang/String;Lkotlin/jvm/functions/Function6;)Lapp/cash/sqldelight/Query; } diff --git a/sharingan-db/api/sharingan-db.klib.api b/sharingan-db/api/sharingan-db.klib.api index 726e9a8..6397242 100644 --- a/sharingan-db/api/sharingan-db.klib.api +++ b/sharingan-db/api/sharingan-db.klib.api @@ -21,7 +21,12 @@ abstract interface dev.sharingan.db/SharinganDatabase : app.cash.sqldelight/Tran final class <#A: kotlin/Any> dev.sharingan.db/PersistenceController { // dev.sharingan.db/PersistenceController|null[0] constructor (kotlin/Function1<#A, dev.sharingan.db/EventRow>, kotlin/Int = ..., kotlin/Long = ...) // dev.sharingan.db/PersistenceController.|(kotlin.Function1<1:0,dev.sharingan.db.EventRow>;kotlin.Int;kotlin.Long){}[0] + final val currentSessionId // dev.sharingan.db/PersistenceController.currentSessionId|{}currentSessionId[0] + final fun (): kotlin/String? // dev.sharingan.db/PersistenceController.currentSessionId.|(){}[0] + final fun clear() // dev.sharingan.db/PersistenceController.clear|clear(){}[0] + final fun pastSessions(): kotlin.collections/List // dev.sharingan.db/PersistenceController.pastSessions|pastSessions(){}[0] + final fun sessionEvents(kotlin/String): kotlin.collections/List // dev.sharingan.db/PersistenceController.sessionEvents|sessionEvents(kotlin.String){}[0] final fun start() // dev.sharingan.db/PersistenceController.start|start(){}[0] final fun submit(#A) // dev.sharingan.db/PersistenceController.submit|submit(1:0){}[0] final suspend fun close() // dev.sharingan.db/PersistenceController.close|close(){}[0] @@ -87,6 +92,28 @@ final class dev.sharingan.db/EventRow { // dev.sharingan.db/EventRow|null[0] final fun toString(): kotlin/String // dev.sharingan.db/EventRow.toString|toString(){}[0] } +final class dev.sharingan.db/SelectPastSessions { // dev.sharingan.db/SelectPastSessions|null[0] + constructor (kotlin/String, kotlin/Long, kotlin/Long, kotlin/Long) // dev.sharingan.db/SelectPastSessions.|(kotlin.String;kotlin.Long;kotlin.Long;kotlin.Long){}[0] + + final val eventCount // dev.sharingan.db/SelectPastSessions.eventCount|{}eventCount[0] + final fun (): kotlin/Long // dev.sharingan.db/SelectPastSessions.eventCount.|(){}[0] + final val failureCount // dev.sharingan.db/SelectPastSessions.failureCount|{}failureCount[0] + final fun (): kotlin/Long // dev.sharingan.db/SelectPastSessions.failureCount.|(){}[0] + final val id // dev.sharingan.db/SelectPastSessions.id|{}id[0] + final fun (): kotlin/String // dev.sharingan.db/SelectPastSessions.id.|(){}[0] + final val started_at // dev.sharingan.db/SelectPastSessions.started_at|{}started_at[0] + final fun (): kotlin/Long // dev.sharingan.db/SelectPastSessions.started_at.|(){}[0] + + final fun component1(): kotlin/String // dev.sharingan.db/SelectPastSessions.component1|component1(){}[0] + final fun component2(): kotlin/Long // dev.sharingan.db/SelectPastSessions.component2|component2(){}[0] + final fun component3(): kotlin/Long // dev.sharingan.db/SelectPastSessions.component3|component3(){}[0] + final fun component4(): kotlin/Long // dev.sharingan.db/SelectPastSessions.component4|component4(){}[0] + final fun copy(kotlin/String = ..., kotlin/Long = ..., kotlin/Long = ..., kotlin/Long = ...): dev.sharingan.db/SelectPastSessions // dev.sharingan.db/SelectPastSessions.copy|copy(kotlin.String;kotlin.Long;kotlin.Long;kotlin.Long){}[0] + final fun equals(kotlin/Any?): kotlin/Boolean // dev.sharingan.db/SelectPastSessions.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // dev.sharingan.db/SelectPastSessions.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // dev.sharingan.db/SelectPastSessions.toString|toString(){}[0] +} + final class dev.sharingan.db/Session { // dev.sharingan.db/Session|null[0] constructor (kotlin/String, kotlin/Long, kotlin/String?, kotlin/String?, kotlin/String?, kotlin/String?) // dev.sharingan.db/Session.|(kotlin.String;kotlin.Long;kotlin.String?;kotlin.String?;kotlin.String?;kotlin.String?){}[0] @@ -115,19 +142,44 @@ final class dev.sharingan.db/Session { // dev.sharingan.db/Session|null[0] final fun toString(): kotlin/String // dev.sharingan.db/Session.toString|toString(){}[0] } +final class dev.sharingan.db/SessionSummary { // dev.sharingan.db/SessionSummary|null[0] + constructor (kotlin/String, kotlin/Long, kotlin/Int, kotlin/Int) // dev.sharingan.db/SessionSummary.|(kotlin.String;kotlin.Long;kotlin.Int;kotlin.Int){}[0] + + final val eventCount // dev.sharingan.db/SessionSummary.eventCount|{}eventCount[0] + final fun (): kotlin/Int // dev.sharingan.db/SessionSummary.eventCount.|(){}[0] + final val failureCount // dev.sharingan.db/SessionSummary.failureCount|{}failureCount[0] + final fun (): kotlin/Int // dev.sharingan.db/SessionSummary.failureCount.|(){}[0] + final val id // dev.sharingan.db/SessionSummary.id|{}id[0] + final fun (): kotlin/String // dev.sharingan.db/SessionSummary.id.|(){}[0] + final val startedAtMillis // dev.sharingan.db/SessionSummary.startedAtMillis|{}startedAtMillis[0] + final fun (): kotlin/Long // dev.sharingan.db/SessionSummary.startedAtMillis.|(){}[0] + + final fun component1(): kotlin/String // dev.sharingan.db/SessionSummary.component1|component1(){}[0] + final fun component2(): kotlin/Long // dev.sharingan.db/SessionSummary.component2|component2(){}[0] + final fun component3(): kotlin/Int // dev.sharingan.db/SessionSummary.component3|component3(){}[0] + final fun component4(): kotlin/Int // dev.sharingan.db/SessionSummary.component4|component4(){}[0] + final fun copy(kotlin/String = ..., kotlin/Long = ..., kotlin/Int = ..., kotlin/Int = ...): dev.sharingan.db/SessionSummary // dev.sharingan.db/SessionSummary.copy|copy(kotlin.String;kotlin.Long;kotlin.Int;kotlin.Int){}[0] + final fun equals(kotlin/Any?): kotlin/Boolean // dev.sharingan.db/SessionSummary.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // dev.sharingan.db/SessionSummary.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // dev.sharingan.db/SessionSummary.toString|toString(){}[0] +} + final class dev.sharingan.db/SharinganDatabaseQueries : app.cash.sqldelight/TransacterImpl { // dev.sharingan.db/SharinganDatabaseQueries|null[0] constructor (app.cash.sqldelight.db/SqlDriver) // dev.sharingan.db/SharinganDatabaseQueries.|(app.cash.sqldelight.db.SqlDriver){}[0] final fun <#A1: kotlin/Any> selectAllEvents(kotlin/Function7): app.cash.sqldelight/Query<#A1> // dev.sharingan.db/SharinganDatabaseQueries.selectAllEvents|selectAllEvents(kotlin.Function7){0§}[0] final fun <#A1: kotlin/Any> selectAllSessions(kotlin/Function6): app.cash.sqldelight/Query<#A1> // dev.sharingan.db/SharinganDatabaseQueries.selectAllSessions|selectAllSessions(kotlin.Function6){0§}[0] final fun <#A1: kotlin/Any> selectEventsForSession(kotlin/String, kotlin/Function7): app.cash.sqldelight/Query<#A1> // dev.sharingan.db/SharinganDatabaseQueries.selectEventsForSession|selectEventsForSession(kotlin.String;kotlin.Function7){0§}[0] + final fun <#A1: kotlin/Any> selectPastSessions(kotlin/String?, kotlin/Function4): app.cash.sqldelight/Query<#A1> // dev.sharingan.db/SharinganDatabaseQueries.selectPastSessions|selectPastSessions(kotlin.String?;kotlin.Function4){0§}[0] final fun <#A1: kotlin/Any> selectSession(kotlin/String, kotlin/Function6): app.cash.sqldelight/Query<#A1> // dev.sharingan.db/SharinganDatabaseQueries.selectSession|selectSession(kotlin.String;kotlin.Function6){0§}[0] final fun deleteAllEvents() // dev.sharingan.db/SharinganDatabaseQueries.deleteAllEvents|deleteAllEvents(){}[0] + final fun deleteEventsForSession(kotlin/String) // dev.sharingan.db/SharinganDatabaseQueries.deleteEventsForSession|deleteEventsForSession(kotlin.String){}[0] final fun deleteSession(kotlin/String) // dev.sharingan.db/SharinganDatabaseQueries.deleteSession|deleteSession(kotlin.String){}[0] final fun insertEvent(kotlin/String, kotlin/String, kotlin/Long, kotlin/String, kotlin/Long, kotlin/String?, kotlin/String?) // dev.sharingan.db/SharinganDatabaseQueries.insertEvent|insertEvent(kotlin.String;kotlin.String;kotlin.Long;kotlin.String;kotlin.Long;kotlin.String?;kotlin.String?){}[0] final fun insertSession(kotlin/String, kotlin/Long, kotlin/String?, kotlin/String?, kotlin/String?, kotlin/String?) // dev.sharingan.db/SharinganDatabaseQueries.insertSession|insertSession(kotlin.String;kotlin.Long;kotlin.String?;kotlin.String?;kotlin.String?;kotlin.String?){}[0] final fun selectAllEvents(): app.cash.sqldelight/Query // dev.sharingan.db/SharinganDatabaseQueries.selectAllEvents|selectAllEvents(){}[0] final fun selectAllSessions(): app.cash.sqldelight/Query // dev.sharingan.db/SharinganDatabaseQueries.selectAllSessions|selectAllSessions(){}[0] final fun selectEventsForSession(kotlin/String): app.cash.sqldelight/Query // dev.sharingan.db/SharinganDatabaseQueries.selectEventsForSession|selectEventsForSession(kotlin.String){}[0] + final fun selectPastSessions(kotlin/String?): app.cash.sqldelight/Query // dev.sharingan.db/SharinganDatabaseQueries.selectPastSessions|selectPastSessions(kotlin.String?){}[0] final fun selectSession(kotlin/String): app.cash.sqldelight/Query // dev.sharingan.db/SharinganDatabaseQueries.selectSession|selectSession(kotlin.String){}[0] } diff --git a/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/PersistenceController.kt b/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/PersistenceController.kt index 94f6d27..2311a60 100644 --- a/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/PersistenceController.kt +++ b/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/PersistenceController.kt @@ -78,6 +78,7 @@ public class PersistenceController private constructor( // AtomicReference so a racing stop() can't read a stale null and skip the join. private val flusherJob = AtomicReference(null) + private val _currentSessionId = AtomicReference(null) // Terminal flag; the controller is single-use once stopped. private val stopped = AtomicBoolean(false) @@ -96,6 +97,23 @@ public class PersistenceController private constructor( /** Test seam: flusher coroutines that actually started. */ internal fun flusherStartCount(): Int = flusherStarts.load() + /** Session id committed for events recorded during this process lifetime. */ + public val currentSessionId: String? get() = _currentSessionId.load() + + /** Past sessions with at least one event, newest first. */ + public fun pastSessions(): List = + database.sharinganDatabaseQueries + .selectPastSessions(excludeId = currentSessionId) + .executeAsList() + .map { SessionSummary(it.id, it.started_at, it.eventCount.toInt(), it.failureCount.toInt()) } + + /** Persisted event payloads for [sessionId], oldest first; rows without payloads are omitted. */ + public fun sessionEvents(sessionId: String): List = + database.sharinganDatabaseQueries + .selectEventsForSession(sessionId) + .executeAsList() + .mapNotNull { it.payload_json } + /** * Wires the seam and starts the flusher. Idempotent before [stop]; after * [stop] the controller is single-use and [start] throws. @@ -113,7 +131,7 @@ public class PersistenceController private constructor( } /** - * Deletes every persisted row and discards whatever is still queued or + * Deletes current-session rows and discards whatever is still queued or * held in the flusher's in-flight batch. Enqueued as a command on the same * channel the writes travel on, so the single flusher coroutine applies it * at an exact point in the write order — events recorded before [clear] @@ -121,7 +139,7 @@ public class PersistenceController private constructor( * survive. No locks, no resurrection window. */ public fun clear() { - channel.trySend(Command.ClearAll) + channel.trySend(Command.ClearCurrent) } /** @@ -180,9 +198,9 @@ public class PersistenceController private constructor( batch.add(event) if (batch.size >= batchSize) flush(batch) } - is Command.ClearAll -> { + is Command.ClearCurrent -> { batch.clear() - database.sharinganDatabaseQueries.deleteAllEvents() + sessionId?.let(database.sharinganDatabaseQueries::deleteEventsForSession) onCleared?.invoke() } null -> flush(batch) @@ -204,11 +222,17 @@ public class PersistenceController private constructor( if (isNewSession) insertSession(session) rows.forEach { persist(it, session) } } - if (isNewSession) sessionId = session + if (isNewSession) { + sessionId = session + _currentSessionId.store(session) + } onBatchFlushed?.invoke(rows.size) } catch (t: Throwable) { // Reset the session in case its row rolled back with this transaction. - if (isNewSession) sessionId = null + if (isNewSession) { + sessionId = null + _currentSessionId.store(null) + } // ponytail: println is the whole story — no logging facility exists; route through a real one if it ever gains one. println("Sharingan persistence: dropped a batch of ${snapshot.size} events ($t)") } @@ -256,7 +280,7 @@ private sealed interface Command { val event: T, ) : Command - data object ClearAll : Command + data object ClearCurrent : Command } // UUID, not timestamp+Random: the latter collides on Kotlin/Native under rapid calls. diff --git a/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt b/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt new file mode 100644 index 0000000..bf48247 --- /dev/null +++ b/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt @@ -0,0 +1,8 @@ +package dev.sharingan.db + +public data class SessionSummary( + public val id: String, + public val startedAtMillis: Long, + public val eventCount: Int, + public val failureCount: Int, +) diff --git a/sharingan-db/src/commonMain/sqldelight/dev/sharingan/db/SharinganDatabase.sq b/sharingan-db/src/commonMain/sqldelight/dev/sharingan/db/SharinganDatabase.sq index 9cda940..0c79437 100644 --- a/sharingan-db/src/commonMain/sqldelight/dev/sharingan/db/SharinganDatabase.sq +++ b/sharingan-db/src/commonMain/sqldelight/dev/sharingan/db/SharinganDatabase.sq @@ -34,6 +34,17 @@ SELECT * FROM session WHERE id = ?; selectEventsForSession: SELECT * FROM event WHERE session_id = ? ORDER BY timestamp ASC; +selectPastSessions: +SELECT session.id, session.started_at, + COUNT(event.id) AS eventCount, + COALESCE(SUM(CASE WHEN event.is_failure = 1 THEN 1 ELSE 0 END), 0) AS failureCount +FROM session +LEFT JOIN event ON event.session_id = session.id +WHERE (:excludeId IS NULL OR session.id != :excludeId) +GROUP BY session.id +HAVING COUNT(event.id) > 0 +ORDER BY session.started_at DESC; + selectAllSessions: SELECT * FROM session ORDER BY started_at ASC; @@ -45,3 +56,6 @@ DELETE FROM session WHERE id = ?; deleteAllEvents: DELETE FROM event; + +deleteEventsForSession: +DELETE FROM event WHERE session_id = ?; diff --git a/sharingan-db/src/commonTest/kotlin/dev/sharingan/db/PersistenceControllerTest.kt b/sharingan-db/src/commonTest/kotlin/dev/sharingan/db/PersistenceControllerTest.kt index 4d66a1e..f65af7d 100644 --- a/sharingan-db/src/commonTest/kotlin/dev/sharingan/db/PersistenceControllerTest.kt +++ b/sharingan-db/src/commonTest/kotlin/dev/sharingan/db/PersistenceControllerTest.kt @@ -402,6 +402,67 @@ internal class PersistenceControllerTest { assertTrue(firstBatchSize < 10, "deadline flush should fire mid-stream, got a batch of $firstBatchSize") assertTrue(elapsed < 600, "expected flush within interval, took $elapsed ms") + controller.close() + } + + @Test + fun `Given committed sessions When past sessions are queried Then current empty and failures are handled`() = + runBlocking { + val driver = createTestDriver() + val controller = PersistenceController(toRow = { it }, driver = driver) + val flushed = CompletableDeferred() + controller.onBatchFlushed = { flushed.complete(Unit) } + controller.start() + controller.submit(event("current")) + withTimeout(10_000) { flushed.await() } + + val queries = SharinganDatabase(driver).sharinganDatabaseQueries + queries.insertSession("older", 1_000L, null, null, null, null) + queries.insertSession("newer", 2_000L, null, null, null, null) + queries.insertSession("empty", 3_000L, null, null, null, null) + queries.insertEvent("older-event", "older", 1_100L, "HTTP", 0L, null, """{"id":"older"}""") + queries.insertEvent("newer-event", "newer", 2_100L, "HTTP", 0L, null, """{"id":"newer"}""") + queries.insertEvent("newer-failure", "newer", 2_200L, "HTTP", 1L, null, """{"id":"failure"}""") + queries.insertEvent("newer-without-payload", "newer", 2_300L, "HTTP", 0L, null, null) + + assertEquals( + listOf( + SessionSummary("newer", 2_000L, 3, 1), + SessionSummary("older", 1_000L, 1, 0), + ), + controller.pastSessions(), + ) + assertEquals(listOf("""{"id":"newer"}""", """{"id":"failure"}"""), controller.sessionEvents("newer")) + + controller.close() + } + + @Test + fun `Given current and past session events When current session is cleared Then past events remain`() = + runBlocking { + val driver = createTestDriver() + val controller = PersistenceController(toRow = { it }, driver = driver) + val flushed = CompletableDeferred() + controller.onBatchFlushed = { flushed.complete(Unit) } + controller.start() + controller.submit(event("current")) + withTimeout(10_000) { flushed.await() } + + val currentSessionId = controller.currentSessionId + assertTrue(currentSessionId != null) + val queries = SharinganDatabase(driver).sharinganDatabaseQueries + queries.insertSession("past", 1_000L, null, null, null, null) + queries.insertEvent("past-event", "past", 1_100L, "HTTP", 0L, null, """{"id":"past"}""") + + val cleared = CompletableDeferred() + controller.onCleared = { cleared.complete(Unit) } + controller.clear() + withTimeout(10_000) { cleared.await() } + + val events = queries.selectAllEvents().executeAsList() + assertEquals(listOf("past-event"), events.map { it.id }) + assertEquals(listOf("past"), controller.pastSessions().map { it.id }) + controller.close() } } From e36601e9b13ee88fcafffdb57288b92db5f737de Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim Date: Fri, 27 Nov 2026 02:03:13 +0000 Subject: [PATCH 3/5] feat(ui): browse past sessions in Sharingan --- sharingan/api/sharingan.api | 12 ++ .../sharingan/internal/Platform.android.kt | 2 + .../kotlin/dev/sharingan/internal/EventDto.kt | 52 ++++- .../dev/sharingan/internal/Persistence.kt | 11 + .../kotlin/dev/sharingan/internal/Platform.kt | 3 + .../kotlin/dev/sharingan/ui/HomeScreen.kt | 81 +++++++- .../dev/sharingan/ui/SessionPickerSheet.kt | 193 ++++++++++++++++++ .../dev/sharingan/ui/SharinganScreen.kt | 133 +++++++++++- .../dev/sharingan/internal/EventDtoTest.kt | 59 ++++++ .../dev/sharingan/internal/Platform.ios.kt | 10 + 10 files changed, 544 insertions(+), 12 deletions(-) create mode 100644 sharingan/src/commonMain/kotlin/dev/sharingan/ui/SessionPickerSheet.kt diff --git a/sharingan/api/sharingan.api b/sharingan/api/sharingan.api index 89648e7..4b25c04 100644 --- a/sharingan/api/sharingan.api +++ b/sharingan/api/sharingan.api @@ -292,6 +292,12 @@ public final class dev/sharingan/ui/ComposableSingletons$HomeScreenKt { public final fun getLambda$140966640$io_github_mibrahimdev_sharingan_release ()Lkotlin/jvm/functions/Function2; } +public final class dev/sharingan/ui/ComposableSingletons$SessionPickerSheetKt { + public static final field INSTANCE Ldev/sharingan/ui/ComposableSingletons$SessionPickerSheetKt; + public fun ()V + public final fun getLambda$134908413$io_github_mibrahimdev_sharingan_release ()Lkotlin/jvm/functions/Function2; +} + public final class dev/sharingan/ui/ComposableSingletons$ShareSheetKt { public static final field INSTANCE Ldev/sharingan/ui/ComposableSingletons$ShareSheetKt; public fun ()V @@ -303,6 +309,12 @@ public final class dev/sharingan/ui/ComposableSingletons$ShareSheetKt { public final fun getLambda$1942219465$io_github_mibrahimdev_sharingan_release ()Lkotlin/jvm/functions/Function3; } +public final class dev/sharingan/ui/ComposableSingletons$SharinganScreenKt { + public static final field INSTANCE Ldev/sharingan/ui/ComposableSingletons$SharinganScreenKt; + public fun ()V + public final fun getLambda$-58490654$io_github_mibrahimdev_sharingan_release ()Lkotlin/jvm/functions/Function2; +} + public final class dev/sharingan/ui/SharinganScreenKt { public static final fun SharinganScreen (Landroidx/compose/ui/Modifier;ZLdev/sharingan/SharinganStore;Landroidx/compose/runtime/Composer;II)V } diff --git a/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Platform.android.kt b/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Platform.android.kt index dad750d..456962e 100644 --- a/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Platform.android.kt +++ b/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Platform.android.kt @@ -7,3 +7,5 @@ import java.util.Locale internal actual fun currentTimeMillis(): Long = System.currentTimeMillis() internal actual fun formatClockTime(epochMillis: Long): String = SimpleDateFormat("HH:mm:ss.SSS", Locale.US).format(Date(epochMillis)) + +internal actual fun formatDateTime(epochMillis: Long): String = SimpleDateFormat("MMM d, yyyy HH:mm", Locale.US).format(Date(epochMillis)) diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/EventDto.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/EventDto.kt index f0b0dec..e268639 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/EventDto.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/EventDto.kt @@ -1,9 +1,12 @@ package dev.sharingan.internal import dev.sharingan.BleEvent +import dev.sharingan.BleOperation import dev.sharingan.HttpEvent +import dev.sharingan.MqttDirection import dev.sharingan.MqttEvent import dev.sharingan.SharinganEvent +import dev.sharingan.TimingPhase import kotlinx.serialization.Serializable /** @@ -11,8 +14,8 @@ import kotlinx.serialization.Serializable * blob. A separate internal type because the #15 ABI freeze forbids adding * `@Serializable` to the public events. * - * Encode-only ([fromEvent]). Every field is mirrored and enums carried by name - * so a decoder can be added without a format change. + * Every field is mirrored and enums carried by name so the on-disk payload can + * reconstruct events without changing the public ABI. */ @Serializable internal sealed interface EventDto { @@ -68,6 +71,51 @@ internal sealed interface EventDto { } } +internal fun EventDto.toEvent(): SharinganEvent = + when (this) { + is HttpDto -> + HttpEvent( + id = id, + timestampMillis = timestampMillis, + method = method, + url = url, + statusCode = statusCode, + durationMillis = durationMillis, + requestHeaders = requestHeaders.map { it.name to it.value }, + responseHeaders = responseHeaders.map { it.name to it.value }, + requestBody = requestBody, + responseBody = responseBody, + contentType = contentType, + responseSizeBytes = responseSizeBytes, + timing = timing.map { TimingPhase(it.label, it.millis) }, + error = error, + ) + is MqttDto -> + MqttEvent( + id = id, + timestampMillis = timestampMillis, + direction = MqttDirection.valueOf(direction), + topic = topic, + qos = qos, + retained = retained, + payload = payload, + payloadSizeBytes = payloadSizeBytes, + error = error, + ) + is BleDto -> + BleEvent( + id = id, + timestampMillis = timestampMillis, + operation = BleOperation.valueOf(operation), + device = device, + characteristic = characteristic, + uuid = uuid, + payload = payload, + sizeBytes = sizeBytes, + error = error, + ) + } + @Serializable internal data class HeaderDto( val name: String, diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt index 740bf2a..11f31bf 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt @@ -8,6 +8,7 @@ import dev.sharingan.SharinganEvent import dev.sharingan.SharinganStore import dev.sharingan.db.EventRow import dev.sharingan.db.PersistenceController +import dev.sharingan.db.SessionSummary import kotlinx.serialization.json.Json import kotlin.concurrent.atomics.AtomicBoolean import kotlin.concurrent.atomics.ExperimentalAtomicApi @@ -29,6 +30,16 @@ internal object Persistence { private var controller: PersistenceController? = null private var store: SharinganStore? = null + val currentSessionId: String? get() = controller?.currentSessionId + + fun pastSessions(): List = controller?.pastSessions().orEmpty() + + fun sessionEvents(sessionId: String): List = + controller + ?.sessionEvents(sessionId) + .orEmpty() + .mapNotNull { payload -> runCatching { json.decodeFromString(EventDto.serializer(), payload).toEvent() }.getOrNull() } + fun start(store: SharinganStore = Sharingan.store) { if (!started.compareAndSet(false, true)) return val controller = PersistenceController(::toRow) diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Platform.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Platform.kt index ca0924b..9f8452f 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Platform.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Platform.kt @@ -5,3 +5,6 @@ internal expect fun currentTimeMillis(): Long /** Formats epoch milliseconds as local `HH:mm:ss.SSS`, e.g. `12:04:31.882`. */ internal expect fun formatClockTime(epochMillis: Long): String + +/** Formats epoch milliseconds as a local date and time for session history. */ +internal expect fun formatDateTime(epochMillis: Long): String diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/ui/HomeScreen.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/ui/HomeScreen.kt index b537a90..467c798 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/ui/HomeScreen.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/ui/HomeScreen.kt @@ -55,6 +55,8 @@ internal data class HomeUiState( val query: String, val chipKey: String, val recording: Boolean, + val pastSession: Boolean = false, + val sessionLabel: String = "Current session ▾", ) @Composable @@ -66,12 +68,22 @@ internal fun HomeScreenContent( onToggleRecording: () -> Unit, onOpenEvent: (SharinganEvent) -> Unit, onShareAll: () -> Unit, + onOpenSessionPicker: () -> Unit = {}, + onReturnToLive: () -> Unit = {}, modifier: Modifier = Modifier, ) { val colors = LocalSharinganColors.current Column(modifier.fillMaxSize().background(colors.bg)) { Column(Modifier.fillMaxWidth().background(colors.bgElev)) { - HomeHeader(recording = state.recording, onToggleRecording = onToggleRecording, onShareAll = onShareAll) + HomeHeader( + recording = state.recording, + pastSession = state.pastSession, + sessionLabel = state.sessionLabel, + onToggleRecording = onToggleRecording, + onOpenSessionPicker = onOpenSessionPicker, + onReturnToLive = onReturnToLive, + onShareAll = onShareAll, + ) TabBar(selected = state.protocol, counts = state.counts, onSelect = onSelectProtocol) SearchField( protocol = state.protocol, @@ -91,6 +103,7 @@ internal fun HomeScreenContent( count = state.rows.size, noun = state.protocol.eventNoun(), recording = state.recording, + pastSession = state.pastSession, ) if (state.rows.isEmpty()) { EmptyState(hasAny = (state.counts[state.protocol] ?: 0) > 0) @@ -107,7 +120,11 @@ internal fun HomeScreenContent( @Composable private fun HomeHeader( recording: Boolean, + pastSession: Boolean, + sessionLabel: String, onToggleRecording: () -> Unit, + onOpenSessionPicker: () -> Unit, + onReturnToLive: () -> Unit, onShareAll: () -> Unit, ) { val colors = LocalSharinganColors.current @@ -125,7 +142,12 @@ private fun HomeHeader( fontFamily = SansFont, modifier = Modifier.weight(1f), ) - RecordingPill(recording = recording, onToggle = onToggleRecording) + SessionSelectorPill(label = sessionLabel, onClick = onOpenSessionPicker) + if (pastSession) { + LiveReturnPill(onClick = onReturnToLive) + } else { + RecordingPill(recording = recording, onToggle = onToggleRecording) + } Box( Modifier .size(32.dp) @@ -140,6 +162,50 @@ private fun HomeHeader( } } +@Composable +private fun SessionSelectorPill( + label: String, + onClick: () -> Unit, +) { + val colors = LocalSharinganColors.current + Text( + label, + color = colors.textMid, + fontSize = 10.5.sp, + fontWeight = FontWeight.SemiBold, + fontFamily = MonoFont, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = + Modifier + .clip(RoundedCornerShape(20.dp)) + .background(colors.surface) + .border(1.dp, colors.border, RoundedCornerShape(20.dp)) + .clickable(onClick = onClick) + .padding(horizontal = 9.dp, vertical = 7.dp), + ) +} + +@Composable +private fun LiveReturnPill(onClick: () -> Unit) { + val colors = LocalSharinganColors.current + Text( + "↩ Live", + color = colors.accent, + fontSize = 11.sp, + fontWeight = FontWeight.Bold, + fontFamily = MonoFont, + maxLines = 1, + modifier = + Modifier + .clip(RoundedCornerShape(20.dp)) + .background(colors.accentSoft) + .border(1.dp, colors.accent, RoundedCornerShape(20.dp)) + .clickable(onClick = onClick) + .padding(horizontal = 9.dp, vertical = 7.dp), + ) +} + @Composable internal fun RecordingPill( recording: Boolean, @@ -327,8 +393,15 @@ private fun ColumnHeader( count: Int, noun: String, recording: Boolean, + pastSession: Boolean, ) { val colors = LocalSharinganColors.current + val status = + when { + pastSession -> "past session" + recording -> "● live" + else -> "paused" + } Row( Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 7.dp), verticalAlignment = Alignment.CenterVertically, @@ -342,8 +415,8 @@ private fun ColumnHeader( modifier = Modifier.weight(1f), ) Text( - if (recording) "● live" else "paused", - color = if (recording) colors.textDim else colors.warn, + status, + color = if (pastSession || recording) colors.textDim else colors.warn, fontSize = 10.5.sp, fontFamily = MonoFont, ) diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SessionPickerSheet.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SessionPickerSheet.kt new file mode 100644 index 0000000..c091dea --- /dev/null +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SessionPickerSheet.kt @@ -0,0 +1,193 @@ +package dev.sharingan.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import dev.sharingan.db.SessionSummary +import dev.sharingan.internal.formatDateTime +import org.jetbrains.compose.ui.tooling.preview.Preview + +internal data class SessionPickerState( + val currentEventCount: Int, + val pastSessions: List, + val selectedSessionId: String?, + val isLoading: Boolean, +) + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun SessionPickerSheet( + state: SessionPickerState, + onSelectCurrent: () -> Unit, + onSelectPast: (SessionSummary) -> Unit, + onDismiss: () -> Unit, +) { + val colors = LocalSharinganColors.current + ModalBottomSheet( + onDismissRequest = onDismiss, + containerColor = colors.bgElev, + dragHandle = { + Box( + Modifier + .padding(top = 10.dp, bottom = 2.dp) + .width(38.dp) + .height(4.dp) + .clip(RoundedCornerShape(4.dp)) + .background(colors.borderStrong), + ) + }, + ) { + SessionPickerBody(state, onSelectCurrent, onSelectPast) + } +} + +@Composable +internal fun SessionPickerBody( + state: SessionPickerState, + onSelectCurrent: () -> Unit, + onSelectPast: (SessionSummary) -> Unit, + modifier: Modifier = Modifier, +) { + val colors = LocalSharinganColors.current + Column(modifier.fillMaxWidth().padding(start = 14.dp, end = 14.dp, top = 8.dp, bottom = 26.dp)) { + Text("Sessions", color = colors.text, fontSize = 16.sp, fontWeight = FontWeight.Bold, fontFamily = SansFont) + Text( + "Choose a session to inspect its captured events.", + color = colors.textMid, + fontSize = 12.5.sp, + fontFamily = SansFont, + modifier = Modifier.padding(top = 4.dp, bottom = 12.dp), + ) + LazyColumn( + Modifier.fillMaxWidth().heightIn(max = 440.dp), + verticalArrangement = Arrangement.spacedBy(7.dp), + ) { + item(key = "current") { + SessionRow( + title = "Current session", + subtitle = "● LIVE · ${state.currentEventCount} events", + selected = state.selectedSessionId == null, + onClick = onSelectCurrent, + ) + } + if (state.isLoading && state.pastSessions.isEmpty()) { + item(key = "loading") { + Text( + "Loading past sessions…", + color = colors.textDim, + fontSize = 12.sp, + fontFamily = MonoFont, + modifier = Modifier.padding(vertical = 14.dp, horizontal = 4.dp), + ) + } + } else if (state.pastSessions.isEmpty()) { + item(key = "empty") { + Text( + "No past sessions yet", + color = colors.textDim, + fontSize = 12.sp, + fontFamily = MonoFont, + modifier = Modifier.padding(vertical = 14.dp, horizontal = 4.dp), + ) + } + } else { + items(state.pastSessions, key = { it.id }) { session -> + SessionRow( + title = formatDateTime(session.startedAtMillis), + subtitle = "${session.eventCount} events", + badge = if (session.failureCount > 0) "${session.failureCount} failed" else null, + selected = state.selectedSessionId == session.id, + onClick = { onSelectPast(session) }, + ) + } + } + } + } +} + +@Composable +private fun SessionRow( + title: String, + subtitle: String, + selected: Boolean, + onClick: () -> Unit, + badge: String? = null, +) { + val colors = LocalSharinganColors.current + Row( + Modifier + .fillMaxWidth() + .clip(RoundedCornerShape(10.dp)) + .background(if (selected) colors.accentSoft else colors.surface) + .border(1.dp, if (selected) colors.accent else colors.border, RoundedCornerShape(10.dp)) + .clickable(onClick = onClick) + .padding(horizontal = 12.dp, vertical = 11.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(10.dp), + ) { + Column(Modifier.weight(1f)) { + Text(title, color = colors.text, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, fontFamily = SansFont) + Text( + subtitle, + color = colors.textDim, + fontSize = 11.sp, + fontFamily = MonoFont, + modifier = Modifier.padding(top = 2.dp), + ) + } + badge?.let { + Text(it, color = colors.warn, fontSize = 10.sp, fontWeight = FontWeight.SemiBold, fontFamily = MonoFont) + } + if (selected) { + Icon(SharinganIcons.Check, contentDescription = "Selected", tint = colors.accent, modifier = Modifier.size(15.dp)) + } + } +} + +@Preview +@Composable +private fun SessionPickerBody_PastSessionsPreview() { + SharinganTheme(darkTheme = false) { + Box(Modifier.background(LocalSharinganColors.current.bgElev)) { + SessionPickerBody( + state = + SessionPickerState( + currentEventCount = 6, + pastSessions = + listOf( + SessionSummary("session-1", 1_749_556_771_000L, 18, 2), + SessionSummary("session-2", 1_749_470_371_000L, 9, 0), + ), + selectedSessionId = "session-1", + isLoading = false, + ), + onSelectCurrent = {}, + onSelectPast = {}, + ) + } + } +} diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SharinganScreen.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SharinganScreen.kt index 56ac67e..424e7bd 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SharinganScreen.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/ui/SharinganScreen.kt @@ -28,7 +28,13 @@ import dev.sharingan.HttpEvent import dev.sharingan.Sharingan import dev.sharingan.SharinganEvent import dev.sharingan.SharinganStore +import dev.sharingan.db.SessionSummary +import dev.sharingan.internal.Persistence +import dev.sharingan.internal.formatDateTime +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay +import kotlinx.coroutines.withContext +import org.jetbrains.compose.ui.tooling.preview.Preview // Sheet hosts sit below the status bar, so the top inset would be paid twice (#42); full-screen hosts still need it. internal val LocalStripTopInset = staticCompositionLocalOf { false } @@ -64,6 +70,12 @@ public fun SharinganScreen( var protocolName by rememberSaveable { mutableStateOf(Protocol.HTTP.name) } val protocol = Protocol.valueOf(protocolName) var selectedId by rememberSaveable { mutableStateOf(null) } + var selectedSessionId by rememberSaveable { mutableStateOf(null) } + var selectedSessionStartedAt by rememberSaveable { mutableStateOf(null) } + var sessionEvents by remember { mutableStateOf?>(null) } + var sessionPickerOpen by remember { mutableStateOf(false) } + var pastSessions by remember { mutableStateOf>(emptyList()) } + var loadingPastSessions by remember { mutableStateOf(false) } var shareScope by remember { mutableStateOf(null) } var toastMessage by remember { mutableStateOf(null) } @@ -71,16 +83,17 @@ public fun SharinganScreen( var query by remember(protocol) { mutableStateOf("") } var chipKey by remember(protocol) { mutableStateOf("all") } + val activeEvents = sessionEvents ?: events val counts = - remember(events) { - Protocol.entries.associateWith { p -> events.count { protocolOf(it) == p } } + remember(activeEvents) { + Protocol.entries.associateWith { p -> activeEvents.count { protocolOf(it) == p } } } val rows = - remember(events, protocol, chipKey, query) { - visibleEvents(events, protocol, chipKey, query) + remember(activeEvents, protocol, chipKey, query) { + visibleEvents(activeEvents, protocol, chipKey, query) } - val selectedEvent = selectedId?.let { id -> events.firstOrNull { it.id == id } } - val tabEvents = remember(events, protocol) { events.filter { protocolOf(it) == protocol } } + val selectedEvent = selectedId?.let { id -> activeEvents.firstOrNull { it.id == id } } + val tabEvents = remember(activeEvents, protocol) { activeEvents.filter { protocolOf(it) == protocol } } LaunchedEffect(toastMessage) { if (toastMessage != null) { @@ -89,6 +102,20 @@ public fun SharinganScreen( } } + LaunchedEffect(sessionPickerOpen) { + if (sessionPickerOpen) { + loadingPastSessions = true + pastSessions = withContext(Dispatchers.Default) { Persistence.pastSessions() } + loadingPastSessions = false + } + } + + LaunchedEffect(selectedSessionId) { + selectedSessionId?.let { id -> + sessionEvents = withContext(Dispatchers.Default) { Persistence.sessionEvents(id) } + } + } + val shareState = shareScope?.let { scope -> ShareSheetState( @@ -109,7 +136,22 @@ public fun SharinganScreen( query = query, chipKey = chipKey, recording = recording, + pastSession = selectedSessionId != null, + sessionLabel = + selectedSessionStartedAt?.let(::formatDateTime) + ?: if (selectedSessionId == null) "Current session ▾" else "Past session", ), + sessionPickerState = + if (sessionPickerOpen) { + SessionPickerState( + currentEventCount = events.size, + pastSessions = pastSessions, + selectedSessionId = selectedSessionId, + isLoading = loadingPastSessions, + ) + } else { + null + }, selectedEvent = selectedEvent, shareState = shareState, toastMessage = toastMessage, @@ -122,6 +164,30 @@ public fun SharinganScreen( onToggleRecording = { store.setRecording(!recording) }, onOpenEvent = { selectedId = it.id }, onBack = { selectedId = null }, + onOpenSessionPicker = { sessionPickerOpen = true }, + onSelectCurrentSession = { + selectedId = null + selectedSessionId = null + selectedSessionStartedAt = null + sessionEvents = null + sessionPickerOpen = false + }, + onSelectPastSession = { session -> + selectedId = null + if (selectedSessionId != session.id || sessionEvents == null) { + sessionEvents = emptyList() + selectedSessionId = session.id + } + selectedSessionStartedAt = session.startedAtMillis + sessionPickerOpen = false + }, + onReturnToLive = { + selectedId = null + selectedSessionId = null + selectedSessionStartedAt = null + sessionEvents = null + }, + onSessionPickerDismiss = { sessionPickerOpen = false }, onShareSingle = { shareScope = ShareScope.SINGLE }, onShareAll = { shareScope = ShareScope.ALL }, onShareAction = { action -> @@ -143,6 +209,7 @@ public fun SharinganScreen( @Composable internal fun SharinganScreenContent( homeState: HomeUiState, + sessionPickerState: SessionPickerState?, selectedEvent: SharinganEvent?, shareState: ShareSheetState?, toastMessage: String?, @@ -152,6 +219,11 @@ internal fun SharinganScreenContent( onToggleRecording: () -> Unit, onOpenEvent: (SharinganEvent) -> Unit, onBack: () -> Unit, + onOpenSessionPicker: () -> Unit, + onSelectCurrentSession: () -> Unit, + onSelectPastSession: (SessionSummary) -> Unit, + onReturnToLive: () -> Unit, + onSessionPickerDismiss: () -> Unit, onShareSingle: () -> Unit, onShareAll: () -> Unit, onShareAction: (ShareAction) -> Unit, @@ -184,6 +256,8 @@ internal fun SharinganScreenContent( onToggleRecording = onToggleRecording, onOpenEvent = onOpenEvent, onShareAll = onShareAll, + onOpenSessionPicker = onOpenSessionPicker, + onReturnToLive = onReturnToLive, ) } SharinganToast(toastMessage, Modifier.align(Alignment.BottomCenter)) @@ -192,5 +266,52 @@ internal fun SharinganScreenContent( if (shareState != null) { ShareSheet(state = shareState, onAction = onShareAction, onDismiss = onShareDismiss) } + if (sessionPickerState != null) { + SessionPickerSheet( + state = sessionPickerState, + onSelectCurrent = onSelectCurrentSession, + onSelectPast = onSelectPastSession, + onDismiss = onSessionPickerDismiss, + ) + } + } +} + +@Preview +@Composable +private fun SharinganScreenContent_PastSessionPreview() { + SharinganTheme(darkTheme = false) { + SharinganScreenContent( + homeState = + HomeUiState( + protocol = Protocol.HTTP, + counts = previewCounts(), + rows = PreviewData.http, + query = "", + chipKey = "all", + recording = true, + pastSession = true, + sessionLabel = "Jun 10, 2025 14:22", + ), + sessionPickerState = null, + selectedEvent = null, + shareState = null, + toastMessage = null, + onSelectProtocol = {}, + onQueryChange = {}, + onChipChange = {}, + onToggleRecording = {}, + onOpenEvent = {}, + onBack = {}, + onOpenSessionPicker = {}, + onSelectCurrentSession = {}, + onSelectPastSession = {}, + onReturnToLive = {}, + onSessionPickerDismiss = {}, + onShareSingle = {}, + onShareAll = {}, + onShareAction = {}, + onShareDismiss = {}, + ) } } diff --git a/sharingan/src/commonTest/kotlin/dev/sharingan/internal/EventDtoTest.kt b/sharingan/src/commonTest/kotlin/dev/sharingan/internal/EventDtoTest.kt index 33cea1f..b2274de 100644 --- a/sharingan/src/commonTest/kotlin/dev/sharingan/internal/EventDtoTest.kt +++ b/sharingan/src/commonTest/kotlin/dev/sharingan/internal/EventDtoTest.kt @@ -6,7 +6,9 @@ import dev.sharingan.HttpEvent import dev.sharingan.HttpLogger import dev.sharingan.MqttDirection import dev.sharingan.MqttEvent +import dev.sharingan.TimingPhase import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue internal class EventDtoTest { @@ -126,4 +128,61 @@ internal class EventDtoTest { assertTrue("\"device\":\"Scale-B2\"" in encoded) assertTrue("\"error\":\"GATT 133\"" in encoded) } + + @Test + fun `Given protocol events When DTOs are reconstructed Then every field is preserved`() { + val events = + listOf( + HttpEvent( + id = "http-1", + timestampMillis = 1_700_000_000_001L, + method = "POST", + url = "https://api.example.com/path?q=1", + statusCode = 201, + durationMillis = 125, + requestHeaders = listOf("Content-Type" to "application/json"), + responseHeaders = listOf("X-Request-Id" to "abc"), + requestBody = """{"name":"Ada"}""", + responseBody = """{"id":1}""", + contentType = "application/json", + responseSizeBytes = 42, + timing = listOf(TimingPhase("TTFB", 70)), + ), + MqttEvent( + id = "mqtt-1", + timestampMillis = 1_700_000_000_002L, + direction = MqttDirection.RECEIVE, + topic = "devices/1/status", + qos = 2, + retained = true, + payload = """{"online":true}""", + payloadSizeBytes = 15, + error = "decode warning", + ), + BleEvent( + id = "ble-1", + timestampMillis = 1_700_000_000_003L, + operation = BleOperation.READ, + device = "HR-Monitor", + characteristic = "Heart Rate", + uuid = "0x2A37", + payload = """{"bpm":72}""", + sizeBytes = 8, + error = "read failed", + ), + ) + + events.forEach { event -> + assertEquals(event, EventDto.fromEvent(event).toEvent()) + + val withoutBodies = + when (event) { + is HttpEvent -> event.copy(requestBody = null, responseBody = null) + is MqttEvent -> event.copy(payload = null) + is BleEvent -> event.copy(payload = null) + } + val persisted = json.decodeFromString(EventDto.serializer(), toRow(event).payloadJson).toEvent() + assertEquals(withoutBodies, persisted) + } + } } diff --git a/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Platform.ios.kt b/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Platform.ios.kt index 4512759..525a780 100644 --- a/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Platform.ios.kt +++ b/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Platform.ios.kt @@ -18,3 +18,13 @@ private val clockFormatter: NSDateFormatter by lazy { internal actual fun formatClockTime(epochMillis: Long): String = clockFormatter.stringFromDate(NSDate.dateWithTimeIntervalSince1970(epochMillis / 1000.0)) + +private val dateTimeFormatter: NSDateFormatter by lazy { + NSDateFormatter().apply { + dateFormat = "MMM d, yyyy HH:mm" + locale = NSLocale.localeWithLocaleIdentifier("en_US_POSIX") + } +} + +internal actual fun formatDateTime(epochMillis: Long): String = + dateTimeFormatter.stringFromDate(NSDate.dateWithTimeIntervalSince1970(epochMillis / 1000.0)) From 724ce391de349ccab829fdd52f49d39edde5c4e5 Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim Date: Fri, 27 Nov 2026 02:06:39 +0000 Subject: [PATCH 4/5] fix(ios): initialize session persistence --- sharingan/build.gradle.kts | 2 ++ .../kotlin/dev/sharingan/internal/Persistence.android.kt | 3 +++ sharingan/src/commonMain/kotlin/dev/sharingan/Sharingan.kt | 5 +++++ .../commonMain/kotlin/dev/sharingan/internal/Persistence.kt | 6 ++++-- .../kotlin/dev/sharingan/internal/Persistence.ios.kt | 5 +++++ 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 sharingan/src/androidMain/kotlin/dev/sharingan/internal/Persistence.android.kt create mode 100644 sharingan/src/iosMain/kotlin/dev/sharingan/internal/Persistence.ios.kt diff --git a/sharingan/build.gradle.kts b/sharingan/build.gradle.kts index 50d9b72..0db7e55 100644 --- a/sharingan/build.gradle.kts +++ b/sharingan/build.gradle.kts @@ -38,6 +38,8 @@ kotlin { isStatic = false sharinganXCFramework.add(this) } + // :sharingan-db links system SQLite; test binaries need it too. + target.binaries.all { linkerOpts("-lsqlite3") } } sourceSets { diff --git a/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Persistence.android.kt b/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Persistence.android.kt new file mode 100644 index 0000000..e4dbc56 --- /dev/null +++ b/sharingan/src/androidMain/kotlin/dev/sharingan/internal/Persistence.android.kt @@ -0,0 +1,3 @@ +package dev.sharingan.internal + +internal actual fun startPlatformPersistence() = Unit diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/Sharingan.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/Sharingan.kt index 5262fe0..0225641 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/Sharingan.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/Sharingan.kt @@ -1,5 +1,6 @@ package dev.sharingan +import dev.sharingan.internal.startPlatformPersistence import kotlinx.coroutines.flow.StateFlow /** @@ -26,6 +27,10 @@ public object Sharingan { /** The shared event buffer backing the notification and the log browser. */ public val store: SharinganStore = SharinganStore() + init { + startPlatformPersistence() + } + /** Manual HTTP logging (automatic when the `SharinganKtor` plugin is installed). */ public val http: HttpLogger = HttpLogger(store) diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt index 11f31bf..813c3b0 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt @@ -13,9 +13,11 @@ import kotlinx.serialization.json.Json import kotlin.concurrent.atomics.AtomicBoolean import kotlin.concurrent.atomics.ExperimentalAtomicApi +internal expect fun startPlatformPersistence() + /** - * Starts persistence once per process. The only caller is Android's - * manifest-merged ContentProvider — there is no Kotlin call site to grep. + * Starts persistence once per process. Android calls this from its + * manifest-merged ContentProvider; iOS starts it when the shared facade loads. * [stop] tears the wiring down so a new lifecycle can start again. * * ponytail: not unit-tested. [start] builds a real driver, and on Android diff --git a/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Persistence.ios.kt b/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Persistence.ios.kt new file mode 100644 index 0000000..eeaad1d --- /dev/null +++ b/sharingan/src/iosMain/kotlin/dev/sharingan/internal/Persistence.ios.kt @@ -0,0 +1,5 @@ +package dev.sharingan.internal + +internal actual fun startPlatformPersistence() { + Persistence.start() +} From 2bad0639be5b857a8489f8a031e6ff955edfa836 Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim Date: Fri, 27 Nov 2026 02:09:42 +0000 Subject: [PATCH 5/5] =?UTF-8?q?review:=20address=20architect=20feedback=20?= =?UTF-8?q?=E2=80=94=20remove=20unused=20currentSessionId,=20add=20Session?= =?UTF-8?q?Summary=20KDoc,=20fix=20api-parity=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api-parity.md | 7 ++++--- .../commonMain/kotlin/dev/sharingan/db/SessionSummary.kt | 1 + .../kotlin/dev/sharingan/internal/Persistence.kt | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api-parity.md b/docs/api-parity.md index f2e42ce..30216bf 100644 --- a/docs/api-parity.md +++ b/docs/api-parity.md @@ -56,9 +56,10 @@ consumer-facing public API: - `:sample:composeApp` — the sample application, not a published library. - `:sharingan-db` — the on-device SQLDelight database is an implementation -detail of `:sharingan`. Its generated surface changes with every schema edit in -slices 3–5, and no consumer codes against it. It is published only as a -required runtime dependency of `:sharingan`. +detail of `:sharingan`. It is BCV-guarded like `:sharingan` itself, but its +generated surface is **not** compared against `:sharingan-noop` (it is an +implementation dependency, not a consumer-facing twin). Its schema and public +query API evolve with slices 3–5. In CI it runs as the `api-parity` job in [`.github/workflows/api-check.yml`](../.github/workflows/api-check.yml), on a cheap diff --git a/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt b/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt index bf48247..1c274ae 100644 --- a/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt +++ b/sharingan-db/src/commonMain/kotlin/dev/sharingan/db/SessionSummary.kt @@ -1,5 +1,6 @@ package dev.sharingan.db +/** One row in the session picker: a past session's launch timestamp and event counts. */ public data class SessionSummary( public val id: String, public val startedAtMillis: Long, diff --git a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt index 813c3b0..a8fae6b 100644 --- a/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt +++ b/sharingan/src/commonMain/kotlin/dev/sharingan/internal/Persistence.kt @@ -32,8 +32,6 @@ internal object Persistence { private var controller: PersistenceController? = null private var store: SharinganStore? = null - val currentSessionId: String? get() = controller?.currentSessionId - fun pastSessions(): List = controller?.pastSessions().orEmpty() fun sessionEvents(sessionId: String): List =