borderless 0.1.0__py3-none-any.whl

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.
borderless/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """borderless: Evaluate profile evidence for US and international talent/skilled-migration visas."""
2
+
3
+ __version__ = "0.1.0"
borderless/cli.py ADDED
@@ -0,0 +1,320 @@
1
+ """CLI for borderless."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import click
8
+ from rich.console import Console
9
+ from rich.markdown import Markdown
10
+ from rich.panel import Panel
11
+ from rich.table import Table
12
+ from rich.text import Text
13
+
14
+ from .cli_options import common_options
15
+ from .criteria import CriterionResult, Strength
16
+ from .evaluator import EvaluationReport, evaluate
17
+ from .intl_visas import COUNTRY_NAMES, resolve_country
18
+ from .policy import visa_availability
19
+ from .profile_loader import load_profile
20
+
21
+ console = Console()
22
+
23
+ STRENGTH_STYLE = {
24
+ Strength.NOT_MET: ("Not Met", "red"),
25
+ Strength.WEAK: ("Weak", "yellow"),
26
+ Strength.MODERATE: ("Moderate", "cyan"),
27
+ Strength.STRONG: ("Strong", "green"),
28
+ }
29
+
30
+
31
+ def _strength_text(s: Strength) -> Text:
32
+ label, color = STRENGTH_STYLE[s]
33
+ return Text(label, style=f"bold {color}")
34
+
35
+
36
+ def _criteria_table(
37
+ title: str,
38
+ results: list[CriterionResult],
39
+ numbered: bool = False,
40
+ ) -> Table:
41
+ """Generic table builder for any list of CriterionResults."""
42
+ table = Table(title=title, show_lines=True, title_style="bold magenta")
43
+ if numbered:
44
+ table.add_column("#", style="dim", width=4)
45
+ table.add_column("Criterion", min_width=30)
46
+ table.add_column("Strength", width=10, justify="center")
47
+ table.add_column("Evidence", ratio=3)
48
+
49
+ for i, r in enumerate(results, 1):
50
+ evidence_str = "\n".join(r.evidence) if r.evidence else "-"
51
+ row = [str(i)] if numbered else []
52
+ row += [r.name, _strength_text(r.strength), evidence_str]
53
+ table.add_row(*row)
54
+
55
+ return table
56
+
57
+
58
+ def _print_summary(report: EvaluationReport) -> None:
59
+ rows = [
60
+ ("EB-1A (self-petition)",
61
+ "green" if report.eb1a_threshold_met else "yellow",
62
+ "Threshold signals; merits pending" if report.eb1a_threshold_met else "Strengthen evidence"),
63
+ ("EB-1B (employer-sponsored)",
64
+ "green" if report.eb1b_prerequisites_met else "yellow",
65
+ "Prerequisites supported; review pending" if report.eb1b_prerequisites_met else "Assess prerequisites / criteria"),
66
+ ("EB2-NIW (self-petition)",
67
+ "green" if report.niw_signals_supported else "yellow",
68
+ "Qualification + prong signals present" if report.niw_signals_supported else "Assess qualification / prongs"),
69
+ ("O-1A (nonimmigrant bridge)",
70
+ "cyan" if report.o1a_result and report.o1a_result.strength == Strength.MODERATE else "yellow",
71
+ "Threshold signals; totality pending" if report.o1a_result and report.o1a_result.strength == Strength.MODERATE else "Build evidence"),
72
+ ]
73
+
74
+ table = Table(title="US Visa Category Summary", show_lines=True, title_style="bold bright_blue")
75
+ table.add_column("Category", min_width=40)
76
+ table.add_column("Status", width=35, justify="center")
77
+ for name, color, status in rows:
78
+ table.add_row(name, Text(status, style=f"bold {color}"))
79
+
80
+ console.print()
81
+ console.print(table)
82
+ console.print()
83
+
84
+
85
+ def _print_eb1a(report: EvaluationReport) -> None:
86
+ met, needed = report.eb1a_met_count, 3
87
+ color = "green" if met >= needed else "red"
88
+
89
+ console.print(_criteria_table(
90
+ "EB-1A Extraordinary Ability (need >= 3 of 10 criteria)",
91
+ report.eb1a_results,
92
+ numbered=True,
93
+ ))
94
+ console.print(
95
+ f"\n Criteria met (moderate+): [{color}]{met}/{needed}[/{color}]"
96
+ f" | Strong: {report.eb1a_strong_count}"
97
+ )
98
+ if report.eb1a_threshold_met:
99
+ console.print(" [cyan]Initial EB-1A evidence threshold has heuristic signals.[/cyan] Final merits remain unassessed.\n")
100
+ else:
101
+ console.print(f" [yellow]Initial EB-1A threshold: need signals for {needed - met} more criteria.[/yellow]\n")
102
+
103
+
104
+ def _print_eb1b(report: EvaluationReport) -> None:
105
+ met, needed = report.eb1b_met_count, 2
106
+ color = "green" if met >= needed else "red"
107
+
108
+ console.print(_criteria_table(
109
+ "EB-1B Outstanding Professor/Researcher (need >= 2 of 6 criteria + employer)",
110
+ report.eb1b_results,
111
+ ))
112
+ console.print(f"\n Criteria met (moderate+): [{color}]{met}/{needed}[/{color}]")
113
+
114
+ if report.eb1b_prerequisites_met:
115
+ console.print(" [cyan]EB-1B prerequisite and criterion signals present; recognition assessment pending.[/cyan]\n")
116
+ else:
117
+ prereq = next((r for r in report.eb1b_results if r.criterion_id == "eb1b_prereq"), None)
118
+ job = next((r for r in report.eb1b_results if r.criterion_id == "eb1b_job"), None)
119
+ notes = []
120
+ if prereq and prereq.strength == Strength.NOT_MET:
121
+ notes.append("need 3+ years research experience")
122
+ if met < needed:
123
+ notes.append(f"need {needed - met} more criteria")
124
+ if job and job.strength not in (Strength.MODERATE, Strength.STRONG):
125
+ notes.append("need a qualifying documented U.S. job offer")
126
+ console.print(f" [yellow bold]EB-1B gaps: {'; '.join(notes)}.[/yellow bold]\n")
127
+
128
+
129
+ def _print_niw(report: EvaluationReport) -> None:
130
+ console.print(_criteria_table(
131
+ "EB2-NIW National Interest Waiver (Dhanasar 3-prong test)",
132
+ report.niw_results,
133
+ ))
134
+
135
+ if report.eb2_base and report.eb2_base.strength == Strength.STRONG:
136
+ console.print(" [green]EB-2 base qualification: supported by advanced degree[/green]")
137
+ else:
138
+ console.print(" [yellow]EB-2 base qualification: not established; assess degree equivalence or exceptional ability[/yellow]")
139
+
140
+ if report.niw_prongs_met:
141
+ console.print(" [green]NIW prong signals present; attorney review still required.[/green]\n")
142
+ else:
143
+ console.print(" [yellow]NIW Dhanasar test: strengthen weak or unassessed prongs.[/yellow]\n")
144
+
145
+
146
+ def _print_o1a(report: EvaluationReport) -> None:
147
+ r = report.o1a_result
148
+ if not r:
149
+ return
150
+ console.print(
151
+ Panel(
152
+ f"Strength: [bold]{STRENGTH_STYLE[r.strength][0]}[/bold]\n"
153
+ + "\n".join(r.evidence),
154
+ title="O-1A Extraordinary Ability (Nonimmigrant Bridge Strategy)",
155
+ title_align="left",
156
+ border_style="cyan",
157
+ )
158
+ )
159
+
160
+
161
+ def _print_intl_overview(report: EvaluationReport) -> None:
162
+ if not report.intl_results:
163
+ return
164
+
165
+ table = Table(
166
+ title="International Alternatives (given US visa uncertainty)",
167
+ show_lines=True,
168
+ title_style="bold bright_cyan",
169
+ )
170
+ table.add_column("Code", width=6)
171
+ table.add_column("Country", min_width=14)
172
+ table.add_column("Pathway", min_width=28)
173
+ table.add_column("Type", width=10)
174
+ table.add_column("Fit", width=10, justify="center")
175
+
176
+ for p in report.intl_results:
177
+ table.add_row(
178
+ p.country_code,
179
+ p.country,
180
+ p.pathway,
181
+ p.visa_type,
182
+ _strength_text(p.strength),
183
+ )
184
+
185
+ console.print()
186
+ console.print(table)
187
+ console.print(
188
+ " [dim]Use --country <code> for details (e.g. --country fr, --country ae, --country us)[/dim]\n"
189
+ )
190
+
191
+
192
+ def _print_intl_country(report: EvaluationReport, country_code: str) -> None:
193
+ pathways = [p for p in report.intl_results if p.country_code == country_code]
194
+ if not pathways:
195
+ console.print(f"[red]No pathways found for country code {country_code!r}.[/red]")
196
+ return
197
+
198
+ for p in pathways:
199
+ evidence_lines = "\n".join(f" • {e}" for e in p.evidence) if p.evidence else " • none"
200
+ body = (
201
+ f"[bold]Pathway:[/bold] {p.pathway}\n"
202
+ f"[bold]Type:[/bold] {p.visa_type}\n"
203
+ f"[bold]Fit:[/bold] {STRENGTH_STYLE[p.strength][0]}\n\n"
204
+ f"[bold]Evidence:[/bold]\n{evidence_lines}\n\n"
205
+ f"[bold]Notes:[/bold] {p.notes}"
206
+ )
207
+ console.print(
208
+ Panel(
209
+ body,
210
+ title=f"{p.country} ({p.country_code})",
211
+ title_align="left",
212
+ border_style="bright_cyan",
213
+ )
214
+ )
215
+ console.print()
216
+
217
+
218
+ def _print_us_context() -> None:
219
+ codes = ", ".join(sorted(c for c in COUNTRY_NAMES if c != "us"))
220
+ console.print(
221
+ Panel(
222
+ "Visa and work-authorization policies change; verify current official requirements.\n\n"
223
+ f"Evaluate parallel pathways with [bold]--country[/bold]: {codes}",
224
+ title="US Visa Climate",
225
+ border_style="yellow",
226
+ )
227
+ )
228
+
229
+
230
+ def _print_visa_availability(report: EvaluationReport) -> None:
231
+ console.print(Panel(
232
+ Text(visa_availability(report.country_of_birth)),
233
+ title="US Visa Availability (not a filing-readiness determination)",
234
+ border_style="yellow",
235
+ ))
236
+
237
+
238
+ def _prepare_llm_markdown(text: str) -> Markdown:
239
+ """Normalize LLM markdown for terminal rendering."""
240
+ cleaned = (
241
+ text.replace("<br>", "\n")
242
+ .replace("<br/>", "\n")
243
+ .replace("<br />", "\n")
244
+ )
245
+ return Markdown(cleaned)
246
+
247
+
248
+ def _print_llm_review(analysis: str, label: str, provider: str) -> None:
249
+ console.print()
250
+ console.rule(f"[bold bright_magenta]LLM Review — {label} ({provider})[/bold bright_magenta]")
251
+ console.print(_prepare_llm_markdown(analysis))
252
+ console.print()
253
+
254
+
255
+ def _print_report(report: EvaluationReport, country: str | None = None) -> None:
256
+ title = "Visa Eligibility Evaluation"
257
+ if country:
258
+ title = f"{COUNTRY_NAMES[country]} — Visa Eligibility"
259
+
260
+ console.print(
261
+ Panel(
262
+ f"[bold]{report.name}[/bold] | Nationality: {report.nationality}",
263
+ title=title,
264
+ border_style="bright_blue",
265
+ )
266
+ )
267
+
268
+ show_us = country in (None, "us")
269
+ show_intl_overview = country is None
270
+ show_intl_country = country is not None and country != "us"
271
+
272
+ if show_us:
273
+ _print_summary(report)
274
+ _print_eb1a(report)
275
+ _print_eb1b(report)
276
+ _print_niw(report)
277
+ _print_o1a(report)
278
+ if country is None:
279
+ _print_us_context()
280
+
281
+ if show_intl_overview:
282
+ _print_intl_overview(report)
283
+ elif show_intl_country:
284
+ _print_intl_country(report, country)
285
+
286
+ if show_us:
287
+ _print_visa_availability(report)
288
+
289
+
290
+
291
+ @click.command()
292
+ @common_options
293
+ @click.option("-c", "--country", default=None, metavar="CODE",
294
+ help="Show only this country (us, au, fr, ae/dubai, ...). Omit for all.")
295
+ def main(profile: str, country: str | None, review: bool, provider: str, model: str | None) -> None:
296
+ """Evaluate visa eligibility (US EB-1A/EB-1B/NIW/O-1A + international alternatives)."""
297
+ try:
298
+ country_code = resolve_country(country) if country else None
299
+ data = load_profile(Path(profile))
300
+ report = evaluate(data, country=country_code)
301
+ except (ValueError, OSError) as exc:
302
+ raise click.ClickException(str(exc)) from exc
303
+ _print_report(report, country=country_code)
304
+
305
+ if review:
306
+ from .llm_review import llm_review
307
+
308
+ label = COUNTRY_NAMES.get(country_code, "all countries") if country_code else "all countries"
309
+ try:
310
+ with console.status(f"[bold cyan]Requesting LLM review ({provider}, {label})..."):
311
+ analysis = llm_review(report, data, provider=provider, model=model, country=country_code)
312
+ except ValueError as exc:
313
+ raise click.ClickException(str(exc)) from exc
314
+ _print_llm_review(analysis, label, provider)
315
+ else:
316
+ console.print("\n [dim]Run with --review for LLM-powered analysis and action plan.[/dim]\n")
317
+
318
+
319
+ if __name__ == "__main__":
320
+ main()
@@ -0,0 +1,19 @@
1
+ """Options shared by terminal and markdown evaluation commands."""
2
+
3
+ import click
4
+
5
+ from .llm_review import PROVIDERS
6
+
7
+
8
+ def common_options(command):
9
+ for option in reversed((
10
+ click.option("-p", "--profile", default="profile.yaml",
11
+ type=click.Path(exists=True, dir_okay=False), help="Path to profile YAML file."),
12
+ click.option("--review", is_flag=True,
13
+ help="Request an LLM attorney-style review (requires provider API key)."),
14
+ click.option("--provider", type=click.Choice(PROVIDERS, case_sensitive=False),
15
+ default="openrouter", help="LLM provider for --review."),
16
+ click.option("--model", default=None, help="Override the default model for --review."),
17
+ )):
18
+ command = option(command)
19
+ return command
borderless/criteria.py ADDED
@@ -0,0 +1,33 @@
1
+ """USCIS visa criteria definitions for green-card eligibility evaluation.
2
+
3
+ Sources:
4
+ - EB1A: 8 CFR 204.5(h)(3), USCIS Policy Manual Vol 6, Part F, Ch 2
5
+ (updated Oct 2024)
6
+ - EB1B: 8 CFR 204.5(i), USCIS Policy Manual Vol 6, Part F, Ch 3
7
+ (updated Sep 2023)
8
+ - EB2-NIW: Matter of Dhanasar, 26 I&N Dec. 884 (AAO 2016),
9
+ USCIS Policy Manual Vol 6, Part F, Ch 5 (updated Jan 2025)
10
+ - O-1A: 8 CFR 214.2(o), USCIS Policy Manual Vol 2, Part M, Ch 4
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from dataclasses import dataclass, field
16
+ from enum import Enum
17
+
18
+
19
+ class Strength(Enum):
20
+ NOT_MET = "not_met"
21
+ WEAK = "weak"
22
+ MODERATE = "moderate"
23
+ STRONG = "strong"
24
+
25
+
26
+ @dataclass
27
+ class CriterionResult:
28
+ """Evaluation result for a single criterion."""
29
+
30
+ criterion_id: str
31
+ name: str
32
+ strength: Strength
33
+ evidence: list[str] = field(default_factory=list)