Every way a company gets a board is set_board, and an unreadable host keeps its slug

`app.jobs.sources.set_board` attaches a board to an existing company,
replaces the one it has (closing the old board's open roles) or creates
the company, with row and subscription changed in one transaction by
`Store.set_company_board`. A board that lists zero roles is kept. `add`,
`discover --add`, the seed importer (moved out of app/cli.py) and the new
`POST|DELETE /api/companies/{key}/board` all go through it; a seed re-run
attaches a board to a row that never had one. A company's subscription is
rewritten in place, and detaching hides it.

`companies.ats_slug` (migration 9) keeps the slug of a host the app
cannot read yet, and discovery returns such a host before probing slugs.
The Companies rows get Set board / Change, the host select is rendered
from `plugins.ats.HOSTS`, and a row with nothing found reads "board not
found" and is in the "Not readable yet" filter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 14:04:52 +02:00
1 parent 0558ef19ed
commit 3b209d628a
18 files changed
+1038 -178

No files matched your search

+65 -54
View File
@@ -3,7 +3,7 @@
app serve [--host H] [--port P] [--reload]
app job pull|extract|embed|score [--payload JSON]
app worker [--workers http=8,cpu=1] [--until-idle]
app companies seed|add|discover|check
app companies seed|add|set-board|detach|discover|check
app searches add|list|remove
app db init
@@ -67,17 +67,26 @@ def build_parser() -> argparse.ArgumentParser:
companies = sub.add_parser("companies", help="the target company list")
companies_sub = companies.add_subparsers(dest="action", required=True)
seed = companies_sub.add_parser(
"seed", help="import seed/companies.json, subscribing to each readable board")
"seed", help="import seed/companies.json, and the boards it names for rows without one")
seed.add_argument("--path", default="seed/companies.json")
add = companies_sub.add_parser("add", help="add one company from its board")
add = companies_sub.add_parser(
"add", help="follow a company by its board, attaching or replacing an existing one's")
add.add_argument("board", help="host:slug, e.g. greenhouse:acme")
add.add_argument("name")
set_board = companies_sub.add_parser(
"set-board", help="attach a board to a company, or replace the one it has")
set_board.add_argument("key", help="the company key, e.g. trade-republic")
set_board.add_argument("board", help="host:slug, e.g. greenhouse:acme")
detach = companies_sub.add_parser(
"detach", help="stop reading a company's board and close its roles; the row stays")
detach.add_argument("key")
discover = companies_sub.add_parser(
"discover", help="find a company's board from its website; --add follows it")
discover.add_argument("name")
discover.add_argument("domain", help="its website, e.g. pleo.io")
discover.add_argument("--add", action="store_true",
help="add the company, with its board when one is readable")
help="add or update the company: its board when one is readable, "
"else the host it runs on")
companies_sub.add_parser("check", help="report boards that do not answer")
searches = sub.add_parser("searches", help="saved searches on cross-company job boards")
@@ -230,69 +239,41 @@ def run_companies(args: argparse.Namespace) -> int:
config = config_mod.load(args.config)
store = Store(config.database)
if args.action == "seed":
print(json.dumps(seed_companies(store, args.path)))
return 0
return seed_companies(store, args.path)
if args.action == "add":
return add_company(store, args.board, args.name)
if args.action == "set-board":
return set_board(store, args.key, args.board)
if args.action == "detach":
return detach_board(store, args.key)
if args.action == "discover":
return discover_company(store, args.name, args.domain, add=args.add)
return check_companies(store)
def seed_companies(store: Store, path: str) -> dict[str, int]:
"""Import `seed/companies.json`: one `companies` row per entry, and one
`ats` subscription for each entry with a readable `board`. An entry
without one is the point of the list as much as one with: a company worth
following whose careers site the app cannot read yet keeps its `ats`
host and `careers_url`, and the Companies section says so. A key that
already exists is skipped, so re-running only ever adds what is missing;
it never edits a row."""
from app.models import company_key
from plugins.ats import careers_url, is_known_target
def seed_companies(store: Store, path: str) -> int:
"""`app companies seed`: `app.jobs.sources.seed_companies`, its counts as
JSON and each entry that did not land whole on stderr."""
from app import jobs
data = json.loads(Path(path).read_text(encoding="utf-8"))
added = readable = skipped = 0
for row in data.get("companies", []):
name = row["name"]
key = row.get("key") or company_key(name)
if store.company(key) is not None:
skipped += 1
continue
board = row.get("board") or ""
if board and not is_known_target(board):
print(f"companies seed: {key}: {board!r} is not a known board; kept without it",
file=sys.stderr)
board = ""
host = board.partition(":")[0]
store.add_company(
name, key=key, domain=row.get("domain", ""),
careers_url=row.get("careers_url") or (careers_url(board) if board else ""),
ats=row.get("ats") or host, country=row.get("country", ""),
city=row.get("city", ""))
added += 1
if not board:
continue
try:
store.add_subscription("ats", board, label=name, company=name, board=host)
readable += 1
except ValueError as exc:
# The company row landed; the subscription is the only thing
# missing, and worth saying rather than losing silently.
print(f"companies seed: {key}: {exc}", file=sys.stderr)
return {"added": added, "readable": readable, "skipped": skipped,
"total": len(data.get("companies", []))}
result = jobs.sources.seed_companies(store, path)
for problem in result.pop("problems"):
print(f"companies seed: {problem}", file=sys.stderr)
print(json.dumps(result))
return 0
def discover_company(store: Store, name: str, domain: str, *, add: bool) -> int:
"""`app companies discover "Pleo" pleo.io [--add]`: what the company's
site says its board is, as JSON. With `--add`, the company is added the
way the seed adds it: with its board when one is readable, as a row the
app cannot read yet otherwise."""
site says its board is, as JSON. With `--add`, the company is added or
updated: its board attached or replaced when one is readable, else the
host and slug it runs on recorded; see `add_discovered`."""
from app import jobs
found = jobs.discover.discover(name, domain)
out: dict[str, Any] = {"name": name, "domain": domain, "board": found.board,
"ats": found.ats, "careers_url": found.careers_url,
"ats": found.ats, "ats_slug": found.ats_slug,
"careers_url": found.careers_url,
"evidence": found.evidence}
if add:
try:
@@ -306,8 +287,8 @@ def discover_company(store: Store, name: str, domain: str, *, add: bool) -> int:
def add_company(store: Store, board: str, name: str) -> int:
"""`app companies add greenhouse:acme "Acme"`: fetch the board first
and refuse if it does not answer, is not a known host, or the company
already exists. Port of seedgen's `-add`."""
and refuse if it does not answer or is not a known host. A company that
exists gets the board attached or replaced. Port of seedgen's `-add`."""
from app import jobs
from app.models import company_key
@@ -320,12 +301,42 @@ def add_company(store: Store, board: str, name: str) -> int:
return 0
def set_board(store: Store, key: str, board: str) -> int:
"""`app companies set-board trade-republic greenhouse:traderepublic`:
attach the board to an existing company or replace the one it has."""
from app import jobs
try:
sub, found, closed = jobs.sources.set_board(store, key, board)
except ValueError as exc:
print(f"companies set-board: {exc}", file=sys.stderr)
return 1
print(json.dumps({"key": key, "board": sub.target, "roles": found, "closed": closed}))
return 0
def detach_board(store: Store, key: str) -> int:
"""`app companies detach acme`: stop reading its board, close its roles."""
from app import jobs
try:
closed = jobs.sources.detach_board(store, key)
except KeyError:
print(f"companies detach: no company {key!r}", file=sys.stderr)
return 1
except ValueError as exc:
print(f"companies detach: {exc}", file=sys.stderr)
return 1
print(json.dumps({"key": key, "closed": closed}))
return 0
def check_companies(store: Store) -> int:
"""`app companies check`: every `ats` board, fetched once. Prints a
line per board that did not answer and exits 1 if any did not."""
from plugins.ats import fetch_board
subs = store.subscriptions(source="ats")
subs = [s for s in store.subscriptions(source="ats") if s.show]
dead = []
for sub in subs:
try: