Skip to content

Commit ae30763

Browse files
refactor(boss): extract common.ts utilities, fix missing login detection (#200)
* refactor(boss): extract common utilities, fix missing login detection - 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. * fix(review): fix execution.ts pre-nav regression, sanitize UID input, 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). * fix: restore DEBUG env support in verbose(), improve skipPreNav comment - 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 --------- Co-authored-by: jackwener <jakevingoo@gmail.com>
1 parent 3669a89 commit ae30763

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/clis/boss/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ export async function typeAndSendMessage(page: IPage, text: string): Promise<boo
278278
}
279279

280280
/**
281-
* Verbose log helper — only prints when OPENCLI_VERBOSE is set.
281+
* Verbose log helper — prints when OPENCLI_VERBOSE or DEBUG=opencli is set.
282282
*/
283283
export function verbose(msg: string): void {
284-
if (process.env.OPENCLI_VERBOSE) {
284+
if (process.env.OPENCLI_VERBOSE || process.env.DEBUG?.includes('opencli')) {
285285
console.error(`[opencli:boss] ${msg}`);
286286
}
287287
}

src/execution.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ export async function executeCommand(
123123
const BrowserFactory = getBrowserFactory();
124124
return browserSession(BrowserFactory, async (page) => {
125125
// Cookie/header strategies require same-origin context for credentialed fetch.
126-
// Skip pre-navigation for boss adapters — they all handle their own goto()
127-
// via common.ts, and pre-navigating would cause redundant double page loads.
128-
// Other TS adapters (weread, etc.) may still rely on this pre-navigation.
126+
// TS adapters that manage their own navigation (via common.ts helpers like
127+
// navigateToChat/navigateTo) should skip this pre-navigation to avoid
128+
// redundant double page loads. Currently only boss adapters do this.
129+
// TODO: replace site check with an adapter-level `skipPreNav` flag.
129130
const skipPreNav = cmd.site === 'boss';
130131
if (!skipPreNav && (cmd.strategy === Strategy.COOKIE || cmd.strategy === Strategy.HEADER) && cmd.domain) {
131132
try { await page.goto(`https://${cmd.domain}`); await page.wait(2); } catch {}

0 commit comments

Comments
 (0)