ilml-plugin-linkedin 1.20.0 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/dist/applyQueue.mjs +13 -13
- package/dist/connect.mjs +55 -55
- package/dist/daily.mjs +18 -18
- package/dist/enrichProfiles.mjs +5 -5
- package/dist/funnelRunner.mjs +39 -39
- package/dist/migrationCli.mjs +10 -10
- package/dist/quota.mjs +5 -5
- package/dist/run.mjs +45 -45
- package/dist/scout.mjs +11 -11
- package/dist/syncAll.mjs +87 -87
- package/dist/syncConnections.mjs +40 -40
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +22 -22
- package/ilml-plugin.json +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.20.1
|
|
4
|
+
- **Fixed the discovery feature (from 1.20.0) so the "who to reach next" list is actually ranked by relevance.** It was saving each discovered person without their job title — it accidentally grabbed the "2nd/3rd-degree" label instead — which left the relevance ranking blank. It now reads each person's real headline, so the best-fit people rise to the top. It's also more robust: names with special characters stay intact, people are grouped under the right section, and duplicate links no longer skew the order. Discovery is still off by default. No schema change.
|
|
5
|
+
|
|
3
6
|
## 1.20.0
|
|
4
7
|
- **Your daily connection quota no longer has to sit idle.** A new command, `ilml linkedin connect fill --from-discovered`, fills your connection queue with the most relevant people the plugin has already come across — best fit first — so when your hand-picked list runs out there are still good people to reach. It just lines them up; you review and send them the usual way (`connect approve`, then `connect run`). Add `--dry-run` to preview who it would add before anything is queued. It never re-adds someone you're already connected to or already have waiting in the queue.
|
|
5
8
|
- **The plugin can now grow your "who to reach next" list on its own.** As it sends your connection requests, it can also take note of the related people LinkedIn shows on each profile — so your pool of good leads keeps building while you work, without any extra browsing. This is **off by default**; leave it off and everything (apply, sync, connect, scout) works exactly as before.
|
package/dist/applyQueue.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var Le=Object.defineProperty;var B=(e,n)=>{for(var o in n)Le(e,o,{get:n[o],enumerable:!0})};import"dotenv/config";import*as
|
|
1
|
+
var Le=Object.defineProperty;var B=(e,n)=>{for(var o in n)Le(e,o,{get:n[o],enumerable:!0})};import"dotenv/config";import*as D from"fs";import*as M from"path";import{fileURLToPath as un}from"url";import{execFileSync as fn}from"child_process";import{getPluginConfig as Me}from"@ilivemylife/graph-sdk";var Ue=await Me();for(let[e,n]of Object.entries(Ue))process.env[e]===void 0&&(process.env[e]=n);var bn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),wn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),vn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as h from"fs";import*as g from"path";import{fileURLToPath as Pe}from"url";var Je=Pe(import.meta.url),qe=g.dirname(g.dirname(Je)),I=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"collected-profiles"):g.join(qe,"collected-profiles"),Be=g.join(I,"people.json"),En=g.join(I,"jobs.json"),On=g.join(I,"quota.json"),In=g.join(I,"conversations.json"),Rn=g.join(I,"sync-state.json"),Tn=g.join(I,"application-questions.json"),Cn=g.join(I,"profile-history"),ue=(e,n)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:n},Dn=ue(process.env.CONNECT_MAX_DAILY,20),Nn=ue(process.env.CONNECT_MAX_WEEKLY,100),P=null,Ve=null,Ge=null,We=null,Ye=null,He=null;function fe(){P=null,Ve=null,Ge=null,We=null,Ye=null,He=null}function Ke(){h.existsSync(I)||h.mkdirSync(I,{recursive:!0})}function ze(e,n){if(!h.existsSync(e))return null;try{let o=JSON.parse(h.readFileSync(e,"utf-8"));try{h.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${n} is corrupted: ${o.message}`),console.error(` File: ${g.resolve(e)}`);let t=e+".backup";if(h.existsSync(t))try{let r=JSON.parse(h.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{h.copyFileSync(t,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{h.copyFileSync(e,e+".corrupted")}catch{}return null}}function pe(){return P||(Ke(),P=ze(Be,"people.json")||{},P)}import"dotenv/config";import*as w from"fs";import*as b from"path";import{fileURLToPath as Qe}from"url";var Xe=Qe(import.meta.url),Ze=b.dirname(b.dirname(Xe)),_=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"market-research"):b.join(Ze,"market-research"),de=b.join(_,"scouted-jobs.json"),Jn=b.join(_,"discovered-people.json"),qn=b.join(_,"visit-log.json"),Bn=b.join(_,"companies.json"),eo=b.join(_,"job-decisions.json");function oo(){w.existsSync(_)||w.mkdirSync(_,{recursive:!0})}function no(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";w.writeFileSync(t,o);for(let r=0;r<3;r++)try{w.renameSync(t,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 me(e){try{if(w.existsSync(e))return JSON.parse(w.readFileSync(e,"utf-8"))}catch{}return null}function he(){J=null,q=null,to=null,ro=null,so=null}var J=null;function H(){return J||(J=me(de)||{},J)}function ge(e,n){if(!e)return;oo();let o=H(),t=new Date().toISOString().slice(0,10);if(o[e]){for(let[r,s]of Object.entries(n))s!=null&&(o[e][r]=s);o[e].lastSeen=t}else o[e]={...n,scoutedAt:t,lastSeen:t};try{no(de,o)}catch(r){console.error(`[!] Failed to save scouted-jobs.json: ${r.message}`)}}var q=null;function ye(){return q||(q=me(eo)||{},q)}var to=null;var ro=null;var so=null;var io=new Set(["java","c#",".net","scala","python","typescript","javascript","react","node.js","aws","azure","docker","kubernetes","microservices","graphql","rest","sql","postgresql","mongodb","kafka","redis","ci/cd","terraform","spring"]),co=new Set(["iot","machine learning","ai","data engineering","spark","go","rust","kotlin","next.js","devops","sre"]),Se=["vancouver","british columbia"],lo=["canada","montreal","quebec","alberta","calgary","ottawa"],ao=["toronto","ontario"],uo=["india","pakistan","nigeria","philippines"];function fo(e,n={}){let o=0,t=(e.techStack||[]).map(a=>a.toLowerCase()),r=0,s=0;for(let a of t)io.has(a)&&r++,co.has(a)&&s++;if(o+=Math.min(r*6,24),o+=Math.min(s*3,6),e.salary){let a=po(e.salary);a&&(a>=15e4?o+=20:a>=12e4?o+=15:a>=1e5?o+=10:a>=8e4?o+=5:a>=100&&a<1e3?o+=15:a>=70&&a<1e3&&(o+=10))}let i=(e.location||"").toLowerCase(),u=/remote/i.test(i)||e.workplaceType==="remote";uo.some(a=>i.includes(a))?o-=30:u&&/united states|usa|\bus\b/i.test(i)?o+=25:u&&Se.some(a=>i.includes(a))?o+=22:u?o+=20:Se.some(a=>i.includes(a))?o+=18:lo.some(a=>i.includes(a))?o+=10:ao.some(a=>i.includes(a))&&(o+=5),e.isEasyApply&&(o+=5);let c=(e.seniority||"").toLowerCase();c.includes("senior")||c.includes("lead")||c.includes("staff")?o+=10:c.includes("mid")?o+=5:(c.includes("entry")||c.includes("intern"))&&(o-=10),e.recruiterUrl&&(n.conversationRecruiters?.has(e.recruiterUrl)?o+=20:n.connectedRecruiters?.has(e.recruiterUrl)?o+=15:o+=3);let f=new Set(e.jobTags||[]);return f.has("managerial")?o+=8:f.has("senior-ic")&&(o+=5),f.has("junior")&&(o-=15),f.has("consultant")&&(o-=3),Math.max(0,Math.min(100,o))}function K(e=10,n={}){let{easyApplyOnly:o=!0}=n,t=H(),r=pe(),s=new Set,i=new Set;for(let[m,p]of Object.entries(r))p.connectionStatus==="connected"&&s.add(m);let u={connectedRecruiters:s,conversationRecruiters:i},c=ye(),f=new Set(["applied","skipped","expired","archived"]);return Object.entries(t).filter(([m,p])=>{if(typeof p!="object"||o&&!p.isEasyApply||p.applied)return!1;let y=c[m];return!(y&&f.has(y.status))}).map(([m,p])=>({jobId:m,score:fo(p,u),job:p})).sort((m,p)=>{if(p.score!==m.score)return p.score-m.score;let y=m.job.scoutedAt||m.job.postedTime||"";return(p.job.scoutedAt||p.job.postedTime||"").localeCompare(y)}).slice(0,e)}function po(e){if(!e)return null;let n=e.match(/[\$£€CAD\s]*([\d,]+(?:\.\d+)?)\s*[kK]?/g);if(!n||n.length===0)return null;let o=n.map(t=>{let r=parseFloat(t.replace(/[^\d.]/g,""));return t.toLowerCase().includes("k")&&(r*=1e3),r}).filter(t=>t>0);return o.length>=2?(o[0]+o[1])/2:o.length===1?o[0]:null}import"dotenv/config";import*as v from"fs";import*as T from"path";import{fileURLToPath as bo}from"url";import"dotenv/config";import{createGraphClient as mo,resolveToken as ho}from"@ilivemylife/graph-sdk";import{config as go}from"dotenv";go();var be=ho()||process.env.TOKEN;be||(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 we=mo({token:be});function
|
|
5
|
+
`),process.exit(1));var we=mo({token:be});function yo(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let o=Math.floor(n/60),t=n%60;return t?`${o}m ${t}s`:`${o}m`}function So({scriptName:e,mode:n,status:o,error:t,duration:r}){let s=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),u=r?` ${yo(r)}`:"",c=o==="error"?`error${t?`: ${String(t).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",f=n&&n!=="default"?` (${n})`:"";return`${s} ${e}${f} \u2014 ${c} \u2014 ${i}${u}`}async function ve({scriptName:e,mode:n,status:o,summaryLines:t,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(t)||t.length===0)return;let c=`**${So({scriptName:e,mode:n,status:o,error:r,duration:s})}**
|
|
6
6
|
|
|
7
7
|
${t.join(`
|
|
8
|
-
`)}`;try{await we.addMessage(i,c)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var wo=bo(import.meta.url),vo=T.dirname(T.dirname(wo)),z=process.env.DATA_DIR?T.resolve(process.env.DATA_DIR,"collected-profiles"):T.join(vo,"collected-profiles"),Q=T.join(z,"run-log.json");function ko(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";v.writeFileSync(t,o);for(let r=0;r<3;r++)try{v.renameSync(t,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 ke(){try{if(!v.existsSync(Q))return{runs:[]};let e=JSON.parse(v.readFileSync(Q,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Ae(e){v.existsSync(z)||v.mkdirSync(z,{recursive:!0});try{ko(Q,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function $e(e,n="default"){let o=ke();for(let i of o.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let t=new Date,r={timestamp:t.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>s),Ae(o),{script:e,mode:n,startTime:t.getTime(),runIndex:o.runs.length-1}}function X(e,n,o=null,t=null){if(!e)return;let r=null;try{let i=ke(),u=i.runs[e.runIndex];if(u&&u.status==="running"&&u.script===e.script)u.status=n,u.result=n,u.duration=Date.now()-e.startTime,u.stats=o,u.error=t,r=u.duration;else{let c=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=o,c.error=t,r=c.duration)}Ae(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";ve({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:t,duration:r??Date.now()-e.startTime}).catch(u=>console.error(`[runLog] postRunReport failed: ${u.message}`))}}import"dotenv/config";import*as l from"fs";import*as ie from"os";import*as d from"path";import{fileURLToPath as Wo}from"url";var oe={};B(oe,{NAME:()=>$o,VERSION:()=>Ao,up:()=>Oo});import*as k from"fs";import*as V from"path";var Ao=1,$o="normalize-jobs-and-questions",jo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Eo=50;function Z(e){return k.existsSync(e)?JSON.parse(k.readFileSync(e,"utf-8")):null}function ee(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{k.writeFileSync(t,o)}catch(r){try{k.unlinkSync(t)}catch{}throw r}try{k.renameSync(t,e)}catch(r){try{k.unlinkSync(t)}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 Oo(e,n){let o=V.join(e,"jobs.json"),t=V.join(n,"scouted-jobs.json"),r=V.join(e,"application-questions.json"),s=Z(o)||{},i=Z(t)||{},u=0,c=[];for(let a of Object.keys(s)){if(!i[a])continue;let m=i[a],p=s[a];for(let g of jo)m[g]!=null&&p[g]==null&&(p[g]=m[g]);c.push(a),u++}u>0?(ee(o,s),console.log(` Phase 1: Merged ${u} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=Z(r);if(f&&Array.isArray(f.applications)){let a={},m=0;for(let p of f.applications){let g=p.jobId||"unknown";a[g]||(a[g]={applications:[]});let Y=(p.questions||[]).map(E=>{let P={type:E.type||"input",question:E.question||"",answer:E.answer||""};return E.options&&(E.options.length<=Eo?P.options=E.options:(P.optionsOmitted=!0,m++)),E.page&&(P.page=E.page),E.wasPreFilled&&(P.wasPreFilled=!0),E.wasRetry&&(P.wasRetry=!0),P});a[g].applications.push({applicationId:p.applicationId,date:p.date,result:p.result||"submitted",formPages:p.formPages||null,duration:p.duration||null,retries:p.retries||0,failedField:p.failedField||null,questionCount:p.questionCount||Y.length,questions:Y})}ee(r,a),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let a of c)delete i[a];ee(t,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 ne={};B(ne,{NAME:()=>Ro,VERSION:()=>Io,up:()=>Co});import*as A from"fs";import*as je from"path";var Io=2,Ro="reset-unread-flags";function To(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function Do(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{A.writeFileSync(t,o)}catch(r){try{A.unlinkSync(t)}catch{}throw r}try{A.renameSync(t,e)}catch(r){try{A.unlinkSync(t)}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 Co(e){let n=je.join(e,"conversations.json"),o=To(n);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let r of Object.keys(o))o[r].unread===!0&&(o[r].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Do(n,o),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var te={};B(te,{NAME:()=>_o,VERSION:()=>No,up:()=>Po});import*as $ from"fs";import*as Ee from"path";var No=3,_o="recompute-last-message-by",xo=new Set(["draft","confirmed","rejected","needs_review"]);function Fo(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Lo(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{$.writeFileSync(t,o)}catch(r){try{$.unlinkSync(t)}catch{}throw r}try{$.renameSync(t,e)}catch(r){try{$.unlinkSync(t)}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 Mo(e,n){if(!e||e.length===0)return"them";let o=e.filter(s=>!xo.has(s.status));if(o.length===0)return"them";let t=o.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=t.length>0?t:[...o].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 Po(e){let n=Ee.join(e,"conversations.json"),o=Fo(n);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let t=process.env.LINKEDIN_NAME;if(!t||typeof t!="string"||!t.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 u of Object.keys(o)){let c=o[u];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let f=Array.isArray(c.messages)?c.messages:[],a=Mo(f,t),m=a==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==a&&i++,c.lastMessageBy=a,c.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}Lo(n,o),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 re={};B(re,{NAME:()=>Jo,VERSION:()=>Uo,up:()=>Go});import*as j from"fs";import*as Oe from"path";var Uo=4,Jo="split-connection-timestamps",qo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Bo(e){if(!j.existsSync(e))return null;let n=j.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Vo(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{j.writeFileSync(t,o)}catch(r){try{j.unlinkSync(t)}catch{}throw r}try{j.renameSync(t,e)}catch(r){try{j.unlinkSync(t)}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=Oe.join(e,"people.json"),o=Bo(n);if(!o||typeof o!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let t=0,r=0;for(let s of Object.keys(o)){let i=o[s];!i||typeof i!="object"||(r++,qo.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Vo(n,o),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${t} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var Yo=Wo(import.meta.url),Ho=d.dirname(Yo),Ko=d.dirname(d.dirname(Ho));function zo(e){return e&&(e==="~"?ie.homedir():e.startsWith("~/")||e.startsWith("~\\")?d.join(ie.homedir(),e.slice(2)):e)}var O=process.env.DATA_DIR?d.resolve(zo(process.env.DATA_DIR)):Ko,F=d.join(O,"collected-profiles"),L=d.join(O,"market-research"),S=d.join(O,".schema-version"),Ie=[d.join(F,".schema-version"),d.join(L,".schema-version")],D=4,R=[{version:1,module:oe},{version:2,module:ne},{version:3,module:te},{version:4,module:re}];(function(){R.sort((t,r)=>t.version-r.version);let n=new Set;for(let t of R){if(!Number.isInteger(t.version)||t.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(t.version)} (must be positive integer)`);if(n.has(t.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${t.version}`);n.add(t.version);let r=t.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=R.length?R[R.length-1].version:0;if(o!==D)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${D}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<R.length;t++){let r=t+1;if(R[t].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${t} but found v${R[t].version}`)}})();function Ce(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
8
|
+
`)}`;try{await we.addMessage(i,c)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var wo=bo(import.meta.url),vo=T.dirname(T.dirname(wo)),z=process.env.DATA_DIR?T.resolve(process.env.DATA_DIR,"collected-profiles"):T.join(vo,"collected-profiles"),Q=T.join(z,"run-log.json");function ko(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";v.writeFileSync(t,o);for(let r=0;r<3;r++)try{v.renameSync(t,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 ke(){try{if(!v.existsSync(Q))return{runs:[]};let e=JSON.parse(v.readFileSync(Q,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Ae(e){v.existsSync(z)||v.mkdirSync(z,{recursive:!0});try{ko(Q,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function $e(e,n="default"){let o=ke();for(let i of o.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let t=new Date,r={timestamp:t.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>s),Ae(o),{script:e,mode:n,startTime:t.getTime(),runIndex:o.runs.length-1}}function X(e,n,o=null,t=null){if(!e)return;let r=null;try{let i=ke(),u=i.runs[e.runIndex];if(u&&u.status==="running"&&u.script===e.script)u.status=n,u.result=n,u.duration=Date.now()-e.startTime,u.stats=o,u.error=t,r=u.duration;else{let c=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=o,c.error=t,r=c.duration)}Ae(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";ve({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:t,duration:r??Date.now()-e.startTime}).catch(u=>console.error(`[runLog] postRunReport failed: ${u.message}`))}}import"dotenv/config";import*as l from"fs";import*as ie from"os";import*as d from"path";import{fileURLToPath as Wo}from"url";var oe={};B(oe,{NAME:()=>$o,VERSION:()=>Ao,up:()=>Oo});import*as k from"fs";import*as V from"path";var Ao=1,$o="normalize-jobs-and-questions",jo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Eo=50;function Z(e){return k.existsSync(e)?JSON.parse(k.readFileSync(e,"utf-8")):null}function ee(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{k.writeFileSync(t,o)}catch(r){try{k.unlinkSync(t)}catch{}throw r}try{k.renameSync(t,e)}catch(r){try{k.unlinkSync(t)}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 Oo(e,n){let o=V.join(e,"jobs.json"),t=V.join(n,"scouted-jobs.json"),r=V.join(e,"application-questions.json"),s=Z(o)||{},i=Z(t)||{},u=0,c=[];for(let a of Object.keys(s)){if(!i[a])continue;let m=i[a],p=s[a];for(let y of jo)m[y]!=null&&p[y]==null&&(p[y]=m[y]);c.push(a),u++}u>0?(ee(o,s),console.log(` Phase 1: Merged ${u} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=Z(r);if(f&&Array.isArray(f.applications)){let a={},m=0;for(let p of f.applications){let y=p.jobId||"unknown";a[y]||(a[y]={applications:[]});let Y=(p.questions||[]).map(E=>{let U={type:E.type||"input",question:E.question||"",answer:E.answer||""};return E.options&&(E.options.length<=Eo?U.options=E.options:(U.optionsOmitted=!0,m++)),E.page&&(U.page=E.page),E.wasPreFilled&&(U.wasPreFilled=!0),E.wasRetry&&(U.wasRetry=!0),U});a[y].applications.push({applicationId:p.applicationId,date:p.date,result:p.result||"submitted",formPages:p.formPages||null,duration:p.duration||null,retries:p.retries||0,failedField:p.failedField||null,questionCount:p.questionCount||Y.length,questions:Y})}ee(r,a),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let a of c)delete i[a];ee(t,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 ne={};B(ne,{NAME:()=>Ro,VERSION:()=>Io,up:()=>Do});import*as A from"fs";import*as je from"path";var Io=2,Ro="reset-unread-flags";function To(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function Co(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{A.writeFileSync(t,o)}catch(r){try{A.unlinkSync(t)}catch{}throw r}try{A.renameSync(t,e)}catch(r){try{A.unlinkSync(t)}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=je.join(e,"conversations.json"),o=To(n);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let r of Object.keys(o))o[r].unread===!0&&(o[r].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Co(n,o),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var te={};B(te,{NAME:()=>_o,VERSION:()=>No,up:()=>Uo});import*as $ from"fs";import*as Ee from"path";var No=3,_o="recompute-last-message-by",xo=new Set(["draft","confirmed","rejected","needs_review"]);function Fo(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Lo(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{$.writeFileSync(t,o)}catch(r){try{$.unlinkSync(t)}catch{}throw r}try{$.renameSync(t,e)}catch(r){try{$.unlinkSync(t)}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 Mo(e,n){if(!e||e.length===0)return"them";let o=e.filter(s=>!xo.has(s.status));if(o.length===0)return"them";let t=o.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=t.length>0?t:[...o].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 Uo(e){let n=Ee.join(e,"conversations.json"),o=Fo(n);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let t=process.env.LINKEDIN_NAME;if(!t||typeof t!="string"||!t.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 u of Object.keys(o)){let c=o[u];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let f=Array.isArray(c.messages)?c.messages:[],a=Mo(f,t),m=a==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==a&&i++,c.lastMessageBy=a,c.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}Lo(n,o),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 re={};B(re,{NAME:()=>Jo,VERSION:()=>Po,up:()=>Go});import*as j from"fs";import*as Oe from"path";var Po=4,Jo="split-connection-timestamps",qo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Bo(e){if(!j.existsSync(e))return null;let n=j.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Vo(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{j.writeFileSync(t,o)}catch(r){try{j.unlinkSync(t)}catch{}throw r}try{j.renameSync(t,e)}catch(r){try{j.unlinkSync(t)}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=Oe.join(e,"people.json"),o=Bo(n);if(!o||typeof o!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let t=0,r=0;for(let s of Object.keys(o)){let i=o[s];!i||typeof i!="object"||(r++,qo.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Vo(n,o),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${t} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var Yo=Wo(import.meta.url),Ho=d.dirname(Yo),Ko=d.dirname(d.dirname(Ho));function zo(e){return e&&(e==="~"?ie.homedir():e.startsWith("~/")||e.startsWith("~\\")?d.join(ie.homedir(),e.slice(2)):e)}var O=process.env.DATA_DIR?d.resolve(zo(process.env.DATA_DIR)):Ko,F=d.join(O,"collected-profiles"),L=d.join(O,"market-research"),S=d.join(O,".schema-version"),Ie=[d.join(F,".schema-version"),d.join(L,".schema-version")],C=4,R=[{version:1,module:oe},{version:2,module:ne},{version:3,module:te},{version:4,module:re}];(function(){R.sort((t,r)=>t.version-r.version);let n=new Set;for(let t of R){if(!Number.isInteger(t.version)||t.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(t.version)} (must be positive integer)`);if(n.has(t.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${t.version}`);n.add(t.version);let r=t.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=R.length?R[R.length-1].version:0;if(o!==C)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${C}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<R.length;t++){let r=t+1;if(R[t].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${t} but found v${R[t].version}`)}})();function De(){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
10
|
`),process.exit(1));try{l.mkdirSync(O,{recursive:!0})}catch(n){n.code!=="EEXIST"&&(console.error(`
|
|
11
11
|
[FATAL] Cannot create DATA_DIR (${O}): ${n.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -27,15 +27,15 @@ ${t.join(`
|
|
|
27
27
|
[FATAL] ${S} is not valid JSON: ${o.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
28
28
|
`),process.exit(1)}let n=en(e);return n===null&&(console.error(`
|
|
29
29
|
[FATAL] ${S} 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 Ne(e){try{l.chmodSync(e,384)}catch{}}function on(e){if(
|
|
31
|
-
[FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${
|
|
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${
|
|
30
|
+
`),process.exit(1)),n}function Ne(e){try{l.chmodSync(e,384)}catch{}}function on(e){if(De(),l.existsSync(S))try{if(l.lstatSync(S).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${S}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(o){if(o.message?.includes("symbolic link"))throw o}let n=S+".tmp";try{l.writeFileSync(n,JSON.stringify(e,null,2)),Ne(n),l.renameSync(n,S)}catch(o){try{l.unlinkSync(n)}catch{}throw o}}function Ce(e,n){if(!l.existsSync(e))return;let o=`.pre-v${String(n).padStart(3,"0")}.backup`,t=l.readdirSync(e).filter(u=>{let c=u.toLowerCase();if(c.includes(".backup")||c===".schema-version"||c.endsWith(".tmp"))return!1;try{return l.statSync(d.join(e,u)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let u of t){let c=d.join(e,u),f=d.join(e,u+o);if(l.existsSync(f)){s++;continue}try{xe(c,f),r++}catch(a){i.push({file:u,err:a.message})}}if(i.length>0){let u=new Error(`Failed to back up ${i.length} file(s) in ${d.basename(e)}/: `+i.map(c=>`${c.file} (${c.err})`).join(", "));throw u.code="BACKUP_INCOMPLETE",u}if(r>0||s>0){let u=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${d.basename(e)}/ (${o})${u}`)}}var se=!1;async function _e(){if(se)return;De(),cn();let n=Te().version;if(n===C){se=!0;return}Xo(),Qo(),process.on("exit",ce),n>C&&(console.error(`
|
|
31
|
+
[FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${C}.`),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${C}.
|
|
33
33
|
`),process.exit(1)),console.log(`
|
|
34
|
-
\u{1F4E6} Schema migration: v${n} \u2192 v${
|
|
34
|
+
\u{1F4E6} Schema migration: v${n} \u2192 v${C}`);let o=ln();if(!o.ok){console.error(`
|
|
35
35
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of o.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
36
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
37
|
`),process.exit(1)}let t=R.filter(r=>r.version>n);for(let r of t){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{
|
|
38
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{Ce(F,r.version),Ce(L,r.version)}catch(c){console.error(`
|
|
39
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
40
|
`),process.exit(1)}let u=r.module;try{await u.up(F,L)}catch(c){console.error(`
|
|
41
41
|
[FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let f=an(i);f.ok?(console.error(` \u2713 Auto-rollback restored ${f.restored} files. Schema stays at v${n}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
@@ -44,15 +44,15 @@ ${t.join(`
|
|
|
44
44
|
`)}process.exit(1)}try{let c=new Date().toISOString(),f={version:r.version,name:u.NAME||s,appliedAt:c},a=Te();a.version=r.version,a.migratedAt=c,a.migrations=a.migrations||[],a.migrations.push(f),on(a)}catch(c){console.error(`
|
|
45
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
46
|
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{fe()}catch{}try{he()}catch{}se=!0,ce(),console.log(`
|
|
47
|
-
\u2713 Schema is now at v${
|
|
47
|
+
\u2713 Schema is now at v${C}
|
|
48
48
|
`)}var nn=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function tn(e){let n=e.toLowerCase();return nn.some(o=>o.test(n))}var rn=6e4;function sn(){let e=Date.now(),n=[];for(let o of[O,F,L]){if(!l.existsSync(o))continue;let t;try{t=l.readdirSync(o)}catch{continue}for(let r of t){if(!tn(r))continue;let s=d.join(o,r);try{let i=l.statSync(s);if(!i.isFile()||e-i.mtimeMs<rn)continue;n.push({dir:o,file:r,fullPath:s})}catch{}}}return n}function cn({verbose:e=!1}={}){let n=sn();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let t of n)try{l.unlinkSync(t.fullPath),o++,e&&console.log(` Removed orphan: ${d.basename(t.dir)}/${t.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${r.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function ln(){let e=[];for(let n of[F,L]){if(!l.existsSync(n))continue;let o=l.readdirSync(n).filter(t=>{let r=t.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let t of o){let r=d.join(n,t);try{G(r)}catch(s){e.push({dir:d.basename(n),file:t,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function an(e){let n=[],o=[];for(let s of[F,L]){if(!l.existsSync(s))continue;let i=l.readdirSync(s).filter(u=>u.endsWith(e));for(let u of i){let c=d.join(s,u),f=u.slice(0,-e.length),a=d.join(s,f);try{f.toLowerCase().endsWith(".json")?G(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:a,fileName:u,dir:s})}catch(m){o.push(`${d.basename(s)}/${u}: ${m.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let t=0,r=[];for(let{backupPath:s,originalPath:i,fileName:u,dir:c}of n)try{xe(s,i),t++}catch(f){r.push(`${d.basename(c)}/${u}: ${f.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:t}:{ok:!0,restored:t}}function xe(e,n){let o=n+".tmp";try{l.copyFileSync(e,o),Ne(o)}catch(t){try{l.unlinkSync(o)}catch{}throw t}try{l.renameSync(o,n)}catch(t){try{l.unlinkSync(o)}catch{}if(t.code==="EPERM"||t.code==="EBUSY"){let r=new Error(`File locked: ${n} (${t.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=t.code,r}throw t}}var pn=un(import.meta.url),dn=M.dirname(pn),le=process.env.DATA_DIR?M.resolve(process.env.DATA_DIR,"collected-profiles"):M.join(dn,"collected-profiles");await _e();var ae=process.argv.slice(2),Fe=parseInt(ae.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),W=parseInt(ae.find(e=>e.startsWith("--min-score="))?.split("=")[1]||"50"),mn=ae.includes("--list");function hn(){let n=K(20,{easyApplyOnly:!0}).filter(o=>o.score>=W);if(console.log(`
|
|
49
49
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` APPLY QUEUE (${n.length} jobs, min score ${W})`),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"),n.length===0)console.log(" No jobs in queue. Run: npm run scout");else for(let o=0;o<n.length;o++){let{score:t,job:r,jobId:s}=n[o],i=(r.techStack||[]).slice(0,4).join(", ");console.log(` ${String(o+1).padStart(2)}. [${t}] ${(r.title||"?").slice(0,35)} @ ${(r.company||"?").slice(0,20)}`),console.log(` ${r.salary||"no salary"} | ${r.location||"?"} | ${i||"no tech"}`),console.log(` ${r.url}`)}console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
50
|
-
`)}async function
|
|
50
|
+
`)}async function gn(){if(console.log(`
|
|
51
51
|
LinkedIn Apply Queue
|
|
52
52
|
`),mn){hn();return}let n=K(Fe*3,{easyApplyOnly:!0}).filter(s=>s.score>=W).slice(0,Fe);if(n.length===0){console.log(` No jobs to apply. Run: npm run scout
|
|
53
53
|
`);return}console.log(` Applying to ${n.length} jobs (score >= ${W}):
|
|
54
|
-
`);for(let{score:s,job:i}of n)console.log(` [${s}] ${(i.title||"?").slice(0,40)} @ ${(i.company||"?").slice(0,20)}`);
|
|
55
|
-
Generated ${o} with ${t.length} jobs`);for(let{jobId:s}of n)
|
|
54
|
+
`);for(let{score:s,job:i}of n)console.log(` [${s}] ${(i.title||"?").slice(0,40)} @ ${(i.company||"?").slice(0,20)}`);D.existsSync(le)||D.mkdirSync(le,{recursive:!0});let o=M.join(le,"apply-queue-urls.json"),t=n.map(({job:s,jobId:i})=>({url:s.url,title:s.title,company:s.company,location:s.location,salary:s.salary}));D.writeFileSync(o,JSON.stringify(t,null,2)),console.log(`
|
|
55
|
+
Generated ${o} with ${t.length} jobs`);for(let{jobId:s}of n)ge(s,{queued:!0,queuedAt:new Date().toISOString().slice(0,10)});let r=$e("apply-queue",`${n.length} jobs`);console.log(`
|
|
56
56
|
Launching run.mjs --job-urls...
|
|
57
57
|
`);try{fn("node",["run.mjs",`--job-urls=${o}`],{stdio:"inherit",timeout:144e5}),X(r,"success",{applied:n.length})}catch(s){console.error(`
|
|
58
|
-
Apply queue error: ${s.message?.slice(0,80)}`),X(r,"error",{applied:n.length},s.message)}try{
|
|
58
|
+
Apply queue error: ${s.message?.slice(0,80)}`),X(r,"error",{applied:n.length},s.message)}try{D.unlinkSync(o)}catch{}}gn().catch(e=>{console.error("Apply queue failed:",e),process.exit(1)});
|