Skip to content

Feat/complete v0.1 implementation#5

Merged
dgenio merged 14 commits into
mainfrom
feat/complete-v0.1-implementation
Mar 2, 2026
Merged

Feat/complete v0.1 implementation#5
dgenio merged 14 commits into
mainfrom
feat/complete-v0.1-implementation

Conversation

@dgenio
Copy link
Copy Markdown
Owner

@dgenio dgenio commented Mar 2, 2026

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.0 to reflect these enhancements.

Adapters and Session Replay Enhancements:

  • Implemented load_a2a_session_jsonl and load_mcp_session_jsonl functions to enable replaying protocol sessions from JSONL files into lists of ContextItem objects, with error handling for file and JSON issues. [1] [2]
  • Completed conversion logic for A2A agent cards and MCP tool definitions to SelectableItem, and for protocol results to ResultEnvelope, including extraction of artifacts, facts, and provenance. [1] [2]

Public API Expansion (__init__.py):

  • Added imports and __all__ exports for new protocol, routing, store, and summarization classes and functions, making them available at the top-level package API. [1] [2] [3]
  • Updated version string to 0.1.0 to reflect breaking and feature changes.

Internal Refactoring:

  • Improved type annotations and imports in ContextManager to 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.

dgenio added 2 commits March 2, 2026 08:53
- 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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ContextManager with ingestion helpers, fact/episode helpers, budget overrides, and a route-integrated prompt builder.
  • Broaden the top-level contextweaver public API exports and bump __version__ to 0.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.

Comment thread src/contextweaver/adapters/mcp.py Outdated
Comment thread src/contextweaver/adapters/a2a.py Outdated
Comment thread src/contextweaver/adapters/a2a.py Outdated
Comment thread src/contextweaver/__init__.py Outdated
Comment thread src/contextweaver/context/manager.py Outdated
Comment thread src/contextweaver/context/manager.py Outdated
Comment thread src/contextweaver/context/manager.py
Comment thread src/contextweaver/adapters/mcp.py Outdated
dgenio added 12 commits March 2, 2026 09:41
- 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 dgenio merged commit c36200b into main Mar 2, 2026
3 checks passed
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)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants