Feat/complete v0.1 implementation#5
Merged
Conversation
- mcp_tool_to_selectable: convert MCP tool definitions to SelectableItem - mcp_result_to_envelope: convert MCP call results to ResultEnvelope - load_mcp_session_jsonl: load MCP session logs as ContextItems - a2a_agent_to_selectable: convert A2A agent cards to SelectableItem - a2a_result_to_envelope: convert A2A task results to ResultEnvelope - load_a2a_session_jsonl: load A2A session logs as ContextItems - 27 comprehensive adapter tests covering all functions
…, routing - StoreBundle constructor for pre-wired stores - ingest(), ingest_sync(), ingest_async() for event log appends - ingest_tool_result() with firewall integration for large outputs - add_fact() / add_episode() for memory stores - build_route_prompt() integrating Router + ChoiceCards + context - Episodic memory and facts injection into prompt header - budget_tokens override for per-call budget control - Wire up all public exports in __init__.py (version 0.1.0) - 25 manager tests covering all new methods
There was a problem hiding this comment.
Pull request overview
This PR completes the v0.1 adapter + API surface work for contextweaver by adding JSONL session replay loaders for MCP/A2A, fleshing out protocol conversion helpers, and expanding the high-level ContextManager + top-level exports to make integration and replay workflows easier.
Changes:
- Implement MCP/A2A adapters for converting tool/agent descriptors and results, plus JSONL session replay loaders.
- Expand
ContextManagerwith ingestion helpers, fact/episode helpers, budget overrides, and a route-integrated prompt builder. - Broaden the top-level
contextweaverpublic API exports and bump__version__to0.1.0.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_manager.py | Adds tests for new ContextManager ingestion, stores, budget override, and per-phase builds. |
| tests/test_adapters.py | Adds tests for MCP/A2A adapters and JSONL session loaders. |
| src/contextweaver/context/manager.py | Introduces StoreBundle support, ingestion helpers, fact/episode stores, header injection, budget overrides, and build_route_prompt. |
| src/contextweaver/adapters/mcp.py | Implements MCP tool/result conversion and JSONL session replay loader. |
| src/contextweaver/adapters/a2a.py | Implements A2A agent/result conversion and JSONL session replay loader. |
| src/contextweaver/adapters/init.py | Re-exports new adapter helpers/loaders from the adapters package. |
| src/contextweaver/init.py | Expands top-level exports and bumps __version__ to 0.1.0. |
- Add isinstance(obj, dict) guard for non-dict JSON values - Wrap field extraction in try/except (TypeError, ValueError, AttributeError) CatalogError with line number - Apply same fix to both load_mcp_session_jsonl and load_a2a_session_jsonl - Add 6 tests: non-dict lines, bad token_estimate, bad metadata - Include ruff formatting pass on manager.py/test_manager.py All 382 tests passing, mypy clean, ruff clean.
Add docstring note to a2a_result_to_envelope and mcp_result_to_envelope explaining that returned ArtifactRef entries are not persisted to an ArtifactStore. Callers needing resolvable handles should use ContextManager.ingest_tool_result or store data separately.
…dcoding text/plain - apply_firewall now reads item.metadata['media_type'] with fallback to 'text/plain', so ingest_tool_result's media_type parameter is honored - Add 2 tests: media_type propagation from metadata, default fallback All 384 tests passing, mypy clean, ruff clean.
…d growth - Add module-level _MAX_FACT_LINES=64 and _MAX_FACT_CHARS=2000 constants - Fact injection now stops at line cap (with '... N more facts omitted') or char cap (with '... facts truncated to fit header budget') - Add 2 tests: line-count cap and char-budget cap
- test_build_route_prompt_returns_tuple: verifies (pack, cards, route_result) structure, phase=route, GOAL header, AVAILABLE TOOLS footer - test_build_route_prompt_sync_alias: verifies sync wrapper works
- Pre-build episodic + fact injection text before select_and_pack() - Estimate header/footer token cost via the configured TokenEstimator - Subtract overhead from effective budget so selection stays within limit - Add BuildStats.header_footer_tokens field for full observability - Update BuildStats.to_dict/from_dict with new field - Add 3 tests: tokens recorded, zero without injection, budget subtraction
- New _common.py with _load_session_jsonl(path, default_kind, id_prefix, label) - mcp.py and a2a.py now delegate to the shared helper - Eliminates ~95% code duplication between the two JSONL loaders - Removes unused json import from both adapter modules
Remove 57 tmpclaude-* scratch files from version control and add tmpclaude-* pattern to .gitignore to prevent future tracking.
dgenio
added a commit
that referenced
this pull request
Apr 15, 2026
- Move routing_config to keyword-only position in Router.__init__ to preserve positional argument backward compatibility (#1) - Add two focused tests for routing_config override behavior in test_router.py (#2) - Document policy omission in ProfileConfig.to_dict()/from_dict() docstrings with Note: blocks (#3) - Use ContextBudget()/ScoringConfig() defaults in ProfileConfig.from_dict() instead of hardcoded literals to prevent drift (#4) - Add ConfigError to contextweaver.exceptions; replace bare ValueError in ProfileConfig.from_preset(); export ConfigError from __init__; update test_config.py to assert ConfigError (#5) - Fold answer_budget into _ROUTING_PRESETS tuple (6th element) to keep all preset data in a single structure (#6) - Merge duplicate ### Added sections in CHANGELOG.md into one (#7)
7 tasks
dgenio
pushed a commit
that referenced
this pull request
May 16, 2026
- benchmark_delta.py: render status-bearing matrix rows as "skipped" with the reason text instead of treating zeroed metrics as a real regression (Copilot #4). +2 tests. - benchmark.py: validate --backends against the supported set (tfidf, bm25, fuzzy) and exit with argparse-style code 2 on typos rather than a ConfigError traceback from Router init (Copilot #5). +2 tests. - sweep_scoring.py: drop the unreachable `if default_row is not None and not default_row.is_default: pass` branch in render_report() (Copilot #7). - benchmark.py: emit naive_delta.naive_tokens / cw_tokens as ints (counts), matching the NaiveDelta dataclass and avoiding the int(float(...)) coercion in renderers (Copilot #8). - README.md / CHANGELOG.md: matrix and per_namespace live at the top of latest.json, not nested under routing (Copilot #2, #3). Comments #1 (_DELIM_CHARS missing _) and #6 (sweep_scoring.py size) are non-actionable — #1 is a false positive (underscore is already present; verified by behavioural test on _foo_) and #6 follows the existing scripts/ precedent (render_scorecard.py = 526 lines) acknowledged in the PR description. make ci: all 6 targets clean. make scorecard-check + make llms-check also clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to the contextweaver adapters and public API, focusing on making session replay and protocol integration easier and more robust. The main changes include implementing session JSONL loaders for both A2A and MCP protocols, completing the conversion logic for agent/tool descriptors and results, and expanding the top-level API surface for better usability. Additionally, the version is bumped to
0.1.0to reflect these enhancements.Adapters and Session Replay Enhancements:
load_a2a_session_jsonlandload_mcp_session_jsonlfunctions to enable replaying protocol sessions from JSONL files into lists ofContextItemobjects, with error handling for file and JSON issues. [1] [2]SelectableItem, and for protocol results toResultEnvelope, including extraction of artifacts, facts, and provenance. [1] [2]Public API Expansion (
__init__.py):__all__exports for new protocol, routing, store, and summarization classes and functions, making them available at the top-level package API. [1] [2] [3]0.1.0to reflect breaking and feature changes.Internal Refactoring:
ContextManagerto support new features and ensure compatibility with the expanded API. [1] [2]These changes collectively make contextweaver much easier to integrate with external agent/tool protocols and replay real-world sessions for context compilation and analysis.