job-apply-cli 0.2.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.
- job_apply_agent/__init__.py +3 -0
- job_apply_agent/api.py +340 -0
- job_apply_agent/ats/__init__.py +12 -0
- job_apply_agent/ats/answer_binding.py +308 -0
- job_apply_agent/ats/base.py +64 -0
- job_apply_agent/ats/captcha.py +76 -0
- job_apply_agent/ats/codex_planner.py +174 -0
- job_apply_agent/ats/cua_harness.py +846 -0
- job_apply_agent/ats/dom_browser.py +275 -0
- job_apply_agent/ats/form_preparation.py +452 -0
- job_apply_agent/ats/hybrid_harness.py +379 -0
- job_apply_agent/ats/lcu_bridge.mjs +94 -0
- job_apply_agent/ats/lcu_harness.py +226 -0
- job_apply_agent/ats/lcu_worker.sh +12 -0
- job_apply_agent/ats/page_readiness.py +119 -0
- job_apply_agent/ats/playwright_adapter.py +561 -0
- job_apply_agent/cli.py +108 -0
- job_apply_agent/collectors/__init__.py +7 -0
- job_apply_agent/collectors/ashby.py +64 -0
- job_apply_agent/collectors/base.py +75 -0
- job_apply_agent/collectors/greenhouse.py +50 -0
- job_apply_agent/collectors/job_link.py +471 -0
- job_apply_agent/collectors/lever.py +42 -0
- job_apply_agent/collectors/normalizer.py +156 -0
- job_apply_agent/config.py +190 -0
- job_apply_agent/db.py +40 -0
- job_apply_agent/domain/__init__.py +11 -0
- job_apply_agent/domain/enums.py +50 -0
- job_apply_agent/domain/schemas.py +173 -0
- job_apply_agent/examples/__init__.py +1 -0
- job_apply_agent/examples/answer-bank.json +7 -0
- job_apply_agent/examples/experiences.json +8 -0
- job_apply_agent/examples/profile.json +24 -0
- job_apply_agent/examples/search-policy.json +15 -0
- job_apply_agent/examples/source-boards.json +10 -0
- job_apply_agent/experience/__init__.py +1 -0
- job_apply_agent/experience/benchmark.py +199 -0
- job_apply_agent/experience/library.py +140 -0
- job_apply_agent/experience/reasoning.py +240 -0
- job_apply_agent/experience/retrieval.py +221 -0
- job_apply_agent/managed_apply.py +104 -0
- job_apply_agent/managed_backlog.py +410 -0
- job_apply_agent/models.py +133 -0
- job_apply_agent/onboarding.py +152 -0
- job_apply_agent/repository.py +54 -0
- job_apply_agent/resume/__init__.py +3 -0
- job_apply_agent/resume/composer.py +121 -0
- job_apply_agent/scheduler.py +115 -0
- job_apply_agent/services/__init__.py +18 -0
- job_apply_agent/services/answer_derivation.py +59 -0
- job_apply_agent/services/answers.py +71 -0
- job_apply_agent/services/application_report.py +144 -0
- job_apply_agent/services/artifacts.py +38 -0
- job_apply_agent/services/codex_narratives.py +64 -0
- job_apply_agent/services/facts.py +57 -0
- job_apply_agent/services/model_errors.py +93 -0
- job_apply_agent/services/narratives.py +278 -0
- job_apply_agent/services/orchestrator.py +149 -0
- job_apply_agent/services/policy.py +173 -0
- job_apply_agent/services/quota.py +88 -0
- job_apply_agent/services/resumes.py +86 -0
- job_apply_agent/services/review_actions.py +120 -0
- job_apply_agent/tasks.py +775 -0
- job_apply_agent/telegram/__init__.py +1 -0
- job_apply_agent/telegram/experiences.py +105 -0
- job_apply_agent/telegram/review.py +494 -0
- job_apply_cli-0.2.0.dist-info/METADATA +330 -0
- job_apply_cli-0.2.0.dist-info/RECORD +71 -0
- job_apply_cli-0.2.0.dist-info/WHEEL +4 -0
- job_apply_cli-0.2.0.dist-info/entry_points.txt +3 -0
- job_apply_cli-0.2.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"""DOM observations, checked stable identities, and independently read-back effects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
from typing import Any
|
|
9
|
+
from urllib.parse import urlparse
|
|
10
|
+
|
|
11
|
+
from playwright.async_api import Error, expect
|
|
12
|
+
|
|
13
|
+
from .captcha import inspect_captcha
|
|
14
|
+
from .cua_harness import UnsafeComputerAction, scroll_amount
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RecoverableBrowserError(RuntimeError):
|
|
18
|
+
"""A fresh observation/replan is allowed, but the previous action is not replayed."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
DESCRIBE = r"""root => {
|
|
22
|
+
const text = x => (x || '').replace(/\s+/g, ' ').trim();
|
|
23
|
+
const path = el => {
|
|
24
|
+
const parts = [];
|
|
25
|
+
for (let node=el; node?.parentElement; node=node.parentElement) {
|
|
26
|
+
const peers = [...node.parentElement.children].filter(x=>x.tagName===node.tagName);
|
|
27
|
+
parts.unshift(node.tagName.toLowerCase()+':nth-of-type('+(peers.indexOf(node)+1)+')');
|
|
28
|
+
}
|
|
29
|
+
return parts.join(' > ');
|
|
30
|
+
};
|
|
31
|
+
const describe = el => {
|
|
32
|
+
const labelled = (el.getAttribute('aria-labelledby') || '').split(/\s+/)
|
|
33
|
+
.map(id => el.ownerDocument.getElementById(id)?.textContent || '').join(' ');
|
|
34
|
+
const group = el.closest('fieldset,[role=group],.ashby-application-form-field-entry,.application-question');
|
|
35
|
+
const question = group?.querySelector('legend,.ashby-application-form-question-title,.application-label');
|
|
36
|
+
const labels = el.labels ? [...el.labels].map(x => x.textContent).join(' ') : '';
|
|
37
|
+
const tag = el.tagName.toLowerCase(), type = (el.type || '').toLowerCase();
|
|
38
|
+
const role = el.getAttribute('role') || ({button:'button',a:'link',select:'combobox',textarea:'textbox'}[tag]) ||
|
|
39
|
+
(tag === 'input' ? ({checkbox:'checkbox',radio:'radio',button:'button',submit:'button'}[type] || 'textbox') : '');
|
|
40
|
+
const label = text(labels || el.getAttribute('aria-label') || labelled || el.placeholder ||
|
|
41
|
+
(['button','a','option'].includes(tag) || el.getAttribute('role') ? el.textContent : '') || el.name);
|
|
42
|
+
const rect = el.getBoundingClientRect(), style = getComputedStyle(el);
|
|
43
|
+
return {tag, type, role, label, group:text(question?.textContent || ''), form_bound:!!el.form,
|
|
44
|
+
dom_id:el.id || '', dom_name:el.name || '', placeholder:el.getAttribute('placeholder') || '',
|
|
45
|
+
value:el.value == null ? '' : String(el.value), checked:!!el.checked,
|
|
46
|
+
required:!!el.required || el.getAttribute('aria-required') === 'true' ||
|
|
47
|
+
[...(question?.classList || [])].some(name=>name.startsWith('_required_')),
|
|
48
|
+
disabled:!!el.disabled || el.getAttribute('aria-disabled') === 'true',
|
|
49
|
+
visible:rect.width > 0 && rect.height > 0 && style.visibility !== 'hidden',
|
|
50
|
+
invalid:el.getAttribute('aria-invalid') === 'true',
|
|
51
|
+
validation:el.validationMessage || '', expanded:el.getAttribute('aria-expanded'),
|
|
52
|
+
pressed:el.getAttribute('aria-pressed'), focused:el === el.ownerDocument.activeElement,
|
|
53
|
+
listbox_id:el.closest('[role=listbox]')?.id || '',
|
|
54
|
+
options:tag === 'select' ? [...el.options].map(o=>text(o.textContent)) : [],
|
|
55
|
+
selected_labels:tag === 'select' ? [...el.selectedOptions].map(o=>text(o.textContent)) : [],
|
|
56
|
+
href:tag === 'a' ? el.href : '', link_path:tag === 'a' ? path(el) : '',
|
|
57
|
+
bounds:{x:rect.x,y:rect.y,width:rect.width,height:rect.height}};
|
|
58
|
+
};
|
|
59
|
+
if (root && root.nodeType === 1) return describe(root);
|
|
60
|
+
const all = [];
|
|
61
|
+
const collect = scope => {
|
|
62
|
+
for (const el of scope.querySelectorAll('*')) {
|
|
63
|
+
if (el.matches('input,textarea,select,button,a,[role=button],[role=combobox],[role=option],[role=checkbox],[role=radio]')) {
|
|
64
|
+
const item = describe(el);
|
|
65
|
+
if (item.visible && item.type !== 'hidden') all.push(item);
|
|
66
|
+
}
|
|
67
|
+
if (el.shadowRoot) collect(el.shadowRoot);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
collect(document);
|
|
71
|
+
return {elements:all.slice(0,300), truncated:all.length > 300,
|
|
72
|
+
scroll:{x:window.scrollX,y:window.scrollY}, text:text(document.body?.innerText).slice(-8000)};
|
|
73
|
+
}"""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def normalize(value: Any) -> str:
|
|
77
|
+
return " ".join(str(value or "").split()).casefold()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def same_identity(actual: dict, expected: dict) -> bool:
|
|
81
|
+
if "frame" in actual and "frame" in expected and actual["frame"] != expected["frame"]:
|
|
82
|
+
return False
|
|
83
|
+
if expected.get("tag") == "a" and any(
|
|
84
|
+
actual.get(k) != expected.get(k) for k in ("href", "link_path")
|
|
85
|
+
):
|
|
86
|
+
return False
|
|
87
|
+
return all(
|
|
88
|
+
normalize(actual.get(k)) == normalize(expected.get(k))
|
|
89
|
+
for k in ("tag", "type", "role", "label", "group")
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def fingerprint(observation: dict) -> str:
|
|
94
|
+
elements = [
|
|
95
|
+
{k: v for k, v in e.items() if k not in {"ref", "bounds"}} for e in observation["elements"]
|
|
96
|
+
]
|
|
97
|
+
state = {"url": observation["url"], "elements": elements, "scroll": observation["scroll"]}
|
|
98
|
+
return hashlib.sha256(json.dumps(state, sort_keys=True).encode()).hexdigest()[:16]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def is_final_control(element: dict, elements: list[dict]) -> bool:
|
|
102
|
+
has_form = any(
|
|
103
|
+
e["tag"] in {"input", "textarea", "select"} or e.get("pressed") is not None
|
|
104
|
+
for e in elements
|
|
105
|
+
)
|
|
106
|
+
if element.get("role") not in {"button", "link"} or not has_form:
|
|
107
|
+
return False
|
|
108
|
+
if element.get("type") == "submit" and element.get("form_bound"):
|
|
109
|
+
return True
|
|
110
|
+
return bool(
|
|
111
|
+
re.search(
|
|
112
|
+
r"\bsubmit\b|send application|complete application|apply now",
|
|
113
|
+
element.get("label", ""),
|
|
114
|
+
re.IGNORECASE,
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class DOMBrowser:
|
|
120
|
+
def __init__(self, page: Any, *, action_timeout_ms: int = 10_000) -> None:
|
|
121
|
+
self.page = page
|
|
122
|
+
self.initial_host = urlparse(page.url).hostname
|
|
123
|
+
self.timeout = action_timeout_ms
|
|
124
|
+
self.generation = 0
|
|
125
|
+
self.frames: dict[int, Any] = {}
|
|
126
|
+
|
|
127
|
+
def assert_origin(self) -> None:
|
|
128
|
+
if urlparse(self.page.url).hostname != self.initial_host:
|
|
129
|
+
raise UnsafeComputerAction("browser left the initial ATS host")
|
|
130
|
+
|
|
131
|
+
async def observe(self) -> dict:
|
|
132
|
+
self.assert_origin()
|
|
133
|
+
self.generation += 1
|
|
134
|
+
self.frames = {}
|
|
135
|
+
elements: list[dict[str, Any]] = []
|
|
136
|
+
excluded, scrolls = [], []
|
|
137
|
+
main_text = ""
|
|
138
|
+
truncated = False
|
|
139
|
+
for index, frame in enumerate(self.page.frames):
|
|
140
|
+
if frame != self.page.main_frame and urlparse(frame.url).hostname != self.initial_host:
|
|
141
|
+
excluded.append({"frame": index, "reason": "outside_initial_host"})
|
|
142
|
+
continue
|
|
143
|
+
try:
|
|
144
|
+
state = await frame.evaluate(DESCRIBE)
|
|
145
|
+
except Error:
|
|
146
|
+
excluded.append({"frame": index, "reason": "unavailable"})
|
|
147
|
+
continue
|
|
148
|
+
self.frames[index] = frame
|
|
149
|
+
if frame == self.page.main_frame:
|
|
150
|
+
main_text = state["text"]
|
|
151
|
+
truncated |= state["truncated"]
|
|
152
|
+
scrolls.append(state["scroll"])
|
|
153
|
+
for item in state["elements"]:
|
|
154
|
+
elements.append(
|
|
155
|
+
{
|
|
156
|
+
**item,
|
|
157
|
+
"frame": index,
|
|
158
|
+
"frame_url": frame.url,
|
|
159
|
+
"ref": f"d{self.generation}:{len(elements)}",
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
if 0 not in self.frames:
|
|
163
|
+
raise RecoverableBrowserError("main DOM is unavailable")
|
|
164
|
+
return {
|
|
165
|
+
"url": self.page.url,
|
|
166
|
+
"captcha": await inspect_captcha(self.page),
|
|
167
|
+
"elements": elements,
|
|
168
|
+
"text": main_text,
|
|
169
|
+
"excluded_frames": excluded,
|
|
170
|
+
"truncated": truncated,
|
|
171
|
+
"scroll": scrolls,
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async def locate(self, element: dict):
|
|
175
|
+
frame = self.frames.get(element["frame"])
|
|
176
|
+
if frame is None or frame.is_detached() or frame.url != element["frame_url"]:
|
|
177
|
+
raise RecoverableBrowserError("target frame changed; observe again")
|
|
178
|
+
candidates = []
|
|
179
|
+
for attribute, key in (("id", "dom_id"), ("name", "dom_name")):
|
|
180
|
+
if element.get(key):
|
|
181
|
+
candidates.append(frame.locator(f"[{attribute}={json.dumps(element[key])}]"))
|
|
182
|
+
if element["label"]:
|
|
183
|
+
candidates += [frame.get_by_label(element["label"], exact=True)]
|
|
184
|
+
if element["role"]:
|
|
185
|
+
candidates += [
|
|
186
|
+
frame.get_by_role(element["role"], name=element["label"], exact=True)
|
|
187
|
+
]
|
|
188
|
+
if element.get("placeholder"):
|
|
189
|
+
candidates.append(frame.get_by_placeholder(element["placeholder"], exact=True))
|
|
190
|
+
for candidate in candidates:
|
|
191
|
+
count = await candidate.count()
|
|
192
|
+
if count > 15:
|
|
193
|
+
continue
|
|
194
|
+
matches = []
|
|
195
|
+
for i in range(count):
|
|
196
|
+
current = candidate.nth(i)
|
|
197
|
+
try:
|
|
198
|
+
actual = await current.evaluate(DESCRIBE, timeout=self.timeout)
|
|
199
|
+
except Error:
|
|
200
|
+
continue
|
|
201
|
+
if same_identity(actual, element) and actual["visible"] and not actual["disabled"]:
|
|
202
|
+
matches.append(current)
|
|
203
|
+
if len(matches) == 1:
|
|
204
|
+
return matches[0]
|
|
205
|
+
if len(matches) > 1:
|
|
206
|
+
raise RecoverableBrowserError("target is ambiguous; observe again")
|
|
207
|
+
raise RecoverableBrowserError("stable target not found; observe again")
|
|
208
|
+
|
|
209
|
+
async def execute(self, action: dict, observation: dict) -> dict:
|
|
210
|
+
self.assert_origin()
|
|
211
|
+
kind = action["action"]
|
|
212
|
+
if kind == "scroll":
|
|
213
|
+
await self.page.mouse.wheel(
|
|
214
|
+
0, max(-1200, min(1200, scroll_amount(action.get("value"))))
|
|
215
|
+
)
|
|
216
|
+
return {"outcome": "delivered", "effect": "unverified"}
|
|
217
|
+
element = next((e for e in observation["elements"] if e["ref"] == action.get("ref")), None)
|
|
218
|
+
if element is None:
|
|
219
|
+
raise UnsafeComputerAction("action ref is not in the current DOM observation")
|
|
220
|
+
if is_final_control(element, observation["elements"]):
|
|
221
|
+
raise UnsafeComputerAction("planner attempted a final submit control")
|
|
222
|
+
if element["type"] in {"password", "file"}:
|
|
223
|
+
raise UnsafeComputerAction("planner cannot operate password or upload controls")
|
|
224
|
+
if element.get("href") and urlparse(element["href"]).hostname != self.initial_host:
|
|
225
|
+
raise UnsafeComputerAction("planner link leaves the initial ATS host")
|
|
226
|
+
if kind == "fill" and (
|
|
227
|
+
element["tag"] not in {"input", "textarea"}
|
|
228
|
+
or element["type"] in {"checkbox", "radio", "submit", "button"}
|
|
229
|
+
):
|
|
230
|
+
raise UnsafeComputerAction("fill is incompatible with the inspected control type")
|
|
231
|
+
locator = await self.locate(element)
|
|
232
|
+
try:
|
|
233
|
+
if kind == "fill":
|
|
234
|
+
await locator.fill(action["value"], timeout=self.timeout)
|
|
235
|
+
await expect(locator).to_have_value(action["value"], timeout=self.timeout)
|
|
236
|
+
elif kind == "select":
|
|
237
|
+
if element["tag"] != "select" or action["value"] not in element["options"]:
|
|
238
|
+
raise UnsafeComputerAction("select does not match a native option")
|
|
239
|
+
await locator.select_option(label=action["value"], timeout=self.timeout)
|
|
240
|
+
actual = await locator.locator("option:checked").all_text_contents()
|
|
241
|
+
if [normalize(x) for x in actual] != [normalize(action["value"])]:
|
|
242
|
+
raise RecoverableBrowserError("selected option did not persist")
|
|
243
|
+
elif kind in {"check", "uncheck"}:
|
|
244
|
+
if element["type"] not in {"checkbox", "radio"}:
|
|
245
|
+
raise UnsafeComputerAction("check action requires a native choice control")
|
|
246
|
+
await locator.set_checked(kind == "check", timeout=self.timeout)
|
|
247
|
+
await expect(locator).to_be_checked(checked=kind == "check", timeout=self.timeout)
|
|
248
|
+
elif kind == "click":
|
|
249
|
+
await locator.click(timeout=self.timeout)
|
|
250
|
+
return {"outcome": "delivered", "effect": "unverified"}
|
|
251
|
+
else:
|
|
252
|
+
raise UnsafeComputerAction("unsupported DOM action")
|
|
253
|
+
except (Error, AssertionError) as exc:
|
|
254
|
+
# Reobserve before any retry: a timeout can occur after delivery.
|
|
255
|
+
raise RecoverableBrowserError(
|
|
256
|
+
type(exc).__name__ + ": effect requires reinspection"
|
|
257
|
+
) from exc
|
|
258
|
+
return {"outcome": "verified", "effect": "field_readback"}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def semantic_issues(observation: dict) -> list[str]:
|
|
262
|
+
"""Reject the known past-employment narrative in a current-company field."""
|
|
263
|
+
issues = []
|
|
264
|
+
for item in observation["elements"]:
|
|
265
|
+
if (
|
|
266
|
+
re.search(r"\bcurrent (?:company|employer)\b", item.get("label", ""), re.IGNORECASE)
|
|
267
|
+
and item.get("value")
|
|
268
|
+
and re.search(
|
|
269
|
+
r"most recent|previous|during my studies|graduate|master.s",
|
|
270
|
+
item["value"],
|
|
271
|
+
re.IGNORECASE,
|
|
272
|
+
)
|
|
273
|
+
):
|
|
274
|
+
issues.append("current company contains an unverified employment narrative")
|
|
275
|
+
return issues
|