ilml-plugin-linkedin 1.20.9 → 1.20.11
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/CHANGELOG.md +11 -0
- package/dist/messageBot.mjs +57 -57
- package/dist/readPost.mjs +12 -10
- package/dist/run.mjs +27 -27
- package/dist/scout.mjs +31 -29
- package/dist/version.mjs +1 -1
- package/ilml-plugin.json +1 -1
- package/package.json +2 -2
package/dist/scout.mjs
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
|
-
var Qt=Object.defineProperty;var ue=(e,t)=>{for(var o in t)Qt(e,o,{get:t[o],enumerable:!0})};import po from"puppeteer";import{addExtra as mo}from"puppeteer-extra";import ho from"puppeteer-extra-plugin-stealth";import O from"fs";import B from"path";var Xt="cookies.json";function Be(){let e=process.env.ILML_SCOPE_DIR;return e?B.join(e,"plugins-state","linkedin","cookies.json"):Xt}function Je(){let e=Be();if(!O.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=O.readFileSync(e,"utf-8")}catch(n){throw new Error(`Failed to read cookies at ${e}: ${n.message}. Run: ilml linkedin login`)}let o;try{o=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(o)||o.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return o}function He(){return O.existsSync(Be())}function Zt(){let e=process.env.ILML_SCOPE_DIR;return e?B.join(e,"plugins-state","linkedin"):"."}function We(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function eo(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?We(t[1]):"default"}function Ge(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return O.existsSync(t)||O.mkdirSync(t,{recursive:!0}),B.resolve(t);let o=We(e||eo()),n=B.join(Zt(),"chrome-profile",o);return O.existsSync(n)||O.mkdirSync(n,{recursive:!0}),B.resolve(n)}var Ve=".ilml-seeded";function Ke(e){return!O.existsSync(B.join(e,Ve))}function Ye(e){try{O.writeFileSync(B.join(e,Ve),new Date().toISOString())}catch{}}function ze(e){let t=0;for(let o of["SingletonLock","SingletonCookie","SingletonSocket"])try{O.rmSync(B.join(e,o),{force:!0}),t++}catch{}return t}async function E(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function Qe(e,t,{timeout:o=45e3,poll:n=1e3,label:r="page"}={}){let i=Date.now();for(;Date.now()-i<o;){try{if(await e.evaluate(c=>!!document.querySelector(c),t)){let c=Date.now()-i;return c>6e3&&console.log(` (waited ${Math.round(c/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(s=>setTimeout(s,n))}return!1}var to=/\/authwall|\/login|\/checkpoint|\/uas\/login/;function ve(e){return to.test(e||"")}import{getPluginConfig as oo}from"@ilivemylife/graph-sdk";var no=await oo();for(let[e,t]of Object.entries(no))process.env[e]===void 0&&(process.env[e]=t);var ro=process.env.LINKEDIN_NAME,G=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Wn=Object.freeze(new Set([G.DRAFT,G.CONFIRMED,G.NEEDS_REVIEW])),so=Object.freeze(new Set([G.DRAFT,G.CONFIRMED,G.REJECTED,G.NEEDS_REVIEW]));import ke from"fs";import io from"path";var co={headless:!1,defaultViewport:null,protocolTimeout:3e5},ee=new Set,Xe=!1;async function fe(){let e=[...ee].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});ee.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function lo(){if(Xe)return;Xe=!0;let e=t=>async()=>{await fe(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await fe(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await fe(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await fe(),process.exit(0))}),process.on("exit",()=>{for(let t of ee)try{let o=t.process&&t.process();o&&o.kill("SIGKILL")}catch{}})}function Ae(e){return io.join(e,".ilml-browser-session.json")}function ot(e,t={}){try{ke.writeFileSync(Ae(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function ao(e,t){try{let o=t.wsEndpoint&&t.wsEndpoint();ot(e,o?{wsEndpoint:o}:{})}catch{}}function uo(e){let t=nt(e);t&&t.ownerPid===process.pid&&Z(e)}function Z(e){try{ke.rmSync(Ae(e),{force:!0})}catch{}}function nt(e){try{return JSON.parse(ke.readFileSync(Ae(e),"utf-8"))}catch{return null}}function Ze(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function et(e,t,o){let n,r=new Promise(s=>{n=setTimeout(()=>s(o),t)}),i=Promise.resolve(e).then(s=>(clearTimeout(n),s),s=>{throw clearTimeout(n),s});return Promise.race([i,r])}async function tt(e,t,{probeTimeoutMs:o=4e3}={}){let n=nt(t);if(!n)return"free";if(!n.wsEndpoint)return n.ownerPid&&n.ownerPid!==process.pid&&Ze(n.ownerPid)?"live":(Z(t),"free");let r=Symbol("timeout"),i=e.connect({browserWSEndpoint:n.wsEndpoint,defaultViewport:null}).catch(()=>null),s=await et(i,o,r);if(s===r)return i.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!s)return Z(t),"free";if(Ze(n.ownerPid)){try{s.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await et(s.close().then(()=>!0).catch(()=>!1),o,!1))return Z(t),"free";try{s.disconnect()}catch{}return"live"}function fo(e,t){e&&(lo(),ee.add(e),e.on("disconnected",()=>{ee.delete(e),t&&Z(t)}))}async function rt(e,t={}){let o=Ge(),n={...co,...t,userDataDir:o},r=`Could not open the LinkedIn automation Chrome profile at ${o}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await tt(e,o)==="live")throw new Error(r);ot(o);let i;try{i=await e.launch(n)}catch{if(await tt(e,o)==="live")throw new Error(r);ze(o);try{i=await e.launch(n)}catch(c){throw uo(o),new Error(`Could not open the LinkedIn automation Chrome profile at ${o}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${c.message})`)}}return fo(i,o),ao(o,i),{browser:i,profileDir:o,needsSeed:Ke(o)}}async function st(e,t){if(!t||!t.needsSeed)return!1;if(!He())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...Je()),Ye(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var it=mo(po);it.use(ho());async function ct(){let{browser:e,profileDir:t,needsSeed:o}=await rt(it),n=await e.newPage();return await n.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await st(n,{profileDir:t,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:n}}async function lt(e){let t=[".jobs-search-results-list",".scaffold-layout__list-container",".jobs-search-two-pane__results","div.jobs-search-results-list"];return await e.evaluate(async n=>{let r=null,i=null;for(let h of n)if(r=document.querySelector(h),r){i=h;break}if(!r){let h=document.querySelector("li.scaffold-layout__list-item");if(h){let u=h.parentElement;for(;u&&u!==document.body;){if(u.scrollHeight>u.clientHeight){r=u,i="parent of li.scaffold-layout__list-item";break}u=u.parentElement}}}if(!r)return{found:!1,triedSelectors:n};let s=r.scrollTop,c=300,l=300,f=50,d=0;for(;d<f&&(r.scrollBy(0,c),await new Promise(h=>setTimeout(h,l)),!(r.scrollTop+r.clientHeight>=r.scrollHeight));)d++;return{found:!0,usedSelector:i,initialScroll:s,finalScroll:r.scrollTop,scrollHeight:r.scrollHeight,attempts:d}},t)}async function at(e,{easyApplyOnly:t=!0}={}){let o=await e.evaluate(()=>{let n=document.querySelectorAll("li.scaffold-layout__list-item");return Array.from(n).map(r=>{let s=(r.querySelector(".job-card-list__footer-wrapper")?.innerText??"").includes("Easy Apply"),c=r.querySelector("a.job-card-container__link");if(c){let l=c.getAttribute("href").split("?")[0],f=r.querySelector(".job-card-list__title--link")?.getAttribute("aria-label")?.replace(/ with verification$/,""),d=r.querySelector(".artdeco-entity-lockup__subtitle")?.innerText.trim(),h=r.querySelector(".artdeco-entity-lockup__caption")?.innerText.trim(),u=r.querySelector(".artdeco-entity-lockup__metadata")?.innerText.trim();return{id:l,isEasyApply:s,applyType:s?"easy-apply":"external",dataId:c.getAttribute("data-control-id"),href:`https://linkedin.com${l}`,jobTitle:f,companyName:d,location:h,salary:u||null,jobLink:s?c.href:null}}return{isEasyApply:!1}})});return t?o.filter(n=>n.isEasyApply&&n.href):o.filter(n=>n.href)}async function ut(e){let t=await e.evaluate(()=>{let o=document.querySelector('button[aria-label="View next page"]')||document.querySelector(".jobs-search-pagination__button--next");if(o&&!o.disabled){let n=document.querySelector(".jobs-search-pagination__page-state")?.textContent?.trim();return o.click(),{success:!0,pageState:n}}return{success:!1,reason:"No next page button found"}});return console.log(" Pagination:",t.success?t.pageState:t.reason),t.success&&await E(2e3),t.success}async function ft(e,t){let o=e.url();if(o.includes("/jobs/"))return!1;if(ve(o)){if(!await Qe(e,".scaffold-layout__main, main.scaffold-layout__main, .jobs-search-results-list",{timeout:45e3,label:"job search"})&&ve(e.url()))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");if(e.url().includes("/jobs/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await E(2e3)),!e.url().includes("/jobs/"))throw new Error(`Session expired \u2014 could not return to job search (landed on ${e.url().slice(0,60)}). Run: ilml linkedin login`);return!0}console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to job search..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await E(3e3);let n=e.url();if(!n.includes("/jobs/"))throw new Error(`Could not return to job search. Current URL: ${n.slice(0,80)}`);return console.log(" Recovered to job search page"),!0}async function pt(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,o=t.querySelector(".hirer-card__hirer-information");if(o){let s=o.querySelector('a[href*="/in/"]'),c=o.querySelector(".jobs-poster__name")||o.querySelector("strong")||o.querySelector('[class*="name"]');if(s)return{name:c?.textContent?.trim()||s.textContent?.trim(),profileUrl:s.href?.split("?")[0],source:"hiring_team"}}let n=t.querySelector(".jobs-poster__name");if(n){let s=n.closest('a[href*="/in/"]')||n.parentElement?.querySelector('a[href*="/in/"]')||n.parentElement?.parentElement?.querySelector('a[href*="/in/"]');if(s)return{name:n.textContent?.trim(),profileUrl:s.href?.split("?")[0],source:"poster_name"}}let r=t.querySelector(".job-details-people-who-can-help__section--two-pane")||t.querySelector('[class*="people-who-can-help"]');if(r){let s=r.querySelector('a[href*="/in/"]');if(s)return{name:(r.querySelector(".jobs-poster__name")||r.querySelector("strong"))?.textContent?.trim()||s.textContent?.trim(),profileUrl:s.href?.split("?")[0],source:"people_section"}}let i=t.querySelectorAll('a[href*="/in/"]');for(let s of i){let c=s.textContent?.trim();if(c&&c.length>3&&!["View","Connect","Follow","Message","Apply","Save"].includes(c))return{name:c,profileUrl:s.href?.split("?")[0],source:"details_link"}}return null})}async function dt(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,n=(t.querySelector(".jobs-description__content")||t.querySelector(".jobs-box__html-content")||t.querySelector(".jobs-description"))?.innerText?.trim()||"",r={},i=t.querySelectorAll(".jobs-unified-top-card__job-insight, li.job-criteria__item");for(let W of i){let we=W.querySelector(".job-criteria__subheader")?.textContent?.trim(),qe=W.querySelector(".job-criteria__text")?.textContent?.trim();we&&qe&&(r[we.toLowerCase()]=qe)}let s=["Java","Python","JavaScript","TypeScript","React","Angular","Vue","Node.js","C#",".NET","C\\+\\+","Go","Rust","Scala","Kotlin","AWS","Azure","GCP","Docker","Kubernetes","Terraform","SQL","PostgreSQL","MongoDB","Redis","Kafka","RabbitMQ","Spring","Django","Flask","Express","Next.js","CI/CD","Jenkins","GitHub Actions","GraphQL","REST","Microservices","Machine Learning","AI","Data Engineering","Spark","Hadoop","Snowflake","Databricks","Airflow","iOS","Android","React Native","Flutter","Agile","Scrum","DevOps","SRE"],c=[];for(let W of s)new RegExp("\\b"+W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i").test(n)&&c.push(W.replace(/\\\+/g,"+"));let f=t.querySelector('.jobs-company__box, [class*="jobs-company"], [class*="company-card"]')?.innerText?.trim()?.slice(0,1e3)||null,h=t.querySelector('a.jobs-apply-button[href], a[data-tracking-control-name="public_jobs_apply-link-offsite_sign-up"]')?.getAttribute("href")||null,u=t.querySelector(".job-details-jobs-unified-top-card__company-name, .jobs-unified-top-card__company-name"),p=u?.innerText?.trim()||null,S=(u?.querySelector('a[href*="/company/"]')||t.querySelector('a[href*="/company/"]'))?.getAttribute("href")?.split("?")[0]||null,g=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container")?.innerText?.trim()||"",M=g.match(/(\d+\s+(?:hour|day|week|month)s?\s+ago|Reposted|Just now)/i)?.[0]||null,U=g.match(/(\d[\d,]*)\s+applicant/i),ge=U?parseInt(U[1].replace(/,/g,"")):null,Se=t.querySelectorAll(".job-details-jobs-unified-top-card__job-insight"),ce=Array.from(Se).map(W=>W.innerText?.trim()?.replace(/\s+/g," ")),be=ce.join(" ").match(/([\d,]+-[\d,]+\s+employees|[\d,]+\+?\s+employees)/i)?.[0]||null,q=ce.join(" ")+" "+g,Yt=/\bremote\b/i.test(q)?"remote":/\bhybrid\b/i.test(q)?"hybrid":/\bon-?site\b/i.test(q)?"onsite":null,zt=/\bcontract\b/i.test(q)?"contract":/\bfull-?time\b/i.test(q)?"full-time":/\bpart-?time\b/i.test(q)?"part-time":/\bfreelance\b/i.test(q)?"freelance":/\btemporary\b/i.test(q)?"temporary":null,Me=t.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24")?.innerText?.trim()||"",ae=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container, .jobs-unified-top-card__subtitle-primary-grouping")?.innerText?.trim()||"",R=(Me+" "+n+" "+ae).toLowerCase(),D=Me.toLowerCase(),m=[];/\bremote\b/.test(R)&&m.push("remote"),/\bhybrid\b/.test(R)&&m.push("hybrid"),/\bon-?site\b|\bin-?office\b/.test(R)&&m.push("onsite"),(m.length===0||!m.includes("remote")&&!m.includes("hybrid")&&!m.includes("onsite"))&&/remote/i.test(ae)&&m.push("remote"),/\b(manager|director|vp|vice president|head of|chief|cto|cio|lead.*team|managing)\b/i.test(D)&&m.push("managerial"),/\b(architect|principal|staff|distinguished)\b/i.test(D)&&m.push("senior-ic"),/\b(developer|engineer|programmer|analyst)\b/i.test(D)&&!m.includes("managerial")&&m.push("ic"),/\b(junior|jr\.?|entry)\b/i.test(D)?m.push("junior"):/\b(senior|sr\.?)\b/i.test(D)?m.push("senior"):/\b(staff|principal|distinguished)\b/i.test(D)?m.push("staff+"):/\b(director|vp|chief|cto|cio)\b/i.test(D)?m.push("executive"):/\b(lead|team lead)\b/i.test(D)&&m.push("lead"),/\b(backend|back-end|server-side|api)\b/i.test(R)&&m.push("backend"),/\b(frontend|front-end|ui|ux)\b/i.test(R)&&m.push("frontend"),/\b(full.?stack|fullstack)\b/i.test(R)&&m.push("fullstack"),/\b(devops|sre|infrastructure|platform)\b/i.test(R)&&m.push("devops"),/\b(data engineer|data science|machine learning|ml engineer)\b/i.test(R)&&m.push("data"),/\b(mobile|ios|android|react native|flutter)\b/i.test(R)&&m.push("mobile"),/\b(architect)\b/i.test(D)&&m.push("architect"),/\b(consultant|consulting)\b/i.test(D)&&m.push("consultant");let Ue=(r["employment type"]||"").toLowerCase();return(/contract|freelance|temporary/i.test(Ue)||/\bcontract\b/i.test(R))&&m.push("contract"),/full.?time|permanent/i.test(Ue)&&m.push("permanent"),/\bcanada\b|toronto|vancouver|montreal|ontario|british columbia|quebec|alberta|calgary|ottawa/i.test(ae)&&m.push("canada"),/\bunited states\b|\busa\b|new york|california|texas|seattle|san francisco/i.test(ae)&&m.push("usa"),(t.querySelector(".jobs-unified-top-card__job-insight--highlight, .compensation__salary")?.innerText?.trim()||""||/\$[\d,]+/.test(n))&&m.push("has-salary"),{description:n.substring(0,5e3),externalApplyUrl:h,companyName:p,companyUrl:S?S.startsWith("/")?"https://www.linkedin.com"+S:S:null,aboutCompany:f,seniority:r["seniority level"]||null,employmentType:r["employment type"]||null,industries:r.industries||null,jobFunction:r["job function"]||null,postedTime:M,applicantCount:ge,companySize:be,workplaceType:Yt,contractType:zt,techStack:[...new Set(c)],jobTags:[...new Set(m)]}})}import"dotenv/config";import*as j from"fs";import*as _ from"path";import{fileURLToPath as yo}from"url";function mt(e){if(!e||typeof e!="string"||/custom-invite|\/search\//i.test(e)||/\/in\/[^/?#]+\/(overlay|details)(\/|$)/i.test(e))return null;let t=e.match(/\/in\/([^/?#]+)/i);if(!t||!t[1])return null;let o=t[1].trim();return o?`https://www.linkedin.com/in/${o}/`:null}var go=yo(import.meta.url),So=_.dirname(_.dirname(go)),K=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"market-research"):_.join(So,"market-research"),ht=_.join(K,"scouted-jobs.json"),yt=_.join(K,"discovered-people.json"),bo=_.join(K,"visit-log.json"),gt=_.join(K,"companies.json"),br=_.join(K,"job-decisions.json");function _e(){j.existsSync(K)||j.mkdirSync(K,{recursive:!0})}function Ee(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";j.writeFileSync(n,o);for(let r=0;r<3;r++)try{j.renameSync(n,e);return}catch(i){if(r<2&&(i.code==="EPERM"||i.code==="EBUSY")){let s=Date.now();for(;Date.now()-s<200;);continue}throw i}}function de(e){try{if(j.existsSync(e))return JSON.parse(j.readFileSync(e,"utf-8"))}catch{}return null}function St(){te=null,wo=null,oe=null,ne=null,V=null}var te=null;function me(){return te||(te=de(ht)||{},te)}function bt(e,t){if(!e)return;_e();let o=me(),n=new Date().toISOString().slice(0,10);if(o[e]){for(let[r,i]of Object.entries(t))i!=null&&(o[e][r]=i);o[e].lastSeen=n}else o[e]={...t,scoutedAt:n,lastSeen:n};try{Ee(ht,o)}catch(r){console.error(`[!] Failed to save scouted-jobs.json: ${r.message}`)}}var wo=null;var oe=null;function wt(){return oe||(oe=de(yt)||{},oe)}function pe(e){let t=String(e||"").match(/\/in\/([^/?#]+)/i);return t?t[1].toLowerCase():null}function vo(e,t){let o=mt(t)||t;if(e[o])return o;let n=pe(t);if(!n)return o;let r=null;for(let[i,s]of Object.entries(e)){if(pe(s&&(s.canonicalUrl||s.profileUrl)||i)===n)return i;!r&&s&&Array.isArray(s.aliases)&&s.aliases.includes(n)&&(r=i)}return r||o}function vt(e,t){if(!e)return;_e();let o=wt(),n=new Date().toISOString().slice(0,10),r=vo(o,e),i=pe(e);if(o[r]){let s=o[r];t.name&&(s.name=t.name),t.title&&(s.title=t.title),t.company&&(s.company=t.company),t.location&&(s.location=t.location),t.role&&(s.role=t.role),t.isConnected!=null&&(s.isConnected=t.isConnected),t.jobId&&(s.jobIds||(s.jobIds=[]),s.jobIds.includes(t.jobId)||s.jobIds.push(t.jobId)),i&&pe(s.canonicalUrl||s.profileUrl||r)!==i&&(Array.isArray(s.aliases)||(s.aliases=[]),s.aliases.includes(i)||s.aliases.push(i)),s.lastSeen=n,s.seenCount=(s.seenCount||1)+1}else o[r]={canonicalUrl:r,aliases:[],name:t.name||null,title:t.title||null,company:t.company||null,location:t.location||null,role:t.role||null,source:t.source||"scout",isConnected:t.isConnected||!1,discoveredAt:n,lastSeen:n,seenCount:1,jobIds:t.jobId?[t.jobId]:[]};try{Ee(yt,o)}catch(s){console.error(`[!] Failed to save discovered-people.json: ${s.message}`)}}var ne=null;function ko(){return ne||(ne=de(gt)||{},ne)}function kt(e,t){if(!e)return;_e();let o=ko(),n=new Date().toISOString().slice(0,10);if(o[e]){let r=o[e];t.name&&(r.name=t.name),t.about&&(r.about=t.about),t.size&&(r.size=t.size),t.industries&&(r.industries=t.industries),t.jobId&&(r.jobIds||(r.jobIds=[]),r.jobIds.includes(t.jobId)||r.jobIds.push(t.jobId)),t.recruiterUrl&&(r.recruiterUrls||(r.recruiterUrls=[]),r.recruiterUrls.includes(t.recruiterUrl)||r.recruiterUrls.push(t.recruiterUrl)),r.lastSeen=n,r.jobCount=r.jobIds?.length||0}else o[e]={name:t.name||null,about:t.about||null,size:t.size||null,industries:t.industries||null,discoveredAt:n,lastSeen:n,jobIds:t.jobId?[t.jobId]:[],recruiterUrls:t.recruiterUrl?[t.recruiterUrl]:[],jobCount:t.jobId?1:0};try{Ee(gt,o)}catch(r){console.error(`[!] Failed to save companies.json: ${r.message}`)}}var V=null;function Ao(){return V||(V=de(bo)||{visits:[]},Array.isArray(V.visits)||(V.visits=[]),V)}function At(){let e=me(),t=wt(),o=Object.values(e),n=Object.values(t),r={};for(let u of o)u.company&&(r[u.company]=(r[u.company]||0)+1);let i=Object.entries(r).sort((u,p)=>p[1]-u[1]).slice(0,5).map(([u,p])=>`${u} (${p})`),s={};for(let u of o)for(let p of u.techStack||[])s[p]=(s[p]||0)+1;let c=Object.entries(s).sort((u,p)=>p[1]-u[1]).slice(0,8).map(([u,p])=>`${u} (${p})`),l=Ao(),f=new Date().toISOString().slice(0,10),d=l.visits.filter(u=>u.date.startsWith(f)).length,h=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:o.length,totalRecruiters:n.length,topCompanies:i,topTech:c,totalVisited:h,todayVisited:d,lastScoutDate:o.length>0?o.sort((u,p)=>(p.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}import"dotenv/config";import*as b from"fs";import*as v from"path";import{fileURLToPath as _o}from"url";var Eo=_o(import.meta.url),jo=v.dirname(v.dirname(Eo)),F=process.env.DATA_DIR?v.resolve(process.env.DATA_DIR,"collected-profiles"):v.join(jo,"collected-profiles"),xo=v.join(F,"people.json"),Co=v.join(F,"jobs.json"),_r=v.join(F,"quota.json"),Er=v.join(F,"conversations.json"),jr=v.join(F,"sync-state.json"),xr=v.join(F,"application-questions.json"),Cr=v.join(F,"profile-history"),_t=(e,t)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:t},$r=_t(process.env.CONNECT_MAX_DAILY,20),Tr=_t(process.env.CONNECT_MAX_WEEKLY,100),re=null,se=null,$o=null,To=null,Io=null,Ro=null;function Et(){re=null,se=null,$o=null,To=null,Io=null,Ro=null}function jt(){b.existsSync(F)||b.mkdirSync(F,{recursive:!0})}function xt(e,t){if(!b.existsSync(e))return null;try{let o=JSON.parse(b.readFileSync(e,"utf-8"));try{b.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${v.resolve(e)}`);let n=e+".backup";if(b.existsSync(n))try{let r=JSON.parse(b.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{b.copyFileSync(n,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{b.copyFileSync(e,e+".corrupted")}catch{}return null}}function Ct(){return re||(jt(),re=xt(xo,"people.json")||{},re)}function $t(){return se||(jt(),se=xt(Co,"jobs.json")||{},se)}import"dotenv/config";import*as x from"fs";import*as J from"path";import{fileURLToPath as Po}from"url";import"dotenv/config";import{createGraphClient as Do,resolveToken as Oo}from"@ilivemylife/graph-sdk";import{config as No}from"dotenv";No();var Tt=Oo()||process.env.TOKEN;Tt||(console.error(`
|
|
1
|
+
var eo=Object.defineProperty;var ue=(e,t)=>{for(var o in t)eo(e,o,{get:t[o],enumerable:!0})};import yo from"puppeteer";import{addExtra as go}from"puppeteer-extra";import So from"puppeteer-extra-plugin-stealth";import k from"fs";import F from"path";var to="cookies.json";function ve(){let e=process.env.ILML_SCOPE_DIR;return e?F.join(e,"plugins-state","linkedin","cookies.json"):to}function oo(){let e=ve(),t=F.dirname(e);return t&&t!=="."&&!k.existsSync(t)&&k.mkdirSync(t,{recursive:!0}),e}function Je(e){let t=oo();return k.writeFileSync(t,JSON.stringify(e)),t}function He(){let e=ve();if(!k.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=k.readFileSync(e,"utf-8")}catch(n){throw new Error(`Failed to read cookies at ${e}: ${n.message}. Run: ilml linkedin login`)}let o;try{o=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(o)||o.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return o}function We(){return k.existsSync(ve())}function no(){let e=process.env.ILML_SCOPE_DIR;return e?F.join(e,"plugins-state","linkedin"):"."}function Ge(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function ro(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?Ge(t[1]):"default"}function Ve(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),F.resolve(t);let o=Ge(e||ro()),n=F.join(no(),"chrome-profile",o);return k.existsSync(n)||k.mkdirSync(n,{recursive:!0}),F.resolve(n)}var Ke=".ilml-seeded";function Ye(e){return!k.existsSync(F.join(e,Ke))}function ze(e){try{k.writeFileSync(F.join(e,Ke),new Date().toISOString())}catch{}}function Qe(e){let t=0;for(let o of["SingletonLock","SingletonCookie","SingletonSocket"])try{k.rmSync(F.join(e,o),{force:!0}),t++}catch{}return t}async function j(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function Xe(e,t,{timeout:o=45e3,poll:n=1e3,label:r="page"}={}){let i=Date.now();for(;Date.now()-i<o;){try{if(await e.evaluate(c=>!!document.querySelector(c),t)){let c=Date.now()-i;return c>6e3&&console.log(` (waited ${Math.round(c/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(s=>setTimeout(s,n))}return!1}var Ze=/\/authwall|\/login|\/checkpoint|\/uas\/login/;function ke(e){return Ze.test(e||"")}async function et(e,{credentialWaitMs:t=36e4,label:o="page"}={}){console.log(` \u26A0 Auth wall on ${o} \u2014 attempting self-recovery (cookies may just need a refresh)...`);try{await e.goto("https://www.linkedin.com/feed/",{waitUntil:"domcontentloaded",timeout:6e4})}catch{}let n=!!(process.stdin&&process.stdin.isTTY),r=n?t:Math.min(t,45e3),i=Date.now(),s=!1;for(;Date.now()-i<r;){let l="wait";try{l=await e.evaluate(a=>!new RegExp(a).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",Ze.source)}catch{}if(l==="in"){try{let a=await e.cookies();if(Array.isArray(a)&&a.some(m=>m.name==="li_at")){let m=Je(a);console.log(` \u2713 Session recovered \u2014 re-saved ${a.length} cookies (${m}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(a){console.log(` \u2713 Session recovered (cookie re-save skipped: ${a.message}).`)}return!0}if(l==="creds"){if(!n){let a=new Error(`Session expired (${o}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}s||(s=!0,console.log(`
|
|
2
|
+
\u26A0 LinkedIn is asking for your login + password (cookies not enough this time).`),console.log(" \u2192 Sign in MANUALLY in the browser window that is already open."),console.log(` I will wait and resume automatically \u2014 do NOT close the window or re-run the command.
|
|
3
|
+
`))}await new Promise(a=>setTimeout(a,2500))}let c=new Error(`Session expired (${o}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw c.code="SESSION_EXPIRED",c}import{getPluginConfig as so}from"@ilivemylife/graph-sdk";var io=await so();for(let[e,t]of Object.entries(io))process.env[e]===void 0&&(process.env[e]=t);var co=process.env.LINKEDIN_NAME,G=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Vn=Object.freeze(new Set([G.DRAFT,G.CONFIRMED,G.NEEDS_REVIEW])),lo=Object.freeze(new Set([G.DRAFT,G.CONFIRMED,G.REJECTED,G.NEEDS_REVIEW]));import Ae from"fs";import ao from"path";var uo={headless:!1,defaultViewport:null,protocolTimeout:3e5},ee=new Set,tt=!1;async function fe(){let e=[...ee].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});ee.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function fo(){if(tt)return;tt=!0;let e=t=>async()=>{await fe(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await fe(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await fe(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await fe(),process.exit(0))}),process.on("exit",()=>{for(let t of ee)try{let o=t.process&&t.process();o&&o.kill("SIGKILL")}catch{}})}function _e(e){return ao.join(e,".ilml-browser-session.json")}function st(e,t={}){try{Ae.writeFileSync(_e(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function po(e,t){try{let o=t.wsEndpoint&&t.wsEndpoint();st(e,o?{wsEndpoint:o}:{})}catch{}}function mo(e){let t=it(e);t&&t.ownerPid===process.pid&&Z(e)}function Z(e){try{Ae.rmSync(_e(e),{force:!0})}catch{}}function it(e){try{return JSON.parse(Ae.readFileSync(_e(e),"utf-8"))}catch{return null}}function ot(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function nt(e,t,o){let n,r=new Promise(s=>{n=setTimeout(()=>s(o),t)}),i=Promise.resolve(e).then(s=>(clearTimeout(n),s),s=>{throw clearTimeout(n),s});return Promise.race([i,r])}async function rt(e,t,{probeTimeoutMs:o=4e3}={}){let n=it(t);if(!n)return"free";if(!n.wsEndpoint)return n.ownerPid&&n.ownerPid!==process.pid&&ot(n.ownerPid)?"live":(Z(t),"free");let r=Symbol("timeout"),i=e.connect({browserWSEndpoint:n.wsEndpoint,defaultViewport:null}).catch(()=>null),s=await nt(i,o,r);if(s===r)return i.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!s)return Z(t),"free";if(ot(n.ownerPid)){try{s.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await nt(s.close().then(()=>!0).catch(()=>!1),o,!1))return Z(t),"free";try{s.disconnect()}catch{}return"live"}function ho(e,t){e&&(fo(),ee.add(e),e.on("disconnected",()=>{ee.delete(e),t&&Z(t)}))}async function ct(e,t={}){let o=Ve(),n={...uo,...t,userDataDir:o},r=`Could not open the LinkedIn automation Chrome profile at ${o}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await rt(e,o)==="live")throw new Error(r);st(o);let i;try{i=await e.launch(n)}catch{if(await rt(e,o)==="live")throw new Error(r);Qe(o);try{i=await e.launch(n)}catch(c){throw mo(o),new Error(`Could not open the LinkedIn automation Chrome profile at ${o}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${c.message})`)}}return ho(i,o),po(o,i),{browser:i,profileDir:o,needsSeed:Ye(o)}}async function lt(e,t){if(!t||!t.needsSeed)return!1;if(!We())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...He()),ze(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var at=go(yo);at.use(So());async function ut(){let{browser:e,profileDir:t,needsSeed:o}=await ct(at),n=await e.newPage();return await n.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await lt(n,{profileDir:t,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:n}}async function ft(e){let t=[".jobs-search-results-list",".scaffold-layout__list-container",".jobs-search-two-pane__results","div.jobs-search-results-list"];return await e.evaluate(async n=>{let r=null,i=null;for(let m of n)if(r=document.querySelector(m),r){i=m;break}if(!r){let m=document.querySelector("li.scaffold-layout__list-item");if(m){let f=m.parentElement;for(;f&&f!==document.body;){if(f.scrollHeight>f.clientHeight){r=f,i="parent of li.scaffold-layout__list-item";break}f=f.parentElement}}}if(!r)return{found:!1,triedSelectors:n};let s=r.scrollTop,c=300,l=300,a=50,p=0;for(;p<a&&(r.scrollBy(0,c),await new Promise(m=>setTimeout(m,l)),!(r.scrollTop+r.clientHeight>=r.scrollHeight));)p++;return{found:!0,usedSelector:i,initialScroll:s,finalScroll:r.scrollTop,scrollHeight:r.scrollHeight,attempts:p}},t)}async function pt(e,{easyApplyOnly:t=!0}={}){let o=await e.evaluate(()=>{let n=document.querySelectorAll("li.scaffold-layout__list-item");return Array.from(n).map(r=>{let s=(r.querySelector(".job-card-list__footer-wrapper")?.innerText??"").includes("Easy Apply"),c=r.querySelector("a.job-card-container__link");if(c){let l=c.getAttribute("href").split("?")[0],a=r.querySelector(".job-card-list__title--link")?.getAttribute("aria-label")?.replace(/ with verification$/,""),p=r.querySelector(".artdeco-entity-lockup__subtitle")?.innerText.trim(),m=r.querySelector(".artdeco-entity-lockup__caption")?.innerText.trim(),f=r.querySelector(".artdeco-entity-lockup__metadata")?.innerText.trim();return{id:l,isEasyApply:s,applyType:s?"easy-apply":"external",dataId:c.getAttribute("data-control-id"),href:`https://linkedin.com${l}`,jobTitle:a,companyName:p,location:m,salary:f||null,jobLink:s?c.href:null}}return{isEasyApply:!1}})});return t?o.filter(n=>n.isEasyApply&&n.href):o.filter(n=>n.href)}async function dt(e){let t=await e.evaluate(()=>{let o=document.querySelector('button[aria-label="View next page"]')||document.querySelector(".jobs-search-pagination__button--next");if(o&&!o.disabled){let n=document.querySelector(".jobs-search-pagination__page-state")?.textContent?.trim();return o.click(),{success:!0,pageState:n}}return{success:!1,reason:"No next page button found"}});return console.log(" Pagination:",t.success?t.pageState:t.reason),t.success&&await j(2e3),t.success}async function mt(e,t){let o=e.url();if(o.includes("/jobs/"))return!1;if(ke(o)){if(!await Xe(e,".scaffold-layout__main, main.scaffold-layout__main, .jobs-search-results-list",{timeout:45e3,label:"job search"})&&ke(e.url())&&await et(e,{label:"job search"}),e.url().includes("/jobs/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await j(2e3)),!e.url().includes("/jobs/"))throw new Error(`Session expired \u2014 could not return to job search (landed on ${e.url().slice(0,60)}). Run: ilml linkedin login`);return!0}console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to job search..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await j(3e3);let n=e.url();if(!n.includes("/jobs/"))throw new Error(`Could not return to job search. Current URL: ${n.slice(0,80)}`);return console.log(" Recovered to job search page"),!0}async function ht(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,o=t.querySelector(".hirer-card__hirer-information");if(o){let s=o.querySelector('a[href*="/in/"]'),c=o.querySelector(".jobs-poster__name")||o.querySelector("strong")||o.querySelector('[class*="name"]');if(s)return{name:c?.textContent?.trim()||s.textContent?.trim(),profileUrl:s.href?.split("?")[0],source:"hiring_team"}}let n=t.querySelector(".jobs-poster__name");if(n){let s=n.closest('a[href*="/in/"]')||n.parentElement?.querySelector('a[href*="/in/"]')||n.parentElement?.parentElement?.querySelector('a[href*="/in/"]');if(s)return{name:n.textContent?.trim(),profileUrl:s.href?.split("?")[0],source:"poster_name"}}let r=t.querySelector(".job-details-people-who-can-help__section--two-pane")||t.querySelector('[class*="people-who-can-help"]');if(r){let s=r.querySelector('a[href*="/in/"]');if(s)return{name:(r.querySelector(".jobs-poster__name")||r.querySelector("strong"))?.textContent?.trim()||s.textContent?.trim(),profileUrl:s.href?.split("?")[0],source:"people_section"}}let i=t.querySelectorAll('a[href*="/in/"]');for(let s of i){let c=s.textContent?.trim();if(c&&c.length>3&&!["View","Connect","Follow","Message","Apply","Save"].includes(c))return{name:c,profileUrl:s.href?.split("?")[0],source:"details_link"}}return null})}async function yt(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,n=(t.querySelector(".jobs-description__content")||t.querySelector(".jobs-box__html-content")||t.querySelector(".jobs-description"))?.innerText?.trim()||"",r={},i=t.querySelectorAll(".jobs-unified-top-card__job-insight, li.job-criteria__item");for(let W of i){let we=W.querySelector(".job-criteria__subheader")?.textContent?.trim(),Be=W.querySelector(".job-criteria__text")?.textContent?.trim();we&&Be&&(r[we.toLowerCase()]=Be)}let s=["Java","Python","JavaScript","TypeScript","React","Angular","Vue","Node.js","C#",".NET","C\\+\\+","Go","Rust","Scala","Kotlin","AWS","Azure","GCP","Docker","Kubernetes","Terraform","SQL","PostgreSQL","MongoDB","Redis","Kafka","RabbitMQ","Spring","Django","Flask","Express","Next.js","CI/CD","Jenkins","GitHub Actions","GraphQL","REST","Microservices","Machine Learning","AI","Data Engineering","Spark","Hadoop","Snowflake","Databricks","Airflow","iOS","Android","React Native","Flutter","Agile","Scrum","DevOps","SRE"],c=[];for(let W of s)new RegExp("\\b"+W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i").test(n)&&c.push(W.replace(/\\\+/g,"+"));let a=t.querySelector('.jobs-company__box, [class*="jobs-company"], [class*="company-card"]')?.innerText?.trim()?.slice(0,1e3)||null,m=t.querySelector('a.jobs-apply-button[href], a[data-tracking-control-name="public_jobs_apply-link-offsite_sign-up"]')?.getAttribute("href")||null,f=t.querySelector(".job-details-jobs-unified-top-card__company-name, .jobs-unified-top-card__company-name"),d=f?.innerText?.trim()||null,S=(f?.querySelector('a[href*="/company/"]')||t.querySelector('a[href*="/company/"]'))?.getAttribute("href")?.split("?")[0]||null,g=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container")?.innerText?.trim()||"",U=g.match(/(\d+\s+(?:hour|day|week|month)s?\s+ago|Reposted|Just now)/i)?.[0]||null,q=g.match(/(\d[\d,]*)\s+applicant/i),ge=q?parseInt(q[1].replace(/,/g,"")):null,Se=t.querySelectorAll(".job-details-jobs-unified-top-card__job-insight"),ce=Array.from(Se).map(W=>W.innerText?.trim()?.replace(/\s+/g," ")),be=ce.join(" ").match(/([\d,]+-[\d,]+\s+employees|[\d,]+\+?\s+employees)/i)?.[0]||null,B=ce.join(" ")+" "+g,Xt=/\bremote\b/i.test(B)?"remote":/\bhybrid\b/i.test(B)?"hybrid":/\bon-?site\b/i.test(B)?"onsite":null,Zt=/\bcontract\b/i.test(B)?"contract":/\bfull-?time\b/i.test(B)?"full-time":/\bpart-?time\b/i.test(B)?"part-time":/\bfreelance\b/i.test(B)?"freelance":/\btemporary\b/i.test(B)?"temporary":null,Ue=t.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24")?.innerText?.trim()||"",ae=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container, .jobs-unified-top-card__subtitle-primary-grouping")?.innerText?.trim()||"",D=(Ue+" "+n+" "+ae).toLowerCase(),O=Ue.toLowerCase(),h=[];/\bremote\b/.test(D)&&h.push("remote"),/\bhybrid\b/.test(D)&&h.push("hybrid"),/\bon-?site\b|\bin-?office\b/.test(D)&&h.push("onsite"),(h.length===0||!h.includes("remote")&&!h.includes("hybrid")&&!h.includes("onsite"))&&/remote/i.test(ae)&&h.push("remote"),/\b(manager|director|vp|vice president|head of|chief|cto|cio|lead.*team|managing)\b/i.test(O)&&h.push("managerial"),/\b(architect|principal|staff|distinguished)\b/i.test(O)&&h.push("senior-ic"),/\b(developer|engineer|programmer|analyst)\b/i.test(O)&&!h.includes("managerial")&&h.push("ic"),/\b(junior|jr\.?|entry)\b/i.test(O)?h.push("junior"):/\b(senior|sr\.?)\b/i.test(O)?h.push("senior"):/\b(staff|principal|distinguished)\b/i.test(O)?h.push("staff+"):/\b(director|vp|chief|cto|cio)\b/i.test(O)?h.push("executive"):/\b(lead|team lead)\b/i.test(O)&&h.push("lead"),/\b(backend|back-end|server-side|api)\b/i.test(D)&&h.push("backend"),/\b(frontend|front-end|ui|ux)\b/i.test(D)&&h.push("frontend"),/\b(full.?stack|fullstack)\b/i.test(D)&&h.push("fullstack"),/\b(devops|sre|infrastructure|platform)\b/i.test(D)&&h.push("devops"),/\b(data engineer|data science|machine learning|ml engineer)\b/i.test(D)&&h.push("data"),/\b(mobile|ios|android|react native|flutter)\b/i.test(D)&&h.push("mobile"),/\b(architect)\b/i.test(O)&&h.push("architect"),/\b(consultant|consulting)\b/i.test(O)&&h.push("consultant");let qe=(r["employment type"]||"").toLowerCase();return(/contract|freelance|temporary/i.test(qe)||/\bcontract\b/i.test(D))&&h.push("contract"),/full.?time|permanent/i.test(qe)&&h.push("permanent"),/\bcanada\b|toronto|vancouver|montreal|ontario|british columbia|quebec|alberta|calgary|ottawa/i.test(ae)&&h.push("canada"),/\bunited states\b|\busa\b|new york|california|texas|seattle|san francisco/i.test(ae)&&h.push("usa"),(t.querySelector(".jobs-unified-top-card__job-insight--highlight, .compensation__salary")?.innerText?.trim()||""||/\$[\d,]+/.test(n))&&h.push("has-salary"),{description:n.substring(0,5e3),externalApplyUrl:m,companyName:d,companyUrl:S?S.startsWith("/")?"https://www.linkedin.com"+S:S:null,aboutCompany:a,seniority:r["seniority level"]||null,employmentType:r["employment type"]||null,industries:r.industries||null,jobFunction:r["job function"]||null,postedTime:U,applicantCount:ge,companySize:be,workplaceType:Xt,contractType:Zt,techStack:[...new Set(c)],jobTags:[...new Set(h)]}})}import"dotenv/config";import*as x from"fs";import*as E from"path";import{fileURLToPath as bo}from"url";function gt(e){if(!e||typeof e!="string"||/custom-invite|\/search\//i.test(e)||/\/in\/[^/?#]+\/(overlay|details)(\/|$)/i.test(e))return null;let t=e.match(/\/in\/([^/?#]+)/i);if(!t||!t[1])return null;let o=t[1].trim();return o?`https://www.linkedin.com/in/${o}/`:null}var wo=bo(import.meta.url),vo=E.dirname(E.dirname(wo)),K=process.env.DATA_DIR?E.resolve(process.env.DATA_DIR,"market-research"):E.join(vo,"market-research"),St=E.join(K,"scouted-jobs.json"),bt=E.join(K,"discovered-people.json"),ko=E.join(K,"visit-log.json"),wt=E.join(K,"companies.json"),vr=E.join(K,"job-decisions.json");function Ee(){x.existsSync(K)||x.mkdirSync(K,{recursive:!0})}function je(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";x.writeFileSync(n,o);for(let r=0;r<3;r++)try{x.renameSync(n,e);return}catch(i){if(r<2&&(i.code==="EPERM"||i.code==="EBUSY")){let s=Date.now();for(;Date.now()-s<200;);continue}throw i}}function de(e){try{if(x.existsSync(e))return JSON.parse(x.readFileSync(e,"utf-8"))}catch{}return null}function vt(){te=null,Ao=null,oe=null,ne=null,V=null}var te=null;function me(){return te||(te=de(St)||{},te)}function kt(e,t){if(!e)return;Ee();let o=me(),n=new Date().toISOString().slice(0,10);if(o[e]){for(let[r,i]of Object.entries(t))i!=null&&(o[e][r]=i);o[e].lastSeen=n}else o[e]={...t,scoutedAt:n,lastSeen:n};try{je(St,o)}catch(r){console.error(`[!] Failed to save scouted-jobs.json: ${r.message}`)}}var Ao=null;var oe=null;function At(){return oe||(oe=de(bt)||{},oe)}function pe(e){let t=String(e||"").match(/\/in\/([^/?#]+)/i);return t?t[1].toLowerCase():null}function _o(e,t){let o=gt(t)||t;if(e[o])return o;let n=pe(t);if(!n)return o;let r=null;for(let[i,s]of Object.entries(e)){if(pe(s&&(s.canonicalUrl||s.profileUrl)||i)===n)return i;!r&&s&&Array.isArray(s.aliases)&&s.aliases.includes(n)&&(r=i)}return r||o}function _t(e,t){if(!e)return;Ee();let o=At(),n=new Date().toISOString().slice(0,10),r=_o(o,e),i=pe(e);if(o[r]){let s=o[r];t.name&&(s.name=t.name),t.title&&(s.title=t.title),t.company&&(s.company=t.company),t.location&&(s.location=t.location),t.role&&(s.role=t.role),t.isConnected!=null&&(s.isConnected=t.isConnected),t.jobId&&(s.jobIds||(s.jobIds=[]),s.jobIds.includes(t.jobId)||s.jobIds.push(t.jobId)),i&&pe(s.canonicalUrl||s.profileUrl||r)!==i&&(Array.isArray(s.aliases)||(s.aliases=[]),s.aliases.includes(i)||s.aliases.push(i)),s.lastSeen=n,s.seenCount=(s.seenCount||1)+1}else o[r]={canonicalUrl:r,aliases:[],name:t.name||null,title:t.title||null,company:t.company||null,location:t.location||null,role:t.role||null,source:t.source||"scout",isConnected:t.isConnected||!1,discoveredAt:n,lastSeen:n,seenCount:1,jobIds:t.jobId?[t.jobId]:[]};try{je(bt,o)}catch(s){console.error(`[!] Failed to save discovered-people.json: ${s.message}`)}}var ne=null;function Eo(){return ne||(ne=de(wt)||{},ne)}function Et(e,t){if(!e)return;Ee();let o=Eo(),n=new Date().toISOString().slice(0,10);if(o[e]){let r=o[e];t.name&&(r.name=t.name),t.about&&(r.about=t.about),t.size&&(r.size=t.size),t.industries&&(r.industries=t.industries),t.jobId&&(r.jobIds||(r.jobIds=[]),r.jobIds.includes(t.jobId)||r.jobIds.push(t.jobId)),t.recruiterUrl&&(r.recruiterUrls||(r.recruiterUrls=[]),r.recruiterUrls.includes(t.recruiterUrl)||r.recruiterUrls.push(t.recruiterUrl)),r.lastSeen=n,r.jobCount=r.jobIds?.length||0}else o[e]={name:t.name||null,about:t.about||null,size:t.size||null,industries:t.industries||null,discoveredAt:n,lastSeen:n,jobIds:t.jobId?[t.jobId]:[],recruiterUrls:t.recruiterUrl?[t.recruiterUrl]:[],jobCount:t.jobId?1:0};try{je(wt,o)}catch(r){console.error(`[!] Failed to save companies.json: ${r.message}`)}}var V=null;function jo(){return V||(V=de(ko)||{visits:[]},Array.isArray(V.visits)||(V.visits=[]),V)}function jt(){let e=me(),t=At(),o=Object.values(e),n=Object.values(t),r={};for(let f of o)f.company&&(r[f.company]=(r[f.company]||0)+1);let i=Object.entries(r).sort((f,d)=>d[1]-f[1]).slice(0,5).map(([f,d])=>`${f} (${d})`),s={};for(let f of o)for(let d of f.techStack||[])s[d]=(s[d]||0)+1;let c=Object.entries(s).sort((f,d)=>d[1]-f[1]).slice(0,8).map(([f,d])=>`${f} (${d})`),l=jo(),a=new Date().toISOString().slice(0,10),p=l.visits.filter(f=>f.date.startsWith(a)).length,m=new Set(l.visits.map(f=>f.profileUrl)).size;return{totalJobs:o.length,totalRecruiters:n.length,topCompanies:i,topTech:c,totalVisited:m,todayVisited:p,lastScoutDate:o.length>0?o.sort((f,d)=>(d.scoutedAt||"").localeCompare(f.scoutedAt||""))[0]?.scoutedAt:null}}import"dotenv/config";import*as b from"fs";import*as v from"path";import{fileURLToPath as xo}from"url";var Co=xo(import.meta.url),$o=v.dirname(v.dirname(Co)),P=process.env.DATA_DIR?v.resolve(process.env.DATA_DIR,"collected-profiles"):v.join($o,"collected-profiles"),To=v.join(P,"people.json"),Io=v.join(P,"jobs.json"),jr=v.join(P,"quota.json"),xr=v.join(P,"conversations.json"),Cr=v.join(P,"sync-state.json"),$r=v.join(P,"application-questions.json"),Tr=v.join(P,"profile-history"),xt=(e,t)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:t},Ir=xt(process.env.CONNECT_MAX_DAILY,20),Rr=xt(process.env.CONNECT_MAX_WEEKLY,100),re=null,se=null,Ro=null,Do=null,Oo=null,No=null;function Ct(){re=null,se=null,Ro=null,Do=null,Oo=null,No=null}function $t(){b.existsSync(P)||b.mkdirSync(P,{recursive:!0})}function Tt(e,t){if(!b.existsSync(e))return null;try{let o=JSON.parse(b.readFileSync(e,"utf-8"));try{b.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${v.resolve(e)}`);let n=e+".backup";if(b.existsSync(n))try{let r=JSON.parse(b.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{b.copyFileSync(n,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{b.copyFileSync(e,e+".corrupted")}catch{}return null}}function It(){return re||($t(),re=Tt(To,"people.json")||{},re)}function Rt(){return se||($t(),se=Tt(Io,"jobs.json")||{},se)}import"dotenv/config";import*as C from"fs";import*as J from"path";import{fileURLToPath as qo}from"url";import"dotenv/config";import{createGraphClient as Lo,resolveToken as Fo}from"@ilivemylife/graph-sdk";import{config as Po}from"dotenv";Po();var Dt=Fo()||process.env.TOKEN;Dt||(console.error(`
|
|
2
4
|
[FATAL] No iLiveMyLife token found.`),console.error(" The bot uses Lifebot AI to decide which jobs to apply for"),console.error(` and how to fill application forms. It cannot work without it.
|
|
3
5
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
4
6
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
5
|
-
`),process.exit(1));var
|
|
7
|
+
`),process.exit(1));var Ot=Lo({token:Dt});function Mo(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let o=Math.floor(t/60),n=t%60;return n?`${o}m ${n}s`:`${o}m`}function Uo({scriptName:e,mode:t,status:o,error:n,duration:r}){let i=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",s=new Date().toISOString().slice(0,16).replace("T"," "),c=r?` ${Mo(r)}`:"",l=o==="error"?`error${n?`: ${String(n).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",a=t&&t!=="default"?` (${t})`:"";return`${i} ${e}${a} \u2014 ${l} \u2014 ${s}${c}`}async function Nt({scriptName:e,mode:t,status:o,summaryLines:n,error:r,duration:i}){let s=process.env.NODE_RUN_REPORTS;if(!s||!Array.isArray(n)||n.length===0)return;let l=`**${Uo({scriptName:e,mode:t,status:o,error:r,duration:i})}**
|
|
6
8
|
|
|
7
9
|
${n.join(`
|
|
8
|
-
`)}`;try{await It.addMessage(s,l)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var Mo=Po(import.meta.url),Uo=J.dirname(J.dirname(Mo)),je=process.env.DATA_DIR?J.resolve(process.env.DATA_DIR,"collected-profiles"):J.join(Uo,"collected-profiles"),xe=J.join(je,"run-log.json");function qo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";x.writeFileSync(n,o);for(let r=0;r<3;r++)try{x.renameSync(n,e);return}catch(i){if(r<2&&(i.code==="EPERM"||i.code==="EBUSY")){let s=Date.now();for(;Date.now()-s<200;);continue}throw i}}function Dt(){try{if(!x.existsSync(xe))return{runs:[]};let e=JSON.parse(x.readFileSync(xe,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Ot(e){x.existsSync(je)||x.mkdirSync(je,{recursive:!0});try{qo(xe,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Nt(e,t="default"){let o=Dt();for(let s of o.runs)s.status==="running"&&(s.status="interrupted",s.result="interrupted",s.timestamp&&(s.duration=Date.now()-new Date(s.timestamp).getTime()));let n=new Date,r={timestamp:n.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(r);let i=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(s=>new Date(s.timestamp).getTime()>i),Ot(o),{script:e,mode:t,startTime:n.getTime(),runIndex:o.runs.length-1}}function Ce(e,t,o=null,n=null){if(!e)return;let r=null;try{let s=Dt(),c=s.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=o,c.error=n,r=c.duration;else{let l=s.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=o,l.error=n,r=l.duration)}Ot(s)}catch(s){console.error(`[runLog] Failed to end run: ${s.message}`)}let i=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(i&&i.length>0&&process.env.NODE_RUN_REPORTS){let s=t==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";Rt({scriptName:e.script,mode:e.mode,status:s,summaryLines:i,error:n,duration:r??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as a from"fs";import*as Le from"os";import*as y from"path";import{fileURLToPath as pn}from"url";var Ie={};ue(Ie,{NAME:()=>Jo,VERSION:()=>Bo,up:()=>Go});import*as C from"fs";import*as he from"path";var Bo=1,Jo="normalize-jobs-and-questions",Ho=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Wo=50;function $e(e){return C.existsSync(e)?JSON.parse(C.readFileSync(e,"utf-8")):null}function Te(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{C.writeFileSync(n,o)}catch(r){try{C.unlinkSync(n)}catch{}throw r}try{C.renameSync(n,e)}catch(r){try{C.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}async function Go(e,t){let o=he.join(e,"jobs.json"),n=he.join(t,"scouted-jobs.json"),r=he.join(e,"application-questions.json"),i=$e(o)||{},s=$e(n)||{},c=0,l=[];for(let d of Object.keys(i)){if(!s[d])continue;let h=s[d],u=i[d];for(let p of Ho)h[p]!=null&&u[p]==null&&(u[p]=h[p]);l.push(d),c++}c>0?(Te(o,i),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=$e(r);if(f&&Array.isArray(f.applications)){let d={},h=0;for(let u of f.applications){let p=u.jobId||"unknown";d[p]||(d[p]={applications:[]});let A=(u.questions||[]).map(S=>{let w={type:S.type||"input",question:S.question||"",answer:S.answer||""};return S.options&&(S.options.length<=Wo?w.options=S.options:(w.optionsOmitted=!0,h++)),S.page&&(w.page=S.page),S.wasPreFilled&&(w.wasPreFilled=!0),S.wasRetry&&(w.wasRetry=!0),w});d[p].applications.push({applicationId:u.applicationId,date:u.date,result:u.result||"submitted",formPages:u.formPages||null,duration:u.duration||null,retries:u.retries||0,failedField:u.failedField||null,questionCount:u.questionCount||A.length,questions:A})}Te(r,d),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(d).length} unique jobs)`),h>0&&console.log(` Phase 2: Stripped bloated options from ${h} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let d of l)delete s[d];Te(n,s),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(s).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Re={};ue(Re,{NAME:()=>Ko,VERSION:()=>Vo,up:()=>Qo});import*as $ from"fs";import*as Lt from"path";var Vo=2,Ko="reset-unread-flags";function Yo(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function zo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{$.writeFileSync(n,o)}catch(r){try{$.unlinkSync(n)}catch{}throw r}try{$.renameSync(n,e)}catch(r){try{$.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}async function Qo(e){let t=Lt.join(e,"conversations.json"),o=Yo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let n=0;for(let r of Object.keys(o))o[r].unread===!0&&(o[r].unread=!1,n++);if(n===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}zo(t,o),console.log(` Reset unread=false on ${n} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var De={};ue(De,{NAME:()=>Zo,VERSION:()=>Xo,up:()=>rn});import*as T from"fs";import*as Ft from"path";var Xo=3,Zo="recompute-last-message-by",en=new Set(["draft","confirmed","rejected","needs_review"]);function tn(e){return T.existsSync(e)?JSON.parse(T.readFileSync(e,"utf-8")):null}function on(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{T.writeFileSync(n,o)}catch(r){try{T.unlinkSync(n)}catch{}throw r}try{T.renameSync(n,e)}catch(r){try{T.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}function nn(e,t){if(!e||e.length===0)return"them";let o=e.filter(i=>!en.has(i.status));if(o.length===0)return"them";let n=o.map(i=>({m:i,t:Date.parse(i.time)})).filter(i=>Number.isFinite(i.t)).sort((i,s)=>s.t-i.t).map(i=>i.m),r=n.length>0?n:[...o].reverse();for(let i of r){let s=i.sender;if(s===t)return"me";if(s!=="Unknown"&&s!=="")return"them"}return"them"}async function rn(e){let t=Ft.join(e,"conversations.json"),o=tn(t);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let n=process.env.LINKEDIN_NAME;if(!n||typeof n!="string"||!n.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,i=0,s=0;for(let c of Object.keys(o)){let l=o[c];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,i++);let f=Array.isArray(l.messages)?l.messages:[],d=nn(f,n),h=d==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==d&&s++,l.lastMessageBy=d,l.conversationStatus=h,r++}if(r===0){console.log(" No conversations to recompute.");return}on(t,o),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${s} had stale lastMessageBy (now corrected).`),i>0&&console.log(` Cleaned ${i} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var Oe={};ue(Oe,{NAME:()=>cn,VERSION:()=>sn,up:()=>fn});import*as I from"fs";import*as Pt from"path";var sn=4,cn="split-connection-timestamps",ln=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function an(e){if(!I.existsSync(e))return null;let t=I.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function un(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{I.writeFileSync(n,o)}catch(r){try{I.unlinkSync(n)}catch{}throw r}try{I.renameSync(n,e)}catch(r){try{I.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}async function fn(e){let t=Pt.join(e,"people.json"),o=an(t);if(!o||typeof o!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let n=0,r=0;for(let i of Object.keys(o)){let s=o[i];!s||typeof s!="object"||(r++,ln.has(s.connectionStatus)&&s.connectionDate&&!s.requestedConnectionAt&&(s.requestedConnectionAt=s.connectionDate,s.connectionDate=null,n++))}if(n===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}un(t,o),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${n} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var dn=pn(import.meta.url),mn=y.dirname(dn),hn=y.dirname(y.dirname(mn));function yn(e){return e&&(e==="~"?Le.homedir():e.startsWith("~/")||e.startsWith("~\\")?y.join(Le.homedir(),e.slice(2)):e)}var N=process.env.DATA_DIR?y.resolve(yn(process.env.DATA_DIR)):hn,z=y.join(N,"collected-profiles"),Q=y.join(N,"market-research"),k=y.join(N,".schema-version"),Mt=[y.join(z,".schema-version"),y.join(Q,".schema-version")],H=4,P=[{version:1,module:Ie},{version:2,module:Re},{version:3,module:De},{version:4,module:Oe}];(function(){P.sort((n,r)=>n.version-r.version);let t=new Set;for(let n of P){if(!Number.isInteger(n.version)||n.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(n.version)} (must be positive integer)`);if(t.has(n.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${n.version}`);t.add(n.version);let r=n.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${n.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==n.version)throw new Error(`MIGRATION_REGISTRY: v${n.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=P.length?P[P.length-1].version:0;if(o!==H)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${H}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let n=0;n<P.length;n++){let r=n+1;if(P[n].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${n} but found v${P[n].version}`)}})();function Jt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
10
|
+
`)}`;try{await Ot.addMessage(s,l)}catch(a){console.error(`[runReport] Failed to post end-of-session message: ${a.message}`)}}var Bo=qo(import.meta.url),Jo=J.dirname(J.dirname(Bo)),xe=process.env.DATA_DIR?J.resolve(process.env.DATA_DIR,"collected-profiles"):J.join(Jo,"collected-profiles"),Ce=J.join(xe,"run-log.json");function Ho(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";C.writeFileSync(n,o);for(let r=0;r<3;r++)try{C.renameSync(n,e);return}catch(i){if(r<2&&(i.code==="EPERM"||i.code==="EBUSY")){let s=Date.now();for(;Date.now()-s<200;);continue}throw i}}function Lt(){try{if(!C.existsSync(Ce))return{runs:[]};let e=JSON.parse(C.readFileSync(Ce,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Ft(e){C.existsSync(xe)||C.mkdirSync(xe,{recursive:!0});try{Ho(Ce,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Pt(e,t="default"){let o=Lt();for(let s of o.runs)s.status==="running"&&(s.status="interrupted",s.result="interrupted",s.timestamp&&(s.duration=Date.now()-new Date(s.timestamp).getTime()));let n=new Date,r={timestamp:n.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(r);let i=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(s=>new Date(s.timestamp).getTime()>i),Ft(o),{script:e,mode:t,startTime:n.getTime(),runIndex:o.runs.length-1}}function $e(e,t,o=null,n=null){if(!e)return;let r=null;try{let s=Lt(),c=s.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=o,c.error=n,r=c.duration;else{let l=s.runs.find(a=>a.script===e.script&&a.status==="running"&&a.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=o,l.error=n,r=l.duration)}Ft(s)}catch(s){console.error(`[runLog] Failed to end run: ${s.message}`)}let i=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(i&&i.length>0&&process.env.NODE_RUN_REPORTS){let s=t==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";Nt({scriptName:e.script,mode:e.mode,status:s,summaryLines:i,error:n,duration:r??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as u from"fs";import*as Fe from"os";import*as y from"path";import{fileURLToPath as hn}from"url";var Re={};ue(Re,{NAME:()=>Go,VERSION:()=>Wo,up:()=>Yo});import*as $ from"fs";import*as he from"path";var Wo=1,Go="normalize-jobs-and-questions",Vo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Ko=50;function Te(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Ie(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{$.writeFileSync(n,o)}catch(r){try{$.unlinkSync(n)}catch{}throw r}try{$.renameSync(n,e)}catch(r){try{$.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}async function Yo(e,t){let o=he.join(e,"jobs.json"),n=he.join(t,"scouted-jobs.json"),r=he.join(e,"application-questions.json"),i=Te(o)||{},s=Te(n)||{},c=0,l=[];for(let p of Object.keys(i)){if(!s[p])continue;let m=s[p],f=i[p];for(let d of Vo)m[d]!=null&&f[d]==null&&(f[d]=m[d]);l.push(p),c++}c>0?(Ie(o,i),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let a=Te(r);if(a&&Array.isArray(a.applications)){let p={},m=0;for(let f of a.applications){let d=f.jobId||"unknown";p[d]||(p[d]={applications:[]});let _=(f.questions||[]).map(S=>{let w={type:S.type||"input",question:S.question||"",answer:S.answer||""};return S.options&&(S.options.length<=Ko?w.options=S.options:(w.optionsOmitted=!0,m++)),S.page&&(w.page=S.page),S.wasPreFilled&&(w.wasPreFilled=!0),S.wasRetry&&(w.wasRetry=!0),w});p[d].applications.push({applicationId:f.applicationId,date:f.date,result:f.result||"submitted",formPages:f.formPages||null,duration:f.duration||null,retries:f.retries||0,failedField:f.failedField||null,questionCount:f.questionCount||_.length,questions:_})}Ie(r,p),console.log(` Phase 2: Rekeyed ${a.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else a&&!a.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let p of l)delete s[p];Ie(n,s),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(s).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var De={};ue(De,{NAME:()=>Qo,VERSION:()=>zo,up:()=>en});import*as T from"fs";import*as Mt from"path";var zo=2,Qo="reset-unread-flags";function Xo(e){return T.existsSync(e)?JSON.parse(T.readFileSync(e,"utf-8")):null}function Zo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{T.writeFileSync(n,o)}catch(r){try{T.unlinkSync(n)}catch{}throw r}try{T.renameSync(n,e)}catch(r){try{T.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}async function en(e){let t=Mt.join(e,"conversations.json"),o=Xo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let n=0;for(let r of Object.keys(o))o[r].unread===!0&&(o[r].unread=!1,n++);if(n===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Zo(t,o),console.log(` Reset unread=false on ${n} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Oe={};ue(Oe,{NAME:()=>on,VERSION:()=>tn,up:()=>ln});import*as I from"fs";import*as Ut from"path";var tn=3,on="recompute-last-message-by",nn=new Set(["draft","confirmed","rejected","needs_review"]);function rn(e){return I.existsSync(e)?JSON.parse(I.readFileSync(e,"utf-8")):null}function sn(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{I.writeFileSync(n,o)}catch(r){try{I.unlinkSync(n)}catch{}throw r}try{I.renameSync(n,e)}catch(r){try{I.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}function cn(e,t){if(!e||e.length===0)return"them";let o=e.filter(i=>!nn.has(i.status));if(o.length===0)return"them";let n=o.map(i=>({m:i,t:Date.parse(i.time)})).filter(i=>Number.isFinite(i.t)).sort((i,s)=>s.t-i.t).map(i=>i.m),r=n.length>0?n:[...o].reverse();for(let i of r){let s=i.sender;if(s===t)return"me";if(s!=="Unknown"&&s!=="")return"them"}return"them"}async function ln(e){let t=Ut.join(e,"conversations.json"),o=rn(t);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let n=process.env.LINKEDIN_NAME;if(!n||typeof n!="string"||!n.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,i=0,s=0;for(let c of Object.keys(o)){let l=o[c];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,i++);let a=Array.isArray(l.messages)?l.messages:[],p=cn(a,n),m=p==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==p&&s++,l.lastMessageBy=p,l.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}sn(t,o),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${s} had stale lastMessageBy (now corrected).`),i>0&&console.log(` Cleaned ${i} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var Ne={};ue(Ne,{NAME:()=>un,VERSION:()=>an,up:()=>mn});import*as R from"fs";import*as qt from"path";var an=4,un="split-connection-timestamps",fn=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function pn(e){if(!R.existsSync(e))return null;let t=R.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function dn(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{R.writeFileSync(n,o)}catch(r){try{R.unlinkSync(n)}catch{}throw r}try{R.renameSync(n,e)}catch(r){try{R.unlinkSync(n)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let i=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw i.code=r.code,i}throw r}}async function mn(e){let t=qt.join(e,"people.json"),o=pn(t);if(!o||typeof o!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let n=0,r=0;for(let i of Object.keys(o)){let s=o[i];!s||typeof s!="object"||(r++,fn.has(s.connectionStatus)&&s.connectionDate&&!s.requestedConnectionAt&&(s.requestedConnectionAt=s.connectionDate,s.connectionDate=null,n++))}if(n===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}dn(t,o),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${n} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var yn=hn(import.meta.url),gn=y.dirname(yn),Sn=y.dirname(y.dirname(gn));function bn(e){return e&&(e==="~"?Fe.homedir():e.startsWith("~/")||e.startsWith("~\\")?y.join(Fe.homedir(),e.slice(2)):e)}var N=process.env.DATA_DIR?y.resolve(bn(process.env.DATA_DIR)):Sn,z=y.join(N,"collected-profiles"),Q=y.join(N,"market-research"),A=y.join(N,".schema-version"),Bt=[y.join(z,".schema-version"),y.join(Q,".schema-version")],H=4,M=[{version:1,module:Re},{version:2,module:De},{version:3,module:Oe},{version:4,module:Ne}];(function(){M.sort((n,r)=>n.version-r.version);let t=new Set;for(let n of M){if(!Number.isInteger(n.version)||n.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(n.version)} (must be positive integer)`);if(t.has(n.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${n.version}`);t.add(n.version);let r=n.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${n.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==n.version)throw new Error(`MIGRATION_REGISTRY: v${n.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=M.length?M[M.length-1].version:0;if(o!==H)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${H}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let n=0;n<M.length;n++){let r=n+1;if(M[n].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${n} but found v${M[n].version}`)}})();function Gt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
9
11
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
10
|
-
`),process.exit(1));try{
|
|
12
|
+
`),process.exit(1));try{u.mkdirSync(N,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
11
13
|
[FATAL] Cannot create DATA_DIR (${N}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
12
|
-
`),process.exit(1))}let e;try{e=
|
|
14
|
+
`),process.exit(1))}let e;try{e=u.statSync(N)}catch(t){console.error(`
|
|
13
15
|
[FATAL] DATA_DIR (${N}) is not accessible: ${t.message}
|
|
14
16
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
15
17
|
[FATAL] DATA_DIR (${N}) exists but is NOT a directory.`),console.error(` Looks like a typo \u2014 your DATA_DIR points at a file. Fix the path and try again.
|
|
16
|
-
`),process.exit(1));for(let t of[z,Q]){let o;try{o=
|
|
18
|
+
`),process.exit(1));for(let t of[z,Q]){let o;try{o=u.lstatSync(t)}catch(n){if(n.code==="ENOENT")continue;throw n}o.isSymbolicLink()&&(console.error(`
|
|
17
19
|
[FATAL] Data subdirectory is a symbolic link: ${t}`),console.error(" Refusing to follow \u2014 backup code would copy whatever the link points at."),console.error(` If this is intentional, replace the symlink with the real directory.
|
|
18
|
-
`),process.exit(1))}}var Y=y.join(N,".migration-lock");function
|
|
20
|
+
`),process.exit(1))}}var Y=y.join(N,".migration-lock");function wn(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return u.writeFileSync(Y,e,{flag:"wx"}),!0}catch(n){if(n.code!=="EEXIST")throw n}let t;try{t=JSON.parse(u.readFileSync(Y,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let n=!1;try{process.kill(t.pid,0),n=!0}catch(s){s.code==="EPERM"&&(n=!0)}let r=24*60*60*1e3,i=1/0;if(t.startedAt){let s=Date.parse(t.startedAt);Number.isNaN(s)||(i=Date.now()-s)}n&&i<r&&(console.error(`
|
|
19
21
|
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${Y}
|
|
20
22
|
`),console.error(" Wait for it to finish, or if you're sure it's not actually running,"),console.error(` delete the lock file manually and re-run.
|
|
21
|
-
`),process.exit(1)),n&&i>=r&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let o=Y+".tmp";try{return
|
|
23
|
+
`),process.exit(1)),n&&i>=r&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let o=Y+".tmp";try{return u.writeFileSync(o,e),u.renameSync(o,Y),!0}catch(n){try{u.unlinkSync(o)}catch{}throw new Error(`Failed to take over stale migration lock: ${n.message}`)}}function Pe(){try{if(JSON.parse(u.readFileSync(Y,"utf-8")).pid!==process.pid)return;u.unlinkSync(Y)}catch{}}var Jt=!1;function vn(){if(Jt)return;Jt=!0;let e=()=>{try{Pe()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function kn(){if(u.existsSync(A))return;let e=[],t=[];for(let i of Bt)if(u.existsSync(i))try{e.push({file:i,schema:ye(i)})}catch(s){t.push({file:i,err:s.message})}if(t.length>0){console.error(`
|
|
22
24
|
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let i of t)console.error(` ${i.file}: ${i.err}`);console.error(`
|
|
23
25
|
Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
|
|
24
26
|
`),process.exit(1)}if(e.length===0)return;let o=e.map(i=>i.schema.version);if(new Set(o).size>1){console.error(`
|
|
25
27
|
[FATAL] Legacy .schema-version files disagree:`);for(let i of e)console.error(` ${i.file}: v${i.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
|
|
26
|
-
`),process.exit(1)}let n=e[0].schema,r=
|
|
27
|
-
[FATAL] ${
|
|
28
|
-
`),process.exit(1)}let t=
|
|
29
|
-
[FATAL] ${
|
|
30
|
-
`),process.exit(1)),t}function
|
|
28
|
+
`),process.exit(1)}let n=e[0].schema,r=A+".tmp";try{u.writeFileSync(r,JSON.stringify(n,null,2)),u.renameSync(r,A)}catch(i){try{u.unlinkSync(r)}catch{}throw i}for(let i of Bt)if(u.existsSync(i))try{u.unlinkSync(i)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${A}`)}function An(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function ye(e){let t=u.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Ht(){if(kn(),!u.existsSync(A))return{version:0,migrations:[]};let e;try{e=ye(A)}catch(o){if(o.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
29
|
+
[FATAL] ${A} is not valid JSON: ${o.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
30
|
+
`),process.exit(1)}let t=An(e);return t===null&&(console.error(`
|
|
31
|
+
[FATAL] ${A} has invalid structure:`),console.error(` ${JSON.stringify(e)?.slice(0,200)||"(unparseable)"}`),console.error(' Expected shape: { "version": <integer>, "migrations": [...] }'),console.error(` Repair the file or restore from a backup.
|
|
32
|
+
`),process.exit(1)),t}function Vt(e){try{u.chmodSync(e,384)}catch{}}function _n(e){if(Gt(),u.existsSync(A))try{if(u.lstatSync(A).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${A}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(o){if(o.message?.includes("symbolic link"))throw o}let t=A+".tmp";try{u.writeFileSync(t,JSON.stringify(e,null,2)),Vt(t),u.renameSync(t,A)}catch(o){try{u.unlinkSync(t)}catch{}throw o}}function Wt(e,t){if(!u.existsSync(e))return;let o=`.pre-v${String(t).padStart(3,"0")}.backup`,n=u.readdirSync(e).filter(c=>{let l=c.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return u.statSync(y.join(e,c)).isFile()}catch{return!1}}),r=0,i=0,s=[];for(let c of n){let l=y.join(e,c),a=y.join(e,c+o);if(u.existsSync(a)){i++;continue}try{Yt(l,a),r++}catch(p){s.push({file:c,err:p.message})}}if(s.length>0){let c=new Error(`Failed to back up ${s.length} file(s) in ${y.basename(e)}/: `+s.map(l=>`${l.file} (${l.err})`).join(", "));throw c.code="BACKUP_INCOMPLETE",c}if(r>0||i>0){let c=i>0?` (${i} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${y.basename(e)}/ (${o})${c}`)}}var Le=!1;async function Kt(){if(Le)return;Gt(),$n();let t=Ht().version;if(t===H){Le=!0;return}vn(),wn(),process.on("exit",Pe),t>H&&(console.error(`
|
|
31
33
|
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${H}.`),console.error(" This usually means you downgraded the plugin without rolling back data."),console.error(` Operating on the newer-format data with this build would risk corrupting it.
|
|
32
34
|
`),console.error(" Options:"),console.error(" A) Re-install the newer plugin version that produced this schema, then"),console.error(" (if you really want to downgrade) run 'rollback-data --confirm' first,"),console.error(" then re-install the older plugin version."),console.error(` B) Manually restore your data from the *.pre-vNNN.backup files matching v${H}.
|
|
33
35
|
`),process.exit(1)),console.log(`
|
|
34
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${H}`);let o=
|
|
36
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${H}`);let o=Tn();if(!o.ok){console.error(`
|
|
35
37
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of o.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
36
38
|
Migration ABORTED. No backups taken, no files modified.`),console.error(" Repair the file(s) above (restore from your own backup, or fix manually)"),console.error(` and try again. To inspect: 'ilml linkedin migrate-status'.
|
|
37
|
-
`),process.exit(1)}let n=
|
|
38
|
-
Running migration v${String(r.version).padStart(3,"0")}...`);let i=`v${String(r.version).padStart(3,"0")}`,s=`.pre-${i}.backup`;try{
|
|
39
|
+
`),process.exit(1)}let n=M.filter(r=>r.version>t);for(let r of n){console.log(`
|
|
40
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let i=`v${String(r.version).padStart(3,"0")}`,s=`.pre-${i}.backup`;try{Wt(z,r.version),Wt(Q,r.version)}catch(l){console.error(`
|
|
39
41
|
[FATAL] Pre-migration backup failed for ${i}: ${l.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
40
42
|
`),process.exit(1)}let c=r.module;try{await c.up(z,Q)}catch(l){console.error(`
|
|
41
|
-
[FATAL] Migration ${i} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${s} files...`);try{let
|
|
42
|
-
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${
|
|
43
|
-
`))}catch(
|
|
44
|
-
`)}process.exit(1)}try{let l=new Date().toISOString(),
|
|
43
|
+
[FATAL] Migration ${i} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${s} files...`);try{let a=In(s);a.ok?(console.error(` \u2713 Auto-rollback restored ${a.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
44
|
+
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${a.error}`),console.error(` Manual recovery: copy *${s} files back over the originals.
|
|
45
|
+
`))}catch(a){console.error(` [!] Auto-rollback CRASHED while restoring: ${a.message}`),console.error(` Manual recovery: copy *${s} files back over the originals.
|
|
46
|
+
`)}process.exit(1)}try{let l=new Date().toISOString(),a={version:r.version,name:c.NAME||i,appliedAt:l},p=Ht();p.version=r.version,p.migratedAt=l,p.migrations=p.migrations||[],p.migrations.push(a),_n(p)}catch(l){console.error(`
|
|
45
47
|
[FATAL] Migration ${i} applied successfully but schema version file could NOT be updated: ${l.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${t}.`),console.error(` On next plugin command the runner will try to re-apply ${i}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
|
|
46
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${i} complete`)}try{
|
|
48
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${i} complete`)}try{Ct()}catch{}try{vt()}catch{}Le=!0,Pe(),console.log(`
|
|
47
49
|
\u2713 Schema is now at v${H}
|
|
48
|
-
`)}var
|
|
50
|
+
`)}var En=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function jn(e){let t=e.toLowerCase();return En.some(o=>o.test(t))}var xn=6e4;function Cn(){let e=Date.now(),t=[];for(let o of[N,z,Q]){if(!u.existsSync(o))continue;let n;try{n=u.readdirSync(o)}catch{continue}for(let r of n){if(!jn(r))continue;let i=y.join(o,r);try{let s=u.statSync(i);if(!s.isFile()||e-s.mtimeMs<xn)continue;t.push({dir:o,file:r,fullPath:i})}catch{}}}return t}function $n({verbose:e=!1}={}){let t=Cn();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let n of t)try{u.unlinkSync(n.fullPath),o++,e&&console.log(` Removed orphan: ${y.basename(n.dir)}/${n.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${n.fullPath}: ${r.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function Tn(){let e=[];for(let t of[z,Q]){if(!u.existsSync(t))continue;let o=u.readdirSync(t).filter(n=>{let r=n.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let n of o){let r=y.join(t,n);try{ye(r)}catch(i){e.push({dir:y.basename(t),file:n,err:i.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function In(e){let t=[],o=[];for(let i of[z,Q]){if(!u.existsSync(i))continue;let s=u.readdirSync(i).filter(c=>c.endsWith(e));for(let c of s){let l=y.join(i,c),a=c.slice(0,-e.length),p=y.join(i,a);try{a.toLowerCase().endsWith(".json")?ye(l):u.accessSync(l,u.constants.R_OK),t.push({backupPath:l,originalPath:p,fileName:c,dir:i})}catch(m){o.push(`${y.basename(i)}/${c}: ${m.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let n=0,r=[];for(let{backupPath:i,originalPath:s,fileName:c,dir:l}of t)try{Yt(i,s),n++}catch(a){r.push(`${y.basename(l)}/${c}: ${a.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:n}:{ok:!0,restored:n}}function Yt(e,t){let o=t+".tmp";try{u.copyFileSync(e,o),Vt(o)}catch(n){try{u.unlinkSync(o)}catch{}throw n}try{u.renameSync(o,t)}catch(n){try{u.unlinkSync(o)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let r=new Error(`File locked: ${t} (${n.code}). On Windows this is usually antivirus / Search Indexer / the file open in another app. Close anything that might be holding it and re-run.`);throw r.code=n.code,r}throw n}}await Kt();var ie=process.argv.slice(2),X=parseInt(ie.find(e=>e.startsWith("--max="))?.split("=")[1]||"200"),zt=parseInt(ie.find(e=>e.startsWith("--pages="))?.split("=")[1]||"20"),Qt=ie.find(e=>e.startsWith("--url="))?.split("=").slice(1).join("="),Rn=ie.includes("--list"),Me=ie.includes("--verbose");function Dn(){if(Qt)return[Qt];let e=process.env.LINKEDIN_SCOUT_URLS;if(e)return e.split(",").map(o=>o.trim()).filter(Boolean);let t=process.env.LINKEDIN_SEARCH_URL;return t?[t]:[]}function On(){let e=jt();console.log(`
|
|
49
51
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" MARKET RESEARCH STATS"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Scouted jobs: ${e.totalJobs}`),console.log(` Discovered recruiters: ${e.totalRecruiters}`),console.log(` Last scout: ${e.lastScoutDate||"never"}`),console.log(` Profile visits: ${e.totalVisited} unique (${e.todayVisited} today)`),e.topTech.length>0&&console.log(` Top tech: ${e.topTech.join(", ")}`),e.topCompanies.length>0&&console.log(` Top companies: ${e.topCompanies.join(", ")}`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
50
|
-
`)}async function
|
|
52
|
+
`)}async function Nn(){if(console.log(`
|
|
51
53
|
LinkedIn Job Scout
|
|
52
|
-
`)
|
|
53
|
-
`);let{browser:s,page:c}=await
|
|
54
|
-
\u2550\u2550\u2550 Scout URL ${o.urlsProcessed}/${e.length}: ${l.slice(0,70)}... \u2550\u2550\u2550`),await c.goto(l,{waitUntil:"domcontentloaded",timeout:6e4}),await
|
|
55
|
-
\u2500\u2500 Page ${
|
|
54
|
+
`),Rn){On();return}let e=Dn();e.length===0&&(console.error("No search URL. Set LINKEDIN_SCOUT_URL or LINKEDIN_SCOUT_URLS in .env, or use --url=..."),process.exit(1));let t=Pt("scout",`max=${X},urls=${e.length}`),o={scouted:0,recruitersFound:0,skipped:0,skippedApplied:0,alreadyConnected:0,pages:0,errors:0,urlsProcessed:0},n=me(),r=Rt(),i=It();console.log(` Scout URLs: ${e.length}`),e.forEach((l,a)=>console.log(` ${a+1}. ${l.slice(0,80)}...`)),console.log(` Max jobs: ${X} | Max pages per URL: ${zt}
|
|
55
|
+
`);let{browser:s,page:c}=await ut();try{for(let l of e){if(o.scouted>=X)break;o.urlsProcessed++,console.log(`
|
|
56
|
+
\u2550\u2550\u2550 Scout URL ${o.urlsProcessed}/${e.length}: ${l.slice(0,70)}... \u2550\u2550\u2550`),await c.goto(l,{waitUntil:"domcontentloaded",timeout:6e4}),await j(3e3);let a=0,p=!1;for(let m=0;m<zt&&o.scouted<X&&!p;m++){o.pages++,console.log(`
|
|
57
|
+
\u2500\u2500 Page ${m+1} \u2500\u2500`),await mt(c,l),await ft(c),await j(1e3);let f=await pt(c,{easyApplyOnly:!1});console.log(` Found ${f.length} jobs on page`);for(let d of f){if(o.scouted>=X)break;let _=d.href?.match(/jobs\/view\/(\d+)/)?.[1]||d.id?.match(/\d+/)?.[0];if(_&&n[_]){o.skipped++;continue}if(_&&r[_]){o.skippedApplied++;continue}try{let S=await c.$(`a[data-control-id="${d.dataId}"]`);if(!S)continue;let w=await c.evaluate(()=>document.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24")?.innerText?.trim()?.slice(0,80)||"");await S.click(),await j(1500+Math.random()*1500);for(let U=0;U<8;U++){let q=await c.evaluate(ge=>{let Se=document.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24"),ce=document.querySelector(".jobs-description__content"),le=Se?.innerText?.trim()?.slice(0,80)||"",be=ce?.innerText?.trim()?.length||0;return{title:le,descLen:be,titleChanged:le!==ge&&le.length>0}},w);if(q.titleChanged&&q.descLen>50)break;await j(600)}let g=await yt(c),L=await ht(c);if(_&&(kt(_,{title:d.jobTitle,company:g.companyName||d.companyName,companyUrl:g.companyUrl,location:d.location,salary:d.salary,url:d.href,isEasyApply:d.isEasyApply,applyType:d.applyType||(d.isEasyApply?"easy-apply":"external"),externalApplyUrl:g.externalApplyUrl,description:g.description,techStack:g.techStack,jobTags:g.jobTags,seniority:g.seniority,employmentType:g.employmentType,industries:g.industries,jobFunction:g.jobFunction,postedTime:g.postedTime,applicantCount:g.applicantCount,companySize:g.companySize,workplaceType:g.workplaceType,contractType:g.contractType,recruiterUrl:L?.profileUrl||null}),o.scouted++),g.companyUrl&&Et(g.companyUrl,{name:g.companyName||d.companyName,about:g.aboutCompany,size:g.companySize,industries:g.industries,jobId:_,recruiterUrl:L?.profileUrl}),L?.profileUrl){let q=i[L.profileUrl]?.connectionStatus==="connected";_t(L.profileUrl,{name:L.name,source:"scout",role:"recruiter",jobId:_,jobTitle:d.jobTitle,isConnected:q}),o.recruitersFound++,q&&o.alreadyConnected++}if(Me){let U=g.techStack?.slice(0,5).join(", ")||"none";console.log(` [${o.scouted}] ${d.jobTitle?.slice(0,40)} @ ${d.companyName?.slice(0,20)} | ${U}${L?" | \u{1F464} "+L.name:""}`)}else o.scouted%10===0&&console.log(` Scouted: ${o.scouted} (${o.recruitersFound} recruiters)`)}catch(S){o.errors++,a++,Me&&console.error(` Error: ${S.message?.slice(0,80)}`);let w=(S.message||"").toLowerCase();if(w.includes("detached")||w.includes("session closed")||w.includes("target closed")||w.includes("browser has disconnected")||w.includes("protocol error")){console.log(" \u26A0 Fatal browser error \u2014 stopping scout"),p=!0;break}if(a>=5){console.log(" \u26A0 5 consecutive errors \u2014 stopping scout"),p=!0;break}continue}a=0}if(p)break;if(o.scouted<X)try{if(!await dt(c)){console.log(" No more pages.");break}await j(2e3)}catch(d){console.log(` \u26A0 Pagination failed: ${d.message?.slice(0,60)}`);break}}if(p)break}console.log(`
|
|
56
58
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" Scout Complete"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` URLs processed: ${o.urlsProcessed}/${e.length}`),console.log(` Pages scanned: ${o.pages}`),console.log(` Jobs scouted: ${o.scouted}`),console.log(` Skipped (existing): ${o.skipped}`),console.log(` Skipped (applied): ${o.skippedApplied}`),console.log(` Recruiters found: ${o.recruitersFound} (${o.alreadyConnected} already connected)`),console.log(` Errors: ${o.errors}`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
57
|
-
`)
|
|
58
|
-
Error:`,l.message),
|
|
59
|
+
`),$e(t,"success",o)}catch(l){console.error(`
|
|
60
|
+
Error:`,l.message),Me&&console.error(l.stack),$e(t,"error",o,l.message)}finally{await s.close().catch(()=>{})}}Nn().catch(e=>{console.error("Scout failed:",e),process.exit(1)});
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.20.
|
|
1
|
+
import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.20.11";try{let n=new URL("./ilml-plugin.json",import.meta.url);return JSON.parse(e(r(n),"utf-8")).version}catch{return"unknown"}}console.log(`ilml-plugin-linkedin ${i()}`);
|
package/ilml-plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linkedin",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.11",
|
|
4
4
|
"description": "Reference ilml plugin: keep a local mirror of your LinkedIn data with AI-assisted workflows",
|
|
5
5
|
"commands": {
|
|
6
6
|
"help": { "run": "node dist/help.mjs", "description": "List all commands with descriptions; or `help <cmd>` for detailed info on one command (usage, flags, ban-risk, when-to-use). Reads ilml-plugin.json directly.", "usage": "ilml linkedin help [<cmd>]", "useWhen": "You forgot what a command does, or you're an AI agent picking the right tool." },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilml-plugin-linkedin",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.11",
|
|
4
4
|
"description": "Reference ilml plugin: keep a local mirror of your LinkedIn data and run AI-assisted workflows under your direction.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"puppeteer",
|
|
78
78
|
"ai-assistant"
|
|
79
79
|
],
|
|
80
|
-
"author": "
|
|
80
|
+
"author": "Ilya Sorokin (https://digitaltwins.team/in/ilya-sorokin)",
|
|
81
81
|
"license": "UNLICENSED",
|
|
82
82
|
"bugs": {
|
|
83
83
|
"url": "https://github.com/iLiveMyLife/linkedInJobsAutoApply/issues"
|