feat:抖音全链分发——采集落库三跳+ARTICLE executor 同代际闭环:
真机 11 轮迭代达成首次全链闭环(采集→落库→FILTERED→PREPARED→READY→ 门控→领取→图文机器→草稿回执→Confirmed,真库 DRAFT_SAVED 实锤)。 关键修复: ① 代际统一(真库实锤根因):三跳/领取共用任务库 run_control 代际, 服务 startGeneration 是另一命名空间,混用致 active() 全拒任务卡死; ② 采集分发同沙盒:beginRun 每次代际+1 且 interruptTasks 全 PAUSED, 采集/分发拆两个沙盒任务永远追不上代际——单沙盒单代际一次完成; ③ prepare 补齐 payloadHash(64 位 hex 策略门槛,空串必拒 PREPARED); ④ 旧 PAUSED 残留重采先 resumeTask 重绑代际(跨天热榜撞幂等键场景); ⑤ ARTICLE executor 路由(分发沙盒+抖音沙盒):草稿已核对→Confirmed / PREPARE 写入期失败→NotSubmitted / 其余→Unknown 进核对; ⑥ openArticleEditor 深层页分支:门控遗留处罚中心/全部服务页逐级 BACK 收拢;⚠️ 创作中心页含同款锚点但方向相反(要点+发布),判据排除; ⑦ openEntry 截屏限流退避重试(帧追赶末轮紧拍 errorCode=3 致解析 0 条)。 Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
@@ -796,8 +796,12 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
RunLogger.i(TAG, "M6 长跑:收到停止指令,当前轮结束后终止")
|
RunLogger.i(TAG, "M6 长跑:收到停止指令,当前轮结束后终止")
|
||||||
} else {
|
} else {
|
||||||
val loopHours = intent.getIntExtra("loopHours", 0)
|
val loopHours = intent.getIntExtra("loopHours", 0)
|
||||||
val accepted = startCrossDispatchSandbox(loopHours)
|
// article=true:不造视频任务,直接走协调器领取库中 READY 任务(如抖音 ARTICLE);
|
||||||
RunLogger.i(TAG, "协调器分发沙盒受理=$accepted(广播 ACTION_TEST_CROSS_DISPATCH loopHours=$loopHours)")
|
// accountKey:领取账号键(默认沙盒自造任务,抖音任务用 douyin-local)
|
||||||
|
val article = intent.getBooleanExtra("article", false)
|
||||||
|
val accountKey = intent.getStringExtra("accountKey") ?: "sandbox-dispatch"
|
||||||
|
val accepted = startCrossDispatchSandbox(loopHours, accountKey, article)
|
||||||
|
RunLogger.i(TAG, "协调器分发沙盒受理=$accepted(广播 ACTION_TEST_CROSS_DISPATCH loopHours=$loopHours article=$article accountKey=$accountKey)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
|
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
|
||||||
@@ -972,17 +976,27 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
* @param loopHours >0 = 混合长跑模式:循环执行单次沙盒直到预算耗尽(M6 验收硬门槛:
|
* @param loopHours >0 = 混合长跑模式:循环执行单次沙盒直到预算耗尽(M6 验收硬门槛:
|
||||||
* 混合连续运行 4 小时+跨日;休息期/额度门在循环内自然生效等待,广播 loopHours=0 可停)。
|
* 混合连续运行 4 小时+跨日;休息期/额度门在循环内自然生效等待,广播 loopHours=0 可停)。
|
||||||
*/
|
*/
|
||||||
fun startCrossDispatchSandbox(loopHours: Int = 0): Boolean = synchronized(stepLifecycleLock) {
|
fun startCrossDispatchSandbox(loopHours: Int = 0, accountKey: String = "sandbox-dispatch", article: Boolean = false): Boolean = synchronized(stepLifecycleLock) {
|
||||||
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
|
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
|
||||||
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
|
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
|
||||||
frontGuard.creditNavigating || !foregroundCoordinator.isIdle() || latestConfig.toutiao.autoPublish ||
|
frontGuard.creditNavigating || !foregroundCoordinator.isIdle() || latestConfig.toutiao.autoPublish ||
|
||||||
runCatching { videoDownloader.hasPendingDrafts() }.getOrDefault(true)) return@synchronized false
|
runCatching { videoDownloader.hasPendingDrafts() }.getOrDefault(true)) return@synchronized false
|
||||||
val fixture = java.io.File(getExternalFilesDir(null), "m5-fixture.mp4")
|
if (article) {
|
||||||
if (!fixture.exists() || fixture.length() <= 0) {
|
// ARTICLE 模式领取库中已有 READY 任务(如抖音采集落库的图文任务),不造视频任务;
|
||||||
RunLogger.w(TAG, "M6 分发沙盒:夹具缺失(adb push 到 ${fixture.absolutePath})")
|
// 图文写入依赖调试输入法(自绘无节点,ACTION_SET_TEXT 不可用——M4 定案)
|
||||||
return@synchronized false
|
val ime = android.provider.Settings.Secure.getString(contentResolver, "default_input_method").orEmpty()
|
||||||
|
if (!ime.startsWith("com.haorui.app/")) {
|
||||||
|
RunLogger.w(TAG, "M6 分发沙盒(ARTICLE):当前输入法非调试输入法($ime),请先 adb shell ime set com.haorui.app/.automation.ime.HaoRuiDebugIme")
|
||||||
|
return@synchronized false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val fixture = java.io.File(getExternalFilesDir(null), "m5-fixture.mp4")
|
||||||
|
if (!fixture.exists() || fixture.length() <= 0) {
|
||||||
|
RunLogger.w(TAG, "M6 分发沙盒:夹具缺失(adb push 到 ${fixture.absolutePath})")
|
||||||
|
return@synchronized false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
automationScope.launch { runCrossDispatchSandbox(fixture, loopHours) }
|
automationScope.launch { runCrossDispatchSandbox(null, loopHours, accountKey, article) }
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -991,9 +1005,15 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
private var marathonRemainingHours: Int = 0
|
private var marathonRemainingHours: Int = 0
|
||||||
|
|
||||||
/** 沙盒主体(IO 协程内执行;suspend,全部落库走挂起 API 无 runBlocking)。
|
/** 沙盒主体(IO 协程内执行;suspend,全部落库走挂起 API 无 runBlocking)。
|
||||||
* loopHours>0 时循环执行单次沙盒(每轮独立 try-catch,异常不终止长跑)。 */
|
* loopHours>0 时循环执行单次沙盒(每轮独立 try-catch,异常不终止长跑)。
|
||||||
private suspend fun runCrossDispatchSandbox(fixture: java.io.File, loopHours: Int = 0): Boolean {
|
* fixture=null 且 article=true 时为 ARTICLE 模式:不造任务,领库中 READY 图文任务执行。 */
|
||||||
if (loopHours <= 0) return runCrossDispatchOnce(fixture)
|
private suspend fun runCrossDispatchSandbox(
|
||||||
|
fixture: java.io.File?,
|
||||||
|
loopHours: Int = 0,
|
||||||
|
accountKey: String = "sandbox-dispatch",
|
||||||
|
article: Boolean = false,
|
||||||
|
): Boolean {
|
||||||
|
if (loopHours <= 0) return runCrossDispatchOnce(fixture, accountKey = accountKey, article = article)
|
||||||
// ── 混合长跑模式 ──────────────────────────────────────
|
// ── 混合长跑模式 ──────────────────────────────────────
|
||||||
marathonRemainingHours = loopHours
|
marathonRemainingHours = loopHours
|
||||||
val deadlineMs = android.os.SystemClock.elapsedRealtime() + loopHours * 3_600_000L
|
val deadlineMs = android.os.SystemClock.elapsedRealtime() + loopHours * 3_600_000L
|
||||||
@@ -1011,7 +1031,7 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
RunLogger.i(TAG, "M6 长跑第 $round 轮开始(剩余 ${marathonRemainingHours}h)")
|
RunLogger.i(TAG, "M6 长跑第 $round 轮开始(剩余 ${marathonRemainingHours}h)")
|
||||||
val roundStart = android.os.SystemClock.elapsedRealtime()
|
val roundStart = android.os.SystemClock.elapsedRealtime()
|
||||||
val ok = try {
|
val ok = try {
|
||||||
runCrossDispatchOnce(fixture, manageSession = false)
|
runCrossDispatchOnce(fixture, manageSession = false, accountKey = accountKey, article = article)
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
RunLogger.e(TAG, "M6 长跑第 $round 轮异常(不终止长跑): ${t.javaClass.simpleName}:${t.message}", t)
|
RunLogger.e(TAG, "M6 长跑第 $round 轮异常(不终止长跑): ${t.javaClass.simpleName}:${t.message}", t)
|
||||||
false
|
false
|
||||||
@@ -1037,8 +1057,14 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 单次沙盒(长跑循环体复用;manageSession=false 时不做会话开关——长跑统一管理)。 */
|
/** 单次沙盒(长跑循环体复用;manageSession=false 时不做会话开关——长跑统一管理)。
|
||||||
private suspend fun runCrossDispatchOnce(fixture: java.io.File, manageSession: Boolean = true): Boolean {
|
* article=true:不造视频任务,协调器直接领取库中 READY 任务(ARTICLE 走图文机器,VIDEO 走视频桥)。 */
|
||||||
|
private suspend fun runCrossDispatchOnce(
|
||||||
|
fixture: java.io.File?,
|
||||||
|
manageSession: Boolean = true,
|
||||||
|
accountKey: String = "sandbox-dispatch",
|
||||||
|
article: Boolean = false,
|
||||||
|
): Boolean {
|
||||||
try {
|
try {
|
||||||
// 沙盒需要运行代际——跨平台会话默认关闭(新模块默认关闭),临时开启(内存态,
|
// 沙盒需要运行代际——跨平台会话默认关闭(新模块默认关闭),临时开启(内存态,
|
||||||
// 不改持久配置;currentGeneration 要求 enabled && wanted,configure+start 双开)。
|
// 不改持久配置;currentGeneration 要求 enabled && wanted,configure+start 双开)。
|
||||||
@@ -1059,6 +1085,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
opened
|
opened
|
||||||
}
|
}
|
||||||
val taskStore = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
val taskStore = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
||||||
|
// ── ① ARTICLE 模式:不造视频任务,直接进门控+领取(库中已有 READY 图文任务)──
|
||||||
|
if (!article) {
|
||||||
// ── ① 管线加工成品要素(指纹/媒体路径/许可,满足 preparationRejection)──
|
// ── ① 管线加工成品要素(指纹/媒体路径/许可,满足 preparationRejection)──
|
||||||
val provider = com.haorui.app.crossplatform.media.SourceMediaProvider(this) { msg ->
|
val provider = com.haorui.app.crossplatform.media.SourceMediaProvider(this) { msg ->
|
||||||
RunLogger.i(TAG, "M6-Provider: $msg")
|
RunLogger.i(TAG, "M6-Provider: $msg")
|
||||||
@@ -1125,7 +1153,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
com.haorui.app.crossplatform.model.CrossTaskState.READY,
|
com.haorui.app.crossplatform.model.CrossTaskState.READY,
|
||||||
generation, "分发沙盒·就绪",
|
generation, "分发沙盒·就绪",
|
||||||
)
|
)
|
||||||
// ── ③ 门控 + 协调器 + 桥接执行(VIDEO→旧发布器草稿车道)──
|
} // end if(!article) 造任务块
|
||||||
|
// ── ③ 门控 + 协调器 + 执行(按 contentKind 路由:ARTICLE→图文机器 / VIDEO→视频桥)──
|
||||||
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
||||||
quotaManager, latestConfig.credit.threshold,
|
quotaManager, latestConfig.credit.threshold,
|
||||||
{ threshold ->
|
{ threshold ->
|
||||||
@@ -1136,6 +1165,36 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
RunLogger.i(TAG, "M6-Coordinator: $msg")
|
RunLogger.i(TAG, "M6-Coordinator: $msg")
|
||||||
}
|
}
|
||||||
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
||||||
|
when (t.contentKind) {
|
||||||
|
com.haorui.app.crossplatform.model.CrossContentKind.ARTICLE -> {
|
||||||
|
// 图文机器(M4 已真机验收全链):导航→写入→回读→草稿回执
|
||||||
|
val port = com.haorui.app.crossplatform.publish.ToutiaoArticlePort(this@HaoRuiAccessibilityService)
|
||||||
|
if (!port.openArticleEditor()) {
|
||||||
|
return@Executor com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("未进入文章编辑器")
|
||||||
|
}
|
||||||
|
val machine = com.haorui.app.crossplatform.publish.ArticlePublishMachine(port) { msg ->
|
||||||
|
RunLogger.i(TAG, "M6-Article: $msg")
|
||||||
|
}
|
||||||
|
val result = machine.run(t.title, t.bodyText)
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"M6-Article 结果: outcome=${result.outcome} phase=${result.phase} " +
|
||||||
|
"reason=${result.reason} exited=${result.exitedSafely}",
|
||||||
|
)
|
||||||
|
when {
|
||||||
|
// 草稿回执明确确认(顶栏「草稿已保存」+字数/锚点回读全过)
|
||||||
|
result.outcome == "草稿已核对" ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Confirmed("article-draft:${t.title.take(20)}")
|
||||||
|
// 写入失败/未进编辑器等确定性失败(未点提交,草稿未生成)——释放预占
|
||||||
|
result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.PREPARE ||
|
||||||
|
result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.WRITE_TITLE && result.outcome == "失败" ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("图文写入失败:${result.reason}")
|
||||||
|
// 暂停核对/回读不吻合/回执未见——编辑器可能已自动保存,结果未知进人工核对
|
||||||
|
else ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Unknown("图文待核对:${result.reason}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
com.haorui.app.crossplatform.model.CrossContentKind.VIDEO -> {
|
||||||
val bridge = com.haorui.app.crossplatform.media.VideoTaskBridge({ tt, uri, auto, decl ->
|
val bridge = com.haorui.app.crossplatform.media.VideoTaskBridge({ tt, uri, auto, decl ->
|
||||||
publisher.submit(tt, uri, autoPublish = auto, declaration = decl)
|
publisher.submit(tt, uri, autoPublish = auto, declaration = decl)
|
||||||
}) { msg -> RunLogger.i(TAG, "M6-Bridge: $msg") }
|
}) { msg -> RunLogger.i(TAG, "M6-Bridge: $msg") }
|
||||||
@@ -1171,13 +1230,15 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
is com.haorui.app.crossplatform.media.VideoTaskBridge.Result.Rejected ->
|
is com.haorui.app.crossplatform.media.VideoTaskBridge.Result.Rejected ->
|
||||||
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted(bridged.reason)
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted(bridged.reason)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} // end when(contentKind)
|
||||||
}
|
}
|
||||||
scheduler.startLaneOnly(LaneScheduler.Lane.PUBLISH)
|
scheduler.startLaneOnly(LaneScheduler.Lane.PUBLISH)
|
||||||
// dispatchOnce 在本协程(automationScope=IO)直接执行——绝不 runBlocking:
|
// dispatchOnce 在本协程(automationScope=IO)直接执行——绝不 runBlocking:
|
||||||
// 本函数可能从广播接收器(主线程)启动,runBlocking 会堵死主线程消息队列,
|
// 本函数可能从广播接收器(主线程)启动,runBlocking 会堵死主线程消息队列,
|
||||||
// 门控信用读的 withContext(Dispatchers.Main) 截屏永远排不上(2026-11-16
|
// 门控信用读的 withContext(Dispatchers.Main) 截屏永远排不上(2026-11-16
|
||||||
// 第 3~6 轮卡死实锤:卡点恒在 launchApp 后第一处 Main 调度)。
|
// 第 3~6 轮卡死实锤:卡点恒在 launchApp 后第一处 Main 调度)。
|
||||||
val dispatch = coordinator.dispatchOnce("sandbox-dispatch", generation, executor)
|
val dispatch = coordinator.dispatchOnce(accountKey, generation, executor)
|
||||||
RunLogger.i(TAG, "M6 分发沙盒结果:$dispatch")
|
RunLogger.i(TAG, "M6 分发沙盒结果:$dispatch")
|
||||||
return dispatch is com.haorui.app.crossplatform.publish.PublishCoordinator.Outcome.Dispatched
|
return dispatch is com.haorui.app.crossplatform.publish.PublishCoordinator.Outcome.Dispatched
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
@@ -1281,6 +1342,25 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
// 落库:采集成功后 enqueue 到任务库(仿微博模式)
|
// 落库:采集成功后 enqueue 到任务库(仿微博模式)
|
||||||
if (result.outcome == "已观察") {
|
if (result.outcome == "已观察") {
|
||||||
val store = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
val store = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
||||||
|
// ⚠️ 代际统一(2026-11-17 真库实锤):enqueue 校验与三跳、协调器领取
|
||||||
|
// 共用任务库 run_control 代际(beginRun);服务 startGeneration 是另一
|
||||||
|
// 命名空间,混用会让 active() 校验全失败、任务卡 DISCOVERED。
|
||||||
|
// 沙盒默认不启调度器,会话未开 → 临时开启并轮询等 beginRun 落库。
|
||||||
|
val gen: Long = currentCrossRunGeneration() ?: run {
|
||||||
|
crossRunSession?.configure(true)
|
||||||
|
crossRunSession?.start()
|
||||||
|
var opened: Long? = null
|
||||||
|
for (i in 1..15) {
|
||||||
|
kotlinx.coroutines.delay(1_000)
|
||||||
|
opened = currentCrossRunGeneration()
|
||||||
|
if (opened != null) break
|
||||||
|
}
|
||||||
|
if (opened == null) {
|
||||||
|
RunLogger.w(TAG, "抖音采集落库:会话临时开启后仍无代际(beginRun 未完成),放弃落库")
|
||||||
|
return@let
|
||||||
|
}
|
||||||
|
opened
|
||||||
|
}
|
||||||
val title = obs.hotEntry?.title ?: "抖音热榜第${obs.hotEntry?.rank ?: entryIndex}条"
|
val title = obs.hotEntry?.title ?: "抖音热榜第${obs.hotEntry?.rank ?: entryIndex}条"
|
||||||
val identity = "douyin-rank${obs.hotEntry?.rank ?: entryIndex}-${title.hashCode()}"
|
val identity = "douyin-rank${obs.hotEntry?.rank ?: entryIndex}-${title.hashCode()}"
|
||||||
// 图文发布:用热榜标题生成模板正文(AI 创作链后续接入)
|
// 图文发布:用热榜标题生成模板正文(AI 创作链后续接入)
|
||||||
@@ -1320,23 +1400,81 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
|||||||
payloadHash = java.security.MessageDigest.getInstance("SHA-256")
|
payloadHash = java.security.MessageDigest.getInstance("SHA-256")
|
||||||
.digest((title + bodyText).toByteArray())
|
.digest((title + bodyText).toByteArray())
|
||||||
.joinToString("") { "%02x".format(it) },
|
.joinToString("") { "%02x".format(it) },
|
||||||
runGeneration = startGeneration.toLong(),
|
runGeneration = gen,
|
||||||
)
|
)
|
||||||
val enqueued = kotlinx.coroutines.runBlocking {
|
val enqueued = kotlinx.coroutines.runBlocking {
|
||||||
runCatching { store.enqueue(task) }.getOrDefault(false)
|
runCatching { store.enqueue(task) }.getOrDefault(false)
|
||||||
}
|
}
|
||||||
RunLogger.i(TAG, "抖音采集落库: id=$identity 落库=$enqueued")
|
RunLogger.i(TAG, "抖音采集落库: id=$identity 落库=$enqueued gen=$gen")
|
||||||
// 状态推进:DISCOVERED→FILTERED→PREPARED→READY(走标准发布流程)
|
// 状态推进:DISCOVERED→FILTERED→PREPARED→READY(走标准发布流程)
|
||||||
// ⚠️ 任务已存在(幂等)时也要推进状态(r35 实锤:重复采集同一条目不推进)
|
// ⚠️ 任务已存在(幂等)时也要推进状态(r35 实锤:重复采集同一条目不推进);
|
||||||
|
// ⚠️ 旧代际残留(PAUSED,resumeState=DISCOVERED)先 resume 重绑代际再推进
|
||||||
|
// (2026-11-17 真机实锤:跨天热榜复现撞幂等键,gen=0≠当前代际三跳全拒)
|
||||||
|
var readyId: String? = null
|
||||||
if (enqueued || store.find(identity) != null) {
|
if (enqueued || store.find(identity) != null) {
|
||||||
val gen = startGeneration.toLong()
|
|
||||||
kotlinx.coroutines.runBlocking {
|
kotlinx.coroutines.runBlocking {
|
||||||
|
if (!enqueued) {
|
||||||
|
val resumed = store.resumeTask(identity, gen)
|
||||||
|
RunLogger.i(TAG, "抖音旧任务重绑代际: resume=$resumed gen=$gen")
|
||||||
|
}
|
||||||
val t1 = store.transition(identity, com.haorui.app.crossplatform.model.CrossTaskState.DISCOVERED, com.haorui.app.crossplatform.model.CrossTaskState.FILTERED, gen, "抖音热榜采集")
|
val t1 = store.transition(identity, com.haorui.app.crossplatform.model.CrossTaskState.DISCOVERED, com.haorui.app.crossplatform.model.CrossTaskState.FILTERED, gen, "抖音热榜采集")
|
||||||
val t2 = store.prepare(identity, gen, bodyText, "", task.evidenceJson, "", "")
|
// prepare 必须带齐 rightsRef/payloadHash(策略检查 PREPARED 门槛:
|
||||||
|
// payloadHash 须 64 位 hex,rightsRef 空串对 ARTICLE 不拦但指纹必查)
|
||||||
|
val t2 = store.prepare(identity, gen, bodyText, "", task.evidenceJson, "douyin-hotlist", task.payloadHash)
|
||||||
val t3 = store.transition(identity, com.haorui.app.crossplatform.model.CrossTaskState.PREPARED, com.haorui.app.crossplatform.model.CrossTaskState.READY, gen, "图文已生成")
|
val t3 = store.transition(identity, com.haorui.app.crossplatform.model.CrossTaskState.PREPARED, com.haorui.app.crossplatform.model.CrossTaskState.READY, gen, "图文已生成")
|
||||||
RunLogger.i(TAG, "抖音任务状态推进: FILTERED=$t1 PREPARED=$t2 READY=$t3")
|
RunLogger.i(TAG, "抖音任务状态推进: FILTERED=$t1 PREPARED=$t2 READY=$t3 gen=$gen")
|
||||||
|
// 以库内实际状态为准:三跳成功或本代际已 READY(会话复用重采)均可分发
|
||||||
|
if (t3 || store.find(identity)?.state == com.haorui.app.crossplatform.model.CrossTaskState.READY) readyId = identity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ── 同代际分发:会话已开启(本沙盒开启),协调器直接领取执行 ──
|
||||||
|
// ⚠️ 不能拆成两个沙盒:beginRun/pauseRun 每次代际+1 并把 READY 全部
|
||||||
|
// PAUSED(interruptTasks),采集与分发分开跑任务永远追不上代际。
|
||||||
|
if (readyId != null) {
|
||||||
|
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
||||||
|
quotaManager, latestConfig.credit.threshold,
|
||||||
|
{ threshold ->
|
||||||
|
com.haorui.app.ocr.CreditGateRunner.evaluate(this@HaoRuiAccessibilityService, threshold)
|
||||||
|
},
|
||||||
|
) { msg -> RunLogger.i(TAG, "DY-Gate: $msg") }
|
||||||
|
val coordinator = com.haorui.app.crossplatform.publish.PublishCoordinator(store, gate) { msg ->
|
||||||
|
RunLogger.i(TAG, "DY-Coordinator: $msg")
|
||||||
|
}
|
||||||
|
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
||||||
|
when (t.contentKind) {
|
||||||
|
com.haorui.app.crossplatform.model.CrossContentKind.ARTICLE -> {
|
||||||
|
val port = com.haorui.app.crossplatform.publish.ToutiaoArticlePort(this@HaoRuiAccessibilityService)
|
||||||
|
if (!port.openArticleEditor()) {
|
||||||
|
return@Executor com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("未进入文章编辑器")
|
||||||
|
}
|
||||||
|
val machine = com.haorui.app.crossplatform.publish.ArticlePublishMachine(port) { msg ->
|
||||||
|
RunLogger.i(TAG, "DY-Article: $msg")
|
||||||
|
}
|
||||||
|
val result = machine.run(t.title, t.bodyText)
|
||||||
|
RunLogger.i(
|
||||||
|
TAG,
|
||||||
|
"DY-Article 结果: outcome=${result.outcome} phase=${result.phase} " +
|
||||||
|
"reason=${result.reason} exited=${result.exitedSafely}",
|
||||||
|
)
|
||||||
|
when {
|
||||||
|
result.outcome == "草稿已核对" ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Confirmed("article-draft:${t.title.take(20)}")
|
||||||
|
// PREPARE/写入期失败=编辑器未动或草稿未成形,确定性未提交
|
||||||
|
result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.PREPARE ||
|
||||||
|
(result.phase == com.haorui.app.crossplatform.publish.ArticlePublishMachine.Phase.WRITE_TITLE && result.outcome == "失败") ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("图文写入失败:${result.reason}")
|
||||||
|
// 暂停核对/回读不吻合/回执未见——可能已自动保存,结果未知进核对
|
||||||
|
else ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Unknown("图文待核对:${result.reason}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else ->
|
||||||
|
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("沙盒仅支持 ARTICLE,任务 ${t.id} kind=${t.contentKind}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val dispatch = coordinator.dispatchOnce("douyin-local", gen, executor)
|
||||||
|
RunLogger.i(TAG, "抖音采集分发结果:$dispatch")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,25 @@ class ToutiaoArticlePort(
|
|||||||
kotlinx.coroutines.runBlocking { service.gestures.back() }
|
kotlinx.coroutines.runBlocking { service.gestures.back() }
|
||||||
Thread.sleep(1_500); continue
|
Thread.sleep(1_500); continue
|
||||||
}
|
}
|
||||||
|
// ⓪′ 信用分门控遗留深层页(处罚中心/全部服务等)→ BACK 收拢回首页。
|
||||||
|
// 2026-11-17 真机两轮实锤:
|
||||||
|
// - 处罚中心 BACK 一跳到「全部服务」(有作品管理锚点但无顶部「发布」,
|
||||||
|
// 判据③不命中)→ 锚点须覆盖门控导航链沿途页面;
|
||||||
|
// - ⚠️ 创作中心页同样含「作品管理/创作工具/收益提现」字样但方向相反
|
||||||
|
// (要点「+发布」不是 BACK)——这些词不能进本判据;判据锚点限定
|
||||||
|
// 处罚中心专属词 + 「全部服务」页专属标题,且无首页底栏。
|
||||||
|
val deepAnchor = lines.any {
|
||||||
|
it.text.contains("处罚记录") || it.text.contains("账号处罚中心") ||
|
||||||
|
it.text.contains("全部服务") || it.text.contains("信用分") ||
|
||||||
|
it.text.contains("治理公告")
|
||||||
|
} && !lines.any { it.text.trim() == "首页" && (it.boundingBox?.top ?: 0) > height * 0.85 } &&
|
||||||
|
// 排除创作中心:有顶部「发布」或「作品管理+数据助手」组合走判据③
|
||||||
|
!lines.any { it.text.contains("发布") && (it.boundingBox?.top ?: Int.MAX_VALUE) < height * 0.12 }
|
||||||
|
if (deepAnchor) {
|
||||||
|
log("导航:信用分门控遗留深层页,BACK 回首页")
|
||||||
|
kotlinx.coroutines.runBlocking { service.gestures.back() }
|
||||||
|
Thread.sleep(1_500); continue
|
||||||
|
}
|
||||||
// ① 已在编辑器空稿
|
// ① 已在编辑器空稿
|
||||||
if (editorMarkers(lines)) return true
|
if (editorMarkers(lines)) return true
|
||||||
// ② 发布面板(微头条撰写页)→「文章」Tab(底部)。
|
// ② 发布面板(微头条撰写页)→「文章」Tab(底部)。
|
||||||
|
|||||||
@@ -373,10 +373,21 @@ internal class DouyinDevicePort(
|
|||||||
// ⚠️ r31 实锤:collectOne 和 openEntry 读不同帧导致 entry 不一致——
|
// ⚠️ r31 实锤:collectOne 和 openEntry 读不同帧导致 entry 不一致——
|
||||||
// collectOne 挑的 entry[0] 到 openEntry 时序号变了。
|
// collectOne 挑的 entry[0] 到 openEntry 时序号变了。
|
||||||
// 修法:openEntry 自己重读解析,按**标题碎片**匹配 OCR 行块(不依赖 index)。
|
// 修法:openEntry 自己重读解析,按**标题碎片**匹配 OCR 行块(不依赖 index)。
|
||||||
val lines = ocrCurrentScreen()
|
// ⚠️ 2026-11-17 真机:帧追赶末轮截屏后立即再拍命中 takeScreenshot 限流
|
||||||
val parsed = DouyinHotListParser.parse(lines)
|
// (errorCode=3)→ 重读解析 0 条直接失败。先退避再拍,空解析重试一次。
|
||||||
|
val parsed: List<com.haorui.app.crossplatform.source.douyin.DouyinHotEntry> = buildList {
|
||||||
|
for (attempt in 1..2) {
|
||||||
|
Thread.sleep(1_300) // 截屏限流退避(系统配额约 1s+)
|
||||||
|
val lines = ocrCurrentScreen()
|
||||||
|
val p = DouyinHotListParser.parse(lines)
|
||||||
|
if (p.isNotEmpty()) {
|
||||||
|
addAll(p); break
|
||||||
|
}
|
||||||
|
log("openEntry 重读解析 0 条(第 $attempt 次)")
|
||||||
|
}
|
||||||
|
}
|
||||||
if (parsed.isEmpty()) {
|
if (parsed.isEmpty()) {
|
||||||
log("openEntry 重读解析 0 条")
|
log("openEntry 重读两次均 0 条,放弃")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 优先用 index 对应的 entry,找不到则用第 0 条
|
// 优先用 index 对应的 entry,找不到则用第 0 条
|
||||||
|
|||||||
Reference in New Issue
Block a user