Grand Diomande Research · Full HTML Reader

METAMORPHOSIS: Context-Aware Code Suggestions from Orbit Logs

METAMORPHOSIS mines historical Orbit data (prompt logs, session histories, noosphere connections, plans) to build a pattern model of developer behavior. It predicts what code actions, files, and tools the developer will need next based on:

Research Backlog architecture technical paper candidate score 44 .md

Full Public Reader

METAMORPHOSIS: Context-Aware Code Suggestions from Orbit Logs

Architecture Document

Dream ID: dream_202601260830_3071c1
Version: 1.0.0
Date: 2026-02-09

---

1. Executive Summary

METAMORPHOSIS mines historical Orbit data (prompt logs, session histories, noosphere connections, plans) to build a pattern model of developer behavior. It predicts what code actions, files, and tools the developer will need next based on:

  • Current project context (which project, which files, git state)
  • Session phase (early exploration vs deep implementation)
  • Historical co-occurrence patterns (what actions typically follow what)
  • Cross-project knowledge transfer (patterns learned in one project apply to similar ones)

2. Data Sources

2.1 Primary Sources (Available in [home-path])

SourcePathRecordsContent
Prompt Logs`prompt-logs/prompts-all.jsonl`2,355Every prompt with cwd, git context, session ID, timestamps
Session History`history.jsonl`884Display text, project, session grouping
Noosphere`noosphere/connections.json`145 nodesDreams, orbit contexts, plans with semantic connections
Plans`plans/`43+Architectural plans with status tracking
Project Map`orbit-project-map.json`8 projectsProject ID mappings
Per-Project Prompts`prompt-logs/projects/*/prompts.jsonl`VariesProject-scoped prompt sequences

2.2 Derived Data

DerivedDescription
Action SequencesOrdered prompt chains within sessions
Project FingerprintsCharacteristic action patterns per project
Transition MatricesProbability of action B following action A
Temporal PatternsTime-of-day and session-duration correlations
Keyword ClustersGroups of semantically related prompts

3. Architecture

┌─────────────────────────────────────────────────────┐
│                   Suggestion API                     │
│  suggest(project, recent_prompts, files) → [...]    │
├─────────────────────────────────────────────────────┤
│               Pattern Matching Engine                │
│  ┌──────────┐ ┌──────────┐ ┌───────────────────┐   │
│  │ Sequence  │ │ Project  │ │ Cross-Project     │   │
│  │ Matcher   │ │ Context  │ │ Transfer          │   │
│  └──────────┘ └──────────┘ └───────────────────┘   │
├─────────────────────────────────────────────────────┤
│               Pattern Mining Engine                  │
│  ┌──────────┐ ┌──────────┐ ┌───────────────────┐   │
│  │ Action    │ │ N-gram   │ │ Session Phase     │   │
│  │ Classifier│ │ Extractor│ │ Detector          │   │
│  └──────────┘ └──────────┘ └───────────────────┘   │
├─────────────────────────────────────────────────────┤
│                  Data Ingestion                       │
│  ┌──────────┐ ┌──────────┐ ┌───────────────────┐   │
│  │ Prompt    │ │ History  │ │ Noosphere         │   │
│  │ Parser    │ │ Parser   │ │ Parser            │   │
│  └──────────┘ └──────────┘ └───────────────────┘   │
├─────────────────────────────────────────────────────┤
│                 Raw Data Layer                        │
│  prompts-all.jsonl  history.jsonl  connections.json  │
└─────────────────────────────────────────────────────┘

4. Pattern Mining Pipeline

### Stage 1: Data Ingestion
- Parse all JSONL files into structured records
- Normalize project paths to canonical names
- Group prompts into sessions with temporal ordering
- Extract git context (repo, branch, dirty state)

### Stage 2: Action Classification
Each prompt is classified into an action category:
- `create` — Creating new files, projects, features
- `fix` — Bug fixes, error resolution
- `build` — Build/compile/deploy operations
- `navigate` — Reading, exploring, checking status
- `refactor` — Moving, renaming, restructuring
- `configure` — Installing, setting up, configuring
- `test` — Testing, debugging, validation
- `continue` — Continuation of previous action
- `meta` — Commands, slash-commands, system operations

### Stage 3: N-gram Extraction
- Build bigram and trigram models of action sequences within sessions
- Weight by recency (recent sessions count more)
- Track per-project and global patterns separately

### Stage 4: Session Phase Detection
Sessions follow predictable phases:
1. Orientation (first 1-3 prompts) — Reading, checking, understanding
2. Planning (prompts 3-6) — Creating plans, discussing architecture
3. Implementation (prompts 6-20+) — Building, creating, writing code
4. Refinement (late session) — Fixing, testing, polishing
5. Wrap-up (final prompts) — Deploying, committing, documenting

### Stage 5: Cross-Project Transfer
- Cluster projects by their action fingerprints
- When a developer starts a new project, suggest patterns from similar projects
- Use noosphere connections to find semantically related contexts

5. Suggestion Generation

Input Context

python
{
    "project": "/Users/.../current-project",
    "recent_prompts": ["last 3-5 prompts"],
    "session_phase": "implementation",  # auto-detected
    "files_open": ["optional"],
    "git_state": {"branch": "...", "dirty": true}
}

Output Suggestions

python
[
    {
        "suggestion": "Consider adding tests for the new feature",
        "action_type": "test",
        "confidence": 0.82,
        "basis": "After 3+ create actions, testing follows 82% of the time",
        "related_contexts": ["orbit_abc123"]
    },
    ...
]

### Ranking Algorithm
1. Sequence match score — How well does current sequence match known patterns?
2. Project context score — How common is this action for this project type?
3. Phase score — Is this action typical for the current session phase?
4. Recency weight — Recent patterns weighted higher
5. Cross-project boost — If similar projects commonly do this next

6. Storage

### Pattern Database
Mined patterns are stored as JSON at:

[home-path]
├── action_sequences.json     # N-gram models
├── project_fingerprints.json # Per-project profiles
├── transition_matrix.json    # Action transition probabilities
├── session_phases.json       # Phase detection models
└── suggestions_cache.json    # Pre-computed common suggestions

7. Integration Points

  • Claude Code hooks — UserPromptSubmit hook can query suggestions
  • MCP tool — Expose as `get_code_suggestions` MCP tool
  • Noosphere — Feed suggestions back as new connections
  • Dream Weaver — Inform dream synthesis with pattern data

8. Privacy & Performance

  • All data stays local (no external API calls for pattern mining)
  • Pattern database is <1MB for typical usage
  • Suggestion latency target: <100ms
  • Incremental updates: only process new prompts since last run

Promotion Decision

Promote into a technical note or architecture paper with implementation anchors.

Source Anchor

projects/dream-metamorphosis/code-suggestions/ARCHITECTURE.md

Detected Structure

Method · Evaluation · Figures · Architecture