惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
博客园_首页
美团技术团队
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
J
Java Code Geeks
T
Tailwind CSS Blog
Jina AI
Jina AI
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(android): show live chat context usage · openclaw/ope...
Tosko4 · 2026-06-15 · via Recent Commits to openclaw:main

@@ -74,6 +74,7 @@ import kotlinx.coroutines.withContext

7474

import java.text.DateFormat

7575

import java.util.Date

7676

import java.util.Locale

77+

import kotlin.math.roundToInt

77787879

/** Full chat surface that wires MainViewModel state to messages, attachments, voice, and composer actions. */

7980

@Composable

@@ -95,6 +96,7 @@ fun ChatScreen(

9596

val sessions by viewModel.chatSessions.collectAsState()

9697

val chatDraft by viewModel.chatDraft.collectAsState()

9798

val pendingAssistantAutoSend by viewModel.pendingAssistantAutoSend.collectAsState()

99+

val contextUsage = resolveChatContextUsage(sessionKey = sessionKey, mainSessionKey = mainSessionKey, sessions = sessions)

98100

val context = LocalContext.current

99101

val resolver = context.contentResolver

100102

val scope = rememberCoroutineScope()

@@ -196,6 +198,7 @@ fun ChatScreen(

196198

onValueChange = { input = it },

197199

attachments = attachments,

198200

thinkingLevel = thinkingLevel,

201+

contextUsage = contextUsage,

199202

healthOk = healthOk,

200203

pendingRunCount = pendingRunCount,

201204

onThinkingLevelChange = viewModel::setChatThinkingLevel,

@@ -685,6 +688,7 @@ private fun ChatComposer(

685688

onValueChange: (String) -> Unit,

686689

attachments: List<PendingImageAttachment>,

687690

thinkingLevel: String,

691+

contextUsage: ChatContextUsage,

688692

healthOk: Boolean,

689693

pendingRunCount: Int,

690694

onThinkingLevelChange: (String) -> Unit,

@@ -699,7 +703,11 @@ private fun ChatComposer(

699703

AttachmentStrip(attachments = attachments, onRemoveAttachment = onRemoveAttachment)

700704

}

701705702-

ChatContextMeter(thinkingLevel = thinkingLevel, onClick = { onThinkingLevelChange(nextThinkingValue(thinkingLevel)) })

706+

ChatContextMeter(

707+

thinkingLevel = thinkingLevel,

708+

contextUsage = contextUsage,

709+

onClick = { onThinkingLevelChange(nextThinkingValue(thinkingLevel)) },

710+

)

703711704712

Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {

705713

ChatInputPill(value = value, onValueChange = onValueChange, onPickImages = onPickImages, onVoice = onVoice, modifier = Modifier.weight(1f))

@@ -735,8 +743,10 @@ private fun ChatComposer(

735743

@Composable

736744

private fun ChatContextMeter(

737745

thinkingLevel: String,

746+

contextUsage: ChatContextUsage,

738747

onClick: () -> Unit,

739748

) {

749+

val contextFraction = contextMeterWidth(contextUsage) ?: 0f

740750

Row(

741751

modifier = Modifier.width(178.dp),

742752

verticalAlignment = Alignment.CenterVertically,

@@ -755,7 +765,13 @@ private fun ChatContextMeter(

755765

horizontalArrangement = Arrangement.spacedBy(6.dp),

756766

) {

757767

Icon(imageVector = Icons.Default.Refresh, contentDescription = null, modifier = Modifier.size(12.dp), tint = ClawTheme.colors.textSubtle)

758-

Text(text = "Context ${contextPercent(thinkingLevel)}%", style = ClawTheme.type.caption.copy(fontSize = 12.5.sp, lineHeight = 16.sp), color = ClawTheme.colors.textMuted)

768+

Text(

769+

text = contextMeterLabel(contextUsage, thinkingLevel),

770+

style = ClawTheme.type.caption.copy(fontSize = 12.5.sp, lineHeight = 16.sp),

771+

color = ClawTheme.colors.textMuted,

772+

maxLines = 1,

773+

overflow = TextOverflow.Ellipsis,

774+

)

759775

}

760776

}

761777

Box(

@@ -768,7 +784,7 @@ private fun ChatContextMeter(

768784

Box(

769785

modifier =

770786

Modifier

771-

.fillMaxWidth(thinkingMeterWidth(thinkingLevel))

787+

.fillMaxWidth(contextFraction)

772788

.height(3.dp)

773789

.background(ClawTheme.colors.primary, RoundedCornerShape(999.dp)),

774790

)

@@ -902,6 +918,32 @@ private fun isActiveSessionChoice(

902918

return choiceKey == current

903919

}

904920921+

internal data class ChatContextUsage(

922+

val totalTokens: Long?,

923+

val totalTokensFresh: Boolean?,

924+

val contextTokens: Long?,

925+

)

926+927+

internal fun resolveChatContextUsage(

928+

sessionKey: String,

929+

mainSessionKey: String,

930+

sessions: List<ChatSessionEntry>,

931+

): ChatContextUsage {

932+

val entry =

933+

sessions.firstOrNull {

934+

isActiveSessionChoice(

935+

choiceKey = it.key,

936+

sessionKey = sessionKey,

937+

mainSessionKey = mainSessionKey,

938+

)

939+

}

940+

return ChatContextUsage(

941+

totalTokens = entry?.totalTokens,

942+

totalTokensFresh = entry?.totalTokensFresh,

943+

contextTokens = entry?.contextTokens,

944+

)

945+

}

946+905947

@Composable

906948

private fun SendButton(

907949

enabled: Boolean,

@@ -958,17 +1000,29 @@ private fun nextThinkingValue(value: String): String =

9581000

else -> "off"

9591001

}

9601002961-

/** Maps thinking presets to the visual context meter fill fraction. */

962-

private fun thinkingMeterWidth(value: String): Float =

1003+

internal fun contextMeterWidth(usage: ChatContextUsage): Float? {

1004+

if (usage.totalTokensFresh == false) return null

1005+

val total = usage.totalTokens?.takeIf { it >= 0L } ?: return null

1006+

val context = usage.contextTokens?.takeIf { it > 0L } ?: return null

1007+

return (total.toDouble() / context.toDouble()).coerceIn(0.0, 1.0).toFloat()

1008+

}

1009+1010+

internal fun contextMeterLabel(

1011+

usage: ChatContextUsage,

1012+

thinkingLevel: String,

1013+

): String {

1014+

val contextLabel = contextMeterWidth(usage)?.let { "Context ${(it * 100).roundToInt()}%" } ?: "Context --"

1015+

return "$contextLabel · ${contextMeterThinkingLabel(thinkingLevel)}"

1016+

}

1017+1018+

internal fun contextMeterThinkingLabel(value: String): String =

9631019

when (value.lowercase(Locale.US)) {

964-

"low" -> 0.34f

965-

"medium" -> 0.58f

966-

"high" -> 0.82f

967-

else -> 0.18f

1020+

"low" -> "low"

1021+

"medium" -> "medium"

1022+

"high" -> "high"

1023+

else -> "off"

9681024

}

9691025970-

private fun contextPercent(value: String): Int = (thinkingMeterWidth(value) * 100).toInt()

971-9721026

private fun formatChatTimestamp(timestampMs: Long): String = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(Date(timestampMs))

97310279741028

/** Quick markdown detector used to avoid routing plain chat text through the markdown renderer. */