ilml-plugin-linkedin 1.13.0 → 1.14.0

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,4 +1,4 @@
1
- var Kt=Object.defineProperty;var nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>{for(var n in t)Kt(e,n,{get:t[n],enumerable:!0})};async function $(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ot(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"),c=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||c){let a=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:r.substring(0,80)};let m=o.querySelectorAll("button");for(let l of m){let y=l.innerText?.trim().toLowerCase()||"",u=l.getAttribute("aria-label")?.toLowerCase()||"";if(y==="not now"||y==="no thanks"||y==="dismiss"||u.includes("dismiss"))return l.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 se=nt(()=>{});var ht={};ge(ht,{extractCertificationsFromDetails:()=>_n,extractEducationFromDetails:()=>An,extractExperienceFromDetails:()=>xn,extractFeaturedFromDetails:()=>$n,extractRecommendationsFromDetails:()=>In,extractSkillsFromDetails:()=>En});async function xn(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();if(/\/(login|authwall|checkpoint)/i.test(o))throw new Error(`Session expired \u2014 bounced to ${o} when fetching /details/experience/`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(900);await $(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 $(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(l){let y=[];for(let u of l.querySelectorAll("div")){let f=Array.from(u.children).filter(v=>v.tagName==="DIV");if(f.length<3)continue;let C=f.filter(v=>(v.textContent||"").trim().length>50);C.length<3||(u.textContent||"").length<500||y.push({el:u,count:C.length,totalText:(u.textContent||"").length})}return y.sort((u,f)=>f.count-u.count||u.totalText-f.totalText),y[0]?.el}let c=i(s);if(!c)return[];let a=Array.from(c.children).filter(l=>l.tagName==="DIV").filter(l=>(l.textContent||"").trim().length>50);function m(l){let y=l[0]||null,u=null,f=null;if(l[1]){let b=l[1].split("\xB7").map(I=>I.trim());u=b[0]||null,b[1]&&(f=b[1])}let C=l.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),v=null,_=null;if(C>=0){let b=l[C].split("\xB7").map(I=>I.trim());v=b[0]||null,b[1]&&(_=b[1])}let h=null,g=-1;if(C>=0&&l[C+1]){let b=l[C+1],I=/^[>*\-•]|^&gt;/.test(b),te=/https?:\/\//.test(b),D=/\d{4}/.test(b),me=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!I&&!te&&!D&&b.length<100&&me&&(h=b,g=C+1)}let x=null,ee=-1,q=l[l.length-1];if(q&&/and\s+\+\d+\s+skills?$/i.test(q)){ee=l.length-1;let b=q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(x={listed:b[1].split(",").map(I=>I.trim()),additional:parseInt(b[2],10)})}let W=new Set([0,1,C,g,ee].filter(b=>b>=0)),T=l.filter((b,I)=>!W.has(I)),ve=T.length>0?T.join(`
1
+ var Kt=Object.defineProperty;var nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>{for(var n in t)Kt(e,n,{get:t[n],enumerable:!0})};async function $(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ot(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"),c=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||c){let a=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:r.substring(0,80)};let m=o.querySelectorAll("button");for(let l of m){let y=l.innerText?.trim().toLowerCase()||"",u=l.getAttribute("aria-label")?.toLowerCase()||"";if(y==="not now"||y==="no thanks"||y==="dismiss"||u.includes("dismiss"))return l.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 se=nt(()=>{});var ht={};ge(ht,{extractCertificationsFromDetails:()=>_n,extractEducationFromDetails:()=>En,extractExperienceFromDetails:()=>xn,extractFeaturedFromDetails:()=>$n,extractRecommendationsFromDetails:()=>In,extractSkillsFromDetails:()=>An});async function xn(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();if(/\/(login|authwall|checkpoint)/i.test(o))throw new Error(`Session expired \u2014 bounced to ${o} when fetching /details/experience/`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(900);await $(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 $(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(l){let y=[];for(let u of l.querySelectorAll("div")){let f=Array.from(u.children).filter(v=>v.tagName==="DIV");if(f.length<3)continue;let C=f.filter(v=>(v.textContent||"").trim().length>50);C.length<3||(u.textContent||"").length<500||y.push({el:u,count:C.length,totalText:(u.textContent||"").length})}return y.sort((u,f)=>f.count-u.count||u.totalText-f.totalText),y[0]?.el}let c=i(s);if(!c)return[];let a=Array.from(c.children).filter(l=>l.tagName==="DIV").filter(l=>(l.textContent||"").trim().length>50);function m(l){let y=l[0]||null,u=null,f=null;if(l[1]){let b=l[1].split("\xB7").map(I=>I.trim());u=b[0]||null,b[1]&&(f=b[1])}let C=l.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),v=null,_=null;if(C>=0){let b=l[C].split("\xB7").map(I=>I.trim());v=b[0]||null,b[1]&&(_=b[1])}let h=null,g=-1;if(C>=0&&l[C+1]){let b=l[C+1],I=/^[>*\-•]|^&gt;/.test(b),te=/https?:\/\//.test(b),D=/\d{4}/.test(b),me=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!I&&!te&&!D&&b.length<100&&me&&(h=b,g=C+1)}let x=null,ee=-1,q=l[l.length-1];if(q&&/and\s+\+\d+\s+skills?$/i.test(q)){ee=l.length-1;let b=q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(x={listed:b[1].split(",").map(I=>I.trim()),additional:parseInt(b[2],10)})}let W=new Set([0,1,C,g,ee].filter(b=>b>=0)),T=l.filter((b,I)=>!W.has(I)),ve=T.length>0?T.join(`
2
2
 
3
3
  `):null;return{title:y,company:u,employmentType:f,dates:v,duration:_,location:h,description:ve,skills:x,_raw:l}}return a.map(l=>{let u=(l.innerText||"").trim().split(`
4
4
  `).map(f=>f.trim()).filter(f=>f&&f.length<5e3);return m(u)}).filter(l=>l.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${t}: ${o.message?.slice(0,120)}`),[]}}async function le(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let r=e.url();if(/\/(login|authwall|checkpoint)/i.test(r))throw new Error(`Session expired \u2014 bounced to ${r} when fetching /details/${n}/`);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 $(700);await $(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let c of document.querySelectorAll("button"))if(/^Load more$/i.test((c.textContent||"").trim()))return c.click(),!0;return!1});)s++,await $(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(600)}async function ce(e,t,n,o){try{return await o()}catch(r){let s=r.message||"";if(/session expired|bounced to|authwall|checkpoint/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 $n(e,t){return ce(t,"featured","extractFeaturedFromDetails",async()=>(await le(e,t,"featured"),await e.evaluate(`(() => {
@@ -37,9 +37,12 @@ var Kt=Object.defineProperty;var nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>{
37
37
  // Reject "People You May Know" sidebar cards: signature is
38
38
  // exactly [title, "View"] with no url/caption beyond "View".
39
39
  if (e._raw.length === 2 && e._raw[1] === 'View') return false;
40
+ // Reject "Other profiles you may know" widget cards: caption is
41
+ // just a connection-degree marker (e.g. "\xB7 3rd", "\xB7 2nd").
42
+ if (e.caption && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.caption.trim())) return false;
40
43
  return true;
41
44
  });
42
- })()`)))}async function An(e,t){return ce(t,"education","extractEducationFromDetails",async()=>(await le(e,t,"education"),await e.evaluate(`(() => {
45
+ })()`)))}async function En(e,t){return ce(t,"education","extractEducationFromDetails",async()=>(await le(e,t,"education"),await e.evaluate(`(() => {
43
46
  ${ae}
44
47
 
45
48
  const main = document.querySelector('main');
@@ -71,9 +74,12 @@ var Kt=Object.defineProperty;var nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>{
71
74
  if (!e.school) return false;
72
75
  // Reject "People You May Know" sidebar cards: [title, "View"].
73
76
  if (e._raw.length === 2 && e._raw[1] === 'View') return false;
77
+ // Reject related-profile widget: "degree" parsed as the
78
+ // connection-degree marker ("\xB7 3rd") instead of a real degree.
79
+ if (e.degree && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.degree.trim())) return false;
74
80
  return true;
75
81
  });
76
- })()`)))}async function En(e,t){return ce(t,"skills","extractSkillsFromDetails",async()=>(await le(e,t,"skills"),await e.evaluate(`(() => {
82
+ })()`)))}async function An(e,t){return ce(t,"skills","extractSkillsFromDetails",async()=>(await le(e,t,"skills"),await e.evaluate(`(() => {
77
83
  ${ae}
78
84
 
79
85
  const main = document.querySelector('main');
@@ -161,6 +167,9 @@ var Kt=Object.defineProperty;var nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>{
161
167
  if (!e.recommender || !e.text) return false;
162
168
  // Reject "People You May Know" sidebar cards: [title, "View"].
163
169
  if (e._raw.length === 2 && e._raw[1] === 'View') return false;
170
+ // Reject related-profile widget: recommenderTitle is the
171
+ // connection-degree marker, not a real job title.
172
+ if (e.recommenderTitle && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.recommenderTitle.trim())) return false;
164
173
  return true;
165
174
  });
166
175
  })()`)))}var ae,gt=nt(()=>{se();ae=`
@@ -183,6 +192,20 @@ function findEntryContainer(root) {
183
192
  });
184
193
  if (allLookLikePYMK) continue;
185
194
 
195
+ // Reject "Other profiles you may know" / related-profile widget:
196
+ // LinkedIn shows this when /details/<section>/ has no real data
197
+ // (e.g. profile has no Featured at all). Every entry is a short
198
+ // [name, "\xB7 Nth"] card with a connection-degree marker as the only
199
+ // metadata. Real Featured / Education / Recommendations entries
200
+ // NEVER consist solely of name + degree.
201
+ const DEGREE_RE = /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i;
202
+ const allLookLikeRelatedProfiles = substantial.every(c => {
203
+ const lines = (c.innerText || '').trim().split('\\n').map(l => l.trim()).filter(Boolean);
204
+ if (lines.length > 4) return false;
205
+ return lines.some(l => DEGREE_RE.test(l));
206
+ });
207
+ if (allLookLikeRelatedProfiles) continue;
208
+
186
209
  // Reject LinkedIn footer/legal blocks: when a /details/<section>/ page
187
210
  // renders empty, LinkedIn falls back to "Questions? Visit our Help
188
211
  // Center", "Select language" (35+ languages), "Recommendation
@@ -198,6 +221,8 @@ function findEntryContainer(root) {
198
221
  'Who your viewers also viewed', // "Private to you" PYMK block on empty pages
199
222
  'People also viewed',
200
223
  'People you may know',
224
+ 'More profiles for you', // LinkedIn related-profiles widget shown
225
+ 'Other profiles you may know', // when /details/<section>/ is empty
201
226
  ];
202
227
  if (FOOTER_MARKERS.some(m => containerText.includes(m))) continue;
203
228
 
@@ -213,14 +238,14 @@ function findEntryContainer(root) {
213
238
  `});import on from"puppeteer";import{addExtra as rn}from"puppeteer-extra";import sn from"puppeteer-extra-plugin-stealth";se();import{getPluginConfig as zt}from"@ilivemylife/graph-sdk";var Qt=await zt();for(let[e,t]of Object.entries(Qt))process.env[e]===void 0&&(process.env[e]=t);var Zt=process.env.LINKEDIN_NAME,Y=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Mo=Object.freeze(new Set([Y.DRAFT,Y.CONFIRMED,Y.NEEDS_REVIEW])),Xt=Object.freeze(new Set([Y.DRAFT,Y.CONFIRMED,Y.REJECTED,Y.NEEDS_REVIEW]));import rt from"fs";import en from"path";var tn="cookies.json";function nn(){let e=process.env.ILML_SCOPE_DIR;return e?en.join(e,"plugins-state","linkedin","cookies.json"):tn}function st(){let e=nn();if(!rt.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=rt.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}var it=rn(on);it.use(sn());async function lt(){let e=await it.launch({headless:!1,defaultViewport:null,protocolTimeout:3e5}),t=async()=>{console.log(`
214
239
  Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t);let n=await e.newPage();await n.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})});try{let o=st();await n.setCookie(...o),console.log(" Browser launched, cookies loaded.")}catch(o){console.error(`
215
240
  [!] ${o.message}
216
- `),await e.close(),process.exit(1)}return{browser:e,page:n}}se();import"dotenv/config";import*as A from"fs";import*as E from"path";import{fileURLToPath as ln}from"url";var an=ln(import.meta.url),cn=E.dirname(E.dirname(an)),B=process.env.DATA_DIR?E.resolve(process.env.DATA_DIR,"collected-profiles"):E.join(cn,"collected-profiles"),xe=E.join(B,"people.json"),nr=E.join(B,"jobs.json"),or=E.join(B,"quota.json"),rr=E.join(B,"conversations.json"),sr=E.join(B,"sync-state.json"),ir=E.join(B,"application-questions.json"),$e=E.join(B,"profile-history");var ne=null,un=null,dn=null,fn=null,mn=null,pn=null;function ut(){ne=null,un=null,dn=null,fn=null,mn=null,pn=null}function dt(){A.existsSync(B)||A.mkdirSync(B,{recursive:!0})}function ft(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 mt(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: ${E.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 hn(){return new Date().toISOString().split("T")[0]}var gn=["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"],yn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function Ae(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function wn(){A.existsSync($e)||A.mkdirSync($e,{recursive:!0})}function pt(e){let t=Ae(e);return t?E.join($e,`${t}.json`):null}function bn(e){let t=pt(e);return t?mt(t,`profile-history/${Ae(e)}.json`)||[]:[]}function Sn(e,t){let n=pt(e);if(!n)return;wn();let o=bn(e);o.unshift(t);try{ft(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${Ae(e)}: ${r.message}`)}}function at(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function ct(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function vn(e,t){if(!e)return[];let n=[];for(let o of yn){let r=e[o],s=t[o];at(r)||at(s)||ct(r)!==ct(s)&&n.push(o)}return n}function kn(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 ie(){return ne||(dt(),ne=mt(xe,"people.json")||{},ne)}function Cn(e){dt(),ne=e;try{ft(xe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${E.resolve(xe)}`)}}function Ee(e,t={}){if(!e)return null;let n=ie(),o=hn(),r=new Date().toISOString(),s=n[e];if(s){let i=vn(s,t);i.length>0&&(Sn(e,{capturedAt:r,previousLastUpdated:s.lastUpdated||null,changedFields:i,snapshot:kn(s)}),s.lastSnapshotAt=r),s.seenCount=(s.seenCount||1)+1,s.lastSeen=o,s.lastUpdated=r,t.source&&!s.sources?.includes(t.source)&&(s.sources=s.sources||[],s.sources.push(t.source));for(let c of gn)if(t[c]!=null){if(Array.isArray(t[c])&&t[c].length===0&&Array.isArray(s[c])&&s[c].length>0)continue;s[c]=t[c]}Array.isArray(t.availableSections)&&(s.lastFullVisitAt=r)}else n[e]={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,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return Cn(n),n[e]}async function Tn(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: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function yt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:c=!1,extractCertifications:a=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await ot(e)&&(console.log(" Dismissed Premium overlay"),await $(1500),await Tn(e,t));let l=0;for(let x=0;x<2;x++){let ee=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(T=>window.scrollTo(0,T),ee*W/6),await $(900);let q=await e.evaluate(()=>document.body.scrollHeight);if(q===l)break;l=q}await $(800);let y=await e.evaluate(()=>{let x=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"]),ee=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"]),q=p=>{let w=(p||"").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:[]},T=document.querySelector("main");if(!T)return W;let ve=[...Array.from(T.querySelectorAll("h1")),...Array.from(T.querySelectorAll("h2"))],b=Array.from(T.querySelectorAll("h2")),I=ve.find(p=>{let w=p.textContent&&p.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!x.has(S)&&!ee.has(S)}),te=I?I.textContent.trim():null,D=I?I.parentElement:null;for(;D&&D!==T&&!Array.from(D.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!q(S)});)D=D.parentElement;let me=null,Ve=null,He=null,ke=null;if(D&&D!==T){let p=Array.from(D.children).filter(S=>S.tagName==="P").filter(S=>{let V=S.textContent&&S.textContent.trim();return V&&V.length>5&&!q(V)});if(p[0]&&(me=p[0].textContent.trim()),p[1]){let S=p[1].textContent.trim().split(/\s*[·•]\s*/);Ve=S[0]||null,S.length>1&&(He=S.slice(1).join(" \xB7 "))}let w=Array.from(D.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let V=w[S].textContent&&w[S].textContent.trim();if(V&&!(te&&V.startsWith(te))&&(ke=V.split(/[·•]/)[0].trim(),ke))break}}let Je=null;if(D){let p=D.querySelectorAll("p, span, div");for(let w of p){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){Je=S;break}}}let Ut=!!T.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),We=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Vt=We&&We.src||null,pe=T.textContent||"",Ye=null,Ge=pe.match(/(\d+\+?)\s+connections\b/i);Ge&&(Ye=Ge[1]+" connections");let he=null,Ke=pe.match(/(\d+)\s+mutual connection/i),ze=pe.match(/and\s+(\d+)\s+other mutual/i),Ht=pe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ke?he=parseInt(Ke[1],10):ze?he=2+parseInt(ze[1],10):Ht&&(he=2);let Qe=null,Ze=null,Xe=b.find(p=>p.textContent&&p.textContent.trim()==="About");if(Xe){let p=Xe.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ce=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Gt=>Gt.trim()).filter(Boolean);Ce.length>0&&Ce.length<10&&(Ze=Ce)}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(),Qe=w||null}}let et=null,tt=b.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(tt){let p=tt.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(et=parseInt(w[1].replace(/,/g,""),10))}}let Jt=[...new Set(b.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==te).filter(p=>x.has(p)))],re=document.body.textContent||"",Wt=/#OpenToWork\b/i.test(re)||/\bOpen to work\b/.test(re),Yt=/#Hiring\b/i.test(re)||/\bI'?m hiring\b/i.test(re)||/\bWe are hiring\b/i.test(re);return{name:te,title:me,location:ke,currentCompany:Ve,currentSchool:He,connectionDegree:Je,hasVerifiedBadge:Ut,photoUrl:Vt,connectionsLevel:Ye,mutualConnectionsCount:he,followers:et,openToWork:Wt,hiring:Yt,about:Qe,topSkills:Ze,availableSections:Jt}});console.log(`Viewed: ${y.name} - ${y.title}`);let u=null,f=null,C=null,v=null,_=null,h=null;if(o||r||s||i||c||a){let x=await Promise.resolve().then(()=>(gt(),ht));o&&(u=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${u.length} entries`)),r&&(f=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${f.length} entries`)),s&&(C=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${C.length} entries`)),i&&(v=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${v.length} entries`)),c&&(_=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${_.length} entries`)),a&&(h=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${h.length} entries`))}return{...y,profileUrl:t,...u!==null&&{experience:u},...f!==null&&{featured:f},...C!==null&&{education:C},...v!==null&&{skillsFull:v},..._!==null&&{recommendations:_},...h!==null&&{certifications:h}}}catch(m){console.error(`Error viewing profile ${t}:`,m.message);try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(m.message||""))throw m;return null}}import"dotenv/config";import*as O from"fs";import*as j from"path";import{fileURLToPath as Dn}from"url";var Rn=Dn(import.meta.url),jn=j.dirname(j.dirname(Rn)),K=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(jn,"market-research"),On=j.join(K,"scouted-jobs.json"),Nn=j.join(K,"discovered-people.json"),wt=j.join(K,"visit-log.json"),Sr=j.join(K,"companies.json"),vr=j.join(K,"job-decisions.json");function Fn(){O.existsSync(K)||O.mkdirSync(K,{recursive:!0})}function Ln(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";O.writeFileSync(o,n);for(let r=0;r<3;r++)try{O.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 _e(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function bt(){ue=null,Pn=null,de=null,qn=null,G=null}var ue=null;function Mn(){return ue||(ue=_e(On)||{},ue)}var Pn=null;var de=null;function ye(){return de||(de=_e(Nn)||{},de)}var qn=null;var G=null;function oe(){return G||(G=_e(wt)||{visits:[]},Array.isArray(G.visits)||(G.visits=[]),G)}function St(e,t={}){if(!e)return;Fn();let n=oe();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{Ln(wt,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function vt(e){let t=oe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function kt(){let e=Mn(),t=ye(),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 c=Object.entries(i).sort((u,f)=>f[1]-u[1]).slice(0,8).map(([u,f])=>`${u} (${f})`),a=oe(),m=new Date().toISOString().slice(0,10),l=a.visits.filter(u=>u.date.startsWith(m)).length,y=new Set(a.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:c,totalVisited:y,todayVisited:l,lastScoutDate:n.length>0?n.sort((u,f)=>(f.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}se();async function Ct(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:c=!1}=n,a={visited:0,skipped:0,errors:0},m=Date.now()-s*24*60*60*1e3;for(let l of t){if(a.visited>=o)break;if(!l.profileUrl)continue;let y=vt(l.profileUrl);if(y&&new Date(y).getTime()>m){a.skipped++;continue}try{let u=await yt(e,l.profileUrl,{extractExperience:c}),f=l.source||"visit";if(u){let v={...u,source:f};c&&Array.isArray(u.experience)&&u.experience.length>0&&(v._lastEnrichedAt=new Date().toISOString()),Ee(l.profileUrl,v)}St(l.profileUrl,{name:u?.name||l.name||null,source:f}),a.visited++,i?console.log(` [${a.visited}] ${u?.name||l.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let C=Math.random()*4e3;await $(r+C)}catch(u){a.errors++,i&&console.error(` Error visiting ${l.name||l.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 a}function xt(e={}){let{limit:t=150,revisitDays:n=14}=e,o=oe(),r=new Set(o.visits?.map(h=>h.profileUrl)||[]),s=new Map;for(let h of o.visits||[]){let g=s.get(h.profileUrl);(!g||h.date>g)&&s.set(h.profileUrl,h.date)}let i=Date.now()-7*24*60*60*1e3,c=Date.now()-n*24*60*60*1e3;function a(h){let g=s.get(h);return g&&new Date(g).getTime()>i}let m=ye(),l=Object.entries(m).filter(([h])=>!r.has(h)).map(([h,g])=>({profileUrl:h,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),y=ie(),u=Object.entries(y).filter(([h,g])=>g.connectionStatus==="connected"||a(h)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([h,g])=>({profileUrl:h,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(y).filter(([h,g])=>{let x=g.connectionStatus;return!(!x||x==="connected"||x==="pending"||x==="sent_without_note"||x==="sent_with_note"||a(h)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([h,g])=>({profileUrl:h,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),C=[...s.entries()].filter(([h,g])=>new Date(g).getTime()<c).map(([h,g])=>({profileUrl:h,name:null,source:"revisit",priority:4,lastVisit:g})),v=h=>h.sort(()=>Math.random()-.5);return l.sort((h,g)=>g.jobCount-h.jobCount),u.sort((h,g)=>g.jobCount-h.jobCount),v(f),v(C),[...l,...u,...f,...C].slice(0,t)}function $t(){let e=ye();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Ie(){let e=ie();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 Te(e=14){let t=oe(),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"}))}import"dotenv/config";import*as N from"fs";import*as H from"path";import{fileURLToPath as Wn}from"url";import"dotenv/config";import{createGraphClient as Bn,resolveToken as Un}from"@ilivemylife/graph-sdk";import{config as Vn}from"dotenv";Vn();var At=Un()||process.env.TOKEN;At||(console.error(`
241
+ `),await e.close(),process.exit(1)}return{browser:e,page:n}}se();import"dotenv/config";import*as E from"fs";import*as A from"path";import{fileURLToPath as ln}from"url";var an=ln(import.meta.url),cn=A.dirname(A.dirname(an)),B=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"collected-profiles"):A.join(cn,"collected-profiles"),xe=A.join(B,"people.json"),nr=A.join(B,"jobs.json"),or=A.join(B,"quota.json"),rr=A.join(B,"conversations.json"),sr=A.join(B,"sync-state.json"),ir=A.join(B,"application-questions.json"),$e=A.join(B,"profile-history");var ne=null,un=null,dn=null,fn=null,mn=null,pn=null;function ut(){ne=null,un=null,dn=null,fn=null,mn=null,pn=null}function dt(){E.existsSync(B)||E.mkdirSync(B,{recursive:!0})}function ft(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";E.writeFileSync(o,n);for(let r=0;r<3;r++)try{E.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 mt(e,t){if(!E.existsSync(e))return null;try{let n=JSON.parse(E.readFileSync(e,"utf-8"));try{E.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${A.resolve(e)}`);let o=e+".backup";if(E.existsSync(o))try{let r=JSON.parse(E.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{E.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{E.copyFileSync(e,e+".corrupted")}catch{}return null}}function hn(){return new Date().toISOString().split("T")[0]}var gn=["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"],yn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function Ee(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function wn(){E.existsSync($e)||E.mkdirSync($e,{recursive:!0})}function pt(e){let t=Ee(e);return t?A.join($e,`${t}.json`):null}function bn(e){let t=pt(e);return t?mt(t,`profile-history/${Ee(e)}.json`)||[]:[]}function Sn(e,t){let n=pt(e);if(!n)return;wn();let o=bn(e);o.unshift(t);try{ft(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${Ee(e)}: ${r.message}`)}}function at(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function ct(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function vn(e,t){if(!e)return[];let n=[];for(let o of yn){let r=e[o],s=t[o];at(r)||at(s)||ct(r)!==ct(s)&&n.push(o)}return n}function kn(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 ie(){return ne||(dt(),ne=mt(xe,"people.json")||{},ne)}function Cn(e){dt(),ne=e;try{ft(xe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${A.resolve(xe)}`)}}function Ae(e,t={}){if(!e)return null;let n=ie(),o=hn(),r=new Date().toISOString(),s=n[e];if(s){let i=vn(s,t);i.length>0&&(Sn(e,{capturedAt:r,previousLastUpdated:s.lastUpdated||null,changedFields:i,snapshot:kn(s)}),s.lastSnapshotAt=r),s.seenCount=(s.seenCount||1)+1,s.lastSeen=o,s.lastUpdated=r,t.source&&!s.sources?.includes(t.source)&&(s.sources=s.sources||[],s.sources.push(t.source));for(let c of gn)if(t[c]!=null){if(Array.isArray(t[c])&&t[c].length===0&&Array.isArray(s[c])&&s[c].length>0)continue;s[c]=t[c]}Array.isArray(t.availableSections)&&(s.lastFullVisitAt=r)}else n[e]={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,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return Cn(n),n[e]}async function Tn(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: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function yt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:c=!1,extractCertifications:a=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await ot(e)&&(console.log(" Dismissed Premium overlay"),await $(1500),await Tn(e,t));let l=0;for(let x=0;x<2;x++){let ee=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(T=>window.scrollTo(0,T),ee*W/6),await $(900);let q=await e.evaluate(()=>document.body.scrollHeight);if(q===l)break;l=q}await $(800);let y=await e.evaluate(()=>{let x=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"]),ee=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"]),q=p=>{let w=(p||"").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:[]},T=document.querySelector("main");if(!T)return W;let ve=[...Array.from(T.querySelectorAll("h1")),...Array.from(T.querySelectorAll("h2"))],b=Array.from(T.querySelectorAll("h2")),I=ve.find(p=>{let w=p.textContent&&p.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!x.has(S)&&!ee.has(S)}),te=I?I.textContent.trim():null,D=I?I.parentElement:null;for(;D&&D!==T&&!Array.from(D.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!q(S)});)D=D.parentElement;let me=null,Ve=null,He=null,ke=null;if(D&&D!==T){let p=Array.from(D.children).filter(S=>S.tagName==="P").filter(S=>{let V=S.textContent&&S.textContent.trim();return V&&V.length>5&&!q(V)});if(p[0]&&(me=p[0].textContent.trim()),p[1]){let S=p[1].textContent.trim().split(/\s*[·•]\s*/);Ve=S[0]||null,S.length>1&&(He=S.slice(1).join(" \xB7 "))}let w=Array.from(D.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let V=w[S].textContent&&w[S].textContent.trim();if(V&&!(te&&V.startsWith(te))&&(ke=V.split(/[·•]/)[0].trim(),ke))break}}let Je=null;if(D){let p=D.querySelectorAll("p, span, div");for(let w of p){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){Je=S;break}}}let Ut=!!T.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),We=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Vt=We&&We.src||null,pe=T.textContent||"",Ye=null,Ge=pe.match(/(\d+\+?)\s+connections\b/i);Ge&&(Ye=Ge[1]+" connections");let he=null,Ke=pe.match(/(\d+)\s+mutual connection/i),ze=pe.match(/and\s+(\d+)\s+other mutual/i),Ht=pe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ke?he=parseInt(Ke[1],10):ze?he=2+parseInt(ze[1],10):Ht&&(he=2);let Qe=null,Ze=null,Xe=b.find(p=>p.textContent&&p.textContent.trim()==="About");if(Xe){let p=Xe.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ce=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Gt=>Gt.trim()).filter(Boolean);Ce.length>0&&Ce.length<10&&(Ze=Ce)}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(),Qe=w||null}}let et=null,tt=b.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(tt){let p=tt.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(et=parseInt(w[1].replace(/,/g,""),10))}}let Jt=[...new Set(b.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==te).filter(p=>x.has(p)))],re=document.body.textContent||"",Wt=/#OpenToWork\b/i.test(re)||/\bOpen to work\b/.test(re),Yt=/#Hiring\b/i.test(re)||/\bI'?m hiring\b/i.test(re)||/\bWe are hiring\b/i.test(re);return{name:te,title:me,location:ke,currentCompany:Ve,currentSchool:He,connectionDegree:Je,hasVerifiedBadge:Ut,photoUrl:Vt,connectionsLevel:Ye,mutualConnectionsCount:he,followers:et,openToWork:Wt,hiring:Yt,about:Qe,topSkills:Ze,availableSections:Jt}});console.log(`Viewed: ${y.name} - ${y.title}`);let u=null,f=null,C=null,v=null,_=null,h=null;if(o||r||s||i||c||a){let x=await Promise.resolve().then(()=>(gt(),ht));o&&(u=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${u.length} entries`)),r&&(f=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${f.length} entries`)),s&&(C=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${C.length} entries`)),i&&(v=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${v.length} entries`)),c&&(_=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${_.length} entries`)),a&&(h=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${h.length} entries`))}return{...y,profileUrl:t,...u!==null&&{experience:u},...f!==null&&{featured:f},...C!==null&&{education:C},...v!==null&&{skillsFull:v},..._!==null&&{recommendations:_},...h!==null&&{certifications:h}}}catch(m){console.error(`Error viewing profile ${t}:`,m.message);try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(m.message||""))throw m;return null}}import"dotenv/config";import*as O from"fs";import*as j from"path";import{fileURLToPath as Dn}from"url";var Rn=Dn(import.meta.url),jn=j.dirname(j.dirname(Rn)),K=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(jn,"market-research"),On=j.join(K,"scouted-jobs.json"),Nn=j.join(K,"discovered-people.json"),wt=j.join(K,"visit-log.json"),Sr=j.join(K,"companies.json"),vr=j.join(K,"job-decisions.json");function Ln(){O.existsSync(K)||O.mkdirSync(K,{recursive:!0})}function Fn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";O.writeFileSync(o,n);for(let r=0;r<3;r++)try{O.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 _e(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function bt(){ue=null,Pn=null,de=null,qn=null,G=null}var ue=null;function Mn(){return ue||(ue=_e(On)||{},ue)}var Pn=null;var de=null;function ye(){return de||(de=_e(Nn)||{},de)}var qn=null;var G=null;function oe(){return G||(G=_e(wt)||{visits:[]},Array.isArray(G.visits)||(G.visits=[]),G)}function St(e,t={}){if(!e)return;Ln();let n=oe();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{Fn(wt,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function vt(e){let t=oe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function kt(){let e=Mn(),t=ye(),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 c=Object.entries(i).sort((u,f)=>f[1]-u[1]).slice(0,8).map(([u,f])=>`${u} (${f})`),a=oe(),m=new Date().toISOString().slice(0,10),l=a.visits.filter(u=>u.date.startsWith(m)).length,y=new Set(a.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:c,totalVisited:y,todayVisited:l,lastScoutDate:n.length>0?n.sort((u,f)=>(f.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}se();async function Ct(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:c=!1}=n,a={visited:0,skipped:0,errors:0},m=Date.now()-s*24*60*60*1e3;for(let l of t){if(a.visited>=o)break;if(!l.profileUrl)continue;let y=vt(l.profileUrl);if(y&&new Date(y).getTime()>m){a.skipped++;continue}try{let u=await yt(e,l.profileUrl,{extractExperience:c}),f=l.source||"visit";if(u){let v={...u,source:f};c&&Array.isArray(u.experience)&&u.experience.length>0&&(v._lastEnrichedAt=new Date().toISOString()),Ae(l.profileUrl,v)}St(l.profileUrl,{name:u?.name||l.name||null,source:f}),a.visited++,i?console.log(` [${a.visited}] ${u?.name||l.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let C=Math.random()*4e3;await $(r+C)}catch(u){a.errors++,i&&console.error(` Error visiting ${l.name||l.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 a}function xt(e={}){let{limit:t=150,revisitDays:n=14}=e,o=oe(),r=new Set(o.visits?.map(h=>h.profileUrl)||[]),s=new Map;for(let h of o.visits||[]){let g=s.get(h.profileUrl);(!g||h.date>g)&&s.set(h.profileUrl,h.date)}let i=Date.now()-7*24*60*60*1e3,c=Date.now()-n*24*60*60*1e3;function a(h){let g=s.get(h);return g&&new Date(g).getTime()>i}let m=ye(),l=Object.entries(m).filter(([h])=>!r.has(h)).map(([h,g])=>({profileUrl:h,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),y=ie(),u=Object.entries(y).filter(([h,g])=>g.connectionStatus==="connected"||a(h)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([h,g])=>({profileUrl:h,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(y).filter(([h,g])=>{let x=g.connectionStatus;return!(!x||x==="connected"||x==="pending"||x==="sent_without_note"||x==="sent_with_note"||a(h)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([h,g])=>({profileUrl:h,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),C=[...s.entries()].filter(([h,g])=>new Date(g).getTime()<c).map(([h,g])=>({profileUrl:h,name:null,source:"revisit",priority:4,lastVisit:g})),v=h=>h.sort(()=>Math.random()-.5);return l.sort((h,g)=>g.jobCount-h.jobCount),u.sort((h,g)=>g.jobCount-h.jobCount),v(f),v(C),[...l,...u,...f,...C].slice(0,t)}function $t(){let e=ye();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Ie(){let e=ie();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 Te(e=14){let t=oe(),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"}))}import"dotenv/config";import*as N from"fs";import*as H from"path";import{fileURLToPath as Wn}from"url";import"dotenv/config";import{createGraphClient as Bn,resolveToken as Un}from"@ilivemylife/graph-sdk";import{config as Vn}from"dotenv";Vn();var Et=Un()||process.env.TOKEN;Et||(console.error(`
217
242
  [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.
218
243
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
219
244
  `),console.error(` Or add ILML_TOKEN=... to .env
220
- `),process.exit(1));var Et=Bn({token:At});function Hn(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`}function Jn({scriptName:e,mode:t,status:n,error:o,duration:r}){let s=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),c=r?` ${Hn(r)}`:"",a=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",m=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${m} \u2014 ${a} \u2014 ${i}${c}`}async function _t({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=`**${Jn({scriptName:e,mode:t,status:n,error:r,duration:s})}**
245
+ `),process.exit(1));var At=Bn({token:Et});function Hn(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`}function Jn({scriptName:e,mode:t,status:n,error:o,duration:r}){let s=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),c=r?` ${Hn(r)}`:"",a=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",m=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${m} \u2014 ${a} \u2014 ${i}${c}`}async function _t({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=`**${Jn({scriptName:e,mode:t,status:n,error:r,duration:s})}**
221
246
 
222
247
  ${o.join(`
223
- `)}`;try{await Et.addMessage(i,a)}catch(m){console.error(`[runReport] Failed to post end-of-session message: ${m.message}`)}}var Yn=Wn(import.meta.url),Gn=H.dirname(H.dirname(Yn)),De=process.env.DATA_DIR?H.resolve(process.env.DATA_DIR,"collected-profiles"):H.join(Gn,"collected-profiles"),Re=H.join(De,"run-log.json");function Kn(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 It(){try{if(!N.existsSync(Re))return{runs:[]};let e=JSON.parse(N.readFileSync(Re,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Tt(e){N.existsSync(De)||N.mkdirSync(De,{recursive:!0});try{Kn(Re,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Dt(e,t="default"){let n=It();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),Tt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function je(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=It(),c=i.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration;else{let a=i.runs.find(m=>m.script===e.script&&m.status==="running"&&m.timestamp===new Date(e.startTime).toISOString());a&&(a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration)}Tt(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";_t({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as d from"fs";import*as qe from"os";import*as k from"path";import{fileURLToPath as po}from"url";var Fe={};ge(Fe,{NAME:()=>Qn,VERSION:()=>zn,up:()=>eo});import*as F from"fs";import*as we from"path";var zn=1,Qn="normalize-jobs-and-questions",Zn=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Xn=50;function Oe(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function Ne(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 eo(e,t){let n=we.join(e,"jobs.json"),o=we.join(t,"scouted-jobs.json"),r=we.join(e,"application-questions.json"),s=Oe(n)||{},i=Oe(o)||{},c=0,a=[];for(let l of Object.keys(s)){if(!i[l])continue;let y=i[l],u=s[l];for(let f of Zn)y[f]!=null&&u[f]==null&&(u[f]=y[f]);a.push(l),c++}c>0?(Ne(n,s),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let m=Oe(r);if(m&&Array.isArray(m.applications)){let l={},y=0;for(let u of m.applications){let f=u.jobId||"unknown";l[f]||(l[f]={applications:[]});let C=(u.questions||[]).map(v=>{let _={type:v.type||"input",question:v.question||"",answer:v.answer||""};return v.options&&(v.options.length<=Xn?_.options=v.options:(_.optionsOmitted=!0,y++)),v.page&&(_.page=v.page),v.wasPreFilled&&(_.wasPreFilled=!0),v.wasRetry&&(_.wasRetry=!0),_});l[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})}Ne(r,l),console.log(` Phase 2: Rekeyed ${m.applications.length} applications by jobId (${Object.keys(l).length} unique jobs)`),y>0&&console.log(` Phase 2: Stripped bloated options from ${y} questions`)}else m&&!m.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(a.length>0){for(let l of a)delete i[l];Ne(o,i),console.log(` Phase 3: Removed ${a.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 Le={};ge(Le,{NAME:()=>no,VERSION:()=>to,up:()=>so});import*as L from"fs";import*as Rt from"path";var to=2,no="reset-unread-flags";function oo(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function ro(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{L.writeFileSync(o,n)}catch(r){try{L.unlinkSync(o)}catch{}throw r}try{L.renameSync(o,e)}catch(r){try{L.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 so(e){let t=Rt.join(e,"conversations.json"),n=oo(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}ro(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Me={};ge(Me,{NAME:()=>lo,VERSION:()=>io,up:()=>mo});import*as M from"fs";import*as jt from"path";var io=3,lo="recompute-last-message-by",ao=new Set(["draft","confirmed","rejected","needs_review"]);function co(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function uo(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 fo(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!ao.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 mo(e){let t=jt.join(e,"conversations.json"),n=co(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 c of Object.keys(n)){let a=n[c];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,s++);let m=Array.isArray(a.messages)?a.messages:[],l=fo(m,o),y=l==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==l&&i++,a.lastMessageBy=l,a.conversationStatus=y,r++}if(r===0){console.log(" No conversations to recompute.");return}uo(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 ho=po(import.meta.url),go=k.dirname(ho),yo=k.dirname(k.dirname(go));function wo(e){return e&&(e==="~"?qe.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(qe.homedir(),e.slice(2)):e)}var P=process.env.DATA_DIR?k.resolve(wo(process.env.DATA_DIR)):yo,Q=k.join(P,"collected-profiles"),Z=k.join(P,"market-research"),R=k.join(P,".schema-version"),Ot=[k.join(Q,".schema-version"),k.join(Z,".schema-version")],J=3,U=[{version:1,module:Fe},{version:2,module:Le},{version:3,module:Me}];(function(){U.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of U){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=U.length?U[U.length-1].version:0;if(n!==J)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${J}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<U.length;o++){let r=o+1;if(U[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${U[o].version}`)}})();function Mt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
248
+ `)}`;try{await At.addMessage(i,a)}catch(m){console.error(`[runReport] Failed to post end-of-session message: ${m.message}`)}}var Yn=Wn(import.meta.url),Gn=H.dirname(H.dirname(Yn)),De=process.env.DATA_DIR?H.resolve(process.env.DATA_DIR,"collected-profiles"):H.join(Gn,"collected-profiles"),Re=H.join(De,"run-log.json");function Kn(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 It(){try{if(!N.existsSync(Re))return{runs:[]};let e=JSON.parse(N.readFileSync(Re,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Tt(e){N.existsSync(De)||N.mkdirSync(De,{recursive:!0});try{Kn(Re,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Dt(e,t="default"){let n=It();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),Tt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function je(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=It(),c=i.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration;else{let a=i.runs.find(m=>m.script===e.script&&m.status==="running"&&m.timestamp===new Date(e.startTime).toISOString());a&&(a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration)}Tt(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";_t({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as d from"fs";import*as qe from"os";import*as k from"path";import{fileURLToPath as po}from"url";var Le={};ge(Le,{NAME:()=>Qn,VERSION:()=>zn,up:()=>eo});import*as L from"fs";import*as we from"path";var zn=1,Qn="normalize-jobs-and-questions",Zn=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Xn=50;function Oe(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function Ne(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{L.writeFileSync(o,n)}catch(r){try{L.unlinkSync(o)}catch{}throw r}try{L.renameSync(o,e)}catch(r){try{L.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 eo(e,t){let n=we.join(e,"jobs.json"),o=we.join(t,"scouted-jobs.json"),r=we.join(e,"application-questions.json"),s=Oe(n)||{},i=Oe(o)||{},c=0,a=[];for(let l of Object.keys(s)){if(!i[l])continue;let y=i[l],u=s[l];for(let f of Zn)y[f]!=null&&u[f]==null&&(u[f]=y[f]);a.push(l),c++}c>0?(Ne(n,s),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let m=Oe(r);if(m&&Array.isArray(m.applications)){let l={},y=0;for(let u of m.applications){let f=u.jobId||"unknown";l[f]||(l[f]={applications:[]});let C=(u.questions||[]).map(v=>{let _={type:v.type||"input",question:v.question||"",answer:v.answer||""};return v.options&&(v.options.length<=Xn?_.options=v.options:(_.optionsOmitted=!0,y++)),v.page&&(_.page=v.page),v.wasPreFilled&&(_.wasPreFilled=!0),v.wasRetry&&(_.wasRetry=!0),_});l[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})}Ne(r,l),console.log(` Phase 2: Rekeyed ${m.applications.length} applications by jobId (${Object.keys(l).length} unique jobs)`),y>0&&console.log(` Phase 2: Stripped bloated options from ${y} questions`)}else m&&!m.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(a.length>0){for(let l of a)delete i[l];Ne(o,i),console.log(` Phase 3: Removed ${a.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 Fe={};ge(Fe,{NAME:()=>no,VERSION:()=>to,up:()=>so});import*as F from"fs";import*as Rt from"path";var to=2,no="reset-unread-flags";function oo(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function ro(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 so(e){let t=Rt.join(e,"conversations.json"),n=oo(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}ro(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Me={};ge(Me,{NAME:()=>lo,VERSION:()=>io,up:()=>mo});import*as M from"fs";import*as jt from"path";var io=3,lo="recompute-last-message-by",ao=new Set(["draft","confirmed","rejected","needs_review"]);function co(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function uo(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 fo(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!ao.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 mo(e){let t=jt.join(e,"conversations.json"),n=co(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 c of Object.keys(n)){let a=n[c];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,s++);let m=Array.isArray(a.messages)?a.messages:[],l=fo(m,o),y=l==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==l&&i++,a.lastMessageBy=l,a.conversationStatus=y,r++}if(r===0){console.log(" No conversations to recompute.");return}uo(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 ho=po(import.meta.url),go=k.dirname(ho),yo=k.dirname(k.dirname(go));function wo(e){return e&&(e==="~"?qe.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(qe.homedir(),e.slice(2)):e)}var P=process.env.DATA_DIR?k.resolve(wo(process.env.DATA_DIR)):yo,Q=k.join(P,"collected-profiles"),Z=k.join(P,"market-research"),R=k.join(P,".schema-version"),Ot=[k.join(Q,".schema-version"),k.join(Z,".schema-version")],J=3,U=[{version:1,module:Le},{version:2,module:Fe},{version:3,module:Me}];(function(){U.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of U){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=U.length?U[U.length-1].version:0;if(n!==J)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${J}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<U.length;o++){let r=o+1;if(U[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${U[o].version}`)}})();function Mt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
224
249
  [FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
225
250
  `),process.exit(1));try{d.mkdirSync(P,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
226
251
  [FATAL] Cannot create DATA_DIR (${P}): ${t.message}`),console.error(` Fix the path or permissions and try again.
@@ -238,11 +263,11 @@ ${o.join(`
238
263
  Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
239
264
  `),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
240
265
  [FATAL] Legacy .schema-version files disagree:`);for(let s of e)console.error(` ${s.file}: v${s.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
241
- `),process.exit(1)}let o=e[0].schema,r=R+".tmp";try{d.writeFileSync(r,JSON.stringify(o,null,2)),d.renameSync(r,R)}catch(s){try{d.unlinkSync(r)}catch{}throw s}for(let s of Ot)if(d.existsSync(s))try{d.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${R}`)}function ko(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function be(e){let t=d.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Ft(){if(vo(),!d.existsSync(R))return{version:0,migrations:[]};let e;try{e=be(R)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
266
+ `),process.exit(1)}let o=e[0].schema,r=R+".tmp";try{d.writeFileSync(r,JSON.stringify(o,null,2)),d.renameSync(r,R)}catch(s){try{d.unlinkSync(r)}catch{}throw s}for(let s of Ot)if(d.existsSync(s))try{d.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${R}`)}function ko(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function be(e){let t=d.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Lt(){if(vo(),!d.existsSync(R))return{version:0,migrations:[]};let e;try{e=be(R)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
242
267
  [FATAL] ${R} 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.
243
268
  `),process.exit(1)}let t=ko(e);return t===null&&(console.error(`
244
269
  [FATAL] ${R} 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.
245
- `),process.exit(1)),t}function Pt(e){try{d.chmodSync(e,384)}catch{}}function Co(e){if(Mt(),d.existsSync(R))try{if(d.lstatSync(R).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${R}. 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=R+".tmp";try{d.writeFileSync(t,JSON.stringify(e,null,2)),Pt(t),d.renameSync(t,R)}catch(n){try{d.unlinkSync(t)}catch{}throw n}}function Lt(e,t){if(!d.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=d.readdirSync(e).filter(c=>{let a=c.toLowerCase();if(a.includes(".backup")||a===".schema-version"||a.endsWith(".tmp"))return!1;try{return d.statSync(k.join(e,c)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let c of o){let a=k.join(e,c),m=k.join(e,c+n);if(d.existsSync(m)){s++;continue}try{Bt(a,m),r++}catch(l){i.push({file:c,err:l.message})}}if(i.length>0){let c=new Error(`Failed to back up ${i.length} file(s) in ${k.basename(e)}/: `+i.map(a=>`${a.file} (${a.err})`).join(", "));throw c.code="BACKUP_INCOMPLETE",c}if(r>0||s>0){let c=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${k.basename(e)}/ (${n})${c}`)}}var Pe=!1;async function qt(){if(Pe)return;Mt(),_o();let t=Ft().version;if(t===J){Pe=!0;return}So(),bo(),process.on("exit",Be),t>J&&(console.error(`
270
+ `),process.exit(1)),t}function Pt(e){try{d.chmodSync(e,384)}catch{}}function Co(e){if(Mt(),d.existsSync(R))try{if(d.lstatSync(R).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${R}. 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=R+".tmp";try{d.writeFileSync(t,JSON.stringify(e,null,2)),Pt(t),d.renameSync(t,R)}catch(n){try{d.unlinkSync(t)}catch{}throw n}}function Ft(e,t){if(!d.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=d.readdirSync(e).filter(c=>{let a=c.toLowerCase();if(a.includes(".backup")||a===".schema-version"||a.endsWith(".tmp"))return!1;try{return d.statSync(k.join(e,c)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let c of o){let a=k.join(e,c),m=k.join(e,c+n);if(d.existsSync(m)){s++;continue}try{Bt(a,m),r++}catch(l){i.push({file:c,err:l.message})}}if(i.length>0){let c=new Error(`Failed to back up ${i.length} file(s) in ${k.basename(e)}/: `+i.map(a=>`${a.file} (${a.err})`).join(", "));throw c.code="BACKUP_INCOMPLETE",c}if(r>0||s>0){let c=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${k.basename(e)}/ (${n})${c}`)}}var Pe=!1;async function qt(){if(Pe)return;Mt(),_o();let t=Lt().version;if(t===J){Pe=!0;return}So(),bo(),process.on("exit",Be),t>J&&(console.error(`
246
271
  [FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${J}.`),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.
247
272
  `),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${J}.
248
273
  `),process.exit(1)),console.log(`
@@ -250,17 +275,17 @@ ${o.join(`
250
275
  [FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
251
276
  Migration ABORTED. No backups taken, no files modified.`),console.error(" Repair the file(s) above (restore from your own backup, or fix manually)"),console.error(` and try again. To inspect: 'ilml linkedin migrate-status'.
252
277
  `),process.exit(1)}let o=U.filter(r=>r.version>t);for(let r of o){console.log(`
253
- Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{Lt(Q,r.version),Lt(Z,r.version)}catch(a){console.error(`
278
+ Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{Ft(Q,r.version),Ft(Z,r.version)}catch(a){console.error(`
254
279
  [FATAL] Pre-migration backup failed for ${s}: ${a.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
255
280
  `),process.exit(1)}let c=r.module;try{await c.up(Q,Z)}catch(a){console.error(`
256
281
  [FATAL] Migration ${s} failed: ${a.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let m=To(i);m.ok?(console.error(` \u2713 Auto-rollback restored ${m.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
257
282
  `)):(console.error(` [!] Auto-rollback INCOMPLETE: ${m.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
258
283
  `))}catch(m){console.error(` [!] Auto-rollback CRASHED while restoring: ${m.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
259
- `)}process.exit(1)}try{let a=new Date().toISOString(),m={version:r.version,name:c.NAME||s,appliedAt:a},l=Ft();l.version=r.version,l.migratedAt=a,l.migrations=l.migrations||[],l.migrations.push(m),Co(l)}catch(a){console.error(`
284
+ `)}process.exit(1)}try{let a=new Date().toISOString(),m={version:r.version,name:c.NAME||s,appliedAt:a},l=Lt();l.version=r.version,l.migratedAt=a,l.migrations=l.migrations||[],l.migrations.push(m),Co(l)}catch(a){console.error(`
260
285
  [FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${a.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.
261
286
  `),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{ut()}catch{}try{bt()}catch{}Pe=!0,Be(),console.log(`
262
287
  \u2713 Schema is now at v${J}
263
- `)}var xo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function $o(e){let t=e.toLowerCase();return xo.some(n=>n.test(t))}var Ao=6e4;function Eo(){let e=Date.now(),t=[];for(let n of[P,Q,Z]){if(!d.existsSync(n))continue;let o;try{o=d.readdirSync(n)}catch{continue}for(let r of o){if(!$o(r))continue;let s=k.join(n,r);try{let i=d.statSync(s);if(!i.isFile()||e-i.mtimeMs<Ao)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function _o({verbose:e=!1}={}){let t=Eo();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{d.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 Io(){let e=[];for(let t of[Q,Z]){if(!d.existsSync(t))continue;let n=d.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{be(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 To(e){let t=[],n=[];for(let s of[Q,Z]){if(!d.existsSync(s))continue;let i=d.readdirSync(s).filter(c=>c.endsWith(e));for(let c of i){let a=k.join(s,c),m=c.slice(0,-e.length),l=k.join(s,m);try{m.toLowerCase().endsWith(".json")?be(a):d.accessSync(a,d.constants.R_OK),t.push({backupPath:a,originalPath:l,fileName:c,dir:s})}catch(y){n.push(`${k.basename(s)}/${c}: ${y.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:c,dir:a}of t)try{Bt(s,i),o++}catch(m){r.push(`${k.basename(a)}/${c}: ${m.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Bt(e,t){let n=t+".tmp";try{d.copyFileSync(e,n),Pt(n)}catch(o){try{d.unlinkSync(n)}catch{}throw o}try{d.renameSync(n,t)}catch(o){try{d.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 qt();var fe=process.argv.slice(2),Se=fe.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",Ue=parseInt(fe.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),X=parseInt(fe.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),Do=fe.includes("--list"),Ro=fe.includes("--verbose");function jo(){let e=kt();console.log(`
288
+ `)}var xo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function $o(e){let t=e.toLowerCase();return xo.some(n=>n.test(t))}var Eo=6e4;function Ao(){let e=Date.now(),t=[];for(let n of[P,Q,Z]){if(!d.existsSync(n))continue;let o;try{o=d.readdirSync(n)}catch{continue}for(let r of o){if(!$o(r))continue;let s=k.join(n,r);try{let i=d.statSync(s);if(!i.isFile()||e-i.mtimeMs<Eo)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function _o({verbose:e=!1}={}){let t=Ao();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{d.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 Io(){let e=[];for(let t of[Q,Z]){if(!d.existsSync(t))continue;let n=d.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{be(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 To(e){let t=[],n=[];for(let s of[Q,Z]){if(!d.existsSync(s))continue;let i=d.readdirSync(s).filter(c=>c.endsWith(e));for(let c of i){let a=k.join(s,c),m=c.slice(0,-e.length),l=k.join(s,m);try{m.toLowerCase().endsWith(".json")?be(a):d.accessSync(a,d.constants.R_OK),t.push({backupPath:a,originalPath:l,fileName:c,dir:s})}catch(y){n.push(`${k.basename(s)}/${c}: ${y.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:c,dir:a}of t)try{Bt(s,i),o++}catch(m){r.push(`${k.basename(a)}/${c}: ${m.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Bt(e,t){let n=t+".tmp";try{d.copyFileSync(e,n),Pt(n)}catch(o){try{d.unlinkSync(n)}catch{}throw o}try{d.renameSync(n,t)}catch(o){try{d.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 qt();var fe=process.argv.slice(2),Se=fe.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",Ue=parseInt(fe.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),X=parseInt(fe.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),Do=fe.includes("--list"),Ro=fe.includes("--verbose");function jo(){let e=kt();console.log(`
264
289
  \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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=Ie();if(console.log(` Unconnected recruiters: ${t.length}`),X>0){let n=Te(X);console.log(` Revisit (>${X}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
265
290
  `)}async function Oo(){if(console.log(`
266
291
  LinkedIn Profile Visitor
package/dist/warmScan.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import"dotenv/config";import*as l from"fs";import*as s from"path";import{fileURLToPath as A}from"url";var g=s.dirname(A(import.meta.url)),y=process.env.DATA_DIR?s.resolve(process.env.DATA_DIR,"collected-profiles"):s.join(g,"collected-profiles"),a={};for(let n of process.argv.slice(2)){let e=n.match(/^--([^=]+)(?:=(.*))?$/);e&&(a[e[1]]=e[2]??!0)}var h=a.group||"apiLeaders",d=a["min-seniority"]||null,v=!!a["show-all"],S=[process.env.DATA_DIR&&s.resolve(process.env.DATA_DIR,"target-companies.json"),s.join(g,"target-companies.json"),s.resolve(g,"..","target-companies.json")].filter(Boolean),C=S.find(n=>l.existsSync(n));C||(console.error(`target-companies.json not found. Tried:
2
- `+S.join(`
3
- `)),console.error("Set DATA_DIR and place your own target-companies.json there, or reinstall the plugin to restore the shipped default."),process.exit(1));var j=JSON.parse(l.readFileSync(C,"utf8")),u=a.companies?String(a.companies).split(",").map(n=>n.trim()).filter(Boolean):j[h]?.companies;u||(console.error(`Unknown group: ${h}. Available: ${Object.keys(j).join(", ")}`),process.exit(1));var R=JSON.parse(l.readFileSync(s.join(y,"people.json"),"utf8")),b=JSON.parse(l.readFileSync(s.join(y,"conversations.json"),"utf8")),m=new Map;for(let[n,e]of Object.entries(b))typeof e.isConnection=="boolean"&&m.set(n,{isConnection:e.isConnection,conv:e});function k(n){if(n.name&&m.has(n.name)){let e=m.get(n.name);return{is:e.isConnection,src:"A.convInbox",conv:e.conv}}return n.connectionDegree==="1st"?{is:!0,src:"B.profileScrape"}:n.connectionDegree==="2nd"||n.connectionDegree==="3rd"?{is:!1,src:"B.profileScrape"}:n.connectionStatus==="connected"?{is:!0,src:"C.botStatus"}:["sent_without_note","sent_with_note","withdrawn","rejected"].includes(n.connectionStatus)?{is:!1,src:"C.botStatus"}:{is:null,src:null}}var $={intern:0,junior:1,mid:2,senior:3,lead:4,staff:4,principal:5,director:5,vp:6};function O(n,e){if(!e)return!0;if(!n)return!1;let r=n.toLowerCase(),i=$[e.toLowerCase()];if(i==null)return!0;for(let[o,t]of Object.entries($))if(r.includes(o)&&t>=i)return!0;return!1}function T(n,e){return[n.company,n.title,e?.personContext?.title,e?.personContext?.company].filter(Boolean).join(" | ").toLowerCase()}function x(n){let e=n.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${e}\\b`,"i")}var B=u.map(n=>({name:n,re:x(n)})),p={};for(let n of u)p[n]={connected:[],notConnected:[],unknown:[]};for(let[n,e]of Object.entries(R)){let r=e.name?b[e.name]:null,i=T(e,r);if(i)for(let{name:o,re:t}of B){if(!t.test(i))continue;if(!O(e.title||r?.personContext?.title,d))break;let c=k(e),f={name:e.name||n.slice(-40),title:e.title||r?.personContext?.title||"",company:e.company,degree:e.connectionDegree,via:c.src,convStatus:c.conv?.conversationStatus,lastMsg:c.conv?.lastMessageTime,lastBy:c.conv?.lastMessageBy,category:c.conv?.category||e.category};c.is===!0?p[o].connected.push(f):c.is===!1?p[o].notConnected.push(f):p[o].unknown.push(f);break}}var _=d?` (min-seniority=${d})`:"";console.log(`
4
- \u2550\u2550 Warm-scan: ${h}${_} \u2014 ${u.length} target companies \u2550\u2550
5
- `);var I=Object.entries(p).sort((n,e)=>e[1].connected.length-n[1].connected.length),w=0;for(let[n,e]of I){let r=e.connected.length+e.notConnected.length+e.unknown.length;w+=e.connected.length;let i=`${n.padEnd(18)} connected: ${e.connected.length}, other: ${e.notConnected.length+e.unknown.length}, total seen: ${r}`;if(console.log(i),e.connected.length>0)for(let t of e.connected){let c=(t.title||"").slice(0,55),f=t.convStatus?` [${t.convStatus}]`:"",D=t.lastMsg?` (${t.lastMsg.slice(0,10)})`:"";console.log(` \xB7 ${t.name.padEnd(28)} ${c}${f}${D}`)}let o=[...e.notConnected,...e.unknown];if(o.length>0&&(v||o.length<=5)){console.log(" seen but not 1st-degree:");for(let t of o.slice(0,v?o.length:5))console.log(` ${t.name.padEnd(28)} ${(t.title||"").slice(0,55)}`)}else o.length>5&&console.log(` seen but not 1st-degree: ${o.length} \u2014 add --show-all or --companies="${n}" to expand`);console.log("")}console.log(`Total 1st-degree at target companies: ${w}`);
1
+ import"dotenv/config";import*as j from"fs";import*as a from"path";import{fileURLToPath as N}from"url";import{getPluginConfig as T}from"@ilivemylife/graph-sdk";var _=await T();for(let[e,n]of Object.entries(_))process.env[e]===void 0&&(process.env[e]=n);var z=process.env.LINKEDIN_NAME,p=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Y=Object.freeze(new Set([p.DRAFT,p.CONFIRMED,p.NEEDS_REVIEW])),G=Object.freeze(new Set([p.DRAFT,p.CONFIRMED,p.REJECTED,p.NEEDS_REVIEW]));import"dotenv/config";import*as s from"fs";import*as t from"path";import{fileURLToPath as k}from"url";var F=k(import.meta.url),R=t.dirname(t.dirname(F)),f=process.env.DATA_DIR?t.resolve(process.env.DATA_DIR,"collected-profiles"):t.join(R,"collected-profiles"),ee=t.join(f,"people.json"),ne=t.join(f,"jobs.json"),te=t.join(f,"quota.json"),oe=t.join(f,"conversations.json"),se=t.join(f,"sync-state.json"),re=t.join(f,"application-questions.json"),ie=t.join(f,"profile-history");function b(e,n){if(!s.existsSync(e))return null;try{let c=JSON.parse(s.readFileSync(e,"utf-8"));try{s.copyFileSync(e,e+".backup")}catch{}return c}catch(c){console.error(`[!] ${n} is corrupted: ${c.message}`),console.error(` File: ${t.resolve(e)}`);let i=e+".backup";if(s.existsSync(i))try{let o=JSON.parse(s.readFileSync(i,"utf-8"));console.error(` Restored from ${i}`);try{s.copyFileSync(i,e)}catch{}return o}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{s.copyFileSync(e,e+".corrupted")}catch{}return null}}var L=a.dirname(N(import.meta.url)),I=process.env.DATA_DIR?a.resolve(process.env.DATA_DIR,"collected-profiles"):a.join(L,"collected-profiles"),g={};for(let e of process.argv.slice(2)){let n=e.match(/^--([^=]+)(?:=(.*))?$/);n&&(g[n[1]]=n[2]??!0)}var d=g.group||null,C=typeof g["min-seniority"]=="string"?g["min-seniority"]:null,D=!!g["show-all"],u={},h=process.env.DATA_DIR&&a.resolve(process.env.DATA_DIR,"target-companies.json");if(h&&j.existsSync(h))try{u=JSON.parse(j.readFileSync(h,"utf8"))}catch(e){console.error(`Ignoring malformed ${h}: ${e.message}`)}(!u||typeof u!="object"||Array.isArray(u))&&(u={});var A=typeof g.companies=="string"?g.companies.split(","):d?u[d]?.companies:null,y=Array.isArray(A)?A.filter(e=>typeof e=="string"&&e.trim()).map(e=>e.trim()):null;if(!y||!y.length){console.error("Specify which companies to scan:"),console.error(' --companies="Google,Meta,Stripe"');let e=Object.keys(u);d&&!u[d]&&console.error(` (group "${d}" not found)`),e.length?console.error(` --group=<name> your groups: ${e.join(", ")}`):console.error(` or define named groups in ${h||"<DATA_DIR>/target-companies.json"}`),process.exit(1)}var v=b(a.join(I,"people.json"),"people.json")||{},E=b(a.join(I,"conversations.json"),"conversations.json")||{};Object.keys(v).length||(console.error("No contacts found yet \u2014 run `ilml linkedin sync` first to build your network, then warm-scan."),process.exit(1));var w=new Map;for(let[e,n]of Object.entries(E))typeof n.isConnection=="boolean"&&w.set(e,{isConnection:n.isConnection,conv:n});function M(e){if(e.name&&w.has(e.name)){let n=w.get(e.name);return{is:n.isConnection,src:"A.convInbox",conv:n.conv}}return e.connectionDegree==="1st"?{is:!0,src:"B.profileScrape"}:e.connectionDegree==="2nd"||e.connectionDegree==="3rd"?{is:!1,src:"B.profileScrape"}:e.connectionStatus==="connected"?{is:!0,src:"C.botStatus"}:["sent_without_note","sent_with_note","withdrawn","rejected"].includes(e.connectionStatus)?{is:!1,src:"C.botStatus"}:{is:null,src:null}}var O={intern:0,junior:1,mid:2,senior:3,lead:4,staff:4,principal:5,director:5,vp:6};function P(e,n){if(!n)return!0;if(!e)return!1;let c=e.toLowerCase(),i=O[n.toLowerCase()];if(i==null)return!0;for(let[o,r]of Object.entries(O))if(c.includes(o)&&r>=i)return!0;return!1}function J(e,n){return[e.company,e.title,n?.personContext?.title,n?.personContext?.company].filter(Boolean).join(" | ").toLowerCase()}function B(e){let n=e.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${n}\\b`,"i")}var U=y.map(e=>({name:e,re:B(e)})),S={};for(let e of y)S[e]={connected:[],notConnected:[],unknown:[]};for(let[e,n]of Object.entries(v)){let c=n.name?E[n.name]:null,i=J(n,c);if(i)for(let{name:o,re:r}of U){if(!r.test(i))continue;if(!P(n.title||c?.personContext?.title,C))break;let l=M(n),m={name:n.name||e.slice(-40),title:n.title||c?.personContext?.title||"",company:n.company,degree:n.connectionDegree,via:l.src,convStatus:l.conv?.conversationStatus,lastMsg:l.conv?.lastMessageTime,lastBy:l.conv?.lastMessageBy,category:l.conv?.category||n.category};l.is===!0?S[o].connected.push(m):l.is===!1?S[o].notConnected.push(m):S[o].unknown.push(m);break}}var q=C?` (min-seniority=${C})`:"",V=d?`group "${d}"`:`${y.length} target companies`;console.log(`
2
+ \u2550\u2550 Warm-scan: ${V}${q} \u2550\u2550
3
+ `);var Q=Object.entries(S).sort((e,n)=>n[1].connected.length-e[1].connected.length),$=0;for(let[e,n]of Q){let c=n.connected.length+n.notConnected.length+n.unknown.length;$+=n.connected.length;let i=`${e.padEnd(18)} connected: ${n.connected.length}, other: ${n.notConnected.length+n.unknown.length}, total seen: ${c}`;if(console.log(i),n.connected.length>0)for(let r of n.connected){let l=(r.title||"").slice(0,55),m=r.convStatus?` [${r.convStatus}]`:"",x=r.lastMsg?` (${r.lastMsg.slice(0,10)})`:"";console.log(` \xB7 ${r.name.padEnd(28)} ${l}${m}${x}`)}let o=[...n.notConnected,...n.unknown];if(o.length>0&&(D||o.length<=5)){console.log(" seen but not 1st-degree:");for(let r of o.slice(0,D?o.length:5))console.log(` ${r.name.padEnd(28)} ${(r.title||"").slice(0,55)}`)}else o.length>5&&console.log(` seen but not 1st-degree: ${o.length} \u2014 add --show-all or --companies="${e}" to expand`);console.log("")}console.log(`Total 1st-degree at target companies: ${$}`);
package/ilml-plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkedin",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
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." },
@@ -36,6 +36,37 @@
36
36
  "today": { "run": "node dist/syncAll.mjs --today", "description": "No-browser daily action plan from already-synced data: who to reply to, what to do, prioritised by category and last activity.", "usage": "ilml linkedin today", "useWhen": "First thing each morning — what should I touch today?" },
37
37
  "enrich": { "run": "node dist/syncAll.mjs --enrich", "description": "Re-classify every saved conversation (recruiter / HM / founder / coach / etc.) and rebuild summaries, priorities, suggested actions. Offline, no browser. Idempotent.", "usage": "ilml linkedin enrich", "useWhen": "After upgrading the plugin and enrichment rules changed, or to refresh stale auto-tags." },
38
38
  "report": { "run": "node dist/syncAll.mjs --report", "description": "Print the summary of the latest sync session and current inbox stats. No browser, no writes.", "usage": "ilml linkedin report", "useWhen": "Quick health check on the local DB and recent sync results." },
39
+ "version": { "run": "node dist/version.mjs", "description": "Print the installed plugin version. Use this to confirm an update actually landed.", "usage": "ilml linkedin version" },
40
+ "quota": {
41
+ "run": "node dist/quota.mjs",
42
+ "description": "Connection-quota monitor and acceptance analytics. No browser. Shows how much of today's/this week's connection quota is left and how it was spent (by source), joins the send log with your contacts to show acceptance rate per source (which outreach actually converts), and lists high-value people (founder / investor / hiring_manager / peer) you haven't connected to yet.",
43
+ "usage": "ilml linkedin quota [--json]",
44
+ "flags": {
45
+ "--json": "Machine-readable JSON instead of the formatted report."
46
+ },
47
+ "banRisk": "None. Reads local data only, no browser.",
48
+ "useWhen": "You want to see if your daily connection quota is being used, and whether the people you connect with actually accept — before deciding who to target next."
49
+ },
50
+ "connect": {
51
+ "run": "node dist/connect.mjs",
52
+ "description": "Connect queue: a reviewable, prioritised list of people to send connection requests to. Drop a list of profiles, review and approve them, choose who gets a personal note (LinkedIn limits those), then send the approved ones in one browser session under the daily/weekly quota. The queue is one file with a status on each entry (queued → approved → sent) — approving, reordering and sending all update it in place. Rich profile data stays in your contacts DB; the queue just references people by URL.",
53
+ "usage": "ilml linkedin connect <add|fill|list|approve|note|no-note|skip|priority|run> [...]",
54
+ "flags": {
55
+ "add <file.json>": "Add profiles from a JSON array [{url, note?, name?}] to the queue. Dedupes against the queue and skips people already connected/pending. Combine with --tag=X and --priority=high|normal|low.",
56
+ "fill --category=...": "Fill the queue from people already categorised in your contacts DB (not yet connected). e.g. --category=founder,investor,hiring_manager (or --valuable for the standard high-value set). Each entry is tagged with its category so `quota` shows acceptance per category. --min-posts=N keeps only people who appeared in at least N of your job posts (the repeat-recruiter signal, useful with --category=recruiter). --max=N keeps the best N (ranked by priority, mutual connections, repeat count). Respects your excluded-locations setting. No browser.",
57
+ "list": "Show the queue (status, priority, note flag, name/title joined from your contacts). No browser. Optional --status=queued|approved|sent|skipped|failed.",
58
+ "approve <url>": "Move an entry from queued to approved. Or approve a whole batch with --all or --tag=X. Only approved entries are sent.",
59
+ "note <url> \"text\"": "Attach a personal note to an entry (it will send WITH a note). LinkedIn caps notes at 300 characters and limits how many you can send — allocate deliberately.",
60
+ "no-note <url>": "Remove the note from an entry (sends without a note, frees your note budget).",
61
+ "skip <url>": "Drop an entry from sending (queued/approved → skipped).",
62
+ "priority <url> <lvl>": "Set priority high|normal|low. Higher priority is sent first.",
63
+ "run": "Send approved entries, highest priority first, under the daily/weekly quota (browser). --max=N caps this run, --dry-run previews without sending, --yes skips the confirmation prompt (for schedulers).",
64
+ "--tag=X": "Label a batch (used by add/approve). Shows up as the source in `ilml linkedin quota` acceptance stats.",
65
+ "--priority=LEVEL": "high|normal|low (used by add)."
66
+ },
67
+ "banRisk": "Medium for `run` (sends real connection requests, browser) — but every send goes through the same daily/weekly quota gate as the funnel, so you can't exceed the limit. All other subcommands are local, no browser, no risk.",
68
+ "useWhen": "You have a curated list of people worth connecting to (investors from a post, event speakers, company leaders) and want to review, prioritise, and send requests under quota instead of blindly connecting recruiters."
69
+ },
39
70
  "scout": {
40
71
  "run": "node dist/scout.mjs",
41
72
  "description": "Scan jobs from LINKEDIN_SCOUT_URLS (multiple search URLs supported), score them, and save to market-research/ — WITHOUT applying. Builds a ranked queue for apply-queue to consume.",
@@ -120,8 +151,10 @@
120
151
  "description": "Find your 1st-degree connections at target companies. Offline read of people.json. Use to identify mutual paths into a company before cold outreach.",
121
152
  "usage": "ilml linkedin warm-scan [--companies=\"X,Y,Z\"] [--group=<named-group>]",
122
153
  "flags": {
123
- "--companies=\"X,Y,Z\"": "Comma-separated company-name filter.",
124
- "--group=<name>": "Use a named group from your config (e.g., 'frontier-ai-labs')."
154
+ "--companies=\"X,Y,Z\"": "The companies to scan for (comma-separated). Primary input — no file needed.",
155
+ "--group=<name>": "Use a named group from your own <DATA_DIR>/target-companies.json.",
156
+ "--min-seniority=<lvl>": "Only show titles at or above this level (intern|junior|mid|senior|lead|staff|principal|director|vp).",
157
+ "--show-all": "Expand the 'seen but not 1st-degree' lists."
125
158
  },
126
159
  "banRisk": "None — offline.",
127
160
  "useWhen": "Before drafting an outreach to a company — see who you already know there."
@@ -259,6 +292,7 @@
259
292
  {
260
293
  "title": "Recruiter funnel (optional)",
261
294
  "fields": [
295
+ { "key": "FUNNEL_CONNECT_RECRUITERS", "label": "Auto-connect recruiters found while applying", "type": "boolean", "required": false, "default": false, "hint": "Off by default. Cold recruiters who post job listings rarely convert and dilute your feed relevance. Turn on only if you want apply to also send recruiter connection requests." },
262
296
  { "key": "FUNNEL_USE_CUSTOM_MESSAGE", "label": "Send custom message with connection requests", "type": "boolean", "required": false, "default": false },
263
297
  { "key": "FUNNEL_MAX_CONNECTIONS", "label": "Max connection requests per run", "type": "number", "required": false, "default": 20 },
264
298
  { "key": "FUNNEL_MESSAGE", "label": "Connection request message", "type": "text", "required": false, "hint": "Use {name} placeholder, e.g., 'Hi {name}, I just applied for a role at your company'" },
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "ilml-plugin-linkedin",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
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": [
7
7
  "dist",
8
8
  "ilml-plugin.json",
9
- "target-companies.json",
10
9
  "CHANGELOG.md"
11
10
  ],
12
11
  "scripts": {
@@ -56,7 +55,9 @@
56
55
  "warm-scan": "node warmScan.mjs",
57
56
  "enrich": "node syncAll.mjs --enrich",
58
57
  "today": "node syncAll.mjs --today",
59
- "fix-unknown": "node fix-unknown-senders.mjs",
58
+ "quota": "node quota.mjs",
59
+ "connect": "node connect.mjs",
60
+ "plugin-version": "node version.mjs",
60
61
  "migrate:status": "node migrationCli.mjs status",
61
62
  "rollback:data": "node migrationCli.mjs rollback-data",
62
63
  "data:cleanup": "node migrationCli.mjs data-cleanup",
@@ -1,58 +0,0 @@
1
- {
2
- "apiLeaders": {
3
- "description": "API/AI industry leaders (original focus). Substring match, word-boundary.",
4
- "companies": [
5
- "Anthropic",
6
- "OpenAI",
7
- "Stripe",
8
- "Plaid",
9
- "Twilio",
10
- "Mastercard",
11
- "Visa",
12
- "Square",
13
- "Block",
14
- "Ramp",
15
- "Retool",
16
- "Linear",
17
- "Cohere",
18
- "Hugging Face",
19
- "Scale AI"
20
- ]
21
- },
22
- "topPaying": {
23
- "description": "FAANG + tier-1 tech + top AI + high-comp fintech/SaaS — senior engineer total comp typically $300K+. Broader target when user isn't picky about domain, only about pay.",
24
- "companies": [
25
- "Meta",
26
- "Google",
27
- "Amazon",
28
- "Apple",
29
- "Netflix",
30
- "Microsoft",
31
- "Uber",
32
- "Airbnb",
33
- "LinkedIn",
34
- "Pinterest",
35
- "Anthropic",
36
- "OpenAI",
37
- "Cohere",
38
- "Databricks",
39
- "Snowflake",
40
- "Hugging Face",
41
- "Scale AI",
42
- "Stripe",
43
- "Plaid",
44
- "Mastercard",
45
- "Visa",
46
- "Square",
47
- "Block",
48
- "Ramp",
49
- "Datadog",
50
- "MongoDB",
51
- "Figma",
52
- "Notion",
53
- "HashiCorp",
54
- "Retool",
55
- "Linear"
56
- ]
57
- }
58
- }