refactor(boss): extract common.ts utilities, fix missing login detection#200
Merged
jackwener merged 3 commits intojackwener:mainfrom Mar 21, 2026
Merged
Conversation
- Add src/clis/boss/common.ts with shared helpers:
- bossFetch(): unified XHR template with auto cookie-expiry detection (code 7/37)
- navigateToChat()/navigateTo(): page navigation helpers
- checkAuth()/assertOk(): centralized login state validation
- fetchFriendList()/fetchRecommendList()/findFriendByUid(): data queries
- clickCandidateInList()/typeAndSendMessage(): UI automation helpers
- verbose(): conditional debug logging
- Refactor all 14 boss adapters to use common.ts:
- chatlist.ts: was missing cookie-expiry check (fixes #login-detect)
- chatmsg.ts: was missing cookie-expiry check (fixes #login-detect)
- Remaining 12 adapters: deduplicated XHR boilerplate and error handling
- Fix execution.ts: skip redundant pre-navigation for TS adapters
- TS adapters handle their own goto(), pre-navigating caused double
page loads and could trigger duplicate login prompts
- Pre-navigation preserved for YAML pipeline commands that need it
Net reduction: ~730 lines of duplicated code across boss adapters.
All 244 unit tests pass.
… restore docs - execution.ts: use site-specific skip (boss only) instead of isYamlPipeline. The original check skipped pre-navigation for ALL TS adapters, but weread, chaoxing, and others don't do their own goto() and depend on it. - common.ts: sanitize numericUid to digits-only and use JSON.stringify for safe interpolation in page.evaluate() (prevents template literal injection). - resume.ts: restore HTML structure doc comments (scraping selector guide). - send.ts: restore MQTT architecture note (explains why UI automation is needed).
- verbose() now checks both OPENCLI_VERBOSE and DEBUG=opencli, matching the original behavior from search.ts and detail.ts - Clarify skipPreNav comment with TODO for future adapter-level flag
49d5ba9 to
4404ae5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract shared logic from 14 boss adapters into
src/clis/boss/common.ts, fixing missing login state detection and eliminating ~730 lines of duplicated code.Problems Fixed
1. Missing Login Detection
chatlist.tsandchatmsg.tswere missing cookie-expiry checks (API code 7/37). All other boss commands had this check, but these two would throw a generic error instead of telling the user to re-login.2. Redundant Double Navigation
execution.tspre-navigated tohttps://www.zhipin.comfor all COOKIE-strategy commands, but every boss TS adapter already navigates to the correct page itself. This caused two page loads per command, potentially triggering duplicate login prompts.Changes
New:
src/clis/boss/common.tsShared utilities for all boss adapters:
navigateToChat(),navigateTo()checkAuth(),assertOk()bossFetch(page, url, opts)fetchFriendList(),fetchRecommendList(),findFriendByUid()clickCandidateInList(),typeAndSendMessage()requirePage(),verbose()Refactored: All 14 boss adapters
Each adapter now imports from
common.tsinstead of copy-pasting XHR templates, auth checks, and navigation logic.Fixed:
src/execution.tsSkip pre-navigation for TS adapters (they handle their own
goto()). Pre-navigation is preserved for YAML pipeline commands that need it.Stats