Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b4547e5
OPE-82 Stream message.part.delta and keep long replies responsive
ivanfenenko Jul 26, 2026
9857f31
OPE-82 Open large histories plain-first and fix Android scroll-to-end…
ivanfenenko Jul 26, 2026
8b1a091
OPE-82 Harden message streaming synchronization
ivanfenenko Jul 26, 2026
d7b8b98
OPE-82 Align native message synchronization
ivanfenenko Jul 26, 2026
5dd3a20
OPE-82 Keep iOS large-session chat scrollable on warm reopen
ivanfenenko Jul 27, 2026
ddec057
OPE-82 Harden assistant message pipeline latest-wins
ivanfenenko Jul 27, 2026
4f4039d
OPE-82 Harden message display rendering through Phase 7a
ivanfenenko Jul 27, 2026
e9e16be
Smooth Session Chat streaming updates and iOS end pinning.
ivanfenenko Jul 28, 2026
9017d44
Make markdown chat rendering snappy and match web fence semantics.
ivanfenenko Jul 28, 2026
9ffa5ca
Keep Session Chat live after image pick and SSE resume.
ivanfenenko Jul 28, 2026
67f7122
Harden TextMate pipeline measurement and lifetime
ivanfenenko Jul 29, 2026
7bb185f
feat: add TextMate parsing logbook
ivanfenenko Jul 29, 2026
963be5e
test: close TextMate phase 1 simulator gate
ivanfenenko Jul 29, 2026
aaecabc
feat: add TextMate highlighting engine boundary
ivanfenenko Jul 29, 2026
6edfe06
feat: add TextMate Phase 3 scheduling and backpressure
ivanfenenko Jul 29, 2026
7803721
feat: add TextMate Phase 4 compiled programs and caches
ivanfenenko Jul 29, 2026
965d02e
feat: add TextMate Phase 5 incremental reuse
ivanfenenko Jul 29, 2026
2a9552d
feat: enable TextMate Phase 6 default allowlist
ivanfenenko Jul 29, 2026
fb8b984
feat: add TextMate language toggles and logbook speed metrics
ivanfenenko Jul 30, 2026
9c0d62b
feat: cut TextMate search tax and add software OnigScanner
ivanfenenko Jul 30, 2026
cab171b
feat: format markdown first, apply TextMate colors later
ivanfenenko Jul 30, 2026
6506f45
fix: keep TextMate admit stable and refresh span upgrades on iOS
ivanfenenko Jul 30, 2026
00caa29
fix: keep Session Chat composer above the iOS keyboard
ivanfenenko Jul 30, 2026
f0cd9ac
fix: dismiss Session Chat keyboard when scrolling the timeline
ivanfenenko Jul 31, 2026
367bd99
fix: green CI for TextMate allowlist and structure-first tests
ivanfenenko Jul 31, 2026
4178b13
fix: preserve TextMate upgrade metadata and align streaming decoratio…
ivanfenenko Jul 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .xcodebuildmcp/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ schemaVersion: 1
enabledWorkflows:
- simulator
- ui-automation
- debugging
18 changes: 11 additions & 7 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ is the server-managed conversation for the current project.
### Message Repository

The mobile integration layer that reads and sends **messages** for a session
(list, get one, sync send, and asynchronous prompt send).
(list, get one, sync send, and asynchronous prompt send). Its read boundary also
exposes the observed raw and display-message timelines backed by
`MessageSync`, `InMemoryMessageStore`, and `DisplayMessagePipeline`.

Distinct from a **message**: the repository is app infrastructure; a message is
a single item in a session timeline.
Expand Down Expand Up @@ -189,12 +191,14 @@ Attachment.
A reactive observation layer above CRUD repositories that keeps screen data fresh
while the **foreground event stream** is active.

A Live Store listens for relevant server-sent events, applies debounced REST
refresh policy, and exposes ongoing updates through platform streams (for
example Kotlin `Flow` or Swift `AsyncStream`). Screen Models collect Live Store
streams for timelines, session lists, and status labels. Mutations such as
send, create, and delete still go through repositories directly. Optimistic send
and quiet refresh merge stay in the Screen Model.
A Live Store listens for relevant server-sent events, applies refresh policy,
and exposes ongoing updates through platform streams (for example Kotlin `Flow`
or Swift `AsyncStream`). Screen Models collect Live Store streams for session
lists, status labels, permissions, and questions. The message timeline uses the
equivalent synchronization boundary behind **Message Repository** rather than a
type named `MessageLiveStore`. Mutations such as send, create, and delete still
go through repositories directly. Optimistic send and quiet refresh merge stay
in the Screen Model.

### message

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package dev.opencode.mobile.markdown

import android.os.Debug
import android.os.SystemClock
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.math.max

@RunWith(AndroidJUnit4::class)
class TextMateSoakTest {
@Test
fun mixedLanguageSoakWhenRequested() {
val arguments = InstrumentationRegistry.getArguments()
val durationSeconds = arguments.getString(ARGUMENT_DURATION_SECONDS)?.toLongOrNull() ?: 0L
assumeTrue("Set $ARGUMENT_DURATION_SECONDS to run the opt-in TextMate soak.", durationSeconds > 0L)

val metrics = SoakMetricsSink()
val highlighter = createHighlighter(metrics)
val workload = mixedLanguageWorkload()

repeat(WARM_UP_CYCLES) {
parseCycle(workload, highlighter)
}
val retainedBaselinePssKb = stabilizedPssKb()
var peakPssKb = retainedBaselinePssKb
var cycles = 0
val startedAt = SystemClock.elapsedRealtime()
val deadline = startedAt + durationSeconds * 1_000L

while (SystemClock.elapsedRealtime() < deadline) {
parseCycle(workload, highlighter)
cycles += 1
peakPssKb = max(peakPssKb, Debug.getPss())
}

val retainedFinalPssKb = stabilizedPssKb()
peakPssKb = max(peakPssKb, retainedFinalPssKb)
val retainedGrowthKb = retainedFinalPssKb - retainedBaselinePssKb
val elapsedMs = SystemClock.elapsedRealtime() - startedAt

println(
"TEXTMATE_SOAK platform=android-joni duration-ms=$elapsedMs cycles=$cycles " +
"warmup-cycles=$WARM_UP_CYCLES retained-baseline-pss-kb=$retainedBaselinePssKb " +
"retained-final-pss-kb=$retainedFinalPssKb retained-growth-kb=$retainedGrowthKb " +
"peak-pss-kb=$peakPssKb native-search-count=${metrics.nativeSearchCount} " +
"native-search-max-ms=${metrics.nativeSearchMaximumNanoseconds / 1_000_000.0}",
)

assertTrue("The soak must complete at least one mixed-language cycle.", cycles > 0)
assertTrue(
"Retained PSS grew by $retainedGrowthKb KiB after warm-up.",
retainedGrowthKb <= RETAINED_PSS_TOLERANCE_KB,
)
}

@Test
fun referenceFixtureColdAndWarmWhenRequested() {
val arguments = InstrumentationRegistry.getArguments()
assumeTrue(
"Set $ARGUMENT_BENCHMARK to run the opt-in TextMate reference benchmark.",
arguments.getString(ARGUMENT_BENCHMARK)?.toBooleanStrictOrNull() == true,
)

val metrics = SoakMetricsSink()
val fixture = longMarkdownHistory()
val pssBeforeKb = stabilizedPssKb()
val coldStartedAt = SystemClock.elapsedRealtimeNanos()
val highlighter = createHighlighter(metrics)
parseCycle(fixture, highlighter)
val coldMs = (SystemClock.elapsedRealtimeNanos() - coldStartedAt) / 1_000_000.0
val warmSamplesMs =
List(WARM_SAMPLE_COUNT) {
val startedAt = SystemClock.elapsedRealtimeNanos()
parseCycle(fixture, highlighter)
(SystemClock.elapsedRealtimeNanos() - startedAt) / 1_000_000.0
}
val retainedPssKb = stabilizedPssKb()

assertEquals(20, fixture.size)
println(
"TEXTMATE_BENCHMARK platform=android-joni cold-ms=$coldMs " +
"warm-ms=${warmSamplesMs.joinToString(",")} warm-samples=$WARM_SAMPLE_COUNT " +
"pss-before-kb=$pssBeforeKb retained-pss-kb=$retainedPssKb " +
"native-search-count=${metrics.nativeSearchCount} " +
"native-search-max-ms=${metrics.nativeSearchMaximumNanoseconds / 1_000_000.0} " +
"messages=20 code-lines=3000",
)
}

private fun createHighlighter(metrics: OpenCodeTextMateMetricsSink): OpenCodeSyntaxHighlighter {
val context = InstrumentationRegistry.getInstrumentation().targetContext
return OpenCodeBundledJoniMarkdownHighlighter.create(
resourceReader =
OpenCodeTextMateResourceReader { resourcePath ->
runCatching {
context.assets
.open(resourcePath)
.bufferedReader()
.use { reader -> reader.readText() }
}.getOrNull()
},
metricsSink = metrics,
)
}

private fun parseCycle(
workload: List<String>,
highlighter: OpenCodeSyntaxHighlighter,
) {
workload.forEach { markdown ->
val document = OpenCodeMarkdownParser.parse(markdown, highlighter)
assertTrue(document.blocks.any { block -> block is MarkdownBlock.CodeBlock })
}
}

private fun stabilizedPssKb(): Long {
repeat(2) {
Runtime.getRuntime().gc()
System.runFinalization()
Thread.sleep(100)
}
return Debug.getPss()
}

private class SoakMetricsSink : OpenCodeTextMateMetricsSink {
var nativeSearchCount: Long = 0
private set
var nativeSearchMaximumNanoseconds: Long = 0
private set

override fun record(event: TextMateMetricEvent) {
if (event.stage == TextMateMetricStage.NativeRegexSearch) {
nativeSearchCount += 1
nativeSearchMaximumNanoseconds =
max(nativeSearchMaximumNanoseconds, event.durationNanoseconds)
}
}
}

private fun mixedLanguageWorkload(): List<String> =
listOf(
markdown("typescript") { index -> "const item$index = response$index?.value ?? 'soak';" },
markdown("kotlin") { index -> "val item$index = response$index?.value ?: \"soak\"" },
markdown("swift") { index -> "let item$index = response$index?.value ?? \"soak\"" },
markdown("python") { index -> "item_$index = response_$index.value if response_$index else 'soak'" },
markdown("json") { index -> "\"item$index\": { \"value\": $index, \"enabled\": true }," },
markdown("shellscript") { index -> "item_$index=\"\${response_$index:-soak}\"" },
)

private fun longMarkdownHistory(): List<String> =
(1..20).map { messageIndex ->
buildString {
append("## Response $messageIndex\n\n```typescript\n")
repeat(150) { lineIndex ->
append("const item$lineIndex = response$lineIndex?.value ?? 'markdown benchmark';\n")
}
append("```\n")
}
}

private fun markdown(
language: String,
line: (Int) -> String,
): String =
buildString {
append("## TextMate soak\n\n```")
append(language)
append('\n')
repeat(LINES_PER_LANGUAGE) { index ->
append(line(index))
append('\n')
}
append("```\n")
}

companion object {
private const val ARGUMENT_DURATION_SECONDS = "textmateSoakSeconds"
private const val ARGUMENT_BENCHMARK = "textmateBenchmark"
private const val WARM_UP_CYCLES = 5
private const val WARM_SAMPLE_COUNT = 5
private const val LINES_PER_LANGUAGE = 40
private const val RETAINED_PSS_TOLERANCE_KB = 8L * 1_024L
}
}
27 changes: 27 additions & 0 deletions android/app/src/main/java/dev/opencode/mobile/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import dev.opencode.mobile.ui.componentgallery.components.MessageListGalleryDeta
import dev.opencode.mobile.ui.componentgallery.components.OutgoingMessageGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.OverflowMenuGalleryScreen
import dev.opencode.mobile.domain.preferences.HomeDisplayPreferences
import dev.opencode.mobile.domain.preferences.MarkdownHighlightPreferences
import dev.opencode.mobile.ui.componentgallery.components.ProjectSessionSelectorGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SessionListDockGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SessionListGalleryScreen
Expand All @@ -75,6 +76,9 @@ import dev.opencode.mobile.ui.sessionchat.SessionChatScreen
import dev.opencode.mobile.ui.sessioncontext.SessionContextScreen
import dev.opencode.mobile.ui.settings.SettingsScreen
import dev.opencode.mobile.ui.settings.SettingsViewModel
import dev.opencode.mobile.ui.settings.TextMateLanguagesRoute
import dev.opencode.mobile.ui.settings.TextMateLogbookScreen
import dev.opencode.mobile.ui.settings.TextMateLogbookViewModel

@Composable
fun MainNavigation() {
Expand Down Expand Up @@ -138,6 +142,8 @@ fun MainNavigation() {
RouteSurface {
SettingsScreen(
onComponentGalleryClick = { backStack.add(ComponentGalleryHome) },
onTextMateLanguagesClick = { backStack.add(TextMateLanguagesHome) },
onTextMateLogbookClick = { backStack.add(TextMateLogbookHome) },
onNavigateBack = { backStack.removeLastOrNull() },
onConnectionSetup = {
setupViewModel.configureFromCurrentProfile()
Expand All @@ -149,6 +155,27 @@ fun MainNavigation() {
showSessionListOnHome = HomeDisplayPreferences.showSessionListOnHome,
onShowSessionListOnHomeChange =
settingsViewModel::setShowSessionListOnHome,
textMateEnabled = MarkdownHighlightPreferences.textMateEnabled,
onTextMateEnabledChange = settingsViewModel::setTextMateEnabled,
)
}
}
entry<TextMateLanguagesHome> {
RouteSurface {
TextMateLanguagesRoute(
onNavigateBack = { backStack.removeLastOrNull() },
)
}
}
entry<TextMateLogbookHome> {
RouteSurface {
val logbookViewModel: TextMateLogbookViewModel = hiltViewModel()
val logbookState by logbookViewModel.state.collectAsStateWithLifecycle()
TextMateLogbookScreen(
state = logbookState,
onNavigateBack = { backStack.removeLastOrNull() },
onRefresh = logbookViewModel::refresh,
onClear = logbookViewModel::clear,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import kotlinx.serialization.Serializable

@Serializable data object SettingsHome : NavKey

@Serializable data object TextMateLogbookHome : NavKey

@Serializable data object TextMateLanguagesHome : NavKey

@Serializable data object ComponentGalleryHome : NavKey

@Serializable data class ComponentGalleryDetail(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package dev.opencode.mobile

import android.app.Application
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.android.HiltAndroidApp
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dev.opencode.mobile.domain.preferences.HomeDisplayPreferences
import dev.opencode.mobile.domain.preferences.MarkdownHighlightPreferences
import dev.opencode.mobile.domain.textmate.TextMateProcessPressureObserver
import dev.opencode.mobile.markdown.OpenCodeAndroidMarkdownAssets
import dev.opencode.mobile.theme.ThemeManager

Expand All @@ -12,7 +18,18 @@ class OpenCodeMobileApplication : Application() {
super.onCreate()
ThemeManager.initialize(this)
HomeDisplayPreferences.initialize(this)
MarkdownHighlightPreferences.initialize(this)
OpenCodeAndroidMarkdownAssets.init(this)
OpenCodeReleaseObservability.initialize(this)
EntryPointAccessors
.fromApplication(this, TextMatePressureEntryPoint::class.java)
.textMateProcessPressureObserver()
.start()
}
}

@EntryPoint
@InstallIn(SingletonComponent::class)
interface TextMatePressureEntryPoint {
fun textMateProcessPressureObserver(): TextMateProcessPressureObserver
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,22 @@ class EventsApi(
.prepareGet("global/event") {
accept(ContentType.Text.EventStream)
header(HttpHeaders.CacheControl, "no-cache")
// Match iOS: keep SSE uncompressed so framing stays line-oriented under burst.
header(HttpHeaders.AcceptEncoding, "identity")
}.execute { response ->
onHTTPResponse(response.status.value)
val channel = response.bodyAsChannel()
val dataBuffer = StringBuilder()
val parser = SseDataLineParser()
try {
while (!channel.isClosedForRead) {
val line = channel.readUTF8Line() ?: break
when {
line.isEmpty() -> {
if (dataBuffer.isNotEmpty()) {
onDataLine(dataBuffer.toString())
dataBuffer.clear()
}
}
line.startsWith("data:") -> {
val payload = line.removePrefix("data:").trimStart()
if (dataBuffer.isNotEmpty()) dataBuffer.append('\n')
dataBuffer.append(payload)
}
line.startsWith("{") -> {
if (dataBuffer.isNotEmpty()) {
onDataLine(dataBuffer.toString())
dataBuffer.clear()
}
onDataLine(line)
}
for (payload in parser.ingest(line)) {
onDataLine(payload)
}
}
for (payload in parser.finish()) {
onDataLine(payload)
}
} catch (error: CancellationException) {
throw error
}
Expand Down
Loading
Loading