diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index c58627a..6edb1d4 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -30,8 +30,8 @@ android { * versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装", * 改小了会装不上)。 */ - versionCode = 248 - versionName = "2.0.48" + versionCode = 249 + versionName = "2.0.49" ndk { // Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份 diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentEditScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentEditScreen.kt index 5c60501..6aafba9 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentEditScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentEditScreen.kt @@ -314,6 +314,25 @@ fun AgentEditScreen( ) } + /* ---------------- 记忆 / 用量 ---------------- */ + if (!isNew) { + SectionLabel("它的状态") + Row( + Modifier.fillMaxWidth().padding(horizontal = 12.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + BigAction("看它记住了什么") { vm.openMemories(draft.id) } + BigAction("看它用了多少") { vm.openTokenUsage(draft.id) } + } + Spacer(Modifier.height(4.dp)) + Box(Modifier.fillMaxWidth().padding(horizontal = 14.dp)) { + Hint( + "记忆是 AI 自己攒的(也可能记错),觉得不对就在那里改 —— " + + "这是它记错时唯一的兜底。", + ) + } + } + /* ---------------- 导出 / 删除 ---------------- */ if (!isNew) { Spacer(Modifier.height(10.dp)) @@ -376,6 +395,21 @@ private fun Hint(text: String) { Text(text, fontSize = 11.sp, lineHeight = 16.sp, color = doubaoTextSecondary()) } +/** 一行里并排的两个入口按钮(记忆 / 用量这种"跳去另一个界面"的动作) */ +@Composable +private fun BigAction(label: String, onClick: () -> Unit) { + Text( + label, + fontSize = 13.sp, + color = Doubao.Blue, + modifier = Modifier + .clip(RoundedCornerShape(12.dp)) + .background(Doubao.Blue.copy(alpha = 0.10f)) + .clickable { onClick() } + .padding(horizontal = 14.dp, vertical = 9.dp), + ) +} + @Composable private fun LabeledField( label: String, diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt index ba825c2..9bd01f6 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt @@ -125,6 +125,8 @@ fun AgentSelectScreen( onEnter: (Agent) -> Unit, /** 「更多」→ Token 用量详情(需求 2.4) */ onMore: (Agent) -> Unit, + /** 「记忆」→ 看它记住了什么(记忆管理界面的主入口) */ + onMemories: (Agent) -> Unit, /** 管理(新建 / 编辑 / 导入导出)—— 需求文档之外,但少了它用户没法加自己的智能体 */ onManage: () -> Unit, onBack: () -> Unit, @@ -295,14 +297,27 @@ fun AgentSelectScreen( } } - // ---------------- 底部:进入对话 ---------------- + // ---------------- 底部:进对话 / 看记忆 ---------------- Row( Modifier.fillMaxWidth().padding(12.dp), - horizontalArrangement = Arrangement.Center, + horizontalArrangement = Arrangement.spacedBy(8.dp), ) { + // ★「记忆」和「开始对话」并排:进对话之前顺手看一眼它记住了什么。 + // 记忆是这个功能里最需要"用户能看见"的东西 —— AI 会记错 + // (把"喜欢猫"记成"讨厌猫"很常见),看见了才能改。 Box( Modifier - .fillMaxWidth() + .clip(RoundedCornerShape(26.dp)) + .background(doubaoSurface()) + .clickable { onMemories(pickedAgent) } + .padding(horizontal = 20.dp, vertical = 14.dp), + contentAlignment = Alignment.Center, + ) { + Text("记忆", fontSize = 15.sp, color = doubaoText()) + } + Box( + Modifier + .weight(1f) .clip(RoundedCornerShape(26.dp)) .background( Brush.horizontalGradient(listOf(Color(0xFF2B7BFF), Color(0xFF5B9BFF))), diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt index 04b1ac7..19639c7 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt @@ -122,6 +122,7 @@ fun AgentsScreen(vm: AppViewModel) { active = agent.id == activeId, onUse = { vm.useAgent(agent.id) }, onEdit = { vm.openAgentEdit(agent) }, + onMemories = { vm.openMemories(agent.id) }, onDelete = { confirmDelete = agent }, ) } @@ -185,6 +186,8 @@ private fun AgentRow( active: Boolean, onUse: () -> Unit, onEdit: () -> Unit, + /** 看这个智能体记住了什么(记忆管理界面的入口之一) */ + onMemories: () -> Unit, onDelete: () -> Unit, ) { Surface( @@ -222,6 +225,9 @@ private fun AgentRow( maxLines = 1, ) } + // ★「记忆」放在「编辑」**左边**:它是"看它记住了什么", + // 属于日常动作;编辑是配置动作,用得少。 + TextButton(onClick = onMemories) { Text("记忆", fontSize = 12.sp) } TextButton(onClick = onEdit) { Text("编辑", fontSize = 12.sp) } if (!agent.builtin) { TextButton(onClick = onDelete) { Text("删除", fontSize = 12.sp) } diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt index e6382b6..939567e 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt @@ -150,6 +150,7 @@ fun AppRoot( activeId = vm.state.settings.activeAgentId, onEnter = { vm.enterAgent(it.id) }, onMore = { vm.openTokenUsage(it.id) }, + onMemories = { vm.openMemories(it.id) }, onManage = { vm.screen = Screen.Agents }, onBack = { vm.screen = Screen.Chat }, ) @@ -243,6 +244,40 @@ fun AppRoot( ) } + // 世界观的**共享记忆**(从「资源 → 世界观 → 记忆」进来)。 + // + // ★ 它和上面那个是同一个空间(world:)的**另一个视角**: + // 那边问"玄辰记住了什么",这边问"这个世界里大家共同记得什么"。 + // 纯只读 —— 写入限权是按 author 判的,而这个视角没有"我"。 + AnimatedVisibility( + visible = vm.worldMemoryId.isNotBlank(), + enter = slideInVertically(tween(240)) { it / 6 } + fadeIn(tween(180)), + exit = slideOutVertically(tween(200)) { it / 8 } + fadeOut(tween(150)), + ) { + MemoryScreen( + space = vm.worldMemorySpace, + agentName = vm.state.worldviews.firstOrNull { it.id == vm.worldMemoryId }?.name + ?: "世界观", + agentId = "", + agentNames = vm.agents.associate { it.id to it.name }, + worldMode = true, + loading = false, + hint = "", + onSetEmotion = {}, + onAdd = { _, _ -> }, + onUpdate = { _, _, _ -> }, + // 删是可以的:限权只约束 AI,用户有权清掉任何人写的 + onDelete = { vm.deleteWorldMemory(it) }, + onTogglePin = { _, _ -> }, + onSummarize = {}, + onExport = {}, + onImportClick = {}, + onOpenOwn = {}, + onBackToActive = {}, + onBack = { vm.closeWorldMemories() }, + ) + } + // 「智能体编辑」—— 全屏界面(字段二十多个,弹窗装不下,见 AGENTS.md 那张表) AnimatedVisibility( visible = vm.agentEditOpen, @@ -463,6 +498,13 @@ private fun DrawerOverlay(vm: AppViewModel) { // 管理(新建/编辑/导入导出)在那个页面的「管理」里 vm.screen = Screen.AgentSelect; vm.drawerOpen = false } + // ★「记忆」:当前这个智能体记住了什么。 + // 给它一个抽屉直达入口,因为这是**日常要看**的东西 —— + // 你得知道它记对没记错(AI 记反了"喜欢猫/讨厌猫"这种事很常见)。 + DrawerItem(Icons.Filled.Psychology, "记忆") { + vm.drawerOpen = false + vm.activeAgent?.id?.let { vm.openMemories(it) } + } // 「笔记」—— 用户要能查看 AI 替他记了什么 DrawerItem(Icons.Filled.EditNote, "笔记") { vm.drawerOpen = false diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt index 7bfdf0e..5571aae 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt @@ -463,6 +463,42 @@ class AppViewModel(val client: KernelClient) : ViewModel() { memorySpace = null } + /** + * 世界观的**共享记忆**("这个世界里大家共同记得什么")。 + * + * ★ 和智能体的记忆是同一个空间、不同的视角,所以用**独立的状态**: + * 共用一个 `memorySpace` 的话,从世界观进去看完再回智能体那边, + * 会看到上一个视角留下的数据(界面上表现为"名字和内容对不上")。 + */ + var worldMemoryId by mutableStateOf("") + private set + var worldMemorySpace by mutableStateOf(null) + private set + + fun openWorldMemories(worldviewId: String) { + worldMemoryId = worldviewId + worldMemorySpace = null + viewModelScope.launch { + worldMemorySpace = runCatching { + withContext(Dispatchers.IO) { client.worldMemories(worldviewId) } + }.getOrNull() + } + } + + fun closeWorldMemories() { + worldMemoryId = "" + worldMemorySpace = null + } + + /** 世界观视角下删一条(用户有权删任何人的 —— 限权只约束 AI) */ + fun deleteWorldMemory(mid: String) { + val wid = worldMemoryId + viewModelScope.launch { + runCatching { withContext(Dispatchers.IO) { client.deleteMemory(mid) } } + if (wid.isNotBlank()) openWorldMemories(wid) + } + } + fun refreshMemories() { val id = memoryAgentId if (id.isBlank()) return @@ -807,7 +843,13 @@ class AppViewModel(val client: KernelClient) : ViewModel() { urlPickerOpen = true } - /** 用户自己输了一个网址(或从列表里挑了一个) */ + /** + * 用户自己输了一个网址(或从列表里挑了一个)。 + * + * ★ 它**取代**了原来的 `openWebPage(url)` —— 那个是"只负责打开、不补协议", + * 和这个除了补 https 之外一模一样,等于同一逻辑两份。 + * 删掉的那个审计脚本抓出来的(`openWebPage` 没有任何调用点)。 + */ fun openTypedUrl(text: String) { val t = text.trim() if (t.isEmpty()) return @@ -823,14 +865,6 @@ class AppViewModel(val client: KernelClient) : ViewModel() { urlPickerOpen = false } - /** 打开一个网页(全屏界面) */ - fun openWebPage(url: String) { - val u = url.trim() - if (u.isEmpty()) return - pickUrlFrom = emptyList() // 进网页界面时把"选哪个"收掉 - webPage = u - } - fun closeWebPage() { webPage = null } diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt index 3342ff1..6e43f7e 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt @@ -64,6 +64,15 @@ fun MemoryScreen( agentId: String, /** 所有智能体的 id → 名字(共享记忆里显示"由某某写入") */ agentNames: Map, + /** + * **世界观视角**("这个世界里大家共同记得什么")。 + * + * ★ 只读:增删改仍从智能体那边做。世界观视角没有"我", + * 而共享空间的写入限权是按 author 判的(需求 3.6)—— + * 硬做一个权限含义不明的界面,只会让人误操作。 + * 情绪也藏起来:情绪是**智能体私有**的,不属于这个空间。 + */ + worldMode: Boolean = false, loading: Boolean, hint: String, onSetEmotion: (String) -> Unit, @@ -94,6 +103,7 @@ fun MemoryScreen( append(agentName.ifBlank { "智能体" }) append(" · ") when { + worldMode -> append("世界观共享记忆") readingOwn -> append("绑定前的私有记忆") space == null -> append("读取中") space.shared -> append("世界观共享记忆") @@ -104,7 +114,9 @@ fun MemoryScreen( }, onBack = { if (readingOwn) onBackToActive() else onBack() }, actions = { - if (!readingOwn) TopTextAction("导入", onClick = onImportClick) + // 世界观视角是纯只读(导入/导出都以"某个智能体的记忆"为单位, + // 而这里没有"我")—— 不给按钮,而不是给一个点了没反应的按钮 + if (!worldMode && !readingOwn) TopTextAction("导入", onClick = onImportClick) }, ) { Column(Modifier.fillMaxWidth().verticalScroll(rememberScrollState())) { @@ -153,7 +165,25 @@ fun MemoryScreen( } // ---- 共享记忆提示(不写清楚用户会以为记忆串了)---- - if (space?.shared == true) { + if (worldMode) { + Box( + Modifier + .fillMaxWidth() + .padding(horizontal = 12.dp, vertical = 6.dp) + .clip(RoundedCornerShape(10.dp)) + .background(Color(0x14F29900)) + .padding(10.dp), + ) { + Text( + "这是这个世界观里所有人共同记得的 —— 绑定了它的智能体共用这一份。\n" + + "这里只供查看(改和删请从各自的智能体进去,那边才知道「我」是谁);" + + "每条都标了是谁写的。", + fontSize = 11.sp, + lineHeight = 16.sp, + color = Color(0xFF8A6100), + ) + } + } else if (space?.shared == true) { Row( Modifier .fillMaxWidth() @@ -210,7 +240,8 @@ fun MemoryScreen( ) } - // ---- 情绪 ---- + // ---- 情绪(世界观视角没有"自己的情绪",隐藏)---- + if (!worldMode) { SectionLabel("情绪") Column( Modifier @@ -242,6 +273,7 @@ fun MemoryScreen( ) { Text("保存情绪", fontSize = 13.sp) } } } + } // ---- 操作条 ---- SectionLabel("记忆(按时间排,最新的在下面)") @@ -249,8 +281,8 @@ fun MemoryScreen( Modifier.fillMaxWidth().padding(horizontal = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - if (!readingOwn) SmallAction("+ 加一条") { adding = true } - if (!readingOwn) { + if (!readingOwn && !worldMode) SmallAction("+ 加一条") { adding = true } + if (!readingOwn && !worldMode) { SmallAction(if (loading) "整理中…" else "AI 整理") { // ★ 先确认再调(复查报告 4.2.1):整理是**一次真的 LLM 调用**、 // 会改掉现有记忆,而且用户可能刚标好了「必须保留」—— diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt index 8e8851f..2558fb5 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt @@ -284,6 +284,11 @@ fun ResourcesScreen(vm: AppViewModel, onBack: () -> Unit) { ) } } + RowAction("记忆") { + // ★ 世界观的**共享记忆**("大家共同记得什么")—— + // 和从智能体进去看的是同一个空间、不同的视角 + vm.openWorldMemories(id) + } RowAction("导出") { vm.exportPackage(kind.id, id) { content, ext -> pendingExport = Triple(content, ext, "x") diff --git a/android/kernel/agent_api.py b/android/kernel/agent_api.py index f585493..af9f2f9 100644 --- a/android/kernel/agent_api.py +++ b/android/kernel/agent_api.py @@ -214,6 +214,38 @@ def _extract_json(text: str): # 记忆 # --------------------------------------------------------------------------- # +def _world_memories(handler, wid: str, err) -> bool: + """ + 一个世界观的共享记忆(只读快照)。 + + ★ 为什么世界观也要有这个入口:记忆挂在**空间**上,而空间是世界观定义的 + (`world:`)。从智能体进去看到的是"这个空间里的记忆", + 但从世界观进去问的是另一个问题 —— "这个世界里大家共同记得什么"。 + 有五个智能体共用同一个世界观时,后者才是你要看的那个视角。 + + ★ 只读:增删改仍然从智能体那边做。世界观视角没有"我", + 而共享空间的写入限权是**按 author 判的**(需求 3.6), + 这里没有一个"我"可以拿来判 —— 硬做只会做出一个权限含义不明的界面。 + """ + world = store.get_resource('worldviews', wid) + if not world: + err(404, '没有这个世界观') + return True + scope = agentdb.world_scope(wid) + items = agentdb.memory_list(scope) + names = {a.get('id'): (a.get('name') or '某人') for a in store.list_agents()} + for m in items: + m['authorName'] = names.get((m.get('author_agent') or '').strip(), '') + return _send_json_ok(handler, { + 'ok': True, + 'worldviewId': wid, + 'name': world.get('name') or '', + 'shared': True, + 'memories': items, + 'count': len(items), + }) + + def _memory_space(agent: dict) -> str: return agentdb.scope_of(agent.get('id') or '', agent.get('worldviewId') or '') @@ -670,6 +702,9 @@ def _resource_route(handler, seg: list, method: str, body, err): if len(seg) == 4 and seg[3] == 'asset' and method == 'POST': # 世界观的外观图(需求 3.6:沿用同一套四件套) return _set_asset(handler, 'worldviews', seg[2], body(), err) + if len(seg) == 4 and seg[3] == 'memories' and method == 'GET': + # 世界观的**共享记忆**(大家共同记得什么)—— 只读视角 + return _world_memories(handler, seg[2], err) if len(seg) == 4 and seg[3] == 'package' and method == 'GET': return _resource_export(handler, name, seg[2], err) if len(seg) == 4 and seg[3] == 'export' and method == 'GET': diff --git a/docs/screenshots/agent-memory.png b/docs/screenshots/agent-memory.png new file mode 100644 index 0000000..6f66a9e Binary files /dev/null and b/docs/screenshots/agent-memory.png differ diff --git a/scripts/audit-ui-entries.py b/scripts/audit-ui-entries.py new file mode 100644 index 0000000..c91f99c --- /dev/null +++ b/scripts/audit-ui-entries.py @@ -0,0 +1,146 @@ +"""审计:**做好了但没有入口的界面**。 + +## 为什么要有这个脚本 + +记忆管理界面做完、内核接口全通、探针 80 多项全绿 —— 但**没有任何地方能打开它**。 +是用户问"记忆管理在哪"才发现的。 + +这类漏**探针抓不到**(它测的是内核和数据,不测界面有没有入口), +**编译也抓不到**(Kotlin 允许一个 public 方法没人调用), +**截图也抓不到**(你只会去截你已经知道怎么进去的那几个页面)。 + +能抓到的只有"机器扫一遍:这个打开方法,除了定义之外还有人用吗"。 + +## 查什么 + + 1. `AppViewModel` 里所有 `fun openXxx` / `fun closeXxx` —— 谁在调? + 2. `Screen` 枚举的每个值 —— 有 `when` 分支吗?有地方 `= Screen.X` 跳过去吗? + 3. `mutableStateOf` 的 `*Open` / `*Id` 状态 —— 有地方把它设成"打开"吗? + +## 怎么判"没入口" + +- 打开类方法:**除定义和内部自查外**没有调用点 +- Screen 值:没有 `Screen.X ->` 分支(会编译失败,Compiler 已覆盖)**或者** + 没有 `= Screen.X` 赋值(这个编译不管,就是死页面) +- 状态:没有任何地方把它设成 true / 非空(只有读没有写) + +用法: + python scripts/audit-ui-entries.py # 有问题时退出码 1 +""" +import io +import os +import re +import sys +from collections import defaultdict + +try: + sys.stdout.reconfigure(encoding="utf-8", errors="replace") +except Exception: + pass + +HERE = os.path.dirname(os.path.abspath(__file__)) +UI = os.path.join( + HERE, "..", "android", "app", "src", "main", "java", "com", "doubao", "lynxclone", "ui", +) +VM = os.path.join(UI, "AppViewModel.kt") + +#: 这些**故意**不在这里判:它们是 ViewModel 内部用的,或者由别处(Activity/Service)触发 +ALLOW_NO_CALLER = { + # close 类方法经常只在自己的界面里用,正常 + "closeTimeouts", "closeTokenUsage", "closeMemories", "closeAgentEdit", +} + + +def read(path): + with io.open(path, encoding="utf-8") as fh: + return fh.read() + + +def main(): + files = {} + for name in os.listdir(UI): + if name.endswith(".kt"): + files[name] = read(os.path.join(UI, name)) + + vm_src = files.get("AppViewModel.kt", "") + problems = [] + + print("=" * 66) + print("1. 打开类方法:除了定义,有没有人调?") + print("=" * 66) + # 定义:fun openXxx( / fun closeXxx( + defined = re.findall(r"^\s*fun ((?:open|close|toggle)[A-Za-z0-9_]*)\s*\(", vm_src, re.M) + for fn in sorted(set(defined)): + if fn in ALLOW_NO_CALLER: + print(f" · {fn}(白名单:可能只在自身界面里用)") + continue + # 调用点:在**别的**文件里出现 fn(,或者在 AppViewModel 里出现第二次以上 + callers = [] + for name, src in files.items(): + n = len(re.findall(rf"\b{re.escape(fn)}\s*\(", src)) + if name == "AppViewModel.kt": + n -= 1 # 减掉定义那一处 + if n > 0: + callers.append(f"{name}×{n}") + if callers: + print(f" ✓ {fn} ← {', '.join(callers)}") + else: + print(f" ✗ {fn} **没有任何地方调用** —— 界面做好了但进不去") + problems.append(f"{fn} 没有入口") + + print() + print("=" * 66) + print("2. Screen 枚举:每个值都有人跳过去吗?") + print("=" * 66) + m = re.search(r"enum class Screen \{([^}]*)\}", vm_src) + if not m: + print(" !! 找不到 Screen 枚举") + return 1 + values = [v.strip() for v in m.group(1).split(",") if v.strip()] + for v in values: + # 跳过去的地方:= Screen.X(赋值),排除 when 分支和枚举定义 + jump = 0 + for name, src in files.items(): + jump += len(re.findall(rf"=\s*Screen\.{re.escape(v)}\b", src)) + branch = sum(len(re.findall(rf"Screen\.{re.escape(v)}\s*->", src)) for src in files.values()) + if jump == 0: + print(f" ✗ Screen.{v} 有 {branch} 个 when 分支,但**没有任何地方跳过去**") + problems.append(f"Screen.{v} 是死页面") + elif branch == 0: + print(f" ✗ Screen.{v} 有 {jump} 处跳转,但**没有 when 分支**(会渲染不出东西)") + problems.append(f"Screen.{v} 没有渲染分支") + else: + print(f" ✓ Screen.{v} ({jump} 处跳转 / {branch} 个分支)") + + print() + print("=" * 66) + print("3. 打开状态:有没有地方把它打开?") + print("=" * 66) + states = re.findall(r"var (\w*(?:Open|Id|Hit|Editing))\s+by\s+mutableStateOf", vm_src) + for st in sorted(set(states)): + # ★ 两种写法都要数,否则全是误报: + # ① 外部 `vm.xxx = true`(界面直接设) + # ② ViewModel **内部** `xxx = true`(openXxx() 里设)—— 最常见的那种 + external = sum(len(re.findall(rf"\.{re.escape(st)}\s*=", src)) for src in files.values()) + inner = len(re.findall(rf"^\s*{re.escape(st)}\s*=", vm_src, re.M)) + writes = external + inner + reads = sum(len(re.findall(rf"\bvm\.{re.escape(st)}\b", src)) for src in files.values()) + # `private set` 的状态只能内部写 —— 那正是第 ② 种 + if writes <= 0: + print(f" ✗ {st} 只被读 {reads} 次、**没有地方写** —— 这个界面永远打不开") + problems.append(f"{st} 永远打不开") + else: + print(f" ✓ {st} (写 {writes} 次:内部 {inner} / 外部 {external};读 {reads} 次)") + + print() + if problems: + print(f"❌ {len(problems)} 个问题:") + for p in problems: + print(" -", p) + return 1 + print("✅ 所有界面都有入口") + return 0 + + +if __name__ == "__main__": + sys.exit(main())