@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: InitAutoScroll
|
|
3
|
+
*
|
|
4
|
+
* 初始化滚动状态机
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 初始化自动滚动
|
|
8
|
+
*
|
|
9
|
+
* @param input - 输入参数
|
|
10
|
+
* @returns Promise<InitAutoScrollOutput>
|
|
11
|
+
*/
|
|
12
|
+
export async function execute(input) {
|
|
13
|
+
const { sessionId, scrollStrategy = 'smooth', scrollDistance = 800, serviceUrl = 'http://127.0.0.1:7704' } = input;
|
|
14
|
+
const commandUrl = `${serviceUrl}/command`;
|
|
15
|
+
try {
|
|
16
|
+
const evalRes = await fetch(commandUrl, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
action: 'evaluate',
|
|
21
|
+
args: {
|
|
22
|
+
profileId: sessionId,
|
|
23
|
+
script: `
|
|
24
|
+
(() => {
|
|
25
|
+
window.__scrollState = {
|
|
26
|
+
initialized: true,
|
|
27
|
+
currentPosition: window.scrollY || 0,
|
|
28
|
+
strategy: '${scrollStrategy}',
|
|
29
|
+
distance: ${scrollDistance}
|
|
30
|
+
};
|
|
31
|
+
return window.__scrollState;
|
|
32
|
+
})()
|
|
33
|
+
`
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
const evalData = await evalRes.json();
|
|
38
|
+
if (!evalData.success) {
|
|
39
|
+
return {
|
|
40
|
+
scrollState: {
|
|
41
|
+
initialized: true,
|
|
42
|
+
currentPosition: 0,
|
|
43
|
+
strategy: scrollStrategy,
|
|
44
|
+
distance: scrollDistance
|
|
45
|
+
},
|
|
46
|
+
error: 'Failed to initialize scroll state'
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
scrollState: evalData.data
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
scrollState: {
|
|
56
|
+
initialized: true,
|
|
57
|
+
currentPosition: 0,
|
|
58
|
+
strategy: scrollStrategy,
|
|
59
|
+
distance: scrollDistance
|
|
60
|
+
},
|
|
61
|
+
error: `Init error: ${error.message}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=InitAutoScroll.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: LoadContainerDefinition
|
|
3
|
+
*
|
|
4
|
+
* 从容器定义文件加载容器配置
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
/**
|
|
9
|
+
* 加载容器定义
|
|
10
|
+
*
|
|
11
|
+
* @param input - 输入参数
|
|
12
|
+
* @returns Promise<LoadContainerDefinitionOutput>
|
|
13
|
+
*/
|
|
14
|
+
export async function execute(input) {
|
|
15
|
+
const { siteKey, containerId, containerLibraryRoot } = input;
|
|
16
|
+
if (!containerLibraryRoot) {
|
|
17
|
+
return {
|
|
18
|
+
definition: null,
|
|
19
|
+
metrics: { selectors: 0, operations: 0 },
|
|
20
|
+
error: '缺少容器库根目录'
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const containerPath = path.join(containerLibraryRoot, siteKey, ...containerId.split('.').filter(Boolean), 'container.json');
|
|
24
|
+
if (!fs.existsSync(containerPath)) {
|
|
25
|
+
return {
|
|
26
|
+
definition: null,
|
|
27
|
+
metrics: { selectors: 0, operations: 0 },
|
|
28
|
+
error: `容器定义不存在: ${containerPath}`
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const content = fs.readFileSync(containerPath, 'utf-8');
|
|
33
|
+
const containerDef = JSON.parse(content);
|
|
34
|
+
return {
|
|
35
|
+
definition: containerDef,
|
|
36
|
+
metrics: {
|
|
37
|
+
selectors: Array.isArray(containerDef.selectors) ? containerDef.selectors.length : 0,
|
|
38
|
+
operations: Array.isArray(containerDef.operations) ? containerDef.operations.length : 0
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
definition: null,
|
|
45
|
+
metrics: { selectors: 0, operations: 0 },
|
|
46
|
+
error: `加载容器定义失败: ${error.message}`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=LoadContainerDefinition.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: LoadContainerIndex
|
|
3
|
+
*
|
|
4
|
+
* 从容器索引文件加载站点配置
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
/**
|
|
8
|
+
* 加载容器索引
|
|
9
|
+
*
|
|
10
|
+
* @param context - 执行上下文
|
|
11
|
+
* @returns Promise<LoadContainerIndexOutput>
|
|
12
|
+
*/
|
|
13
|
+
export async function execute(input) {
|
|
14
|
+
const { containerIndexPath } = input;
|
|
15
|
+
if (!fs.existsSync(containerIndexPath)) {
|
|
16
|
+
return {
|
|
17
|
+
index: {},
|
|
18
|
+
metrics: { sites: 0, totalContainers: 0 },
|
|
19
|
+
error: '容器索引文件不存在'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const content = fs.readFileSync(containerIndexPath, 'utf-8');
|
|
24
|
+
const index = JSON.parse(content);
|
|
25
|
+
const sites = Object.keys(index);
|
|
26
|
+
const totalContainers = sites.reduce((sum, siteKey) => {
|
|
27
|
+
const site = index[siteKey];
|
|
28
|
+
return sum + (site?.containers?.length || 0);
|
|
29
|
+
}, 0);
|
|
30
|
+
return {
|
|
31
|
+
index,
|
|
32
|
+
metrics: { sites: sites.length, totalContainers }
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return {
|
|
37
|
+
index: {},
|
|
38
|
+
metrics: { sites: 0, totalContainers: 0 },
|
|
39
|
+
error: `加载索引失败: ${error.message}`
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=LoadContainerIndex.js.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocateAndGuardBlock - 全局自我定位与守卫模块
|
|
3
|
+
*
|
|
4
|
+
* 功能:
|
|
5
|
+
* 1. 基于容器匹配分析当前页面状态
|
|
6
|
+
* 2. 检测 hard stops (risk_control/login_guard/offsite)
|
|
7
|
+
* 3. 记录定位证据到 run-events.jsonl
|
|
8
|
+
* 4. 在关键决策点/迷失时调用,避免盲操作
|
|
9
|
+
*
|
|
10
|
+
* 使用场景:
|
|
11
|
+
* - Phase 脚本入口:确保处于预期状态
|
|
12
|
+
* - 关键操作后验证:导航/点击/滚动后确认状态
|
|
13
|
+
* - 迷失恢复:未命中预期容器时重新定位并执行最小恢复
|
|
14
|
+
*/
|
|
15
|
+
import { controllerAction } from './helpers/searchExecutor.js';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
function resolveRunEventsPath() {
|
|
20
|
+
const explicit = process.env.WEBAUTO_RUN_EVENTS;
|
|
21
|
+
if (explicit && explicit.trim())
|
|
22
|
+
return explicit.trim();
|
|
23
|
+
return path.join(os.homedir(), '.webauto', 'logs', 'run-events.jsonl');
|
|
24
|
+
}
|
|
25
|
+
async function emitRunEvent(event, data) {
|
|
26
|
+
try {
|
|
27
|
+
const filePath = resolveRunEventsPath();
|
|
28
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
29
|
+
const line = JSON.stringify({ ts: new Date().toISOString(), event, data });
|
|
30
|
+
fs.appendFileSync(filePath, `${line}\n`);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Best-effort logging; failure should not block workflow execution.
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function findContainerNode(tree, targetId) {
|
|
37
|
+
if (!tree)
|
|
38
|
+
return null;
|
|
39
|
+
const root = tree.container || tree.containers?.[0];
|
|
40
|
+
if (!root)
|
|
41
|
+
return null;
|
|
42
|
+
function search(node) {
|
|
43
|
+
if (node.id === targetId)
|
|
44
|
+
return node;
|
|
45
|
+
if (node.children) {
|
|
46
|
+
for (const child of node.children) {
|
|
47
|
+
const found = search(child);
|
|
48
|
+
if (found)
|
|
49
|
+
return found;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return search(root);
|
|
55
|
+
}
|
|
56
|
+
function extractContainerRect(node) {
|
|
57
|
+
return node.match?.nodes?.[0]?.rect || null;
|
|
58
|
+
}
|
|
59
|
+
function detectHardStop(containerTree, url) {
|
|
60
|
+
const lowerUrl = url.toLowerCase();
|
|
61
|
+
// 风控页面检测
|
|
62
|
+
if (lowerUrl.includes('/website-login/captcha') ||
|
|
63
|
+
lowerUrl.includes('verifyuuid=') ||
|
|
64
|
+
lowerUrl.includes('/website-login/verify') ||
|
|
65
|
+
lowerUrl.includes('/website-login/security')) {
|
|
66
|
+
return 'risk_control';
|
|
67
|
+
}
|
|
68
|
+
// 登录保护检测
|
|
69
|
+
const hasLoginGuard = findContainerNode(containerTree, 'xiaohongshu_login.login_guard');
|
|
70
|
+
if (hasLoginGuard)
|
|
71
|
+
return 'login_guard';
|
|
72
|
+
// 站外检测
|
|
73
|
+
if (!url.includes('xiaohongshu.com'))
|
|
74
|
+
return 'offsite';
|
|
75
|
+
return 'none';
|
|
76
|
+
}
|
|
77
|
+
export async function execute(input) {
|
|
78
|
+
const { sessionId, controllerUrl = process.env.WEBAUTO_UNIFIED_API_URL || 'http://127.0.0.1:7701', url, expectedContainers = [], invalidateCache = false, maxDepth = 3, maxChildren = 10, rootSelector, evidence = true, } = input;
|
|
79
|
+
const startTime = Date.now();
|
|
80
|
+
// 记录定位开始
|
|
81
|
+
if (evidence) {
|
|
82
|
+
await emitRunEvent('locate_start', {
|
|
83
|
+
sessionId,
|
|
84
|
+
expectedContainers,
|
|
85
|
+
url,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const matchResult = await controllerAction(controllerUrl, 'containers:match', {
|
|
90
|
+
profile: sessionId,
|
|
91
|
+
url,
|
|
92
|
+
maxDepth,
|
|
93
|
+
maxChildren,
|
|
94
|
+
rootSelector,
|
|
95
|
+
cache: true,
|
|
96
|
+
invalidateCache,
|
|
97
|
+
});
|
|
98
|
+
const snapshot = matchResult?.snapshot || matchResult?.data?.snapshot;
|
|
99
|
+
const containerTree = snapshot?.container_tree;
|
|
100
|
+
const currentUrl = snapshot?.url || url || '';
|
|
101
|
+
const cache = matchResult?.cache || matchResult?.data?.cache || { enabled: false, hit: false, ageMs: null, ttlMs: 5000 };
|
|
102
|
+
// 检测 hard stops
|
|
103
|
+
const hardStop = detectHardStop(containerTree, currentUrl);
|
|
104
|
+
const needManualIntervention = hardStop !== 'none';
|
|
105
|
+
// 检测期望容器
|
|
106
|
+
const matchedContainers = [];
|
|
107
|
+
for (const id of expectedContainers) {
|
|
108
|
+
const node = findContainerNode(containerTree, id);
|
|
109
|
+
if (node) {
|
|
110
|
+
matchedContainers.push(id);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const located = expectedContainers.length === 0
|
|
114
|
+
? true // 无期望容器时,只要有任何容器匹配就算定位成功
|
|
115
|
+
: matchedContainers.length > 0;
|
|
116
|
+
const duration = Date.now() - startTime;
|
|
117
|
+
// 记录定位结果
|
|
118
|
+
if (evidence) {
|
|
119
|
+
await emitRunEvent('locate_result', {
|
|
120
|
+
sessionId,
|
|
121
|
+
url: currentUrl,
|
|
122
|
+
expectedContainers,
|
|
123
|
+
matchedContainers,
|
|
124
|
+
located,
|
|
125
|
+
hardStop,
|
|
126
|
+
needManualIntervention,
|
|
127
|
+
cache,
|
|
128
|
+
duration,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
located,
|
|
133
|
+
url: currentUrl,
|
|
134
|
+
matchedContainers,
|
|
135
|
+
hardStop,
|
|
136
|
+
needManualIntervention,
|
|
137
|
+
cache,
|
|
138
|
+
duration,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
const duration = Date.now() - startTime;
|
|
143
|
+
if (evidence) {
|
|
144
|
+
await emitRunEvent('locate_error', {
|
|
145
|
+
sessionId,
|
|
146
|
+
expectedContainers,
|
|
147
|
+
error: err?.message || String(err),
|
|
148
|
+
duration,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 检查是否处于预期状态,若不是则抛出错误
|
|
156
|
+
*/
|
|
157
|
+
export function guardOrThrow(output, context) {
|
|
158
|
+
if (output.needManualIntervention) {
|
|
159
|
+
throw new Error(`[${context}] Hard stop detected: ${output.hardStop}. URL: ${output.url}. Manual intervention required.`);
|
|
160
|
+
}
|
|
161
|
+
if (!output.located) {
|
|
162
|
+
throw new Error(`[${context}] Locate failed. Expected containers not found. URL: ${output.url}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 检查是否包含指定容器
|
|
167
|
+
*/
|
|
168
|
+
export function hasContainer(output, containerId) {
|
|
169
|
+
return output.matchedContainers.includes(containerId);
|
|
170
|
+
}
|
|
171
|
+
export default {
|
|
172
|
+
execute,
|
|
173
|
+
guardOrThrow,
|
|
174
|
+
hasContainer,
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=LocateAndGuardBlock.js.map
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: LoginRecoveryBlock
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* - 检测当前登录状态
|
|
6
|
+
* - 若未登录,尝试自动恢复(调用 Phase1 登录流程)
|
|
7
|
+
* - 提供明确的失败原因和恢复建议
|
|
8
|
+
* - 用于长时间运行任务中的登录状态保障
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { logControllerActionError, logControllerActionResult, logControllerActionStart, } from './helpers/operationLogger.js';
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
const repoRoot = path.resolve(__dirname, '..', '..', '..');
|
|
17
|
+
export async function execute(input) {
|
|
18
|
+
const { sessionId, serviceUrl = 'http://127.0.0.1:7701', maxRetries = 2, autoRecover = true } = input;
|
|
19
|
+
const controllerUrl = `${serviceUrl}/v1/controller/action`;
|
|
20
|
+
async function controllerAction(action, payload = {}) {
|
|
21
|
+
const opId = logControllerActionStart(action, payload, { source: 'LoginRecoveryBlock' });
|
|
22
|
+
try {
|
|
23
|
+
const res = await fetch(controllerUrl, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: { 'Content-Type': 'application/json' },
|
|
26
|
+
body: JSON.stringify({ action, payload }),
|
|
27
|
+
signal: AbortSignal.timeout ? AbortSignal.timeout(10000) : undefined
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok) {
|
|
30
|
+
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
|
|
31
|
+
}
|
|
32
|
+
const data = await res.json();
|
|
33
|
+
const result = data.data || data;
|
|
34
|
+
logControllerActionResult(opId, action, result, { source: 'LoginRecoveryBlock' });
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
logControllerActionError(opId, action, error, payload, { source: 'LoginRecoveryBlock' });
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 通过容器匹配检测登录状态(login_anchor / login_guard)
|
|
44
|
+
* - logged_in: 命中任意 *.login_anchor
|
|
45
|
+
* - not_logged_in: 命中 xiaohongshu_login.login_guard
|
|
46
|
+
* - uncertain: 未命中上述任何容器
|
|
47
|
+
* - error: containers:match 调用异常
|
|
48
|
+
*/
|
|
49
|
+
async function checkLoginByContainer() {
|
|
50
|
+
try {
|
|
51
|
+
// 先拿当前 URL,再显式传给 containers:match,避免因为默认 URL(如 about:blank)
|
|
52
|
+
// 找不到 definitions 而直接 400。
|
|
53
|
+
const currentUrl = await getCurrentUrl();
|
|
54
|
+
const matchPayload = {
|
|
55
|
+
profile: sessionId,
|
|
56
|
+
maxDepth: 3,
|
|
57
|
+
maxChildren: 8
|
|
58
|
+
};
|
|
59
|
+
if (currentUrl) {
|
|
60
|
+
matchPayload.url = currentUrl;
|
|
61
|
+
}
|
|
62
|
+
const matchResult = await controllerAction('containers:match', matchPayload);
|
|
63
|
+
const snapshot = matchResult?.snapshot || matchResult;
|
|
64
|
+
const tree = snapshot?.container_tree;
|
|
65
|
+
if (!tree) {
|
|
66
|
+
return { status: 'uncertain', detail: 'no_container_tree' };
|
|
67
|
+
}
|
|
68
|
+
const findContainer = (node, pattern) => {
|
|
69
|
+
if (!node)
|
|
70
|
+
return null;
|
|
71
|
+
if (pattern.test(node.id || node.defId || ''))
|
|
72
|
+
return node;
|
|
73
|
+
if (Array.isArray(node.children)) {
|
|
74
|
+
for (const child of node.children) {
|
|
75
|
+
const found = findContainer(child, pattern);
|
|
76
|
+
if (found)
|
|
77
|
+
return found;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
const loginAnchor = findContainer(tree, /\.login_anchor$/);
|
|
83
|
+
if (loginAnchor) {
|
|
84
|
+
return {
|
|
85
|
+
status: 'logged_in',
|
|
86
|
+
detail: loginAnchor.id || loginAnchor.defId
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const loginGuard = findContainer(tree, /xiaohongshu_login\.login_guard$/);
|
|
90
|
+
if (loginGuard) {
|
|
91
|
+
return {
|
|
92
|
+
status: 'not_logged_in',
|
|
93
|
+
detail: loginGuard.id || loginGuard.defId
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
status: 'uncertain',
|
|
98
|
+
detail: 'no_login_anchor_or_guard'
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
console.warn('[LoginRecovery] 容器检测异常:', err.message);
|
|
103
|
+
return { status: 'error', detail: err.message || 'containers:match error' };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function getCurrentUrl() {
|
|
107
|
+
try {
|
|
108
|
+
const data = await controllerAction('browser:execute', {
|
|
109
|
+
profile: sessionId,
|
|
110
|
+
script: 'location.href'
|
|
111
|
+
});
|
|
112
|
+
const url = data?.result || data?.data?.result || '';
|
|
113
|
+
console.log('[LoginRecovery] getCurrentUrl:', url || '<empty>');
|
|
114
|
+
return url;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
console.warn('[LoginRecovery] getCurrentUrl failed');
|
|
118
|
+
return '';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 调用 Phase1 登录脚本
|
|
123
|
+
*/
|
|
124
|
+
async function runPhase1Login() {
|
|
125
|
+
console.log('[LoginRecovery] 检测到未登录,尝试自动恢复...');
|
|
126
|
+
const phase1Script = path.join(repoRoot, 'scripts', 'xiaohongshu', 'tests', 'phase1-session-login-with-gate.mjs');
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
const child = spawn('node', [phase1Script], {
|
|
129
|
+
cwd: repoRoot,
|
|
130
|
+
stdio: 'inherit', // 让用户看到登录过程
|
|
131
|
+
detached: false
|
|
132
|
+
});
|
|
133
|
+
child.on('exit', async (code) => {
|
|
134
|
+
if (code === 0) {
|
|
135
|
+
console.log('[LoginRecovery] Phase1 登录脚本执行完成');
|
|
136
|
+
// 等待几秒让页面稳定
|
|
137
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
138
|
+
// 重新验证登录状态
|
|
139
|
+
const loggedIn = await checkLoginByContainer();
|
|
140
|
+
resolve(loggedIn.status === 'logged_in');
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.error('[LoginRecovery] Phase1 登录脚本失败,退出码:', code);
|
|
144
|
+
resolve(false);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
child.on('error', (err) => {
|
|
148
|
+
console.error('[LoginRecovery] 启动 Phase1 脚本失败:', err.message);
|
|
149
|
+
resolve(false);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// 主流程
|
|
154
|
+
try {
|
|
155
|
+
console.log('[LoginRecovery] 检查登录状态...');
|
|
156
|
+
const state = await checkLoginByContainer();
|
|
157
|
+
if (state.status === 'logged_in') {
|
|
158
|
+
console.log('[LoginRecovery] ✅ 已检测到登录态(login_anchor=', state.detail || 'unknown', ')');
|
|
159
|
+
return {
|
|
160
|
+
success: true,
|
|
161
|
+
loggedIn: true,
|
|
162
|
+
recovered: false
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (state.status === 'uncertain') {
|
|
166
|
+
// 状态不确定时不强行自动登录,交给上层脚本决定下一步动作
|
|
167
|
+
console.warn('[LoginRecovery] ⚠️ 登录状态不确定(容器未命中 login_anchor/login_guard)');
|
|
168
|
+
return {
|
|
169
|
+
success: false,
|
|
170
|
+
loggedIn: false,
|
|
171
|
+
recovered: false,
|
|
172
|
+
error: 'login_status_uncertain',
|
|
173
|
+
suggestion: '请先运行: node scripts/xiaohongshu/tests/status-v2.mjs 或手动检查浏览器页面上的登录状态'
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (state.status === 'error') {
|
|
177
|
+
// 容器匹配本身失败时,尝试用 URL 做一次弱判断,避免因为单次超时就阻塞所有后续流程。
|
|
178
|
+
const url = await getCurrentUrl();
|
|
179
|
+
if (url && url.includes('xiaohongshu.com') && !url.includes('/login')) {
|
|
180
|
+
console.warn('[LoginRecovery] ⚠️ 容器检测失败,但当前仍在小红书非登录页,暂按“已登录”处理(弱判断,仅供长任务继续执行)');
|
|
181
|
+
return {
|
|
182
|
+
success: true,
|
|
183
|
+
loggedIn: true,
|
|
184
|
+
recovered: false,
|
|
185
|
+
error: `登录容器检测失败: ${state.detail}`,
|
|
186
|
+
suggestion: '建议在前台或通过 scripts/xiaohongshu/tests/status-v2.mjs 再次确认登录锚点是否正常命中'
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
loggedIn: false,
|
|
192
|
+
recovered: false,
|
|
193
|
+
error: `登录容器检测失败: ${state.detail}`,
|
|
194
|
+
suggestion: '请检查 Unified API / Browser Service 状态,或手动运行 Phase1 登录脚本'
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// 走到这里说明明确未登录(命中 login_guard)
|
|
198
|
+
if (!autoRecover) {
|
|
199
|
+
return {
|
|
200
|
+
success: true,
|
|
201
|
+
loggedIn: false,
|
|
202
|
+
recovered: false,
|
|
203
|
+
error: '未检测到登录态',
|
|
204
|
+
suggestion: '请先运行: node scripts/xiaohongshu/tests/phase1-session-login-with-gate.mjs'
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// 尝试自动恢复
|
|
208
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
209
|
+
console.log(`[LoginRecovery] 自动恢复尝试 ${i + 1}/${maxRetries}`);
|
|
210
|
+
const recovered = await runPhase1Login();
|
|
211
|
+
if (recovered) {
|
|
212
|
+
console.log('[LoginRecovery] ✅ 登录恢复成功');
|
|
213
|
+
return {
|
|
214
|
+
success: true,
|
|
215
|
+
loggedIn: true,
|
|
216
|
+
recovered: true
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (i < maxRetries - 1) {
|
|
220
|
+
console.log('[LoginRecovery] 等待5秒后重试...');
|
|
221
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
success: false,
|
|
226
|
+
loggedIn: false,
|
|
227
|
+
recovered: false,
|
|
228
|
+
error: '自动登录恢复失败',
|
|
229
|
+
suggestion: '请手动运行: node scripts/xiaohongshu/tests/phase1-session-login-with-gate.mjs'
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
return {
|
|
234
|
+
success: false,
|
|
235
|
+
loggedIn: false,
|
|
236
|
+
recovered: false,
|
|
237
|
+
error: `登录检查异常: ${err.message}`,
|
|
238
|
+
suggestion: '请检查会话状态和网络连接'
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=LoginRecoveryBlock.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: MatchContainers
|
|
3
|
+
*
|
|
4
|
+
* 执行容器匹配
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 执行容器匹配
|
|
8
|
+
*
|
|
9
|
+
* @param input - 输入参数
|
|
10
|
+
* @returns Promise<MatchContainersOutput>
|
|
11
|
+
*/
|
|
12
|
+
export async function execute(input) {
|
|
13
|
+
const { sessionId, rootSelector, serviceUrl = 'http://127.0.0.1:7704' } = input;
|
|
14
|
+
const commandUrl = `${serviceUrl}/command`;
|
|
15
|
+
try {
|
|
16
|
+
const domRes = await fetch(commandUrl, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
action: 'evaluate',
|
|
21
|
+
args: {
|
|
22
|
+
profileId: sessionId,
|
|
23
|
+
script: `
|
|
24
|
+
(() => {
|
|
25
|
+
const root = document.querySelector('${rootSelector || "body"}');
|
|
26
|
+
if (!root) return { error: 'Root not found' };
|
|
27
|
+
return {
|
|
28
|
+
tag: root.tagName,
|
|
29
|
+
classes: Array.from(root.classList),
|
|
30
|
+
html: root.outerHTML.slice(0, 1000)
|
|
31
|
+
};
|
|
32
|
+
})()
|
|
33
|
+
`
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
const domData = await domRes.json();
|
|
38
|
+
if (!domData.success) {
|
|
39
|
+
return {
|
|
40
|
+
snapshot: { root: null, timestamp: 0 },
|
|
41
|
+
matchCount: 0,
|
|
42
|
+
rootContainerId: '',
|
|
43
|
+
error: `Failed to access DOM: ${domData.error}`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
snapshot: {
|
|
48
|
+
root: domData.data,
|
|
49
|
+
timestamp: Date.now()
|
|
50
|
+
},
|
|
51
|
+
matchCount: 1,
|
|
52
|
+
rootContainerId: 'matched.container.id'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
snapshot: { root: null, timestamp: 0 },
|
|
58
|
+
matchCount: 0,
|
|
59
|
+
rootContainerId: '',
|
|
60
|
+
error: `Match error: ${error.message}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=MatchContainers.js.map
|