Skip to content

refactor(boss): extract common.ts utilities, fix missing login detection#200

Merged
jackwener merged 3 commits intojackwener:mainfrom
huangsen365:feat/boss-common-utils
Mar 21, 2026
Merged

refactor(boss): extract common.ts utilities, fix missing login detection#200
jackwener merged 3 commits intojackwener:mainfrom
huangsen365:feat/boss-common-utils

Conversation

@huangsen365
Copy link
Copy Markdown
Contributor

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.ts and chatmsg.ts were 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.ts pre-navigated to https://www.zhipin.com for 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.ts

Shared utilities for all boss adapters:

Category Functions Purpose
Navigation navigateToChat(), navigateTo() Unified page navigation
Auth checkAuth(), assertOk() Centralized code 7/37 cookie-expiry detection
API bossFetch(page, url, opts) Single function replacing 15-line XHR boilerplate
Data fetchFriendList(), fetchRecommendList(), findFriendByUid() Common data queries
UI clickCandidateInList(), typeAndSendMessage() Chat page UI automation
Misc requirePage(), verbose() Page assertion, conditional logging

Refactored: All 14 boss adapters

Each adapter now imports from common.ts instead of copy-pasting XHR templates, auth checks, and navigation logic.

Fixed: src/execution.ts

Skip pre-navigation for TS adapters (they handle their own goto()). Pre-navigation is preserved for YAML pipeline commands that need it.

Stats

  • -1221 lines removed from boss adapters
  • +493 lines (285 in common.ts + adapter imports)
  • Net: ~730 lines reduced (32% less code)
  • ✅ TypeScript: 0 errors
  • ✅ Unit tests: 244/244 passing

huangsen365 and others added 3 commits March 21, 2026 23:35
- 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
@jackwener jackwener force-pushed the feat/boss-common-utils branch from 49d5ba9 to 4404ae5 Compare March 21, 2026 15:37
@jackwener jackwener merged commit ae30763 into jackwener:main Mar 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants