Back to catalog

historical-tracking

Track graph evolution over time to detect trajectory patterns (expanding, consolidating, cycling, stuck, balanced). Use when analyzing thinking progress, detecting patterns, or optimizing explore/focus balance across sessions.

  • Category: discovered
  • Tags: github, community
  • Version: 1.0.0
  • Author: walid
  • Downloads: 0
  • Updated: 2025-11-22

Download the latest version (v1.0.0) from this page.

SKILL.md

---
name: historical-tracking
description: Track graph evolution over time to detect trajectory patterns (expanding, consolidating, cycling, stuck, balanced). Use when analyzing thinking progress, detecting patterns, or optimizing explore/focus balance across sessions.
---

# Historical Tracking Skill

**Purpose:** Track graph evolution over time to detect trajectory patterns and state transitions

**Backend:** `backend/services/graph-history-tracker.cjs` (343 lines)

**Status:** ✅ Operational (implemented Phase 4)

---

## What This Skill Does

Records graph analysis snapshots over time and analyzes evolution trajectories to identify patterns like expanding, consolidating, cycling, stuck, or balanced states.

**Key Capabilities:**
- Snapshot recording (in-memory + optional disk persistence)
- Evolution trajectory analysis (5 pattern types)
- State transition tracking (BIAS → FOCUSED → DIVERSE → DISPERSED)
- Trend analysis (modularity/entropy over time)
- Pattern recognition (stuck states, cycling, healthy variation)

---

## When to Use This Skill

Use historical tracking when:
- User asks "how has my thinking evolved?"
- Need to track progress over multiple sessions
- Detecting thinking patterns (stuck, cycling)
- Optimizing explore/focus balance
- Long-term knowledge development tracking

---

## Snapshot Structure

**Captured data per snapshot:**
```javascript
{
  timestamp: "2025-11-06T...",
  agentId: "marketing",
  cognitiveState: "FOCUSED",
  modularity: 0.272,
  entropy: 0.847,
  density: 0.183,
  nodeCount: 8,
  clusterCount: 3,
  gapCount: 1,
  evolutionStage: "Saturation"
}
```

**Storage:**
- In-memory: Last 100 snapshots per agent (default)
- Disk: Optional JSON files in `workspace/data/graph-history/`
- Format: `{agentId}-history.json`

---

## Evolution Trajectory Patterns

### 1. Expanding

**Definition:** Modularity increasing over time → Moving toward DISPERSED state

**Detection:** Linear regression slope > 0.1 on modularity values

**Interpretation:**
- Good: Exploration, diversity increasing
- Risk: Over-fragmentation, loss of coherence

**Recommendation:**
```
"Good for exploration, but watch for over-fragmentation"
```

**Example:**
```
Snapshot 1: modularity=0.015 (BIAS)
Snapshot 2: modularity=0.204 (FOCUSED)
Snapshot 3: modularity=0.431 (DIVERSE)
→ Trajectory: EXPANDING
```

---

### 2. Consolidating

**Definition:** Modularity decreasing over time → Moving toward FOCUSED/BIAS state

**Detection:** Linear regression slope < -0.1 on modularity values

**Interpretation:**
- Good: Coherence building, structure emerging
- Risk: Echo chambers, closed thinking

**Recommendation:**
```
"Good for coherence, but watch for echo chambers"
```

**Example:**
```
Snapshot 1: modularity=0.650 (DISPERSED)
Snapshot 2: modularity=0.431 (DIVERSE)
Snapshot 3: modularity=0.272 (FOCUSED)
→ Trajectory: CONSOLIDATING
```

---

### 3. Cycling

**Definition:** Oscillating between states (A→B→A→B repeatedly)

**Detection:** ≥2 cycles detected in state transitions (pattern: transition i matches transition i-2)

**Interpretation:**
- Problem: Indecision, unstable thinking
- Cause: Lack of commitment to explore or focus direction

**Recommendation:**
```
"Break cycle by introducing new concepts or changing scale"
```

**Example:**
```
Snapshot 1: FOCUSED
Snapshot 2: DIVERSE
Snapshot 3: FOCUSED
Snapshot 4: DIVERSE
→ Trajectory: CYCLING (FOCUSED ↔ DIVERSE)
```

---

### 4. Stuck

**Definition:** Same cognitive state repeatedly (no transitions)

**Detection:** All snapshots have identical cognitive state

**Interpretation:**
- Problem: No progress, stagnation
- Cause: Insufficient exploration or insufficient consolidation

**Recommendation:**
```
"Force transition - try opposite approach (explore vs focus)"
```

**Example:**
```
Snapshot 1: FOCUSED
Snapshot 2: FOCUSED
Snapshot 3: FOCUSED
→ Trajectory: STUCK (in FOCUSED state)
```

---

### 5. Balanced

**Definition:** Healthy variation in modularity (neither expanding nor consolidating)

**Detection:** Linear regression slope between -0.1 and 0.1

**Interpretation:**
- Good: Natural oscillation between explore and focus
- Healthy thinking pattern

**Recommendation:**
```
"Continue current approach"
```

**Example:**
```
Snapshot 1: modularity=0.272 (FOCUSED)
Snapshot 2: modularity=0.315 (FOCUSED)
Snapshot 3: modularity=0.289 (FOCUSED)
→ Trajectory: BALANCED (healthy variation)
```

---

## State Transition Tracking

**4 Cognitive States:**
- **BIAS** (modularity < 0.2): Highly focused, single perspective
- **FOCUSED** (0.2-0.4): Coherent structure, clear clusters
- **DIVERSE** (0.4-0.65): Multiple perspectives, balanced exploration
- **DISPERSED** (> 0.65): Highly fragmented, many disconnected ideas

**Transition Tracking:**
```javascript
{
  from: "BIAS",
  to: "FOCUSED",
  modularityChange: +0.189,
  entropyChange: +0.142,
  timestamp: "2025-11-06T...",
  duration: 3600000  // milliseconds
}
```

**State Distribution:**
```javascript
{
  BIAS: 1,      // 1 snapshot in BIAS state
  FOCUSED: 5,   // 5 snapshots in FOCUSED state
  DIVERSE: 2,   // 2 snapshots in DIVERSE state
  DISPERSED: 0  // 0 snapshots in DISPERSED state
}
```

---

## Trend Analysis

**Linear Regression on Modularity:**
```javascript
calculateTrend(modularityValues)
// Returns slope: positive (expanding), negative (consolidating), ~0 (balanced)
```

**Slope Interpretation:**
- `> 0.1` → Expanding trajectory
- `< -0.1` → Consolidating trajectory
- `-0.1 to 0.1` → Balanced trajectory

**Algorithm:**
```javascript
// Simple linear regression
slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX^2)
```

---

## Pattern Detection Algorithm

**Cycling Detection:**
```javascript
// Check if transition i matches transition i-2
for (i = 2; i < transitions.length; i++) {
  if (transitions[i].to === transitions[i-2].from) {
    cycles++;
  }
}
return cycles >= 2;  // At least 2 cycles = cycling pattern
```

**Stuck Detection:**
```javascript
const uniqueStates = new Set(states);
return uniqueStates.size === 1;  // Only one unique state = stuck
```

---

## Storage Configuration

```javascript
const tracker = new GraphHistoryTracker({
  storageDir: 'workspace/data/graph-history',
  maxHistorySize: 100,              // Keep last 100 snapshots
  enablePersistence: true           // Save to disk
});
```

**Persistence:**
- Automatic save after each snapshot (if enabled)
- JSON format for easy inspection
- Per-agent files: `marketing-history.json`, `seo-history.json`, etc.

**Load on startup:**
```javascript
tracker.loadHistory('marketing');  // Restore from disk
```

---

## API Usage

### Record Snapshot
```javascript
const { getGlobalTracker } = require('./backend/services/graph-history-tracker.cjs');
const tracker = getGlobalTracker();

const result = await analyzeForAgent('marketing', 'Your content here');
const snapshot = tracker.recordSnapshot('marketing', result);

console.log('Snapshot recorded:', snapshot.snapshot.timestamp);
console.log('Evolution:', snapshot.evolution?.trajectory);
console.log('Recommendation:', snapshot.evolution?.recommendation);
```

### Get History
```javascript
const history = tracker.getHistory('marketing', 10);  // Last 10 snapshots
console.log('History size:', history.length);
history.forEach(s => {
  console.log(`${s.timestamp}: ${s.cognitiveState} (modularity=${s.modularity})`);
});
```

### Analyze Evolution
```javascript
const evolution = tracker.analyzeEvolution('marketing');
console.log('Trajectory:', evolution.trajectory);
console.log('Pattern:', evolution.pattern);
console.log('Metrics:', evolution.metrics);
console.log('State distribution:', evolution.stateDistribution);
console.log('Recommendation:', evolution.recommendation);
```

### Clear History
```javascript
tracker.clearHistory('marketing');  // Delete in-memory + disk file
```

---

## Integration Points

**Called by:**
- Manual recording via `tracker.recordSnapshot()`
- Not called automatically by agent-graph-service.cjs
- User-initiated evolution tracking workflow

**Depends on:**
- Complete graph analysis from agent-graph-service.cjs
- Cognitive state from evolution-tracker.cjs
- Statistics (modularity, entropy, density)

**Outputs:**
- Snapshot with timestamp
- Evolution analysis (if ≥2 snapshots)
- Trajectory pattern and recommendation

---

## Performance

- **Speed:** <5ms overhead per snapshot
- **Memory:** ~1KB per snapshot × 100 snapshots = 100KB per agent
- **Disk:** ~100KB per agent history file
- **Cost:** $0 (local storage)

**No regression:** Snapshot recording adds minimal overhead

---

## Testing

```bash
# Test historical tracking
node -e "
const { analyzeForAgent } = require('./backend/services/agent-graph-service.cjs');
const { getGlobalTracker } = require('./backend/services/graph-history-tracker.cjs');
const tracker = getGlobalTracker();

(async () => {
  // Record 3 snapshots with different content
  const result1 = await analyzeForAgent('marketing', 'product campaigns');
  tracker.recordSnapshot('marketing', result1);

  const result2 = await analyzeForAgent('marketing', 'product campaigns funnel conversion');
  tracker.recordSnapshot('marketing', result2);

  const result3 = await analyzeForAgent('marketing', 'product campaigns funnel conversion growth metrics');
  tracker.recordSnapshot('marketing', result3);

  // Analyze evolution
  const evolution = tracker.analyzeEvolution('marketing');
  console.log('Snapshots recorded:', evolution.historySize);
  console.log('Trajectory:', evolution.trajectory);
  console.log('Pattern:', evolution.pattern);
  console.log('Recommendation:', evolution.recommendation);
  console.log('');
  console.log('State distribution:', evolution.stateDistribution);
  console.log('Modularity trend:', evolution.metrics.modularityTrend.toFixed(3));
})();
"

# Expected output:
# Snapshots recorded: 3
# Trajectory: expanding
# Pattern: Modularity increasing - moving toward DISPERSED
# Recommendation: Good for exploration, but watch for over-fragmentation
#
# State distribution: { BIAS: 1, FOCUSED: 2 }
# Modularity trend: 0.114
```

---

## Real-World Examples

**@marketing Evolution (3 snapshots):**
```
Snapshot 1 (BIAS, modularity=0.015):
  Content: "product campaigns"
  Nodes: 6, Clusters: 2

Snapshot 2 (FOCUSED, modularity=0.204):
  Content: "product campaigns funnel conversion"
  Nodes: 10, Clusters: 3

Snapshot 3 (FOCUSED, modularity=0.243):
  Content: "product campaigns funnel conversion growth metrics"
  Nodes: 11, Clusters: 3

Evolution Analysis:
  Trajectory: STUCK (stuck in FOCUSED state)
  Pattern: "Stuck in FOCUSED state"
  Recommendation: "Force transition - try opposite approach (explore vs focus)"
  Modularity trend: +0.114 (expanding)
```

**Interpretation:** Graph stuck in FOCUSED state despite modularity increasing. Recommendation: Force exploration to break out of current structure.

---

## Summary Statistics

**Available via `getSummary()`:**
```javascript
{
  totalSnapshots: 8,
  agents: {
    marketing: {
      snapshotCount: 3,
      latestState: "FOCUSED",
      latestTimestamp: "2025-11-06T..."
    },
    seo: {
      snapshotCount: 2,
      latestState: "DIVERSE",
      latestTimestamp: "2025-11-06T..."
    },
    finance: {
      snapshotCount: 3,
      latestState: "FOCUSED",
      latestTimestamp: "2025-11-06T..."
    }
  },
  mostActiveAgent: "marketing",
  mostActiveCount: 3
}
```

---

## Limitations

**Current constraints:**
- In-memory only (lost on restart unless persisted to disk)
- Linear regression only (no advanced time series analysis)
- Simple pattern detection (5 predefined types)
- No cross-agent comparisons
- No anomaly detection

**Future enhancements (not implemented):**
- Database storage (persistent across restarts)
- Advanced time series forecasting
- Anomaly detection (sudden jumps, unexpected patterns)
- Cross-agent trajectory comparison
- Seasonal pattern detection
- Configurable pattern thresholds

---

## Related Skills

- **Evolution Tracking** - Provides evolution stage used in snapshots
- **Cognitive Variability** - Provides cognitive state for trajectory analysis
- **Graph Export** - Exports snapshots for external analysis

---

**Implementation:** Phase 4 (2025-11-06)
**Test Status:** ✅ Verified operational with 3-snapshot trajectory analysis
**Documentation:** workspace/docs/Obsidian-v2/daily/2025-11-06-PHASE4-COMPLETE.md