Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。
feat(desktop): a left sidebar, topic list, and the glass on a real backdrop
booboosui7b055a6e679e
diff --git a/desktop/build.gradle b/desktop/build.gradleindex 8fdae21..f29cec1 100644--- a/desktop/build.gradle+++ b/desktop/build.gradle@@ -144,3 +144,11 @@ tasks.register('signApp') {}}tasks.matching { it.name == 'createDistributable' }.configureEach { finalizedBy('signApp') }++// The real window body, drawn offscreen against seeded throwaway data:+// ./gradlew :desktop:uishot --args='chat 1020 820 /tmp/ui.png'+tasks.register('uishot', JavaExec) {+ classpath = sourceSets.main.runtimeClasspath+ mainClass = 'net.kuafuai.andee.desktop.UiShotKt'+ jvmArgs '-Dapple.awt.UIElement=true'+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/App.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/App.ktnew file mode 100644index 0000000..8f32878--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/App.kt@@ -0,0 +1,54 @@+package net.kuafuai.andee.desktop++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.widthIn+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp++/**+ * The window body: one photograph behind everything, the sidebar and the content+ * as glass on it, the approval and question cards above both. Its own function so+ * the screenshot harness draws exactly what the app draws.+ */+@Composable+fun AppRoot(nav: Nav, pending: ApprovalGate.Pending?, ask: AskGate.Pending?) {+ Box(Modifier.fillMaxSize()) {+ BackdropLayer()+ Row(Modifier.fillMaxSize()) {+ Sidebar(nav)+ Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.TopCenter) {+ // A reading column: on a wide window the conversation stays a comfortable measure.+ val screen = nav.current+ val card = if (screen == "chat") Modifier else Modifier.padding(14.dp).frostedCard()+ Box(Modifier.widthIn(max = 900.dp).fillMaxHeight().then(card)) {+ when {+ screen == "settings" -> SettingsScreen(+ onDone = { nav.back() },+ onOpenNotebook = { nav.push("notebook") },+ onOpenVault = { nav.push("vault") },+ onOpenScenes = { nav.push("scenes") },+ onOpenExpressions = { nav.push("expressions") },+ onOpenSelfCheck = { nav.push("selfcheck") },+ )+ screen == "selfcheck" -> SelfCheckCard(onDone = { nav.back() }, onOpenSettings = { nav.push("settings") })+ screen == "notebook" -> NotebookCard(onDone = { nav.back() })+ screen == "vault" -> VaultCard(onDone = { nav.back() })+ screen == "scenes" -> ScenesCard(onDone = { nav.back() })+ screen == "expressions" -> ExpressionsCard(onDone = { nav.back() })+ screen == "artifacts" -> ArtifactsCard(onDone = { nav.back() })+ screen.startsWith("topic:") -> TopicScreen(screen.removePrefix("topic:").toLongOrNull() ?: -1L, onDone = { nav.back() })+ else -> ChatScreen(onOpenArtifacts = { nav.go("artifacts") })+ }+ }+ }+ }+ pending?.let { ApprovalCard(it) }+ ask?.let { AskCard(it) }+ }+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.ktindex 29e48ed..2ec0493 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.kt@@ -121,12 +121,48 @@ object Assistant {if (speakReplies) net.kuafuai.andee.desktop.voice.MacVoice.speak(text)},onTurnEnd = { busy(false) },+ onSweepSpent = { Sweep.spent(it) },)brain = bbuiltFor = cfgreturn b}+ /**+ * 新对话. Puts the stretch on screen away as a topic (no model call: the title is the+ * first thing the user said, the text is the verbatim exchange) and gives the brain a+ * clean context. Same fold the quiet-hour review makes, started by the user instead.+ * Does nothing to a conversation too short to be worth keeping; never touches a turn+ * that is still running — that one is stopped first, as ■ would.+ */+ @Synchronized+ fun newConversation() {+ if (brain?.isBusy() == true) stop()+ val open = Scrollback.snapshot().filter { it.topicId == null && it.role != Scrollback.Role.ERROR }+ if (open.count { it.role == Scrollback.Role.USER } >= 1 && open.size >= 2) {+ val first = open.first { it.role == Scrollback.Role.USER }.text.replace('\n', ' ').trim()+ val text = open.joinToString("\n\n") { (if (it.role == Scrollback.Role.USER) "User: " else "Andee: ") + it.text }+ Scrollback.fold(+ title = first.take(28) + if (first.length > 28) "…" else "",+ summary = first.take(120),+ members = open.map { it.id },+ text = text,+ )+ }+ brain?.stop()+ brain = null+ builtFor = null+ progressClear()+ }++ private fun progressClear() { onProgress("") }++ /** The quiet-hour review (also the sidebar's 整理 button). Silent: no answer, no voice, no task light. */+ fun runSweep() {+ if (config().apiKey.isEmpty()) { Log.i(TAG, "sweep skipped: no API key"); return }+ ensure().runSweep()+ }+/** A turn started or ended: the window's stop button and the ball's working face. */private fun busy(b: Boolean) {MacBall.onBusy(b)@@ -171,6 +207,7 @@ object Assistant {}fun start() {+ Sweep.start()Meeting.onUserEnded = { payload ->// The user ended the recording themselves, so the brain does not have the// transcript — ask it for the minutes on a fresh turn (the phone's asr.final path).diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Backdrop.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Backdrop.ktnew file mode 100644index 0000000..f4fcfd5--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Backdrop.kt@@ -0,0 +1,125 @@+package net.kuafuai.andee.desktop++import androidx.compose.foundation.Image+import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+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.runtime.LaunchedEffect+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.ImageBitmap+import androidx.compose.ui.graphics.toComposeImageBitmap+import androidx.compose.ui.layout.ContentScale+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext+import net.kuafuai.andee.util.Log+import java.awt.image.BufferedImage+import javax.imageio.ImageIO+import kotlin.math.max++/**+ * The phone's backdrop: one photograph, blurred by us and darkened by a veil,+ * behind every surface. The cards are translucent glass laid on it — which is+ * what makes them read as glass rather than as grey boxes.+ *+ * Same recipe as the phone's Backdrop.kt, and for the same reasons: a 512-px+ * copy with three box-blur passes (a downscale-upscale smears rather than+ * frosts), and a veil *derived from the image* — `1 − 0.22 / meanLuma`, clamped+ * to 38–75% black — so swapping the file needs no new constants. The veil goes+ * over the image, not under it.+ */+object Backdrop {++ private const val TARGET_W = 512+ private const val BLUR_RADIUS = 8+ private const val BLUR_PASSES = 3+ private const val TARGET_LUMA = 0.22f+ private const val VEIL_MIN = 0.38f+ private const val VEIL_MAX = 0.75f++ class Built(val image: ImageBitmap, val veil: Float)++ @Volatile private var built: Built? = null++ /** Decode, shrink, blur, measure. Off the UI thread; cached after the first call. */+ fun build(): Built? {+ built?.let { return it }+ val src = runCatching {+ Backdrop::class.java.getResourceAsStream("/backdrop.jpg")?.use { ImageIO.read(it) }+ }.getOrNull() ?: run { Log.w("Backdrop", "backdrop.jpg missing; surfaces keep their plain fill"); return null }+ val k = TARGET_W.toDouble() / src.width+ val w = TARGET_W+ val h = max(1, (src.height * k).toInt())+ val small = BufferedImage(w, h, BufferedImage.TYPE_INT_RGB)+ small.createGraphics().apply {+ setRenderingHint(java.awt.RenderingHints.KEY_INTERPOLATION, java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR)+ drawImage(src, 0, 0, w, h, null); dispose()+ }+ val px = IntArray(w * h)+ small.getRGB(0, 0, w, h, px, 0, w)+ boxBlur(px, w, h)+ small.setRGB(0, 0, w, h, px, 0, w)+ val luma = meanLuma(px)+ val veil = (1f - TARGET_LUMA / max(luma, 0.02f)).coerceIn(VEIL_MIN, VEIL_MAX)+ Log.i("Backdrop", "backdrop ${w}x$h mean luma %.3f → veil %.0f%%".format(luma, veil * 100))+ return Built(small.toComposeImageBitmap(), veil).also { built = it }+ }++ private fun boxBlur(px: IntArray, w: Int, h: Int) {+ val tmp = IntArray(px.size)+ val r = BLUR_RADIUS+ val n = r * 2 + 1+ repeat(BLUR_PASSES) {+ for (y in 0 until h) {+ val row = y * w+ var sr = 0; var sg = 0; var sb = 0+ for (i in -r..r) { val c = px[row + i.coerceIn(0, w - 1)]; sr += (c shr 16) and 0xFF; sg += (c shr 8) and 0xFF; sb += c and 0xFF }+ for (x in 0 until w) {+ tmp[row + x] = -0x1000000 or ((sr / n) shl 16) or ((sg / n) shl 8) or (sb / n)+ val add = px[row + (x + r + 1).coerceIn(0, w - 1)]+ val sub = px[row + (x - r).coerceIn(0, w - 1)]+ sr += ((add shr 16) and 0xFF) - ((sub shr 16) and 0xFF)+ sg += ((add shr 8) and 0xFF) - ((sub shr 8) and 0xFF)+ sb += (add and 0xFF) - (sub and 0xFF)+ }+ }+ for (x in 0 until w) {+ var sr = 0; var sg = 0; var sb = 0+ for (i in -r..r) { val c = tmp[i.coerceIn(0, h - 1) * w + x]; sr += (c shr 16) and 0xFF; sg += (c shr 8) and 0xFF; sb += c and 0xFF }+ for (y in 0 until h) {+ px[y * w + x] = -0x1000000 or ((sr / n) shl 16) or ((sg / n) shl 8) or (sb / n)+ val add = tmp[(y + r + 1).coerceIn(0, h - 1) * w + x]+ val sub = tmp[(y - r).coerceIn(0, h - 1) * w + x]+ sr += ((add shr 16) and 0xFF) - ((sub shr 16) and 0xFF)+ sg += ((add shr 8) and 0xFF) - ((sub shr 8) and 0xFF)+ sb += (add and 0xFF) - (sub and 0xFF)+ }+ }+ }+ }++ private fun meanLuma(px: IntArray): Float {+ var sum = 0.0+ for (c in px) sum += (0.2126 * ((c shr 16) and 0xFF) + 0.7152 * ((c shr 8) and 0xFF) + 0.0722 * (c and 0xFF)) / 255.0+ return (sum / px.size).toFloat()+ }+}++/** The photograph and its veil, filling whatever it is put in. Black until the image is ready. */+@Composable+fun BackdropLayer(modifier: Modifier = Modifier.fillMaxSize()) {+ var b by remember { mutableStateOf(Backdrop.build()) }+ LaunchedEffect(Unit) { if (b == null) b = withContext(Dispatchers.Default) { Backdrop.build() } }+ Box(modifier.background(Palette.base)) {+ b?.let {+ Image(it.image, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize())+ // The veil goes on top of the image, not under it: a background behind the image darkens nothing.+ Box(Modifier.fillMaxSize().background(Color(0f, 0f, 0f, it.veil)))+ }+ }+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.ktindex 7ec1a9a..856231e 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt@@ -59,7 +59,7 @@ fun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {if (voice) if (zh) "能听能说" else "Can hear and speak" else if (zh) "还没配,说不了话" else "Missing — Andee cannot speak",{ onOpenSettings() }))}- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(if (zh) "自检" else "Self-check", if (zh) "每一项都可能悄悄坏掉" else "Each of these can fail silently", onClose = onDone)for (r in rows) {Row(@@ -92,10 +92,10 @@ fun ArtifactsCard(onDone: () -> Unit) {val zh = Strings.lang() == "zh"var refresh by remember { mutableStateOf(0) }val artifacts = Pages.artifacts()- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(if (zh) "产物" else "Artifacts", if (zh) "它做出来的页面" else "Pages it has built", onClose = onDone)if (artifacts.isEmpty()) {- Text(if (zh) "还没有产物。让 Andee 用 show_html 画一页。" else "Nothing yet. Ask Andee to draw a page with show_html.", color = Palette.muted, fontSize = 13.sp)+ Text(if (zh) "还没有产物。让 Andee 用 show_html 画一页。" else "Nothing yet. Ask Andee to draw a page with show_html.", color = Palette.photoInk, fontSize = 13.sp)}for (a in artifacts) {var showVersions by remember { mutableStateOf(false) }@@ -149,7 +149,7 @@ fun VaultCard(onDone: () -> Unit) {var username by remember { mutableStateOf("") }var password by remember { mutableStateOf("") }val entries = net.kuafuai.andee.desktop.mac.MacVault.entries()- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(if (zh) "保险箱" else "Vault", if (zh) "你的账号,密码只用来填,从不读出来" else "Your accounts; passwords are filled, never read out", onClose = onDone,trailing = { Text("+ " + (if (zh) "添加" else "Add"), color = Palette.accent, fontSize = 13.sp, modifier = Modifier.clickable { adding = !adding }.padding(6.dp)) })if (adding) {@@ -168,7 +168,7 @@ fun VaultCard(onDone: () -> Unit) {Spacer(Modifier.height(8.dp))}if (entries.isEmpty()) {- Text(if (zh) "保险箱是空的。" else "The vault is empty.", color = Palette.muted, fontSize = 13.sp)+ Text(if (zh) "保险箱是空的。" else "The vault is empty.", color = Palette.photoInk, fontSize = 13.sp)}for (e in entries) {val l = e.optString("label")@@ -197,7 +197,7 @@ fun NotebookCard(onDone: () -> Unit) {val memories = DesktopNotebook.book.memories().sortedByDescending { it.importance }val todos = DesktopNotebook.book.todos("pending").filter { it.status in listOf("active", "paused") }.sortedBy { if (it.nextRunAt > 0) it.nextRunAt else Long.MAX_VALUE }- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(if (zh) "小本本" else "Notebook", if (zh) "它记得的事" else "What it remembers", onClose = onDone,trailing = {Text(if (zh) "复制全部" else "Copy all", color = Palette.accent, fontSize = 13.sp,@@ -210,7 +210,7 @@ fun NotebookCard(onDone: () -> Unit) {SectionTitle(if (zh) "记忆" else "Memories")if (memories.isEmpty()) {- Text(if (zh) "还没有记住什么。" else "Nothing remembered yet.", color = Palette.muted, fontSize = 13.sp)+ Text(if (zh) "还没有记住什么。" else "Nothing remembered yet.", color = Palette.photoInk, fontSize = 13.sp)}for (m in memories) {Column(Modifier.fillMaxWidth().glassPanel(14).padding(12.dp)) {@@ -228,7 +228,7 @@ fun NotebookCard(onDone: () -> Unit) {SectionTitle(if (zh) "待办" else "Todos")if (todos.isEmpty()) {- Text(if (zh) "没有待办。" else "Nothing pending.", color = Palette.muted, fontSize = 13.sp)+ Text(if (zh) "没有待办。" else "Nothing pending.", color = Palette.photoInk, fontSize = 13.sp)}for (t in todos) {Row(Modifier.fillMaxWidth().glassPanel(14).padding(12.dp), verticalAlignment = Alignment.CenterVertically) {@@ -250,10 +250,10 @@ fun ScenesCard(onDone: () -> Unit) {var refresh by remember { mutableStateOf(0) }val scenes = DesktopNotebook.book.scenes().sortedByDescending { it.lastUsedAt }val active = Settings.get("scene").ifEmpty { null }- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(if (zh) "情景" else "Scenes", if (zh) "它和你一起学会的做事方式" else "Ways of working it learned", onClose = onDone)if (scenes.isEmpty()) {- Text(if (zh) "还没有情景。空对话里可以选一个预设,或让它学着提一个。" else "No scenes yet. Pick a preset from an empty chat, or let Andee propose one.", color = Palette.muted, fontSize = 13.sp)+ Text(if (zh) "还没有情景。空对话里可以选一个预设,或让它学着提一个。" else "No scenes yet. Pick a preset from an empty chat, or let Andee propose one.", color = Palette.photoInk, fontSize = 13.sp)}for (s in scenes) {var expanded by remember { mutableStateOf(false) }@@ -291,3 +291,32 @@ fun ScenesCard(onDone: () -> Unit) {}}}++/** One finished topic, read back: the verbatim text, and a way to pick it up again. */+@Composable+fun TopicScreen(topicId: Long, onDone: () -> Unit) {+ val zh = Strings.lang() == "zh"+ val topic = Scrollback.topics().firstOrNull { it.id == topicId }+ val text = Scrollback.topicText(topicId)+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {+ GlassHeader(topic?.title ?: (if (zh) "话题" else "Topic"),+ topic?.let { java.text.SimpleDateFormat("yyyy-MM-dd HH:mm", java.util.Locale.US).format(java.util.Date(it.endedAt)) }, onClose = onDone)+ if (topic == null) {+ Text(if (zh) "这个话题已经不在了。" else "This topic is gone.", color = Palette.photoInk, fontSize = 13.sp)+ return@Column+ }+ if (topic.summary.isNotBlank()) {+ Text(topic.summary, color = Palette.label, fontSize = 13.sp, modifier = Modifier.fillMaxWidth().glassPanel(14).padding(12.dp))+ Spacer(Modifier.height(10.dp))+ }+ PrimaryButton(if (zh) "接着聊这个话题" else "Continue this topic") {+ Thread { Assistant.say("继续聊「${topic.title}」。先 get_topic(id=${topic.id}) 读回对话再接着聊。") }.start()+ onDone()+ }+ Spacer(Modifier.height(12.dp))+ androidx.compose.foundation.text.selection.SelectionContainer {+ Text(text ?: (if (zh) "(记录已经不在了)" else "(the transcript is gone)"), color = Palette.label, fontSize = 13.sp, lineHeight = 19.sp,+ modifier = Modifier.fillMaxWidth().glassWell(14).padding(14.dp))+ }+ }+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatScreen.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatScreen.ktindex d1edaf8..945769c 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatScreen.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatScreen.kt@@ -63,6 +63,8 @@ object Palette {val label = Color(0xFFDCE1EA)val secondary = Color(0xFF8F97A6)val muted = Color(0xFF5F6775)+ /** Text sitting directly on the photograph. [muted] is chosen against a card and has no ground to stand on here. */+ val photoInk = Color(0xFF98A0AE)val accent = Color(0xFF7FA5FF)val tint = Color(0xFF4C6FFF)val danger = Color(0xFFFF6B6B)@@ -78,7 +80,7 @@ object Palette {}@Composable-fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenArtifacts: () -> Unit) {+fun ChatScreen(onOpenArtifacts: () -> Unit) {var rows by remember { mutableStateOf(Scrollback.snapshot()) }var progress by remember { mutableStateOf("") }var busy by remember { mutableStateOf(false) }@@ -88,10 +90,18 @@ fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenArvar artifacts by remember { mutableStateOf(Pages.artifacts()) }var recording by remember { mutableStateOf(Meeting.isActive()) }val list = rememberLazyListState()- val items = displayItems(rows)+ // Folded stretches live in the sidebar's topic list; the chat is the conversation in progress.+ val items = rows.filter { it.topicId == null }+ // Registered on enter, removed on leave: the sidebar remounts this screen on every+ // navigation, and a listener left behind per visit is a leak that grows all day.+ androidx.compose.runtime.DisposableEffect(Unit) {+ val l: () -> Unit = { rows = Scrollback.snapshot() }+ Scrollback.addListener(l)+ onDispose { Scrollback.removeListener(l) }+ }LaunchedEffect(Unit) {- Scrollback.addListener { rows = Scrollback.snapshot() }+ rows = Scrollback.snapshot()Pages.onChange = { artifacts = Pages.artifacts() }Meeting.onRecordingChanged = { recording = it }Assistant.onProgress = { progress = it }@@ -119,7 +129,7 @@ fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenArThread { Assistant.say(t) }.start()}- Column(Modifier.fillMaxSize().background(Palette.base)) {+ Column(Modifier.fillMaxSize()) {Header(status = when {recording -> if (Strings.lang() == "zh") "● 正在录音" else "● Recording"@@ -132,8 +142,6 @@ fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenAronStop = {if (recording) Meeting.stopFromUser() else if (busy) Assistant.stop()},- onSettings = onOpenSettings,- onSelfCheck = onOpenSelfCheck,)Column(Modifier.weight(1f).fillMaxWidth().padding(horizontal = 16.dp)) {@@ -141,7 +149,7 @@ fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenArText("📄 " + (if (Strings.lang() == "zh") "产物" else "Artifacts") + " (${artifacts.size})",color = Palette.accent, fontSize = 13.sp,- modifier = Modifier.fillMaxWidth().glassPanel(12).clickable { onOpenArtifacts() }.padding(12.dp),+ modifier = Modifier.fillMaxWidth().glassSurface(12).clickable { onOpenArtifacts() }.padding(12.dp),)Spacer(Modifier.height(10.dp))}@@ -156,14 +164,7 @@ fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenAr}}}- items(items, key = { itemKey(it) }) { it ->- when (it) {- is Scrollback.Row -> Bubble(it)- is TopicRow -> TopicCard(it.topic, it.count) {- Thread { Assistant.say("继续聊「${it.topic.title}」。先 get_topic(id=${it.topic.id}) 读回对话再接着聊。") }.start()- }- }- }+ items(items, key = { it.id }) { Bubble(it) }}}@@ -187,25 +188,21 @@ fun ChatScreen(onOpenSettings: () -> Unit, onOpenSelfCheck: () -> Unit, onOpenAr/** Title plus a one-line status, with stop and settings on the right — the phone's control bar. */@Composable-private fun Header(status: String?, stoppable: Boolean, onStop: () -> Unit, onSettings: () -> Unit, onSelfCheck: () -> Unit) {+private fun Header(status: String?, stoppable: Boolean, onStop: () -> Unit) {Row(Modifier.fillMaxWidth().padding(start = 16.dp, end = 16.dp, top = 14.dp, bottom = 10.dp),verticalAlignment = Alignment.CenterVertically,) {- Column {- Text("Andee", color = Palette.text, fontSize = 20.sp, fontWeight = FontWeight.SemiBold)- if (status != null) {- Text(status, color = if (status.startsWith("●")) Palette.accent else Palette.secondary, fontSize = 12.sp)- }- }+ Text(+ status ?: (if (Strings.lang() == "zh") "对话" else "Chat"),+ color = if (status?.startsWith("●") == true) Palette.accent else Palette.title,+ fontSize = 18.sp, fontWeight = FontWeight.SemiBold,+ )Spacer(Modifier.weight(1f))if (stoppable) {Pill(if (Strings.lang() == "zh") "■ 停止" else "■ Stop") { onStop() }Spacer(Modifier.width(8.dp))}- Pill("✓") { onSelfCheck() }- Spacer(Modifier.width(8.dp))- Pill("⚙") { onSettings() }}}@@ -257,29 +254,6 @@ private fun RoundButton(enabled: Boolean, onClick: () -> Unit, glyph: () -> Stri}}-/** One folded stretch rendered as a single card, at the position of its first row. */-private data class TopicRow(val topic: Scrollback.Topic, val count: Int)--private fun displayItems(rows: List<Scrollback.Row>): List<Any> {- val topics = Scrollback.topics().associateBy { it.id }- val seen = mutableSetOf<Long>()- val out = mutableListOf<Any>()- for (r in rows) {- val tid = r.topicId- if (tid == null) { out += r; continue }- if (seen.add(tid)) {- topics[tid]?.let { out += TopicRow(it, rows.count { x -> x.topicId == tid }) }- }- }- return out-}--private fun itemKey(it: Any): Any = when (it) {- is Scrollback.Row -> "r${it.id}"- is TopicRow -> "t${it.topic.id}"- else -> it-}-fun noVoiceKey() =if (Strings.lang() == "zh") "还没配语音 Key:在 ⚙ 设置的「语音」里填上。" else "No voice key yet: add it under Voice in ⚙ Settings."@@ -299,11 +273,11 @@ private fun Bubble(r: Scrollback.Row) {when {error -> Palette.error.copy(alpha = 0.12f)mine -> Palette.accentSoft- else -> Palette.panel+ else -> Palette.glass},- RoundedCornerShape(if (mine) 16.dp else 16.dp),+ RoundedCornerShape(16.dp),)- .border(1.dp, if (error) Palette.error.copy(alpha = 0.4f) else Palette.hairline, RoundedCornerShape(16.dp))+ .border(1.dp, if (error) Palette.error.copy(alpha = 0.4f) else Palette.glassEdge, RoundedCornerShape(16.dp)).padding(horizontal = 14.dp, vertical = 9.dp),)}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatUi.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatUi.ktindex 48453f3..3a0b308 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatUi.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ChatUi.kt@@ -29,99 +29,17 @@ import java.text.SimpleDateFormatimport java.util.Dateimport java.util.Locale-/** A folded conversation, collapsed to one card: 继续话题 / 对话记录. */-@Composable-fun TopicCard(topic: Scrollback.Topic, count: Int, onContinue: () -> Unit) {- var expanded by remember { mutableStateOf(false) }- val fmt = SimpleDateFormat("MM-dd HH:mm", Locale.US)- Column(- Modifier.fillMaxWidth().background(Palette.panel, RoundedCornerShape(14.dp))- .border(1.dp, Palette.hairline, RoundedCornerShape(14.dp)).padding(12.dp),- verticalArrangement = Arrangement.spacedBy(8.dp),- ) {- Row(verticalAlignment = androidx.compose.ui.Alignment.CenterVertically) {- Text("🗂 " + topic.title, color = Palette.text, fontSize = 14.sp)- Spacer(Modifier.weight(1f))- Text("${fmt.format(Date(topic.endedAt))} · $count msgs", color = Palette.secondary, fontSize = 11.sp)- }- if (topic.summary.isNotBlank()) {- Text(topic.summary, color = Palette.secondary, fontSize = 12.sp)- }- if (expanded) {- SelectionContainer {- Text(- Scrollback.topicText(topic.id) ?: "(记录已不在)",- color = Palette.text, fontSize = 12.sp,- modifier = Modifier.fillMaxWidth().background(Palette.well, RoundedCornerShape(10.dp)).padding(10.dp),- )- }- }- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- Pill(t("继续话题", "Continue")) { onContinue() }- Pill(if (expanded) t("收起记录", "Hide transcript") else t("对话记录", "Transcript")) { expanded = !expanded }- }- }-}--/** The 产物 shelf: one card per artifact, with open / continue / versions. */-@Composable-fun ArtifactsPanel(artifacts: List<Pages.Page>, onOpen: (Pages.Page) -> Unit, onRevise: (Pages.Page) -> Unit, onRollback: (Pages.Page) -> Unit) {- if (artifacts.isEmpty()) return- Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {- Text(t("产物", "Artifacts"), color = Palette.secondary, fontSize = 13.sp)- Row(- Modifier.horizontalScroll(rememberScrollState()),- horizontalArrangement = Arrangement.spacedBy(8.dp),- ) {- for (a in artifacts) {- ArtifactCard(a, onOpen, onRevise, onRollback)- }- }- }-}--@Composable-private fun ArtifactCard(a: Pages.Page, onOpen: (Pages.Page) -> Unit, onRevise: (Pages.Page) -> Unit, onRollback: (Pages.Page) -> Unit) {- var showVersions by remember { mutableStateOf(false) }- Column(- Modifier.width(200.dp).background(Palette.panel, RoundedCornerShape(12.dp))- .border(1.dp, Palette.hairline, RoundedCornerShape(12.dp)).padding(10.dp),- verticalArrangement = Arrangement.spacedBy(6.dp),- ) {- Text("📄 " + a.title, color = Palette.text, fontSize = 13.sp)- Text("v${a.version}", color = Palette.secondary, fontSize = 11.sp)- Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {- Pill(t("打开", "Open")) { onOpen(a) }- Pill(t("继续", "Edit")) { onRevise(a) }- Pill(t("版本", "Versions")) { showVersions = !showVersions }- }- if (showVersions) {- for (v in Pages.versionsOf(a.groupId)) {- Row(verticalAlignment = androidx.compose.ui.Alignment.CenterVertically) {- Text("v${v.version}${if (v.file == null) "(没了)" else ""}", color = if (v.id == a.id) Palette.text else Palette.secondary, fontSize = 11.sp)- Spacer(Modifier.weight(1f))- if (v.id != a.id && v.file != null) {- Text(t("回退", "Roll back"), color = Palette.accent, fontSize = 11.sp, modifier = Modifier.clickable { onRollback(v) })- }- }- }- }- }-}-private fun t(zh: String, en: String) = if (Strings.lang() == "zh") zh else en/** An empty chat offers scenes instead of sitting blank — the phone's presets bubbles. */@Composablefun SceneOffer(onPick: (ScenePresets.Preset) -> Unit) {Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {- Text(t("还没有对话。说点什么,或选一个情景:", "Nothing here yet. Say something, or pick a scene:"), color = Palette.secondary, fontSize = 13.sp)+ Text(t("还没有对话。说点什么,或选一个情景:", "Nothing here yet. Say something, or pick a scene:"), color = Palette.photoInk, fontSize = 13.sp)Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {for (p in ScenePresets.ALL) {Column(- Modifier.fillMaxWidth().background(Palette.panel, RoundedCornerShape(12.dp))- .border(1.dp, Palette.hairline, RoundedCornerShape(12.dp))- .clickable { onPick(p) }.padding(12.dp),+ Modifier.fillMaxWidth().glassSurface(12).clickable { onPick(p) }.padding(12.dp),) {Text(p.title, color = Palette.text, fontSize = 14.sp)Text(p.summary, color = Palette.secondary, fontSize = 12.sp)diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ExpressionsCard.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ExpressionsCard.ktindex 63b4820..4d678eb 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ExpressionsCard.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/ExpressionsCard.kt@@ -48,7 +48,7 @@ fun ExpressionsCard(onDone: () -> Unit) {val zh = Strings.lang() == "zh"var pickedMood by remember { mutableStateOf(Mood.CALM) }val currentLook = Settings.get("ball").ifEmpty { BallLooks.active.name }- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(if (zh) "形象与表情" else "Look & expressions", if (zh) "选一个形象,表情跟着它变" else "Pick a look; the face follows", onClose = onDone)Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {BallPreview(pickedMood, 168.dp)diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Glass.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Glass.ktindex ac70119..8ff7ed7 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Glass.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Glass.kt@@ -17,8 +17,6 @@ import androidx.compose.material.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifier-import androidx.compose.ui.draw.drawBehind-import androidx.compose.ui.geometry.Offsetimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.SolidColor@@ -48,24 +46,40 @@ fun Modifier.glassPanel(radius: Int = 14): Modifier = this.background(Palette.panel, RoundedCornerShape(radius.dp)).border(1.dp, Palette.panelEdge, RoundedCornerShape(radius.dp))+/**+ * A surface sitting directly on the photograph rather than inside a card: 12% white, not+ * the 6% film that is right one level down. 6% on a blurred photograph is a card that has+ * quietly stopped existing — the phone's Glass.GLASS note, and the reason there are two.+ */+fun Modifier.glassSurface(radius: Int = 14): Modifier = this+ .background(Palette.glass, RoundedCornerShape(radius.dp))+ .border(1.dp, Palette.glassEdge, RoundedCornerShape(radius.dp))++/**+ * The frosted card the form screens sit in: 60% black over the photograph, the phone's+ * CARD_FROSTED. Text is chosen against a dark ground; left directly on the photograph it+ * is legible on the dark half and gone on the bright one.+ */+fun Modifier.frostedCard(radius: Int = 20): Modifier = this+ .background(Palette.cardFrosted, RoundedCornerShape(radius.dp))+ .border(1.dp, Palette.hairline, RoundedCornerShape(radius.dp))+ .then(sheen(radius))+/** A recessed surface: text fields and picker tracks. */fun Modifier.glassWell(radius: Int = 12): Modifier = this.background(Palette.well, RoundedCornerShape(radius.dp)).border(1.dp, Palette.wellEdge, RoundedCornerShape(radius.dp))-/** The lit top edge — the one piece that reads as glass on a flat backdrop. */-private fun Modifier.sheen(radius: Int): Modifier = this.drawBehind {- val h = size.height * 0.5f- drawRect(- brush = Brush.verticalGradient(- 0f to Color(0x1FFFFFFF),- h / size.height to Color(0x00FFFFFF),- endY = h,- ),- topLeft = Offset(0f, 0f),- size = androidx.compose.ui.geometry.Size(size.width, h),- )-}+/**+ * The lit top edge — the one piece that reads as glass on a flat backdrop. A gradient+ * *background in the card's own shape*. It returns a fresh [Modifier], not an extension on the+ * receiver: used as `.then(sheen(r))` an extension would re-append the receiver's whole chain+ * (padding included), which painted a second card inset by the padding.+ */+private fun sheen(radius: Int): Modifier = Modifier.background(+ Brush.verticalGradient(0f to Color(0x1FFFFFFF), 0.45f to Color(0x00FFFFFF)),+ RoundedCornerShape(radius.dp),+)@Composablefun GlassHeader(title: String, subtitle: String? = null, onClose: () -> Unit, trailing: @Composable (() -> Unit)? = null) {diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Main.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Main.ktindex 7bd5008..1e40b9f 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Main.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Main.kt@@ -4,6 +4,9 @@ import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.widthInimport androidx.compose.ui.unit.dpimport androidx.compose.ui.window.Windowimport androidx.compose.ui.window.MenuBar@@ -22,18 +25,14 @@ fun main() {Assistant.start()application {var pending by remember { mutableStateOf(ApprovalGate.current) }- // The chat is the phone's unfolded card: the ball is always there, the chat comes and goes.+ // The chat window comes and goes (the ball is always there); the nav says what it shows.var chat by remember { mutableStateOf(true) }- // The card stack: each card is a full-window surface, opened on top of the last.- val stack = remember { androidx.compose.runtime.mutableStateListOf("chat") }- fun push(s: String) { stack.add(s) }- fun pop() { if (stack.size > 1) stack.removeAt(stack.lastIndex) }- val screen = stack.last()- ApprovalGate.onChange = { pending = ApprovalGate.current; if (pending != null) { chat = true; stack.clear(); stack.add("chat") } }+ val nav = remember { Nav() }+ ApprovalGate.onChange = { pending = ApprovalGate.current; if (pending != null) { chat = true; nav.go("chat") } }var ballWindow by remember { mutableStateOf<java.awt.Window?>(null) }var chatWindow by remember { mutableStateOf<java.awt.Window?>(null) }var ask by remember { mutableStateOf(AskGate.current) }- AskGate.onChange = { ask = AskGate.current; if (ask != null) { chat = true; stack.clear(); stack.add("chat") } }+ AskGate.onChange = { ask = AskGate.current; if (ask != null) { chat = true; nav.go("chat") } }// A click aimed at another app must not land on Andee: both windows step aside for the instant of it.// (Native, not Window.opacity: AWT refuses that on the decorated chat window.)Assistant.hideWindows = { hide -> net.kuafuai.andee.desktop.mac.Bridge.setOwnAlpha(if (hide) 0.0 else 1.0) }@@ -41,7 +40,7 @@ fun main() {FloatingBall(onTap = {if (Meeting.isActive()) Meeting.stopFromUser()- else if (!net.kuafuai.andee.desktop.voice.MacVoice.toggle()) { chat = true; stack.clear(); stack.add("chat"); push("settings") }+ else if (!net.kuafuai.andee.desktop.voice.MacVoice.toggle()) { chat = true; nav.go("settings") }},onLongPress = { chat = !chat },onWindow = { ballWindow = it },@@ -51,38 +50,23 @@ fun main() {onCloseRequest = { chat = false },visible = chat,title = "Andee",- state = rememberWindowState(width = 620.dp, height = 820.dp),+ state = rememberWindowState(width = 1020.dp, height = 820.dp),resizable = true,) {chatWindow = window+ window.minimumSize = java.awt.Dimension(760, 520)MenuBar {Menu("Andee") {- Item(if (Strings.lang() == "zh") "显示对话" else "Show chat", onClick = { chat = true; stack.clear(); stack.add("chat") })+ Item(if (Strings.lang() == "zh") "新对话" else "New chat", onClick = { Assistant.newConversation(); chat = true; nav.go("chat") },+ shortcut = androidx.compose.ui.input.key.KeyShortcut(androidx.compose.ui.input.key.Key.N, meta = true))+ Item(if (Strings.lang() == "zh") "显示对话" else "Show chat", onClick = { chat = true; nav.go("chat") })+ Item(if (Strings.lang() == "zh") "设置" else "Settings", onClick = { chat = true; nav.go("settings") },+ shortcut = androidx.compose.ui.input.key.KeyShortcut(androidx.compose.ui.input.key.Key.Comma, meta = true))Item(if (Strings.lang() == "zh") "退出 Andee" else "Quit Andee", onClick = ::exitApplication,shortcut = androidx.compose.ui.input.key.KeyShortcut(androidx.compose.ui.input.key.Key.Q, meta = true))}}- androidx.compose.foundation.layout.Box {- when (screen) {- "settings" -> SettingsScreen(- onDone = { pop() },- onOpenNotebook = { push("notebook") },- onOpenVault = { push("vault") },- onOpenScenes = { push("scenes") },- onOpenExpressions = { push("expressions") },- onOpenSelfCheck = { push("selfcheck") },- )- "selfcheck" -> SelfCheckCard(onDone = { pop() }, onOpenSettings = { push("settings") })- "notebook" -> NotebookCard(onDone = { pop() })- "vault" -> VaultCard(onDone = { pop() })- "scenes" -> ScenesCard(onDone = { pop() })- "expressions" -> ExpressionsCard(onDone = { pop() })- "artifacts" -> ArtifactsCard(onDone = { pop() })- else -> ChatScreen(onOpenSettings = { push("settings") }, onOpenSelfCheck = { push("selfcheck") }, onOpenArtifacts = { push("artifacts") })- }- pending?.let { ApprovalCard(it) }- ask?.let { AskCard(it) }- }+ AppRoot(nav, pending, ask)}}}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Nav.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Nav.ktnew file mode 100644index 0000000..ad8a95e--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Nav.kt@@ -0,0 +1,26 @@+package net.kuafuai.andee.desktop++import androidx.compose.runtime.mutableStateListOf++/**+ * Where the window is. A stack, because settings opens the notebook and the+ * notebook closes back to settings; the sidebar jumps by replacing the stack.+ * Screens are plain strings: "chat", "settings", "notebook", "vault", "scenes",+ * "expressions", "selfcheck", "artifacts", and "topic:<id>".+ */+class Nav {+ val stack = mutableStateListOf("chat")+ val current: String get() = stack.last()++ /** Open [s] on top of what is showing. */+ fun push(s: String) { if (current != s) stack.add(s) }++ /** The sidebar's jump: a top-level destination replaces the stack, with chat underneath so ✕ lands there. */+ fun go(s: String) {+ stack.clear()+ stack.add("chat")+ if (s != "chat") stack.add(s)+ }++ fun back() { if (stack.size > 1) stack.removeAt(stack.lastIndex) }+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Scrollback.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Scrollback.ktindex 7cd457d..8432e36 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Scrollback.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Scrollback.kt@@ -45,6 +45,7 @@ object Scrollback {}fun addListener(l: () -> Unit) = synchronized(lock) { listeners += l }+ fun removeListener(l: () -> Unit) = synchronized(lock) { listeners -= l }fun snapshot(): List<Row> = synchronized(lock) { rows.toList() }diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Settings.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Settings.ktindex 0e28aa2..30853f0 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Settings.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Settings.kt@@ -10,6 +10,9 @@ import java.util.UUID*/object AppDirs {val root: File by lazy {+ // `andee.home` is for the screenshot harness and tests: a throwaway directory, so+ // drawing the UI never reads or writes the user's real conversation.+ System.getProperty("andee.home")?.let { return@lazy File(it).apply { mkdirs() } }val home = System.getProperty("user.home")File(home, "Library/Application Support/Andee").apply { mkdirs() }}@@ -30,7 +33,7 @@ object Settings {val KEYS = setOf("brain", "llm_api_key", "llm_base_url", "llm_model", "llm_thinking", "llm_reasoning_effort","api_key", "asr_endpoint", "tts_endpoint", "asr_resource_id", "tts_resource_id", "tts_speaker",- "voice_provider", "lang", "max_steps", "scene", "ball", "ball_pos", "notify",+ "voice_provider", "lang", "max_steps", "scene", "ball", "ball_pos", "notify", "sweep", "sweep_quiet_minutes", "sweep_daily_cap","shell_mode", "shell_workdirs", "shell_critical_confirm",)diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/SettingsScreen.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/SettingsScreen.ktindex b733b73..d14e1b3 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/SettingsScreen.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/SettingsScreen.kt@@ -44,7 +44,7 @@ fun SettingsScreen(var lang by remember { mutableStateOf(Strings.lang()) }var fullOpenAsk by remember { mutableStateOf(false) }- Column(Modifier.fillMaxSize().background(Palette.base).padding(20.dp).verticalScroll(rememberScrollState())) {+ Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp)) {GlassHeader(t("设置", "Settings"), subtitle = t("所有设置都存在本机", "Everything stays on this Mac"), onClose = onDone)SectionTitle(t("界面语言", "Language"))@@ -73,7 +73,7 @@ fun SettingsScreen("full" -> t("不进沙箱、不问:Andee 能改动这台 Mac 上的任何文件。", "No sandbox, no asking: Andee can change any file.")else -> t("只读命令直接跑,其它每条先问你。", "Read-only commands run; everything else asks first.")},- color = Palette.secondary, fontSize = 12.sp,+ color = Palette.secondary, fontSize = 12.sp, modifier = Modifier.padding(top = 6.dp),)GlassField(t("工作文件夹(逗号分隔,留空用 ~/Andee)", "Work folders (comma-separated; blank = ~/Andee)"), v["shell_workdirs"].orEmpty(), { v["shell_workdirs"] = it })SectionTitle(t("SSH 钥匙", "SSH keys"))diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Sidebar.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Sidebar.ktnew file mode 100644index 0000000..4af6110--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Sidebar.kt@@ -0,0 +1,147 @@+package net.kuafuai.andee.desktop++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.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+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.material.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.DisposableEffect+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.graphics.Color+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import java.text.SimpleDateFormat+import java.util.Date+import java.util.Locale++/**+ * The left rail: the doors the phone hides behind ⚙ and ✓, as one tap each, and+ * under them the conversation's finished topics. A desktop has the room for it+ * and a person at a desk reaches for these all day.+ *+ * It is glass laid on the same blurred photograph as everything else, a shade+ * lighter than the content pane so the two read as two panes of one material.+ */+@Composable+fun Sidebar(nav: Nav, width: androidx.compose.ui.unit.Dp = 228.dp) {+ val zh = Strings.lang() == "zh"+ fun t(a: String, b: String) = if (zh) a else b++ // The topic list re-reads whenever the scrollback changes (a fold is a write to it).+ var version by remember { mutableStateOf(0) }+ DisposableEffect(Unit) {+ val l: () -> Unit = { version = version + 1 }+ Scrollback.addListener(l)+ onDispose { Scrollback.removeListener(l) }+ }+ val topics = remember(version) { Scrollback.topics() }+ val artifactCount = remember(version, nav.current) { Pages.artifacts().size }+ val fmt = remember { SimpleDateFormat("MM-dd HH:mm", Locale.US) }+ val here = nav.current+ var sweeping by remember { mutableStateOf(false) }++ Column(+ Modifier.width(width).fillMaxHeight()+ .background(Color(0x14FFFFFF))+ .border(1.dp, Palette.panelEdge)+ .padding(horizontal = 10.dp, vertical = 12.dp),+ ) {+ // Brand row, and the one button that always means "start over".+ Row(Modifier.fillMaxWidth().padding(horizontal = 6.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {+ Text("Andee", color = Palette.title, fontSize = 18.sp, fontWeight = FontWeight.SemiBold)+ }+ Spacer(Modifier.height(10.dp))+ Text(+ "+ " + t("新对话", "New chat"), color = Palette.title, fontSize = 14.sp, fontWeight = FontWeight.Medium,+ modifier = Modifier.fillMaxWidth()+ .background(Palette.tint.copy(alpha = 0.55f), RoundedCornerShape(12.dp))+ .border(1.dp, Palette.accent.copy(alpha = 0.6f), RoundedCornerShape(12.dp))+ .clickable { Assistant.newConversation(); nav.go("chat") }+ .padding(horizontal = 12.dp, vertical = 9.dp),+ )+ Spacer(Modifier.height(12.dp))++ NavItem("💬", t("对话", "Chat"), here == "chat") { nav.go("chat") }+ NavItem("📄", t("产物", "Artifacts") + if (artifactCount > 0) " $artifactCount" else "", here == "artifacts") { nav.go("artifacts") }+ NavItem("📓", t("小本本", "Notebook"), here == "notebook") { nav.go("notebook") }+ NavItem("🎭", t("情景", "Scenes"), here == "scenes") { nav.go("scenes") }+ NavItem("🔐", t("保险箱", "Vault"), here == "vault") { nav.go("vault") }+ NavItem("🙂", t("形象与表情", "Look"), here == "expressions") { nav.go("expressions") }++ Spacer(Modifier.height(14.dp))+ Row(Modifier.fillMaxWidth().padding(horizontal = 8.dp), verticalAlignment = Alignment.CenterVertically) {+ Text(t("话题", "Topics"), color = Palette.secondary, fontSize = 12.sp)+ Spacer(Modifier.weight(1f))+ Text(+ if (sweeping) t("整理中…", "Working…") else t("整理", "Tidy up"),+ color = if (sweeping) Palette.photoInk else Palette.accent, fontSize = 12.sp,+ modifier = Modifier.clickable(enabled = !sweeping) {+ sweeping = true+ Thread { Sweep.now(); Thread.sleep(4000); sweeping = false }.start()+ }.padding(2.dp),+ )+ }+ Spacer(Modifier.height(4.dp))++ if (topics.isEmpty()) {+ Text(+ t("聊完的一段会收在这里。安静一会儿它会自己整理,也可以点上面的「整理」。",+ "Finished stretches are put away here. Andee tidies up when it's quiet, or tap Tidy up."),+ color = Palette.photoInk, fontSize = 11.sp, lineHeight = 15.sp,+ modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),+ )+ }+ LazyColumn(Modifier.weight(1f).fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(2.dp)) {+ items(topics, key = { it.id }) { tp ->+ val on = here == "topic:${tp.id}"+ Column(+ Modifier.fillMaxWidth()+ .background(if (on) Palette.glass else Color.Transparent, RoundedCornerShape(10.dp))+ .clickable { nav.go("topic:${tp.id}") }+ .padding(horizontal = 10.dp, vertical = 7.dp),+ ) {+ Text(tp.title, color = if (on) Palette.title else Palette.label, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)+ Text(fmt.format(Date(tp.endedAt)), color = Palette.photoInk, fontSize = 10.sp)+ }+ }+ }++ Spacer(Modifier.height(8.dp))+ NavItem("✅", t("自检", "Self-check"), here == "selfcheck") { nav.go("selfcheck") }+ NavItem("🔧", t("设置", "Settings"), here == "settings") { nav.go("settings") }+ }+}++@Composable+private fun NavItem(icon: String, label: String, selected: Boolean, onClick: () -> Unit) {+ Row(+ Modifier.fillMaxWidth()+ .background(if (selected) Palette.glass else Color.Transparent, RoundedCornerShape(10.dp))+ .border(1.dp, if (selected) Palette.glassEdge else Color.Transparent, RoundedCornerShape(10.dp))+ .clickable { onClick() }+ .padding(horizontal = 10.dp, vertical = 8.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Text(icon, fontSize = 14.sp, modifier = Modifier.width(24.dp))+ Text(label, color = if (selected) Palette.title else Palette.label, fontSize = 14.sp)+ }+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Sweep.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Sweep.ktnew file mode 100644index 0000000..9202587--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Sweep.kt@@ -0,0 +1,105 @@+package net.kuafuai.andee.desktop++import net.kuafuai.andee.util.Log+import org.json.JSONObject+import java.io.File+import java.text.SimpleDateFormat+import java.util.Date+import java.util.Locale+import java.util.concurrent.Executors+import java.util.concurrent.TimeUnit++/**+ * The quiet-hour review, on the Mac: when the conversation has been silent for a+ * while, the brain looks back over it, keeps what is worth keeping in the notebook,+ * and folds finished stretches into topics — which is where the sidebar's topic+ * list comes from. Nothing else on the desktop ever calls `runSweep`, so without+ * this the list would stay empty for ever.+ *+ * Same gates as the phone's onSweepTimer, for the same reasons: it is the user's+ * own key paying for it, so it is on a daily cap; it waits for real silence+ * (measured from the *user's* last words, which `touchActivity` stamps); and it+ * never fires while a meeting holds the microphone or a turn is running.+ *+ * A sweep that is skipped (fewer than six messages) must not be retried every+ * minute: [lastAttemptAt] remembers that this stretch of silence was already+ * tried, and the next try waits for new activity.+ */+object Sweep {++ private const val TAG = "Sweep"+ private const val DEFAULT_QUIET_MINUTES = 20+ private const val DEFAULT_DAILY_CAP = 12+ private const val CHECK_EVERY_S = 60L++ private val exec = Executors.newSingleThreadScheduledExecutor { r -> Thread(r, "sweep").apply { isDaemon = true } }+ private val metaFile get() = AppDirs.file("sweep.json")+ private val lock = Any()++ @Volatile private var lastAttemptAt = 0L++ fun enabled(): Boolean = Settings.get("sweep").lowercase() != "off"+ private fun quietMs(): Long =+ (Settings.get("sweep_quiet_minutes").toIntOrNull() ?: DEFAULT_QUIET_MINUTES).coerceIn(5, 240) * 60_000L+ private fun dailyCap(): Int =+ (Settings.get("sweep_daily_cap").toIntOrNull() ?: DEFAULT_DAILY_CAP).coerceIn(0, 100)++ fun start() {+ exec.scheduleWithFixedDelay({ runCatching { tick() }.onFailure { Log.w(TAG, "tick failed", it) } },+ CHECK_EVERY_S, CHECK_EVERY_S, TimeUnit.SECONDS)+ }++ private fun lastActivity(): Long =+ runCatching { AppDirs.file("last_activity").readText().trim().toLong() }.getOrDefault(0L)++ /**+ * Whether a review should start now. Pure, because the retry rule is the part that is+ * easy to get wrong and expensive to get wrong: without the `activity <= lastAttemptAt`+ * line a conversation too short to review is retried every minute for ever, each time+ * waking the brain.+ */+ internal fun shouldSweep(+ now: Long, activity: Long, lastAttemptAt: Long, quietMs: Long,+ countToday: Int, cap: Int, enabled: Boolean, meeting: Boolean,+ ): Boolean = when {+ !enabled || meeting -> false+ activity == 0L -> false // the user has never spoken+ activity <= lastAttemptAt -> false // this silence was already tried+ now - activity < quietMs -> false // not quiet long enough yet+ countToday >= cap -> false // today's budget is spent+ else -> true+ }++ private fun tick() {+ val now = System.currentTimeMillis()+ if (!shouldSweep(now, lastActivity(), lastAttemptAt, quietMs(), countToday(), dailyCap(), enabled(), Meeting.isActive())) return+ lastAttemptAt = now+ Log.i(TAG, "quiet for a while; reviewing the conversation")+ Assistant.runSweep()+ }++ /** The "整理" button: review now, quiet or not. Still respects the busy and key checks inside the brain. */+ fun now() {+ lastAttemptAt = System.currentTimeMillis()+ Assistant.runSweep()+ }++ /** A sweep finished: count it against today's cap. Called from the brain's onSweepSpent. */+ fun spent(tokens: Int) = synchronized(lock) {+ val day = today()+ val o = read()+ val sameDay = o.optString("day") == day+ o.put("day", day)+ .put("count", (if (sameDay) o.optInt("count") else 0) + 1)+ .put("tokens", (if (sameDay) o.optInt("tokens") else 0) + tokens)+ .put("last", System.currentTimeMillis())+ runCatching { metaFile.writeText(o.toString()) }+ Log.i(TAG, "sweep done (${o.optInt("count")} today, ~$tokens tokens)")+ }++ fun countToday(): Int = synchronized(lock) { read().let { if (it.optString("day") == today()) it.optInt("count") else 0 } }+ fun tokensToday(): Int = synchronized(lock) { read().let { if (it.optString("day") == today()) it.optInt("tokens") else 0 } }++ private fun today() = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date())+ private fun read(): JSONObject = runCatching { JSONObject(metaFile.readText()) }.getOrDefault(JSONObject())+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.ktnew file mode 100644index 0000000..104d049--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.kt@@ -0,0 +1,53 @@+package net.kuafuai.andee.desktop++import androidx.compose.ui.ExperimentalComposeUiApi+import androidx.compose.ui.ImageComposeScene+import androidx.compose.ui.unit.Density+import org.jetbrains.skia.EncodedImageFormat+import java.io.File+import kotlin.system.exitProcess++/**+ * The real UI, drawn offscreen to a PNG, for checking layout and the glass without a+ * window on screen: `./gradlew :desktop:uishot --args='chat 1020 820 /tmp/ui.png'`.+ * Draws [AppRoot] itself — the same function the app draws — against a throwaway data+ * directory seeded with a short conversation and two topics, so nothing of the user's+ * is read or shown.+ *+ * screen: chat | settings | notebook | scenes | vault | selfcheck | expressions | artifacts | topic:1+ */+@OptIn(ExperimentalComposeUiApi::class)+fun main(args: Array<String>) {+ val screen = args.getOrElse(0) { "chat" }+ val w = args.getOrElse(1) { "1020" }.toInt()+ val h = args.getOrElse(2) { "820" }.toInt()+ val out = File(args.getOrElse(3) { "/tmp/ui.png" })+ System.setProperty("andee.home", File.createTempFile("andee-shot", "").also { it.delete(); it.mkdirs() }.path)+ if (args.getOrElse(4) { "" } == "empty") Scrollback.wipe() else seed()+ val nav = Nav().also { if (screen != "chat") it.go(screen) }+ val density = Density(2f)+ val scene = ImageComposeScene(width = w * 2, height = h * 2, density = density) { AppRoot(nav, null, null) }+ // Let the backdrop (decoded off the main thread) and the layout settle.+ repeat(12) { scene.render(it * 50_000_000L); Thread.sleep(60) }+ val img = scene.render(700_000_000L)+ out.writeBytes(img.encodeToData(EncodedImageFormat.PNG)!!.bytes)+ println("wrote $out (${w}x$h @2x, screen=$screen)")+ scene.close()+ exitProcess(0)+}++private fun seed() {+ Scrollback.wipe()+ Scrollback.add(Scrollback.Role.USER, "帮我把桌面上的截图整理一下")+ Scrollback.add(Scrollback.Role.ASSISTANT, "好的,我先看看桌面上有多少张截图。一共 14 张,按日期分了三组,要我放进「截图」文件夹吗?")+ Scrollback.add(Scrollback.Role.USER, "放吧")+ Scrollback.add(Scrollback.Role.ASSISTANT, "已经放好了:~/Desktop/截图/ 下面按月份分了三个子文件夹。")+ val a = Scrollback.snapshot().map { it.id }+ Scrollback.fold("整理桌面截图", "把 14 张截图按月份归档", a, "User: 帮我把桌面上的截图整理一下\n\nAndee: 好的……")+ Scrollback.add(Scrollback.Role.USER, "明天上午十点提醒我开周会")+ Scrollback.add(Scrollback.Role.ASSISTANT, "好,已经设好了明天 10:00 的提醒。")+ val b = Scrollback.snapshot().filter { it.topicId == null }.map { it.id }+ Scrollback.fold("周会提醒", "明天 10:00 开周会", b, "User: 明天上午十点提醒我开周会\n\nAndee: 好……")+ Scrollback.add(Scrollback.Role.USER, "看看今天有什么新闻")+ Scrollback.add(Scrollback.Role.ASSISTANT, "我先打开浏览器搜一下,稍等。")+}diff --git a/desktop/src/main/resources/backdrop.jpg b/desktop/src/main/resources/backdrop.jpgnew file mode 100644index 0000000..91e7bd2Binary files /dev/null and b/desktop/src/main/resources/backdrop.jpg differdiff --git a/desktop/src/test/kotlin/net/kuafuai/andee/desktop/SweepTest.kt b/desktop/src/test/kotlin/net/kuafuai/andee/desktop/SweepTest.ktnew file mode 100644index 0000000..f2b2e18--- /dev/null+++ b/desktop/src/test/kotlin/net/kuafuai/andee/desktop/SweepTest.kt@@ -0,0 +1,30 @@+package net.kuafuai.andee.desktop++import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class SweepTest {+ private val quiet = 20 * 60_000L+ private val t0 = 1_000_000_000L++ private fun go(+ now: Long = t0 + quiet + 1, activity: Long = t0, last: Long = 0, count: Int = 0, cap: Int = 12,+ enabled: Boolean = true, meeting: Boolean = false,+ ) = Sweep.shouldSweep(now, activity, last, quiet, count, cap, enabled, meeting)++ @Test fun `fires once the conversation has been quiet long enough`() = assertTrue(go())+ @Test fun `waits while it is not quiet yet`() = assertFalse(go(now = t0 + quiet - 1))+ @Test fun `never fires for a user who has not spoken`() = assertFalse(go(activity = 0))++ @Test fun `does not retry the same silence`() {+ // A sweep was attempted after the last activity (and skipped: too few messages).+ assertFalse(go(last = t0 + quiet))+ }++ @Test fun `new activity re-opens it`() = assertTrue(go(activity = t0 + 5 * quiet, now = t0 + 6 * quiet + 1, last = t0 + quiet))+ @Test fun `stops at the daily cap`() = assertFalse(go(count = 12))+ @Test fun `a cap of zero means off`() = assertFalse(go(cap = 0))+ @Test fun `off means off`() = assertFalse(go(enabled = false))+ @Test fun `never during a meeting`() = assertFalse(go(meeting = true))+}