Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 14 additions & 2 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,23 @@ config commands, built-ins such as `init`/`review`, MCP prompts, and skills —
that the client lists and runs against a session instead of sending as a normal
prompt.

Distinct from client slash actions (local UI under the same `/` trigger) and
from a timeline message with role `command`.
Distinct from **client slash actions** (Commands-sheet local actions) and from a
timeline message with role `command`.
_Avoid_: slash command (as the name for this concept); custom command (when
meaning the whole server catalog).

### client slash action

A curated local Session Chat action shown in the composer **Commands** sheet
(opened from the `/` circle button next to Attach). Selecting one runs client
behavior immediately (for example new session, fork, undo/redo, compact). It is
not listed from `GET /command` and is not submitted as `POST …/command`.

Distinct from **server command** (typed `/` suggestions and command send) and
from desktop/TUI builtins that mobile intentionally omits.
_Avoid_: slash command (ambiguous); builtin command (when meaning the mobile
allowlist).

### Agent Repository

The mobile integration layer that lists agents for the current project so
Expand Down
12 changes: 12 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 @@ -41,6 +41,7 @@ import dev.opencode.mobile.ui.componentgallery.components.BottomSheetGalleryScre
import dev.opencode.mobile.ui.componentgallery.components.ButtonGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ChoiceBadgeGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.DialogGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SnackbarGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.HunkNavigationPillGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.IconsGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ListGroupGalleryScreen
Expand Down Expand Up @@ -182,6 +183,7 @@ fun MainNavigation() {
ComponentGalleryEntryId.OverflowMenu -> OverflowMenuGalleryScreen()
ComponentGalleryEntryId.BottomSheet -> BottomSheetGalleryScreen()
ComponentGalleryEntryId.Dialog -> DialogGalleryScreen()
ComponentGalleryEntryId.Snackbar -> SnackbarGalleryScreen()
ComponentGalleryEntryId.ListItem -> ListItemGalleryScreen()
ComponentGalleryEntryId.ListGroup -> ListGroupGalleryScreen()
ComponentGalleryEntryId.ChoiceBadge -> ChoiceBadgeGalleryScreen()
Expand Down Expand Up @@ -239,6 +241,16 @@ fun MainNavigation() {
),
)
},
onSessionReplaceRequested = { target ->
backStack.removeLastOrNull()
backStack.add(
SessionChat(
sessionId = target.sessionId,
sessionTitle = target.sessionTitle,
worktree = target.worktree,
),
)
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ data class SessionDto(
val cost: Double? = null,
val tokens: MessageTokensDto? = null,
val time: SessionTimeDto? = null,
val revert: SessionRevertDto? = null,
)

@Serializable
data class SessionRevertDto(
@SerialName("messageID") val messageId: String,
@SerialName("partID") val partId: String? = null,
val snapshot: String? = null,
val diff: String? = null,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.opencode.mobile.domain.command

enum class ClientSlashAction(
val command: String,
val description: String,
) {
New("new", "Start a new session"),
Fork("fork", "Fork this session"),
Undo("undo", "Undo last message"),
Redo("redo", "Redo undone message"),
Compact("compact", "Compact session context"),
;

val rowTitle: String
get() = "[$command] $description"
}

data class ClientSlashMessageRef(
val id: String,
val isUser: Boolean,
val isPending: Boolean,
val isStreaming: Boolean,
val hasNonEmptyText: Boolean,
)

data class ClientSlashActionVisibilityInput(
val visibleUserMessageCount: Int,
val hasUndoableUserMessage: Boolean,
val hasActiveSessionRevert: Boolean,
val hasSelectedComposerModel: Boolean,
)

object ClientSlashActionCatalog {
fun visibleActions(input: ClientSlashActionVisibilityInput): List<ClientSlashAction> =
buildList {
add(ClientSlashAction.New)
if (input.visibleUserMessageCount > 0) {
add(ClientSlashAction.Fork)
}
if (input.hasUndoableUserMessage) {
add(ClientSlashAction.Undo)
}
if (input.hasActiveSessionRevert) {
add(ClientSlashAction.Redo)
}
if (input.visibleUserMessageCount > 0 && input.hasSelectedComposerModel) {
add(ClientSlashAction.Compact)
}
}

fun visibilityInput(
messages: List<ClientSlashMessageRef>,
revertMessageId: String?,
hasSelectedComposerModel: Boolean,
): ClientSlashActionVisibilityInput {
val visible =
messages.filter { message ->
revertMessageId == null || message.id < revertMessageId
}
val visibleUsers =
visible.filter { message ->
message.isUser && !message.isPending && !message.isStreaming
}
return ClientSlashActionVisibilityInput(
visibleUserMessageCount = visibleUsers.size,
hasUndoableUserMessage = visibleUsers.any { it.hasNonEmptyText },
hasActiveSessionRevert = revertMessageId != null,
hasSelectedComposerModel = hasSelectedComposerModel,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.opencode.mobile.data.remote.dto.PermissionRequestDto
import dev.opencode.mobile.data.remote.dto.QuestionInfoDto
import dev.opencode.mobile.data.remote.dto.QuestionRequestDto
import dev.opencode.mobile.data.remote.dto.SessionDto
import dev.opencode.mobile.data.remote.dto.SessionRevertDto
import dev.opencode.mobile.data.remote.dto.TodoDto
import dev.opencode.mobile.data.remote.dto.VcsInfoDto
import dev.opencode.mobile.domain.message.MessageTokenUsage
Expand All @@ -32,6 +33,15 @@ class SessionDomainAdapter {
createdAtEpochMs = dto.time?.created,
updatedAtEpochMs = dto.time?.updated,
archivedAtEpochMs = dto.time?.archived,
revert = dto.revert?.let(::toSessionRevert),
)

private fun toSessionRevert(dto: SessionRevertDto): SessionRevert =
SessionRevert(
messageId = dto.messageId,
partId = dto.partId,
snapshot = dto.snapshot,
diff = dto.diff,
)

fun toSessionSummary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ data class Session(
val createdAtEpochMs: Long? = null,
val updatedAtEpochMs: Long? = null,
val archivedAtEpochMs: Long? = null,
val revert: SessionRevert? = null,
) {
val isArchived: Boolean
get() = archivedAtEpochMs != null
}

data class SessionRevert(
val messageId: String,
val partId: String? = null,
val snapshot: String? = null,
val diff: String? = null,
)

fun List<Session>.activeSessions(): List<Session> = filterNot { it.isArchived }

data class SessionSummary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class ComponentGalleryEntryId {
OverflowMenu,
BottomSheet,
Dialog,
Snackbar,
ListItem,
ListGroup,
ChoiceBadge,
Expand Down Expand Up @@ -125,6 +126,12 @@ val ComponentGalleryEntries =
description = "Centered popup with title, optional subtitle, two options, and optional text field.",
category = ComponentGalleryCategory.Navigation,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.Snackbar,
title = "Snackbar",
description = "Auto-dismissing transient success or error feedback overlay.",
category = ComponentGalleryCategory.Navigation,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.OverflowMenu,
title = "Overflow Menu",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ private val OpenCodeSessionComposerAction.label: String
OpenCodeSessionComposerAction.SelectMode -> "Select mode"
OpenCodeSessionComposerAction.SelectVariant -> "Select variant"
OpenCodeSessionComposerAction.Attach -> "Attach"
OpenCodeSessionComposerAction.OpenCommands -> "Open commands"
is OpenCodeSessionComposerAction.RemoveAttachment -> "Remove attachment"
OpenCodeSessionComposerAction.Send -> "Send"
OpenCodeSessionComposerAction.Stop -> "Stop"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package dev.opencode.mobile.ui.componentgallery.components

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.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.ui.components.OpenCodeButton
import dev.opencode.mobile.ui.components.OpenCodeButtonVariant
import dev.opencode.mobile.ui.components.OpenCodeSnackbarHost
import dev.opencode.mobile.ui.components.OpenCodeSnackbarMessage
import dev.opencode.mobile.ui.components.OpenCodeSnackbarVariant

@Composable
fun SnackbarGalleryScreen(modifier: Modifier = Modifier) {
var message by remember { mutableStateOf<OpenCodeSnackbarMessage?>(null) }

Column(
modifier = modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
Text(
text = "Snackbar",
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.onSurface,
)
Text(
text = "Fire a one-shot snackbar. It auto-dismisses after a few seconds.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OpenCodeButton(
variant = OpenCodeButtonVariant.CompactText("Default"),
onClick = {
message =
OpenCodeSnackbarMessage(
text = "Session compacted.",
variant = OpenCodeSnackbarVariant.Default,
)
},
)
OpenCodeButton(
variant = OpenCodeButtonVariant.CompactText("Error"),
onClick = {
message =
OpenCodeSnackbarMessage(
text = "Couldn't compact session context.",
variant = OpenCodeSnackbarVariant.Error,
)
},
)
}
Box(
modifier =
Modifier
.fillMaxWidth()
.height(160.dp),
) {
OpenCodeSnackbarHost(
message = message,
onDismissed = { message = null },
modifier = Modifier.align(Alignment.BottomCenter),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.theme.OpenCodeTheme
Expand Down Expand Up @@ -49,6 +51,11 @@ sealed interface OpenCodeButtonVariant {
val imageVector: ImageVector,
val contentDescription: String? = null,
) : OpenCodeButtonVariant

data class IconCircleText(
val text: String,
val contentDescription: String? = null,
) : OpenCodeButtonVariant
}

enum class OpenCodeButtonContrast {
Expand Down Expand Up @@ -105,10 +112,12 @@ fun OpenCodeButton(
is OpenCodeButtonVariant.CompactText -> Modifier.defaultMinSize(minHeight = variantMinHeight)
is OpenCodeButtonVariant.IconSquare -> Modifier.size(iconSize)
is OpenCodeButtonVariant.IconCircle -> Modifier.size(iconSize)
is OpenCodeButtonVariant.IconCircleText -> Modifier.size(iconSize)
}
val shape =
when (variant) {
is OpenCodeButtonVariant.IconCircle -> CircleShape
is OpenCodeButtonVariant.IconCircleText -> CircleShape
else -> OpenCodeButtonCornerRadius
}

Expand Down Expand Up @@ -162,6 +171,20 @@ fun OpenCodeButton(
tint = contentColor,
)
}
is OpenCodeButtonVariant.IconCircleText ->
Box(
contentAlignment = Alignment.Center,
modifier =
variant.contentDescription?.let {
Modifier.semantics { contentDescription = it }
} ?: Modifier,
) {
Text(
text = variant.text,
style = MaterialTheme.typography.titleMedium,
color = contentColor,
)
}
}
}
}
Expand Down Expand Up @@ -210,6 +233,17 @@ private fun OpenCodeButtonIconCirclePreview() {
}
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeButtonIconCircleTextPreview() {
OpenCodeTheme(darkTheme = true) {
OpenCodeButton(
variant = OpenCodeButtonVariant.IconCircleText("/", "Open commands"),
onClick = {},
)
}
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeButtonLowContrastPreview() {
Expand Down
Loading
Loading