Files
jackwener__opencli/clis/boss/resume.ts
jakevin 4fe9a73ebc refactor: migrate adapter imports to package exports (#795)
* refactor: migrate adapter imports to package exports

Replace all relative imports (../../src/registry.js, ../../browser/cdp.js, etc.)
with package exports (@jackwener/opencli/registry, @jackwener/opencli/errors, etc.)
across all 484 adapter files.

This decouples adapter import resolution from directory structure:
- User CLIs in ~/.opencli/clis/ resolve via node_modules symlink
- Internal adapters resolve via Node.js self-referencing
- No more shim files needed for import resolution

Changes:
- package.json: add sub-path exports for all public modules
- clis/**: replace relative imports with @jackwener/opencli/...
- discovery.ts: simplify ensureUserCliCompatShims to symlink-only
- registry-api.ts: export CommandArgs type
- Remove root-level shim directories (browser/, download/, pipeline/)
- Remove shim entries from tsconfig.json include and package.json files

* test: add regression tests for package exports

Prevents regressions like #788/#791 by:
1. Scanning all adapter files for forbidden relative imports
   (../../src/, ../../browser/, etc.) — fails if any remain
2. Verifying every package.json export maps to an existing source file

18 new test cases.

* fix: use junction on Windows + broaden test patterns

- discovery.ts: use 'junction' symlink type on Windows (no admin required)
- package-exports.test.ts: generalize forbidden patterns to catch any
  depth of ../ traversal (not just ../../ and ../../../)

* fix: update stale vi.mock/importActual paths in adapter tests

Test files still used old relative paths for vi.mock() and
vi.importActual() calls. Updated 5 test files to use package exports.
Also broadened regression test patterns to catch mock/importActual paths.

* fix: use rm instead of unlink for symlink cleanup, add warn on failure

Addresses review feedback from Astro-Han:
- rm() handles both symlinks and stale directories (unlink fails on dirs)
- Log a warning when symlink creation fails instead of silent catch

* docs: update import examples to use package exports

Update all documentation, contributing guides, and skills to use
@jackwener/opencli/registry instead of ../../src/registry.js.

Without this, users following the docs would write adapters with
broken imports since the old shim files are no longer created.
2026-04-05 16:02:17 +08:00

158 lines
6.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* BOSS直聘 resume — view candidate resume/profile via chat page UI scraping (boss side).
*
* Flow: navigate to chat page → click on candidate → scrape the right panel info.
*
* Right panel HTML structure:
* .base-info-single-detial → name, gender, age, experience, degree
* .experience-content.time-list → time ranges (icon-base-info-work / icon-base-info-edu)
* .experience-content.detail-list → details (company·position / school·major·degree)
* .position-content → job being discussed + expectation
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { requirePage, navigateToChat, findFriendByUid, clickCandidateInList } from './utils.js';
cli({
site: 'boss',
name: 'resume',
description: 'BOSS直聘查看候选人简历(招聘端)',
domain: 'www.zhipin.com',
strategy: Strategy.COOKIE,
navigateBefore: false,
browser: true,
args: [
{ name: 'uid', required: true, positional: true, help: 'Encrypted UID of the candidate (from chatlist)' },
],
columns: [
'name', 'gender', 'age', 'experience', 'degree', 'active_time',
'work_history', 'education',
'job_chatting', 'expect',
],
func: async (page, kwargs) => {
requirePage(page);
await navigateToChat(page, 3);
const friend = await findFriendByUid(page, kwargs.uid, { maxPages: 5 });
if (!friend) throw new Error('未找到该候选人,请确认 uid 是否正确');
const numericUid = friend.uid;
const clicked = await clickCandidateInList(page, numericUid);
if (!clicked) {
throw new Error('无法在聊天列表中找到该用户,请确认聊天列表中有此人');
}
await page.wait({ time: 2 });
// Scrape the right panel
const resumeInfo: any = await page.evaluate(`
(() => {
const container = document.querySelector('.base-info-single-container') || document.querySelector('.base-info-content');
if (!container) return { error: 'no container found' };
const nameEl = container.querySelector('.base-name');
const name = nameEl ? nameEl.textContent.trim() : '';
let gender = '';
const detailDiv = container.querySelector('.base-info-single-detial');
if (detailDiv) {
const uses = detailDiv.querySelectorAll('use');
for (const u of uses) {
const href = u.getAttribute('xlink:href') || u.getAttribute('href') || '';
if (href.includes('icon-men')) { gender = '男'; break; }
if (href.includes('icon-women')) { gender = '女'; break; }
}
}
const activeEl = container.querySelector('.active-time');
const activeTime = activeEl ? activeEl.textContent.trim() : '';
let age = '', experience = '', degree = '';
if (detailDiv) {
for (const el of detailDiv.children) {
if (el.classList.contains('name-contet') || el.classList.contains('high-light-orange') ||
el.classList.contains('resume-btn-content') || el.classList.contains('label-remark-content') ||
el.classList.contains('base-info-item')) continue;
const text = el.textContent.trim();
if (!text) continue;
if (text.match(/\\d+岁/)) age = text;
else if (text.match(/年|经验|应届/)) experience = text;
else if (['博士', '硕士', '本科', '大专', '高中', '中专', '中技', '初中'].some(d => text.includes(d))) degree = text;
}
}
const workTimes = [], eduTimes = [], workDetails = [], eduDetails = [];
const timeList = container.querySelector('.experience-content.time-list');
if (timeList) {
for (const li of timeList.querySelectorAll('li')) {
const useEl = li.querySelector('use');
const href = useEl ? (useEl.getAttribute('xlink:href') || useEl.getAttribute('href') || '') : '';
const timeSpan = li.querySelector('.time');
const timeText = timeSpan ? timeSpan.textContent.trim() : li.textContent.trim();
if (href.includes('base-info-edu')) eduTimes.push(timeText);
else workTimes.push(timeText);
}
}
const detailList = container.querySelector('.experience-content.detail-list');
if (detailList) {
for (const li of detailList.querySelectorAll('li')) {
const useEl = li.querySelector('use');
const href = useEl ? (useEl.getAttribute('xlink:href') || useEl.getAttribute('href') || '') : '';
const valueSpan = li.querySelector('.value');
const valueText = valueSpan ? valueSpan.textContent.trim() : li.textContent.trim();
if (href.includes('base-info-edu')) eduDetails.push(valueText);
else workDetails.push(valueText);
}
}
const workHistory = [];
for (let i = 0; i < Math.max(workTimes.length, workDetails.length); i++) {
const parts = [];
if (workTimes[i]) parts.push(workTimes[i]);
if (workDetails[i]) parts.push(workDetails[i]);
if (parts.length) workHistory.push(parts.join(' '));
}
const education = [];
for (let i = 0; i < Math.max(eduTimes.length, eduDetails.length); i++) {
const parts = [];
if (eduTimes[i]) parts.push(eduTimes[i]);
if (eduDetails[i]) parts.push(eduDetails[i]);
if (parts.length) education.push(parts.join(' '));
}
const positionContent = container.querySelector('.position-content');
let jobChatting = '', expect = '';
if (positionContent) {
const posNameEl = positionContent.querySelector('.position-name');
if (posNameEl) jobChatting = posNameEl.textContent.trim();
const expectEl = positionContent.querySelector('.position-item.expect .value');
if (expectEl) expect = expectEl.textContent.trim();
}
return { name, gender, age, experience, degree, activeTime, workHistory, education, jobChatting, expect };
})()
`);
if (resumeInfo.error) {
throw new Error('无法获取简历面板: ' + resumeInfo.error);
}
return [{
name: resumeInfo.name || friend.name || '',
gender: resumeInfo.gender || '',
age: resumeInfo.age || '',
experience: resumeInfo.experience || '',
degree: resumeInfo.degree || '',
active_time: resumeInfo.activeTime || '',
work_history: (resumeInfo.workHistory || []).join('\\n') || '(未获取到)',
education: (resumeInfo.education || []).join('\\n') || '(未获取到)',
job_chatting: resumeInfo.jobChatting || '',
expect: resumeInfo.expect || '',
}];
},
});