@web-auto/webauto 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/apps/desktop-console/default-settings.json +1 -0
  2. package/apps/desktop-console/dist/main/index.mjs +1618 -0
  3. package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
  4. package/apps/desktop-console/dist/renderer/index.js +3063 -0
  5. package/apps/desktop-console/entry/ui-console.mjs +299 -0
  6. package/apps/webauto/entry/account.mjs +356 -0
  7. package/apps/webauto/entry/lib/account-detect.mjs +160 -0
  8. package/apps/webauto/entry/lib/account-store.mjs +587 -0
  9. package/apps/webauto/entry/lib/profilepool.mjs +1 -1
  10. package/apps/webauto/entry/xhs-install.mjs +27 -3
  11. package/apps/webauto/entry/xhs-status.mjs +152 -0
  12. package/apps/webauto/entry/xhs-unified.mjs +595 -17
  13. package/bin/webauto.mjs +263 -15
  14. package/dist/apps/webauto/server.js +66 -0
  15. package/dist/modules/camo-backend/src/index.js +575 -0
  16. package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
  17. package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
  18. package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
  19. package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
  20. package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
  21. package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
  22. package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
  23. package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
  24. package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
  25. package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
  26. package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
  27. package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
  28. package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
  29. package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
  30. package/dist/modules/container-registry/src/index.js +184 -0
  31. package/dist/modules/logging/src/index.js +92 -0
  32. package/dist/modules/operations/src/builtin.js +27 -0
  33. package/dist/modules/operations/src/container-binding.js +75 -0
  34. package/dist/modules/operations/src/executor.js +146 -0
  35. package/dist/modules/operations/src/operations/click.js +167 -0
  36. package/dist/modules/operations/src/operations/extract.js +204 -0
  37. package/dist/modules/operations/src/operations/find-child.js +17 -0
  38. package/dist/modules/operations/src/operations/highlight.js +138 -0
  39. package/dist/modules/operations/src/operations/key.js +61 -0
  40. package/dist/modules/operations/src/operations/navigate.js +148 -0
  41. package/dist/modules/operations/src/operations/scroll.js +126 -0
  42. package/dist/modules/operations/src/operations/type.js +190 -0
  43. package/dist/modules/operations/src/queue.js +100 -0
  44. package/dist/modules/operations/src/registry.js +11 -0
  45. package/dist/modules/operations/src/system/mouse.js +33 -0
  46. package/dist/modules/state/src/atomic-json.js +33 -0
  47. package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
  48. package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
  49. package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
  50. package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
  51. package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
  52. package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
  53. package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
  54. package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
  55. package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
  56. package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
  57. package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
  58. package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
  59. package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
  60. package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
  61. package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
  62. package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
  63. package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
  64. package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
  65. package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
  66. package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
  67. package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
  68. package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
  69. package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
  70. package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
  71. package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
  72. package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
  73. package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
  74. package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
  75. package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
  76. package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
  77. package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
  78. package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
  79. package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
  80. package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
  81. package/dist/modules/workflow/blocks/SaveFile.js +54 -0
  82. package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
  83. package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
  84. package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
  85. package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
  86. package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
  87. package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
  88. package/dist/modules/workflow/blocks/WaitStable.js +74 -0
  89. package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
  90. package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
  91. package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
  92. package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
  93. package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
  94. package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
  95. package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
  96. package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
  97. package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
  98. package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
  99. package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
  100. package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
  101. package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
  102. package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
  103. package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
  104. package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
  105. package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
  106. package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
  107. package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
  108. package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
  109. package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
  110. package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
  111. package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
  112. package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
  113. package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
  114. package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
  115. package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
  116. package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
  117. package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
  118. package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
  119. package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
  120. package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
  121. package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
  122. package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
  123. package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
  124. package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
  125. package/dist/modules/workflow/config/workflowRegistry.js +32 -0
  126. package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
  127. package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
  128. package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
  129. package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
  130. package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
  131. package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
  132. package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
  133. package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
  134. package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
  135. package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
  136. package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
  137. package/dist/modules/workflow/src/context.js +70 -0
  138. package/dist/modules/workflow/src/index.js +5 -0
  139. package/dist/modules/workflow/src/orchestrator.js +230 -0
  140. package/dist/modules/workflow/src/runner.js +55 -0
  141. package/dist/modules/workflow/src/runtime.js +70 -0
  142. package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
  143. package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
  144. package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
  145. package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
  146. package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
  147. package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
  148. package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
  149. package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
  150. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
  151. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
  152. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
  153. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
  154. package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
  155. package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
  156. package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
  157. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
  158. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
  159. package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
  160. package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
  161. package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
  162. package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
  163. package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
  164. package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
  165. package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
  166. package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
  167. package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
  168. package/dist/modules/xiaohongshu/app/src/index.js +9 -0
  169. package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
  170. package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
  171. package/dist/services/controller/src/controller.js +1476 -0
  172. package/dist/services/controller/src/index.js +2 -0
  173. package/dist/services/controller/src/payload-normalizer.js +129 -0
  174. package/dist/services/shared/heartbeat.js +120 -0
  175. package/dist/services/shared/lib/errorHandler.js +2 -0
  176. package/dist/services/shared/serviceProcessLogger.js +139 -0
  177. package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
  178. package/dist/services/unified-api/RemoteSessionManager.js +148 -0
  179. package/dist/services/unified-api/container-operations-handler.js +115 -0
  180. package/dist/services/unified-api/server.js +652 -0
  181. package/dist/services/unified-api/state-registry.js +274 -0
  182. package/dist/services/unified-api/task-persistence.js +66 -0
  183. package/dist/services/unified-api/task-state.js +130 -0
  184. package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
  185. package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
  186. package/package.json +38 -10
  187. package/.beads/README.md +0 -81
  188. package/.beads/config.yaml +0 -67
  189. package/.beads/interactions.jsonl +0 -0
  190. package/.beads/issues.jsonl +0 -180
  191. package/.beads/metadata.json +0 -4
  192. package/.claude/settings.local.json +0 -10
  193. package/.github/workflows/ci.yml +0 -55
  194. package/AGENTS.md +0 -253
  195. package/apps/desktop-console/README.md +0 -27
  196. package/apps/desktop-console/package-lock.json +0 -897
  197. package/apps/desktop-console/package.json +0 -20
  198. package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
  199. package/apps/desktop-console/scripts/build.mjs +0 -45
  200. package/apps/desktop-console/scripts/test-preload.mjs +0 -13
  201. package/apps/desktop-console/src/main/config.mts +0 -26
  202. package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
  203. package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
  204. package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
  205. package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
  206. package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
  207. package/apps/desktop-console/src/main/index.mts +0 -980
  208. package/apps/desktop-console/src/main/profile-store.mts +0 -239
  209. package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
  210. package/apps/desktop-console/src/main/state-bridge.mts +0 -114
  211. package/apps/desktop-console/src/main/task-state-types.ts +0 -32
  212. package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
  213. package/apps/desktop-console/src/renderer/index.mts +0 -133
  214. package/apps/desktop-console/src/renderer/index.test.mts +0 -34
  215. package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
  216. package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
  217. package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
  218. package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
  219. package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
  220. package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
  221. package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
  222. package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
  223. package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
  224. package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
  225. package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
  226. package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
  227. package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
  228. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
  229. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
  230. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
  231. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
  232. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
  233. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
  234. package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
  235. package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
  236. package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
  237. package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
  238. package/docs/README_camoufox_chinese.md +0 -141
  239. package/docs/USAGE_V3.md +0 -163
  240. package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
  241. package/docs/arch/PORTS.md +0 -40
  242. package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
  243. package/docs/arch/SEARCH_GATE.md +0 -224
  244. package/docs/arch/VIEWPORT_SAFETY.md +0 -182
  245. package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
  246. package/docs/xiaohongshu-container-driven-summary.md +0 -221
  247. package/docs/xiaohongshu-full-collect-runbook.md +0 -134
  248. package/docs/xiaohongshu-next-steps.md +0 -228
  249. package/docs/xiaohongshu-quickstart.md +0 -73
  250. package/docs/xiaohongshu-workflow-summary.md +0 -227
  251. package/modules/container-registry/tests/container-registry.test.ts +0 -16
  252. package/modules/logging/tests/logging.test.ts +0 -38
  253. package/modules/operations/tests/operations.test.ts +0 -22
  254. package/modules/operations/tests/viewport-filter.test.ts +0 -161
  255. package/modules/operations/tests/visible-only.test.ts +0 -250
  256. package/modules/session-manager/tests/session-manager.test.ts +0 -23
  257. package/modules/state/src/atomic-json.test.ts +0 -30
  258. package/modules/state/src/paths.test.ts +0 -59
  259. package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
  260. package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
  261. package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
  262. package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
  263. package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
  264. package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
  265. package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
  266. package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
  267. package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
  268. package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
  269. package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
  270. package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
  271. package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
  272. package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
  273. package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
  274. package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
  275. package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
  276. package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
  277. package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
  278. package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
  279. package/modules/workflow/tests/smartReply.test.ts +0 -32
  280. package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
  281. package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
  282. package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
  283. package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
  284. package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
  285. package/package-scripts.json +0 -8
  286. package/runtime/infra/utils/README.md +0 -13
  287. package/runtime/infra/utils/scripts/README.md +0 -0
  288. package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
  289. package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
  290. package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
  291. package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
  292. package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
  293. package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
  294. package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
  295. package/runtime/infra/utils/scripts/test-services.mjs +0 -94
  296. package/services/shared/heartbeat.test.ts +0 -102
  297. package/services/unified-api/__tests__/task-state.test.ts +0 -95
  298. package/sitecustomize.py +0 -19
  299. package/tests/README.md +0 -194
  300. package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
  301. package/tests/fixtures/data/container-definitions.json +0 -67
  302. package/tests/fixtures/pages/simple-page.html +0 -69
  303. package/tests/integration/01-test-container-match.mjs +0 -188
  304. package/tests/integration/02-test-dom-branch.mjs +0 -161
  305. package/tests/integration/03-test-container-operation-system.mjs +0 -91
  306. package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
  307. package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
  308. package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
  309. package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
  310. package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
  311. package/tests/integration/10-test-visual-analyzer.mjs +0 -312
  312. package/tests/integration/11-test-visual-loop.mjs +0 -284
  313. package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
  314. package/tests/integration/13-test-visual-robust.mjs +0 -185
  315. package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
  316. package/tests/integration/inspect-page.mjs +0 -50
  317. package/tests/integration/run-all-tests.mjs +0 -95
  318. package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
  319. package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
  320. package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
  321. package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
  322. package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
  323. package/tests/patch_verification/README.md +0 -143
  324. package/tests/patch_verification/RUN_TESTS.md +0 -60
  325. package/tests/patch_verification/TEST_EXECUTION.md +0 -99
  326. package/tests/patch_verification/TEST_PLAN.md +0 -328
  327. package/tests/patch_verification/TEST_RESULTS.md +0 -34
  328. package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
  329. package/tests/patch_verification/run-tool-test.mjs +0 -121
  330. package/tests/patch_verification/temp_test_files/test01.txt +0 -1
  331. package/tests/patch_verification/temp_test_files/test02.txt +0 -3
  332. package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
  333. package/tests/patch_verification/temp_test_files/test03.txt +0 -1
  334. package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
  335. package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
  336. package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
  337. package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
  338. package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
  339. package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
  340. package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
  341. package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
  342. package/tests/runner/TestReporter.mjs +0 -57
  343. package/tests/runner/TestRunner.mjs +0 -244
  344. package/tests/unit/commands/profile.test.mjs +0 -10
  345. package/tests/unit/container/change-notifier.test.mjs +0 -181
  346. package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
  347. package/tests/unit/operations/registry.test.ts +0 -73
  348. package/tests/unit/utils/browser-service.test.mjs +0 -153
  349. package/tests/unit/utils/config.test.mjs +0 -166
  350. package/tests/unit/utils/fingerprint.test.mjs +0 -166
  351. package/tsconfig.json +0 -31
  352. package/tsconfig.services.json +0 -26
  353. /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
  354. /package/apps/desktop-console/{src/renderer/tabs → dist/renderer}/run.mts +0 -0
@@ -1,11 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  import minimist from 'minimist';
3
+ import fs from 'node:fs';
4
+ import fsp from 'node:fs/promises';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
3
7
  import { pathToFileURL } from 'node:url';
4
8
  import { buildXhsUnifiedAutoscript } from '../../../modules/camo-runtime/src/autoscript/xhs-unified-template.mjs';
5
9
  import { normalizeAutoscript, validateAutoscript } from '../../../modules/camo-runtime/src/autoscript/schema.mjs';
6
10
  import { AutoscriptRunner } from '../../../modules/camo-runtime/src/autoscript/runtime.mjs';
11
+ import { syncXhsAccountsByProfiles } from './lib/account-detect.mjs';
12
+ import { markProfileInvalid } from './lib/account-store.mjs';
7
13
  import { listProfilesForPool } from './lib/profilepool.mjs';
8
14
 
15
+ function nowIso() {
16
+ return new Date().toISOString();
17
+ }
18
+
19
+ function formatRunLabel() {
20
+ return new Date().toISOString().replace(/[:.]/g, '-');
21
+ }
22
+
9
23
  function parseBool(value, fallback = false) {
10
24
  if (value === undefined || value === null || value === '') return fallback;
11
25
  if (typeof value === 'boolean') return value;
@@ -22,6 +36,13 @@ function parseIntFlag(value, fallback, min = 1) {
22
36
  return Math.max(min, Math.floor(num));
23
37
  }
24
38
 
39
+ function parseNonNegativeInt(value, fallback = 0) {
40
+ if (value === undefined || value === null || value === '') return fallback;
41
+ const num = Number(value);
42
+ if (!Number.isFinite(num)) return fallback;
43
+ return Math.max(0, Math.floor(num));
44
+ }
45
+
25
46
  function parseProfiles(argv) {
26
47
  const profile = String(argv.profile || '').trim();
27
48
  const profilesRaw = String(argv.profiles || '').trim();
@@ -37,6 +58,36 @@ function parseProfiles(argv) {
37
58
  return [];
38
59
  }
39
60
 
61
+ function sanitizeForPath(name, fallback = 'unknown') {
62
+ const text = String(name || '').trim();
63
+ if (!text) return fallback;
64
+ const cleaned = text.replace(/[\\/:"*?<>|]+/g, '_').trim();
65
+ return cleaned || fallback;
66
+ }
67
+
68
+ function resolveDownloadRoot(customRoot = '') {
69
+ const fromArg = String(customRoot || '').trim();
70
+ if (fromArg) return path.resolve(fromArg);
71
+ const fromEnv = String(process.env.WEBAUTO_DOWNLOAD_ROOT || process.env.WEBAUTO_DOWNLOAD_DIR || '').trim();
72
+ if (fromEnv) return path.resolve(fromEnv);
73
+ const home = process.env.HOME || process.env.USERPROFILE || os.homedir();
74
+ return path.join(home, '.webauto', 'download');
75
+ }
76
+
77
+ async function ensureDir(dirPath) {
78
+ await fsp.mkdir(dirPath, { recursive: true });
79
+ }
80
+
81
+ async function writeJson(filePath, payload) {
82
+ await ensureDir(path.dirname(filePath));
83
+ await fsp.writeFile(filePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf8');
84
+ }
85
+
86
+ async function appendJsonl(filePath, payload) {
87
+ await ensureDir(path.dirname(filePath));
88
+ await fsp.appendFile(filePath, `${JSON.stringify(payload)}\n`, 'utf8');
89
+ }
90
+
40
91
  function buildTemplateOptions(argv, profileId, overrides = {}) {
41
92
  const keyword = String(argv.keyword || argv.k || '').trim();
42
93
  const env = String(argv.env || 'debug').trim() || 'debug';
@@ -88,62 +139,589 @@ function buildTemplateOptions(argv, profileId, overrides = {}) {
88
139
  return { ...base, ...overrides };
89
140
  }
90
141
 
91
- async function runProfile(profileId, argv, overrides = {}) {
142
+ function buildShardPlan({ profiles, totalNotes, defaultMaxNotes }) {
143
+ const uniqueProfiles = Array.from(new Set(profiles.map((item) => String(item || '').trim()).filter(Boolean)));
144
+ if (uniqueProfiles.length === 0) return [];
145
+
146
+ if (!Number.isFinite(totalNotes) || totalNotes <= 0) {
147
+ return uniqueProfiles.map((profileId) => ({ profileId, assignedNotes: defaultMaxNotes }));
148
+ }
149
+
150
+ const base = Math.floor(totalNotes / uniqueProfiles.length);
151
+ const remainder = totalNotes % uniqueProfiles.length;
152
+ const plan = uniqueProfiles.map((profileId, index) => ({
153
+ profileId,
154
+ assignedNotes: base + (index < remainder ? 1 : 0),
155
+ }));
156
+ return plan.filter((item) => item.assignedNotes > 0);
157
+ }
158
+
159
+ function createProfileStats(spec) {
160
+ return {
161
+ assignedNotes: spec.assignedNotes,
162
+ openedNotes: 0,
163
+ commentsHarvestRuns: 0,
164
+ commentsCollected: 0,
165
+ commentsExpected: 0,
166
+ commentsReachedBottomCount: 0,
167
+ likesHitCount: 0,
168
+ likesNewCount: 0,
169
+ likesSkippedCount: 0,
170
+ likesAlreadyCount: 0,
171
+ likesDedupCount: 0,
172
+ searchCount: 0,
173
+ rollbackCount: 0,
174
+ returnToSearchCount: 0,
175
+ operationErrors: 0,
176
+ recoveryFailed: 0,
177
+ terminalCode: null,
178
+ commentPaths: [],
179
+ likeSummaryPaths: [],
180
+ likeStatePaths: [],
181
+ };
182
+ }
183
+
184
+ function pushUnique(arr, value) {
185
+ const text = String(value || '').trim();
186
+ if (!text) return;
187
+ if (!arr.includes(text)) arr.push(text);
188
+ }
189
+
190
+ function toNumber(value, fallback = 0) {
191
+ const num = Number(value);
192
+ return Number.isFinite(num) ? num : fallback;
193
+ }
194
+
195
+ function updateProfileStatsFromEvent(stats, payload) {
196
+ const event = String(payload?.event || '').trim();
197
+ if (!event) return;
198
+
199
+ if (event === 'autoscript:operation_error') {
200
+ stats.operationErrors += 1;
201
+ return;
202
+ }
203
+ if (event === 'autoscript:operation_recovery_failed') {
204
+ stats.recoveryFailed += 1;
205
+ return;
206
+ }
207
+ if (event === 'autoscript:operation_terminal') {
208
+ stats.terminalCode = String(payload.code || '').trim() || stats.terminalCode;
209
+ return;
210
+ }
211
+ if (event !== 'autoscript:operation_done') return;
212
+
213
+ const operationId = String(payload.operationId || '').trim();
214
+ const result = payload.result && typeof payload.result === 'object' ? payload.result : {};
215
+
216
+ if (operationId === 'open_first_detail' || operationId === 'open_next_detail') {
217
+ stats.openedNotes = Math.max(stats.openedNotes, toNumber(result.visited, stats.openedNotes));
218
+ return;
219
+ }
220
+
221
+ if (operationId === 'submit_search') {
222
+ stats.searchCount = Math.max(stats.searchCount, toNumber(result.searchCount, stats.searchCount));
223
+ return;
224
+ }
225
+
226
+ if (operationId === 'comments_harvest') {
227
+ stats.commentsHarvestRuns += 1;
228
+ stats.commentsCollected += toNumber(result.collected, 0);
229
+ stats.commentsExpected += Math.max(0, toNumber(result.expectedCommentsCount, 0));
230
+ if (result.reachedBottom === true) stats.commentsReachedBottomCount += 1;
231
+ pushUnique(stats.commentPaths, result.commentsPath);
232
+ return;
233
+ }
234
+
235
+ if (operationId === 'comment_like') {
236
+ stats.likesHitCount += toNumber(result.hitCount, 0);
237
+ stats.likesNewCount += toNumber(result.likedCount, 0);
238
+ stats.likesSkippedCount += toNumber(result.skippedCount, 0);
239
+ stats.likesAlreadyCount += toNumber(result.alreadyLikedSkipped, 0);
240
+ stats.likesDedupCount += toNumber(result.dedupSkipped, 0);
241
+ pushUnique(stats.likeSummaryPaths, result.summaryPath);
242
+ pushUnique(stats.likeStatePaths, result.likeStatePath);
243
+ pushUnique(stats.commentPaths, result.commentsPath);
244
+ return;
245
+ }
246
+
247
+ if (operationId === 'close_detail') {
248
+ stats.rollbackCount = Math.max(stats.rollbackCount, toNumber(result.rollbackCount, stats.rollbackCount));
249
+ stats.returnToSearchCount = Math.max(stats.returnToSearchCount, toNumber(result.returnToSearchCount, stats.returnToSearchCount));
250
+ }
251
+ }
252
+
253
+ function isObject(value) {
254
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
255
+ }
256
+
257
+ async function runProfile(spec, argv, baseOverrides = {}) {
258
+ const profileId = spec.profileId;
259
+ const overrides = {
260
+ ...baseOverrides,
261
+ maxNotes: spec.assignedNotes,
262
+ outputRoot: spec.outputRoot,
263
+ };
92
264
  const options = buildTemplateOptions(argv, profileId, overrides);
93
265
  const script = buildXhsUnifiedAutoscript(options);
94
266
  const normalized = normalizeAutoscript(script, `xhs-unified:${profileId}`);
95
267
  const validation = validateAutoscript(normalized);
96
268
  if (!validation.ok) throw new Error(`autoscript validation failed for ${profileId}: ${validation.errors.join('; ')}`);
97
269
 
98
- console.log(JSON.stringify({
270
+ await ensureDir(path.dirname(spec.logPath));
271
+ const stats = createProfileStats(spec);
272
+
273
+ const logEvent = (payload) => {
274
+ const eventPayload = isObject(payload) ? payload : { event: 'autoscript:raw', payload };
275
+ const merged = {
276
+ ts: eventPayload.ts || nowIso(),
277
+ profileId,
278
+ ...eventPayload,
279
+ };
280
+ fs.appendFileSync(spec.logPath, `${JSON.stringify(merged)}\n`, 'utf8');
281
+ console.log(JSON.stringify(merged));
282
+ updateProfileStatsFromEvent(stats, merged);
283
+ if (
284
+ merged.event === 'autoscript:event'
285
+ && merged.subscriptionId === 'login_guard'
286
+ && (merged.type === 'appear' || merged.type === 'exist')
287
+ ) {
288
+ try {
289
+ markProfileInvalid(profileId, 'login_guard_runtime');
290
+ } catch {
291
+ // ignore account state update errors during runtime logging
292
+ }
293
+ }
294
+ };
295
+
296
+ logEvent({
99
297
  event: 'xhs.unified.start',
100
- profileId,
101
298
  keyword: options.keyword,
102
299
  env: options.env,
103
300
  maxNotes: options.maxNotes,
104
- doComments: options.doComments,
105
- doLikes: options.doLikes,
106
- doReply: options.doReply,
107
- doOcr: options.doOcr,
108
- }));
301
+ assignedNotes: spec.assignedNotes,
302
+ outputRoot: options.outputRoot,
303
+ parallelRunLabel: spec.runLabel,
304
+ });
109
305
 
110
306
  const runner = new AutoscriptRunner(normalized, {
111
307
  profileId,
112
- log: (payload) => console.log(JSON.stringify(payload)),
308
+ log: logEvent,
113
309
  });
114
310
 
115
311
  const running = await runner.start();
116
312
  const done = await running.done;
117
313
 
118
- console.log(JSON.stringify({
314
+ const stopPayload = {
119
315
  event: 'xhs.unified.stop',
120
316
  profileId,
121
317
  runId: done?.runId || running.runId,
122
318
  reason: done?.reason || null,
123
319
  startedAt: done?.startedAt || null,
124
320
  stoppedAt: done?.stoppedAt || null,
125
- }));
321
+ };
322
+ logEvent(stopPayload);
323
+
324
+ stats.stopReason = stopPayload.reason;
325
+
326
+ const profileResult = {
327
+ ok: stopPayload.reason !== 'script_failure',
328
+ profileId,
329
+ runId: stopPayload.runId,
330
+ reason: stopPayload.reason,
331
+ assignedNotes: spec.assignedNotes,
332
+ outputRoot: options.outputRoot,
333
+ logPath: spec.logPath,
334
+ stats,
335
+ };
336
+
337
+ await writeJson(spec.summaryPath, profileResult);
338
+ return profileResult;
339
+ }
340
+
341
+ async function runWithConcurrency(items, concurrency, worker) {
342
+ const limit = Math.max(1, Math.min(items.length || 1, concurrency || 1));
343
+ const results = new Array(items.length);
344
+ let cursor = 0;
345
+
346
+ async function consume() {
347
+ for (;;) {
348
+ const index = cursor;
349
+ cursor += 1;
350
+ if (index >= items.length) return;
351
+ results[index] = await worker(items[index], index);
352
+ }
353
+ }
354
+
355
+ await Promise.all(Array.from({ length: limit }, () => consume()));
356
+ return results;
357
+ }
358
+
359
+ async function readJsonlRows(filePath) {
360
+ try {
361
+ const text = await fsp.readFile(filePath, 'utf8');
362
+ return text
363
+ .split('\n')
364
+ .map((line) => line.trim())
365
+ .filter(Boolean)
366
+ .map((line) => {
367
+ try {
368
+ return JSON.parse(line);
369
+ } catch {
370
+ return null;
371
+ }
372
+ })
373
+ .filter(Boolean);
374
+ } catch {
375
+ return [];
376
+ }
377
+ }
126
378
 
127
- if (done?.reason === 'script_failure') throw new Error(`autoscript failed for ${profileId}`);
379
+ function buildCommentDedupKey(row) {
380
+ const noteId = String(row?.noteId || '').trim();
381
+ const userId = String(row?.userId || '').trim();
382
+ const content = String(row?.content || '').replace(/\s+/g, ' ').trim();
383
+ return `${noteId}|${userId}|${content}`;
384
+ }
385
+
386
+ async function mergeProfileOutputs({
387
+ results,
388
+ mergedDir,
389
+ keyword,
390
+ env,
391
+ totalNotes,
392
+ parallel,
393
+ concurrency,
394
+ skippedProfiles = [],
395
+ }) {
396
+ const success = results.filter((item) => item && item.ok);
397
+ const failed = results.filter((item) => !item || item.ok === false);
398
+
399
+ const mergedComments = [];
400
+ const seenCommentKeys = new Set();
401
+ const mergedLikeSummaries = [];
402
+
403
+ for (const result of success) {
404
+ for (const commentsPath of result.stats.commentPaths || []) {
405
+ const rows = await readJsonlRows(commentsPath);
406
+ for (const row of rows) {
407
+ const key = buildCommentDedupKey(row);
408
+ if (!key || seenCommentKeys.has(key)) continue;
409
+ seenCommentKeys.add(key);
410
+ mergedComments.push({
411
+ profileId: result.profileId,
412
+ ...row,
413
+ });
414
+ }
415
+ }
416
+
417
+ for (const summaryPath of result.stats.likeSummaryPaths || []) {
418
+ try {
419
+ const raw = await fsp.readFile(summaryPath, 'utf8');
420
+ const summary = JSON.parse(raw);
421
+ mergedLikeSummaries.push({ profileId: result.profileId, summaryPath, summary });
422
+ } catch {
423
+ continue;
424
+ }
425
+ }
426
+ }
427
+
428
+ await ensureDir(mergedDir);
429
+ const mergedCommentsPath = path.join(mergedDir, 'comments.merged.jsonl');
430
+ if (mergedComments.length > 0) {
431
+ const payload = mergedComments.map((row) => JSON.stringify(row)).join('\n');
432
+ await fsp.writeFile(mergedCommentsPath, `${payload}\n`, 'utf8');
433
+ }
434
+
435
+ const mergedLikeSummaryPath = path.join(mergedDir, 'likes.merged.json');
436
+ const likeTotals = {
437
+ noteSummaries: mergedLikeSummaries.length,
438
+ scannedCount: 0,
439
+ hitCount: 0,
440
+ likedCount: 0,
441
+ skippedCount: 0,
442
+ reachedBottomCount: 0,
443
+ };
444
+ for (const item of mergedLikeSummaries) {
445
+ const summary = item.summary || {};
446
+ likeTotals.scannedCount += toNumber(summary.scannedCount, 0);
447
+ likeTotals.hitCount += toNumber(summary.hitCount, 0);
448
+ likeTotals.likedCount += toNumber(summary.likedCount, 0);
449
+ likeTotals.skippedCount += toNumber(summary.skippedCount, 0);
450
+ if (summary.reachedBottom === true) likeTotals.reachedBottomCount += 1;
451
+ }
452
+ await writeJson(mergedLikeSummaryPath, {
453
+ generatedAt: nowIso(),
454
+ totals: likeTotals,
455
+ items: mergedLikeSummaries,
456
+ });
457
+
458
+ const totals = {
459
+ profilesTotal: results.length,
460
+ profilesSucceeded: success.length,
461
+ profilesFailed: failed.length,
462
+ assignedNotes: 0,
463
+ openedNotes: 0,
464
+ commentsHarvestRuns: 0,
465
+ commentsCollected: 0,
466
+ commentsExpected: 0,
467
+ commentsReachedBottomCount: 0,
468
+ likesHitCount: 0,
469
+ likesNewCount: 0,
470
+ likesSkippedCount: 0,
471
+ likesAlreadyCount: 0,
472
+ likesDedupCount: 0,
473
+ searchCount: 0,
474
+ rollbackCount: 0,
475
+ returnToSearchCount: 0,
476
+ operationErrors: 0,
477
+ recoveryFailed: 0,
478
+ };
479
+
480
+ for (const result of results) {
481
+ const stats = result?.stats || {};
482
+ totals.assignedNotes += toNumber(result?.assignedNotes ?? stats.assignedNotes, 0);
483
+ totals.openedNotes += toNumber(stats.openedNotes, 0);
484
+ totals.commentsHarvestRuns += toNumber(stats.commentsHarvestRuns, 0);
485
+ totals.commentsCollected += toNumber(stats.commentsCollected, 0);
486
+ totals.commentsExpected += toNumber(stats.commentsExpected, 0);
487
+ totals.commentsReachedBottomCount += toNumber(stats.commentsReachedBottomCount, 0);
488
+ totals.likesHitCount += toNumber(stats.likesHitCount, 0);
489
+ totals.likesNewCount += toNumber(stats.likesNewCount, 0);
490
+ totals.likesSkippedCount += toNumber(stats.likesSkippedCount, 0);
491
+ totals.likesAlreadyCount += toNumber(stats.likesAlreadyCount, 0);
492
+ totals.likesDedupCount += toNumber(stats.likesDedupCount, 0);
493
+ totals.searchCount += toNumber(stats.searchCount, 0);
494
+ totals.rollbackCount += toNumber(stats.rollbackCount, 0);
495
+ totals.returnToSearchCount += toNumber(stats.returnToSearchCount, 0);
496
+ totals.operationErrors += toNumber(stats.operationErrors, 0);
497
+ totals.recoveryFailed += toNumber(stats.recoveryFailed, 0);
498
+ }
499
+
500
+ const mergedSummary = {
501
+ generatedAt: nowIso(),
502
+ keyword,
503
+ env,
504
+ totalNotes: Number.isFinite(totalNotes) ? totalNotes : null,
505
+ execution: {
506
+ parallel,
507
+ concurrency,
508
+ },
509
+ skippedProfiles,
510
+ totals,
511
+ artifacts: {
512
+ mergedCommentsPath: mergedComments.length > 0 ? mergedCommentsPath : null,
513
+ mergedLikeSummaryPath,
514
+ },
515
+ profiles: results,
516
+ };
517
+
518
+ const summaryPath = path.join(mergedDir, 'summary.json');
519
+ await writeJson(summaryPath, mergedSummary);
520
+ return {
521
+ summaryPath,
522
+ mergedSummary,
523
+ };
128
524
  }
129
525
 
130
526
  export async function runUnified(argv, overrides = {}) {
131
527
  const keyword = String(argv.keyword || argv.k || '').trim();
132
528
  if (!keyword) throw new Error('missing --keyword');
529
+
530
+ const env = String(argv.env || 'debug').trim() || 'debug';
133
531
  const profiles = parseProfiles(argv);
134
532
  if (profiles.length === 0) throw new Error('missing --profile or --profiles or --profilepool');
135
533
 
136
- for (const profileId of profiles) {
137
- console.log(`[unified] running profile=${profileId} keyword=${keyword}`);
138
- await runProfile(profileId, argv, overrides);
534
+ const accountStates = await syncXhsAccountsByProfiles(profiles);
535
+ const executableProfiles = accountStates
536
+ .filter((item) => item?.valid === true && Boolean(String(item?.accountId || '').trim()))
537
+ .map((item) => item.profileId);
538
+ const invalidProfiles = accountStates.filter((item) => !item || item.valid !== true);
539
+ if (executableProfiles.length === 0) {
540
+ throw new Error(`no valid business accounts: ${invalidProfiles.map((item) => `${item.profileId}:${item.reason || 'invalid'}`).join(', ')}`);
139
541
  }
140
- console.log('[unified] all profiles done');
542
+
543
+ const defaultMaxNotes = parseIntFlag(argv['max-notes'] ?? argv.target, 30, 1);
544
+ const totalNotes = parseNonNegativeInt(argv['total-notes'] ?? argv['total-target'], 0);
545
+ const plan = buildShardPlan({ profiles: executableProfiles, totalNotes, defaultMaxNotes });
546
+ if (plan.length === 0) throw new Error('empty shard plan');
547
+
548
+ const parallelRequested = parseBool(argv.parallel, false);
549
+ const parallel = parallelRequested && plan.length > 1;
550
+ const concurrency = parallel
551
+ ? Math.min(plan.length, parseIntFlag(argv.concurrency, plan.length, 1))
552
+ : 1;
553
+
554
+ const runLabel = formatRunLabel();
555
+ const baseOutputRoot = resolveDownloadRoot(argv['output-root']);
556
+ const mergedDir = path.join(
557
+ baseOutputRoot,
558
+ 'xiaohongshu',
559
+ sanitizeForPath(env, 'debug'),
560
+ sanitizeForPath(keyword, 'unknown'),
561
+ 'merged',
562
+ `run-${runLabel}`,
563
+ );
564
+ const planPath = path.join(mergedDir, 'plan.json');
565
+
566
+ const useShardRoots = plan.length > 1;
567
+ const specs = plan.map((item) => {
568
+ const shardId = sanitizeForPath(item.profileId, 'profile');
569
+ const shardOutputRoot = useShardRoots
570
+ ? path.join(baseOutputRoot, 'shards', shardId)
571
+ : String(argv['output-root'] || '').trim();
572
+ return {
573
+ ...item,
574
+ runLabel,
575
+ outputRoot: shardOutputRoot,
576
+ logPath: path.join(mergedDir, 'profiles', `${shardId}.events.jsonl`),
577
+ summaryPath: path.join(mergedDir, 'profiles', `${shardId}.summary.json`),
578
+ };
579
+ });
580
+
581
+ const planPayload = {
582
+ event: 'xhs.unified.plan',
583
+ planPath,
584
+ keyword,
585
+ env,
586
+ totalNotes: totalNotes > 0 ? totalNotes : null,
587
+ defaultMaxNotes,
588
+ parallel,
589
+ concurrency,
590
+ accountStates,
591
+ skippedProfiles: invalidProfiles.map((item) => ({
592
+ profileId: item?.profileId || null,
593
+ status: item?.status || 'invalid',
594
+ reason: item?.reason || 'invalid',
595
+ valid: item?.valid === true,
596
+ accountId: item?.accountId || null,
597
+ })),
598
+ specs: specs.map((item) => ({
599
+ profileId: item.profileId,
600
+ assignedNotes: item.assignedNotes,
601
+ outputRoot: item.outputRoot,
602
+ logPath: item.logPath,
603
+ })),
604
+ };
605
+ console.log(JSON.stringify(planPayload));
606
+
607
+ await writeJson(planPath, planPayload);
608
+
609
+ if (parseBool(argv['plan-only'], false)) {
610
+ return {
611
+ ok: true,
612
+ planOnly: true,
613
+ planPath,
614
+ specs,
615
+ };
616
+ }
617
+
618
+ const execute = async (spec) => {
619
+ try {
620
+ return await runProfile(spec, argv, overrides);
621
+ } catch (error) {
622
+ const failure = {
623
+ ok: false,
624
+ profileId: spec.profileId,
625
+ assignedNotes: spec.assignedNotes,
626
+ outputRoot: spec.outputRoot,
627
+ logPath: spec.logPath,
628
+ reason: 'runner_error',
629
+ error: error?.message || String(error),
630
+ stats: {
631
+ assignedNotes: spec.assignedNotes,
632
+ openedNotes: 0,
633
+ commentsHarvestRuns: 0,
634
+ commentsCollected: 0,
635
+ commentsExpected: 0,
636
+ commentsReachedBottomCount: 0,
637
+ likesHitCount: 0,
638
+ likesNewCount: 0,
639
+ likesSkippedCount: 0,
640
+ likesAlreadyCount: 0,
641
+ likesDedupCount: 0,
642
+ searchCount: 0,
643
+ rollbackCount: 0,
644
+ returnToSearchCount: 0,
645
+ operationErrors: 1,
646
+ recoveryFailed: 0,
647
+ terminalCode: null,
648
+ commentPaths: [],
649
+ likeSummaryPaths: [],
650
+ likeStatePaths: [],
651
+ stopReason: 'runner_error',
652
+ },
653
+ };
654
+ await appendJsonl(spec.logPath, {
655
+ ts: nowIso(),
656
+ profileId: spec.profileId,
657
+ event: 'xhs.unified.runner_error',
658
+ error: failure.error,
659
+ });
660
+ await writeJson(spec.summaryPath, failure);
661
+ console.error(JSON.stringify({
662
+ event: 'xhs.unified.profile_failed',
663
+ profileId: spec.profileId,
664
+ error: failure.error,
665
+ }));
666
+ return failure;
667
+ }
668
+ };
669
+
670
+ const results = parallel
671
+ ? await runWithConcurrency(specs, concurrency, execute)
672
+ : await runWithConcurrency(specs, 1, execute);
673
+
674
+ const merged = await mergeProfileOutputs({
675
+ results,
676
+ mergedDir,
677
+ keyword,
678
+ env,
679
+ totalNotes,
680
+ parallel,
681
+ concurrency,
682
+ skippedProfiles: invalidProfiles.map((item) => ({
683
+ profileId: item?.profileId || null,
684
+ status: item?.status || 'invalid',
685
+ reason: item?.reason || 'invalid',
686
+ accountId: item?.accountId || null,
687
+ })),
688
+ });
689
+
690
+ console.log(JSON.stringify({
691
+ event: 'xhs.unified.merged',
692
+ summaryPath: merged.summaryPath,
693
+ profilesTotal: results.length,
694
+ profilesSucceeded: results.filter((item) => item.ok).length,
695
+ profilesFailed: results.filter((item) => !item.ok).length,
696
+ }));
697
+
698
+ if (results.some((item) => !item.ok)) {
699
+ throw new Error(`unified finished with failures, see ${merged.summaryPath}`);
700
+ }
701
+
702
+ return {
703
+ ok: true,
704
+ summaryPath: merged.summaryPath,
705
+ results,
706
+ };
141
707
  }
142
708
 
143
709
  async function main() {
144
710
  const argv = minimist(process.argv.slice(2));
145
711
  if (argv.help || argv.h) {
146
- console.log('Usage: node apps/webauto/entry/xhs-unified.mjs --profile <id> --keyword <kw> [--max-notes 50]');
712
+ console.log([
713
+ 'Usage: node apps/webauto/entry/xhs-unified.mjs --profile <id> --keyword <kw> [options]',
714
+ 'Options:',
715
+ ' --profiles <a,b,c> 多账号列表',
716
+ ' --profilepool <prefix> 账号池前缀(自动读取匹配 profile)',
717
+ ' --max-notes <n> 单账号目标(未启用 total-notes 时)',
718
+ ' --total-notes <n> 总目标数(自动分片到账号)',
719
+ ' --total-target <n> total-notes 别名',
720
+ ' --parallel 启用并行执行',
721
+ ' --concurrency <n> 并行度(默认=账号数)',
722
+ ' --plan-only 只生成分片计划,不执行',
723
+ ' --output-root <path> 输出根目录(并行时自动分 profile shard)',
724
+ ].join('\n'));
147
725
  return;
148
726
  }
149
727
  await runUnified(argv);