Skip to content

feat: add adaptive context pack representations - #218

Merged
mohanagy merged 7 commits into
mainfrom
issue-176-adaptive-context-representations
May 20, 2026
Merged

mohanagy merged 7 commits into
mainfrom
issue-176-adaptive-context-representations

Conversation

@mohanagy

@mohanagy mohanagy commented May 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add deterministic task-aware render modes for compiled and retrieved context packs without changing retrieval selection
  • preserve full explain snippets while keeping review and impact packs compact, and align compact PR-impact regression coverage with the new token-count contract
  • document the first-pass adaptive representation scope and the six core modes

Closes #176

Test Plan

  • npm run typecheck
  • npm run build
  • CI=1 npm run test:run

Summary by CodeRabbit

  • New Features

    • Added adaptive context-pack rendering modes that automatically select optimized representation formats (signature, behavior sketch, call chain, contract view, implementation excerpt, or dependency record) based on task type (explain, review, impact), while maintaining consistent node selection across tasks.
  • Tests

    • Added comprehensive test coverage for task-aware rendering behavior and representation type selection across different task modes.

Review Change Stack

mohanagy and others added 7 commits May 19, 2026 23:07
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e6b5dde8-b6fa-4dd6-a6e6-20848e5e072a

📥 Commits

Reviewing files that changed from the base of the PR and between c0c8610 and d91f0dd.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • README.md
  • src/contracts/context-pack.ts
  • src/runtime/context-pack-resolution.ts
  • src/runtime/context-pack.ts
  • src/runtime/retrieve.ts
  • tests/unit/context-pack-representation-modes.test.ts
  • tests/unit/context-pack-resolution-signature-132.test.ts
  • tests/unit/context-pack-resolution-sketch.test.ts
  • tests/unit/context-pack-resolution.test.ts
  • tests/unit/context-pack.test.ts
  • tests/unit/pr-impact.test.ts
  • tests/unit/retrieve.test.ts
  • tests/unit/stdio-pr-impact.test.ts

📝 Walkthrough

Walkthrough

This PR implements task-aware adaptive rendering for context packs. After node selection, the same retrieved nodes can be rendered in six deterministic modes (signature, behavior_sketch, call_chain, contract_view, implementation_excerpt, dependency_record) based on task kind (explain, review, impact), reducing tokens while preserving task-relevant evidence.

Changes

Adaptive Context-Pack Representation Modes

Layer / File(s) Summary
Type contracts and representation modes
src/contracts/context-pack.ts, src/runtime/context-pack-resolution.ts, src/runtime/retrieve.ts
ContextRepresentationType now includes three new variants (call_chain, contract_view, implementation_excerpt); ApplyResolutionOptions gains optional task_kind field; RetrieveMatchedNode includes optional representation_type and representation_reason.
Sketch resolution with signal-based selection
src/runtime/context-pack-resolution.ts
sketchResolution accepts taskKind parameter; new internal helpers extract representation "signals" (behavior, execution, tests/config, dependencies, side-effects, latency) from graph relations; renderSketchRepresentation refactored to dispatch across six deterministic modes based on taskKind and signal presence.
Compiled pack rendering pipeline
src/runtime/context-pack.ts
New exported renderCompiledContextPackNodes helper applies applyContextPackResolution when needed and computes token cost by selecting cheaper rendering (original vs resolved); compileContextPack uses rendered output for token_count and nodes; compactContextPack switches to per-node token summation via estimateContextPackEntryTokens.
Retrieve integration
src/runtime/retrieve.ts
contextPackFromRetrieveResult computes token_count via renderCompiledContextPackNodes instead of using input result.token_count, preserving evidence-class mapping and task-contract fields.
Task-aware rendering tests
tests/unit/context-pack-representation-modes.test.ts, tests/unit/context-pack-resolution-signature-132.test.ts, tests/unit/context-pack-resolution-sketch.test.ts, tests/unit/context-pack-resolution.test.ts, tests/unit/context-pack.test.ts
Comprehensive fixtures and test cases validate that node selection is stable across explain, review, and impact tasks while representation_type, representation_reason, and snippet contents change; verify fallback signature behavior; confirm task-specific token counts.
Token and assertion updates
tests/unit/pr-impact.test.ts, tests/unit/retrieve.test.ts, tests/unit/stdio-pr-impact.test.ts
Test assertions updated to compute token counts dynamically from rendered nodes; compact-payload and retrieve-pack tests validate task-aware representation differences and token reduction without changing serialization compatibility.
Documentation
CHANGELOG.md, README.md
Changelog describes the six deterministic rendering modes and token/detail trade-offs; README section clarifies that retrieval selection remains deterministic while rendering adapts by task.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client / Task Contract
  participant Resolution as applyContextPackResolution<br/>(with task_kind)
  participant SketchSelection as Representation Selection<br/>(signals + taskKind)
  participant Render as renderSketchRepresentation
  participant Output as Rendered Node<br/>(representation_type)
  
  Client->>Resolution: nodes, options.task_kind=explain
  Resolution->>SketchSelection: collect behavior/call/dependency signals
  SketchSelection->>SketchSelection: select behavior_sketch or call_chain
  SketchSelection->>Render: representation_type=call_chain
  Render->>Output: detailed snippet with execution path
  Output-->>Client: node with representation_reason
  
  Client->>Resolution: nodes, options.task_kind=review
  Resolution->>SketchSelection: collect behavior/dependency signals
  SketchSelection->>SketchSelection: select contract_view or implementation_excerpt
  SketchSelection->>Render: representation_type=contract_view
  Render->>Output: minimal contract-only snippet
  Output-->>Client: node with reduced token_count
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • mohanagy/graphify-ts#176: This PR directly implements issue #176's feature request for adaptive context-pack representation modes, including all six representation types, task-aware selection, deterministic rendering, test coverage, and documentation.

Possibly related PRs

  • mohanagy/graphify-ts#123: Both PRs modify src/runtime/context-pack-resolution.ts and the applyContextPackResolution pipeline—main PR extends sketch resolution with task-aware representation selection, while the retrieved PR introduced the multi-resolution detail/summary machinery.
  • mohanagy/graphify-ts#138: Both PRs modify resolution modes in src/runtime/context-pack-resolution.ts—main PR extends 'sketch' resolution with task-aware selection, while the retrieved PR adds 'signature' resolution branch, so they're related at the resolution-map level.
  • mohanagy/graphify-ts#121: Both PRs touch src/runtime/retrieve.ts contextPackFromRetrieveResult—main PR changes compiled-pack token accounting via renderCompiledContextPackNodes, while the retrieved PR changed module exports used downstream in stdio/delta paths.

Poem

🐰 Six shapes now dance in task-aware grace,
Each node knows its rightful place—
Explain wants breadth, reviews want tight,
Impact counts every link in sight!
Tokens fall as snippets trim,
Smart retrieval, getting grim! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add adaptive context pack representations' clearly and concisely describes the main change: introducing adaptive representation modes for context packs.
Description check ✅ Passed The description includes a clear summary, references the linked issue #176, and documents the test plan completion (typecheck, build, test:run). However, it omits the Testing section with checkbox items and the Checklist section from the template.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #176: supports six representation modes (signature, behavior_sketch, call_chain, contract_view, implementation_excerpt, dependency_record) [#176], implements task-aware selection based on task kind [#176], preserves provenance via representation_type/representation_reason fields [#176], adds comprehensive unit tests [#176], and documents modes in README/CHANGELOG [#176].
Out of Scope Changes check ✅ Passed All changes directly support the adaptive representation feature from issue #176. Modifications to context-pack contracts, resolution logic, runtime rendering, and comprehensive test coverage are all within scope of implementing task-aware representations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-176-adaptive-context-representations

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@mohanagy
mohanagy merged commit 2559ffc into main May 20, 2026
7 checks passed
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.

[P1][Retrieval] Add adaptive context representations

1 participant