ilml-plugin-linkedin 1.20.20 → 1.20.22

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/dist/visit.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  var Mn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{for(var n in t)Mn(e,n,{get:t[n],enumerable:!0})};import T from"fs";import V from"path";function Le(){let e=process.env.ILML_SCOPE_DIR;return e?V.join(e,"plugins-state","linkedin","cookies.json"):qn}function Un(){let e=Le(),t=V.dirname(e);return t&&t!=="."&&!T.existsSync(t)&&T.mkdirSync(t,{recursive:!0}),e}function bt(e){let t=Un();return T.writeFileSync(t,JSON.stringify(e)),t}function vt(){let e=Le();if(!T.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=T.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function kt(){return T.existsSync(Le())}function Bn(){let e=process.env.ILML_SCOPE_DIR;return e?V.join(e,"plugins-state","linkedin"):"."}function Ct(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function Vn(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?Ct(t[1]):"default"}function xt(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return T.existsSync(t)||T.mkdirSync(t,{recursive:!0}),V.resolve(t);let n=Ct(e||Vn()),o=V.join(Bn(),"chrome-profile",n);return T.existsSync(o)||T.mkdirSync(o,{recursive:!0}),V.resolve(o)}function Et(e){return!T.existsSync(V.join(e,At))}function _t(e){try{T.writeFileSync(V.join(e,At),new Date().toISOString())}catch{}}function $t(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{T.rmSync(V.join(e,n),{force:!0}),t++}catch{}return t}var qn,At,Ee=Y(()=>{qn="cookies.json";At=".ilml-seeded"});async function x(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function Hn(e,t,{timeout:n=45e3,poll:o=1e3,label:r="page"}={}){let s=Date.now();for(;Date.now()-s<n;){try{if(await e.evaluate(a=>!!document.querySelector(a),t)){let a=Date.now()-s;return a>6e3&&console.log(` (waited ${Math.round(a/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(i=>setTimeout(i,o))}return!1}function Jn(e){return Rt.test(e||"")}async function Wn(e,{credentialWaitMs:t=36e4,label:n="page"}={}){console.log(` \u26A0 Auth wall on ${n} \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 o=!!(process.stdin&&process.stdin.isTTY),r=o?t:Math.min(t,45e3),s=Date.now(),i=!1;for(;Date.now()-s<r;){let l="wait";try{l=await e.evaluate(d=>!new RegExp(d).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",Rt.source)}catch{}if(l==="in"){try{let d=await e.cookies();if(Array.isArray(d)&&d.some(p=>p.name==="li_at")){let p=bt(d);console.log(` \u2713 Session recovered \u2014 re-saved ${d.length} cookies (${p}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(d){console.log(` \u2713 Session recovered (cookie re-save skipped: ${d.message}).`)}return!0}if(l==="creds"){if(!o){let d=new Error(`Session expired (${n}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw d.code="SESSION_EXPIRED",d}i||(i=!0,console.log(`
2
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(d=>setTimeout(d,2500))}let a=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}async function It(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await Hn(e,t,{timeout:o,label:n});if(!r&&Jn(e.url())){let s=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}return r}async function ce(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:s=6e4,autoRecover:i=!0}={}){await e.goto(t,{waitUntil:"domcontentloaded",timeout:s});try{return await It(e,{readySelector:n,label:o,timeout:r})}catch(a){if(i&&a.code==="SESSION_EXPIRED"){await Wn(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await It(e,{readySelector:n,label:o,timeout:r})}throw a}}async function Tt(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let r=o.innerText||"",s=r.includes("Premium")||r.includes("premium")||r.includes("Upgrade")||r.includes("upgrade"),i=r.includes("Try for")||r.includes("free trial")||r.includes("/month")||r.includes("per month")||r.includes("Start my")||r.includes("Subscribe"),a=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||a){let l=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(l)return l.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let c of d){let p=c.innerText?.trim().toLowerCase()||"",u=c.getAttribute("aria-label")?.toLowerCase()||"";if(p==="not now"||p==="no thanks"||p==="dismiss"||u.includes("dismiss"))return c.click(),{dismissed:!0,matched:r.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var Rt,he=Y(()=>{Ee();Rt=/\/authwall|\/login|\/checkpoint|\/uas\/login/});function Yn(e){return String(e??"").split(/[,\s|]+/).map(t=>t.trim()).filter(Boolean)}function Ot(e=process.env){let t=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!t)return null;let n=new URLSearchParams;n.set("keywords",t);let o=(e.JOB_SEARCH_LOCATION||"").trim();o&&n.set("location",o);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&n.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&n.set("distance",String(s)),Dt(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),Dt(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Yn(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let a=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();a&&n.set("f_TPR",Gn[a]||a),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let l="https://www.linkedin.com/jobs/search/?"+n.toString(),d=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return d&&(l+="&"+d),l}var Gn,Dt,jt=Y(()=>{Gn={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},Dt=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim())});import{getPluginConfig as Kn}from"@ilivemylife/graph-sdk";var zn,Nt,Qn,Z,es,Xn,Pe=Y(async()=>{jt();zn=await Kn();for(let[e,t]of Object.entries(zn))process.env[e]===void 0&&(process.env[e]=t);Nt=Ot(process.env);Nt&&(process.env.LINKEDIN_SEARCH_URL=Nt);Qn=process.env.LINKEDIN_NAME,Z=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),es=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.NEEDS_REVIEW])),Xn=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.REJECTED,Z.NEEDS_REVIEW]))});import"dotenv/config";import*as A from"fs";import*as _ from"path";import{fileURLToPath as ao}from"url";function zt(){ue=null,fo=null,mo=null,po=null,ho=null,go=null}function Qt(){A.existsSync(H)||A.mkdirSync(H,{recursive:!0})}function Xt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";A.writeFileSync(o,n);for(let r=0;r<3;r++)try{A.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function Zt(e,t){if(!A.existsSync(e))return null;try{let n=JSON.parse(A.readFileSync(e,"utf-8"));try{A.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${_.resolve(e)}`);let o=e+".backup";if(A.existsSync(o))try{let r=JSON.parse(A.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{A.copyFileSync(o,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{A.copyFileSync(e,e+".corrupted")}catch{}return null}}function yo(){return new Date().toISOString().split("T")[0]}function ee(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Wt(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function en(e,t,n=null){if(!t||e[t])return t;let o=ee(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(ee(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=Wt(n),i=Wt(e[r].name);if(s&&i&&s===i)return r}return t}function bo(){A.existsSync(Ue)||A.mkdirSync(Ue,{recursive:!0})}function tn(e){let t=ee(e);return t?_.join(Ue,`${t}.json`):null}function vo(e){let t=tn(e);return t?Zt(t,`profile-history/${ee(e)}.json`)||[]:[]}function ko(e,t){let n=tn(e);if(!n)return;bo();let o=vo(e);o.unshift(t);try{Xt(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${ee(e)}: ${r.message}`)}}function Gt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Yt(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Co(e,t){if(!e)return[];let n=[];for(let o of So){let r=e[o],s=t[o];Gt(r)||Gt(s)||Yt(r)!==Yt(s)&&n.push(o)}return n}function xo(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,r]of Object.entries(e))t.has(o)||(n[o]=r);return n}function de(){return ue||(Qt(),ue=Zt(qe,"people.json")||{},ue)}function nn(e){Qt(),ue=e;try{Xt(qe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${_.resolve(qe)}`)}}function Be(e,t={}){if(!e)return null;let n=de(),o=yo(),r=new Date().toISOString(),s=en(n,e,t.name),i=n[s];if(i){let a=Co(i,t);a.length>0&&(ko(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:a,snapshot:xo(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let l of wo)if(t[l]!=null){if(Array.isArray(t[l])&&t[l].length===0&&Array.isArray(i[l])&&i[l].length>0)continue;i[l]=t[l]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return nn(n),n[s]}function Ve(e,t,n={}){if(n.dryRun||!e||!t)return;let o=ee(t);if(!o)return;let r=de(),s=en(r,e),i=r[s];if(!i)return;let a=ee(i.profileUrl||s);o!==a&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),nn(r)))}var co,uo,H,qe,vs,ks,Cs,xs,As,Ue,Kt,Es,_s,ue,fo,mo,po,ho,go,wo,So,$e=Y(async()=>{await Pe();co=ao(import.meta.url),uo=_.dirname(_.dirname(co)),H=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"collected-profiles"):_.join(uo,"collected-profiles"),qe=_.join(H,"people.json"),vs=_.join(H,"jobs.json"),ks=_.join(H,"quota.json"),Cs=_.join(H,"conversations.json"),xs=_.join(H,"sync-state.json"),As=_.join(H,"application-questions.json"),Ue=_.join(H,"profile-history"),Kt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Es=Kt(process.env.CONNECT_MAX_DAILY,20),_s=Kt(process.env.CONNECT_MAX_WEEKLY,100),ue=null,fo=null,mo=null,po=null,ho=null,go=null;wo=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt","featured","education","skillsFull","recommendations","certifications"],So=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var on={};pe(on,{extractCertificationsFromDetails:()=>Io,extractEducationFromDetails:()=>_o,extractExperienceFromDetails:()=>Ao,extractFeaturedFromDetails:()=>Eo,extractRecommendationsFromDetails:()=>Ro,extractSkillsFromDetails:()=>$o});async function Ao(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await ce(e,n,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await x(1e3);let o=e.url();if(!o.toLowerCase().includes("/details/experience/"))throw new Error(`Section /details/experience/ not available on profile (landed on ${o})`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(900);await x(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await x(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(c){let p=[];for(let u of c.querySelectorAll("div")){let f=Array.from(u.children).filter(b=>b.tagName==="DIV");if(f.length<3)continue;let C=f.filter(b=>(b.textContent||"").trim().length>50);C.length<3||(u.textContent||"").length<500||p.push({el:u,count:C.length,totalText:(u.textContent||"").length})}return p.sort((u,f)=>f.count-u.count||u.totalText-f.totalText),p[0]?.el}let a=i(s);if(!a)return[];let l=Array.from(a.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function d(c){let p=c[0]||null,u=null,f=null;if(c[1]){let v=c[1].split("\xB7").map(I=>I.trim());u=v[0]||null,v[1]&&(f=v[1])}let C=c.findIndex(v=>/(\d{4}|present)/i.test(v)&&/(-|–|—)/i.test(v)&&v.length<80),b=null,$=null;if(C>=0){let v=c[C].split("\xB7").map(I=>I.trim());b=v[0]||null,v[1]&&($=v[1])}let y=null,g=-1;if(C>=0&&c[C+1]){let v=c[C+1],I=/^[>*\-•]|^&gt;/.test(v),le=/https?:\/\//.test(v),ae=/\d{4}/.test(v),R=/,/.test(v)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(v);!I&&!le&&!ae&&v.length<100&&R&&(y=v,g=C+1)}let B=null,E=-1,Q=c[c.length-1];if(Q&&/and\s+\+\d+\s+skills?$/i.test(Q)){E=c.length-1;let v=Q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);v&&(B={listed:v[1].split(",").map(I=>I.trim()),additional:parseInt(v[2],10)})}let X=new Set([0,1,C,g,E].filter(v=>v>=0)),W=c.filter((v,I)=>!X.has(I)),O=W.length>0?W.join(`
3
+ `))}await new Promise(d=>setTimeout(d,2500))}let a=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}async function It(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await Hn(e,t,{timeout:o,label:n});if(!r&&Jn(e.url())){let s=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}return r}async function ce(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:s=6e4,autoRecover:i=!0}={}){await e.goto(t,{waitUntil:"domcontentloaded",timeout:s});try{return await It(e,{readySelector:n,label:o,timeout:r})}catch(a){if(i&&a.code==="SESSION_EXPIRED"){await Wn(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await It(e,{readySelector:n,label:o,timeout:r})}throw a}}async function Tt(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let r=o.innerText||"",s=r.includes("Premium")||r.includes("premium")||r.includes("Upgrade")||r.includes("upgrade"),i=r.includes("Try for")||r.includes("free trial")||r.includes("/month")||r.includes("per month")||r.includes("Start my")||r.includes("Subscribe"),a=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||a){let l=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(l)return l.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let c of d){let p=c.innerText?.trim().toLowerCase()||"",u=c.getAttribute("aria-label")?.toLowerCase()||"";if(p==="not now"||p==="no thanks"||p==="dismiss"||u.includes("dismiss"))return c.click(),{dismissed:!0,matched:r.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var Rt,he=Y(()=>{Ee();Rt=/\/authwall|\/login|\/checkpoint|\/uas\/login/});function Yn(e){return String(e??"").split(/[,\s|]+/).map(t=>t.trim()).filter(Boolean)}function Ot(e=process.env){let t=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!t)return null;let n=new URLSearchParams;n.set("keywords",t);let o=(e.JOB_SEARCH_LOCATION||"").trim();o&&n.set("location",o);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&n.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&n.set("distance",String(s)),Dt(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),Dt(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Yn(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let a=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();a&&n.set("f_TPR",Gn[a]||a),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let l="https://www.linkedin.com/jobs/search/?"+n.toString(),d=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return d&&(l+="&"+d),l}var Gn,Dt,jt=Y(()=>{Gn={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},Dt=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim())});import{getPluginConfig as Kn}from"@ilivemylife/graph-sdk";var zn,Nt,Qn,Z,es,Xn,Pe=Y(async()=>{jt();zn=await Kn();for(let[e,t]of Object.entries(zn))process.env[e]===void 0&&(process.env[e]=t);Nt=Ot(process.env);Nt&&(process.env.LINKEDIN_SEARCH_URL=Nt);Qn=process.env.LINKEDIN_NAME,Z=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),es=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.NEEDS_REVIEW])),Xn=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.REJECTED,Z.NEEDS_REVIEW]))});import"dotenv/config";import*as A from"fs";import*as _ from"path";import{fileURLToPath as ao}from"url";function zt(){ue=null,fo=null,mo=null,po=null,ho=null,go=null}function Qt(){A.existsSync(H)||A.mkdirSync(H,{recursive:!0})}function Xt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";A.writeFileSync(o,n);for(let r=0;r<3;r++)try{A.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function Zt(e,t){if(!A.existsSync(e))return null;try{let n=JSON.parse(A.readFileSync(e,"utf-8"));try{A.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${_.resolve(e)}`);let o=e+".backup";if(A.existsSync(o))try{let r=JSON.parse(A.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{A.copyFileSync(o,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{A.copyFileSync(e,e+".corrupted")}catch{}return null}}function yo(){return new Date().toISOString().split("T")[0]}function ee(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Wt(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function en(e,t,n=null){if(!t||e[t])return t;let o=ee(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(ee(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=Wt(n),i=Wt(e[r].name);if(s&&i&&s===i)return r}return t}function bo(){A.existsSync(Ue)||A.mkdirSync(Ue,{recursive:!0})}function tn(e){let t=ee(e);return t?_.join(Ue,`${t}.json`):null}function vo(e){let t=tn(e);return t?Zt(t,`profile-history/${ee(e)}.json`)||[]:[]}function ko(e,t){let n=tn(e);if(!n)return;bo();let o=vo(e);o.unshift(t);try{Xt(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${ee(e)}: ${r.message}`)}}function Gt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Yt(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Co(e,t){if(!e)return[];let n=[];for(let o of So){let r=e[o],s=t[o];Gt(r)||Gt(s)||Yt(r)!==Yt(s)&&n.push(o)}return n}function xo(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,r]of Object.entries(e))t.has(o)||(n[o]=r);return n}function de(){return ue||(Qt(),ue=Zt(qe,"people.json")||{},ue)}function nn(e){Qt(),ue=e;try{Xt(qe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${_.resolve(qe)}`)}}function Be(e,t={}){if(!e)return null;let n=de(),o=yo(),r=new Date().toISOString(),s=en(n,e,t.name),i=n[s];if(i){let a=Co(i,t);a.length>0&&(ko(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:a,snapshot:xo(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let l of wo)if(t[l]!=null){if(Array.isArray(t[l])&&t[l].length===0&&Array.isArray(i[l])&&i[l].length>0)continue;i[l]=t[l]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return nn(n),n[s]}function Ve(e,t,n={}){if(n.dryRun||!e||!t)return;let o=ee(t);if(!o)return;let r=de(),s=en(r,e),i=r[s];if(!i)return;let a=ee(i.profileUrl||s);o!==a&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),nn(r)))}var co,uo,H,qe,vs,ks,Cs,xs,As,Ue,Kt,Es,_s,ue,fo,mo,po,ho,go,wo,So,$e=Y(async()=>{await Pe();co=ao(import.meta.url),uo=_.dirname(_.dirname(co)),H=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"collected-profiles"):_.join(uo,"collected-profiles"),qe=_.join(H,"people.json"),vs=_.join(H,"jobs.json"),ks=_.join(H,"quota.json"),Cs=_.join(H,"conversations.json"),xs=_.join(H,"sync-state.json"),As=_.join(H,"application-questions.json"),Ue=_.join(H,"profile-history"),Kt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Es=Kt(process.env.CONNECT_MAX_DAILY,20),_s=Kt(process.env.CONNECT_MAX_WEEKLY,100),ue=null,fo=null,mo=null,po=null,ho=null,go=null;wo=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt","featured","education","skillsFull","recommendations","certifications"],So=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var on={};pe(on,{extractCertificationsFromDetails:()=>Io,extractEducationFromDetails:()=>_o,extractExperienceFromDetails:()=>Ao,extractFeaturedFromDetails:()=>Eo,extractRecommendationsFromDetails:()=>Ro,extractSkillsFromDetails:()=>$o});async function Ao(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await ce(e,n,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await x(1e3);let o=e.url();if(!o.toLowerCase().includes("/details/experience/"))throw new Error(`Section /details/experience/ not available on profile (landed on ${o})`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(900);await x(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await x(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(c){let p=[];for(let u of c.querySelectorAll("div")){let f=Array.from(u.children).filter(v=>v.tagName==="DIV");if(f.length<3)continue;let b=f.filter(v=>(v.textContent||"").trim().length>50);b.length<3||(u.textContent||"").length<500||p.push({el:u,count:b.length,totalText:(u.textContent||"").length})}return p.sort((u,f)=>f.count-u.count||u.totalText-f.totalText),p[0]?.el}let a=i(s);if(!a)return[];let l=Array.from(a.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function d(c){let p=c[0]||null,u=null,f=null;if(c[1]){let k=c[1].split("\xB7").map(I=>I.trim());u=k[0]||null,k[1]&&(f=k[1])}let b=c.findIndex(k=>/(\d{4}|present)/i.test(k)&&/(-|–|—)/i.test(k)&&k.length<80),v=null,$=null;if(b>=0){let k=c[b].split("\xB7").map(I=>I.trim());v=k[0]||null,k[1]&&($=k[1])}let y=null,g=-1;if(b>=0&&c[b+1]){let k=c[b+1],I=/^[>*\-•]|^&gt;/.test(k),le=/https?:\/\//.test(k),ae=/\d{4}/.test(k),R=/,/.test(k)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(k);!I&&!le&&!ae&&k.length<100&&R&&(y=k,g=b+1)}let B=null,E=-1,Q=c[c.length-1];if(Q&&/and\s+\+\d+\s+skills?$/i.test(Q)){E=c.length-1;let k=Q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);k&&(B={listed:k[1].split(",").map(I=>I.trim()),additional:parseInt(k[2],10)})}let X=new Set([0,1,b,g,E].filter(k=>k>=0)),W=c.filter((k,I)=>!X.has(I)),O=W.length>0?W.join(`
4
4
 
5
- `):null;return{title:p,company:u,employmentType:f,dates:b,duration:$,location:y,description:O,skills:B,_raw:c}}return l.map(c=>{let u=(c.innerText||"").trim().split(`
5
+ `):null;return{title:p,company:u,employmentType:f,dates:v,duration:$,location:y,description:O,skills:B,_raw:c}}return l.map(c=>{let u=(c.innerText||"").trim().split(`
6
6
  `).map(f=>f.trim()).filter(f=>f&&f.length<5e3);return d(u)}).filter(c=>c.title)})}catch(o){if(o.code==="SESSION_EXPIRED"||/^session expired/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${t}: ${o.message?.slice(0,120)}`),[]}}async function we(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await ce(e,o,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:`details/${n}`}),await x(1e3);let r=e.url();if(!r.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${r})`);for(let i=0;i<4;i++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);await x(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let a of document.querySelectorAll("button"))if(/^Load more$/i.test((a.textContent||"").trim()))return a.click(),!0;return!1});)s++,await x(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(600)}async function be(e,t,n,o){try{return await o()}catch(r){let s=r.message||"";if(r.code==="SESSION_EXPIRED"||/^session expired/i.test(s))throw r;return/not available on profile/i.test(s)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${n} failed for ${e}: ${s.slice(0,120)}`),[])}}async function Eo(e,t){return be(t,"featured","extractFeaturedFromDetails",async()=>(await we(e,t,"featured"),await e.evaluate(`(() => {
7
7
  ${Se}
8
8
 
@@ -237,13 +237,13 @@ function findEntryContainer(root) {
237
237
  candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
238
238
  return candidates[0]?.el;
239
239
  }
240
- `});var ln=Y(()=>{});import"dotenv/config";import*as N from"fs";import*as j from"path";import{fileURLToPath as Do}from"url";function Po(){N.existsSync(ne)||N.mkdirSync(ne,{recursive:!0})}function Fo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";N.writeFileSync(o,n);for(let r=0;r<3;r++)try{N.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function He(e){try{if(N.existsSync(e))return JSON.parse(N.readFileSync(e,"utf-8"))}catch{}return null}function cn(){ve=null,qo=null,ke=null,Uo=null,te=null}function Mo(){return ve||(ve=He(No)||{},ve)}function Ie(){return ke||(ke=He(Lo)||{},ke)}function fe(){return te||(te=He(an)||{visits:[]},Array.isArray(te.visits)||(te.visits=[]),te)}function un(e,t={}){if(!e)return;Po();let n=fe();n.visits.push({date:new Date().toISOString(),profileUrl:e,name:t.name||null,source:t.source||"manual"});let o=Date.now()-90*24*60*60*1e3;n.visits=n.visits.filter(r=>new Date(r.date).getTime()>o);try{Fo(an,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function dn(e){let t=fe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function fn(){let e=Mo(),t=Ie(),n=Object.values(e),o=Object.values(t),r={};for(let u of n)u.company&&(r[u.company]=(r[u.company]||0)+1);let s=Object.entries(r).sort((u,f)=>f[1]-u[1]).slice(0,5).map(([u,f])=>`${u} (${f})`),i={};for(let u of n)for(let f of u.techStack||[])i[f]=(i[f]||0)+1;let a=Object.entries(i).sort((u,f)=>f[1]-u[1]).slice(0,8).map(([u,f])=>`${u} (${f})`),l=fe(),d=new Date().toISOString().slice(0,10),c=l.visits.filter(u=>u.date.startsWith(d)).length,p=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:a,totalVisited:p,todayVisited:c,lastScoutDate:n.length>0?n.sort((u,f)=>(f.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}var Oo,jo,ne,No,Lo,an,Js,Ws,ve,qo,ke,Uo,te,Re=Y(()=>{ln();Oo=Do(import.meta.url),jo=j.dirname(j.dirname(Oo)),ne=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(jo,"market-research"),No=j.join(ne,"scouted-jobs.json"),Lo=j.join(ne,"discovered-people.json"),an=j.join(ne,"visit-log.json"),Js=j.join(ne,"companies.json"),Ws=j.join(ne,"job-decisions.json");ve=null;qo=null,ke=null;Uo=null,te=null});import so from"puppeteer";import{addExtra as io}from"puppeteer-extra";import lo from"puppeteer-extra-plugin-stealth";he();await Pe();Ee();Ee();import Fe from"fs";import Zn from"path";var eo={headless:!1,defaultViewport:null,protocolTimeout:3e5},ye=new Set,Lt=!1;async function _e(){let e=[...ye].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});ye.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function to(){if(Lt)return;Lt=!0;let e=t=>async()=>{await _e(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await _e(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await _e(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await _e(),process.exit(0))}),process.on("exit",()=>{for(let t of ye)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function Me(e){return Zn.join(e,".ilml-browser-session.json")}function qt(e,t={}){try{Fe.writeFileSync(Me(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function no(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();qt(e,n?{wsEndpoint:n}:{})}catch{}}function oo(e){let t=Ut(e);t&&t.ownerPid===process.pid&&ge(e)}function ge(e){try{Fe.rmSync(Me(e),{force:!0})}catch{}}function Ut(e){try{return JSON.parse(Fe.readFileSync(Me(e),"utf-8"))}catch{return null}}function Pt(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Ft(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),s=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([s,r])}async function Mt(e,t,{probeTimeoutMs:n=4e3}={}){let o=Ut(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Pt(o.ownerPid)?"live":(ge(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Ft(s,n,r);if(i===r)return s.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!i)return ge(t),"free";if(Pt(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Ft(i.close().then(()=>!0).catch(()=>!1),n,!1))return ge(t),"free";try{i.disconnect()}catch{}return"live"}function ro(e,t){e&&(to(),ye.add(e),e.on("disconnected",()=>{ye.delete(e),t&&ge(t)}))}async function Bt(e,t={}){let n=xt(),o={...eo,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. 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 Mt(e,n)==="live")throw new Error(r);qt(n);let s;try{s=await e.launch(o)}catch{if(await Mt(e,n)==="live")throw new Error(r);$t(n);try{s=await e.launch(o)}catch(a){throw oo(n),new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${a.message})`)}}return ro(s,n),no(n,s),{browser:s,profileDir:n,needsSeed:Et(n)}}async function Vt(e,t){if(!t||!t.needsSeed)return!1;if(!kt())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(...vt()),_t(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Ht=io(so);Ht.use(lo());async function Jt(){let{browser:e,profileDir:t,needsSeed:n}=await Bt(Ht),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Vt(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}he();await $e();async function To(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function sn(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:a=!1,extractCertifications:l=!1}=n;try{await ce(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await x(1500),await Tt(e)&&(console.log(" Dismissed Premium overlay"),await x(1500),await To(e,t));let c=0;for(let E=0;E<2;E++){let Q=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(O=>window.scrollTo(0,O),Q*W/6),await x(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===c)break;c=X}await x(800);let p=null;try{let E=e.url();E&&/\/in\/[^/?#]/.test(E)&&(p=E.split("?")[0].replace(/\/+$/,""))}catch{}let u=await e.evaluate(()=>{let E=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),Q=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),X=h=>{let w=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(w)},W={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},O=document.querySelector("main");if(!O)return W;let v=[...Array.from(O.querySelectorAll("h1")),...Array.from(O.querySelectorAll("h2"))],I=Array.from(O.querySelectorAll("h2")),le=v.find(h=>{let w=h.textContent&&h.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!E.has(S)&&!Q.has(S)}),ae=le?le.textContent.trim():null,R=le?le.parentElement:null;for(;R&&R!==O&&!Array.from(R.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!X(S)});)R=R.parentElement;let it=null,lt=null,at=null,je=null;if(R&&R!==O){let h=Array.from(R.children).filter(S=>S.tagName==="P").filter(S=>{let G=S.textContent&&S.textContent.trim();return G&&G.length>5&&!X(G)});if(h[0]&&(it=h[0].textContent.trim()),h[1]){let S=h[1].textContent.trim().split(/\s*[·•]\s*/);lt=S[0]||null,S.length>1&&(at=S.slice(1).join(" \xB7 "))}let w=Array.from(R.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let G=w[S].textContent&&w[S].textContent.trim();if(G&&!(ae&&G.startsWith(ae))&&(je=G.split(/[·•]/)[0].trim(),je))break}}let ct=null;if(R){let h=R.querySelectorAll("p, span, div");for(let w of h){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){ct=S;break}}}let Dn=!!O.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ut=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),On=ut&&ut.src||null,xe=O.textContent||"",dt=null,ft=xe.match(/(\d+\+?)\s+connections\b/i);ft&&(dt=ft[1]+" connections");let Ae=null,mt=xe.match(/(\d+)\s+mutual connection/i),pt=xe.match(/and\s+(\d+)\s+other mutual/i),jn=xe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);mt?Ae=parseInt(mt[1],10):pt?Ae=2+parseInt(pt[1],10):jn&&(Ae=2);let ht=null,gt=null,yt=I.find(h=>h.textContent&&h.textContent.trim()==="About");if(yt){let h=yt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ne=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Fn=>Fn.trim()).filter(Boolean);Ne.length>0&&Ne.length<10&&(gt=Ne)}w=w.split(/\n?…\s*more/i)[0].trim(),w=w.split(/\n?\.\.\.\s*more/i)[0].trim(),w=w.split(/\bTop skills\b/i)[0].trim(),w=w.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ht=w||null}}let wt=null,St=I.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(St){let h=St.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(wt=parseInt(w[1].replace(/,/g,""),10))}}let Nn=[...new Set(I.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ae).filter(h=>E.has(h)))],me=document.body.textContent||"",Ln=/#OpenToWork\b/i.test(me)||/\bOpen to work\b/.test(me),Pn=/#Hiring\b/i.test(me)||/\bI'?m hiring\b/i.test(me)||/\bWe are hiring\b/i.test(me);return{name:ae,title:it,location:je,currentCompany:lt,currentSchool:at,connectionDegree:ct,hasVerifiedBadge:Dn,photoUrl:On,connectionsLevel:dt,mutualConnectionsCount:Ae,followers:wt,openToWork:Ln,hiring:Pn,about:ht,topSkills:gt,availableSections:Nn}});console.log(`Viewed: ${u.name} - ${u.title}`);let f=null,C=null,b=null,$=null,y=null,g=null;if(o||r||s||i||a||l){let E=await Promise.resolve().then(()=>(rn(),on));o&&(f=await E.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),r&&(C=await E.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${C.length} entries`)),s&&(b=await E.extractEducationFromDetails(e,t),console.log(` + Education: ${b.length} entries`)),i&&($=await E.extractSkillsFromDetails(e,t),console.log(` + Skills: ${$.length} entries`)),a&&(y=await E.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${y.length} entries`)),l&&(g=await E.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${g.length} entries`))}return{...u,profileUrl:t,resolvedUrl:p,...f!==null&&{experience:f},...C!==null&&{featured:C},...b!==null&&{education:b},...$!==null&&{skillsFull:$},...y!==null&&{recommendations:y},...g!==null&&{certifications:g}}}catch(d){console.error(`Error viewing profile ${t}:`,d.message);try{await e.goto("about:blank",{timeout:1e4}),await x(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(d.message||""))throw d;return null}}Re();await $e();he();async function mn(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:a=!1}=n,l={visited:0,skipped:0,errors:0},d=Date.now()-s*24*60*60*1e3;for(let c of t){if(l.visited>=o)break;if(!c.profileUrl)continue;let p=dn(c.profileUrl);if(p&&new Date(p).getTime()>d){l.skipped++;continue}try{let u=await sn(e,c.profileUrl,{extractExperience:a}),f=c.source||"visit";if(u){let b={...u,source:f};a&&Array.isArray(u.experience)&&u.experience.length>0&&(b._lastEnrichedAt=new Date().toISOString()),Be(c.profileUrl,b),u.resolvedUrl&&Ve(c.profileUrl,u.resolvedUrl)}un(c.profileUrl,{name:u?.name||c.name||null,source:f}),l.visited++,i?console.log(` [${l.visited}] ${u?.name||c.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):l.visited%10===0&&console.log(` Visited: ${l.visited}`);let C=Math.random()*4e3;await x(r+C)}catch(u){l.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${u.message?.slice(0,60)}`);let f=(u.message||"").toLowerCase();if(f.includes("detached")||f.includes("session closed")||f.includes("target closed")||f.includes("session expired")||f.includes("bounced to")||f.includes("authwall")||f.includes("checkpoint")||f.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return l}function pn(e={}){let{limit:t=150,revisitDays:n=14}=e,o=fe(),r=new Set(o.visits?.map(y=>y.profileUrl)||[]),s=new Map;for(let y of o.visits||[]){let g=s.get(y.profileUrl);(!g||y.date>g)&&s.set(y.profileUrl,y.date)}let i=Date.now()-7*24*60*60*1e3,a=Date.now()-n*24*60*60*1e3;function l(y){let g=s.get(y);return g&&new Date(g).getTime()>i}let d=Ie(),c=Object.entries(d).filter(([y])=>!r.has(y)).map(([y,g])=>({profileUrl:y,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),p=de(),u=Object.entries(p).filter(([y,g])=>g.connectionStatus==="connected"||l(y)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([y,g])=>({profileUrl:y,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(p).filter(([y,g])=>{let B=g.connectionStatus;return!(!B||B==="connected"||B==="pending"||B==="sent_without_note"||B==="sent_with_note"||l(y)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([y,g])=>({profileUrl:y,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),C=[...s.entries()].filter(([y,g])=>new Date(g).getTime()<a).map(([y,g])=>({profileUrl:y,name:null,source:"revisit",priority:4,lastVisit:g})),b=y=>y.sort(()=>Math.random()-.5);return c.sort((y,g)=>g.jobCount-y.jobCount),u.sort((y,g)=>g.jobCount-y.jobCount),b(f),b(C),[...c,...u,...f,...C].slice(0,t)}function hn(){let e=Ie();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Je(){let e=de();return Object.entries(e).filter(([,t])=>{let n=t.connectionStatus;return n&&n!=="connected"&&n!=="pending"&&n!=="sent_without_note"&&n!=="sent_with_note"}).map(([t,n])=>({profileUrl:t,name:n.name,source:"unconnected"}))}function We(e=14){let t=fe(),n=Date.now()-e*24*60*60*1e3,o=new Map;for(let r of t.visits){let s=o.get(r.profileUrl);(!s||r.date>s.date)&&o.set(r.profileUrl,r)}return[...o.entries()].filter(([,r])=>new Date(r.date).getTime()<n).map(([r,s])=>({profileUrl:r,name:s.name,source:"revisit"}))}Re();import"dotenv/config";import*as L from"fs";import*as K from"path";import{fileURLToPath as Ko}from"url";import"dotenv/config";import{createGraphClient as Bo,resolveToken as Vo}from"@ilivemylife/graph-sdk";import{config as Ho}from"dotenv";Ho();var gn=Vo()||process.env.TOKEN;gn||(console.error(`
240
+ `});var ln=Y(()=>{});import"dotenv/config";import*as N from"fs";import*as j from"path";import{fileURLToPath as Do}from"url";function Po(){N.existsSync(ne)||N.mkdirSync(ne,{recursive:!0})}function Fo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";N.writeFileSync(o,n);for(let r=0;r<3;r++)try{N.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function He(e){try{if(N.existsSync(e))return JSON.parse(N.readFileSync(e,"utf-8"))}catch{}return null}function cn(){ve=null,qo=null,ke=null,Uo=null,te=null}function Mo(){return ve||(ve=He(No)||{},ve)}function Ie(){return ke||(ke=He(Lo)||{},ke)}function fe(){return te||(te=He(an)||{visits:[]},Array.isArray(te.visits)||(te.visits=[]),te)}function un(e,t={}){if(!e)return;Po();let n=fe();n.visits.push({date:new Date().toISOString(),profileUrl:e,name:t.name||null,source:t.source||"manual"});let o=Date.now()-90*24*60*60*1e3;n.visits=n.visits.filter(r=>new Date(r.date).getTime()>o);try{Fo(an,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function dn(e){let t=fe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function fn(){let e=Mo(),t=Ie(),n=Object.values(e),o=Object.values(t),r={};for(let u of n)u.company&&(r[u.company]=(r[u.company]||0)+1);let s=Object.entries(r).sort((u,f)=>f[1]-u[1]).slice(0,5).map(([u,f])=>`${u} (${f})`),i={};for(let u of n)for(let f of u.techStack||[])i[f]=(i[f]||0)+1;let a=Object.entries(i).sort((u,f)=>f[1]-u[1]).slice(0,8).map(([u,f])=>`${u} (${f})`),l=fe(),d=new Date().toISOString().slice(0,10),c=l.visits.filter(u=>u.date.startsWith(d)).length,p=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:a,totalVisited:p,todayVisited:c,lastScoutDate:n.length>0?n.sort((u,f)=>(f.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}var Oo,jo,ne,No,Lo,an,Js,Ws,ve,qo,ke,Uo,te,Re=Y(()=>{ln();Oo=Do(import.meta.url),jo=j.dirname(j.dirname(Oo)),ne=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(jo,"market-research"),No=j.join(ne,"scouted-jobs.json"),Lo=j.join(ne,"discovered-people.json"),an=j.join(ne,"visit-log.json"),Js=j.join(ne,"companies.json"),Ws=j.join(ne,"job-decisions.json");ve=null;qo=null,ke=null;Uo=null,te=null});import so from"puppeteer";import{addExtra as io}from"puppeteer-extra";import lo from"puppeteer-extra-plugin-stealth";he();await Pe();Ee();Ee();import Fe from"fs";import Zn from"path";var eo={headless:!1,defaultViewport:null,protocolTimeout:3e5},ye=new Set,Lt=!1;async function _e(){let e=[...ye].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});ye.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function to(){if(Lt)return;Lt=!0;let e=t=>async()=>{await _e(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await _e(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await _e(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await _e(),process.exit(0))}),process.on("exit",()=>{for(let t of ye)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function Me(e){return Zn.join(e,".ilml-browser-session.json")}function qt(e,t={}){try{Fe.writeFileSync(Me(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function no(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();qt(e,n?{wsEndpoint:n}:{})}catch{}}function oo(e){let t=Ut(e);t&&t.ownerPid===process.pid&&ge(e)}function ge(e){try{Fe.rmSync(Me(e),{force:!0})}catch{}}function Ut(e){try{return JSON.parse(Fe.readFileSync(Me(e),"utf-8"))}catch{return null}}function Pt(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Ft(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),s=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([s,r])}async function Mt(e,t,{probeTimeoutMs:n=4e3}={}){let o=Ut(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Pt(o.ownerPid)?"live":(ge(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Ft(s,n,r);if(i===r)return s.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!i)return ge(t),"free";if(Pt(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Ft(i.close().then(()=>!0).catch(()=>!1),n,!1))return ge(t),"free";try{i.disconnect()}catch{}return"live"}function ro(e,t){e&&(to(),ye.add(e),e.on("disconnected",()=>{ye.delete(e),t&&ge(t)}))}async function Bt(e,t={}){let n=xt(),o={...eo,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. 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 Mt(e,n)==="live")throw new Error(r);qt(n);let s;try{s=await e.launch(o)}catch{if(await Mt(e,n)==="live")throw new Error(r);$t(n);try{s=await e.launch(o)}catch(a){throw oo(n),new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${a.message})`)}}return ro(s,n),no(n,s),{browser:s,profileDir:n,needsSeed:Et(n)}}async function Vt(e,t){if(!t||!t.needsSeed)return!1;if(!kt())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(...vt()),_t(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Ht=io(so);Ht.use(lo());async function Jt(){let{browser:e,profileDir:t,needsSeed:n}=await Bt(Ht),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Vt(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}he();await $e();async function To(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function sn(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:a=!1,extractCertifications:l=!1}=n;try{await ce(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await x(1500),await Tt(e)&&(console.log(" Dismissed Premium overlay"),await x(1500),await To(e,t));let c=0;for(let E=0;E<2;E++){let Q=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(O=>window.scrollTo(0,O),Q*W/6),await x(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===c)break;c=X}await x(800);let p=null;try{let E=e.url();E&&/\/in\/[^/?#]/.test(E)&&(p=E.split("?")[0].replace(/\/+$/,""))}catch{}let u=await e.evaluate(()=>{let E=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),Q=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),X=h=>{let w=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(w)},W={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},O=document.querySelector("main");if(!O)return W;let k=[...Array.from(O.querySelectorAll("h1")),...Array.from(O.querySelectorAll("h2"))],I=Array.from(O.querySelectorAll("h2")),le=k.find(h=>{let w=h.textContent&&h.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!E.has(S)&&!Q.has(S)}),ae=le?le.textContent.trim():null,R=le?le.parentElement:null;for(;R&&R!==O&&!Array.from(R.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!X(S)});)R=R.parentElement;let it=null,lt=null,at=null,je=null;if(R&&R!==O){let h=Array.from(R.children).filter(S=>S.tagName==="P").filter(S=>{let G=S.textContent&&S.textContent.trim();return G&&G.length>5&&!X(G)});if(h[0]&&(it=h[0].textContent.trim()),h[1]){let S=h[1].textContent.trim().split(/\s*[·•]\s*/);lt=S[0]||null,S.length>1&&(at=S.slice(1).join(" \xB7 "))}let w=Array.from(R.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let G=w[S].textContent&&w[S].textContent.trim();if(G&&!(ae&&G.startsWith(ae))&&(je=G.split(/[·•]/)[0].trim(),je))break}}let ct=null;if(R){let h=R.querySelectorAll("p, span, div");for(let w of h){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){ct=S;break}}}let Dn=!!O.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ut=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),On=ut&&ut.src||null,xe=O.textContent||"",dt=null,ft=xe.match(/(\d+\+?)\s+connections\b/i);ft&&(dt=ft[1]+" connections");let Ae=null,mt=xe.match(/(\d+)\s+mutual connection/i),pt=xe.match(/and\s+(\d+)\s+other mutual/i),jn=xe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);mt?Ae=parseInt(mt[1],10):pt?Ae=2+parseInt(pt[1],10):jn&&(Ae=2);let ht=null,gt=null,yt=I.find(h=>h.textContent&&h.textContent.trim()==="About");if(yt){let h=yt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ne=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Fn=>Fn.trim()).filter(Boolean);Ne.length>0&&Ne.length<10&&(gt=Ne)}w=w.split(/\n?…\s*more/i)[0].trim(),w=w.split(/\n?\.\.\.\s*more/i)[0].trim(),w=w.split(/\bTop skills\b/i)[0].trim(),w=w.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ht=w||null}}let wt=null,St=I.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(St){let h=St.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(wt=parseInt(w[1].replace(/,/g,""),10))}}let Nn=[...new Set(I.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ae).filter(h=>E.has(h)))],me=document.body.textContent||"",Ln=/#OpenToWork\b/i.test(me)||/\bOpen to work\b/.test(me),Pn=/#Hiring\b/i.test(me)||/\bI'?m hiring\b/i.test(me)||/\bWe are hiring\b/i.test(me);return{name:ae,title:it,location:je,currentCompany:lt,currentSchool:at,connectionDegree:ct,hasVerifiedBadge:Dn,photoUrl:On,connectionsLevel:dt,mutualConnectionsCount:Ae,followers:wt,openToWork:Ln,hiring:Pn,about:ht,topSkills:gt,availableSections:Nn}});console.log(`Viewed: ${u.name} - ${u.title}`);let f=null,b=null,v=null,$=null,y=null,g=null;if(o||r||s||i||a||l){let E=await Promise.resolve().then(()=>(rn(),on));o&&(f=await E.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),r&&(b=await E.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${b.length} entries`)),s&&(v=await E.extractEducationFromDetails(e,t),console.log(` + Education: ${v.length} entries`)),i&&($=await E.extractSkillsFromDetails(e,t),console.log(` + Skills: ${$.length} entries`)),a&&(y=await E.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${y.length} entries`)),l&&(g=await E.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${g.length} entries`))}return{...u,profileUrl:t,resolvedUrl:p,...f!==null&&{experience:f},...b!==null&&{featured:b},...v!==null&&{education:v},...$!==null&&{skillsFull:$},...y!==null&&{recommendations:y},...g!==null&&{certifications:g}}}catch(d){console.error(`Error viewing profile ${t}:`,d.message);try{await e.goto("about:blank",{timeout:1e4}),await x(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(d.message||""))throw d;return null}}Re();await $e();he();async function mn(e,t,n={}){let{maxVisits:o=10,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:a=!1}=n,l={visited:0,skipped:0,errors:0},d=Date.now()-s*24*60*60*1e3;for(let c of t){if(l.visited>=o)break;if(!c.profileUrl)continue;let p=dn(c.profileUrl);if(p&&new Date(p).getTime()>d){l.skipped++;continue}try{let u=await sn(e,c.profileUrl,{extractExperience:a}),f=c.source||"visit";if(u){let v={...u,source:f};a&&Array.isArray(u.experience)&&u.experience.length>0&&(v._lastEnrichedAt=new Date().toISOString()),Be(c.profileUrl,v),u.resolvedUrl&&Ve(c.profileUrl,u.resolvedUrl)}un(c.profileUrl,{name:u?.name||c.name||null,source:f}),l.visited++,i?console.log(` [${l.visited}] ${u?.name||c.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):l.visited%10===0&&console.log(` Visited: ${l.visited}`);let b=Math.random()*4e3;await x(r+b)}catch(u){l.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${u.message?.slice(0,60)}`);let f=(u.message||"").toLowerCase();if(f.includes("detached")||f.includes("session closed")||f.includes("target closed")||f.includes("session expired")||f.includes("bounced to")||f.includes("authwall")||f.includes("checkpoint")||f.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return l}function pn(e={}){let{limit:t=150,revisitDays:n=14}=e,o=fe(),r=new Set(o.visits?.map(y=>y.profileUrl)||[]),s=new Map;for(let y of o.visits||[]){let g=s.get(y.profileUrl);(!g||y.date>g)&&s.set(y.profileUrl,y.date)}let i=Date.now()-7*24*60*60*1e3,a=Date.now()-n*24*60*60*1e3;function l(y){let g=s.get(y);return g&&new Date(g).getTime()>i}let d=Ie(),c=Object.entries(d).filter(([y])=>!r.has(y)).map(([y,g])=>({profileUrl:y,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),p=de(),u=Object.entries(p).filter(([y,g])=>g.connectionStatus==="connected"||l(y)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([y,g])=>({profileUrl:y,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(p).filter(([y,g])=>{let B=g.connectionStatus;return!(!B||B==="connected"||B==="pending"||B==="sent_without_note"||B==="sent_with_note"||l(y)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([y,g])=>({profileUrl:y,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),b=[...s.entries()].filter(([y,g])=>new Date(g).getTime()<a).map(([y,g])=>({profileUrl:y,name:null,source:"revisit",priority:4,lastVisit:g})),v=y=>y.sort(()=>Math.random()-.5);return c.sort((y,g)=>g.jobCount-y.jobCount),u.sort((y,g)=>g.jobCount-y.jobCount),v(f),v(b),[...c,...u,...f,...b].slice(0,t)}function hn(){let e=Ie();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Je(){let e=de();return Object.entries(e).filter(([,t])=>{let n=t.connectionStatus;return n&&n!=="connected"&&n!=="pending"&&n!=="sent_without_note"&&n!=="sent_with_note"}).map(([t,n])=>({profileUrl:t,name:n.name,source:"unconnected"}))}function We(e=14){let t=fe(),n=Date.now()-e*24*60*60*1e3,o=new Map;for(let r of t.visits){let s=o.get(r.profileUrl);(!s||r.date>s.date)&&o.set(r.profileUrl,r)}return[...o.entries()].filter(([,r])=>new Date(r.date).getTime()<n).map(([r,s])=>({profileUrl:r,name:s.name,source:"revisit"}))}Re();import"dotenv/config";import*as L from"fs";import*as K from"path";import{fileURLToPath as Ko}from"url";import"dotenv/config";import{createGraphClient as Bo,resolveToken as Vo}from"@ilivemylife/graph-sdk";import{config as Ho}from"dotenv";Ho();var gn=Vo()||process.env.TOKEN;gn||(console.error(`
241
241
  [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.
242
242
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
243
243
  `),console.error(` Or add ILML_TOKEN=... to .env
244
- `),process.exit(1));var yn=Bo({token:gn});function Jo(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),o=t%60;return o?`${n}m ${o}s`:`${n}m`}var Wo={apply:"Job apply","apply-queue":"Job apply (queue)",scout:"Job scout",connect:"Connect run",funnel:"Recruiter funnel",messages:"Messages",sync:"Connections sync","sync-all":"Inbox sync",visit:"Profile visits",viewers:"Profile viewers",daily:"Daily run"};function Go(e){let t=String(e||"").toLowerCase();return/authwall|session expired|not logged in|re-?auth|logged out|sign ?in/.test(t)?"LinkedIn asked to sign in again. Run `ilml linkedin login`, then run this again.":/protocoltimeout|callfunctionon|target closed|session closed|detached|execution context|browser.*disconnected|connection closed/.test(t)?"The browser stopped responding partway through. This is usually temporary \u2014 just run it again.":/err_aborted|err_network|err_connection|err_name_not_resolved|net::/.test(t)?"A page failed to load (network hiccup). Try running it again in a moment.":/navigation timeout|timeout.*exceeded|waiting for selector|waiting for/.test(t)?"A page took too long to load. Try again in a moment.":/invite limit|weekly.*limit|too many|rate.?limit|quota/.test(t)?"You've reached a LinkedIn sending limit for now. Wait a while, then try again.":"Something went wrong partway through. It is safe to run the command again."}function Yo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",a=n==="error"?"stopped early":n==="quota-reached"?"daily limit reached":"done",l=Wo[e]||e,d=t&&t!=="default"?` \xB7 ${t}`:"",c=new Date().toISOString().slice(0,16).replace("T"," "),p=s?` \xB7 ${Jo(s)}`:"",u=[];u.push(`## ${i} ${l} \u2014 ${a}`),u.push(`_${c}${d}${p}_`),u.push("");for(let f of o)u.push(`- ${f}`);if(n==="error"){u.push(""),u.push(`**What happened:** ${Go(r)}`);let f=String(r||"").replace(/\s+/g," ").trim();f&&u.push(`_Technical detail: ${f.slice(0,140)}_`)}return u.join(`
245
- `)}async function Ge({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let a=Yo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s});try{await yn.addMessage(i,a)}catch(l){console.error(`[runReport] Failed to post end-of-session message: ${l.message}`)}}var zo=Ko(import.meta.url),Qo=K.dirname(K.dirname(zo)),Ye=process.env.DATA_DIR?K.resolve(process.env.DATA_DIR,"collected-profiles"):K.join(Qo,"collected-profiles"),Ke=K.join(Ye,"run-log.json");function Xo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";L.writeFileSync(o,n);for(let r=0;r<3;r++)try{L.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function wn(){try{if(!L.existsSync(Ke))return{runs:[]};let e=JSON.parse(L.readFileSync(Ke,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Sn(e){L.existsSync(Ye)||L.mkdirSync(Ye,{recursive:!0});try{Xo(Ke,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Zo(e,t="default"){let n=wn();for(let i of n.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};n.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return n.runs=n.runs.filter(i=>new Date(i.timestamp).getTime()>s),Sn(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function er(e,t,n=null,o=null){if(!e)return;let r=null;try{let a=wn(),l=a.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let d=a.runs.find(c=>c.script===e.script&&c.status==="running"&&c.timestamp===new Date(e.startTime).toISOString());d&&(d.status=t,d.result=t,d.duration=Date.now()-e.startTime,d.stats=n,d.error=o,r=d.duration)}Sn(a)}catch(a){console.error(`[runLog] Failed to end run: ${a.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null,i=n&&n.__deferReport===!0;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS&&!i){let a=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";Ge({scriptName:e.script,mode:e.mode,status:a,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}async function bn(e,t,n,o,r={}){let{rethrow:s=!0}=r,i=Zo(e,t),a={},l=null;try{await n(a)}catch(p){l=p}let d=[];try{let p=o?o(a):[];d=(Array.isArray(p)?p:[]).filter(u=>typeof u=="string"&&u.trim())}catch(p){console.error(`[runLog] summarize threw (report still sent): ${p.message}`)}if(d.length===0&&l&&(d=["(crashed before any progress was recorded)"]),l){let p=t&&t!=="default"?` (${t})`:"";console.error(`
246
- \u2717 ${e}${p} failed: ${l.message||l}`)}let c=Date.now()-i.startTime;try{er(i,l?"error":"success",{...a,summaryLines:d,__deferReport:!0},l?l.message||String(l):null)}catch(p){console.error(`[runLog] endRun failed: ${p.message}`)}if(d.length>0&&process.env.NODE_RUN_REPORTS){let p=l?"error":a.dailyLimitHit?"quota-reached":"done";try{await Ge({scriptName:i.script,mode:i.mode,status:p,summaryLines:d,error:l?l.message||String(l):null,duration:c})}catch(u){console.error(`[runLog] report post failed: ${u.message}`)}}if(l&&s)throw l;return a}import"dotenv/config";import*as m from"fs";import*as ot from"os";import*as k from"path";import{fileURLToPath as xr}from"url";var Xe={};pe(Xe,{NAME:()=>nr,VERSION:()=>tr,up:()=>sr});import*as P from"fs";import*as Te from"path";var tr=1,nr="normalize-jobs-and-questions",or=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],rr=50;function ze(e){return P.existsSync(e)?JSON.parse(P.readFileSync(e,"utf-8")):null}function Qe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{P.writeFileSync(o,n)}catch(r){try{P.unlinkSync(o)}catch{}throw r}try{P.renameSync(o,e)}catch(r){try{P.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function sr(e,t){let n=Te.join(e,"jobs.json"),o=Te.join(t,"scouted-jobs.json"),r=Te.join(e,"application-questions.json"),s=ze(n)||{},i=ze(o)||{},a=0,l=[];for(let c of Object.keys(s)){if(!i[c])continue;let p=i[c],u=s[c];for(let f of or)p[f]!=null&&u[f]==null&&(u[f]=p[f]);l.push(c),a++}a>0?(Qe(n,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let d=ze(r);if(d&&Array.isArray(d.applications)){let c={},p=0;for(let u of d.applications){let f=u.jobId||"unknown";c[f]||(c[f]={applications:[]});let C=(u.questions||[]).map(b=>{let $={type:b.type||"input",question:b.question||"",answer:b.answer||""};return b.options&&(b.options.length<=rr?$.options=b.options:($.optionsOmitted=!0,p++)),b.page&&($.page=b.page),b.wasPreFilled&&($.wasPreFilled=!0),b.wasRetry&&($.wasRetry=!0),$});c[f].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||C.length,questions:C})}Qe(r,c),console.log(` Phase 2: Rekeyed ${d.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),p>0&&console.log(` Phase 2: Stripped bloated options from ${p} questions`)}else d&&!d.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 c of l)delete i[c];Qe(o,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Ze={};pe(Ze,{NAME:()=>lr,VERSION:()=>ir,up:()=>ur});import*as F from"fs";import*as vn from"path";var ir=2,lr="reset-unread-flags";function ar(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function cr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function ur(e){let t=vn.join(e,"conversations.json"),n=ar(t);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(n))n[r].unread===!0&&(n[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}cr(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var et={};pe(et,{NAME:()=>fr,VERSION:()=>dr,up:()=>yr});import*as M from"fs";import*as kn from"path";var dr=3,fr="recompute-last-message-by",mr=new Set(["draft","confirmed","rejected","needs_review"]);function pr(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function hr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function gr(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!mr.has(s.status));if(n.length===0)return"them";let o=n.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...n].reverse();for(let s of r){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function yr(e){let t=kn.join(e,"conversations.json"),n=pr(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.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,s=0,i=0;for(let a of Object.keys(n)){let l=n[a];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let d=Array.isArray(l.messages)?l.messages:[],c=gr(d,o),p=c==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==c&&i++,l.lastMessageBy=c,l.conversationStatus=p,r++}if(r===0){console.log(" No conversations to recompute.");return}hr(t,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var tt={};pe(tt,{NAME:()=>Sr,VERSION:()=>wr,up:()=>Cr});import*as q from"fs";import*as Cn from"path";var wr=4,Sr="split-connection-timestamps",br=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function vr(e){if(!q.existsSync(e))return null;let t=q.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function kr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{q.writeFileSync(o,n)}catch(r){try{q.unlinkSync(o)}catch{}throw r}try{q.renameSync(o,e)}catch(r){try{q.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function Cr(e){let t=Cn.join(e,"people.json"),n=vr(t);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,br.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,o++))}if(o===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}kr(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}await $e();Re();var Ar=xr(import.meta.url),Er=k.dirname(Ar),_r=k.dirname(k.dirname(Er));function $r(e){return e&&(e==="~"?ot.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(ot.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?k.resolve($r(process.env.DATA_DIR)):_r,re=k.join(U,"collected-profiles"),se=k.join(U,"market-research"),D=k.join(U,".schema-version"),xn=[k.join(re,".schema-version"),k.join(se,".schema-version")],z=4,J=[{version:1,module:Xe},{version:2,module:Ze},{version:3,module:et},{version:4,module:tt}];(function(){J.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of J){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(t.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);t.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=J.length?J[J.length-1].version:0;if(n!==z)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${z}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<J.length;o++){let r=o+1;if(J[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${J[o].version}`)}})();function $n(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
244
+ `),process.exit(1));var yn=Bo({token:gn});function Jo(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),o=t%60;return o?`${n}m ${o}s`:`${n}m`}var Wo={apply:"Job apply","apply-queue":"Job apply (queue)",scout:"Job scout",connect:"Connect run",funnel:"Recruiter funnel",messages:"Messages",sync:"Connections sync","sync-all":"Inbox sync",visit:"Profile visits",viewers:"Profile viewers",daily:"Daily run"};function Go(e){let t=String(e||"").toLowerCase();return/authwall|session expired|not logged in|re-?auth|logged out|sign ?in/.test(t)?"LinkedIn asked to sign in again. Run `ilml linkedin login`, then run this again.":/protocoltimeout|callfunctionon|target closed|session closed|detached|execution context|browser.*disconnected|connection closed/.test(t)?"The browser stopped responding partway through. This is usually temporary \u2014 just run it again.":/err_aborted|err_network|err_connection|err_name_not_resolved|net::/.test(t)?"A page failed to load (network hiccup). Try running it again in a moment.":/navigation timeout|timeout.*exceeded|waiting for selector|waiting for/.test(t)?"A page took too long to load. Try again in a moment.":/invite limit|weekly.*limit|too many|rate.?limit|quota/.test(t)?"You've reached a LinkedIn sending limit for now. Wait a while, then try again.":"Something went wrong partway through. It is safe to run the command again."}function Yo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i}){let a=n==="error"||n==="stopped"?n==="error"?"\u2717":"\u26A0":n==="quota-reached"?"\u26A0":"\u2713",l=n==="error"?"stopped early":n==="stopped"?`stopped \u2014 ${s||"did not finish"}`:n==="quota-reached"?"daily limit reached":"done",d=Wo[e]||e,c=t&&t!=="default"?` \xB7 ${t}`:"",p=new Date().toISOString().slice(0,16).replace("T"," "),u=i?` \xB7 ${Jo(i)}`:"",f=[];f.push(`## ${a} ${d} \u2014 ${l}`),f.push(`_${p}${c}${u}_`),f.push("");for(let b of o)f.push(`- ${b}`);if(n==="error"){f.push(""),f.push(`**What happened:** ${Go(r)}`);let b=String(r||"").replace(/\s+/g," ").trim();b&&f.push(`_Technical detail: ${b.slice(0,140)}_`)}return f.join(`
245
+ `)}async function Ge({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i}){let a=process.env.NODE_RUN_REPORTS;if(!a||!Array.isArray(o)||o.length===0)return;let l=Yo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i});try{await yn.addMessage(a,l)}catch(d){console.error(`[runReport] Failed to post end-of-session message: ${d.message}`)}}var zo=Ko(import.meta.url),Qo=K.dirname(K.dirname(zo)),Ye=process.env.DATA_DIR?K.resolve(process.env.DATA_DIR,"collected-profiles"):K.join(Qo,"collected-profiles"),Ke=K.join(Ye,"run-log.json");function Xo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";L.writeFileSync(o,n);for(let r=0;r<3;r++)try{L.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function wn(){try{if(!L.existsSync(Ke))return{runs:[]};let e=JSON.parse(L.readFileSync(Ke,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Sn(e){L.existsSync(Ye)||L.mkdirSync(Ye,{recursive:!0});try{Xo(Ke,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Zo(e,t="default"){let n=wn();for(let i of n.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};n.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return n.runs=n.runs.filter(i=>new Date(i.timestamp).getTime()>s),Sn(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function er(e,t,n=null,o=null){if(!e)return;let r=null;try{let a=wn(),l=a.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let d=a.runs.find(c=>c.script===e.script&&c.status==="running"&&c.timestamp===new Date(e.startTime).toISOString());d&&(d.status=t,d.result=t,d.duration=Date.now()-e.startTime,d.stats=n,d.error=o,r=d.duration)}Sn(a)}catch(a){console.error(`[runLog] Failed to end run: ${a.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null,i=n&&n.__deferReport===!0;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS&&!i){let a=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";Ge({scriptName:e.script,mode:e.mode,status:a,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}async function bn(e,t,n,o,r={}){let{rethrow:s=!0}=r,i=Zo(e,t),a={},l=null;try{await n(a)}catch(u){l=u}let d=[];try{let u=o?o(a):[];d=(Array.isArray(u)?u:[]).filter(f=>typeof f=="string"&&f.trim())}catch(u){console.error(`[runLog] summarize threw (report still sent): ${u.message}`)}if(d.length===0&&l&&(d=["(crashed before any progress was recorded)"]),l){let u=t&&t!=="default"?` (${t})`:"";console.error(`
246
+ \u2717 ${e}${u} failed: ${l.message||l}`)}let c=Date.now()-i.startTime,p=!l&&a.stoppedReason?String(a.stoppedReason):null;try{er(i,l?"error":p?"partial":"success",{...a,summaryLines:d,__deferReport:!0},l?l.message||String(l):null)}catch(u){console.error(`[runLog] endRun failed: ${u.message}`)}if(d.length>0&&process.env.NODE_RUN_REPORTS){let u=l?"error":p?"stopped":a.dailyLimitHit?"quota-reached":"done";try{await Ge({scriptName:i.script,mode:i.mode,status:u,summaryLines:d,error:l?l.message||String(l):null,stoppedReason:p,duration:c})}catch(f){console.error(`[runLog] report post failed: ${f.message}`)}}if(l&&s)throw l;return a}import"dotenv/config";import*as m from"fs";import*as ot from"os";import*as C from"path";import{fileURLToPath as xr}from"url";var Xe={};pe(Xe,{NAME:()=>nr,VERSION:()=>tr,up:()=>sr});import*as P from"fs";import*as Te from"path";var tr=1,nr="normalize-jobs-and-questions",or=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],rr=50;function ze(e){return P.existsSync(e)?JSON.parse(P.readFileSync(e,"utf-8")):null}function Qe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{P.writeFileSync(o,n)}catch(r){try{P.unlinkSync(o)}catch{}throw r}try{P.renameSync(o,e)}catch(r){try{P.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function sr(e,t){let n=Te.join(e,"jobs.json"),o=Te.join(t,"scouted-jobs.json"),r=Te.join(e,"application-questions.json"),s=ze(n)||{},i=ze(o)||{},a=0,l=[];for(let c of Object.keys(s)){if(!i[c])continue;let p=i[c],u=s[c];for(let f of or)p[f]!=null&&u[f]==null&&(u[f]=p[f]);l.push(c),a++}a>0?(Qe(n,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let d=ze(r);if(d&&Array.isArray(d.applications)){let c={},p=0;for(let u of d.applications){let f=u.jobId||"unknown";c[f]||(c[f]={applications:[]});let b=(u.questions||[]).map(v=>{let $={type:v.type||"input",question:v.question||"",answer:v.answer||""};return v.options&&(v.options.length<=rr?$.options=v.options:($.optionsOmitted=!0,p++)),v.page&&($.page=v.page),v.wasPreFilled&&($.wasPreFilled=!0),v.wasRetry&&($.wasRetry=!0),$});c[f].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||b.length,questions:b})}Qe(r,c),console.log(` Phase 2: Rekeyed ${d.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),p>0&&console.log(` Phase 2: Stripped bloated options from ${p} questions`)}else d&&!d.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 c of l)delete i[c];Qe(o,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Ze={};pe(Ze,{NAME:()=>lr,VERSION:()=>ir,up:()=>ur});import*as F from"fs";import*as vn from"path";var ir=2,lr="reset-unread-flags";function ar(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function cr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function ur(e){let t=vn.join(e,"conversations.json"),n=ar(t);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(n))n[r].unread===!0&&(n[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}cr(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var et={};pe(et,{NAME:()=>fr,VERSION:()=>dr,up:()=>yr});import*as M from"fs";import*as kn from"path";var dr=3,fr="recompute-last-message-by",mr=new Set(["draft","confirmed","rejected","needs_review"]);function pr(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function hr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function gr(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!mr.has(s.status));if(n.length===0)return"them";let o=n.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...n].reverse();for(let s of r){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function yr(e){let t=kn.join(e,"conversations.json"),n=pr(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.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,s=0,i=0;for(let a of Object.keys(n)){let l=n[a];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let d=Array.isArray(l.messages)?l.messages:[],c=gr(d,o),p=c==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==c&&i++,l.lastMessageBy=c,l.conversationStatus=p,r++}if(r===0){console.log(" No conversations to recompute.");return}hr(t,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var tt={};pe(tt,{NAME:()=>Sr,VERSION:()=>wr,up:()=>Cr});import*as q from"fs";import*as Cn from"path";var wr=4,Sr="split-connection-timestamps",br=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function vr(e){if(!q.existsSync(e))return null;let t=q.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function kr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{q.writeFileSync(o,n)}catch(r){try{q.unlinkSync(o)}catch{}throw r}try{q.renameSync(o,e)}catch(r){try{q.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function Cr(e){let t=Cn.join(e,"people.json"),n=vr(t);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,br.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,o++))}if(o===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}kr(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}await $e();Re();var Ar=xr(import.meta.url),Er=C.dirname(Ar),_r=C.dirname(C.dirname(Er));function $r(e){return e&&(e==="~"?ot.homedir():e.startsWith("~/")||e.startsWith("~\\")?C.join(ot.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?C.resolve($r(process.env.DATA_DIR)):_r,re=C.join(U,"collected-profiles"),se=C.join(U,"market-research"),D=C.join(U,".schema-version"),xn=[C.join(re,".schema-version"),C.join(se,".schema-version")],z=4,J=[{version:1,module:Xe},{version:2,module:Ze},{version:3,module:et},{version:4,module:tt}];(function(){J.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of J){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(t.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);t.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=J.length?J[J.length-1].version:0;if(n!==z)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${z}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<J.length;o++){let r=o+1;if(J[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${J[o].version}`)}})();function $n(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
247
247
  [FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
248
248
  `),process.exit(1));try{m.mkdirSync(U,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
249
249
  [FATAL] Cannot create DATA_DIR (${U}): ${t.message}`),console.error(` Fix the path or permissions and try again.
@@ -253,7 +253,7 @@ function findEntryContainer(root) {
253
253
  [FATAL] DATA_DIR (${U}) 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.
254
254
  `),process.exit(1));for(let t of[re,se]){let n;try{n=m.lstatSync(t)}catch(o){if(o.code==="ENOENT")continue;throw o}n.isSymbolicLink()&&(console.error(`
255
255
  [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.
256
- `),process.exit(1))}}var oe=k.join(U,".migration-lock");function Ir(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return m.writeFileSync(oe,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(m.readFileSync(oe,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let o=!1;try{process.kill(t.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(t.startedAt){let i=Date.parse(t.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
256
+ `),process.exit(1))}}var oe=C.join(U,".migration-lock");function Ir(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return m.writeFileSync(oe,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(m.readFileSync(oe,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let o=!1;try{process.kill(t.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(t.startedAt){let i=Date.parse(t.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
257
257
  [FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${oe}
258
258
  `),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.
259
259
  `),process.exit(1)),o&&s>=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 n=oe+".tmp";try{return m.writeFileSync(n,e),m.renameSync(n,oe),!0}catch(o){try{m.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function rt(){try{if(JSON.parse(m.readFileSync(oe,"utf-8")).pid!==process.pid)return;m.unlinkSync(oe)}catch{}}var An=!1;function Rr(){if(An)return;An=!0;let e=()=>{try{rt()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Tr(){if(m.existsSync(D))return;let e=[],t=[];for(let s of xn)if(m.existsSync(s))try{e.push({file:s,schema:De(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
@@ -265,7 +265,7 @@ function findEntryContainer(root) {
265
265
  [FATAL] ${D} is not valid JSON: ${n.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.
266
266
  `),process.exit(1)}let t=Dr(e);return t===null&&(console.error(`
267
267
  [FATAL] ${D} 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.
268
- `),process.exit(1)),t}function In(e){try{m.chmodSync(e,384)}catch{}}function Or(e){if($n(),m.existsSync(D))try{if(m.lstatSync(D).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${D}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(n){if(n.message?.includes("symbolic link"))throw n}let t=D+".tmp";try{m.writeFileSync(t,JSON.stringify(e,null,2)),In(t),m.renameSync(t,D)}catch(n){try{m.unlinkSync(t)}catch{}throw n}}function _n(e,t){if(!m.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=m.readdirSync(e).filter(a=>{let l=a.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return m.statSync(k.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let a of o){let l=k.join(e,a),d=k.join(e,a+n);if(m.existsSync(d)){s++;continue}try{Tn(l,d),r++}catch(c){i.push({file:a,err:c.message})}}if(i.length>0){let a=new Error(`Failed to back up ${i.length} file(s) in ${k.basename(e)}/: `+i.map(l=>`${l.file} (${l.err})`).join(", "));throw a.code="BACKUP_INCOMPLETE",a}if(r>0||s>0){let a=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${k.basename(e)}/ (${n})${a}`)}}var nt=!1;async function Rn(){if(nt)return;$n(),Fr();let t=En().version;if(t===z){nt=!0;return}Rr(),Ir(),process.on("exit",rt),t>z&&(console.error(`
268
+ `),process.exit(1)),t}function In(e){try{m.chmodSync(e,384)}catch{}}function Or(e){if($n(),m.existsSync(D))try{if(m.lstatSync(D).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${D}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(n){if(n.message?.includes("symbolic link"))throw n}let t=D+".tmp";try{m.writeFileSync(t,JSON.stringify(e,null,2)),In(t),m.renameSync(t,D)}catch(n){try{m.unlinkSync(t)}catch{}throw n}}function _n(e,t){if(!m.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=m.readdirSync(e).filter(a=>{let l=a.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return m.statSync(C.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let a of o){let l=C.join(e,a),d=C.join(e,a+n);if(m.existsSync(d)){s++;continue}try{Tn(l,d),r++}catch(c){i.push({file:a,err:c.message})}}if(i.length>0){let a=new Error(`Failed to back up ${i.length} file(s) in ${C.basename(e)}/: `+i.map(l=>`${l.file} (${l.err})`).join(", "));throw a.code="BACKUP_INCOMPLETE",a}if(r>0||s>0){let a=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${C.basename(e)}/ (${n})${a}`)}}var nt=!1;async function Rn(){if(nt)return;$n(),Fr();let t=En().version;if(t===z){nt=!0;return}Rr(),Ir(),process.on("exit",rt),t>z&&(console.error(`
269
269
  [FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${z}.`),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.
270
270
  `),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${z}.
271
271
  `),process.exit(1)),console.log(`
@@ -283,7 +283,7 @@ function findEntryContainer(root) {
283
283
  [FATAL] Migration ${s} 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 ${s}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
284
284
  `),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{zt()}catch{}try{cn()}catch{}nt=!0,rt(),console.log(`
285
285
  \u2713 Schema is now at v${z}
286
- `)}var jr=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Nr(e){let t=e.toLowerCase();return jr.some(n=>n.test(t))}var Lr=6e4;function Pr(){let e=Date.now(),t=[];for(let n of[U,re,se]){if(!m.existsSync(n))continue;let o;try{o=m.readdirSync(n)}catch{continue}for(let r of o){if(!Nr(r))continue;let s=k.join(n,r);try{let i=m.statSync(s);if(!i.isFile()||e-i.mtimeMs<Lr)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function Fr({verbose:e=!1}={}){let t=Pr();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{m.unlinkSync(o.fullPath),n++,e&&console.log(` Removed orphan: ${k.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Mr(){let e=[];for(let t of[re,se]){if(!m.existsSync(t))continue;let n=m.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=k.join(t,o);try{De(r)}catch(s){e.push({dir:k.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function qr(e){let t=[],n=[];for(let s of[re,se]){if(!m.existsSync(s))continue;let i=m.readdirSync(s).filter(a=>a.endsWith(e));for(let a of i){let l=k.join(s,a),d=a.slice(0,-e.length),c=k.join(s,d);try{d.toLowerCase().endsWith(".json")?De(l):m.accessSync(l,m.constants.R_OK),t.push({backupPath:l,originalPath:c,fileName:a,dir:s})}catch(p){n.push(`${k.basename(s)}/${a}: ${p.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:a,dir:l}of t)try{Tn(s,i),o++}catch(d){r.push(`${k.basename(l)}/${a}: ${d.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Tn(e,t){let n=t+".tmp";try{m.copyFileSync(e,n),In(n)}catch(o){try{m.unlinkSync(n)}catch{}throw o}try{m.renameSync(n,t)}catch(o){try{m.unlinkSync(n)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${t} (${o.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=o.code,r}throw o}}await Rn();var Ce=process.argv.slice(2),Oe=Ce.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",st=parseInt(Ce.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),ie=parseInt(Ce.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),Ur=Ce.includes("--list"),Br=Ce.includes("--verbose");function Vr(){let e=fn();console.log(`
286
+ `)}var jr=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Nr(e){let t=e.toLowerCase();return jr.some(n=>n.test(t))}var Lr=6e4;function Pr(){let e=Date.now(),t=[];for(let n of[U,re,se]){if(!m.existsSync(n))continue;let o;try{o=m.readdirSync(n)}catch{continue}for(let r of o){if(!Nr(r))continue;let s=C.join(n,r);try{let i=m.statSync(s);if(!i.isFile()||e-i.mtimeMs<Lr)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function Fr({verbose:e=!1}={}){let t=Pr();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{m.unlinkSync(o.fullPath),n++,e&&console.log(` Removed orphan: ${C.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Mr(){let e=[];for(let t of[re,se]){if(!m.existsSync(t))continue;let n=m.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=C.join(t,o);try{De(r)}catch(s){e.push({dir:C.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function qr(e){let t=[],n=[];for(let s of[re,se]){if(!m.existsSync(s))continue;let i=m.readdirSync(s).filter(a=>a.endsWith(e));for(let a of i){let l=C.join(s,a),d=a.slice(0,-e.length),c=C.join(s,d);try{d.toLowerCase().endsWith(".json")?De(l):m.accessSync(l,m.constants.R_OK),t.push({backupPath:l,originalPath:c,fileName:a,dir:s})}catch(p){n.push(`${C.basename(s)}/${a}: ${p.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:a,dir:l}of t)try{Tn(s,i),o++}catch(d){r.push(`${C.basename(l)}/${a}: ${d.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Tn(e,t){let n=t+".tmp";try{m.copyFileSync(e,n),In(n)}catch(o){try{m.unlinkSync(n)}catch{}throw o}try{m.renameSync(n,t)}catch(o){try{m.unlinkSync(n)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${t} (${o.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=o.code,r}throw o}}await Rn();var Ce=process.argv.slice(2),Oe=Ce.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",st=parseInt(Ce.find(e=>e.startsWith("--max="))?.split("=")[1]||"10"),ie=parseInt(Ce.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),Ur=Ce.includes("--list"),Br=Ce.includes("--verbose");function Vr(){let e=fn();console.log(`
287
287
  \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(" PROFILE VISIT 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(` Unique profiles visited: ${e.totalVisited}`),console.log(` Today: ${e.todayVisited}`),console.log(` Discovered recruiters: ${e.totalRecruiters} (potential visits)`);let t=Je();if(console.log(` Unconnected recruiters: ${t.length}`),ie>0){let n=We(ie);console.log(` Revisit (>${ie}d ago): ${n.length}`)}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
288
288
  `)}async function Hr(){if(console.log(`
289
289
  LinkedIn Profile Visitor
package/ilml-plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkedin",
3
- "version": "1.20.20",
3
+ "version": "1.20.22",
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." },
@@ -140,10 +140,10 @@
140
140
  "usage": "ilml linkedin visit [--source=<source>] [--max=N] [--list]",
141
141
  "flags": {
142
142
  "--source=<source>": "Which queue to drain. 'people' (default), 'recruiters', 'discovered'.",
143
- "--max=N": "Cap visits this run (default 50).",
143
+ "--max=N": "Cap visits this run (default 10).",
144
144
  "--list": "Stats only, no browser. Safe."
145
145
  },
146
- "banRisk": "Medium. Profile views are public-by-default LinkedIn signal — visits to dozens of recruiters can be flagged if cadence is unnatural. Cap = 50/session.",
146
+ "banRisk": "HIGH. This command's whole purpose is a profile view with no follow-up action — no message, no connect, no like — which is the exact pattern LinkedIn flags and the reason `enrich-profiles` is rated HIGH. Accounts have been warned for it in practice. Cap = 10/session by default (raise it with --max=N and own the risk), and keep the cadence human and the volume well under it; prefer visiting people you then actually contact.",
147
147
  "useWhen": "You want recruiters at target companies to notice you without sending a connection request."
148
148
  },
149
149
  "viewers": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilml-plugin-linkedin",
3
- "version": "1.20.20",
3
+ "version": "1.20.22",
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": [