ilml-plugin-linkedin 1.11.9 → 1.12.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/CHANGELOG.md +11 -1
- package/README.md +7 -1
- package/dist/applyQueue.mjs +4 -4
- package/dist/daily.mjs +4 -4
- package/dist/enrichProfile.mjs +41 -0
- package/dist/enrichProfiles.mjs +84 -38
- package/dist/funnelRunner.mjs +46 -43
- package/dist/help.mjs +15 -0
- package/dist/messageBot.mjs +11 -11
- package/dist/profileHistory.mjs +5 -5
- package/dist/run.mjs +60 -57
- package/dist/scout.mjs +7 -7
- package/dist/syncAll.mjs +19 -19
- package/dist/verifyAbout.mjs +10 -7
- package/dist/viewers.mjs +9 -9
- package/dist/visit.mjs +43 -40
- package/ilml-plugin.json +53 -24
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.12.0
|
|
4
|
+
- **`ilml linkedin enrich-profile <profile-url>` — pull the full picture on one person into your local contacts DB.** Visits the profile and saves headline, location, About, company, and other basics. Add `--with-experience` and it also pulls the structured Experience list — every role with company, dates, location, description, and skills. Single-URL, on-demand — no batch mode here. Self-profile is recognised (by URL or by your configured name) and printed to your terminal instead of being added to the contacts DB. Run `ilml linkedin enrich-profile --help` for full usage.
|
|
5
|
+
- **`ilml linkedin enrich-profiles --with-experience` — same Experience extraction, in batch.** When you batch-enrich contacts that have missing info (still capped at 10/session by default), each visit can now also pull the structured Experience. An extra ban-risk warning prints because each profile now costs 2 page loads instead of 1 — keep `--max` low.
|
|
6
|
+
- **`ilml linkedin help` — discover what every command does.** Lists all 20+ commands with short descriptions and risk levels (HIGH ban-risk ones marked ⚠). Run `ilml linkedin help <cmd>` for a detailed view of one command — usage, flags, ban-risk, when to use it.
|
|
7
|
+
- **New config field: `MY_LINKEDIN_URL`** (optional, in LinkedIn account section — visible in `ilml plugin config linkedin`). Set it to your own profile URL so `enrich-profile` can recognise your own profile precisely (more robust than the name-match fallback, especially if someone in your network has the same name).
|
|
8
|
+
- **Safer self-detection.** `enrich-profile` refuses to run if neither `MY_LINKEDIN_URL` nor `LINKEDIN_NAME` is set — without one of those it can't reliably tell own profile from a contact, so it stops rather than risk saving you into your own contacts DB.
|
|
9
|
+
- **Auth-wall awareness in batch enrichment.** If your LinkedIn session expires mid-batch (redirected to login), the script now notices and stops cleanly instead of silently burning through your daily quota writing partial records. You'll see a clear error and can `ilml linkedin login` to refresh.
|
|
10
|
+
- **Existing data is preserved on extraction failures.** If a profile visit hits a hiccup (LinkedIn DOM change, network glitch, partial load), previously-saved info on that profile is kept rather than wiped. New Experience data is additive — only appears on a profile after you explicitly enrich it. No migration needed.
|
|
11
|
+
- **Better discoverability for AI assistants.** Per-command description and ban-risk metadata now lives in the plugin manifest, so a Claude / ChatGPT / Cursor / Codex agent helping you with the plugin can read it and pick the right command without guessing.
|
|
12
|
+
|
|
3
13
|
## 1.11.9
|
|
4
|
-
- **`apply` no longer
|
|
14
|
+
- **`apply` no longer ends with "0 jobs" when the search page loads slowly.** The run scraped the job-results list the moment the page reported `DOMContentLoaded`, but on a slow connection LinkedIn finishes that event well before it paints the job cards — so the scrape came back empty, the run concluded "no jobs", and the browser closed even though jobs were on their way. Apply now waits (up to 30s) for the first job card to render before reading the list; a fast connection waits only as long as the cards actually take to appear. When the list is genuinely empty it now logs why — no cards at all (slow load, empty search, or changed markup) vs. cards present but none Easy Apply — so a "0 jobs" run is debuggable instead of silent.
|
|
5
15
|
- No schema migration; behavior fix only.
|
|
6
16
|
|
|
7
17
|
## 1.11.8
|
package/README.md
CHANGED
|
@@ -175,9 +175,15 @@ Sessions live in your active ilml scope (`<scope>/.ilivemylife/plugins-state/lin
|
|
|
175
175
|
| `ilml linkedin viewers` | Pull the "who viewed your profile" list. |
|
|
176
176
|
| `ilml linkedin warm-scan` | Find 1st-degree connections at target companies (offline, no browser). Reads your already-synced people / conversations and groups them by company so you know who you can message directly versus where you need cold outreach. Override the company list via `--companies="Anthropic,OpenAI"` or pick a named group with `--group=topPaying`. |
|
|
177
177
|
| `ilml linkedin daily` | Full pipeline in one command: `sync-all` → `apply` → `scout` → `funnel` → `visit` → `viewers` → run report. |
|
|
178
|
+
| `ilml linkedin enrich-profile <url> [--with-experience]` | Visit ONE profile by URL, save what we learn to `people.json`. Self-profile (recognised via `MY_LINKEDIN_URL` / `LINKEDIN_NAME`) prints to stdout instead of saving. `--with-experience` adds a structured experience array (2 page loads, normal human pattern). Single-URL only — no batch mode. `--help` for full details. |
|
|
179
|
+
| `ilml linkedin enrich-profiles [--with-experience]` | **⚠ HIGH BAN RISK** — batch-visit contacts with missing About text, fill basic fields. Cap 10/session by default (`--max=N` to change). `--with-experience` doubles per-profile page loads. `--connections` for lower risk (1st-degree only). `--match-title="recruiter\|founder"` to filter by role. `--list` for stats-only. `--help` for full details. |
|
|
178
180
|
| `ilml linkedin login` | Re-save LinkedIn cookies after a session expires. |
|
|
179
181
|
|
|
180
|
-
Run `ilml linkedin` (no subcommand) any time to see the list.
|
|
182
|
+
Run `ilml linkedin` (no subcommand) any time to see the list. Any command above supports `--help` for full usage and flags (the new `enrich-profile` / `enrich-profiles` definitely do; older commands print usage when called with bad arguments).
|
|
183
|
+
|
|
184
|
+
### For AI agents using this plugin
|
|
185
|
+
|
|
186
|
+
If an AI agent is figuring out how to drive this plugin, the canonical machine-readable command surface lives in [`ilml-plugin.json`](./ilml-plugin.json). The `commands` object includes per-command `description`, `usage`, `flags`, `banRisk`, and `useWhen` fields for the higher-stakes commands (`enrich-profile`, `enrich-profiles`) — read that before invoking. The `config.sections[].fields[]` array tells you which env vars are required vs optional and what each does. Per-command `--help` is the fast way to see the flag list interactively.
|
|
181
187
|
|
|
182
188
|
## Common routines
|
|
183
189
|
|
package/dist/applyQueue.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var Ce=Object.defineProperty;var G=(e,n)=>{for(var o in n)Ce(e,o,{get:n[o],enumerable:!0})};import"dotenv/config";import*as D from"fs";import*as L from"path";import{fileURLToPath as Zo}from"url";import{execFileSync as en}from"child_process";import{getPluginConfig as _e}from"@ilivemylife/graph-sdk";var xe=await _e();for(let[e,n]of Object.entries(xe))process.env[e]===void 0&&(process.env[e]=n);var an=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),un=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),fn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as
|
|
1
|
+
var Ce=Object.defineProperty;var G=(e,n)=>{for(var o in n)Ce(e,o,{get:n[o],enumerable:!0})};import"dotenv/config";import*as D from"fs";import*as L from"path";import{fileURLToPath as Zo}from"url";import{execFileSync as en}from"child_process";import{getPluginConfig as _e}from"@ilivemylife/graph-sdk";var xe=await _e();for(let[e,n]of Object.entries(xe))process.env[e]===void 0&&(process.env[e]=n);var an=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),un=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),fn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as m from"fs";import*as g from"path";import{fileURLToPath as Fe}from"url";var Le=Fe(import.meta.url),Me=g.dirname(g.dirname(Le)),E=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"collected-profiles"):g.join(Me,"collected-profiles"),Pe=g.join(E,"people.json"),gn=g.join(E,"jobs.json"),yn=g.join(E,"quota.json"),Sn=g.join(E,"conversations.json"),bn=g.join(E,"sync-state.json"),vn=g.join(E,"application-questions.json"),wn=g.join(E,"profile-history");var P=null,Je=null,Ue=null,Be=null,qe=null,Ve=null;function le(){P=null,Je=null,Ue=null,Be=null,qe=null,Ve=null}function We(){m.existsSync(E)||m.mkdirSync(E,{recursive:!0})}function Ge(e,n){if(!m.existsSync(e))return null;try{let o=JSON.parse(m.readFileSync(e,"utf-8"));try{m.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(m.existsSync(t))try{let s=JSON.parse(m.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{m.copyFileSync(t,e)}catch{}return s}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{m.copyFileSync(e,e+".corrupted")}catch{}return null}}function ae(){return P||(We(),P=Ge(Pe,"people.json")||{},P)}import"dotenv/config";import*as v from"fs";import*as b from"path";import{fileURLToPath as Ye}from"url";var He=Ye(import.meta.url),Ke=b.dirname(b.dirname(He)),C=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"market-research"):b.join(Ke,"market-research"),ue=b.join(C,"scouted-jobs.json"),jn=b.join(C,"discovered-people.json"),On=b.join(C,"visit-log.json"),En=b.join(C,"companies.json"),Qe=b.join(C,"job-decisions.json");function ze(){v.existsSync(C)||v.mkdirSync(C,{recursive:!0})}function Xe(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";v.writeFileSync(t,o);for(let s=0;s<3;s++)try{v.renameSync(t,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 fe(e){try{if(v.existsSync(e))return JSON.parse(v.readFileSync(e,"utf-8"))}catch{}return null}function pe(){J=null,U=null,Ze=null,eo=null,oo=null}var J=null;function Y(){return J||(J=fe(ue)||{},J)}function de(e,n){if(!e)return;ze();let o=Y(),t=new Date().toISOString().slice(0,10);if(o[e]){for(let[s,r]of Object.entries(n))r!=null&&(o[e][s]=r);o[e].lastSeen=t}else o[e]={...n,scoutedAt:t,lastSeen:t};try{Xe(ue,o)}catch(s){console.error(`[!] Failed to save scouted-jobs.json: ${s.message}`)}}var U=null;function he(){return U||(U=fe(Qe)||{},U)}var Ze=null;var eo=null;var oo=null;var no=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"]),to=new Set(["iot","machine learning","ai","data engineering","spark","go","rust","kotlin","next.js","devops","sre"]),me=["vancouver","british columbia"],so=["canada","montreal","quebec","alberta","calgary","ottawa"],ro=["toronto","ontario"],io=["india","pakistan","nigeria","philippines"];function co(e,n={}){let o=0,t=(e.techStack||[]).map(a=>a.toLowerCase()),s=0,r=0;for(let a of t)no.has(a)&&s++,to.has(a)&&r++;if(o+=Math.min(s*6,24),o+=Math.min(r*3,6),e.salary){let a=lo(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";io.some(a=>i.includes(a))?o-=30:u&&/united states|usa|\bus\b/i.test(i)?o+=25:u&&me.some(a=>i.includes(a))?o+=22:u?o+=20:me.some(a=>i.includes(a))?o+=18:so.some(a=>i.includes(a))?o+=10:ro.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 H(e=10,n={}){let{easyApplyOnly:o=!0}=n,t=Y(),s=ae(),r=new Set,i=new Set;for(let[h,p]of Object.entries(s))p.connectionStatus==="connected"&&r.add(h);let u={connectedRecruiters:r,conversationRecruiters:i},c=he(),f=new Set(["applied","skipped","expired","archived"]);return Object.entries(t).filter(([h,p])=>{if(typeof p!="object"||o&&!p.isEasyApply||p.applied)return!1;let y=c[h];return!(y&&f.has(y.status))}).map(([h,p])=>({jobId:h,score:co(p,u),job:p})).sort((h,p)=>{if(p.score!==h.score)return p.score-h.score;let y=h.job.scoutedAt||h.job.postedTime||"";return(p.job.scoutedAt||p.job.postedTime||"").localeCompare(y)}).slice(0,e)}function lo(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 s=parseFloat(t.replace(/[^\d.]/g,""));return t.toLowerCase().includes("k")&&(s*=1e3),s}).filter(t=>t>0);return o.length>=2?(o[0]+o[1])/2:o.length===1?o[0]:null}import"dotenv/config";import*as w from"fs";import*as I from"path";import{fileURLToPath as mo}from"url";import"dotenv/config";import{createGraphClient as ao,resolveToken as uo}from"@ilivemylife/graph-sdk";import{config as fo}from"dotenv";fo();var ge=uo()||process.env.TOKEN;ge||(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 ye=ao({token:ge});function po(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
|
|
5
|
+
`),process.exit(1));var ye=ao({token:ge});function po(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 ho({scriptName:e,mode:n,status:o,error:t,duration:s}){let r=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),u=s?` ${po(s)}`:"",c=o==="error"?`error${t?`: ${String(t).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",f=n&&n!=="default"?` (${n})`:"";return`${r} ${e}${f} \u2014 ${c} \u2014 ${i}${u}`}async function Se({scriptName:e,mode:n,status:o,summaryLines:t,error:s,duration:r}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(t)||t.length===0)return;let c=`**${ho({scriptName:e,mode:n,status:o,error:s,duration:r})}**
|
|
6
6
|
|
|
7
7
|
${t.join(`
|
|
8
|
-
`)}`;try{await ye.addMessage(i,c)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var go=
|
|
8
|
+
`)}`;try{await ye.addMessage(i,c)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var go=mo(import.meta.url),yo=I.dirname(I.dirname(go)),K=process.env.DATA_DIR?I.resolve(process.env.DATA_DIR,"collected-profiles"):I.join(yo,"collected-profiles"),Q=I.join(K,"run-log.json");function So(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";w.writeFileSync(t,o);for(let s=0;s<3;s++)try{w.renameSync(t,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 be(){try{if(!w.existsSync(Q))return{runs:[]};let e=JSON.parse(w.readFileSync(Q,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ve(e){w.existsSync(K)||w.mkdirSync(K,{recursive:!0});try{So(Q,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function we(e,n="default"){let o=be();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,s={timestamp:t.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(s);let r=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>r),ve(o),{script:e,mode:n,startTime:t.getTime(),runIndex:o.runs.length-1}}function z(e,n,o=null,t=null){if(!e)return;let s=null;try{let i=be(),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,s=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,s=c.duration)}ve(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let r=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(r&&r.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";Se({scriptName:e.script,mode:e.mode,status:i,summaryLines:r,error:t,duration:s??Date.now()-e.startTime}).catch(u=>console.error(`[runLog] postRunReport failed: ${u.message}`))}}import"dotenv/config";import*as l from"fs";import*as se from"os";import*as d from"path";import{fileURLToPath as Fo}from"url";var ee={};G(ee,{NAME:()=>vo,VERSION:()=>bo,up:()=>ko});import*as $ from"fs";import*as B from"path";var bo=1,vo="normalize-jobs-and-questions",wo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],$o=50;function X(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Z(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{$.writeFileSync(t,o)}catch(s){try{$.unlinkSync(t)}catch{}throw s}try{$.renameSync(t,e)}catch(s){try{$.unlinkSync(t)}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 ko(e,n){let o=B.join(e,"jobs.json"),t=B.join(n,"scouted-jobs.json"),s=B.join(e,"application-questions.json"),r=X(o)||{},i=X(t)||{},u=0,c=[];for(let a of Object.keys(r)){if(!i[a])continue;let h=i[a],p=r[a];for(let y of wo)h[y]!=null&&p[y]==null&&(p[y]=h[y]);c.push(a),u++}u>0?(Z(o,r),console.log(` Phase 1: Merged ${u} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=X(s);if(f&&Array.isArray(f.applications)){let a={},h=0;for(let p of f.applications){let y=p.jobId||"unknown";a[y]||(a[y]={applications:[]});let W=(p.questions||[]).map(j=>{let M={type:j.type||"input",question:j.question||"",answer:j.answer||""};return j.options&&(j.options.length<=$o?M.options=j.options:(M.optionsOmitted=!0,h++)),j.page&&(M.page=j.page),j.wasPreFilled&&(M.wasPreFilled=!0),j.wasRetry&&(M.wasRetry=!0),M});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||W.length,questions:W})}Z(s,a),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),h>0&&console.log(` Phase 2: Stripped bloated options from ${h} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let a of c)delete i[a];Z(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 oe={};G(oe,{NAME:()=>jo,VERSION:()=>Ao,up:()=>Ro});import*as k from"fs";import*as $e from"path";var Ao=2,jo="reset-unread-flags";function Oo(e){return k.existsSync(e)?JSON.parse(k.readFileSync(e,"utf-8")):null}function Eo(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{k.writeFileSync(t,o)}catch(s){try{k.unlinkSync(t)}catch{}throw s}try{k.renameSync(t,e)}catch(s){try{k.unlinkSync(t)}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 Ro(e){let n=$e.join(e,"conversations.json"),o=Oo(n);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let s of Object.keys(o))o[s].unread===!0&&(o[s].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Eo(n,o),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var ne={};G(ne,{NAME:()=>To,VERSION:()=>Io,up:()=>xo});import*as A from"fs";import*as ke from"path";var Io=3,To="recompute-last-message-by",Do=new Set(["draft","confirmed","rejected","needs_review"]);function No(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(s){try{A.unlinkSync(t)}catch{}throw s}try{A.renameSync(t,e)}catch(s){try{A.unlinkSync(t)}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 _o(e,n){if(!e||e.length===0)return"them";let o=e.filter(r=>!Do.has(r.status));if(o.length===0)return"them";let t=o.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=t.length>0?t:[...o].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 xo(e){let n=ke.join(e,"conversations.json"),o=No(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 s=0,r=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,r++);let f=Array.isArray(c.messages)?c.messages:[],a=_o(f,t),h=a==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==a&&i++,c.lastMessageBy=a,c.conversationStatus=h,s++}if(s===0){console.log(" No conversations to recompute.");return}Co(n,o),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 Lo=Fo(import.meta.url),Mo=d.dirname(Lo),Po=d.dirname(d.dirname(Mo));function Jo(e){return e&&(e==="~"?se.homedir():e.startsWith("~/")||e.startsWith("~\\")?d.join(se.homedir(),e.slice(2)):e)}var O=process.env.DATA_DIR?d.resolve(Jo(process.env.DATA_DIR)):Po,x=d.join(O,"collected-profiles"),F=d.join(O,"market-research"),S=d.join(O,".schema-version"),Ae=[d.join(x,".schema-version"),d.join(F,".schema-version")],T=3,R=[{version:1,module:ee},{version:2,module:oe},{version:3,module:ne}];(function(){R.sort((t,s)=>t.version-s.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 s=t.module;if(!s||typeof s.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(s.VERSION!==void 0&&s.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${s.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=R.length?R[R.length-1].version:0;if(o!==T)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${T}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<R.length;t++){let s=t+1;if(R[t].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${t} but found v${R[t].version}`)}})();function Re(){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.
|
|
@@ -45,7 +45,7 @@ ${t.join(`
|
|
|
45
45
|
[FATAL] Migration ${r} applied successfully but schema version file could NOT be updated: ${c.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
46
|
`),process.exit(1)}console.log(` \u2713 Migration ${r} complete`)}try{le()}catch{}try{pe()}catch{}te=!0,re(),console.log(`
|
|
47
47
|
\u2713 Schema is now at v${T}
|
|
48
|
-
`)}var Go=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Yo(e){let n=e.toLowerCase();return Go.some(o=>o.test(n))}var Ho=6e4;function Ko(){let e=Date.now(),n=[];for(let o of[O,x,F]){if(!l.existsSync(o))continue;let t;try{t=l.readdirSync(o)}catch{continue}for(let s of t){if(!Yo(s))continue;let r=d.join(o,s);try{let i=l.statSync(r);if(!i.isFile()||e-i.mtimeMs<Ho)continue;n.push({dir:o,file:s,fullPath:r})}catch{}}}return n}function Qo({verbose:e=!1}={}){let n=Ko();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(s){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${s.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function zo(){let e=[];for(let n of[x,F]){if(!l.existsSync(n))continue;let o=l.readdirSync(n).filter(t=>{let s=t.toLowerCase();return s.endsWith(".json")&&!s.includes(".backup")});for(let t of o){let s=d.join(n,t);try{q(s)}catch(r){e.push({dir:d.basename(n),file:t,err:r.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Xo(e){let n=[],o=[];for(let r of[x,F]){if(!l.existsSync(r))continue;let i=l.readdirSync(r).filter(u=>u.endsWith(e));for(let u of i){let c=d.join(r,u),f=u.slice(0,-e.length),a=d.join(r,f);try{f.toLowerCase().endsWith(".json")?q(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:a,fileName:u,dir:r})}catch(
|
|
48
|
+
`)}var Go=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Yo(e){let n=e.toLowerCase();return Go.some(o=>o.test(n))}var Ho=6e4;function Ko(){let e=Date.now(),n=[];for(let o of[O,x,F]){if(!l.existsSync(o))continue;let t;try{t=l.readdirSync(o)}catch{continue}for(let s of t){if(!Yo(s))continue;let r=d.join(o,s);try{let i=l.statSync(r);if(!i.isFile()||e-i.mtimeMs<Ho)continue;n.push({dir:o,file:s,fullPath:r})}catch{}}}return n}function Qo({verbose:e=!1}={}){let n=Ko();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(s){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${s.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function zo(){let e=[];for(let n of[x,F]){if(!l.existsSync(n))continue;let o=l.readdirSync(n).filter(t=>{let s=t.toLowerCase();return s.endsWith(".json")&&!s.includes(".backup")});for(let t of o){let s=d.join(n,t);try{q(s)}catch(r){e.push({dir:d.basename(n),file:t,err:r.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Xo(e){let n=[],o=[];for(let r of[x,F]){if(!l.existsSync(r))continue;let i=l.readdirSync(r).filter(u=>u.endsWith(e));for(let u of i){let c=d.join(r,u),f=u.slice(0,-e.length),a=d.join(r,f);try{f.toLowerCase().endsWith(".json")?q(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:a,fileName:u,dir:r})}catch(h){o.push(`${d.basename(r)}/${u}: ${h.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let t=0,s=[];for(let{backupPath:r,originalPath:i,fileName:u,dir:c}of n)try{De(r,i),t++}catch(f){s.push(`${d.basename(c)}/${u}: ${f.message}`)}return s.length>0?{ok:!1,error:s.join("; "),restored:t}:{ok:!0,restored:t}}function De(e,n){let o=n+".tmp";try{l.copyFileSync(e,o),Ie(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 s=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 s.code=t.code,s}throw t}}var on=Zo(import.meta.url),nn=L.dirname(on),ie=process.env.DATA_DIR?L.resolve(process.env.DATA_DIR,"collected-profiles"):L.join(nn,"collected-profiles");await Te();var ce=process.argv.slice(2),Ne=parseInt(ce.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),V=parseInt(ce.find(e=>e.startsWith("--min-score="))?.split("=")[1]||"50"),tn=ce.includes("--list");function sn(){let n=H(20,{easyApplyOnly:!0}).filter(o=>o.score>=V);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 ${V})`),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:s,jobId:r}=n[o],i=(s.techStack||[]).slice(0,4).join(", ");console.log(` ${String(o+1).padStart(2)}. [${t}] ${(s.title||"?").slice(0,35)} @ ${(s.company||"?").slice(0,20)}`),console.log(` ${s.salary||"no salary"} | ${s.location||"?"} | ${i||"no tech"}`),console.log(` ${s.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
50
|
`)}async function rn(){if(console.log(`
|
|
51
51
|
LinkedIn Apply Queue
|
package/dist/daily.mjs
CHANGED
|
@@ -5,7 +5,7 @@ var Ce=Object.defineProperty;var W=(e,n)=>{for(var t in n)Ce(e,t,{get:n[t],enume
|
|
|
5
5
|
`),process.exit(1));var se=_e({token:te});function Le(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 Me({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?` ${Le(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 re({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=`**${Me({scriptName:e,mode:n,status:t,error:s,duration:r})}**
|
|
6
6
|
|
|
7
7
|
${o.join(`
|
|
8
|
-
`)}`;try{await se.addMessage(i,l)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Je=Pe(import.meta.url),Ue=R.dirname(R.dirname(Je)),q=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"collected-profiles"):R.join(Ue,"collected-profiles"),Y=R.join(q,"run-log.json");function Be(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 ie(){try{if(!S.existsSync(Y))return{runs:[]};let e=JSON.parse(S.readFileSync(Y,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ce(e){S.existsSync(q)||S.mkdirSync(q,{recursive:!0});try{Be(Y,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function le(e,n="default"){let t=ie();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),ce(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function ae(e,n,t=null,o=null){if(!e)return;let s=null;try{let i=ie(),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)}ce(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";re({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 Ve}from"@ilivemylife/graph-sdk";var We=await Ve();for(let[e,n]of Object.entries(We))process.env[e]===void 0&&(process.env[e]=n);var cn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),ln=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),an=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 qe}from"url";var Ye=qe(import.meta.url),Ge=m.dirname(m.dirname(Ye)),E=process.env.DATA_DIR?m.resolve(process.env.DATA_DIR,"collected-profiles"):m.join(Ge,"collected-profiles"),mn=m.join(E,"people.json"),hn=m.join(E,"jobs.json"),He=m.join(E,"quota.json"),gn=m.join(E,"conversations.json"),yn=m.join(E,"sync-state.json"),Sn=m.join(E,"application-questions.json"),bn=m.join(E,"profile-history"),M=20,P=100,Ke=null,Qe=null,I=null,ze=null,Xe=null,Ze=null;function ue(){Ke=null,Qe=null,I=null,ze=null,Xe=null,Ze=null}function eo(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function oo(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 fe(){return new Date().toISOString().split("T")[0]}function no(){return I||(eo(),I=oo(He,"quota.json"),(!I||!I.connections)&&(I={connections:[]}),I)}function pe(){let e=no(),n=new Date;n.setDate(n.getDate()-7);let t=n.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=t)}function de(){let e=pe(),n=fe(),t=e.filter(l=>l.date===n).length,o=e.length,s=t>=M,r=o>=P,i=!s&&!r,a={allowed:i,daily:{sent:t,max:M},weekly:{sent:o,max:P}};return i||(a.reason=s?`Daily limit reached (${t}/${M})`:`Weekly limit reached (${o}/${P})`),a}function me(){let e=pe(),n=fe(),t=e.filter(s=>s.date===n).length,o=e.length;return{daily:{sent:t,max:M,remaining:M-t},weekly:{sent:o,max:P,remaining:P-o}}}import"dotenv/config";import*as c from"fs";import*as Z from"os";import*as f from"path";import{fileURLToPath as Io}from"url";var K={};W(K,{NAME:()=>so,VERSION:()=>to,up:()=>co});import*as b from"fs";import*as B from"path";var to=1,so="normalize-jobs-and-questions",ro=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],io=50;function G(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(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 co(e,n){let t=B.join(e,"jobs.json"),o=B.join(n,"scouted-jobs.json"),s=B.join(e,"application-questions.json"),r=G(t)||{},i=G(o)||{},a=0,l=[];for(let p of Object.keys(r)){if(!i[p])continue;let w=i[p],h=r[p];for(let O of ro)w[O]!=null&&h[O]==null&&(h[O]=w[O]);l.push(p),a++}a>0?(H(t,r),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=G(s);if(u&&Array.isArray(u.applications)){let p={},w=0;for(let h of u.applications){let O=h.jobId||"unknown";p[O]||(p[O]={applications:[]});let ne=(h.questions||[]).map(k=>{let F={type:k.type||"input",question:k.question||"",answer:k.answer||""};return k.options&&(k.options.length<=io?F.options=k.options:(F.optionsOmitted=!0,w++)),k.page&&(F.page=k.page),k.wasPreFilled&&(F.wasPreFilled=!0),k.wasRetry&&(F.wasRetry=!0),F});p[O].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||ne.length,questions:ne})}H(s,p),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),w>0&&console.log(` Phase 2: Stripped bloated options from ${w} 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];H(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 Q={};W(Q,{NAME:()=>ao,VERSION:()=>lo,up:()=>po});import*as v from"fs";import*as he from"path";var lo=2,ao="reset-unread-flags";function uo(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function fo(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 po(e){let n=he.join(e,"conversations.json"),t=uo(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}fo(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var z={};W(z,{NAME:()=>ho,VERSION:()=>mo,up:()=>vo});import*as $ from"fs";import*as ge from"path";var mo=3,ho="recompute-last-message-by",go=new Set(["draft","confirmed","rejected","needs_review"]);function yo(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function So(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 bo(e,n){if(!e||e.length===0)return"them";let t=e.filter(r=>!go.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 vo(e){let n=ge.join(e,"conversations.json"),t=yo(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=bo(u,o),w=p==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==p&&i++,l.lastMessageBy=p,l.conversationStatus=w,s++}if(s===0){console.log(" No conversations to recompute.");return}So(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.")}import"dotenv/config";import*as y from"path";import{fileURLToPath as $o}from"url";var wo=$o(import.meta.url),ko=y.dirname(y.dirname(wo)),J=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"market-research"):y.join(ko,"market-research"),kn=y.join(J,"scouted-jobs.json"),jn=y.join(J,"discovered-people.json"),En=y.join(J,"visit-log.json"),An=y.join(J,"companies.json"),On=y.join(J,"job-decisions.json");function ye(){jo=null,Eo=null,Ao=null,Oo=null,Ro=null}var jo=null;var Eo=null;var Ao=null;var Oo=null;var Ro=null;var To=Io(import.meta.url),Do=f.dirname(To),No=f.dirname(f.dirname(Do));function Co(e){return e&&(e==="~"?Z.homedir():e.startsWith("~/")||e.startsWith("~\\")?f.join(Z.homedir(),e.slice(2)):e)}var j=process.env.DATA_DIR?f.resolve(Co(process.env.DATA_DIR)):No,_=f.join(j,"collected-profiles"),x=f.join(j,"market-research"),g=f.join(j,".schema-version"),Se=[f.join(_,".schema-version"),f.join(x,".schema-version")],T=3,A=[{version:1,module:K},{version:2,module:Q},{version:3,module:z}];(function(){A.sort((o,s)=>o.version-s.version);let n=new Set;for(let o of A){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=A.length?A[A.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<A.length;o++){let s=o+1;if(A[o].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${o} but found v${A[o].version}`)}})();function we(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
8
|
+
`)}`;try{await se.addMessage(i,l)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Je=Pe(import.meta.url),Ue=R.dirname(R.dirname(Je)),q=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"collected-profiles"):R.join(Ue,"collected-profiles"),Y=R.join(q,"run-log.json");function Be(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 ie(){try{if(!S.existsSync(Y))return{runs:[]};let e=JSON.parse(S.readFileSync(Y,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ce(e){S.existsSync(q)||S.mkdirSync(q,{recursive:!0});try{Be(Y,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function le(e,n="default"){let t=ie();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),ce(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function ae(e,n,t=null,o=null){if(!e)return;let s=null;try{let i=ie(),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)}ce(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";re({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 Ve}from"@ilivemylife/graph-sdk";var We=await Ve();for(let[e,n]of Object.entries(We))process.env[e]===void 0&&(process.env[e]=n);var cn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),ln=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),an=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 qe}from"url";var Ye=qe(import.meta.url),Ge=m.dirname(m.dirname(Ye)),A=process.env.DATA_DIR?m.resolve(process.env.DATA_DIR,"collected-profiles"):m.join(Ge,"collected-profiles"),mn=m.join(A,"people.json"),hn=m.join(A,"jobs.json"),He=m.join(A,"quota.json"),gn=m.join(A,"conversations.json"),yn=m.join(A,"sync-state.json"),Sn=m.join(A,"application-questions.json"),bn=m.join(A,"profile-history"),M=20,P=100,Ke=null,Qe=null,I=null,ze=null,Xe=null,Ze=null;function ue(){Ke=null,Qe=null,I=null,ze=null,Xe=null,Ze=null}function eo(){d.existsSync(A)||d.mkdirSync(A,{recursive:!0})}function oo(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 fe(){return new Date().toISOString().split("T")[0]}function no(){return I||(eo(),I=oo(He,"quota.json"),(!I||!I.connections)&&(I={connections:[]}),I)}function pe(){let e=no(),n=new Date;n.setDate(n.getDate()-7);let t=n.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=t)}function de(){let e=pe(),n=fe(),t=e.filter(l=>l.date===n).length,o=e.length,s=t>=M,r=o>=P,i=!s&&!r,a={allowed:i,daily:{sent:t,max:M},weekly:{sent:o,max:P}};return i||(a.reason=s?`Daily limit reached (${t}/${M})`:`Weekly limit reached (${o}/${P})`),a}function me(){let e=pe(),n=fe(),t=e.filter(s=>s.date===n).length,o=e.length;return{daily:{sent:t,max:M,remaining:M-t},weekly:{sent:o,max:P,remaining:P-o}}}import"dotenv/config";import*as c from"fs";import*as Z from"os";import*as f from"path";import{fileURLToPath as Io}from"url";var K={};W(K,{NAME:()=>so,VERSION:()=>to,up:()=>co});import*as b from"fs";import*as B from"path";var to=1,so="normalize-jobs-and-questions",ro=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],io=50;function G(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(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 co(e,n){let t=B.join(e,"jobs.json"),o=B.join(n,"scouted-jobs.json"),s=B.join(e,"application-questions.json"),r=G(t)||{},i=G(o)||{},a=0,l=[];for(let p of Object.keys(r)){if(!i[p])continue;let w=i[p],h=r[p];for(let O of ro)w[O]!=null&&h[O]==null&&(h[O]=w[O]);l.push(p),a++}a>0?(H(t,r),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=G(s);if(u&&Array.isArray(u.applications)){let p={},w=0;for(let h of u.applications){let O=h.jobId||"unknown";p[O]||(p[O]={applications:[]});let ne=(h.questions||[]).map(k=>{let F={type:k.type||"input",question:k.question||"",answer:k.answer||""};return k.options&&(k.options.length<=io?F.options=k.options:(F.optionsOmitted=!0,w++)),k.page&&(F.page=k.page),k.wasPreFilled&&(F.wasPreFilled=!0),k.wasRetry&&(F.wasRetry=!0),F});p[O].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||ne.length,questions:ne})}H(s,p),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),w>0&&console.log(` Phase 2: Stripped bloated options from ${w} 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];H(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 Q={};W(Q,{NAME:()=>ao,VERSION:()=>lo,up:()=>po});import*as v from"fs";import*as he from"path";var lo=2,ao="reset-unread-flags";function uo(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function fo(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 po(e){let n=he.join(e,"conversations.json"),t=uo(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}fo(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var z={};W(z,{NAME:()=>ho,VERSION:()=>mo,up:()=>vo});import*as $ from"fs";import*as ge from"path";var mo=3,ho="recompute-last-message-by",go=new Set(["draft","confirmed","rejected","needs_review"]);function yo(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function So(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 bo(e,n){if(!e||e.length===0)return"them";let t=e.filter(r=>!go.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 vo(e){let n=ge.join(e,"conversations.json"),t=yo(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=bo(u,o),w=p==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==p&&i++,l.lastMessageBy=p,l.conversationStatus=w,s++}if(s===0){console.log(" No conversations to recompute.");return}So(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.")}import"dotenv/config";import*as y from"path";import{fileURLToPath as $o}from"url";var wo=$o(import.meta.url),ko=y.dirname(y.dirname(wo)),J=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"market-research"):y.join(ko,"market-research"),kn=y.join(J,"scouted-jobs.json"),jn=y.join(J,"discovered-people.json"),An=y.join(J,"visit-log.json"),En=y.join(J,"companies.json"),On=y.join(J,"job-decisions.json");function ye(){jo=null,Ao=null,Eo=null,Oo=null,Ro=null}var jo=null;var Ao=null;var Eo=null;var Oo=null;var Ro=null;var To=Io(import.meta.url),Do=f.dirname(To),No=f.dirname(f.dirname(Do));function Co(e){return e&&(e==="~"?Z.homedir():e.startsWith("~/")||e.startsWith("~\\")?f.join(Z.homedir(),e.slice(2)):e)}var j=process.env.DATA_DIR?f.resolve(Co(process.env.DATA_DIR)):No,_=f.join(j,"collected-profiles"),x=f.join(j,"market-research"),g=f.join(j,".schema-version"),Se=[f.join(_,".schema-version"),f.join(x,".schema-version")],T=3,E=[{version:1,module:K},{version:2,module:Q},{version:3,module:z}];(function(){E.sort((o,s)=>o.version-s.version);let n=new Set;for(let o of E){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=E.length?E[E.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<E.length;o++){let s=o+1;if(E[o].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${o} but found v${E[o].version}`)}})();function we(){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{c.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.
|
|
@@ -27,14 +27,14 @@ ${o.join(`
|
|
|
27
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.
|
|
28
28
|
`),process.exit(1)}let n=Lo(e);return n===null&&(console.error(`
|
|
29
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 ke(e){try{c.chmodSync(e,384)}catch{}}function Mo(e){if(we(),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)),ke(n),c.renameSync(n,g)}catch(t){try{c.unlinkSync(n)}catch{}throw t}}function $e(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{
|
|
30
|
+
`),process.exit(1)),n}function ke(e){try{c.chmodSync(e,384)}catch{}}function Mo(e){if(we(),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)),ke(n),c.renameSync(n,g)}catch(t){try{c.unlinkSync(n)}catch{}throw t}}function $e(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{Ae(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 X=!1;async function je(){if(X)return;we(),Vo();let n=ve().version;if(n===T){X=!0;return}xo(),_o(),process.on("exit",ee),n>T&&(console.error(`
|
|
31
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
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
34
|
\u{1F4E6} Schema migration: v${n} \u2192 v${T}`);let t=Wo();if(!t.ok){console.error(`
|
|
35
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(`
|
|
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=
|
|
37
|
+
`),process.exit(1)}let o=E.filter(s=>s.version>n);for(let s of o){console.log(`
|
|
38
38
|
Running migration v${String(s.version).padStart(3,"0")}...`);let r=`v${String(s.version).padStart(3,"0")}`,i=`.pre-${r}.backup`;try{$e(_,s.version),$e(x,s.version)}catch(l){console.error(`
|
|
39
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
40
|
`),process.exit(1)}let a=s.module;try{await a.up(_,x)}catch(l){console.error(`
|
|
@@ -45,7 +45,7 @@ ${o.join(`
|
|
|
45
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
46
|
`),process.exit(1)}console.log(` \u2713 Migration ${r} complete`)}try{ue()}catch{}try{ye()}catch{}X=!0,ee(),console.log(`
|
|
47
47
|
\u2713 Schema is now at v${T}
|
|
48
|
-
`)}var Po=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Jo(e){let n=e.toLowerCase();return Po.some(t=>t.test(n))}var Uo=6e4;function Bo(){let e=Date.now(),n=[];for(let t of[j,_,x]){if(!c.existsSync(t))continue;let o;try{o=c.readdirSync(t)}catch{continue}for(let s of o){if(!Jo(s))continue;let r=f.join(t,s);try{let i=c.statSync(r);if(!i.isFile()||e-i.mtimeMs<Uo)continue;n.push({dir:t,file:s,fullPath:r})}catch{}}}return n}function Vo({verbose:e=!1}={}){let n=Bo();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 Wo(){let e=[];for(let n of[_,x]){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{V(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 qo(e){let n=[],t=[];for(let r of[_,x]){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")?V(l):c.accessSync(l,c.constants.R_OK),n.push({backupPath:l,originalPath:p,fileName:a,dir:r})}catch(w){t.push(`${f.basename(r)}/${a}: ${w.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{
|
|
48
|
+
`)}var Po=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Jo(e){let n=e.toLowerCase();return Po.some(t=>t.test(n))}var Uo=6e4;function Bo(){let e=Date.now(),n=[];for(let t of[j,_,x]){if(!c.existsSync(t))continue;let o;try{o=c.readdirSync(t)}catch{continue}for(let s of o){if(!Jo(s))continue;let r=f.join(t,s);try{let i=c.statSync(r);if(!i.isFile()||e-i.mtimeMs<Uo)continue;n.push({dir:t,file:s,fullPath:r})}catch{}}}return n}function Vo({verbose:e=!1}={}){let n=Bo();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 Wo(){let e=[];for(let n of[_,x]){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{V(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 qo(e){let n=[],t=[];for(let r of[_,x]){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")?V(l):c.accessSync(l,c.constants.R_OK),n.push({backupPath:l,originalPath:p,fileName:a,dir:r})}catch(w){t.push(`${f.basename(r)}/${a}: ${w.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{Ae(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 Ae(e,n){let t=n+".tmp";try{c.copyFileSync(e,t),ke(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 je();var U=process.argv.slice(2),oe=new Set((U.find(e=>e.startsWith("--skip="))?.split("=")[1]||"").split(",").filter(Boolean)),Ee=new Set((U.find(e=>e.startsWith("--only="))?.split("=")[1]||"").split(",").filter(Boolean)),Ie=U.includes("--dry-run"),Te=U.includes("--jobs"),De=U.includes("--comms"),Oe=["apply-queue","apply","funnel","scout","visit"],Re=["sync","today"],Ne=Te?Oe:De?Re:[...Oe,...Re];function D(e){return Ee.size>0?Ee.has(e):!oe.has(e)&&Ne.includes(e)}function L(e,n,t=[],{optional:o=!1}={}){if(console.log(`
|
|
49
49
|
${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),Ie)return console.log(` [DRY RUN] Would run: node ${n} ${t.join(" ")}`),!0;try{return Yo("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 Go(){let e=Te?"jobs":De?"comms":"full";console.log(`
|
|
50
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=Ne.filter(D);console.log(` Steps: ${n.join(" \u2192 ")}`),oe.size>0&&console.log(` Skipping: ${[...oe].join(", ")}`),Ie&&console.log(" [DRY RUN MODE]");let t=le("daily",e),o={};if(D("apply-queue")&&(o["apply-queue"]=L("Apply Queue (scored jobs)","applyQueue.mjs",["--max=50","--min-score=50"],{optional:!0})),D("apply")){let r=me();o.apply=L("Apply from Search","run.mjs",[],{optional:!0})}if(D("funnel")&&!D("apply")){let r=de();r.allowed?o.funnel=L("Connection Funnel","funnelRunner.mjs",["--max=20"],{optional:!0}):(console.log(`
|
|
51
51
|
\u26A0 Funnel skipped: ${r.reason}`),o.funnel="skipped_quota")}D("scout")&&(o.scout=L("Scout Jobs for Tomorrow","scout.mjs",["--max=300","--verbose"],{optional:!0})),D("sync")&&(o.sync=L("Sync Inbox","syncAll.mjs")),D("today")&&(o.today=L("Daily Report","syncAll.mjs",["--today"])),console.log(`
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var _e=Object.defineProperty;var le=(t,e)=>()=>(t&&(e=t(t=0)),e);var De=(t,e)=>{for(var n in e)_e(t,n,{get:e[n],enumerable:!0})};async function k(t){let e=Math.floor(Math.random()*2001),n=t+e;return new Promise(o=>setTimeout(o,n))}async function ae(t){return await t.evaluate(()=>{let e=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of e){let i=o.innerText||"",r=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),w=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),m=i.includes("Get hired faster")||i.includes("Get hired 2x");if(r||w||m){let C=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(C)return C.click(),{dismissed:!0,matched:i.substring(0,80)};let I=o.querySelectorAll("button");for(let a of I){let h=a.innerText?.trim().toLowerCase()||"",d=a.getAttribute("aria-label")?.toLowerCase()||"";if(h==="not now"||h==="no thanks"||h==="dismiss"||d.includes("dismiss"))return a.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 K=le(()=>{});var we={};De(we,{extractExperienceFromDetails:()=>We});async function We(t,e){let n=e.replace(/\/+$/,"")+"/details/experience/";try{await t.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=t.url();if(/\/(login|authwall|checkpoint)/i.test(o))throw new Error(`Session expired \u2014 bounced to ${o} when fetching /details/experience/`);for(let r=0;r<5;r++)await t.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(900);await k(1e3);let i=0;for(;i<5&&await t.evaluate(()=>{for(let w of document.querySelectorAll("button"))if(/^Load more$/i.test((w.textContent||"").trim()))return w.click(),!0;return!1});)i++,await k(1500),await t.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(700);return await t.evaluate(()=>{let r=document.querySelector("main");if(!r)return[];function w(a){let h=[];for(let d of a.querySelectorAll("div")){let g=Array.from(d.children).filter(x=>x.tagName==="DIV");if(g.length<3)continue;let b=g.filter(x=>(x.textContent||"").trim().length>50);b.length<3||(d.textContent||"").length<500||h.push({el:d,count:b.length,totalText:(d.textContent||"").length})}return h.sort((d,g)=>g.count-d.count||d.totalText-g.totalText),h[0]?.el}let m=w(r);if(!m)return[];let C=Array.from(m.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function I(a){let h=a[0]||null,d=null,g=null;if(a[1]){let u=a[1].split("\xB7").map(S=>S.trim());d=u[0]||null,u[1]&&(g=u[1])}let b=a.findIndex(u=>/(\d{4}|present)/i.test(u)&&/(-|–|—)/i.test(u)&&u.length<80),x=null,A=null;if(b>=0){let u=a[b].split("\xB7").map(S=>S.trim());x=u[0]||null,u[1]&&(A=u[1])}let y=null,L=-1;if(b>=0&&a[b+1]){let u=a[b+1],S=/^[>*\-•]|^>/.test(u),B=/https?:\/\//.test(u),U=/\d{4}/.test(u),M=/,/.test(u)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(u);!S&&!B&&!U&&u.length<100&&M&&(y=u,L=b+1)}let N=null,j=-1,$=a[a.length-1];if($&&/and\s+\+\d+\s+skills?$/i.test($)){j=a.length-1;let u=$.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);u&&(N={listed:u[1].split(",").map(S=>S.trim()),additional:parseInt(u[2],10)})}let O=new Set([0,1,b,L,j].filter(u=>u>=0)),R=a.filter((u,S)=>!O.has(S)),q=R.length>0?R.join(`
|
|
2
|
+
|
|
3
|
+
`):null;return{title:h,company:d,employmentType:g,dates:x,duration:A,location:y,description:q,skills:N,_raw:a}}return C.map(a=>{let d=(a.innerText||"").trim().split(`
|
|
4
|
+
`).map(g=>g.trim()).filter(g=>g&&g.length<5e3);return I(d)}).filter(a=>a.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${e}: ${o.message?.slice(0,120)}`),[]}}var ge=le(()=>{K()});import"dotenv/config";import Qe from"puppeteer";K();import{getPluginConfig as Me}from"@ilivemylife/graph-sdk";var Le=await Me();for(let[t,e]of Object.entries(Le))process.env[t]===void 0&&(process.env[t]=e);var tt=process.env.LINKEDIN_NAME,_=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),nt=Object.freeze(new Set([_.DRAFT,_.CONFIRMED,_.NEEDS_REVIEW])),ot=Object.freeze(new Set([_.DRAFT,_.CONFIRMED,_.REJECTED,_.NEEDS_REVIEW]));import"dotenv/config";import*as f from"fs";import*as p from"path";import{fileURLToPath as Ne}from"url";var je=Ne(import.meta.url),Pe=p.dirname(p.dirname(je)),v=process.env.DATA_DIR?p.resolve(process.env.DATA_DIR,"collected-profiles"):p.join(Pe,"collected-profiles"),z=p.join(v,"people.json"),at=p.join(v,"jobs.json"),ct=p.join(v,"quota.json"),ut=p.join(v,"conversations.json"),dt=p.join(v,"sync-state.json"),ft=p.join(v,"application-questions.json"),Q=p.join(v,"profile-history");var T=null;function de(){f.existsSync(v)||f.mkdirSync(v,{recursive:!0})}function fe(t,e){let n=JSON.stringify(e,null,2),o=t+".tmp";f.writeFileSync(o,n);for(let i=0;i<3;i++)try{f.renameSync(o,t);return}catch(r){if(i<2&&(r.code==="EPERM"||r.code==="EBUSY")){let w=Date.now();for(;Date.now()-w<200;);continue}throw r}}function me(t,e){if(!f.existsSync(t))return null;try{let n=JSON.parse(f.readFileSync(t,"utf-8"));try{f.copyFileSync(t,t+".backup")}catch{}return n}catch(n){console.error(`[!] ${e} is corrupted: ${n.message}`),console.error(` File: ${p.resolve(t)}`);let o=t+".backup";if(f.existsSync(o))try{let i=JSON.parse(f.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{f.copyFileSync(o,t)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${t}.corrupted`);try{f.copyFileSync(t,t+".corrupted")}catch{}return null}}function Te(){return new Date().toISOString().split("T")[0]}var Fe=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt"],Oe=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function G(t){if(!t)return null;let e=t.match(/\/in\/([^/?#]+)/);return e?e[1].toLowerCase():null}function Re(){f.existsSync(Q)||f.mkdirSync(Q,{recursive:!0})}function pe(t){let e=G(t);return e?p.join(Q,`${e}.json`):null}function qe(t){let e=pe(t);return e?me(e,`profile-history/${G(t)}.json`)||[]:[]}function Be(t,e){let n=pe(t);if(!n)return;Re();let o=qe(t);o.unshift(e);try{fe(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${G(t)}: ${i.message}`)}}function ce(t){return!!(t==null||Array.isArray(t)&&t.length===0||typeof t=="string"&&!t.trim())}function ue(t){return Array.isArray(t)?[...t].map(e=>String(e).trim()).sort().join("||"):typeof t=="string"?t.replace(/\s+/g," ").trim():t}function Ue(t,e){if(!t)return[];let n=[];for(let o of Oe){let i=t[o],r=e[o];ce(i)||ce(r)||ue(i)!==ue(r)&&n.push(o)}return n}function He(t){let e=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(t))e.has(o)||(n[o]=i);return n}function he(){return T||(de(),T=me(z,"people.json")||{},T)}function Ve(t){de(),T=t;try{fe(z,t)}catch(e){console.error(`[!] Failed to save people.json: ${e.message}`),console.error(` Path: ${p.resolve(z)}`)}}function Z(t,e={}){if(!t)return null;let n=he(),o=Te(),i=new Date().toISOString(),r=n[t];if(r){let w=Ue(r,e);w.length>0&&(Be(t,{capturedAt:i,previousLastUpdated:r.lastUpdated||null,changedFields:w,snapshot:He(r)}),r.lastSnapshotAt=i),r.seenCount=(r.seenCount||1)+1,r.lastSeen=o,r.lastUpdated=i,e.source&&!r.sources?.includes(e.source)&&(r.sources=r.sources||[],r.sources.push(e.source));for(let m of Fe)if(e[m]!=null){if(Array.isArray(e[m])&&e[m].length===0&&Array.isArray(r[m])&&r[m].length>0)continue;r[m]=e[m]}Array.isArray(e.availableSections)&&(r.lastFullVisitAt=i)}else n[t]={name:e.name||null,title:e.title||null,location:e.location||null,company:e.company||null,about:e.about||null,connectionDegree:e.connectionDegree||null,connectionsCount:e.connectionsCount||null,mutualConnections:e.mutualConnections||null,photoUrl:e.photoUrl||null,hasVerifiedBadge:e.hasVerifiedBadge||!1,currentCompany:e.currentCompany||null,currentSchool:e.currentSchool||null,connectionsLevel:e.connectionsLevel||null,mutualConnectionsCount:e.mutualConnectionsCount||null,followers:e.followers||null,openToWork:e.openToWork||!1,hiring:e.hiring||!1,topSkills:e.topSkills||null,availableSections:e.availableSections||null,experience:e.experience||null,featuredLinks:e.featuredLinks||null,_lastEnrichedAt:e._lastEnrichedAt||null,firstSeen:o,lastSeen:o,seenCount:1,sources:e.source?[e.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(e.availableSections)?i:null};return Ve(n),n[t]}async function Je(t,e){let n=t.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await t.goto(e,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=t.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function be(t,e,n={}){let{extractExperience:o=!1}=n;try{await t.goto(e,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3),await ae(t)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Je(t,e));let r=0;for(let C=0;C<2;C++){let I=await t.evaluate(()=>document.body.scrollHeight);for(let h=1;h<=6;h++)await t.evaluate(d=>window.scrollTo(0,d),I*h/6),await k(900);let a=await t.evaluate(()=>document.body.scrollHeight);if(a===r)break;r=a}await k(800);let w=await t.evaluate(()=>{let C=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"]),I=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"]),a=s=>{let l=(s||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(l)},h={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:[]},d=document.querySelector("main");if(!d)return h;let g=[...Array.from(d.querySelectorAll("h1")),...Array.from(d.querySelectorAll("h2"))],b=Array.from(d.querySelectorAll("h2")),x=g.find(s=>{let l=s.textContent&&s.textContent.trim(),c=(l||"").replace(/\s*\(\d+\)$/,"").trim();return l&&l.length>1&&l.length<100&&!C.has(c)&&!I.has(c)}),A=x?x.textContent.trim():null,y=x?x.parentElement:null;for(;y&&y!==d&&!Array.from(y.children).filter(l=>l.tagName==="P").some(l=>{let c=l.textContent&&l.textContent.trim();return c&&c.length>5&&!a(c)});)y=y.parentElement;let L=null,N=null,j=null,$=null;if(y&&y!==d){let s=Array.from(y.children).filter(c=>c.tagName==="P").filter(c=>{let E=c.textContent&&c.textContent.trim();return E&&E.length>5&&!a(E)});if(s[0]&&(L=s[0].textContent.trim()),s[1]){let c=s[1].textContent.trim().split(/\s*[·•]\s*/);N=c[0]||null,c.length>1&&(j=c.slice(1).join(" \xB7 "))}let l=Array.from(y.children).filter(c=>c.tagName==="DIV");for(let c=l.length-1;c>=0;c--){let E=l[c].textContent&&l[c].textContent.trim();if(E&&!(A&&E.startsWith(A))&&($=E.split(/[·•]/)[0].trim(),$))break}}let O=null;if(y){let s=y.querySelectorAll("p, span, div");for(let l of s){let c=(l.textContent||"").trim().replace(/^[·•]\s*/,"");if(c==="1st"||c==="2nd"||c==="3rd"){O=c;break}}}let R=!!d.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),q=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),u=q&&q.src||null,S=d.textContent||"",B=null,U=S.match(/(\d+\+?)\s+connections\b/i);U&&(B=U[1]+" connections");let M=null,ee=S.match(/(\d+)\s+mutual connection/i),te=S.match(/and\s+(\d+)\s+other mutual/i),ve=S.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);ee?M=parseInt(ee[1],10):te?M=2+parseInt(te[1],10):ve&&(M=2);let ne=null,oe=null,ie=b.find(s=>s.textContent&&s.textContent.trim()==="About");if(ie){let s=ie.parentElement;for(;s&&s.tagName!=="SECTION";)s=s.parentElement;if(s){let l=(s.textContent||"").trim();l=l.replace(/^About\s*/,"").trim();let c=l.match(/Top skills\s*(.+?)$/i);if(c){let Y=c[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map($e=>$e.trim()).filter(Boolean);Y.length>0&&Y.length<10&&(oe=Y)}l=l.split(/\n?…\s*more/i)[0].trim(),l=l.split(/\n?\.\.\.\s*more/i)[0].trim(),l=l.split(/\bTop skills\b/i)[0].trim(),l=l.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ne=l||null}}let se=null,re=b.find(s=>s.textContent&&s.textContent.trim()==="Activity");if(re){let s=re.parentElement;for(;s&&s.tagName!=="SECTION";)s=s.parentElement;if(s){let l=(s.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);l&&(se=parseInt(l[1].replace(/,/g,""),10))}}let Ee=[...new Set(b.map(s=>(s.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(s=>s&&s.length>1&&s.length<60&&s!==A).filter(s=>C.has(s)))],P=document.body.textContent||"",Ie=/#OpenToWork\b/i.test(P)||/\bOpen to work\b/.test(P),Ae=/#Hiring\b/i.test(P)||/\bI'?m hiring\b/i.test(P)||/\bWe are hiring\b/i.test(P);return{name:A,title:L,location:$,currentCompany:N,currentSchool:j,connectionDegree:O,hasVerifiedBadge:R,photoUrl:u,connectionsLevel:B,mutualConnectionsCount:M,followers:se,openToWork:Ie,hiring:Ae,about:ne,topSkills:oe,availableSections:Ee}});console.log(`Viewed: ${w.name} - ${w.title}`);let m=null;if(o){let{extractExperienceFromDetails:C}=await Promise.resolve().then(()=>(ge(),we));m=await C(t,e),console.log(` + Experience: ${m.length} entries`)}return{...w,profileUrl:e,...m!==null&&{experience:m}}}catch(i){console.error(`Error viewing profile ${e}:`,i.message);try{await t.goto("about:blank",{timeout:1e4}),await k(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(i.message||""))throw i;return null}}import ye from"fs";import Ye from"path";var Ke="cookies.json";function ze(){let t=process.env.ILML_SCOPE_DIR;return t?Ye.join(t,"plugins-state","linkedin","cookies.json"):Ke}function Se(){let t=ze();if(!ye.existsSync(t))throw new Error(`Cookies not found at ${t}. Run: ilml linkedin login`);let e;try{e=ye.readFileSync(t,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${t}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(e)}catch{throw new Error(`Cookies file at ${t} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${t} is empty or not an array. Run: ilml linkedin login`);return n}function ke(t){return t?t.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function Ce(t){return(t||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var W=process.argv.slice(2),Ge=W.includes("--help")||W.includes("-h"),D=W.find(t=>t.startsWith("http")),F=W.includes("--with-experience");function xe(){console.log(`
|
|
5
|
+
enrich-profile \u2014 visit ONE LinkedIn profile and save what we learn
|
|
6
|
+
|
|
7
|
+
USAGE
|
|
8
|
+
ilml linkedin enrich-profile <profile-url> [--with-experience]
|
|
9
|
+
node enrichProfile.mjs <profile-url> [--with-experience] # dev
|
|
10
|
+
|
|
11
|
+
ARGUMENTS
|
|
12
|
+
<profile-url> Required. Full LinkedIn profile URL.
|
|
13
|
+
Example: https://www.linkedin.com/in/<slug>/
|
|
14
|
+
|
|
15
|
+
FLAGS
|
|
16
|
+
--with-experience Opt-in. Adds a second navigation to /details/experience/
|
|
17
|
+
and includes a structured experience[] array on the
|
|
18
|
+
saved record (title, company, dates, location,
|
|
19
|
+
description, skills per role). 2 page loads instead of 1.
|
|
20
|
+
Normal human "click show all" pattern \u2014 safe on-demand.
|
|
21
|
+
--help, -h Print this help and exit.
|
|
22
|
+
|
|
23
|
+
BEHAVIOUR
|
|
24
|
+
- Saves to people.json via upsertPerson() \u2014 additive merge, never deletes data.
|
|
25
|
+
- Self-profile detected via MY_LINKEDIN_URL or LINKEDIN_NAME \u2192 printed to
|
|
26
|
+
stdout instead of saved (keeps own profile out of the contacts DB).
|
|
27
|
+
- Refuses to run if NEITHER MY_LINKEDIN_URL nor LINKEDIN_NAME is set (would
|
|
28
|
+
otherwise risk self leaking into people.json).
|
|
29
|
+
- --with-experience: if extraction returns 0 entries (DOM change / auth blip),
|
|
30
|
+
the existing experience array is preserved \u2014 never wiped.
|
|
31
|
+
|
|
32
|
+
BAN RISK
|
|
33
|
+
Low. One profile = 1 load (or 2 with --with-experience) = normal browsing.
|
|
34
|
+
Intentionally no batch mode here. Use 'enrich-profiles --with-experience'
|
|
35
|
+
for gated batch enrichment with cap.
|
|
36
|
+
|
|
37
|
+
WHEN TO USE
|
|
38
|
+
- Audit your own LinkedIn profile (prints to stdout)
|
|
39
|
+
- Deep-dive on one specific contact before reaching out
|
|
40
|
+
- Verify what we know about a recruiter / lead
|
|
41
|
+
`)}Ge&&(xe(),process.exit(0));D||(xe(),process.exit(1));/linkedin\.com\/in\//i.test(D)||(console.error(`URL doesn't look like a LinkedIn profile: ${D}`),console.error("Expected format: https://www.linkedin.com/in/<slug>/"),process.exit(1));var X=ke(process.env.MY_LINKEDIN_URL||""),J=Ce(process.env.LINKEDIN_NAME||"");!X&&!J&&(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 V=X&&ke(D)===X;console.log("");console.log(` enrichProfile \u2014 ${D}`);console.log(` Mode: ${F?"WITH experience (2 loads)":"basic (1 load)"}`);console.log(V?" Target: SELF (URL match) \u2014 will print to stdout, not saved to people.json":J?` 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)");F&&(console.log(""),console.log(" \u26A0 --with-experience triggers an extra navigation to /details/experience/."),console.log(" One profile = 2 page loads. This is fine on-demand (normal human"),console.log(' "click show all" pattern), but DO NOT batch this script. Use'),console.log(" `enrichProfiles.mjs --with-experience` for the gated batch flow."));console.log("");var H=null;try{H=await Qe.launch({headless:!1,defaultViewport:null,protocolTimeout:3e5});let t=await H.newPage();await t.setCookie(...Se());let e=await be(t,D,{extractExperience:F});if((!e||!e.name)&&(console.error(" viewProfile returned no name \u2014 profile not loaded or DOM changed"),process.exit(1)),!V&&J&&e.name&&Ce(e.name)===J&&(V=!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: ${e.name}`),console.log(` title: ${e.title||"(none)"}`),console.log(` location: ${e.location||"(none)"}`),console.log(` about: ${e.about?`${e.about.length} chars`:"(none)"}`),console.log(` topSkills: ${e.topSkills?e.topSkills.join(", "):"(none)"}`),F&&console.log(` experience: ${(e.experience||[]).length} entries`),console.log(""),V)console.log(" \u2500\u2500\u2500 full data (self \u2014 not persisted) \u2500\u2500\u2500"),console.log(JSON.stringify(e,null,2));else{let n={name:e.name,title:e.title,location:e.location,about:e.about,currentCompany:e.currentCompany,currentSchool:e.currentSchool,topSkills:e.topSkills,availableSections:e.availableSections,connectionsLevel:e.connectionsLevel,mutualConnectionsCount:e.mutualConnectionsCount,followers:e.followers,openToWork:e.openToWork,hiring:e.hiring,hasVerifiedBadge:e.hasVerifiedBadge,photoUrl:e.photoUrl,source:"enrich-profile-single"};F&&(e.experience&&e.experience.length>0?(n.experience=e.experience,n._lastEnrichedAt=new Date().toISOString()):console.log(" \u26A0 --with-experience returned 0 entries \u2014 NOT writing experience/_lastEnrichedAt (existing data preserved)")),Z(D,n),console.log(" \u2713 Saved to people.json")}}catch(t){console.error(" Error:",t.message),process.exit(1)}finally{H&&await H.close().catch(()=>{})}
|