refactor: extract pure derive() function (#261) - #273
Conversation
91225ac to
db07251
Compare
|
Rebased onto current main (was branched from a stale base, would have reverted #253's classify-orphans pass on merge). Conflict in cli.py imports resolved as union (both doctor's classify_orphans helpers and the new derivation imports). Full suite green: 1804 passed, 8 skipped. Review: ready. |
…ve() Pure function that maps (raw_text, source_kind, source_path, …) to a Belief + edges with no MemoryStore dependency. Covers all four source-kind families: lock/remember (mcp_remember, cli_remember), triple-extraction (git), and classifier paths (filesystem, python_ast, etc.). Id schemes are byte-for-byte identical to the inline Belief constructions they replace so replay equality is id-stable. Closes half of #261 acceptance criterion 1-2.
Replace inline classify_sentence + Belief construction in _ingest_turn_ids with a derive() call. Store I/O (record_ingest, insert_belief) unchanged; only the belief derivation is delegated. Remove now-unused hashlib import.
Replace _route_from_regex + inline Belief construction with a derive() call for the default regex path. The LLM-router path retains inline Belief construction since the router already encapsulates classification; it still removes the _route_from_regex helper. Remove unused classify_sentence and ORIGIN_AGENT_INFERRED imports.
…ve() Replace get_source_adjusted_prior + inline Belief construction in accept_classifications with a derive() call using override_belief_type. Add override_belief_type field to DerivationInput for host-LLM-classified paths; add get_source_adjusted_prior to derivation.py imports. Use lazy import inside accept_classifications to break the derive->classify_sentence import cycle.
Replace _resolve_or_create_belief's inline Belief construction with a derive() call (source_kind=git). Remove now-dead _belief_id_for_phrase, _content_hash, and _BELIEF_ID_HEX_LEN; remove hashlib import.
Replace inline Belief construction in tool_lock with a derive() call (source_kind=mcp_remember). Remove now-dead _lock_id_for, _content_hash, and hashlib import; remove _LOCK_ID_LEN constant.
Replace inline Belief construction in _cmd_lock with a derive() call (source_kind=cli_remember). Remove dead _lock_id_for, _content_hash, _LOCK_ID_LEN; remove hashlib import; remove BELIEF_FACTUAL and Belief from models imports.
26 tests covering filesystem (factual/requirement/preference/correction/ skip), python_ast, git (triple path), mcp_remember, cli_remember, override_belief_type (accept_classifications path), feedback_loop_synthesis, legacy_unknown, ts default, edges=[], and determinism. Each test states a falsifiable hypothesis per project convention.
db07251 to
5bf0c7b
Compare
|
Review: structurally clean — Two coordination notes, not blockers:
Did not deep-dive into every call-site rewrite (1425-line diff across six modules); pytest 1790-passed in your PR body is the primary signal that behavior didn't change. If you want a closer pair of eyes on a specific call site, leave a thread on the PR and I'll re-claim. Dropping |
Summary
src/aelfrice/derivation.pyexposingDerivationInput,DerivationOutput, andderive()— a pure function with noMemoryStoredependency that maps raw text + source metadata to aBelief(or skip).ingest.py,scanner.py,classification.py,triple_extractor.py,mcp_server.py,cli.py) throughderive()instead of constructingBeliefinline. Store I/O (record_ingest,insert_belief) is unchanged at each call site._lock_id_for,_content_hash,_belief_id_for_phrase) now that the logic lives inderivation.py.tests/test_derivation.pywith 26 unit tests covering everysource_kindinINGEST_SOURCE_KINDS, theoverride_belief_typepath, determinism, and id-scheme cross-checks.No behavior change. Full pytest suite: 1790 passed, 8 skipped.
Closes #261
Touched files
src/aelfrice/derivation.py(new)src/aelfrice/ingest.pysrc/aelfrice/scanner.pysrc/aelfrice/classification.pysrc/aelfrice/triple_extractor.pysrc/aelfrice/mcp_server.pysrc/aelfrice/cli.pytests/test_derivation.py(new)Review
Verify that
derive()has zeroMemoryStoreimports; check that id-scheme assertions intest_derivation.pymatch the sha256 formulas previously in each call site; confirm no behavior change by running the full suite.