Skip to content

Implement RPG-Encoder Evolution (commit-level incremental updates) #10

Description

@amondnet

Summary

Implement commit-level incremental maintenance (Evolution) — the key differentiator of the RPG-Encoder paper achieving 95.7% cost reduction over full re-encoding.

Paper: RPG-Encoder §4 (arXiv:2602.02084)

Tasks

  • Delta-Level Feature Extraction: Parse only changed code from commit diffs
  • Recursive Pruning (deletion): Node deletion + automatic empty ancestor cleanup
  • Differential Modification: Semantic drift detection → in-place update vs re-routing
  • LLM-Based Semantic Routing (insertion): Route new entities to semantically optimal positions

Current State

RPGEncoder.encode() encodes the entire repository from scratch. No incremental update logic exists.

Acceptance Criteria

  • Process only changed files based on commit diffs
  • Clean up nodes/edges for deleted entities with ancestor pruning
  • Detect semantic changes in modified entities and update appropriately
  • Route new entities to optimal positions
  • Measure cost reduction vs full re-encoding

Related Files

  • src/encoder/encoder.ts
  • src/graph/rpg.ts
  • src/graph/node.ts, src/graph/edge.ts

Activity

  1. added theissue type on Feb 6, 2026
  2. self-assigned this
    on Feb 6, 2026
  3. amondnet commented on Feb 6, 2026

    @amondnet
    ContributorAuthor

    Implementation Plan

    Plan file: .please/plans/2026-02-06-rpg-encoder-evolution.md
    Approach: Paper-Faithful — 3 atomic operations from RPG-Encoder §4 (arXiv:2602.02084)

    Architecture

    New src/encoder/evolution/ module with 7 files:

    • types.ts — EvolutionOptions, DiffResult, ChangeEvent
    • diff-parser.ts — Git diff → (U+, U-, U~) categorization
    • operations.ts — DeleteNode (recursive pruning), InsertNode (semantic routing), ProcessModification (drift detection)
    • semantic-router.ts — FindBestParent LLM-based top-down routing
    • prompts.ts — LLM prompt templates
    • evolve.ts — RPGEvolver orchestrator
    • index.ts — Public exports

    Key Design Decisions

    1. Git diff via git CLI (Bun.spawn) — no external git library
    2. Entity matching by qualified name (filePath:entityType:qualifiedName) — stable across line changes
    3. Semantic drift via cosine similarity (embedding) with keyword Jaccard fallback
    4. Scheduling order: Delete → Modify → Insert (paper §A.2.1)
    5. RPG via parameter: evolve(rpg, options) — stateless design

    Tasks (15 total)

    Task Description Depends On
    T001 [P] Define Evolution types —
    T002 [P] Git diff parser (ParseUnitDiff) —
    T003 DeleteNode + recursive pruning T001
    T004 LLM semantic routing (FindBestParent) T001
    T005 LLM prompts (routing + drift) T001
    T006 InsertNode + dependency injection T003, T004, T005
    T007 ProcessModification + drift detection T003, T006
    T008 RPGEvolver orchestrator T002, T006, T007
    T009 Wire encoder.ts evolve() T008
    T010 Module index exports T008
    T011 Tests: diff-parser (AC-1) T002
    T012 Tests: operations (AC-2/3/4) T007
    T013 Tests: integration + cost (AC-5) T009
    T014 Update encoder test T009
    T015 Update implementation-status.md T009

    Acceptance Criteria Mapping

    • AC-1 (only changed files) → T011 verifies unchanged files are skipped
    • AC-2 (delete + prune) → T012 verifies CASCADE deletion + recursive pruning
    • AC-3 (semantic drift) → T012 verifies in-place vs re-routing
    • AC-4 (LLM routing) → T012 verifies FindBestParent routing
    • AC-5 (cost reduction) → T013 tracks llmCalls vs full re-encode (target >90%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions