hired.persistence#
dol-based persistence foundation for hired (Storage v2).
All hired persistence lives outside the repository under a single canonical
data root (~/.local/share/hired/ by default, overridable via HIRED_DATA_DIR).
Stores are MutableMapping views over the filesystem (via dol) with
filesystem codecs that keep keys extension-less while writing properly-extensioned
files. Per-candidate data is split two levels deep: a cross-JD user/ subtree
(UserStore) and per-engagement jds/<jd_id>/ subtrees (JDStore).
See misc/docs/DESIGN.md §4 for the full layout and rationale.
Functions
|
Return the canonical hired data directory, joined with |
|
Filesystem base for a candidate: |
|
Engagement ids under |
|
A |
|
A |
|
A |
|
One-time copy of a legacy store into the canonical root. |
|
Migrate the user to v2 if a legacy layout is detected. |
|
True iff any legacy v1 flat directory remains for this user. |
|
Migrate one user's flat v1 data to the v2 layout. |
Classes
|
Per-candidate cross-JD storage: raw sources + agent-maintained |
|
Per-engagement storage under |
|
Validated CRUD over a |
- class hired.persistence.JDStore(user, jd_id, *, root=None)[source]#
Bases:
objectPer-engagement storage under
users/<user>/jds/<jd_id>/.An engagement is one or a group of related JDs of the same company; it holds the parsed jobs, alignment reports (+ archived history), company research, and interview-prep briefings for that company’s role(s).
>>> import tempfile, os >>> os.environ['HIRED_DATA_DIR'] = tempfile.mkdtemp() >>> jd = JDStore('me', 'acme') >>> jd.reports['role-1'] = {'verdict': {'recommendation': 'apply'}} >>> jd.reports['role-1']['verdict']['recommendation'] 'apply' >>> jd.write_meta({'company': 'Acme'}) >>> jd.read_meta()['company'] 'Acme'
- class hired.persistence.Repository(store, *, model=None)[source]#
Bases:
Generic[M]Validated CRUD over a
MutableMappingfor a single pydantic model type.Subclasses set
modelandkey_of(). The store holds plain JSON-able dicts; models are validated on the way in and out.
- class hired.persistence.UserStore(user='me', *, root=None)[source]#
Bases:
objectPer-candidate cross-JD storage: raw sources + agent-maintained
info.rawis a bytes store;factsandqaare json stores;synopsisis a single markdown file accessed viaread_synopsis()/write_synopsis().>>> import tempfile, os >>> os.environ['HIRED_DATA_DIR'] = tempfile.mkdtemp() >>> us = UserStore() # default user "me" >>> us.facts['f1'] = {'statement': 'knows Python'} >>> us.facts['f1'] {'statement': 'knows Python'} >>> us.raw['cv.pdf'] = b'%PDF-1.4' >>> us.raw['cv.pdf'] b'%PDF-1.4' >>> us.write_synopsis('# me') >>> us.read_synopsis() '# me'
- hired.persistence.app_data_dir(*subpaths, make=True)[source]#
Return the canonical hired data directory, joined with
subpaths.The directory is created when
makeis true (the default).- Return type:
>>> import os, tempfile >>> os.environ['HIRED_DATA_DIR'] = tempfile.mkdtemp() >>> root = app_data_dir() >>> os.path.isdir(root) True >>> app_data_dir('users', 'me').endswith(os.path.join('users', 'me')) True
- hired.persistence.bytes_store(rootdir)[source]#
A
MutableMappingof rawbytes; keys are real filenames (extension kept).- Return type:
- hired.persistence.ensure_v2(user='me', *, root=None)[source]#
Migrate the user to v2 if a legacy layout is detected. Returns True if migrated.
- Return type:
- hired.persistence.is_legacy_layout(user='me', *, root=None)[source]#
True iff any legacy v1 flat directory remains for this user.
Gated on the presence of legacy dirs, not on the existence of
user/— a fully-migrated user has had its legacy dirs removed, so this returns False; a partially-migrated (interrupted) user still has some, so a re-run resumes.- Return type:
- hired.persistence.json_store(rootdir)[source]#
A
MutableMappingof JSON-able values: bare-id keys,<id>.jsonfiles.Built on
JsonFiles(dict↔JSON value codec) + a.jsonkey codec. Missing intermediate directories are created on write, so nested keys (e.g."job/stamp") work transparently.- Return type:
- hired.persistence.list_jds(user='me', *, root=None)[source]#
Engagement ids under
users/<user>/jds/(sorted; empty if none).
- hired.persistence.markdown_store(rootdir)[source]#
A
MutableMappingofstrvalues: bare keys,<key>.mdfiles.- Return type:
- hired.persistence.migrate_legacy(legacy_path, target_path)[source]#
One-time copy of a legacy store into the canonical root.
If
target_pathdoes not yet exist butlegacy_pathdoes, copy it (file or directory) so historical data is preserved when storage roots are unified. No-op otherwise. Returns True iff a copy happened.- Return type:
- hired.persistence.migrate_user_to_v2(user='me', *, root=None, company_of=None, dry_run=False)[source]#
Migrate one user’s flat v1 data to the v2 layout. Returns the move plan.
Idempotent: a no-op (empty plan) if the user is already on v2 or has no legacy data. With
dry_run=Truenothing is moved — the returned[(src, dst), ...]plan can be inspected first.
- hired.persistence.user_base(user='me', *, root=None)[source]#
Filesystem base for a candidate:
<root>or<data>/users/<user>.- Return type:
Modules
Canonical data root, filesystem codecs, and the two-level candidate layout. |
|
One-time migration of legacy flat per-user data to the Storage v2 layout. |
|
A small repository base that maps validated domain models to a key-value store. |