feat(v1.2): 阶段 0 —— 情绪双字段 + 立绘联动的地基 + 死亡规则(v2.0.55)
按 v1.2 需求开工。情绪双字段是所有新功能的**地基**:立绘联动按 preset 切图、 peer_emotions 注入 preset、状态脚本改情绪,三个都压在它上面,所以先做它。 ## 数据层 `emotions` 表:`emotion`(单字段自由文本)→ `preset` + `text`。 - `preset` 五档(喜/怒/哀/平常/死亡)**驱动系统行为**;`text` 只管扮演质感。 合成一个做不到:系统要按 preset 分支,而自然语言没法当分支条件。 - **迁移**:老的自由文本搬进 `text`,preset 给「平常」。旧列留着不动 (SQLite 删列要重建整张表,不值当)。 - 新增 `emotion_state` / `emotion_from_export` / `is_dead`; `emotion_set` 改成"只写传进来的那些"(preset 和 text 分开可选)。 - `emotion_from_export` **两种格式都认**:v1.1 的字符串、v1.2 的对象。 只认新格式的话,用户拿老文件导入会在情绪这一步抛异常, 而前半截记忆已经写进去了 —— 留下一个"记忆进来了、情绪没进来"的半成品。 ## 死亡规则(需求 3.5) - 死亡的智能体**不能对话**:内核在**发起前**拦(和 Token 限额同一层, 不是生成时才拒绝,那时候钱已经花了) - **AI 不能把自己从死亡改活** —— 这条限制放在 **AI 的工具通道**上 (`agent_tools.emotion_set`),**不在数据层**:数据层拦了的话, 界面就没法复活了,而那正是需求写的"用户手动改回是兜底主权" - 死亡状态**照常播报**给同世界观伙伴 ## 注入 - `<emotion>` 两字段都带(附录 C 的格式);「平常 + 空文本」整段省掉 - `<peer_emotions>` 注入 **preset 不是 text** —— text 是那个角色的内心独白, 读给别的角色听等于扒开他的脑子 ## 界面 - 记忆页情绪区:五档选择器(「死亡」标红)+ 自由文本;选中死亡时多一行 红字说明(不说的话用户点了死亡发现发不出消息,会以为坏了) - 聊天页顶栏显示 preset;**死亡时输入条换成提示条**,点「去复活 ›」直达情绪区 ## ★ 真机验证抓到一个探针抓不到的 bug 改完情绪后界面上**什么都没发生** —— `setEmotion` 只刷新了记忆页, 没刷新全局状态,而顶栏标签和死亡禁言读的都是 `state.emotions`。 这种"数据存进去了、界面不知道"的漏,探针(测内核)一个都抓不到。 ## 验证 探针新增两节 14 项: - **17 节 老库迁移**:用**内存库**测(换文件的做法被 WAL 坑过一次—— 连着的连接 + `-wal` 里的新数据会把复制进去的老库盖掉,测出来是假阴性)。 覆盖:能搬、preset 默认、幂等、新库跑它是空操作。 - **18 节 死亡规则**:AI 能把自己改成死亡、**不能自愈**、用户能改活、 死亡照常播报、不认识的 preset 被拒且理由列出合法值、只写 text 时 preset 不动。 五个探针全绿;装机实测五档选择器 + 迁移过来的老文本 + 死亡禁言提示条。
This commit is contained in:
@@ -30,8 +30,8 @@ android {
|
||||
* versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装",
|
||||
* 改小了会装不上)。
|
||||
*/
|
||||
versionCode = 254
|
||||
versionName = "2.0.54"
|
||||
versionCode = 255
|
||||
versionName = "2.0.55"
|
||||
|
||||
ndk {
|
||||
// Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份
|
||||
|
||||
@@ -263,7 +263,7 @@ fun AppRoot(
|
||||
worldMode = true,
|
||||
loading = false,
|
||||
hint = "",
|
||||
onSetEmotion = {},
|
||||
onSetEmotion = { _, _ -> },
|
||||
onAdd = { _, _ -> },
|
||||
onUpdate = { _, _, _ -> },
|
||||
// 删是可以的:限权只约束 AI,用户有权清掉任何人写的
|
||||
@@ -318,7 +318,7 @@ fun AppRoot(
|
||||
agentNames = vm.agents.associate { it.id to it.name },
|
||||
loading = vm.memoryLoading,
|
||||
hint = vm.memoryHint,
|
||||
onSetEmotion = { vm.setEmotion(it) },
|
||||
onSetEmotion = { preset, text -> vm.setEmotion(preset, text) },
|
||||
onAdd = { t, c -> vm.addMemory(t, c) },
|
||||
onUpdate = { id, t, c -> vm.updateMemory(id, t, c) },
|
||||
onDelete = { vm.deleteMemory(it) },
|
||||
|
||||
@@ -531,12 +531,17 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun setEmotion(text: String) {
|
||||
fun setEmotion(preset: String, text: String) {
|
||||
val id = memoryAgentId
|
||||
if (id.isBlank()) return
|
||||
viewModelScope.launch {
|
||||
runCatching { withContext(Dispatchers.IO) { client.setEmotion(id, text) } }
|
||||
runCatching { withContext(Dispatchers.IO) { client.setEmotion(id, preset, text) } }
|
||||
refreshMemories()
|
||||
// ★★ 还必须刷新**全局状态** —— 顶栏的情绪标签、聊天页的**死亡禁言**
|
||||
// 读的都是 `state.emotions`,只刷记忆页的话界面上什么都看不出来。
|
||||
// (这个漏是真机验证抓到的:把智能体改成「死亡」之后回聊天页,
|
||||
// 输入条照样能用。)
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.doubao.lynxclone.ui
|
||||
package com.doubao.lynxclone.ui
|
||||
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -373,7 +373,42 @@ fun ChatScreen(vm: AppViewModel) {
|
||||
)
|
||||
}
|
||||
}
|
||||
InputBar(vm, onPickFile, onMic, speech)
|
||||
// ★★ 死亡禁言(v1.2 §6.1,需求 3.5)。
|
||||
//
|
||||
// 内核那道拦截是权威,但**界面上也要拦一道** ——
|
||||
// 让用户敲完一整句话、点发送、再被拒绝,是最差的体验。
|
||||
// 提示条点一下直达记忆页的情绪区(那就是复活入口)。
|
||||
val deadAgent = vm.activeAgent
|
||||
if (deadAgent != null && vm.state.emotions[deadAgent.id]?.dead == true) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(Color(0x1AD93025))
|
||||
.padding(10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
"「${deadAgent.name}」已经死亡,不能对话。",
|
||||
fontSize = 11.sp,
|
||||
color = Color(0xFFB3261E),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
Text(
|
||||
"去复活 ›",
|
||||
fontSize = 12.sp,
|
||||
color = Color.White,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color(0xFFB3261E))
|
||||
.clickable { vm.openMemories(deadAgent.id) }
|
||||
.padding(horizontal = 10.dp, vertical = 5.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
InputBar(vm, onPickFile, onMic, speech)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,11 +478,15 @@ private fun ChatHeader(vm: AppViewModel, agentName: String, speech: SpeechContro
|
||||
// ★ 当前情绪(复查报告 2.6):AI 自己能改情绪,改了却看不出来,
|
||||
// 这个功能就只是个看不见的字段。放在名字旁边、字号小一半 ——
|
||||
// 它是个状态注脚,不该抢名字的注意力。
|
||||
val emo = vm.state.emotions[vm.activeAgent?.id ?: ""].orEmpty()
|
||||
if (emo.isNotBlank()) {
|
||||
// ★ v1.2:这里显示的是 **preset(五档)**,不是那句自由文本 ——
|
||||
// 自由文本是角色的内心独白,摆在顶栏上不合适;preset 才是
|
||||
// "一眼看出他现在什么情绪"那个粒度。点开记忆页能看到全文。
|
||||
val emo = vm.state.emotions[vm.activeAgent?.id ?: ""]
|
||||
val emoLabel = emo?.preset.orEmpty()
|
||||
if (emoLabel.isNotBlank() && emoLabel != "平常") {
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text(
|
||||
emo.take(8),
|
||||
emoLabel.take(8),
|
||||
fontSize = 10.sp,
|
||||
color = Doubao.Blue,
|
||||
maxLines = 1,
|
||||
|
||||
@@ -35,6 +35,8 @@ import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.doubao.lynxclone.data.MemoryItem
|
||||
import com.doubao.lynxclone.data.PRESETS
|
||||
import com.doubao.lynxclone.data.PRESET_DEAD
|
||||
import com.doubao.lynxclone.data.MemorySpace
|
||||
|
||||
/*
|
||||
@@ -77,7 +79,8 @@ fun MemoryScreen(
|
||||
worldMode: Boolean = false,
|
||||
loading: Boolean,
|
||||
hint: String,
|
||||
onSetEmotion: (String) -> Unit,
|
||||
/** 保存情绪:preset(五档)+ text(自由一句) */
|
||||
onSetEmotion: (String, String) -> Unit,
|
||||
onAdd: (String, String) -> Unit,
|
||||
onUpdate: (String, String?, String?) -> Unit,
|
||||
onDelete: (String) -> Unit,
|
||||
@@ -96,7 +99,9 @@ fun MemoryScreen(
|
||||
) {
|
||||
var editing by remember { mutableStateOf<MemoryItem?>(null) }
|
||||
var adding by remember { mutableStateOf(false) }
|
||||
var emotionDraft by remember(space?.emotion) { mutableStateOf(space?.emotion ?: "") }
|
||||
/** 情绪的双字段草稿(v1.2)。preset 是五档之一、text 是自由文本 */
|
||||
var emotionPreset by remember(space?.emotion) { mutableStateOf(space?.emotion?.preset ?: "平常") }
|
||||
var emotionText by remember(space?.emotion) { mutableStateOf(space?.emotion?.text ?: "") }
|
||||
// 一次确认,正好是弹窗该用的地方(AGENTS.md 那张表)
|
||||
var confirmSummarize by remember { mutableStateOf(false) }
|
||||
/** 调注入窗口(输入条数,0 = 不限) */
|
||||
@@ -308,24 +313,67 @@ fun MemoryScreen(
|
||||
.padding(12.dp),
|
||||
) {
|
||||
Text(
|
||||
"AI 自己能改(emotion_set),你也可以在这里改。它每次对话都会被带进提示词。",
|
||||
"preset 决定系统行为(立绘换哪张、能不能对话、同伴看到什么脸色);" +
|
||||
"下面那句话只是扮演质感。AI 自己能改,你也可以在这里改。",
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
color = doubaoTextSecondary(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Spacer(Modifier.height(10.dp))
|
||||
// ★ 五档选择器,顺序就是需求里的顺序(喜 怒 哀 平常 死亡)。
|
||||
// 「死亡」单独标红 —— 它是**唯一有系统后果**的档位。
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
for (p in PRESETS) {
|
||||
val on = p == emotionPreset
|
||||
val danger = p == PRESET_DEAD
|
||||
Text(
|
||||
p,
|
||||
fontSize = 13.sp,
|
||||
color = when {
|
||||
on -> Color.White
|
||||
danger -> Color(0xFFB3261E)
|
||||
else -> doubaoText()
|
||||
},
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(
|
||||
when {
|
||||
on && danger -> Color(0xFFB3261E)
|
||||
on -> Doubao.Blue
|
||||
else -> doubaoCard()
|
||||
},
|
||||
)
|
||||
.clickable { emotionPreset = p }
|
||||
.padding(horizontal = 14.dp, vertical = 7.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
// 死亡是唯一需要额外解释的档位:它会让这个智能体**不能对话**。
|
||||
// 不说清楚的话,用户点了「死亡」然后发现消息发不出去,会以为坏了。
|
||||
if (emotionPreset == PRESET_DEAD) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
"「死亡」状态下这个智能体不能对话(输入条会禁用)。" +
|
||||
"把它改回其他档就是复活 —— 这是你的权力,AI 自己不能从死亡改活。",
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
color = Color(0xFFB3261E),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(10.dp))
|
||||
OutlinedTextField(
|
||||
value = emotionDraft,
|
||||
onValueChange = { emotionDraft = it },
|
||||
placeholder = { Text("比如:刚被夸了,有点得意", fontSize = 13.sp) },
|
||||
value = emotionText,
|
||||
onValueChange = { emotionText = it },
|
||||
placeholder = { Text("他此刻在想什么(自由一句,比如:强作镇定,手心全是汗)", fontSize = 12.sp) },
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 56.dp),
|
||||
textStyle = androidx.compose.ui.text.TextStyle(fontSize = 14.sp),
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
|
||||
TextButton(
|
||||
onClick = { onSetEmotion(emotionDraft.trim()) },
|
||||
enabled = emotionDraft.trim() != (space?.emotion ?: ""),
|
||||
onClick = { onSetEmotion(emotionPreset, emotionText.trim()) },
|
||||
enabled = emotionPreset != (space?.emotion?.preset ?: "平常") ||
|
||||
emotionText.trim() != (space?.emotion?.text ?: ""),
|
||||
) { Text("保存情绪", fontSize = 13.sp) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user