feat:验证②模型标题生成——composeVerif调试入口端到端实跑:

This commit is contained in:
2026-11-15 16:47:29 +08:00
parent e3b4bf8dd7
commit 4dc5ae7235
4 changed files with 114 additions and 4 deletions
@@ -636,17 +636,23 @@ class HaoRuiAccessibilityService : AccessibilityService() {
val accepted = startZhihuCollectSandbox(index)
RunLogger.i(TAG, "知乎采集沙盒受理=$accepted(广播 ACTION_TEST_ZHIHU cardIndex=$index)")
}
// 微博调试沙盒(debug APK;collectOnlyList=只拉清单;topics=分号分隔词条标题则按勾选采集落库)
// 微博调试沙盒(debug APK;collectOnlyList=只拉清单;topics=分号分隔词条标题则按勾选采集落库;
// composeVerify=1 走 M4 创作链验证:采集→事实包→模型标题候选(日志输出,不落库不发布))
"com.haorui.app.ACTION_TEST_WEIBO" -> {
val categoryId = intent.getStringExtra("categoryId") ?: "hot"
val entryIndex = intent.getStringExtra("entryIndex")?.toIntOrNull() ?: 0
val collectOnlyList = intent.getBooleanExtra("collectOnlyList", false)
val composeVerify = intent.getBooleanExtra("composeVerify", false)
val topics = intent.getStringExtra("topics")?.split(';', ';')?.map { it.trim() }?.filter { it.isNotEmpty() }.orEmpty()
val accepted = startWeiboTopicCollect(categoryId, topics)
val accepted = if (composeVerify) {
startWeiboComposeVerify(categoryId, topics)
} else {
startWeiboTopicCollect(categoryId, topics)
}
RunLogger.i(
TAG,
"微博调试沙盒受理=$accepted(广播 ACTION_TEST_WEIBO category=$categoryId " +
"entry=$entryIndex collectOnlyList=$collectOnlyList topics=${topics.size})",
"entry=$entryIndex collectOnlyList=$collectOnlyList composeVerify=$composeVerify topics=${topics.size})",
)
}
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
@@ -774,6 +780,96 @@ class HaoRuiAccessibilityService : AccessibilityService() {
true
}
/**
* M4 创作链真机验证(debug APK):采集单条 → OCR 全文 → 事实包 → 模型标题候选。
* 只读+模型调用,不落库、不发布;结果全走日志(标题候选逐条输出)。
*/
fun startWeiboComposeVerify(categoryId: String, topics: List<String>): Boolean =
synchronized(stepLifecycleLock) {
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
frontGuard.creditNavigating || !foregroundCoordinator.isIdle()) return@synchronized false
val category = com.haorui.app.crossplatform.source.weibo.WeiboHotCategories.ALL
.firstOrNull { it.id == categoryId } ?: return@synchronized false
if (_weiboCollectState.value.running) return@synchronized false
_weiboCollectState.value = WeiboCollectUiState(running = true, categoryLabel = category.tabLabel)
launchForegroundTask {
val ticket = foregroundCoordinator.tryEnterLegacy("WEIBO-COMPOSE") ?: run {
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = "前台被其他任务占用,稍后重试")
return@launchForegroundTask
}
try {
val port = com.haorui.app.crossplatform.source.weibo.WeiboDevicePort(this@HaoRuiAccessibilityService)
val machine = com.haorui.app.crossplatform.source.weibo.WeiboHotListCollector(port) { SystemClock.elapsedRealtime() }
machine.runGeneration = startGeneration.toLong()
RunLogger.i(TAG, "M4 创作链验证开始:类目「${category.tabLabel}」")
val list = machine.collectCategoryEntries(category)
if (list.outcome != "已取得") {
RunLogger.w(TAG, "M4 创作链验证:清单失败 ${list.reason}")
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = list.reason)
return@launchForegroundTask
}
val targetIndex = if (topics.isEmpty()) 1 else {
list.entries.indexOfFirst { e -> topics.any { it == e.title } }
}
if (targetIndex < 0) {
RunLogger.w(TAG, "M4 创作链验证:勾选词条不在榜单中")
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = "勾选词条不在榜单中")
return@launchForegroundTask
}
val entry = list.entries[targetIndex]
RunLogger.i(TAG, "M4 创作链验证:采集词条「${entry.title}」")
val result = machine.collectOne(category, targetIndex)
val obs = result.observation
if (obs == null) {
RunLogger.w(TAG, "M4 创作链验证:采集未完成 phase=${result.phase} ${result.reason}")
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = result.reason)
return@launchForegroundTask
}
// 事实包:OCR 全文为主路线(真机取证:浏览器 WebView 无 DOM 节点)
// 采集的 readPostOcrLines 已在 collectOne 里跑过一屏;正文全文需要详情页逐屏 OCR——
// 本验证版用已采集行 + 二次全屏 OCR 补充正文材料
val detailOcr = port.readPostOcrLines()
val allLines = detailOcr + obs.unknowns
val builder = com.haorui.app.crossplatform.compose.EvidenceBuilder(
logger = { msg -> RunLogger.i(TAG, "M4-Evidence: $msg") },
)
val evidence = builder.build(entry.title, obs.sourceUrl.orEmpty(), detailOcr, SystemClock.elapsedRealtime())
if (evidence == null) {
RunLogger.w(TAG, "M4 创作链验证:事实包构建失败 ${builder.failureReason}")
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = builder.failureReason)
return@launchForegroundTask
}
RunLogger.i(TAG, "M4 创作链验证:事实包 ${evidence.sourceRoute} ${evidence.sourceText.length} 字")
// 模型标题候选(AiConfig 从配置读)
val aiConfig = latestConfig.ai
val composer = com.haorui.app.crossplatform.compose.ArticleComposer(aiConfig) { msg ->
RunLogger.i(TAG, "M4-Composer: $msg")
}
val titles = composer.composeTitles(evidence)
if (titles == null) {
RunLogger.w(TAG, "M4 创作链验证:标题生成失败 ${composer.failureReason}")
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = composer.failureReason)
return@launchForegroundTask
}
RunLogger.i(TAG, "M4 创作链验证成功:选中「${titles.selected}」")
titles.candidates.forEachIndexed { i, c ->
RunLogger.i(TAG, "M4 标题候选[$i]: $c")
}
_weiboCollectState.value = WeiboCollectUiState(
done = true,
collected = listOf(titles.selected to (obs.sourceUrl.orEmpty())),
)
} catch (t: Throwable) {
RunLogger.e(TAG, "M4 创作链验证异常: ${t.javaClass.simpleName}:${t.message}", t)
_weiboCollectState.value = WeiboCollectUiState(done = true, reason = "异常: ${t.javaClass.simpleName}")
} finally {
foregroundCoordinator.release(ticket)
}
}
true
}
/** 微博采集执行状态(UI 直读;替代早期"服务日志中转"的过渡实现)。 */
data class WeiboCollectUiState(
val running: Boolean = false,