Skip to content
Back to skills

528 Compaction Ontology 3fa52597

ASecurity

``` ┌─────────────────────┐ │ User Request │ └──────────┬──────────┘ │ ▼ ┌──────────────────────────────────────────────────────────────────────────────┐ │ RequestOrchestrator │ │ (core/agents/main.py)

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
developmentreact

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 528-compaction-ontology_3fa52597 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 528 Compaction Ontology 3fa52597?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 528 Compaction Ontology 3fa52597
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-528-compaction-ontology-3fa52597/badge)](https://www.skillsdirectory.com/skills/tools-only-528-compaction-ontology-3fa52597)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
title: Compaction System Ontology
link: compaction-ontology
type: doc
path: docs/codebase-map/architecture/compaction-ontology.md
depth: 2
seams: [A, M, D]
ontological_relations:
  - relates_to: [[core-compaction]]
  - relates_to: [[core-state]]
  - relates_to: [[core-agents]]
  - affects: [[session-messages]]
  - affects: [[context-window]]
tags:
  - compaction
  - context-management
  - architecture
  - ontology
created_at: 2026-01-20T16:25:00Z
updated_at: 2026-01-20T16:25:00Z
---

# Compaction System Ontology

## Entity Relationships

```
                                    ┌─────────────────────┐
                                    │   User Request      │
                                    └──────────┬──────────┘
                                               │
                                               ▼
┌──────────────────────────────────────────────────────────────────────────────┐
│                         RequestOrchestrator                                   │
│                         (core/agents/main.py)                                │
│                                                                              │
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐         │
│  │ state_manager   │───▶│ session.conversation.messages│───▶│ prune_old_tool  │         │
│  │                 │    │                 │    │ _outputs()      │         │
│  └─────────────────┘    └─────────────────┘    └────────┬────────┘         │
│                                                          │                  │
└──────────────────────────────────────────────────────────┼──────────────────┘
                                                           │
                          ┌────────────────────────────────┼────────────────────┐
                          │                                ▼                    │
                          │              ┌─────────────────────────────────┐   │
                          │              │      compaction.py              │   │
                          │              │                                 │   │
                          │              │  ┌───────────────────────────┐  │   │
                          │              │  │ get_prune_thresholds()    │──┼───┼──┐
                          │              │  └───────────────────────────┘  │   │  │
                          │              │                                 │   │  │
                          │              │  ┌───────────────────────────┐  │   │  │
                          │              │  │ is_tool_return_part()     │  │   │  │
                          │              │  └───────────────────────────┘  │   │  │
                          │              │                                 │   │  │
                          │              │  ┌───────────────────────────┐  │   │  │
                          │              │  │ estimate_part_tokens()    │──┼───┼──┼──┐
                          │              │  └───────────────────────────┘  │   │  │  │
                          │              │                                 │   │  │  │
                          │              │  ┌───────────────────────────┐  │   │  │  │
                          │              │  │ prune_part_content()      │  │   │  │  │
                          │              │  └───────────────────────────┘  │   │  │  │
                          │              └─────────────────────────────────┘   │  │  │
                          │                                                    │  │  │
                          └────────────────────────────────────────────────────┘  │  │
                                                                                  │  │
                    ┌─────────────────────────────────────────────────────────────┘  │
                    │                                                                │
                    ▼                                                                │
          ┌─────────────────────┐                                                   │
          │     limits.py       │                                                   │
          │                     │                                                   │
          │  _load_settings()   │                                                   │
          └─────────────────────┘                                                   │
                                                                                    │
                    ┌───────────────────────────────────────────────────────────────┘
                    │
                    ▼
          ┌─────────────────────┐
          │  token_counter.py   │
          │                     │
          │  estimate_tokens()  │
          │  CHARS_PER_TOKEN=4  │
          └─────────────────────┘
```

## Ontological Classes

### Primary Entities

| Entity | Type | Location | Description |
|--------|------|----------|-------------|
| `Compaction` | Process | `core/compaction.py` | Context pruning system |
| `Message` | Data | `session.conversation.messages` | Conversation history item |
| `Part` | Data | `message.parts` | Sub-component of message |
| `ToolReturn` | Data | `part_kind="tool-return"` | Tool execution result |
| `Token` | Unit | Estimated | Context window unit |

### Secondary Entities

| Entity | Type | Location | Description |
|--------|------|----------|-------------|
| `Threshold` | Config | `compaction.py` | Pruning boundaries |
| `Placeholder` | Constant | `compaction.py` | Replacement text |
| `Session` | State | `state.py` | Conversation container |

## Relationships

### Compositional (HAS-A)

```
Session
  └── messages: list[Message]
        └── parts: list[Part]
              └── content: str | Any
              └── part_kind: str
```

### Functional (OPERATES-ON)

| Subject | Verb | Object |
|---------|------|--------|
| `prune_old_tool_outputs` | scans | `messages` |
| `prune_old_tool_outputs` | identifies | `tool-return` parts |
| `prune_old_tool_outputs` | mutates | `part.content` |
| `estimate_part_tokens` | delegates-to | `estimate_tokens()` |

### Dependency (DEPENDS-ON)

```
compaction.py
    │
    └──▶ token_counter.py::estimate_tokens()

main.py
    │
    ├──▶ compaction.py::prune_old_tool_outputs()
    │
    └──▶ state.py::session.conversation.messages
```

### Trigger (INVOKED-BY)

```
User Request
    │
    └──▶ RequestOrchestrator._run_impl()
            │
            └──▶ prune_old_tool_outputs()  [line 342]
```

## Data Flow

### Input/Output

```
INPUT:
  messages: list[ModelMessage]    # Full conversation history
  model: str                      # Model name (for token estimation)

OUTPUT:
  messages: list[ModelMessage]    # Same list, mutated in-place
  tokens_reclaimed: int           # Net tokens freed
```

### State Transitions

```
           ┌─────────────────────────────────────────────┐
           │                                             │
           ▼                                             │
    ┌──────────────┐                              ┌──────┴───────┐
    │   PRISTINE   │──────[accumulate > protect]──▶│   CANDIDATE  │
    │  (protected) │                              │  (to prune)  │
    └──────────────┘                              └──────┬───────┘
                                                         │
                                          [total > minimum_threshold]
                                                         │
                                                         ▼
                                                  ┌──────────────┐
                                                  │    PRUNED    │
                                                  │ (placeholder)│
                                                  └──────────────┘
```

## Threshold Ontology

```
┌─────────────────────────────────────────────────────────────────────┐
│                     200,000 token context window                     │
│                                                                      │
│  ┌──────────────────────────────────────────┬───────────────────┐   │
│  │         PRUNABLE ZONE                    │  PROTECTED ZONE   │   │
│  │         (oldest)                         │  (40,000 tokens)  │   │
│  │                                          │                   │   │
│  │  Only pruned if total > 20,000 tokens    │  Never pruned     │   │
│  └──────────────────────────────────────────┴───────────────────┘   │
│                                                                      │
└─────────────────────────────────────────────────────────────────────┘
```

## Invariants

### Pre-conditions

| Invariant | Check Location | Failure Behavior |
|-----------|----------------|------------------|
| `messages` is mutable list | Caller responsibility | Silent no-op |
| `len(messages) > 0` | line 179 | Early return |
| `user_turns >= 2` | line 183-185 | Early return |

### Post-conditions

| Invariant | Guarantee |
|-----------|-----------|
| Message list identity preserved | Same list object returned |
| Protected content unchanged | Recent tokens untouched |
| Pruned parts contain placeholder | Exactly `PRUNE_PLACEHOLDER` |
| Idempotent | Re-running produces no change |

### Class Invariants

| Class | Invariant |
|-------|-----------|
| `Part` | `part_kind` is immutable |
| `Message` | `parts` list is mutable |
| `Session` | `messages` persists across requests |

## Seams

### Architecture Seams (A)

- **Trigger Location**: Can move compaction to different lifecycle points
- **Proactive vs Reactive**: Currently proactive; could add reactive overflow handling

### Module Seams (M)

- **Threshold Configuration**: Currently hardcoded; could externalize to config
- **Token Estimation**: Uses heuristic; could swap in actual tokenizer
- **Placeholder Format**: Static string; could make dynamic/contextual

### Data Seams (D)

- **Pruning Granularity**: Currently part-level; could do message-level
- **Preservation Rules**: Currently all tool-returns; could add selective rules
- **Content Summarization**: Currently placeholder; could add LLM summarization

## Cross-References

| Document | Relationship |
|----------|--------------|
| [[core-compaction]] | Implementation details |
| [[core-state]] | Session/message storage |
| [[core-agents]] | Integration point |
| [[conversation-turns]] | Message structure |
| [[architecture]] | System overview |

Files in this skill

  • README.md1.1 KB
  • skill.md13.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.