Skip to content

[refactor] Decompose context/manager.py — extract ingestion helpers into context/ingest.py #148

@dgenio

Description

@dgenio

Problem

src/contextweaver/context/manager.py is currently 786 lines (765 on main), well over the project's ≤ 300 lines per module guideline (AGENTS.md coding style). manager.py is not in the exempt list (types.py, envelope.py, __main__.py).

This was flagged during review of #147 (logging integration), which added +21 lines. The debt is pre-existing — not caused by #147.

Proposal

Extract the ingestion helpers into a new src/contextweaver/context/ingest.py module:

  • ingest() method logic
  • ingest_tool_result() and its sync variant ingest_tool_result_sync()
  • Related private helpers used only by ingestion

ContextManager would retain the public ingest() / ingest_tool_result() methods as thin delegating wrappers, keeping the API surface unchanged.

Expected impact

  • manager.py line count reduced significantly (ingestion code is ~150+ lines including docstrings)
  • ingest.py stays well under 300 lines
  • No public API changes — ContextManager remains the single entry point

Constraints

  • Must preserve ContextManager as the public API — callers should not need to import from context/ingest.py
  • Must follow context/ path conventions: async-first with _sync wrappers
  • Must not break the 8-stage pipeline ordering or firewall invariants
  • Update AGENTS.md module map if a new file is added

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/contextContext engine: manager, pipeline, firewallcomplexity/averageStandard effort, moderate familiarity neededenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions