@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.
- 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 +263 -15
- 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 +38 -10
- 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
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 微博 Feed 提取 Workflow (标准化版本)
|
|
3
|
+
*
|
|
4
|
+
* 功能:
|
|
5
|
+
* 1. 事件驱动的帖子提取
|
|
6
|
+
* 2. 自动点击"展开"按钮
|
|
7
|
+
* 3. 捕获点击后的完整文本
|
|
8
|
+
* 4. 标准化接口,可作为 Workflow Chain 的一部分
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from 'events';
|
|
11
|
+
const MSG_CONTAINER_APPEAR = 'MSG_CONTAINER_APPEAR';
|
|
12
|
+
const MSG_CONTAINER_OPERATION_COMPLETE = 'MSG_CONTAINER_OPERATION_COMPLETE';
|
|
13
|
+
const MSG_CONTAINER_CLICK = 'MSG_CONTAINER_CLICK';
|
|
14
|
+
/**
|
|
15
|
+
* 微博 Feed 提取 Workflow
|
|
16
|
+
* 标准化的事件驱动实现
|
|
17
|
+
*/
|
|
18
|
+
export class WeiboFeedExtractionWorkflow extends EventEmitter {
|
|
19
|
+
config;
|
|
20
|
+
context;
|
|
21
|
+
extractedPosts = [];
|
|
22
|
+
processedPostKeys = new Set();
|
|
23
|
+
isRunning = false;
|
|
24
|
+
scrollCount = 0;
|
|
25
|
+
expandButtonClicks = 0;
|
|
26
|
+
constructor(config, context) {
|
|
27
|
+
super();
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.context = context;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 启动 Workflow
|
|
33
|
+
*/
|
|
34
|
+
async execute() {
|
|
35
|
+
try {
|
|
36
|
+
this.isRunning = true;
|
|
37
|
+
this.emit('workflow:start', { config: this.config });
|
|
38
|
+
// Step 1: 订阅容器事件
|
|
39
|
+
await this.setupEventListeners();
|
|
40
|
+
// Step 2: 初始化会话
|
|
41
|
+
await this.initializeSession();
|
|
42
|
+
// Step 3: 匹配容器
|
|
43
|
+
const feedListId = await this.matchContainers();
|
|
44
|
+
// Step 4: 执行提取循环
|
|
45
|
+
await this.extractionLoop(feedListId);
|
|
46
|
+
// Step 5: 清理
|
|
47
|
+
await this.cleanup();
|
|
48
|
+
this.emit('workflow:complete', {
|
|
49
|
+
totalExtracted: this.extractedPosts.length,
|
|
50
|
+
expandButtonClicks: this.expandButtonClicks
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
success: true,
|
|
54
|
+
posts: this.extractedPosts,
|
|
55
|
+
totalExtracted: this.extractedPosts.length
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.emit('workflow:error', { error: error.message });
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
posts: this.extractedPosts,
|
|
63
|
+
totalExtracted: this.extractedPosts.length,
|
|
64
|
+
error: error.message
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.isRunning = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 设置事件监听器
|
|
73
|
+
*/
|
|
74
|
+
async setupEventListeners() {
|
|
75
|
+
const { messageBus } = this.context;
|
|
76
|
+
// 监听容器出现事件
|
|
77
|
+
messageBus.subscribe(MSG_CONTAINER_APPEAR, async (event) => {
|
|
78
|
+
const { containerId, containerType } = event;
|
|
79
|
+
this.emit('container:appeared', { containerId, containerType });
|
|
80
|
+
// 如果是"展开"按钮,自动点击
|
|
81
|
+
if (containerId.includes('expand_button')) {
|
|
82
|
+
await this.handleExpandButtonAppear(event);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
// 监听容器点击完成事件
|
|
86
|
+
messageBus.subscribe(MSG_CONTAINER_OPERATION_COMPLETE, async (event) => {
|
|
87
|
+
const { containerId, operationId, result } = event;
|
|
88
|
+
if (operationId === 'click' && containerId.includes('expand_button')) {
|
|
89
|
+
this.emit('expand:clicked', { containerId });
|
|
90
|
+
// 点击后需要重新提取父容器的内容
|
|
91
|
+
await this.reExtractAfterExpand(containerId);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 处理"展开"按钮出现
|
|
97
|
+
*/
|
|
98
|
+
async handleExpandButtonAppear(event) {
|
|
99
|
+
const { containerId } = event;
|
|
100
|
+
this.emit('expand:detected', { containerId });
|
|
101
|
+
try {
|
|
102
|
+
// 发送点击操作
|
|
103
|
+
await this.context.apiClient.post('/v1/controller/action', {
|
|
104
|
+
action: 'container:operation',
|
|
105
|
+
payload: {
|
|
106
|
+
containerId,
|
|
107
|
+
operationId: 'click',
|
|
108
|
+
config: { wait_after: 500 },
|
|
109
|
+
sessionId: this.config.profile
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
this.expandButtonClicks++;
|
|
113
|
+
this.emit('expand:click-sent', { containerId, totalClicks: this.expandButtonClicks });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.emit('expand:click-failed', { containerId, error: error.message });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 点击后重新提取内容
|
|
121
|
+
*/
|
|
122
|
+
async reExtractAfterExpand(expandButtonId) {
|
|
123
|
+
// 获取父容器 ID (feed_post)
|
|
124
|
+
const parentId = expandButtonId.replace('.expand_button', '');
|
|
125
|
+
try {
|
|
126
|
+
// 等待内容加载
|
|
127
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
128
|
+
// 重新提取父容器内容
|
|
129
|
+
const extractResult = await this.extractPost(parentId);
|
|
130
|
+
if (extractResult) {
|
|
131
|
+
// 更新已提取的帖子内容
|
|
132
|
+
const existingIndex = this.extractedPosts.findIndex(p => p.id === parentId);
|
|
133
|
+
if (existingIndex >= 0) {
|
|
134
|
+
this.extractedPosts[existingIndex] = { ...this.extractedPosts[existingIndex], ...extractResult };
|
|
135
|
+
this.emit('post:updated-after-expand', { postId: parentId, content: extractResult.content });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
this.emit('extract:failed-after-expand', { parentId, error: error.message });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 初始化会话
|
|
145
|
+
*/
|
|
146
|
+
async initializeSession() {
|
|
147
|
+
this.emit('session:init-start');
|
|
148
|
+
const sessions = await this.context.apiClient.post('/v1/controller/action', {
|
|
149
|
+
action: 'session:list',
|
|
150
|
+
payload: {}
|
|
151
|
+
});
|
|
152
|
+
const active = sessions.data?.data?.sessions?.find((s) => s.profileId === this.config.profile);
|
|
153
|
+
if (!active) {
|
|
154
|
+
await this.context.apiClient.post('/v1/controller/action', {
|
|
155
|
+
action: 'session:create',
|
|
156
|
+
payload: {
|
|
157
|
+
profile: this.config.profile,
|
|
158
|
+
url: this.config.url
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
await new Promise(r => setTimeout(r, 5000));
|
|
162
|
+
}
|
|
163
|
+
this.emit('session:init-complete');
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 匹配容器
|
|
167
|
+
*/
|
|
168
|
+
async matchContainers() {
|
|
169
|
+
this.emit('match:start');
|
|
170
|
+
const match = await this.context.apiClient.post('/v1/controller/action', {
|
|
171
|
+
action: 'containers:match',
|
|
172
|
+
payload: {
|
|
173
|
+
profile: this.config.profile,
|
|
174
|
+
url: this.config.url
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (!match.data?.matched) {
|
|
178
|
+
throw new Error('Root container not matched');
|
|
179
|
+
}
|
|
180
|
+
const rootId = match.data.container.id;
|
|
181
|
+
this.emit('match:root-found', { rootId });
|
|
182
|
+
// 查找 feed_list
|
|
183
|
+
const inspect = await this.context.apiClient.post('/v1/controller/action', {
|
|
184
|
+
action: 'containers:inspect-container',
|
|
185
|
+
payload: {
|
|
186
|
+
profile: this.config.profile,
|
|
187
|
+
containerId: rootId
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const feedList = inspect.data?.data?.snapshot?.children?.find((c) => c.id?.includes('feed_list') || c.defId?.includes('feed_list'));
|
|
191
|
+
if (!feedList) {
|
|
192
|
+
throw new Error('Feed list container not found');
|
|
193
|
+
}
|
|
194
|
+
this.emit('match:feed-list-found', { feedListId: feedList.id });
|
|
195
|
+
return feedList.id;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 提取循环
|
|
199
|
+
*/
|
|
200
|
+
async extractionLoop(listId) {
|
|
201
|
+
const maxScrolls = this.config.maxScrolls || 120;
|
|
202
|
+
let heightUnchangedCount = 0;
|
|
203
|
+
let lastHeight = 0;
|
|
204
|
+
this.emit('extraction:loop-start', { targetCount: this.config.targetCount });
|
|
205
|
+
while (this.extractedPosts.length < this.config.targetCount &&
|
|
206
|
+
this.scrollCount < maxScrolls &&
|
|
207
|
+
heightUnchangedCount < 3) {
|
|
208
|
+
this.emit('extraction:cycle', {
|
|
209
|
+
extracted: this.extractedPosts.length,
|
|
210
|
+
target: this.config.targetCount,
|
|
211
|
+
scroll: this.scrollCount,
|
|
212
|
+
maxScrolls
|
|
213
|
+
});
|
|
214
|
+
// 获取当前可见的帖子
|
|
215
|
+
const posts = await this.getVisiblePosts(listId);
|
|
216
|
+
// 提取每个帖子
|
|
217
|
+
for (const post of posts) {
|
|
218
|
+
if (this.extractedPosts.length >= this.config.targetCount)
|
|
219
|
+
break;
|
|
220
|
+
const postKey = this.generatePostKey(post);
|
|
221
|
+
if (this.processedPostKeys.has(postKey))
|
|
222
|
+
continue;
|
|
223
|
+
const extracted = await this.extractPost(post.id);
|
|
224
|
+
if (extracted && extracted.content) {
|
|
225
|
+
this.extractedPosts.push(extracted);
|
|
226
|
+
this.processedPostKeys.add(postKey);
|
|
227
|
+
this.emit('post:extracted', {
|
|
228
|
+
postId: post.id,
|
|
229
|
+
total: this.extractedPosts.length
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
await new Promise(r => setTimeout(r, 500));
|
|
233
|
+
}
|
|
234
|
+
// 检查页面高度
|
|
235
|
+
const currentHeight = await this.getPageHeight();
|
|
236
|
+
if (currentHeight === lastHeight) {
|
|
237
|
+
heightUnchangedCount++;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
heightUnchangedCount = 0;
|
|
241
|
+
}
|
|
242
|
+
lastHeight = currentHeight;
|
|
243
|
+
// 滚动加载更多
|
|
244
|
+
if (this.extractedPosts.length < this.config.targetCount && heightUnchangedCount < 3) {
|
|
245
|
+
await this.scrollPage(listId);
|
|
246
|
+
this.scrollCount++;
|
|
247
|
+
await new Promise(r => setTimeout(r, this.config.waitAfterScroll || 3000));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
this.emit('extraction:loop-complete', {
|
|
251
|
+
totalExtracted: this.extractedPosts.length
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 获取可见帖子
|
|
256
|
+
*/
|
|
257
|
+
async getVisiblePosts(listId) {
|
|
258
|
+
const inspect = await this.context.apiClient.post('/v1/controller/action', {
|
|
259
|
+
action: 'containers:inspect-container',
|
|
260
|
+
payload: {
|
|
261
|
+
profile: this.config.profile,
|
|
262
|
+
containerId: listId,
|
|
263
|
+
maxChildren: 50
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return inspect.data?.data?.snapshot?.children || [];
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* 提取单个帖子
|
|
270
|
+
*/
|
|
271
|
+
async extractPost(postId) {
|
|
272
|
+
try {
|
|
273
|
+
const res = await this.context.apiClient.post('/v1/controller/action', {
|
|
274
|
+
action: 'container:operation',
|
|
275
|
+
payload: {
|
|
276
|
+
containerId: postId,
|
|
277
|
+
operationId: 'extract',
|
|
278
|
+
config: {
|
|
279
|
+
fields: {
|
|
280
|
+
author: "header a[href*='weibo.com']",
|
|
281
|
+
content: "div[class*='detail_wbtext']",
|
|
282
|
+
timestamp: "time",
|
|
283
|
+
url: "a[href*='weibo.com'][href*='/status/']",
|
|
284
|
+
authorUrl: "a[href*='weibo.com/u/']"
|
|
285
|
+
},
|
|
286
|
+
include_text: true
|
|
287
|
+
},
|
|
288
|
+
sessionId: this.config.profile
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
const extracted = res.data?.data?.extracted?.[0];
|
|
292
|
+
if (extracted) {
|
|
293
|
+
return {
|
|
294
|
+
id: postId,
|
|
295
|
+
author: extracted.author,
|
|
296
|
+
content: extracted.text || extracted.content,
|
|
297
|
+
url: extracted.url,
|
|
298
|
+
authorUrl: extracted.authorUrl,
|
|
299
|
+
timestamp: extracted.timestamp
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* 生成帖子唯一标识
|
|
310
|
+
*/
|
|
311
|
+
generatePostKey(post) {
|
|
312
|
+
return post.id || post.defId || `post-${Date.now()}`;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 获取页面高度
|
|
316
|
+
*/
|
|
317
|
+
async getPageHeight() {
|
|
318
|
+
const res = await this.context.apiClient.post('/v1/controller/action', {
|
|
319
|
+
action: 'browser:execute',
|
|
320
|
+
payload: {
|
|
321
|
+
sessionId: this.config.profile,
|
|
322
|
+
script: 'document.documentElement.scrollHeight'
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
return res.data?.result || 0;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* 滚动页面
|
|
329
|
+
*/
|
|
330
|
+
async scrollPage(listId) {
|
|
331
|
+
await this.context.apiClient.post('/v1/controller/action', {
|
|
332
|
+
action: 'container:operation',
|
|
333
|
+
payload: {
|
|
334
|
+
containerId: listId,
|
|
335
|
+
operationId: 'scroll',
|
|
336
|
+
config: {
|
|
337
|
+
direction: 'down',
|
|
338
|
+
distance: this.config.scrollDistance || 800
|
|
339
|
+
},
|
|
340
|
+
sessionId: this.config.profile
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* 清理资源
|
|
346
|
+
*/
|
|
347
|
+
async cleanup() {
|
|
348
|
+
// 取消订阅等清理工作
|
|
349
|
+
this.emit('workflow:cleanup');
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* 停止 Workflow
|
|
353
|
+
*/
|
|
354
|
+
stop() {
|
|
355
|
+
this.isRunning = false;
|
|
356
|
+
this.emit('workflow:stopped');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
//# sourceMappingURL=WeiboFeedExtractionWorkflow.js.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XiaohongshuLoginWorkflow
|
|
3
|
+
*
|
|
4
|
+
* 目标:
|
|
5
|
+
* - 确保指定 profile 的浏览器 Session 存在(或创建)
|
|
6
|
+
* - 基于「登录锚点容器」模型检查登录态(*.login_anchor / xiaohongshu_login.login_guard)
|
|
7
|
+
*
|
|
8
|
+
* 说明:
|
|
9
|
+
* - 这是一个最小登录 Workflow,只负责「起 Session + 判登录」,不做自动登录。
|
|
10
|
+
* - 依赖的 Block:
|
|
11
|
+
* - EnsureSessionBlock:Browser Service /command 层的会话检查与创建
|
|
12
|
+
* - EnsureLoginBlock:Unified API controller 层的容器驱动登录检测
|
|
13
|
+
*/
|
|
14
|
+
import { execute as ensureSessionExecute } from '../blocks/EnsureSession.js';
|
|
15
|
+
import { execute as ensureLoginExecute } from '../blocks/EnsureLoginBlock.js';
|
|
16
|
+
export async function execute(input) {
|
|
17
|
+
const { profileId, startUrl, browserServiceUrl, unifiedApiUrl } = input;
|
|
18
|
+
if (!profileId) {
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
profileId: '',
|
|
22
|
+
session: {
|
|
23
|
+
sessionId: '',
|
|
24
|
+
status: 'active',
|
|
25
|
+
currentPage: '',
|
|
26
|
+
error: 'Missing profileId',
|
|
27
|
+
},
|
|
28
|
+
login: {
|
|
29
|
+
isLoggedIn: false,
|
|
30
|
+
loginMethod: 'manual_wait',
|
|
31
|
+
error: 'Missing profileId',
|
|
32
|
+
},
|
|
33
|
+
error: 'Missing profileId',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
// Step 1: 确保 Session 存在(Browser Service 视角)
|
|
38
|
+
const sessionInput = {
|
|
39
|
+
profileId,
|
|
40
|
+
url: startUrl,
|
|
41
|
+
serviceUrl: browserServiceUrl || 'http://127.0.0.1:7704',
|
|
42
|
+
};
|
|
43
|
+
let sessionResult = await ensureSessionExecute(sessionInput);
|
|
44
|
+
if (sessionResult.error) {
|
|
45
|
+
const waitMsRaw = Number(process.env.WEBAUTO_SESSION_WAIT_MS || 0);
|
|
46
|
+
const waitLimitMs = waitMsRaw <= 0 ? Number.POSITIVE_INFINITY : waitMsRaw;
|
|
47
|
+
const intervalMs = Math.max(1000, Number(process.env.WEBAUTO_SESSION_WAIT_INTERVAL_MS || 3000));
|
|
48
|
+
const startTime = Date.now();
|
|
49
|
+
const waitHint = waitLimitMs === Number.POSITIVE_INFINITY
|
|
50
|
+
? '无超时'
|
|
51
|
+
: `${waitLimitMs}ms`;
|
|
52
|
+
console.warn(`[EnsureSession] 启动失败: ${sessionResult.error}`);
|
|
53
|
+
console.warn(`[EnsureSession] 等待用户处理并重试,最大等待: ${waitHint}, 间隔: ${intervalMs}ms`);
|
|
54
|
+
while (Date.now() - startTime < waitLimitMs) {
|
|
55
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
56
|
+
sessionResult = await ensureSessionExecute(sessionInput);
|
|
57
|
+
if (!sessionResult.error)
|
|
58
|
+
break;
|
|
59
|
+
console.warn(`[EnsureSession] 重试仍失败: ${sessionResult.error}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (sessionResult.error) {
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
profileId,
|
|
66
|
+
session: sessionResult,
|
|
67
|
+
login: {
|
|
68
|
+
isLoggedIn: false,
|
|
69
|
+
loginMethod: 'manual_wait',
|
|
70
|
+
error: 'EnsureSession failed',
|
|
71
|
+
},
|
|
72
|
+
error: sessionResult.error,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Step 2: 基于容器的登录检测(Unified API / containers:match)
|
|
76
|
+
const loginInput = {
|
|
77
|
+
sessionId: profileId,
|
|
78
|
+
serviceUrl: unifiedApiUrl || 'http://127.0.0.1:7701',
|
|
79
|
+
};
|
|
80
|
+
const loginResult = await ensureLoginExecute(loginInput);
|
|
81
|
+
// Workflow 本身不负责自动登录,仅把状态透出给上层
|
|
82
|
+
const success = loginResult.isLoggedIn;
|
|
83
|
+
return {
|
|
84
|
+
success,
|
|
85
|
+
profileId,
|
|
86
|
+
session: sessionResult,
|
|
87
|
+
login: loginResult,
|
|
88
|
+
error: success ? undefined : loginResult.error,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
profileId,
|
|
95
|
+
session: {
|
|
96
|
+
sessionId: '',
|
|
97
|
+
status: 'active',
|
|
98
|
+
currentPage: '',
|
|
99
|
+
error: error.message || String(error),
|
|
100
|
+
},
|
|
101
|
+
login: {
|
|
102
|
+
isLoggedIn: false,
|
|
103
|
+
loginMethod: 'manual_wait',
|
|
104
|
+
error: error.message || String(error),
|
|
105
|
+
},
|
|
106
|
+
error: error.message || String(error),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=XiaohongshuLoginWorkflow.js.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block: 评论命中(MatchComments)
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* - 基于容器提取“视口内评论”
|
|
6
|
+
* - 按可配置规则匹配关键字(任意一个/任意两个/必选过滤/排除词等)
|
|
7
|
+
* - 命中后高亮 + 截图留证(可选)
|
|
8
|
+
*
|
|
9
|
+
* 说明:
|
|
10
|
+
* - 不负责导航(safeUrl 由上层负责)
|
|
11
|
+
* - 不做 DOM click,所有交互均通过 container:operation / 系统能力
|
|
12
|
+
*/
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { promises as fs } from 'node:fs';
|
|
15
|
+
import { controllerAction, delay } from '../utils/controllerAction.js';
|
|
16
|
+
import { isLegacyKeywordRule, matchCommentText } from './helpers/commentMatcher.js';
|
|
17
|
+
import { matchCommentTextDsl } from './helpers/commentMatchDsl.js';
|
|
18
|
+
import { ensureCommentsOpened, extractVisibleComments, highlightCommentRow, isCommentEnd, scrollComments, } from './helpers/xhsComments.js';
|
|
19
|
+
import { resolveDownloadRoot, savePngBase64, takeScreenshotBase64 } from './helpers/evidence.js';
|
|
20
|
+
export async function execute(input) {
|
|
21
|
+
const { sessionId, rule, unifiedApiUrl = 'http://127.0.0.1:7701', maxScrolls = 12, maxItems = 60, maxMatches = 3, openComments = true, highlightOnFirstMatch = true, screenshotOnFirstMatch = true, noteId = `unknown-${Date.now()}`, env = 'debug', keyword = 'unknown', } = input;
|
|
22
|
+
const matches = [];
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
let rounds = 0;
|
|
25
|
+
let reachedBottom = false;
|
|
26
|
+
let firstMatchScreenshot = null;
|
|
27
|
+
try {
|
|
28
|
+
if (openComments) {
|
|
29
|
+
await ensureCommentsOpened(sessionId, unifiedApiUrl);
|
|
30
|
+
}
|
|
31
|
+
const outDir = path.join(resolveDownloadRoot(), 'xiaohongshu', env, keyword, 'comment-match', noteId);
|
|
32
|
+
for (let round = 0; round < maxScrolls; round += 1) {
|
|
33
|
+
rounds = round + 1;
|
|
34
|
+
const rows = await extractVisibleComments(sessionId, unifiedApiUrl, maxItems);
|
|
35
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
36
|
+
if (matches.length >= maxMatches)
|
|
37
|
+
break;
|
|
38
|
+
const r = rows[i] || {};
|
|
39
|
+
const text = String(r.text || '').trim();
|
|
40
|
+
if (!text)
|
|
41
|
+
continue;
|
|
42
|
+
const key = `${String(r.user_id || '')}:${text}`;
|
|
43
|
+
if (seen.has(key))
|
|
44
|
+
continue;
|
|
45
|
+
seen.add(key);
|
|
46
|
+
const matched = isLegacyKeywordRule(rule)
|
|
47
|
+
? (() => {
|
|
48
|
+
const m = matchCommentText(text, rule);
|
|
49
|
+
if (!m.ok)
|
|
50
|
+
return null;
|
|
51
|
+
return {
|
|
52
|
+
ok: true,
|
|
53
|
+
hits: Array.from(new Set([...m.anyHits, ...m.mustHits, ...m.shouldHits])),
|
|
54
|
+
score: m.shouldCount * 100 + m.anyCount + m.mustHits.length,
|
|
55
|
+
legacy: {
|
|
56
|
+
anyHits: m.anyHits,
|
|
57
|
+
mustHits: m.mustHits,
|
|
58
|
+
shouldHits: m.shouldHits,
|
|
59
|
+
anyCount: m.anyCount,
|
|
60
|
+
shouldCount: m.shouldCount,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
})()
|
|
64
|
+
: (() => {
|
|
65
|
+
const d = matchCommentTextDsl(text, rule);
|
|
66
|
+
if (!d.ok)
|
|
67
|
+
return null;
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
hits: d.hits,
|
|
71
|
+
score: d.score,
|
|
72
|
+
dsl: { requireHits: d.requireHits, preferHits: d.preferHits },
|
|
73
|
+
};
|
|
74
|
+
})();
|
|
75
|
+
if (!matched)
|
|
76
|
+
continue;
|
|
77
|
+
matches.push({
|
|
78
|
+
index: i,
|
|
79
|
+
userId: String(r.user_id || ''),
|
|
80
|
+
userName: String(r.user_name || ''),
|
|
81
|
+
content: text,
|
|
82
|
+
timestamp: String(r.timestamp || ''),
|
|
83
|
+
matched: {
|
|
84
|
+
hits: matched.hits,
|
|
85
|
+
score: matched.score,
|
|
86
|
+
legacy: Object.prototype.hasOwnProperty.call(matched, 'legacy') ? matched.legacy : undefined,
|
|
87
|
+
dsl: Object.prototype.hasOwnProperty.call(matched, 'dsl') ? matched.dsl : undefined,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
if (matches.length === 1 && highlightOnFirstMatch) {
|
|
91
|
+
const hl = await highlightCommentRow(sessionId, i, unifiedApiUrl, 'comment-match-first').catch(() => null);
|
|
92
|
+
await delay(450);
|
|
93
|
+
if (screenshotOnFirstMatch && hl?.inViewport === true && !firstMatchScreenshot) {
|
|
94
|
+
const base64 = await takeScreenshotBase64(sessionId, unifiedApiUrl);
|
|
95
|
+
if (base64) {
|
|
96
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
97
|
+
firstMatchScreenshot = await savePngBase64(base64, path.join(outDir, `match-first-${Date.now()}.png`));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (matches.length >= maxMatches)
|
|
103
|
+
break;
|
|
104
|
+
reachedBottom = await isCommentEnd(sessionId, unifiedApiUrl);
|
|
105
|
+
if (reachedBottom)
|
|
106
|
+
break;
|
|
107
|
+
await scrollComments(sessionId, unifiedApiUrl, 650).catch(() => { });
|
|
108
|
+
await delay(900);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
success: true,
|
|
112
|
+
rounds,
|
|
113
|
+
reachedBottom,
|
|
114
|
+
matches,
|
|
115
|
+
evidence: { firstMatchScreenshot },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
rounds,
|
|
122
|
+
reachedBottom,
|
|
123
|
+
matches,
|
|
124
|
+
evidence: { firstMatchScreenshot },
|
|
125
|
+
error: e?.message || String(e),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
// 尽量不破坏会话,仅清理一次高亮 channel(不强制)
|
|
130
|
+
await controllerAction('browser:execute', {
|
|
131
|
+
profile: sessionId,
|
|
132
|
+
script: `(() => {
|
|
133
|
+
try { window.__webautoRuntime?.highlight?.clear?.('comment-match-first'); } catch {}
|
|
134
|
+
return true;
|
|
135
|
+
})()`,
|
|
136
|
+
}, unifiedApiUrl).catch(() => null);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=MatchCommentsBlock.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 1 Block: 确保基础服务就绪
|
|
3
|
+
*/
|
|
4
|
+
export async function execute(input = {}) {
|
|
5
|
+
const { unifiedApiUrl = 'http://127.0.0.1:7701', browserServiceUrl = 'http://127.0.0.1:7704', timeout = 5000, } = input;
|
|
6
|
+
console.log('[Phase1EnsureServices] 检查服务状态...');
|
|
7
|
+
let unifiedApiOk = false;
|
|
8
|
+
try {
|
|
9
|
+
const res = await fetch(`${unifiedApiUrl}/health`, {
|
|
10
|
+
signal: AbortSignal.timeout(timeout),
|
|
11
|
+
});
|
|
12
|
+
unifiedApiOk = res.ok;
|
|
13
|
+
console.log(`[Phase1] Unified API: ${unifiedApiOk ? '✅' : '❌'}`);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.warn(`[Phase1] Unified API 不可达: ${err?.message || String(err)}`);
|
|
17
|
+
}
|
|
18
|
+
let browserServiceOk = false;
|
|
19
|
+
try {
|
|
20
|
+
const res = await fetch(`${browserServiceUrl}/health`, {
|
|
21
|
+
signal: AbortSignal.timeout(timeout),
|
|
22
|
+
});
|
|
23
|
+
browserServiceOk = res.ok;
|
|
24
|
+
console.log(`[Phase1] Browser Service: ${browserServiceOk ? '✅' : '❌'}`);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.warn(`[Phase1] Browser Service 不可达: ${err?.message || String(err)}`);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
unifiedApiOk,
|
|
31
|
+
browserServiceOk,
|
|
32
|
+
unifiedApiUrl,
|
|
33
|
+
browserServiceUrl,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=Phase1EnsureServicesBlock.js.map
|