ilml-plugin-linkedin 1.19.2 → 1.20.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/daily.mjs CHANGED
@@ -1,53 +1,53 @@
1
- var Le=Object.defineProperty;var q=(e,n)=>{for(var t in n)Le(e,t,{get:n[t],enumerable:!0})};import{execFileSync as nn}from"child_process";import"dotenv/config";import*as S from"fs";import*as R from"path";import{fileURLToPath as qe}from"url";import"dotenv/config";import{createGraphClient as Me,resolveToken as Pe}from"@ilivemylife/graph-sdk";import{config as Je}from"dotenv";Je();var re=Pe()||process.env.TOKEN;re||(console.error(`
1
+ var Le=Object.defineProperty;var q=(e,n)=>{for(var t in n)Le(e,t,{get:n[t],enumerable:!0})};import{execFileSync as nn}from"child_process";import"dotenv/config";import*as S from"fs";import*as R from"path";import{fileURLToPath as qe}from"url";import"dotenv/config";import{createGraphClient as Me,resolveToken as Pe}from"@ilivemylife/graph-sdk";import{config as Ue}from"dotenv";Ue();var se=Pe()||process.env.TOKEN;se||(console.error(`
2
2
  [FATAL] No iLiveMyLife token found.`),console.error(" The bot uses Lifebot AI to decide which jobs to apply for"),console.error(` and how to fill application forms. It cannot work without it.
3
3
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
4
4
  `),console.error(` Or add ILML_TOKEN=... to .env
5
- `),process.exit(1));var ie=Me({token:re});function Ue(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let t=Math.floor(n/60),o=n%60;return o?`${t}m ${o}s`:`${t}m`}function Be({scriptName:e,mode:n,status:t,error:o,duration:s}){let r=t==="error"?"\u2717":t==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),a=s?` ${Ue(s)}`:"",l=t==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:t==="quota-reached"?"daily quota reached":"done",u=n&&n!=="default"?` (${n})`:"";return`${r} ${e}${u} \u2014 ${l} \u2014 ${i}${a}`}async function ce({scriptName:e,mode:n,status:t,summaryLines:o,error:s,duration:r}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let l=`**${Be({scriptName:e,mode:n,status:t,error:s,duration:r})}**
5
+ `),process.exit(1));var ie=Me({token:se});function Je(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let t=Math.floor(n/60),o=n%60;return o?`${t}m ${o}s`:`${t}m`}function Be({scriptName:e,mode:n,status:t,error:o,duration:r}){let s=t==="error"?"\u2717":t==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),a=r?` ${Je(r)}`:"",c=t==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:t==="quota-reached"?"daily quota reached":"done",u=n&&n!=="default"?` (${n})`:"";return`${s} ${e}${u} \u2014 ${c} \u2014 ${i}${a}`}async function le({scriptName:e,mode:n,status:t,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let c=`**${Be({scriptName:e,mode:n,status:t,error:r,duration:s})}**
6
6
 
7
7
  ${o.join(`
8
- `)}`;try{await ie.addMessage(i,l)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Ve=qe(import.meta.url),We=R.dirname(R.dirname(Ve)),Y=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"collected-profiles"):R.join(We,"collected-profiles"),G=R.join(Y,"run-log.json");function Ye(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";S.writeFileSync(o,t);for(let s=0;s<3;s++)try{S.renameSync(o,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw r}}function le(){try{if(!S.existsSync(G))return{runs:[]};let e=JSON.parse(S.readFileSync(G,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ae(e){S.existsSync(Y)||S.mkdirSync(Y,{recursive:!0});try{Ye(G,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function ue(e,n="default"){let t=le();for(let i of t.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,s={timestamp:o.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};t.runs.push(s);let r=Date.now()-30*24*60*60*1e3;return t.runs=t.runs.filter(i=>new Date(i.timestamp).getTime()>r),ae(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function fe(e,n,t=null,o=null){if(!e)return;let s=null;try{let i=le(),a=i.runs[e.runIndex];if(a&&a.status==="running"&&a.script===e.script)a.status=n,a.result=n,a.duration=Date.now()-e.startTime,a.stats=t,a.error=o,s=a.duration;else{let l=i.runs.find(u=>u.script===e.script&&u.status==="running"&&u.timestamp===new Date(e.startTime).toISOString());l&&(l.status=n,l.result=n,l.duration=Date.now()-e.startTime,l.stats=t,l.error=o,s=l.duration)}ae(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let r=t&&Array.isArray(t.summaryLines)?t.summaryLines:null;if(r&&r.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":t&&t.dailyLimitHit?"quota-reached":"done";ce({scriptName:e.script,mode:e.mode,status:i,summaryLines:r,error:o,duration:s??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}import{getPluginConfig as Ge}from"@ilivemylife/graph-sdk";var He=await Ge();for(let[e,n]of Object.entries(He))process.env[e]===void 0&&(process.env[e]=n);var yn=process.env.LINKEDIN_NAME,C=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Sn=Object.freeze(new Set([C.DRAFT,C.CONFIRMED,C.NEEDS_REVIEW])),bn=Object.freeze(new Set([C.DRAFT,C.CONFIRMED,C.REJECTED,C.NEEDS_REVIEW]));import"dotenv/config";import*as d from"fs";import*as m from"path";import{fileURLToPath as Ke}from"url";var Qe=Ke(import.meta.url),ze=m.dirname(m.dirname(Qe)),E=process.env.DATA_DIR?m.resolve(process.env.DATA_DIR,"collected-profiles"):m.join(ze,"collected-profiles"),An=m.join(E,"people.json"),jn=m.join(E,"jobs.json"),Xe=m.join(E,"quota.json"),En=m.join(E,"conversations.json"),On=m.join(E,"sync-state.json"),In=m.join(E,"application-questions.json"),Rn=m.join(E,"profile-history"),pe=(e,n)=>{let t=parseInt(e,10);return Number.isInteger(t)&&t>=0?t:n},P=pe(process.env.CONNECT_MAX_DAILY,20),J=pe(process.env.CONNECT_MAX_WEEKLY,100),Ze=null,eo=null,T=null,oo=null,no=null,to=null;function de(){Ze=null,eo=null,T=null,oo=null,no=null,to=null}function so(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function ro(e,n){if(!d.existsSync(e))return null;try{let t=JSON.parse(d.readFileSync(e,"utf-8"));try{d.copyFileSync(e,e+".backup")}catch{}return t}catch(t){console.error(`[!] ${n} is corrupted: ${t.message}`),console.error(` File: ${m.resolve(e)}`);let o=e+".backup";if(d.existsSync(o))try{let s=JSON.parse(d.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{d.copyFileSync(o,e)}catch{}return s}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{d.copyFileSync(e,e+".corrupted")}catch{}return null}}function me(){return new Date().toISOString().split("T")[0]}function io(){return T||(so(),T=ro(Xe,"quota.json"),(!T||!T.connections)&&(T={connections:[]}),T)}function he(){let e=io(),n=new Date;n.setDate(n.getDate()-7);let t=n.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=t)}function ge(){let e=he(),n=me(),t=e.filter(l=>l.date===n).length,o=e.length,s=t>=P,r=o>=J,i=!s&&!r,a={allowed:i,daily:{sent:t,max:P},weekly:{sent:o,max:J}};return i||(a.reason=s?`Daily limit reached (${t}/${P})`:`Weekly limit reached (${o}/${J})`),a}function ye(){let e=he(),n=me(),t=e.filter(s=>s.date===n).length,o=e.length;return{daily:{sent:t,max:P,remaining:P-t},weekly:{sent:o,max:J,remaining:J-o}}}import"dotenv/config";import*as c from"fs";import*as oe from"os";import*as f from"path";import{fileURLToPath as Po}from"url";var Q={};q(Q,{NAME:()=>lo,VERSION:()=>co,up:()=>fo});import*as b from"fs";import*as V from"path";var co=1,lo="normalize-jobs-and-questions",ao=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],uo=50;function H(e){return b.existsSync(e)?JSON.parse(b.readFileSync(e,"utf-8")):null}function K(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{b.writeFileSync(o,t)}catch(s){try{b.unlinkSync(o)}catch{}throw s}try{b.renameSync(o,e)}catch(s){try{b.unlinkSync(o)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function fo(e,n){let t=V.join(e,"jobs.json"),o=V.join(n,"scouted-jobs.json"),s=V.join(e,"application-questions.json"),r=H(t)||{},i=H(o)||{},a=0,l=[];for(let p of Object.keys(r)){if(!i[p])continue;let k=i[p],h=r[p];for(let I of ao)k[I]!=null&&h[I]==null&&(h[I]=k[I]);l.push(p),a++}a>0?(K(t,r),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=H(s);if(u&&Array.isArray(u.applications)){let p={},k=0;for(let h of u.applications){let I=h.jobId||"unknown";p[I]||(p[I]={applications:[]});let se=(h.questions||[]).map(A=>{let L={type:A.type||"input",question:A.question||"",answer:A.answer||""};return A.options&&(A.options.length<=uo?L.options=A.options:(L.optionsOmitted=!0,k++)),A.page&&(L.page=A.page),A.wasPreFilled&&(L.wasPreFilled=!0),A.wasRetry&&(L.wasRetry=!0),L});p[I].applications.push({applicationId:h.applicationId,date:h.date,result:h.result||"submitted",formPages:h.formPages||null,duration:h.duration||null,retries:h.retries||0,failedField:h.failedField||null,questionCount:h.questionCount||se.length,questions:se})}K(s,p),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),k>0&&console.log(` Phase 2: Stripped bloated options from ${k} questions`)}else u&&!u.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let p of l)delete i[p];K(o,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var z={};q(z,{NAME:()=>mo,VERSION:()=>po,up:()=>yo});import*as v from"fs";import*as Se from"path";var po=2,mo="reset-unread-flags";function ho(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function go(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{v.writeFileSync(o,t)}catch(s){try{v.unlinkSync(o)}catch{}throw s}try{v.renameSync(o,e)}catch(s){try{v.unlinkSync(o)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function yo(e){let n=Se.join(e,"conversations.json"),t=ho(n);if(!t){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let s of Object.keys(t))t[s].unread===!0&&(t[s].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}go(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var X={};q(X,{NAME:()=>bo,VERSION:()=>So,up:()=>Ao});import*as $ from"fs";import*as be from"path";var So=3,bo="recompute-last-message-by",vo=new Set(["draft","confirmed","rejected","needs_review"]);function $o(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function wo(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{$.writeFileSync(o,t)}catch(s){try{$.unlinkSync(o)}catch{}throw s}try{$.renameSync(o,e)}catch(s){try{$.unlinkSync(o)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}function ko(e,n){if(!e||e.length===0)return"them";let t=e.filter(r=>!vo.has(r.status));if(t.length===0)return"them";let o=t.map(r=>({m:r,t:Date.parse(r.time)})).filter(r=>Number.isFinite(r.t)).sort((r,i)=>i.t-r.t).map(r=>r.m),s=o.length>0?o:[...t].reverse();for(let r of s){let i=r.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function Ao(e){let n=be.join(e,"conversations.json"),t=$o(n);if(!t){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 s=0,r=0,i=0;for(let a of Object.keys(t)){let l=t[a];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,r++);let u=Array.isArray(l.messages)?l.messages:[],p=ko(u,o),k=p==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==p&&i++,l.lastMessageBy=p,l.conversationStatus=k,s++}if(s===0){console.log(" No conversations to recompute.");return}wo(n,t),console.log(` Recomputed lastMessageBy + conversationStatus on ${s} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),r>0&&console.log(` Cleaned ${r} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var Z={};q(Z,{NAME:()=>Eo,VERSION:()=>jo,up:()=>To});import*as w from"fs";import*as ve from"path";var jo=4,Eo="split-connection-timestamps",Oo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Io(e){if(!w.existsSync(e))return null;let n=w.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Ro(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{w.writeFileSync(o,t)}catch(s){try{w.unlinkSync(o)}catch{}throw s}try{w.renameSync(o,e)}catch(s){try{w.unlinkSync(o)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function To(e){let n=ve.join(e,"people.json"),t=Io(n);if(!t||typeof t!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,s=0;for(let r of Object.keys(t)){let i=t[r];!i||typeof i!="object"||(s++,Oo.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,o++))}if(o===0){console.log(` Scanned ${s} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Ro(n,t),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${s} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as y from"path";import{fileURLToPath as Do}from"url";var No=Do(import.meta.url),Co=y.dirname(y.dirname(No)),U=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"market-research"):y.join(Co,"market-research"),Cn=y.join(U,"scouted-jobs.json"),_n=y.join(U,"discovered-people.json"),xn=y.join(U,"visit-log.json"),Fn=y.join(U,"companies.json"),Ln=y.join(U,"job-decisions.json");function $e(){_o=null,xo=null,Fo=null,Lo=null,Mo=null}var _o=null;var xo=null;var Fo=null;var Lo=null;var Mo=null;var Jo=Po(import.meta.url),Uo=f.dirname(Jo),Bo=f.dirname(f.dirname(Uo));function qo(e){return e&&(e==="~"?oe.homedir():e.startsWith("~/")||e.startsWith("~\\")?f.join(oe.homedir(),e.slice(2)):e)}var j=process.env.DATA_DIR?f.resolve(qo(process.env.DATA_DIR)):Bo,x=f.join(j,"collected-profiles"),F=f.join(j,"market-research"),g=f.join(j,".schema-version"),we=[f.join(x,".schema-version"),f.join(F,".schema-version")],D=4,O=[{version:1,module:Q},{version:2,module:z},{version:3,module:X},{version:4,module:Z}];(function(){O.sort((o,s)=>o.version-s.version);let n=new Set;for(let o of O){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(n.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);n.add(o.version);let s=o.module;if(!s||typeof s.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(s.VERSION!==void 0&&s.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${s.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let t=O.length?O[O.length-1].version:0;if(t!==D)throw new Error(`MIGRATION_REGISTRY: highest version v${t} but CURRENT_SCHEMA_VERSION=${D}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<O.length;o++){let s=o+1;if(O[o].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${o} but found v${O[o].version}`)}})();function Ee(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
8
+ `)}`;try{await ie.addMessage(i,c)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Ve=qe(import.meta.url),We=R.dirname(R.dirname(Ve)),Y=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"collected-profiles"):R.join(We,"collected-profiles"),G=R.join(Y,"run-log.json");function Ye(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";S.writeFileSync(o,t);for(let r=0;r<3;r++)try{S.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 ce(){try{if(!S.existsSync(G))return{runs:[]};let e=JSON.parse(S.readFileSync(G,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ae(e){S.existsSync(Y)||S.mkdirSync(Y,{recursive:!0});try{Ye(G,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function ue(e,n="default"){let t=ce();for(let i of t.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:n,status:"running",result:null,duration:null,stats:null,error:null};t.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return t.runs=t.runs.filter(i=>new Date(i.timestamp).getTime()>s),ae(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function fe(e,n,t=null,o=null){if(!e)return;let r=null;try{let i=ce(),a=i.runs[e.runIndex];if(a&&a.status==="running"&&a.script===e.script)a.status=n,a.result=n,a.duration=Date.now()-e.startTime,a.stats=t,a.error=o,r=a.duration;else{let c=i.runs.find(u=>u.script===e.script&&u.status==="running"&&u.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=t,c.error=o,r=c.duration)}ae(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=t&&Array.isArray(t.summaryLines)?t.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":t&&t.dailyLimitHit?"quota-reached":"done";le({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}import{getPluginConfig as Ge}from"@ilivemylife/graph-sdk";var Ke=await Ge();for(let[e,n]of Object.entries(Ke))process.env[e]===void 0&&(process.env[e]=n);var gn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Sn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),bn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as d from"fs";import*as m from"path";import{fileURLToPath as He}from"url";var ze=He(import.meta.url),Qe=m.dirname(m.dirname(ze)),E=process.env.DATA_DIR?m.resolve(process.env.DATA_DIR,"collected-profiles"):m.join(Qe,"collected-profiles"),$n=m.join(E,"people.json"),jn=m.join(E,"jobs.json"),Xe=m.join(E,"quota.json"),En=m.join(E,"conversations.json"),On=m.join(E,"sync-state.json"),In=m.join(E,"application-questions.json"),Rn=m.join(E,"profile-history"),pe=(e,n)=>{let t=parseInt(e,10);return Number.isInteger(t)&&t>=0?t:n},P=pe(process.env.CONNECT_MAX_DAILY,20),U=pe(process.env.CONNECT_MAX_WEEKLY,100),Ze=null,eo=null,D=null,oo=null,no=null,to=null;function de(){Ze=null,eo=null,D=null,oo=null,no=null,to=null}function ro(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function so(e,n){if(!d.existsSync(e))return null;try{let t=JSON.parse(d.readFileSync(e,"utf-8"));try{d.copyFileSync(e,e+".backup")}catch{}return t}catch(t){console.error(`[!] ${n} is corrupted: ${t.message}`),console.error(` File: ${m.resolve(e)}`);let o=e+".backup";if(d.existsSync(o))try{let r=JSON.parse(d.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{d.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{d.copyFileSync(e,e+".corrupted")}catch{}return null}}function me(){return new Date().toISOString().split("T")[0]}function io(){return D||(ro(),D=so(Xe,"quota.json"),(!D||!D.connections)&&(D={connections:[]}),D)}function he(){let e=io(),n=new Date;n.setDate(n.getDate()-7);let t=n.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=t)}function ye(){let e=he(),n=me(),t=e.filter(c=>c.date===n).length,o=e.length,r=t>=P,s=o>=U,i=!r&&!s,a={allowed:i,daily:{sent:t,max:P},weekly:{sent:o,max:U}};return i||(a.reason=r?`Daily limit reached (${t}/${P})`:`Weekly limit reached (${o}/${U})`),a}function ge(){let e=he(),n=me(),t=e.filter(r=>r.date===n).length,o=e.length;return{daily:{sent:t,max:P,remaining:P-t},weekly:{sent:o,max:U,remaining:U-o}}}import"dotenv/config";import*as l from"fs";import*as oe from"os";import*as f from"path";import{fileURLToPath as Po}from"url";var z={};q(z,{NAME:()=>co,VERSION:()=>lo,up:()=>fo});import*as b from"fs";import*as V from"path";var lo=1,co="normalize-jobs-and-questions",ao=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],uo=50;function K(e){return b.existsSync(e)?JSON.parse(b.readFileSync(e,"utf-8")):null}function H(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{b.writeFileSync(o,t)}catch(r){try{b.unlinkSync(o)}catch{}throw r}try{b.renameSync(o,e)}catch(r){try{b.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 fo(e,n){let t=V.join(e,"jobs.json"),o=V.join(n,"scouted-jobs.json"),r=V.join(e,"application-questions.json"),s=K(t)||{},i=K(o)||{},a=0,c=[];for(let p of Object.keys(s)){if(!i[p])continue;let A=i[p],h=s[p];for(let I of ao)A[I]!=null&&h[I]==null&&(h[I]=A[I]);c.push(p),a++}a>0?(H(t,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=K(r);if(u&&Array.isArray(u.applications)){let p={},A=0;for(let h of u.applications){let I=h.jobId||"unknown";p[I]||(p[I]={applications:[]});let re=(h.questions||[]).map($=>{let L={type:$.type||"input",question:$.question||"",answer:$.answer||""};return $.options&&($.options.length<=uo?L.options=$.options:(L.optionsOmitted=!0,A++)),$.page&&(L.page=$.page),$.wasPreFilled&&(L.wasPreFilled=!0),$.wasRetry&&(L.wasRetry=!0),L});p[I].applications.push({applicationId:h.applicationId,date:h.date,result:h.result||"submitted",formPages:h.formPages||null,duration:h.duration||null,retries:h.retries||0,failedField:h.failedField||null,questionCount:h.questionCount||re.length,questions:re})}H(r,p),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),A>0&&console.log(` Phase 2: Stripped bloated options from ${A} questions`)}else u&&!u.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let p of c)delete i[p];H(o,i),console.log(` Phase 3: Removed ${c.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 Q={};q(Q,{NAME:()=>mo,VERSION:()=>po,up:()=>go});import*as w from"fs";import*as Se from"path";var po=2,mo="reset-unread-flags";function ho(e){return w.existsSync(e)?JSON.parse(w.readFileSync(e,"utf-8")):null}function yo(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{w.writeFileSync(o,t)}catch(r){try{w.unlinkSync(o)}catch{}throw r}try{w.renameSync(o,e)}catch(r){try{w.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 go(e){let n=Se.join(e,"conversations.json"),t=ho(n);if(!t){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(t))t[r].unread===!0&&(t[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}yo(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var X={};q(X,{NAME:()=>bo,VERSION:()=>So,up:()=>$o});import*as v from"fs";import*as be from"path";var So=3,bo="recompute-last-message-by",wo=new Set(["draft","confirmed","rejected","needs_review"]);function vo(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function ko(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{v.writeFileSync(o,t)}catch(r){try{v.unlinkSync(o)}catch{}throw r}try{v.renameSync(o,e)}catch(r){try{v.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 Ao(e,n){if(!e||e.length===0)return"them";let t=e.filter(s=>!wo.has(s.status));if(t.length===0)return"them";let o=t.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:[...t].reverse();for(let s of r){let i=s.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function $o(e){let n=be.join(e,"conversations.json"),t=vo(n);if(!t){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let a of Object.keys(t)){let c=t[a];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let u=Array.isArray(c.messages)?c.messages:[],p=Ao(u,o),A=p==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==p&&i++,c.lastMessageBy=p,c.conversationStatus=A,r++}if(r===0){console.log(" No conversations to recompute.");return}ko(n,t),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 Z={};q(Z,{NAME:()=>Eo,VERSION:()=>jo,up:()=>Do});import*as k from"fs";import*as we from"path";var jo=4,Eo="split-connection-timestamps",Oo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Io(e){if(!k.existsSync(e))return null;let n=k.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Ro(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{k.writeFileSync(o,t)}catch(r){try{k.unlinkSync(o)}catch{}throw r}try{k.renameSync(o,e)}catch(r){try{k.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 Do(e){let n=we.join(e,"people.json"),t=Io(n);if(!t||typeof t!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(t)){let i=t[s];!i||typeof i!="object"||(r++,Oo.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,o++))}if(o===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Ro(n,t),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as g from"path";import{fileURLToPath as To}from"url";var Co=To(import.meta.url),No=g.dirname(g.dirname(Co)),J=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"market-research"):g.join(No,"market-research"),Ln=g.join(J,"scouted-jobs.json"),Mn=g.join(J,"discovered-people.json"),Pn=g.join(J,"visit-log.json"),Un=g.join(J,"companies.json"),Jn=g.join(J,"job-decisions.json");function ve(){_o=null,xo=null,Fo=null,Lo=null,Mo=null}var _o=null;var xo=null;var Fo=null;var Lo=null;var Mo=null;var Uo=Po(import.meta.url),Jo=f.dirname(Uo),Bo=f.dirname(f.dirname(Jo));function qo(e){return e&&(e==="~"?oe.homedir():e.startsWith("~/")||e.startsWith("~\\")?f.join(oe.homedir(),e.slice(2)):e)}var j=process.env.DATA_DIR?f.resolve(qo(process.env.DATA_DIR)):Bo,x=f.join(j,"collected-profiles"),F=f.join(j,"market-research"),y=f.join(j,".schema-version"),ke=[f.join(x,".schema-version"),f.join(F,".schema-version")],T=4,O=[{version:1,module:z},{version:2,module:Q},{version:3,module:X},{version:4,module:Z}];(function(){O.sort((o,r)=>o.version-r.version);let n=new Set;for(let o of O){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(n.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);n.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 t=O.length?O[O.length-1].version:0;if(t!==T)throw new Error(`MIGRATION_REGISTRY: highest version v${t} but CURRENT_SCHEMA_VERSION=${T}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<O.length;o++){let r=o+1;if(O[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${O[o].version}`)}})();function Ee(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
9
9
  [FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
10
- `),process.exit(1));try{c.mkdirSync(j,{recursive:!0})}catch(n){n.code!=="EEXIST"&&(console.error(`
10
+ `),process.exit(1));try{l.mkdirSync(j,{recursive:!0})}catch(n){n.code!=="EEXIST"&&(console.error(`
11
11
  [FATAL] Cannot create DATA_DIR (${j}): ${n.message}`),console.error(` Fix the path or permissions and try again.
12
- `),process.exit(1))}let e;try{e=c.statSync(j)}catch(n){console.error(`
12
+ `),process.exit(1))}let e;try{e=l.statSync(j)}catch(n){console.error(`
13
13
  [FATAL] DATA_DIR (${j}) is not accessible: ${n.message}
14
14
  `),process.exit(1)}e.isDirectory()||(console.error(`
15
15
  [FATAL] DATA_DIR (${j}) exists but is NOT a directory.`),console.error(` Looks like a typo \u2014 your DATA_DIR points at a file. Fix the path and try again.
16
- `),process.exit(1));for(let n of[x,F]){let t;try{t=c.lstatSync(n)}catch(o){if(o.code==="ENOENT")continue;throw o}t.isSymbolicLink()&&(console.error(`
16
+ `),process.exit(1));for(let n of[x,F]){let t;try{t=l.lstatSync(n)}catch(o){if(o.code==="ENOENT")continue;throw o}t.isSymbolicLink()&&(console.error(`
17
17
  [FATAL] Data subdirectory is a symbolic link: ${n}`),console.error(" Refusing to follow \u2014 backup code would copy whatever the link points at."),console.error(` If this is intentional, replace the symlink with the real directory.
18
- `),process.exit(1))}}var _=f.join(j,".migration-lock");function Vo(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return c.writeFileSync(_,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let n;try{n=JSON.parse(c.readFileSync(_,"utf-8"))}catch{n=null}if(n&&Number.isInteger(n.pid)){let o=!1;try{process.kill(n.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let s=24*60*60*1e3,r=1/0;if(n.startedAt){let i=Date.parse(n.startedAt);Number.isNaN(i)||(r=Date.now()-i)}o&&r<s&&(console.error(`
18
+ `),process.exit(1))}}var _=f.join(j,".migration-lock");function Vo(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return l.writeFileSync(_,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let n;try{n=JSON.parse(l.readFileSync(_,"utf-8"))}catch{n=null}if(n&&Number.isInteger(n.pid)){let o=!1;try{process.kill(n.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(n.startedAt){let i=Date.parse(n.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
19
19
  [FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${n.pid}`),console.error(` Started at: ${n.startedAt||"(unknown)"}`),console.error(` Lock file: ${_}
20
20
  `),console.error(" Wait for it to finish, or if you're sure it's not actually running,"),console.error(` delete the lock file manually and re-run.
21
- `),process.exit(1)),o&&r>=s&&console.log(` Lock holder PID ${n.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${n?.pid??"?"} found \u2014 taking over.`);let t=_+".tmp";try{return c.writeFileSync(t,e),c.renameSync(t,_),!0}catch(o){try{c.unlinkSync(t)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function ne(){try{if(JSON.parse(c.readFileSync(_,"utf-8")).pid!==process.pid)return;c.unlinkSync(_)}catch{}}var ke=!1;function Wo(){if(ke)return;ke=!0;let e=()=>{try{ne()}catch{}process.exit(1)};for(let n of["SIGINT","SIGTERM","SIGHUP"])try{process.on(n,e)}catch{}}function Yo(){if(c.existsSync(g))return;let e=[],n=[];for(let r of we)if(c.existsSync(r))try{e.push({file:r,schema:W(r)})}catch(i){n.push({file:r,err:i.message})}if(n.length>0){console.error(`
22
- [FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let r of n)console.error(` ${r.file}: ${r.err}`);console.error(`
21
+ `),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${n.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${n?.pid??"?"} found \u2014 taking over.`);let t=_+".tmp";try{return l.writeFileSync(t,e),l.renameSync(t,_),!0}catch(o){try{l.unlinkSync(t)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function ne(){try{if(JSON.parse(l.readFileSync(_,"utf-8")).pid!==process.pid)return;l.unlinkSync(_)}catch{}}var Ae=!1;function Wo(){if(Ae)return;Ae=!0;let e=()=>{try{ne()}catch{}process.exit(1)};for(let n of["SIGINT","SIGTERM","SIGHUP"])try{process.on(n,e)}catch{}}function Yo(){if(l.existsSync(y))return;let e=[],n=[];for(let s of ke)if(l.existsSync(s))try{e.push({file:s,schema:W(s)})}catch(i){n.push({file:s,err:i.message})}if(n.length>0){console.error(`
22
+ [FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of n)console.error(` ${s.file}: ${s.err}`);console.error(`
23
23
  Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
24
- `),process.exit(1)}if(e.length===0)return;let t=e.map(r=>r.schema.version);if(new Set(t).size>1){console.error(`
25
- [FATAL] Legacy .schema-version files disagree:`);for(let r of e)console.error(` ${r.file}: v${r.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
26
- `),process.exit(1)}let o=e[0].schema,s=g+".tmp";try{c.writeFileSync(s,JSON.stringify(o,null,2)),c.renameSync(s,g)}catch(r){try{c.unlinkSync(s)}catch{}throw r}for(let r of we)if(c.existsSync(r))try{c.unlinkSync(r)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${g}`)}function Go(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=Number(e.version);return!Number.isFinite(n)||n<0||!Number.isInteger(n)?null:(e.version=n,Array.isArray(e.migrations)||(e.migrations=[]),e)}function W(e){let n=c.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Ae(){if(Yo(),!c.existsSync(g))return{version:0,migrations:[]};let e;try{e=W(g)}catch(t){if(t.code==="ENOENT")return{version:0,migrations:[]};console.error(`
27
- [FATAL] ${g} is not valid JSON: ${t.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.
24
+ `),process.exit(1)}if(e.length===0)return;let t=e.map(s=>s.schema.version);if(new Set(t).size>1){console.error(`
25
+ [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.
26
+ `),process.exit(1)}let o=e[0].schema,r=y+".tmp";try{l.writeFileSync(r,JSON.stringify(o,null,2)),l.renameSync(r,y)}catch(s){try{l.unlinkSync(r)}catch{}throw s}for(let s of ke)if(l.existsSync(s))try{l.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${y}`)}function Go(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=Number(e.version);return!Number.isFinite(n)||n<0||!Number.isInteger(n)?null:(e.version=n,Array.isArray(e.migrations)||(e.migrations=[]),e)}function W(e){let n=l.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function $e(){if(Yo(),!l.existsSync(y))return{version:0,migrations:[]};let e;try{e=W(y)}catch(t){if(t.code==="ENOENT")return{version:0,migrations:[]};console.error(`
27
+ [FATAL] ${y} is not valid JSON: ${t.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.
28
28
  `),process.exit(1)}let n=Go(e);return n===null&&(console.error(`
29
- [FATAL] ${g} 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.
30
- `),process.exit(1)),n}function Oe(e){try{c.chmodSync(e,384)}catch{}}function Ho(e){if(Ee(),c.existsSync(g))try{if(c.lstatSync(g).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${g}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(t){if(t.message?.includes("symbolic link"))throw t}let n=g+".tmp";try{c.writeFileSync(n,JSON.stringify(e,null,2)),Oe(n),c.renameSync(n,g)}catch(t){try{c.unlinkSync(n)}catch{}throw t}}function je(e,n){if(!c.existsSync(e))return;let t=`.pre-v${String(n).padStart(3,"0")}.backup`,o=c.readdirSync(e).filter(a=>{let l=a.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return c.statSync(f.join(e,a)).isFile()}catch{return!1}}),s=0,r=0,i=[];for(let a of o){let l=f.join(e,a),u=f.join(e,a+t);if(c.existsSync(u)){r++;continue}try{Re(l,u),s++}catch(p){i.push({file:a,err:p.message})}}if(i.length>0){let a=new Error(`Failed to back up ${i.length} file(s) in ${f.basename(e)}/: `+i.map(l=>`${l.file} (${l.err})`).join(", "));throw a.code="BACKUP_INCOMPLETE",a}if(s>0||r>0){let a=r>0?` (${r} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${s} files in ${f.basename(e)}/ (${t})${a}`)}}var ee=!1;async function Ie(){if(ee)return;Ee(),Zo();let n=Ae().version;if(n===D){ee=!0;return}Wo(),Vo(),process.on("exit",ne),n>D&&(console.error(`
31
- [FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${D}.`),console.error(" This usually means you downgraded the plugin without rolling back data."),console.error(` Operating on the newer-format data with this build would risk corrupting it.
32
- `),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${D}.
29
+ [FATAL] ${y} 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.
30
+ `),process.exit(1)),n}function Oe(e){try{l.chmodSync(e,384)}catch{}}function Ko(e){if(Ee(),l.existsSync(y))try{if(l.lstatSync(y).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${y}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(t){if(t.message?.includes("symbolic link"))throw t}let n=y+".tmp";try{l.writeFileSync(n,JSON.stringify(e,null,2)),Oe(n),l.renameSync(n,y)}catch(t){try{l.unlinkSync(n)}catch{}throw t}}function je(e,n){if(!l.existsSync(e))return;let t=`.pre-v${String(n).padStart(3,"0")}.backup`,o=l.readdirSync(e).filter(a=>{let c=a.toLowerCase();if(c.includes(".backup")||c===".schema-version"||c.endsWith(".tmp"))return!1;try{return l.statSync(f.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let a of o){let c=f.join(e,a),u=f.join(e,a+t);if(l.existsSync(u)){s++;continue}try{Re(c,u),r++}catch(p){i.push({file:a,err:p.message})}}if(i.length>0){let a=new Error(`Failed to back up ${i.length} file(s) in ${f.basename(e)}/: `+i.map(c=>`${c.file} (${c.err})`).join(", "));throw a.code="BACKUP_INCOMPLETE",a}if(r>0||s>0){let a=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${f.basename(e)}/ (${t})${a}`)}}var ee=!1;async function Ie(){if(ee)return;Ee(),Zo();let n=$e().version;if(n===T){ee=!0;return}Wo(),Vo(),process.on("exit",ne),n>T&&(console.error(`
31
+ [FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${T}.`),console.error(" This usually means you downgraded the plugin without rolling back data."),console.error(` Operating on the newer-format data with this build would risk corrupting it.
32
+ `),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${T}.
33
33
  `),process.exit(1)),console.log(`
34
- \u{1F4E6} Schema migration: v${n} \u2192 v${D}`);let t=en();if(!t.ok){console.error(`
35
- [FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let s of t.broken)console.error(` ${s.dir}/${s.file}: ${s.err}`);console.error(`
34
+ \u{1F4E6} Schema migration: v${n} \u2192 v${T}`);let t=en();if(!t.ok){console.error(`
35
+ [FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of t.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
36
36
  Migration ABORTED. No backups taken, no files modified.`),console.error(" Repair the file(s) above (restore from your own backup, or fix manually)"),console.error(` and try again. To inspect: 'ilml linkedin migrate-status'.
37
- `),process.exit(1)}let o=O.filter(s=>s.version>n);for(let s of o){console.log(`
38
- Running migration v${String(s.version).padStart(3,"0")}...`);let r=`v${String(s.version).padStart(3,"0")}`,i=`.pre-${r}.backup`;try{je(x,s.version),je(F,s.version)}catch(l){console.error(`
39
- [FATAL] Pre-migration backup failed for ${r}: ${l.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
40
- `),process.exit(1)}let a=s.module;try{await a.up(x,F)}catch(l){console.error(`
41
- [FATAL] Migration ${r} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let u=on(i);u.ok?(console.error(` \u2713 Auto-rollback restored ${u.restored} files. Schema stays at v${n}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
37
+ `),process.exit(1)}let o=O.filter(r=>r.version>n);for(let r of o){console.log(`
38
+ Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{je(x,r.version),je(F,r.version)}catch(c){console.error(`
39
+ [FATAL] Pre-migration backup failed for ${s}: ${c.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
40
+ `),process.exit(1)}let a=r.module;try{await a.up(x,F)}catch(c){console.error(`
41
+ [FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let u=on(i);u.ok?(console.error(` \u2713 Auto-rollback restored ${u.restored} files. Schema stays at v${n}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
42
42
  `)):(console.error(` [!] Auto-rollback INCOMPLETE: ${u.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
43
43
  `))}catch(u){console.error(` [!] Auto-rollback CRASHED while restoring: ${u.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
44
- `)}process.exit(1)}try{let l=new Date().toISOString(),u={version:s.version,name:a.NAME||r,appliedAt:l},p=Ae();p.version=s.version,p.migratedAt=l,p.migrations=p.migrations||[],p.migrations.push(u),Ho(p)}catch(l){console.error(`
45
- [FATAL] Migration ${r} applied successfully but schema version file could NOT be updated: ${l.message}`),console.error(` Your data is in the v${s.version} state but .schema-version still shows v${n}.`),console.error(` On next plugin command the runner will try to re-apply ${r}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
46
- `),process.exit(1)}console.log(` \u2713 Migration ${r} complete`)}try{de()}catch{}try{$e()}catch{}ee=!0,ne(),console.log(`
47
- \u2713 Schema is now at v${D}
48
- `)}var Ko=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Qo(e){let n=e.toLowerCase();return Ko.some(t=>t.test(n))}var zo=6e4;function Xo(){let e=Date.now(),n=[];for(let t of[j,x,F]){if(!c.existsSync(t))continue;let o;try{o=c.readdirSync(t)}catch{continue}for(let s of o){if(!Qo(s))continue;let r=f.join(t,s);try{let i=c.statSync(r);if(!i.isFile()||e-i.mtimeMs<zo)continue;n.push({dir:t,file:s,fullPath:r})}catch{}}}return n}function Zo({verbose:e=!1}={}){let n=Xo();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let t=0;for(let o of n)try{c.unlinkSync(o.fullPath),t++,e&&console.log(` Removed orphan: ${f.basename(o.dir)}/${o.file}`)}catch(s){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${s.message}`)}return!e&&t>0&&console.log(` Cleaned up ${t} orphan .tmp file(s) from previous run.`),t}function en(){let e=[];for(let n of[x,F]){if(!c.existsSync(n))continue;let t=c.readdirSync(n).filter(o=>{let s=o.toLowerCase();return s.endsWith(".json")&&!s.includes(".backup")});for(let o of t){let s=f.join(n,o);try{W(s)}catch(r){e.push({dir:f.basename(n),file:o,err:r.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function on(e){let n=[],t=[];for(let r of[x,F]){if(!c.existsSync(r))continue;let i=c.readdirSync(r).filter(a=>a.endsWith(e));for(let a of i){let l=f.join(r,a),u=a.slice(0,-e.length),p=f.join(r,u);try{u.toLowerCase().endsWith(".json")?W(l):c.accessSync(l,c.constants.R_OK),n.push({backupPath:l,originalPath:p,fileName:a,dir:r})}catch(k){t.push(`${f.basename(r)}/${a}: ${k.message}`)}}}if(t.length>0)return{ok:!1,error:t.join("; "),restored:0};let o=0,s=[];for(let{backupPath:r,originalPath:i,fileName:a,dir:l}of n)try{Re(r,i),o++}catch(u){s.push(`${f.basename(l)}/${a}: ${u.message}`)}return s.length>0?{ok:!1,error:s.join("; "),restored:o}:{ok:!0,restored:o}}function Re(e,n){let t=n+".tmp";try{c.copyFileSync(e,t),Oe(t)}catch(o){try{c.unlinkSync(t)}catch{}throw o}try{c.renameSync(t,n)}catch(o){try{c.unlinkSync(t)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let s=new Error(`File locked: ${n} (${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 s.code=o.code,s}throw o}}await Ie();var B=process.argv.slice(2),te=new Set((B.find(e=>e.startsWith("--skip="))?.split("=")[1]||"").split(",").filter(Boolean)),Te=new Set((B.find(e=>e.startsWith("--only="))?.split("=")[1]||"").split(",").filter(Boolean)),Ce=B.includes("--dry-run"),_e=B.includes("--jobs"),xe=B.includes("--comms"),De=["apply-queue","apply","funnel","scout","visit"],Ne=["sync","today"],Fe=_e?De:xe?Ne:[...De,...Ne];function N(e){return Te.size>0?Te.has(e):!te.has(e)&&Fe.includes(e)}function M(e,n,t=[],{optional:o=!1}={}){if(console.log(`
49
- ${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),Ce)return console.log(` [DRY RUN] Would run: node ${n} ${t.join(" ")}`),!0;try{return nn("node",[n,...t],{stdio:"inherit",timeout:18e6}),console.log(` \u2713 ${e} completed`),!0}catch(s){return o?(console.log(` \u26A0 ${e} failed (optional): ${s.message?.slice(0,80)}`),!1):(console.error(` \u2717 ${e} failed: ${s.message?.slice(0,80)}`),!1)}}async function tn(){let e=_e?"jobs":xe?"comms":"full";console.log(`
50
- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` DAILY PIPELINE (${e})`),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");let n=Fe.filter(N);console.log(` Steps: ${n.join(" \u2192 ")}`),te.size>0&&console.log(` Skipping: ${[...te].join(", ")}`),Ce&&console.log(" [DRY RUN MODE]");let t=ue("daily",e),o={};if(N("apply-queue")&&(o["apply-queue"]=M("Apply Queue (scored jobs)","applyQueue.mjs",["--max=50","--min-score=50"],{optional:!0})),N("apply")){let r=ye();o.apply=M("Apply from Search","run.mjs",[],{optional:!0})}if(N("funnel")&&!N("apply")){let r=ge();r.allowed?o.funnel=M("Connection Funnel","funnelRunner.mjs",["--max=20"],{optional:!0}):(console.log(`
51
- \u26A0 Funnel skipped: ${r.reason}`),o.funnel="skipped_quota")}N("scout")&&(o.scout=M("Scout Jobs for Tomorrow","scout.mjs",["--max=300","--verbose"],{optional:!0})),N("sync")&&(o.sync=M("Sync Inbox","syncAll.mjs")),N("today")&&(o.today=M("Daily Report","syncAll.mjs",["--today"])),console.log(`
52
- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(" PIPELINE COMPLETE"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");for(let[r,i]of Object.entries(o))console.log(` ${i===!0?"\u2713":i===!1?"\u2717":"\u26A0"} ${r}: ${i===!0?"success":i===!1?"failed":i}`);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
53
- `);let s=Object.values(o).some(r=>r===!1);fe(t,s?"partial":"success",o)}tn().catch(e=>{console.error("Daily pipeline failed:",e),process.exit(1)});
44
+ `)}process.exit(1)}try{let c=new Date().toISOString(),u={version:r.version,name:a.NAME||s,appliedAt:c},p=$e();p.version=r.version,p.migratedAt=c,p.migrations=p.migrations||[],p.migrations.push(u),Ko(p)}catch(c){console.error(`
45
+ [FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${c.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${n}.`),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.
46
+ `),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{de()}catch{}try{ve()}catch{}ee=!0,ne(),console.log(`
47
+ \u2713 Schema is now at v${T}
48
+ `)}var Ho=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function zo(e){let n=e.toLowerCase();return Ho.some(t=>t.test(n))}var Qo=6e4;function Xo(){let e=Date.now(),n=[];for(let t of[j,x,F]){if(!l.existsSync(t))continue;let o;try{o=l.readdirSync(t)}catch{continue}for(let r of o){if(!zo(r))continue;let s=f.join(t,r);try{let i=l.statSync(s);if(!i.isFile()||e-i.mtimeMs<Qo)continue;n.push({dir:t,file:r,fullPath:s})}catch{}}}return n}function Zo({verbose:e=!1}={}){let n=Xo();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let t=0;for(let o of n)try{l.unlinkSync(o.fullPath),t++,e&&console.log(` Removed orphan: ${f.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&t>0&&console.log(` Cleaned up ${t} orphan .tmp file(s) from previous run.`),t}function en(){let e=[];for(let n of[x,F]){if(!l.existsSync(n))continue;let t=l.readdirSync(n).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of t){let r=f.join(n,o);try{W(r)}catch(s){e.push({dir:f.basename(n),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function on(e){let n=[],t=[];for(let s of[x,F]){if(!l.existsSync(s))continue;let i=l.readdirSync(s).filter(a=>a.endsWith(e));for(let a of i){let c=f.join(s,a),u=a.slice(0,-e.length),p=f.join(s,u);try{u.toLowerCase().endsWith(".json")?W(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:p,fileName:a,dir:s})}catch(A){t.push(`${f.basename(s)}/${a}: ${A.message}`)}}}if(t.length>0)return{ok:!1,error:t.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:a,dir:c}of n)try{Re(s,i),o++}catch(u){r.push(`${f.basename(c)}/${a}: ${u.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Re(e,n){let t=n+".tmp";try{l.copyFileSync(e,t),Oe(t)}catch(o){try{l.unlinkSync(t)}catch{}throw o}try{l.renameSync(t,n)}catch(o){try{l.unlinkSync(t)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${n} (${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 Ie();var B=process.argv.slice(2),te=new Set((B.find(e=>e.startsWith("--skip="))?.split("=")[1]||"").split(",").filter(Boolean)),De=new Set((B.find(e=>e.startsWith("--only="))?.split("=")[1]||"").split(",").filter(Boolean)),Ne=B.includes("--dry-run"),_e=B.includes("--jobs"),xe=B.includes("--comms"),Te=["apply-queue","apply","funnel","scout","visit"],Ce=["sync","today"],Fe=_e?Te:xe?Ce:[...Te,...Ce];function C(e){return De.size>0?De.has(e):!te.has(e)&&Fe.includes(e)}function M(e,n,t=[],{optional:o=!1}={}){if(console.log(`
49
+ ${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),Ne)return console.log(` [DRY RUN] Would run: node ${n} ${t.join(" ")}`),!0;try{return nn("node",[n,...t],{stdio:"inherit",timeout:18e6}),console.log(` \u2713 ${e} completed`),!0}catch(r){return o?(console.log(` \u26A0 ${e} failed (optional): ${r.message?.slice(0,80)}`),!1):(console.error(` \u2717 ${e} failed: ${r.message?.slice(0,80)}`),!1)}}async function tn(){let e=_e?"jobs":xe?"comms":"full";console.log(`
50
+ \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` DAILY PIPELINE (${e})`),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");let n=Fe.filter(C);console.log(` Steps: ${n.join(" \u2192 ")}`),te.size>0&&console.log(` Skipping: ${[...te].join(", ")}`),Ne&&console.log(" [DRY RUN MODE]");let t=ue("daily",e),o={};if(C("apply-queue")&&(o["apply-queue"]=M("Apply Queue (scored jobs)","applyQueue.mjs",["--max=50","--min-score=50"],{optional:!0})),C("apply")){let s=ge();o.apply=M("Apply from Search","run.mjs",[],{optional:!0})}if(C("funnel")&&!C("apply")){let s=ye();s.allowed?o.funnel=M("Connection Funnel","funnelRunner.mjs",["--max=20"],{optional:!0}):(console.log(`
51
+ \u26A0 Funnel skipped: ${s.reason}`),o.funnel="skipped_quota")}C("scout")&&(o.scout=M("Scout Jobs for Tomorrow","scout.mjs",["--max=300","--verbose"],{optional:!0})),C("sync")&&(o.sync=M("Sync Inbox","syncAll.mjs")),C("today")&&(o.today=M("Daily Report","syncAll.mjs",["--today"])),console.log(`
52
+ \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(" PIPELINE COMPLETE"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");for(let[s,i]of Object.entries(o))console.log(` ${i===!0?"\u2713":i===!1?"\u2717":"\u26A0"} ${s}: ${i===!0?"success":i===!1?"failed":i}`);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
53
+ `);let r=Object.values(o).some(s=>s===!1);fe(t,r?"partial":"success",o)}tn().catch(e=>{console.error("Daily pipeline failed:",e),process.exit(1)});
@@ -1,8 +1,8 @@
1
- var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{for(var n in t)wt(e,n,{get:t[n],enumerable:!0})};async function g(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function Ne(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let i=o.innerText||"",s=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),r=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),y=i.includes("Get hired faster")||i.includes("Get hired 2x");if(s||r||y){let m=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(m)return m.click(),{dismissed:!0,matched:i.substring(0,80)};let $=o.querySelectorAll("button");for(let c of $){let k=c.innerText?.trim().toLowerCase()||"",h=c.getAttribute("aria-label")?.toLowerCase()||"";if(k==="not now"||k==="no thanks"||k==="dismiss"||h.includes("dismiss"))return c.click(),{dismissed:!0,matched:i.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 ce=Me(()=>{});var Ve={};gt(Ve,{extractCertificationsFromDetails:()=>Tt,extractEducationFromDetails:()=>Nt,extractExperienceFromDetails:()=>Lt,extractFeaturedFromDetails:()=>Mt,extractRecommendationsFromDetails:()=>Ft,extractSkillsFromDetails:()=>Rt});async function Lt(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await g(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 g(900);await g(1e3);let i=0;for(;i<5&&await e.evaluate(()=>{for(let r of document.querySelectorAll("button"))if(/^Load more$/i.test((r.textContent||"").trim()))return r.click(),!0;return!1});)i++,await g(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function r(c){let k=[];for(let h of c.querySelectorAll("div")){let w=Array.from(h.children).filter(E=>E.tagName==="DIV");if(w.length<3)continue;let S=w.filter(E=>(E.textContent||"").trim().length>50);S.length<3||(h.textContent||"").length<500||k.push({el:h,count:S.length,totalText:(h.textContent||"").length})}return k.sort((h,w)=>w.count-h.count||h.totalText-w.totalText),k[0]?.el}let y=r(s);if(!y)return[];let m=Array.from(y.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function $(c){let k=c[0]||null,h=null,w=null;if(c[1]){let d=c[1].split("\xB7").map(C=>C.trim());h=d[0]||null,d[1]&&(w=d[1])}let S=c.findIndex(d=>/(\d{4}|present)/i.test(d)&&/(-|–|—)/i.test(d)&&d.length<80),E=null,R=null;if(S>=0){let d=c[S].split("\xB7").map(C=>C.trim());E=d[0]||null,d[1]&&(R=d[1])}let T=null,F=-1;if(S>=0&&c[S+1]){let d=c[S+1],C=/^[>*\-•]|^&gt;/.test(d),U=/https?:\/\//.test(d),H=/\d{4}/.test(d),v=/,/.test(d)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(d);!C&&!U&&!H&&d.length<100&&v&&(T=d,F=S+1)}let se=null,p=-1,P=c[c.length-1];if(P&&/and\s+\+\d+\s+skills?$/i.test(P)){p=c.length-1;let d=P.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);d&&(se={listed:d[1].split(",").map(C=>C.trim()),additional:parseInt(d[2],10)})}let j=new Set([0,1,S,F,p].filter(d=>d>=0)),D=c.filter((d,C)=>!j.has(C)),x=D.length>0?D.join(`
1
+ var yt=Object.defineProperty;var Q=(e,t)=>()=>(e&&(t=e(e=0)),t);var bt=(e,t)=>{for(var n in t)yt(e,n,{get:t[n],enumerable:!0})};async function g(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function Re(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let i=o.innerText||"",s=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),r=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),y=i.includes("Get hired faster")||i.includes("Get hired 2x");if(s||r||y){let m=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(m)return m.click(),{dismissed:!0,matched:i.substring(0,80)};let $=o.querySelectorAll("button");for(let c of $){let k=c.innerText?.trim().toLowerCase()||"",h=c.getAttribute("aria-label")?.toLowerCase()||"";if(k==="not now"||k==="no thanks"||k==="dismiss"||h.includes("dismiss"))return c.click(),{dismissed:!0,matched:i.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 ue=Q(()=>{});import{getPluginConfig as St}from"@ilivemylife/graph-sdk";var kt,Gt,O,zt,Qt,Te=Q(async()=>{kt=await St();for(let[e,t]of Object.entries(kt))process.env[e]===void 0&&(process.env[e]=t);Gt=process.env.LINKEDIN_NAME,O=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),zt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.NEEDS_REVIEW])),Qt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.REJECTED,O.NEEDS_REVIEW]))});import"dotenv/config";import*as f from"fs";import*as b from"path";import{fileURLToPath as Ct}from"url";function qe(){f.existsSync(_)||f.mkdirSync(_,{recursive:!0})}function Be(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";f.writeFileSync(o,n);for(let i=0;i<3;i++)try{f.renameSync(o,e);return}catch(s){if(i<2&&(s.code==="EPERM"||s.code==="EBUSY")){let r=Date.now();for(;Date.now()-r<200;);continue}throw s}}function Ue(e,t){if(!f.existsSync(e))return null;try{let n=JSON.parse(f.readFileSync(e,"utf-8"));try{f.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${b.resolve(e)}`);let o=e+".backup";if(f.existsSync(o))try{let i=JSON.parse(f.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{f.copyFileSync(o,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{f.copyFileSync(e,e+".corrupted")}catch{}return null}}function Et(){return new Date().toISOString().split("T")[0]}function q(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Fe(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function He(e,t,n=null){if(!t||e[t])return t;let o=q(t);if(!o)return t;let i=null;for(let[s,r]of Object.entries(e)){if(q(r.profileUrl||s)===o)return s;!i&&Array.isArray(r.aliases)&&r.aliases.includes(o)&&(i=s)}if(i){let s=Fe(n),r=Fe(e[i].name);if(s&&r&&s===r)return i}return t}function _t(){f.existsSync(fe)||f.mkdirSync(fe,{recursive:!0})}function Ve(e){let t=q(e);return t?b.join(fe,`${t}.json`):null}function $t(e){let t=Ve(e);return t?Ue(t,`profile-history/${q(e)}.json`)||[]:[]}function Dt(e,t){let n=Ve(e);if(!n)return;_t();let o=$t(e);o.unshift(t);try{Be(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${q(e)}: ${i.message}`)}}function Pe(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function je(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Lt(e,t){if(!e)return[];let n=[];for(let o of At){let i=e[o],s=t[o];Pe(i)||Pe(s)||je(i)!==je(s)&&n.push(o)}return n}function Nt(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(e))t.has(o)||(n[o]=i);return n}function me(){return W||(qe(),W=Ue(de,"people.json")||{},W)}function We(e){qe(),W=e;try{Be(de,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${b.resolve(de)}`)}}function pe(e,t={}){if(!e)return null;let n=me(),o=Et(),i=new Date().toISOString(),s=He(n,e,t.name),r=n[s];if(r){let y=Lt(r,t);y.length>0&&(Dt(s,{capturedAt:i,previousLastUpdated:r.lastUpdated||null,changedFields:y,snapshot:Nt(r)}),r.lastSnapshotAt=i),r.seenCount=(r.seenCount||1)+1,r.lastSeen=o,r.lastUpdated=i,t.source&&!r.sources?.includes(t.source)&&(r.sources=r.sources||[],r.sources.push(t.source));for(let m of It)if(t[m]!=null){if(Array.isArray(t[m])&&t[m].length===0&&Array.isArray(r[m])&&r[m].length>0)continue;r[m]=t[m]}Array.isArray(t.availableSections)&&(r.lastFullVisitAt=i)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?i:null};return We(n),n[s]}function he(e,t,n={}){if(n.dryRun||!e||!t)return;let o=q(t);if(!o)return;let i=me(),s=He(i,e),r=i[s];if(!r)return;let y=q(r.profileUrl||s);o!==y&&(Array.isArray(r.aliases)||(r.aliases=[]),r.aliases.includes(o)||(r.aliases.push(o),r.lastUpdated=new Date().toISOString(),We(i)))}var vt,xt,_,de,nn,on,rn,sn,ln,fe,Oe,an,cn,W,It,At,we=Q(async()=>{await Te();vt=Ct(import.meta.url),xt=b.dirname(b.dirname(vt)),_=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(xt,"collected-profiles"),de=b.join(_,"people.json"),nn=b.join(_,"jobs.json"),on=b.join(_,"quota.json"),rn=b.join(_,"conversations.json"),sn=b.join(_,"sync-state.json"),ln=b.join(_,"application-questions.json"),fe=b.join(_,"profile-history"),Oe=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},an=Oe(process.env.CONNECT_MAX_DAILY,20),cn=Oe(process.env.CONNECT_MAX_WEEKLY,100),W=null;It=["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"],At=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var Ke={};bt(Ke,{extractCertificationsFromDetails:()=>Pt,extractEducationFromDetails:()=>Tt,extractExperienceFromDetails:()=>Mt,extractFeaturedFromDetails:()=>Rt,extractRecommendationsFromDetails:()=>jt,extractSkillsFromDetails:()=>Ft});async function Mt(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await g(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 g(900);await g(1e3);let i=0;for(;i<5&&await e.evaluate(()=>{for(let r of document.querySelectorAll("button"))if(/^Load more$/i.test((r.textContent||"").trim()))return r.click(),!0;return!1});)i++,await g(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function r(c){let k=[];for(let h of c.querySelectorAll("div")){let w=Array.from(h.children).filter(E=>E.tagName==="DIV");if(w.length<3)continue;let S=w.filter(E=>(E.textContent||"").trim().length>50);S.length<3||(h.textContent||"").length<500||k.push({el:h,count:S.length,totalText:(h.textContent||"").length})}return k.sort((h,w)=>w.count-h.count||h.totalText-w.totalText),k[0]?.el}let y=r(s);if(!y)return[];let m=Array.from(y.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function $(c){let k=c[0]||null,h=null,w=null;if(c[1]){let d=c[1].split("\xB7").map(C=>C.trim());h=d[0]||null,d[1]&&(w=d[1])}let S=c.findIndex(d=>/(\d{4}|present)/i.test(d)&&/(-|–|—)/i.test(d)&&d.length<80),E=null,R=null;if(S>=0){let d=c[S].split("\xB7").map(C=>C.trim());E=d[0]||null,d[1]&&(R=d[1])}let T=null,F=-1;if(S>=0&&c[S+1]){let d=c[S+1],C=/^[>*\-•]|^&gt;/.test(d),U=/https?:\/\//.test(d),H=/\d{4}/.test(d),v=/,/.test(d)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(d);!C&&!U&&!H&&d.length<100&&v&&(T=d,F=S+1)}let le=null,p=-1,P=c[c.length-1];if(P&&/and\s+\+\d+\s+skills?$/i.test(P)){p=c.length-1;let d=P.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);d&&(le={listed:d[1].split(",").map(C=>C.trim()),additional:parseInt(d[2],10)})}let j=new Set([0,1,S,F,p].filter(d=>d>=0)),D=c.filter((d,C)=>!j.has(C)),x=D.length>0?D.join(`
2
2
 
3
- `):null;return{title:k,company:h,employmentType:w,dates:E,duration:R,location:T,description:x,skills:se,_raw:c}}return m.map(c=>{let h=(c.innerText||"").trim().split(`
4
- `).map(w=>w.trim()).filter(w=>w&&w.length<5e3);return $(h)}).filter(c=>c.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 J(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${n}/`);if(!i.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${i})`);for(let r=0;r<4;r++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(700);await g(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let y of document.querySelectorAll("button"))if(/^Load more$/i.test((y.textContent||"").trim()))return y.click(),!0;return!1});)s++,await g(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(600)}async function Y(e,t,n,o){try{return await o()}catch(i){let s=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(s))throw i;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 Mt(e,t){return Y(t,"featured","extractFeaturedFromDetails",async()=>(await J(e,t,"featured"),await e.evaluate(`(() => {
5
- ${K}
3
+ `):null;return{title:k,company:h,employmentType:w,dates:E,duration:R,location:T,description:x,skills:le,_raw:c}}return m.map(c=>{let h=(c.innerText||"").trim().split(`
4
+ `).map(w=>w.trim()).filter(w=>w&&w.length<5e3);return $(h)}).filter(c=>c.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 K(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${n}/`);if(!i.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${i})`);for(let r=0;r<4;r++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(700);await g(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let y of document.querySelectorAll("button"))if(/^Load more$/i.test((y.textContent||"").trim()))return y.click(),!0;return!1});)s++,await g(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(600)}async function Y(e,t,n,o){try{return await o()}catch(i){let s=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(s))throw i;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 Rt(e,t){return Y(t,"featured","extractFeaturedFromDetails",async()=>(await K(e,t,"featured"),await e.evaluate(`(() => {
5
+ ${J}
6
6
 
7
7
  const main = document.querySelector('main');
8
8
  if (!main) return [];
@@ -42,8 +42,8 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
42
42
  if (e.caption && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.caption.trim())) return false;
43
43
  return true;
44
44
  });
45
- })()`)))}async function Nt(e,t){return Y(t,"education","extractEducationFromDetails",async()=>(await J(e,t,"education"),await e.evaluate(`(() => {
46
- ${K}
45
+ })()`)))}async function Tt(e,t){return Y(t,"education","extractEducationFromDetails",async()=>(await K(e,t,"education"),await e.evaluate(`(() => {
46
+ ${J}
47
47
 
48
48
  const main = document.querySelector('main');
49
49
  if (!main) return [];
@@ -79,8 +79,8 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
79
79
  if (e.degree && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.degree.trim())) return false;
80
80
  return true;
81
81
  });
82
- })()`)))}async function Rt(e,t){return Y(t,"skills","extractSkillsFromDetails",async()=>(await J(e,t,"skills"),await e.evaluate(`(() => {
83
- ${K}
82
+ })()`)))}async function Ft(e,t){return Y(t,"skills","extractSkillsFromDetails",async()=>(await K(e,t,"skills"),await e.evaluate(`(() => {
83
+ ${J}
84
84
 
85
85
  const main = document.querySelector('main');
86
86
  if (!main) return [];
@@ -111,8 +111,8 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
111
111
  skills.push({ name, endorsements, _raw: lines });
112
112
  }
113
113
  return skills;
114
- })()`)))}async function Tt(e,t){return Y(t,"certifications","extractCertificationsFromDetails",async()=>(await J(e,t,"certifications"),await e.evaluate(`(() => {
115
- ${K}
114
+ })()`)))}async function Pt(e,t){return Y(t,"certifications","extractCertificationsFromDetails",async()=>(await K(e,t,"certifications"),await e.evaluate(`(() => {
115
+ ${J}
116
116
 
117
117
  const main = document.querySelector('main');
118
118
  if (!main) return [];
@@ -136,8 +136,8 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
136
136
 
137
137
  return { name, issuer, issueDate, expiryDate, credentialId, _raw: lines };
138
138
  }).filter(e => e.name);
139
- })()`)))}async function Ft(e,t){return Y(t,"recommendations","extractRecommendationsFromDetails",async()=>(await J(e,t,"recommendations"),await e.evaluate(`(() => {
140
- ${K}
139
+ })()`)))}async function jt(e,t){return Y(t,"recommendations","extractRecommendationsFromDetails",async()=>(await K(e,t,"recommendations"),await e.evaluate(`(() => {
140
+ ${J}
141
141
 
142
142
  const main = document.querySelector('main');
143
143
  if (!main) return [];
@@ -172,7 +172,7 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
172
172
  if (e.recommenderTitle && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.recommenderTitle.trim())) return false;
173
173
  return true;
174
174
  });
175
- })()`)))}var K,We=Me(()=>{ce();K=`
175
+ })()`)))}var J,Je=Q(()=>{ue();J=`
176
176
  function findEntryContainer(root) {
177
177
  const candidates = [];
178
178
  for (const div of root.querySelectorAll('div')) {
@@ -235,7 +235,7 @@ function findEntryContainer(root) {
235
235
  candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
236
236
  return candidates[0]?.el;
237
237
  }
238
- `});import"dotenv/config";import Ut from"puppeteer";ce();import{getPluginConfig as yt}from"@ilivemylife/graph-sdk";var bt=await yt();for(let[e,t]of Object.entries(bt))process.env[e]===void 0&&(process.env[e]=t);var Kt=process.env.LINKEDIN_NAME,O=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Yt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.NEEDS_REVIEW])),Gt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.REJECTED,O.NEEDS_REVIEW]));import"dotenv/config";import*as f from"fs";import*as b from"path";import{fileURLToPath as St}from"url";var kt=St(import.meta.url),Ct=b.dirname(b.dirname(kt)),_=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(Ct,"collected-profiles"),ue=b.join(_,"people.json"),en=b.join(_,"jobs.json"),tn=b.join(_,"quota.json"),nn=b.join(_,"conversations.json"),on=b.join(_,"sync-state.json"),rn=b.join(_,"application-questions.json"),de=b.join(_,"profile-history"),Pe=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},sn=Pe(process.env.CONNECT_MAX_DAILY,20),ln=Pe(process.env.CONNECT_MAX_WEEKLY,100),W=null;function je(){f.existsSync(_)||f.mkdirSync(_,{recursive:!0})}function Oe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";f.writeFileSync(o,n);for(let i=0;i<3;i++)try{f.renameSync(o,e);return}catch(s){if(i<2&&(s.code==="EPERM"||s.code==="EBUSY")){let r=Date.now();for(;Date.now()-r<200;);continue}throw s}}function qe(e,t){if(!f.existsSync(e))return null;try{let n=JSON.parse(f.readFileSync(e,"utf-8"));try{f.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${b.resolve(e)}`);let o=e+".backup";if(f.existsSync(o))try{let i=JSON.parse(f.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{f.copyFileSync(o,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{f.copyFileSync(e,e+".corrupted")}catch{}return null}}function vt(){return new Date().toISOString().split("T")[0]}var xt=["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"],Et=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function q(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Re(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Be(e,t,n=null){if(!t||e[t])return t;let o=q(t);if(!o)return t;let i=null;for(let[s,r]of Object.entries(e)){if(q(r.profileUrl||s)===o)return s;!i&&Array.isArray(r.aliases)&&r.aliases.includes(o)&&(i=s)}if(i){let s=Re(n),r=Re(e[i].name);if(s&&r&&s===r)return i}return t}function It(){f.existsSync(de)||f.mkdirSync(de,{recursive:!0})}function Ue(e){let t=q(e);return t?b.join(de,`${t}.json`):null}function At(e){let t=Ue(e);return t?qe(t,`profile-history/${q(e)}.json`)||[]:[]}function _t(e,t){let n=Ue(e);if(!n)return;It();let o=At(e);o.unshift(t);try{Oe(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${q(e)}: ${i.message}`)}}function Te(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Fe(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function $t(e,t){if(!e)return[];let n=[];for(let o of Et){let i=e[o],s=t[o];Te(i)||Te(s)||Fe(i)!==Fe(s)&&n.push(o)}return n}function Dt(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(e))t.has(o)||(n[o]=i);return n}function fe(){return W||(je(),W=qe(ue,"people.json")||{},W)}function He(e){je(),W=e;try{Oe(ue,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${b.resolve(ue)}`)}}function me(e,t={}){if(!e)return null;let n=fe(),o=vt(),i=new Date().toISOString(),s=Be(n,e,t.name),r=n[s];if(r){let y=$t(r,t);y.length>0&&(_t(s,{capturedAt:i,previousLastUpdated:r.lastUpdated||null,changedFields:y,snapshot:Dt(r)}),r.lastSnapshotAt=i),r.seenCount=(r.seenCount||1)+1,r.lastSeen=o,r.lastUpdated=i,t.source&&!r.sources?.includes(t.source)&&(r.sources=r.sources||[],r.sources.push(t.source));for(let m of xt)if(t[m]!=null){if(Array.isArray(t[m])&&t[m].length===0&&Array.isArray(r[m])&&r[m].length>0)continue;r[m]=t[m]}Array.isArray(t.availableSections)&&(r.lastFullVisitAt=i)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?i:null};return He(n),n[s]}function pe(e,t,n={}){if(n.dryRun||!e||!t)return;let o=q(t);if(!o)return;let i=fe(),s=Be(i,e),r=i[s];if(!r)return;let y=q(r.profileUrl||s);o!==y&&(Array.isArray(r.aliases)||(r.aliases=[]),r.aliases.includes(o)||(r.aliases.push(o),r.lastUpdated=new Date().toISOString(),He(i)))}async function Pt(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Je(e,t,n={}){let{extractExperience:o=!1,extractFeatured:i=!1,extractEducation:s=!1,extractSkills:r=!1,extractRecommendations:y=!1,extractCertifications:m=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await Ne(e)&&(console.log(" Dismissed Premium overlay"),await g(1500),await Pt(e,t));let c=0;for(let p=0;p<2;p++){let P=await e.evaluate(()=>document.body.scrollHeight);for(let D=1;D<=6;D++)await e.evaluate(x=>window.scrollTo(0,x),P*D/6),await g(900);let j=await e.evaluate(()=>document.body.scrollHeight);if(j===c)break;c=j}await g(800);let k=null;try{let p=e.url();p&&/\/in\/[^/?#]/.test(p)&&(k=p.split("?")[0].replace(/\/+$/,""))}catch{}let h=await e.evaluate(()=>{let p=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"]),P=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"]),j=l=>{let a=(l||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(a)},D={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:[]},x=document.querySelector("main");if(!x)return D;let d=[...Array.from(x.querySelectorAll("h1")),...Array.from(x.querySelectorAll("h2"))],C=Array.from(x.querySelectorAll("h2")),U=d.find(l=>{let a=l.textContent&&l.textContent.trim(),u=(a||"").replace(/\s*\(\d+\)$/,"").trim();return a&&a.length>1&&a.length<100&&!p.has(u)&&!P.has(u)}),H=U?U.textContent.trim():null,v=U?U.parentElement:null;for(;v&&v!==x&&!Array.from(v.children).filter(a=>a.tagName==="P").some(a=>{let u=a.textContent&&a.textContent.trim();return u&&u.length>5&&!j(u)});)v=v.parentElement;let ye=null,be=null,Se=null,le=null;if(v&&v!==x){let l=Array.from(v.children).filter(u=>u.tagName==="P").filter(u=>{let L=u.textContent&&u.textContent.trim();return L&&L.length>5&&!j(L)});if(l[0]&&(ye=l[0].textContent.trim()),l[1]){let u=l[1].textContent.trim().split(/\s*[·•]\s*/);be=u[0]||null,u.length>1&&(Se=u.slice(1).join(" \xB7 "))}let a=Array.from(v.children).filter(u=>u.tagName==="DIV");for(let u=a.length-1;u>=0;u--){let L=a[u].textContent&&a[u].textContent.trim();if(L&&!(H&&L.startsWith(H))&&(le=L.split(/[·•]/)[0].trim(),le))break}}let ke=null;if(v){let l=v.querySelectorAll("p, span, div");for(let a of l){let u=(a.textContent||"").trim().replace(/^[·•]\s*/,"");if(u==="1st"||u==="2nd"||u==="3rd"){ke=u;break}}}let ct=!!x.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ce=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),ut=Ce&&Ce.src||null,G=x.textContent||"",ve=null,xe=G.match(/(\d+\+?)\s+connections\b/i);xe&&(ve=xe[1]+" connections");let z=null,Ee=G.match(/(\d+)\s+mutual connection/i),Ie=G.match(/and\s+(\d+)\s+other mutual/i),dt=G.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ee?z=parseInt(Ee[1],10):Ie?z=2+parseInt(Ie[1],10):dt&&(z=2);let Ae=null,_e=null,$e=C.find(l=>l.textContent&&l.textContent.trim()==="About");if($e){let l=$e.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").trim();a=a.replace(/^About\s*/,"").trim();let u=a.match(/Top skills\s*(.+?)$/i);if(u){let ae=u[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(ht=>ht.trim()).filter(Boolean);ae.length>0&&ae.length<10&&(_e=ae)}a=a.split(/\n?…\s*more/i)[0].trim(),a=a.split(/\n?\.\.\.\s*more/i)[0].trim(),a=a.split(/\bTop skills\b/i)[0].trim(),a=a.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Ae=a||null}}let De=null,Le=C.find(l=>l.textContent&&l.textContent.trim()==="Activity");if(Le){let l=Le.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);a&&(De=parseInt(a[1].replace(/,/g,""),10))}}let ft=[...new Set(C.map(l=>(l.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(l=>l&&l.length>1&&l.length<60&&l!==H).filter(l=>p.has(l)))],V=document.body.textContent||"",mt=/#OpenToWork\b/i.test(V)||/\bOpen to work\b/.test(V),pt=/#Hiring\b/i.test(V)||/\bI'?m hiring\b/i.test(V)||/\bWe are hiring\b/i.test(V);return{name:H,title:ye,location:le,currentCompany:be,currentSchool:Se,connectionDegree:ke,hasVerifiedBadge:ct,photoUrl:ut,connectionsLevel:ve,mutualConnectionsCount:z,followers:De,openToWork:mt,hiring:pt,about:Ae,topSkills:_e,availableSections:ft}});console.log(`Viewed: ${h.name} - ${h.title}`);let w=null,S=null,E=null,R=null,T=null,F=null;if(o||i||s||r||y||m){let p=await Promise.resolve().then(()=>(We(),Ve));o&&(w=await p.extractExperienceFromDetails(e,t),console.log(` + Experience: ${w.length} entries`)),i&&(S=await p.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${S.length} entries`)),s&&(E=await p.extractEducationFromDetails(e,t),console.log(` + Education: ${E.length} entries`)),r&&(R=await p.extractSkillsFromDetails(e,t),console.log(` + Skills: ${R.length} entries`)),y&&(T=await p.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${T.length} entries`)),m&&(F=await p.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${F.length} entries`))}return{...h,profileUrl:t,resolvedUrl:k,...w!==null&&{experience:w},...S!==null&&{featured:S},...E!==null&&{education:E},...R!==null&&{skillsFull:R},...T!==null&&{recommendations:T},...F!==null&&{certifications:F}}}catch($){console.error(`Error viewing profile ${t}:`,$.message);try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test($.message||""))throw $;return null}}import I from"fs";import M from"path";var jt="cookies.json";function Ke(){let e=process.env.ILML_SCOPE_DIR;return e?M.join(e,"plugins-state","linkedin","cookies.json"):jt}function Ye(){let e=Ke();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=I.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function Ge(){return I.existsSync(Ke())}function Ot(){let e=process.env.ILML_SCOPE_DIR;return e?M.join(e,"plugins-state","linkedin"):"."}function ze(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function qt(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?ze(t[1]):"default"}function Qe(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return I.existsSync(t)||I.mkdirSync(t,{recursive:!0}),M.resolve(t);let n=ze(e||qt()),o=M.join(Ot(),"chrome-profile",n);return I.existsSync(o)||I.mkdirSync(o,{recursive:!0}),M.resolve(o)}var Ze=".ilml-seeded";function Xe(e){return!I.existsSync(M.join(e,Ze))}function et(e){try{I.writeFileSync(M.join(e,Ze),new Date().toISOString())}catch{}}function tt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(M.join(e,n),{force:!0}),t++}catch{}return t}var Bt={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function nt(e,t={}){let n=Qe(),o={...Bt,...t,userDataDir:n},i;try{i=await e.launch(o)}catch{tt(n);try{i=await e.launch(o)}catch(r){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${r.message})`)}}return{browser:i,profileDir:n,needsSeed:Xe(n)}}async function ot(e,t){if(!t||!t.needsSeed)return!1;if(!Ge())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...Ye()),et(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}function it(e){return e?e.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function rt(e){return(e||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var A=process.argv.slice(2),Ht=A.includes("--help")||A.includes("-h"),N=A.find(e=>e.startsWith("http")),B=A.includes("--full"),Z=B||A.includes("--with-experience"),X=B||A.includes("--with-featured"),ee=B||A.includes("--with-education"),te=B||A.includes("--with-skills"),ne=B||A.includes("--with-recommendations"),oe=B||A.includes("--with-certifications"),st=[["experience",Z],["featured",X],["education",ee],["skills",te],["recommendations",ne],["certifications",oe]],lt=st.filter(([,e])=>e).length,we=1+lt;function at(){console.log(`
238
+ `});import"dotenv/config";import Vt from"puppeteer";ue();await we();async function Ot(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Ye(e,t,n={}){let{extractExperience:o=!1,extractFeatured:i=!1,extractEducation:s=!1,extractSkills:r=!1,extractRecommendations:y=!1,extractCertifications:m=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await Re(e)&&(console.log(" Dismissed Premium overlay"),await g(1500),await Ot(e,t));let c=0;for(let p=0;p<2;p++){let P=await e.evaluate(()=>document.body.scrollHeight);for(let D=1;D<=6;D++)await e.evaluate(x=>window.scrollTo(0,x),P*D/6),await g(900);let j=await e.evaluate(()=>document.body.scrollHeight);if(j===c)break;c=j}await g(800);let k=null;try{let p=e.url();p&&/\/in\/[^/?#]/.test(p)&&(k=p.split("?")[0].replace(/\/+$/,""))}catch{}let h=await e.evaluate(()=>{let p=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"]),P=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"]),j=l=>{let a=(l||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(a)},D={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:[]},x=document.querySelector("main");if(!x)return D;let d=[...Array.from(x.querySelectorAll("h1")),...Array.from(x.querySelectorAll("h2"))],C=Array.from(x.querySelectorAll("h2")),U=d.find(l=>{let a=l.textContent&&l.textContent.trim(),u=(a||"").replace(/\s*\(\d+\)$/,"").trim();return a&&a.length>1&&a.length<100&&!p.has(u)&&!P.has(u)}),H=U?U.textContent.trim():null,v=U?U.parentElement:null;for(;v&&v!==x&&!Array.from(v.children).filter(a=>a.tagName==="P").some(a=>{let u=a.textContent&&a.textContent.trim();return u&&u.length>5&&!j(u)});)v=v.parentElement;let Se=null,ke=null,Ce=null,ae=null;if(v&&v!==x){let l=Array.from(v.children).filter(u=>u.tagName==="P").filter(u=>{let L=u.textContent&&u.textContent.trim();return L&&L.length>5&&!j(L)});if(l[0]&&(Se=l[0].textContent.trim()),l[1]){let u=l[1].textContent.trim().split(/\s*[·•]\s*/);ke=u[0]||null,u.length>1&&(Ce=u.slice(1).join(" \xB7 "))}let a=Array.from(v.children).filter(u=>u.tagName==="DIV");for(let u=a.length-1;u>=0;u--){let L=a[u].textContent&&a[u].textContent.trim();if(L&&!(H&&L.startsWith(H))&&(ae=L.split(/[·•]/)[0].trim(),ae))break}}let ve=null;if(v){let l=v.querySelectorAll("p, span, div");for(let a of l){let u=(a.textContent||"").trim().replace(/^[·•]\s*/,"");if(u==="1st"||u==="2nd"||u==="3rd"){ve=u;break}}}let dt=!!x.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),xe=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),ft=xe&&xe.src||null,G=x.textContent||"",Ee=null,Ie=G.match(/(\d+\+?)\s+connections\b/i);Ie&&(Ee=Ie[1]+" connections");let z=null,Ae=G.match(/(\d+)\s+mutual connection/i),_e=G.match(/and\s+(\d+)\s+other mutual/i),mt=G.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ae?z=parseInt(Ae[1],10):_e?z=2+parseInt(_e[1],10):mt&&(z=2);let $e=null,De=null,Le=C.find(l=>l.textContent&&l.textContent.trim()==="About");if(Le){let l=Le.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").trim();a=a.replace(/^About\s*/,"").trim();let u=a.match(/Top skills\s*(.+?)$/i);if(u){let ce=u[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&&(De=ce)}a=a.split(/\n?…\s*more/i)[0].trim(),a=a.split(/\n?\.\.\.\s*more/i)[0].trim(),a=a.split(/\bTop skills\b/i)[0].trim(),a=a.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),$e=a||null}}let Ne=null,Me=C.find(l=>l.textContent&&l.textContent.trim()==="Activity");if(Me){let l=Me.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);a&&(Ne=parseInt(a[1].replace(/,/g,""),10))}}let pt=[...new Set(C.map(l=>(l.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(l=>l&&l.length>1&&l.length<60&&l!==H).filter(l=>p.has(l)))],V=document.body.textContent||"",ht=/#OpenToWork\b/i.test(V)||/\bOpen to work\b/.test(V),wt=/#Hiring\b/i.test(V)||/\bI'?m hiring\b/i.test(V)||/\bWe are hiring\b/i.test(V);return{name:H,title:Se,location:ae,currentCompany:ke,currentSchool:Ce,connectionDegree:ve,hasVerifiedBadge:dt,photoUrl:ft,connectionsLevel:Ee,mutualConnectionsCount:z,followers:Ne,openToWork:ht,hiring:wt,about:$e,topSkills:De,availableSections:pt}});console.log(`Viewed: ${h.name} - ${h.title}`);let w=null,S=null,E=null,R=null,T=null,F=null;if(o||i||s||r||y||m){let p=await Promise.resolve().then(()=>(Je(),Ke));o&&(w=await p.extractExperienceFromDetails(e,t),console.log(` + Experience: ${w.length} entries`)),i&&(S=await p.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${S.length} entries`)),s&&(E=await p.extractEducationFromDetails(e,t),console.log(` + Education: ${E.length} entries`)),r&&(R=await p.extractSkillsFromDetails(e,t),console.log(` + Skills: ${R.length} entries`)),y&&(T=await p.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${T.length} entries`)),m&&(F=await p.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${F.length} entries`))}return{...h,profileUrl:t,resolvedUrl:k,...w!==null&&{experience:w},...S!==null&&{featured:S},...E!==null&&{education:E},...R!==null&&{skillsFull:R},...T!==null&&{recommendations:T},...F!==null&&{certifications:F}}}catch($){console.error(`Error viewing profile ${t}:`,$.message);try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test($.message||""))throw $;return null}}await we();import I from"fs";import N from"path";var qt="cookies.json";function Ge(){let e=process.env.ILML_SCOPE_DIR;return e?N.join(e,"plugins-state","linkedin","cookies.json"):qt}function ze(){let e=Ge();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=I.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function Qe(){return I.existsSync(Ge())}function Bt(){let e=process.env.ILML_SCOPE_DIR;return e?N.join(e,"plugins-state","linkedin"):"."}function Ze(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function Ut(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?Ze(t[1]):"default"}function Xe(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return I.existsSync(t)||I.mkdirSync(t,{recursive:!0}),N.resolve(t);let n=Ze(e||Ut()),o=N.join(Bt(),"chrome-profile",n);return I.existsSync(o)||I.mkdirSync(o,{recursive:!0}),N.resolve(o)}var et=".ilml-seeded";function tt(e){return!I.existsSync(N.join(e,et))}function nt(e){try{I.writeFileSync(N.join(e,et),new Date().toISOString())}catch{}}function ot(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(N.join(e,n),{force:!0}),t++}catch{}return t}var Ht={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function it(e,t={}){let n=Xe(),o={...Ht,...t,userDataDir:n},i;try{i=await e.launch(o)}catch{ot(n);try{i=await e.launch(o)}catch(r){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${r.message})`)}}return{browser:i,profileDir:n,needsSeed:tt(n)}}async function rt(e,t){if(!t||!t.needsSeed)return!1;if(!Qe())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...ze()),nt(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}function st(e){return e?e.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function lt(e){return(e||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var A=process.argv.slice(2),Wt=A.includes("--help")||A.includes("-h"),M=A.find(e=>e.startsWith("http")),B=A.includes("--full"),X=B||A.includes("--with-experience"),ee=B||A.includes("--with-featured"),te=B||A.includes("--with-education"),ne=B||A.includes("--with-skills"),oe=B||A.includes("--with-recommendations"),ie=B||A.includes("--with-certifications"),at=[["experience",X],["featured",ee],["education",te],["skills",ne],["recommendations",oe],["certifications",ie]],ct=at.filter(([,e])=>e).length,ye=1+ct;function ut(){console.log(`
239
239
  enrich-profile \u2014 visit ONE LinkedIn profile and save what we learn
240
240
 
241
241
  USAGE
@@ -286,4 +286,4 @@ WHEN TO USE
286
286
  - Audit your own LinkedIn profile (--full prints everything to stdout)
287
287
  - Deep-dive on one specific contact before reaching out
288
288
  - Verify what we know about a recruiter / lead
289
- `)}Ht&&(at(),process.exit(0));N||(at(),process.exit(1));/linkedin\.com\/in\//i.test(N)||(console.error(`URL doesn't look like a LinkedIn profile: ${N}`),console.error("Expected format: https://www.linkedin.com/in/<slug>/"),process.exit(1));var ge=it(process.env.MY_LINKEDIN_URL||""),re=rt(process.env.LINKEDIN_NAME||"");!ge&&!re&&(console.error(""),console.error(" \u26D4 Refusing to run: cannot self-detect without configuration."),console.error(""),console.error(" Set EITHER (preferably both) of:"),console.error(" MY_LINKEDIN_URL=https://www.linkedin.com/in/<your-slug>"),console.error(' LINKEDIN_NAME="Your Full Name"'),console.error(""),console.error(" in .env (dev) or via `ilml plugin config linkedin set <KEY> <VALUE>` (prod)."),console.error(" This prevents your own profile from accidentally landing in people.json."),console.error(""),process.exit(1));var ie=ge&&it(N)===ge,he=st.filter(([,e])=>e).map(([e])=>e);console.log("");console.log(` enrichProfile \u2014 ${N}`);B?console.log(` Mode: --full (${we} page loads: main + ${he.join(" + ")})`):he.length>0?console.log(` Mode: rich (${we} loads: main + ${he.join(" + ")})`):console.log(" Mode: basic (1 load \u2014 main page only)");console.log(ie?" Target: SELF (URL match) \u2014 will print to stdout, not saved to people.json":re?` Target: TBD \u2014 name-match against "${process.env.LINKEDIN_NAME}" after fetch`:" Target: will save to people.json (no MY_LINKEDIN_URL or LINKEDIN_NAME set for self-check)");lt>0&&(console.log(""),console.log(` \u26A0 ${we} page loads on the SAME profile = normal "deep read" pattern.`),console.log(" This is intentionally single-URL \u2014 DO NOT batch. For batch enrichment"),console.log(" use `enrichProfiles.mjs --with-experience` (gated, capped)."));console.log("");var Q=null;try{let e=await nt(Ut);Q=e.browser;let t=await Q.newPage();await ot(t,e);let n=await Je(t,N,{extractExperience:Z,extractFeatured:X,extractEducation:ee,extractSkills:te,extractRecommendations:ne,extractCertifications:oe});if((!n||!n.name)&&(console.error(" viewProfile returned no name \u2014 profile not loaded or DOM changed"),process.exit(1)),!ie&&re&&n.name&&rt(n.name)===re&&(ie=!0,console.log(" \u2191 Detected self via LINKEDIN_NAME match \u2014 will NOT save to people.json")),console.log(""),console.log(" \u2500\u2500\u2500 extracted \u2500\u2500\u2500"),console.log(` name: ${n.name}`),console.log(` title: ${n.title||"(none)"}`),console.log(` location: ${n.location||"(none)"}`),console.log(` about: ${n.about?`${n.about.length} chars`:"(none)"}`),console.log(` topSkills: ${n.topSkills?n.topSkills.join(", "):"(none)"}`),Z&&console.log(` experience: ${(n.experience||[]).length} entries`),X&&console.log(` featured: ${(n.featured||[]).length} entries`),ee&&console.log(` education: ${(n.education||[]).length} entries`),te&&console.log(` skillsFull: ${(n.skillsFull||[]).length} entries`),ne&&console.log(` recommendations: ${(n.recommendations||[]).length} entries`),oe&&console.log(` certifications: ${(n.certifications||[]).length} entries`),console.log(""),ie)console.log(" \u2500\u2500\u2500 full data (self \u2014 not persisted) \u2500\u2500\u2500"),console.log(JSON.stringify(n,null,2));else{let o={name:n.name,title:n.title,location:n.location,about:n.about,currentCompany:n.currentCompany,currentSchool:n.currentSchool,topSkills:n.topSkills,availableSections:n.availableSections,connectionsLevel:n.connectionsLevel,mutualConnectionsCount:n.mutualConnectionsCount,followers:n.followers,openToWork:n.openToWork,hiring:n.hiring,hasVerifiedBadge:n.hasVerifiedBadge,photoUrl:n.photoUrl,source:"enrich-profile-single"},i=[["experience",Z,n.experience],["featured",X,n.featured],["education",ee,n.education],["skillsFull",te,n.skillsFull],["recommendations",ne,n.recommendations],["certifications",oe,n.certifications]],s=!1;for(let[r,y,m]of i)y&&(Array.isArray(m)&&m.length>0?(o[r]=m,s=!0):console.log(` \u26A0 --with-${r==="skillsFull"?"skills":r} returned 0 entries \u2014 NOT writing ${r} (existing data preserved)`));s&&(o._lastEnrichedAt=new Date().toISOString()),me(N,o),n.resolvedUrl&&pe(N,n.resolvedUrl),console.log(" \u2713 Saved to people.json")}}catch(e){console.error(" Error:",e.message),process.exit(1)}finally{Q&&await Q.close().catch(()=>{})}
289
+ `)}Wt&&(ut(),process.exit(0));M||(ut(),process.exit(1));/linkedin\.com\/in\//i.test(M)||(console.error(`URL doesn't look like a LinkedIn profile: ${M}`),console.error("Expected format: https://www.linkedin.com/in/<slug>/"),process.exit(1));var be=st(process.env.MY_LINKEDIN_URL||""),se=lt(process.env.LINKEDIN_NAME||"");!be&&!se&&(console.error(""),console.error(" \u26D4 Refusing to run: cannot self-detect without configuration."),console.error(""),console.error(" Set EITHER (preferably both) of:"),console.error(" MY_LINKEDIN_URL=https://www.linkedin.com/in/<your-slug>"),console.error(' LINKEDIN_NAME="Your Full Name"'),console.error(""),console.error(" in .env (dev) or via `ilml plugin config linkedin set <KEY> <VALUE>` (prod)."),console.error(" This prevents your own profile from accidentally landing in people.json."),console.error(""),process.exit(1));var re=be&&st(M)===be,ge=at.filter(([,e])=>e).map(([e])=>e);console.log("");console.log(` enrichProfile \u2014 ${M}`);B?console.log(` Mode: --full (${ye} page loads: main + ${ge.join(" + ")})`):ge.length>0?console.log(` Mode: rich (${ye} loads: main + ${ge.join(" + ")})`):console.log(" Mode: basic (1 load \u2014 main page only)");console.log(re?" Target: SELF (URL match) \u2014 will print to stdout, not saved to people.json":se?` Target: TBD \u2014 name-match against "${process.env.LINKEDIN_NAME}" after fetch`:" Target: will save to people.json (no MY_LINKEDIN_URL or LINKEDIN_NAME set for self-check)");ct>0&&(console.log(""),console.log(` \u26A0 ${ye} page loads on the SAME profile = normal "deep read" pattern.`),console.log(" This is intentionally single-URL \u2014 DO NOT batch. For batch enrichment"),console.log(" use `enrichProfiles.mjs --with-experience` (gated, capped)."));console.log("");var Z=null;try{let e=await it(Vt);Z=e.browser;let t=await Z.newPage();await rt(t,e);let n=await Ye(t,M,{extractExperience:X,extractFeatured:ee,extractEducation:te,extractSkills:ne,extractRecommendations:oe,extractCertifications:ie});if((!n||!n.name)&&(console.error(" viewProfile returned no name \u2014 profile not loaded or DOM changed"),process.exit(1)),!re&&se&&n.name&&lt(n.name)===se&&(re=!0,console.log(" \u2191 Detected self via LINKEDIN_NAME match \u2014 will NOT save to people.json")),console.log(""),console.log(" \u2500\u2500\u2500 extracted \u2500\u2500\u2500"),console.log(` name: ${n.name}`),console.log(` title: ${n.title||"(none)"}`),console.log(` location: ${n.location||"(none)"}`),console.log(` about: ${n.about?`${n.about.length} chars`:"(none)"}`),console.log(` topSkills: ${n.topSkills?n.topSkills.join(", "):"(none)"}`),X&&console.log(` experience: ${(n.experience||[]).length} entries`),ee&&console.log(` featured: ${(n.featured||[]).length} entries`),te&&console.log(` education: ${(n.education||[]).length} entries`),ne&&console.log(` skillsFull: ${(n.skillsFull||[]).length} entries`),oe&&console.log(` recommendations: ${(n.recommendations||[]).length} entries`),ie&&console.log(` certifications: ${(n.certifications||[]).length} entries`),console.log(""),re)console.log(" \u2500\u2500\u2500 full data (self \u2014 not persisted) \u2500\u2500\u2500"),console.log(JSON.stringify(n,null,2));else{let o={name:n.name,title:n.title,location:n.location,about:n.about,currentCompany:n.currentCompany,currentSchool:n.currentSchool,topSkills:n.topSkills,availableSections:n.availableSections,connectionsLevel:n.connectionsLevel,mutualConnectionsCount:n.mutualConnectionsCount,followers:n.followers,openToWork:n.openToWork,hiring:n.hiring,hasVerifiedBadge:n.hasVerifiedBadge,photoUrl:n.photoUrl,source:"enrich-profile-single"},i=[["experience",X,n.experience],["featured",ee,n.featured],["education",te,n.education],["skillsFull",ne,n.skillsFull],["recommendations",oe,n.recommendations],["certifications",ie,n.certifications]],s=!1;for(let[r,y,m]of i)y&&(Array.isArray(m)&&m.length>0?(o[r]=m,s=!0):console.log(` \u26A0 --with-${r==="skillsFull"?"skills":r} returned 0 entries \u2014 NOT writing ${r} (existing data preserved)`));s&&(o._lastEnrichedAt=new Date().toISOString()),pe(M,o),n.resolvedUrl&&he(M,n.resolvedUrl),console.log(" \u2713 Saved to people.json")}}catch(e){console.error(" Error:",e.message),process.exit(1)}finally{Z&&await Z.close().catch(()=>{})}