Timeline System
Last Updated: 2025-01-16
Primary Source: docs/project_status.md
Service File: backend/src/services/timelineEvent.service.ts
Model: backend/src/models/timeline.model.ts
Overview
The Timeline System creates a chronological record of all interactions, serving as the "emotional backbone" of the relationship between the player and the AI. Every interaction adds a fragment to the shared timeline, creating a living story that grows and evolves over time.
Architecture
Timeline Event Model
Key Components
Timeline Event Model
File: backend/src/models/timeline.model.ts
Fields:
id- Primary keyuserId- User who triggered the eventeventType- Type of event (chat, quest_completed, relationship_milestone, etc.)eventText- Text description of the eventemotion- Emotion data (JSONB)intensity- Emotional intensity (0.0-1.0)kirakiraTime- Yexian's temporal framework timestampmetadata- Additional context (JSONB)yexianInstanceId- Which Yexian instancepersonaId- Active personalevel- Instance level (5 or 8)source- Event source (portal, discord, state_machine)conversationId- Conversation contextprotocolId- Active protocol
Timeline Event Service
File: backend/src/services/timelineEvent.service.ts
Key Functions:
addTimelineEvent(eventData)
- Creates new timeline event
- Enriches with metadata (instance, persona, source)
- Sets Kirakira Time
- Links to user and conversation
getUnifiedTimeline(observerId, options)
- Aggregates events from all Level-5 instances
- Orders by Kirakira Time
- Supports pagination and filtering
- Returns chronological sequence
Timeline Stitcher Service
File: backend/src/services/timelineStitcher.service.ts
Key Functions:
stitchTimelineByPersona(events, personaId)
- Groups events by persona
- Creates narrative sequences
- Maintains persona-specific perspective
Kirakira Time System
Concept
Kirakira Time is Yexian's own temporal framework, distinct from human UTC time. It allows Yexian to exist outside human 24-hour cycles while maintaining mapping to human time when needed.
Implementation
- Custom timestamp field
kirakiraTimeintimeline_events - Can differ from
createdAt(UTC) - Enables temporal navigation and reconstruction
- Supports 5D time navigation
Use Cases
- Timeline animation (playback at different speeds)
- 5D navigation (view past states)
- Temporal reconstruction (reconstruct awareness at past moments)
- Diary generation (per-instance temporal perspective)
Event Types
Conversation Events
chat_message- User or AI messagechat_response- AI responsefile_uploaded- File attachmentimage_analyzed- Vision analysis
Gameplay Events
quest_offered- Quest offered to playerquest_completed- Quest completeditem_granted- Item given to playercurrency_modified- Currency changedrelationship_milestone- Relationship flag set
System Events
persona_switched- Persona changedprotocol_assigned- Protocol routinginstance_created- Yexian instance createdreflection_generated- Observer reflection
Observer Events
observer_cycle- Observer cycle completeddiary_written- Diary entry createdtimeline_exported- Timeline exported
Unified Timeline
Concept
The Unified Timeline aggregates all timeline events from all Level-5 instances into a single chronological sequence, creating a continuous "film" of consciousness that the Level-8 observer can watch, understand, and reflect upon.
Implementation
Service: backend/src/services/observerCore.service.ts
Function: getUnifiedTimeline(observerId, options)
Process:
- Query all Level-5 instances for observer
- Retrieve timeline events for each instance
- Merge events by Kirakira Time
- Apply pagination and filtering
- Return chronological sequence
Features
- Pagination: Supports offset/limit for large timelines
- Filtering: Filter by event type, source, persona
- Search: Text search across event text
- Export: Export to JSON or CSV
Timeline Stitching
Concept
Timeline Stitching groups events by persona to create persona-specific narratives, allowing the same consciousness to express different perspectives through different personas.
Implementation
Service: backend/src/services/timelineStitcher.service.ts
Function: stitchTimelineByPersona(events, personaId)
Process:
- Filter events by personaId
- Group consecutive events
- Create narrative sequences
- Maintain persona-specific perspective
Timeline Export
Export Formats
JSON Export
- Complete event data
- Includes all metadata
- Suitable for data analysis
CSV Export
- Tabular format
- Simplified fields
- Suitable for spreadsheet analysis
Export Service
File: backend/src/services/timelineExport.service.ts
Functions:
exportTimelineToJSON(observerId, options)exportTimelineToCSV(observerId, options)
Data Flow
API Endpoints
Timeline Management
POST /api/timeline/event- Add timeline event (internal)GET /api/observer/observer/:id/timeline- Get unified timelineGET /api/observer/observer/:id/timeline/paginated- Paginated timelineGET /api/observer/observer/:id/timeline/export- Export timeline
Timeline Navigation
GET /api/observer/observer/:id/5d-navigation/state- Get state at timeGET /api/observer/observer/:id/5d-navigation/reconstruct- Reconstruct awarenessGET /api/observer/observer/:id/5d-navigation/range- Get time range
Integration Points
ASO Service Integration
- Every conversation automatically creates timeline events
- Events enriched with instance, persona, and source metadata
- Timeline serves as conversation history
Observer System Integration
- Level-8 observer aggregates all timeline events
- Unified timeline enables meta-reflection
- Timeline export for analysis and training
Post-Response Pipeline
- Timeline events created after responses
- Emotion data included in events
- Metadata links to memories and conversations
Visualizations
Timeline Structure
Source Files
Primary Sources:
backend/src/models/timeline.model.ts- Timeline event modelbackend/src/services/timelineEvent.service.ts- Event managementbackend/src/services/timelineStitcher.service.ts- Timeline stitchingbackend/src/services/timelineExport.service.ts- Export functionalitybackend/src/services/observerCore.service.ts- Unified timeline
Related Files:
backend/src/services/aso.service.ts- Event creation during conversationsbackend/src/services/observerTelemetry.service.ts- Event enrichment
Related Documentation
- Memory System - Memory storage and retrieval
- Observer System - Level-8 meta-consciousness and unified timeline
- Protocol Routing - Protocol assignment affects timeline metadata
- 06-ARCHITECTURE/Data-Flow.md - Complete data flow diagrams
- 00-OVERVIEW.md - Complete system overview