@web-auto/webauto 0.1.1 → 0.1.2
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.
- package/apps/desktop-console/default-settings.json +1 -0
- package/apps/desktop-console/dist/main/index.mjs +1618 -0
- package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
- package/apps/desktop-console/dist/renderer/index.js +3063 -0
- package/apps/desktop-console/entry/ui-console.mjs +299 -0
- package/apps/webauto/entry/account.mjs +356 -0
- package/apps/webauto/entry/lib/account-detect.mjs +160 -0
- package/apps/webauto/entry/lib/account-store.mjs +587 -0
- package/apps/webauto/entry/lib/profilepool.mjs +1 -1
- package/apps/webauto/entry/xhs-install.mjs +27 -3
- package/apps/webauto/entry/xhs-status.mjs +152 -0
- package/apps/webauto/entry/xhs-unified.mjs +595 -17
- package/bin/webauto.mjs +247 -12
- package/dist/apps/webauto/server.js +66 -0
- package/dist/modules/camo-backend/src/index.js +575 -0
- package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
- package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
- package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
- package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
- package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
- package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
- package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
- package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
- package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
- package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
- package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
- package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
- package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
- package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
- package/dist/modules/container-registry/src/index.js +184 -0
- package/dist/modules/logging/src/index.js +92 -0
- package/dist/modules/operations/src/builtin.js +27 -0
- package/dist/modules/operations/src/container-binding.js +75 -0
- package/dist/modules/operations/src/executor.js +146 -0
- package/dist/modules/operations/src/operations/click.js +167 -0
- package/dist/modules/operations/src/operations/extract.js +204 -0
- package/dist/modules/operations/src/operations/find-child.js +17 -0
- package/dist/modules/operations/src/operations/highlight.js +138 -0
- package/dist/modules/operations/src/operations/key.js +61 -0
- package/dist/modules/operations/src/operations/navigate.js +148 -0
- package/dist/modules/operations/src/operations/scroll.js +126 -0
- package/dist/modules/operations/src/operations/type.js +190 -0
- package/dist/modules/operations/src/queue.js +100 -0
- package/dist/modules/operations/src/registry.js +11 -0
- package/dist/modules/operations/src/system/mouse.js +33 -0
- package/dist/modules/state/src/atomic-json.js +33 -0
- package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
- package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
- package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
- package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
- package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
- package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
- package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
- package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
- package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
- package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
- package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
- package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
- package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
- package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
- package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
- package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
- package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
- package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
- package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
- package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
- package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
- package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
- package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
- package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
- package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
- package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
- package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
- package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
- package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
- package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
- package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
- package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
- package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
- package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
- package/dist/modules/workflow/blocks/SaveFile.js +54 -0
- package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
- package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
- package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
- package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
- package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
- package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
- package/dist/modules/workflow/blocks/WaitStable.js +74 -0
- package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
- package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
- package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
- package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
- package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
- package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
- package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
- package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
- package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
- package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
- package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
- package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
- package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
- package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
- package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
- package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
- package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
- package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
- package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
- package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
- package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
- package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
- package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
- package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
- package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
- package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
- package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
- package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
- package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
- package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
- package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
- package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
- package/dist/modules/workflow/config/workflowRegistry.js +32 -0
- package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
- package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
- package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
- package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
- package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
- package/dist/modules/workflow/src/context.js +70 -0
- package/dist/modules/workflow/src/index.js +5 -0
- package/dist/modules/workflow/src/orchestrator.js +230 -0
- package/dist/modules/workflow/src/runner.js +55 -0
- package/dist/modules/workflow/src/runtime.js +70 -0
- package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
- package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
- package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
- package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
- package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
- package/dist/modules/xiaohongshu/app/src/index.js +9 -0
- package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
- package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
- package/dist/services/controller/src/controller.js +1476 -0
- package/dist/services/controller/src/index.js +2 -0
- package/dist/services/controller/src/payload-normalizer.js +129 -0
- package/dist/services/shared/heartbeat.js +120 -0
- package/dist/services/shared/lib/errorHandler.js +2 -0
- package/dist/services/shared/serviceProcessLogger.js +139 -0
- package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
- package/dist/services/unified-api/RemoteSessionManager.js +148 -0
- package/dist/services/unified-api/container-operations-handler.js +115 -0
- package/dist/services/unified-api/server.js +652 -0
- package/dist/services/unified-api/state-registry.js +274 -0
- package/dist/services/unified-api/task-persistence.js +66 -0
- package/dist/services/unified-api/task-state.js +130 -0
- package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
- package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
- package/package.json +37 -9
- package/.beads/README.md +0 -81
- package/.beads/config.yaml +0 -67
- package/.beads/interactions.jsonl +0 -0
- package/.beads/issues.jsonl +0 -180
- package/.beads/metadata.json +0 -4
- package/.claude/settings.local.json +0 -10
- package/.github/workflows/ci.yml +0 -55
- package/AGENTS.md +0 -253
- package/apps/desktop-console/README.md +0 -27
- package/apps/desktop-console/package-lock.json +0 -897
- package/apps/desktop-console/package.json +0 -20
- package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
- package/apps/desktop-console/scripts/build.mjs +0 -45
- package/apps/desktop-console/scripts/test-preload.mjs +0 -13
- package/apps/desktop-console/src/main/config.mts +0 -26
- package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
- package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
- package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
- package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
- package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
- package/apps/desktop-console/src/main/index.mts +0 -980
- package/apps/desktop-console/src/main/profile-store.mts +0 -239
- package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
- package/apps/desktop-console/src/main/state-bridge.mts +0 -114
- package/apps/desktop-console/src/main/task-state-types.ts +0 -32
- package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
- package/apps/desktop-console/src/renderer/index.mts +0 -133
- package/apps/desktop-console/src/renderer/index.test.mts +0 -34
- package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
- package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
- package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
- package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
- package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
- package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
- package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
- package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
- package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
- package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
- package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
- package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
- package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
- package/docs/README_camoufox_chinese.md +0 -141
- package/docs/USAGE_V3.md +0 -163
- package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
- package/docs/arch/PORTS.md +0 -40
- package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
- package/docs/arch/SEARCH_GATE.md +0 -224
- package/docs/arch/VIEWPORT_SAFETY.md +0 -182
- package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
- package/docs/xiaohongshu-container-driven-summary.md +0 -221
- package/docs/xiaohongshu-full-collect-runbook.md +0 -134
- package/docs/xiaohongshu-next-steps.md +0 -228
- package/docs/xiaohongshu-quickstart.md +0 -73
- package/docs/xiaohongshu-workflow-summary.md +0 -227
- package/modules/container-registry/tests/container-registry.test.ts +0 -16
- package/modules/logging/tests/logging.test.ts +0 -38
- package/modules/operations/tests/operations.test.ts +0 -22
- package/modules/operations/tests/viewport-filter.test.ts +0 -161
- package/modules/operations/tests/visible-only.test.ts +0 -250
- package/modules/session-manager/tests/session-manager.test.ts +0 -23
- package/modules/state/src/atomic-json.test.ts +0 -30
- package/modules/state/src/paths.test.ts +0 -59
- package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
- package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
- package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
- package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
- package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
- package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
- package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
- package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
- package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
- package/modules/workflow/tests/smartReply.test.ts +0 -32
- package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
- package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
- package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
- package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
- package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
- package/package-scripts.json +0 -8
- package/runtime/infra/utils/README.md +0 -13
- package/runtime/infra/utils/scripts/README.md +0 -0
- package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
- package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
- package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
- package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
- package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
- package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
- package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
- package/runtime/infra/utils/scripts/test-services.mjs +0 -94
- package/services/shared/heartbeat.test.ts +0 -102
- package/services/unified-api/__tests__/task-state.test.ts +0 -95
- package/sitecustomize.py +0 -19
- package/tests/README.md +0 -194
- package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
- package/tests/fixtures/data/container-definitions.json +0 -67
- package/tests/fixtures/pages/simple-page.html +0 -69
- package/tests/integration/01-test-container-match.mjs +0 -188
- package/tests/integration/02-test-dom-branch.mjs +0 -161
- package/tests/integration/03-test-container-operation-system.mjs +0 -91
- package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
- package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
- package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
- package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
- package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
- package/tests/integration/10-test-visual-analyzer.mjs +0 -312
- package/tests/integration/11-test-visual-loop.mjs +0 -284
- package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
- package/tests/integration/13-test-visual-robust.mjs +0 -185
- package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
- package/tests/integration/inspect-page.mjs +0 -50
- package/tests/integration/run-all-tests.mjs +0 -95
- package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
- package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
- package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
- package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
- package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
- package/tests/patch_verification/README.md +0 -143
- package/tests/patch_verification/RUN_TESTS.md +0 -60
- package/tests/patch_verification/TEST_EXECUTION.md +0 -99
- package/tests/patch_verification/TEST_PLAN.md +0 -328
- package/tests/patch_verification/TEST_RESULTS.md +0 -34
- package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
- package/tests/patch_verification/run-tool-test.mjs +0 -121
- package/tests/patch_verification/temp_test_files/test01.txt +0 -1
- package/tests/patch_verification/temp_test_files/test02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
- package/tests/patch_verification/temp_test_files/test03.txt +0 -1
- package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
- package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
- package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
- package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
- package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
- package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
- package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
- package/tests/runner/TestReporter.mjs +0 -57
- package/tests/runner/TestRunner.mjs +0 -244
- package/tests/unit/commands/profile.test.mjs +0 -10
- package/tests/unit/container/change-notifier.test.mjs +0 -181
- package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
- package/tests/unit/operations/registry.test.ts +0 -73
- package/tests/unit/utils/browser-service.test.mjs +0 -153
- package/tests/unit/utils/config.test.mjs +0 -166
- package/tests/unit/utils/fingerprint.test.mjs +0 -166
- package/tsconfig.json +0 -31
- package/tsconfig.services.json +0 -26
- /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
- /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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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:
|
|
308
|
+
log: logEvent,
|
|
113
309
|
});
|
|
114
310
|
|
|
115
311
|
const running = await runner.start();
|
|
116
312
|
const done = await running.done;
|
|
117
313
|
|
|
118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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(
|
|
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);
|