mcp-context-engineering
Version:
The intelligent context optimization system for AI coding assistants. Built with Cole's PRP methodology, Context Portal knowledge graphs, and production-ready MongoDB architecture.
1,149 lines (1,148 loc) • 42.3 kB
TypeScript
import { ObjectId } from 'mongodb';
import { z } from 'zod';
/**
* Context History Schema - Following Context Portal's versioning patterns
*
* Provides comprehensive context evolution tracking with:
* - Automatic versioning for all context changes
* - Change source tracking (user, system, AI agent)
* - Temporal queries for context at any point in time
* - Incremental version management
*/
export declare const ContextHistoryEntrySchema: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
context_type: z.ZodEnum<["product_context", "active_context", "decision", "progress_entry", "system_pattern", "context_pattern"]>;
context_item_id: z.ZodString;
version: z.ZodNumber;
previous_version: z.ZodOptional<z.ZodNumber>;
change_source: z.ZodEnum<["user", "system", "ai_agent", "api", "automation"]>;
change_type: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
change_summary: z.ZodString;
change_details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
content_before: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
content_after: z.ZodRecord<z.ZodString, z.ZodAny>;
content_diff: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
timestamp: z.ZodDate;
user_id: z.ZodOptional<z.ZodString>;
agent_type: z.ZodOptional<z.ZodEnum<["cursor", "windsurf", "claude_code", "generic"]>>;
session_id: z.ZodOptional<z.ZodString>;
impact_score: z.ZodOptional<z.ZodNumber>;
related_changes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
timestamp?: Date;
project_id?: string;
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
_id?: ObjectId;
version?: number;
context_type?: "active_context" | "product_context" | "decision" | "progress_entry" | "system_pattern" | "context_pattern";
context_item_id?: string;
change_source?: "user" | "system" | "ai_agent" | "api" | "automation";
change_type?: "delete" | "create" | "update" | "archive" | "restore";
previous_version?: number;
change_summary?: string;
change_details?: Record<string, any>;
content_before?: Record<string, any>;
content_after?: Record<string, any>;
content_diff?: Record<string, any>;
user_id?: string;
session_id?: string;
impact_score?: number;
related_changes?: string[];
}, {
workspace_id?: string;
timestamp?: Date;
project_id?: string;
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
_id?: ObjectId;
version?: number;
context_type?: "active_context" | "product_context" | "decision" | "progress_entry" | "system_pattern" | "context_pattern";
context_item_id?: string;
change_source?: "user" | "system" | "ai_agent" | "api" | "automation";
change_type?: "delete" | "create" | "update" | "archive" | "restore";
previous_version?: number;
change_summary?: string;
change_details?: Record<string, any>;
content_before?: Record<string, any>;
content_after?: Record<string, any>;
content_diff?: Record<string, any>;
user_id?: string;
session_id?: string;
impact_score?: number;
related_changes?: string[];
}>;
export declare const WorkspaceEvolutionSchema: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
current_version: z.ZodNumber;
total_changes: z.ZodNumber;
change_velocity: z.ZodNumber;
change_frequency: z.ZodObject<{
hourly: z.ZodArray<z.ZodNumber, "many">;
daily: z.ZodArray<z.ZodNumber, "many">;
weekly: z.ZodArray<z.ZodNumber, "many">;
}, "strip", z.ZodTypeAny, {
hourly?: number[];
daily?: number[];
weekly?: number[];
}, {
hourly?: number[];
daily?: number[];
weekly?: number[];
}>;
change_sources: z.ZodRecord<z.ZodString, z.ZodNumber>;
agent_activity: z.ZodRecord<z.ZodString, z.ZodNumber>;
context_growth: z.ZodObject<{
decisions_added: z.ZodNumber;
patterns_created: z.ZodNumber;
progress_entries: z.ZodNumber;
total_content_size: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
}, {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
}>;
stability_score: z.ZodNumber;
consistency_score: z.ZodNumber;
completeness_score: z.ZodNumber;
created_at: z.ZodDate;
last_updated: z.ZodDate;
analysis_date: z.ZodDate;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
created_at?: Date;
current_version?: number;
total_changes?: number;
change_velocity?: number;
change_frequency?: {
hourly?: number[];
daily?: number[];
weekly?: number[];
};
change_sources?: Record<string, number>;
agent_activity?: Record<string, number>;
context_growth?: {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
};
stability_score?: number;
consistency_score?: number;
completeness_score?: number;
last_updated?: Date;
analysis_date?: Date;
}, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
created_at?: Date;
current_version?: number;
total_changes?: number;
change_velocity?: number;
change_frequency?: {
hourly?: number[];
daily?: number[];
weekly?: number[];
};
change_sources?: Record<string, number>;
agent_activity?: Record<string, number>;
context_growth?: {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
};
stability_score?: number;
consistency_score?: number;
completeness_score?: number;
last_updated?: Date;
analysis_date?: Date;
}>;
export declare const ContextSnapshotSchema: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
snapshot_version: z.ZodNumber;
snapshot_timestamp: z.ZodDate;
context_state: z.ZodObject<{
product_context: z.ZodRecord<z.ZodString, z.ZodAny>;
active_context: z.ZodRecord<z.ZodString, z.ZodAny>;
decisions: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
progress_entries: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
system_patterns: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
context_links: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
}, "strip", z.ZodTypeAny, {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
}, {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
}>;
created_by: z.ZodEnum<["system", "user", "ai_agent", "scheduled"]>;
snapshot_reason: z.ZodString;
retention_policy: z.ZodEnum<["permanent", "long_term", "short_term"]>;
compressed: z.ZodDefault<z.ZodBoolean>;
compression_ratio: z.ZodOptional<z.ZodNumber>;
original_size: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
snapshot_version?: number;
snapshot_timestamp?: Date;
context_state?: {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
};
created_by?: "user" | "system" | "ai_agent" | "scheduled";
snapshot_reason?: string;
retention_policy?: "permanent" | "long_term" | "short_term";
compressed?: boolean;
compression_ratio?: number;
original_size?: number;
}, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
snapshot_version?: number;
snapshot_timestamp?: Date;
context_state?: {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
};
created_by?: "user" | "system" | "ai_agent" | "scheduled";
snapshot_reason?: string;
retention_policy?: "permanent" | "long_term" | "short_term";
compressed?: boolean;
compression_ratio?: number;
original_size?: number;
}>;
export declare const ChangeAnalyticsSchema: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
analysis_period: z.ZodObject<{
start_date: z.ZodDate;
end_date: z.ZodDate;
}, "strip", z.ZodTypeAny, {
start_date?: Date;
end_date?: Date;
}, {
start_date?: Date;
end_date?: Date;
}>;
patterns: z.ZodObject<{
most_active_hours: z.ZodArray<z.ZodNumber, "many">;
peak_activity_days: z.ZodArray<z.ZodString, "many">;
common_change_types: z.ZodArray<z.ZodObject<{
type: z.ZodString;
frequency: z.ZodNumber;
impact: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
type?: string;
frequency?: number;
impact?: number;
}, {
type?: string;
frequency?: number;
impact?: number;
}>, "many">;
}, "strip", z.ZodTypeAny, {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
}, {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
}>;
agent_behavior: z.ZodRecord<z.ZodString, z.ZodObject<{
total_changes: z.ZodNumber;
avg_change_impact: z.ZodNumber;
preferred_change_types: z.ZodArray<z.ZodString, "many">;
effectiveness_score: z.ZodNumber;
learning_velocity: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>>;
health_metrics: z.ZodObject<{
consistency_trend: z.ZodArray<z.ZodNumber, "many">;
completeness_trend: z.ZodArray<z.ZodNumber, "many">;
stability_trend: z.ZodArray<z.ZodNumber, "many">;
growth_rate: z.ZodNumber;
quality_score: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
}, {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
}>;
recommendations: z.ZodArray<z.ZodObject<{
category: z.ZodEnum<["optimization", "maintenance", "expansion", "cleanup"]>;
priority: z.ZodEnum<["high", "medium", "low"]>;
description: z.ZodString;
expected_impact: z.ZodNumber;
effort_estimate: z.ZodString;
}, "strip", z.ZodTypeAny, {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}, {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}>, "many">;
analysis_date: z.ZodDate;
next_analysis_due: z.ZodDate;
analysis_version: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
_id?: ObjectId;
patterns?: {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
};
analysis_date?: Date;
analysis_period?: {
start_date?: Date;
end_date?: Date;
};
agent_behavior?: Record<string, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>;
health_metrics?: {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
};
recommendations?: {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}[];
next_analysis_due?: Date;
analysis_version?: number;
}, {
workspace_id?: string;
_id?: ObjectId;
patterns?: {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
};
analysis_date?: Date;
analysis_period?: {
start_date?: Date;
end_date?: Date;
};
agent_behavior?: Record<string, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>;
health_metrics?: {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
};
recommendations?: {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}[];
next_analysis_due?: Date;
analysis_version?: number;
}>;
export declare const ContextHistorySchema: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
history_entries: z.ZodArray<z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
context_type: z.ZodEnum<["product_context", "active_context", "decision", "progress_entry", "system_pattern", "context_pattern"]>;
context_item_id: z.ZodString;
version: z.ZodNumber;
previous_version: z.ZodOptional<z.ZodNumber>;
change_source: z.ZodEnum<["user", "system", "ai_agent", "api", "automation"]>;
change_type: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
change_summary: z.ZodString;
change_details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
content_before: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
content_after: z.ZodRecord<z.ZodString, z.ZodAny>;
content_diff: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
timestamp: z.ZodDate;
user_id: z.ZodOptional<z.ZodString>;
agent_type: z.ZodOptional<z.ZodEnum<["cursor", "windsurf", "claude_code", "generic"]>>;
session_id: z.ZodOptional<z.ZodString>;
impact_score: z.ZodOptional<z.ZodNumber>;
related_changes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
timestamp?: Date;
project_id?: string;
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
_id?: ObjectId;
version?: number;
context_type?: "active_context" | "product_context" | "decision" | "progress_entry" | "system_pattern" | "context_pattern";
context_item_id?: string;
change_source?: "user" | "system" | "ai_agent" | "api" | "automation";
change_type?: "delete" | "create" | "update" | "archive" | "restore";
previous_version?: number;
change_summary?: string;
change_details?: Record<string, any>;
content_before?: Record<string, any>;
content_after?: Record<string, any>;
content_diff?: Record<string, any>;
user_id?: string;
session_id?: string;
impact_score?: number;
related_changes?: string[];
}, {
workspace_id?: string;
timestamp?: Date;
project_id?: string;
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
_id?: ObjectId;
version?: number;
context_type?: "active_context" | "product_context" | "decision" | "progress_entry" | "system_pattern" | "context_pattern";
context_item_id?: string;
change_source?: "user" | "system" | "ai_agent" | "api" | "automation";
change_type?: "delete" | "create" | "update" | "archive" | "restore";
previous_version?: number;
change_summary?: string;
change_details?: Record<string, any>;
content_before?: Record<string, any>;
content_after?: Record<string, any>;
content_diff?: Record<string, any>;
user_id?: string;
session_id?: string;
impact_score?: number;
related_changes?: string[];
}>, "many">;
workspace_evolution: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
current_version: z.ZodNumber;
total_changes: z.ZodNumber;
change_velocity: z.ZodNumber;
change_frequency: z.ZodObject<{
hourly: z.ZodArray<z.ZodNumber, "many">;
daily: z.ZodArray<z.ZodNumber, "many">;
weekly: z.ZodArray<z.ZodNumber, "many">;
}, "strip", z.ZodTypeAny, {
hourly?: number[];
daily?: number[];
weekly?: number[];
}, {
hourly?: number[];
daily?: number[];
weekly?: number[];
}>;
change_sources: z.ZodRecord<z.ZodString, z.ZodNumber>;
agent_activity: z.ZodRecord<z.ZodString, z.ZodNumber>;
context_growth: z.ZodObject<{
decisions_added: z.ZodNumber;
patterns_created: z.ZodNumber;
progress_entries: z.ZodNumber;
total_content_size: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
}, {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
}>;
stability_score: z.ZodNumber;
consistency_score: z.ZodNumber;
completeness_score: z.ZodNumber;
created_at: z.ZodDate;
last_updated: z.ZodDate;
analysis_date: z.ZodDate;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
created_at?: Date;
current_version?: number;
total_changes?: number;
change_velocity?: number;
change_frequency?: {
hourly?: number[];
daily?: number[];
weekly?: number[];
};
change_sources?: Record<string, number>;
agent_activity?: Record<string, number>;
context_growth?: {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
};
stability_score?: number;
consistency_score?: number;
completeness_score?: number;
last_updated?: Date;
analysis_date?: Date;
}, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
created_at?: Date;
current_version?: number;
total_changes?: number;
change_velocity?: number;
change_frequency?: {
hourly?: number[];
daily?: number[];
weekly?: number[];
};
change_sources?: Record<string, number>;
agent_activity?: Record<string, number>;
context_growth?: {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
};
stability_score?: number;
consistency_score?: number;
completeness_score?: number;
last_updated?: Date;
analysis_date?: Date;
}>;
snapshots: z.ZodArray<z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
project_id: z.ZodString;
snapshot_version: z.ZodNumber;
snapshot_timestamp: z.ZodDate;
context_state: z.ZodObject<{
product_context: z.ZodRecord<z.ZodString, z.ZodAny>;
active_context: z.ZodRecord<z.ZodString, z.ZodAny>;
decisions: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
progress_entries: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
system_patterns: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
context_links: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
}, "strip", z.ZodTypeAny, {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
}, {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
}>;
created_by: z.ZodEnum<["system", "user", "ai_agent", "scheduled"]>;
snapshot_reason: z.ZodString;
retention_policy: z.ZodEnum<["permanent", "long_term", "short_term"]>;
compressed: z.ZodDefault<z.ZodBoolean>;
compression_ratio: z.ZodOptional<z.ZodNumber>;
original_size: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
snapshot_version?: number;
snapshot_timestamp?: Date;
context_state?: {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
};
created_by?: "user" | "system" | "ai_agent" | "scheduled";
snapshot_reason?: string;
retention_policy?: "permanent" | "long_term" | "short_term";
compressed?: boolean;
compression_ratio?: number;
original_size?: number;
}, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
snapshot_version?: number;
snapshot_timestamp?: Date;
context_state?: {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
};
created_by?: "user" | "system" | "ai_agent" | "scheduled";
snapshot_reason?: string;
retention_policy?: "permanent" | "long_term" | "short_term";
compressed?: boolean;
compression_ratio?: number;
original_size?: number;
}>, "many">;
change_analytics: z.ZodObject<{
_id: z.ZodOptional<z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>>;
workspace_id: z.ZodString;
analysis_period: z.ZodObject<{
start_date: z.ZodDate;
end_date: z.ZodDate;
}, "strip", z.ZodTypeAny, {
start_date?: Date;
end_date?: Date;
}, {
start_date?: Date;
end_date?: Date;
}>;
patterns: z.ZodObject<{
most_active_hours: z.ZodArray<z.ZodNumber, "many">;
peak_activity_days: z.ZodArray<z.ZodString, "many">;
common_change_types: z.ZodArray<z.ZodObject<{
type: z.ZodString;
frequency: z.ZodNumber;
impact: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
type?: string;
frequency?: number;
impact?: number;
}, {
type?: string;
frequency?: number;
impact?: number;
}>, "many">;
}, "strip", z.ZodTypeAny, {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
}, {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
}>;
agent_behavior: z.ZodRecord<z.ZodString, z.ZodObject<{
total_changes: z.ZodNumber;
avg_change_impact: z.ZodNumber;
preferred_change_types: z.ZodArray<z.ZodString, "many">;
effectiveness_score: z.ZodNumber;
learning_velocity: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>>;
health_metrics: z.ZodObject<{
consistency_trend: z.ZodArray<z.ZodNumber, "many">;
completeness_trend: z.ZodArray<z.ZodNumber, "many">;
stability_trend: z.ZodArray<z.ZodNumber, "many">;
growth_rate: z.ZodNumber;
quality_score: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
}, {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
}>;
recommendations: z.ZodArray<z.ZodObject<{
category: z.ZodEnum<["optimization", "maintenance", "expansion", "cleanup"]>;
priority: z.ZodEnum<["high", "medium", "low"]>;
description: z.ZodString;
expected_impact: z.ZodNumber;
effort_estimate: z.ZodString;
}, "strip", z.ZodTypeAny, {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}, {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}>, "many">;
analysis_date: z.ZodDate;
next_analysis_due: z.ZodDate;
analysis_version: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
_id?: ObjectId;
patterns?: {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
};
analysis_date?: Date;
analysis_period?: {
start_date?: Date;
end_date?: Date;
};
agent_behavior?: Record<string, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>;
health_metrics?: {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
};
recommendations?: {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}[];
next_analysis_due?: Date;
analysis_version?: number;
}, {
workspace_id?: string;
_id?: ObjectId;
patterns?: {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
};
analysis_date?: Date;
analysis_period?: {
start_date?: Date;
end_date?: Date;
};
agent_behavior?: Record<string, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>;
health_metrics?: {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
};
recommendations?: {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}[];
next_analysis_due?: Date;
analysis_version?: number;
}>;
metadata: z.ZodObject<{
created_at: z.ZodDate;
last_updated: z.ZodDate;
retention_policy: z.ZodEnum<["standard", "extended", "permanent"]>;
archive_after_days: z.ZodDefault<z.ZodNumber>;
compress_after_days: z.ZodDefault<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
created_at?: Date;
last_updated?: Date;
retention_policy?: "permanent" | "standard" | "extended";
archive_after_days?: number;
compress_after_days?: number;
}, {
created_at?: Date;
last_updated?: Date;
retention_policy?: "permanent" | "standard" | "extended";
archive_after_days?: number;
compress_after_days?: number;
}>;
}, "strip", z.ZodTypeAny, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
metadata?: {
created_at?: Date;
last_updated?: Date;
retention_policy?: "permanent" | "standard" | "extended";
archive_after_days?: number;
compress_after_days?: number;
};
history_entries?: {
workspace_id?: string;
timestamp?: Date;
project_id?: string;
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
_id?: ObjectId;
version?: number;
context_type?: "active_context" | "product_context" | "decision" | "progress_entry" | "system_pattern" | "context_pattern";
context_item_id?: string;
change_source?: "user" | "system" | "ai_agent" | "api" | "automation";
change_type?: "delete" | "create" | "update" | "archive" | "restore";
previous_version?: number;
change_summary?: string;
change_details?: Record<string, any>;
content_before?: Record<string, any>;
content_after?: Record<string, any>;
content_diff?: Record<string, any>;
user_id?: string;
session_id?: string;
impact_score?: number;
related_changes?: string[];
}[];
workspace_evolution?: {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
created_at?: Date;
current_version?: number;
total_changes?: number;
change_velocity?: number;
change_frequency?: {
hourly?: number[];
daily?: number[];
weekly?: number[];
};
change_sources?: Record<string, number>;
agent_activity?: Record<string, number>;
context_growth?: {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
};
stability_score?: number;
consistency_score?: number;
completeness_score?: number;
last_updated?: Date;
analysis_date?: Date;
};
snapshots?: {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
snapshot_version?: number;
snapshot_timestamp?: Date;
context_state?: {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
};
created_by?: "user" | "system" | "ai_agent" | "scheduled";
snapshot_reason?: string;
retention_policy?: "permanent" | "long_term" | "short_term";
compressed?: boolean;
compression_ratio?: number;
original_size?: number;
}[];
change_analytics?: {
workspace_id?: string;
_id?: ObjectId;
patterns?: {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
};
analysis_date?: Date;
analysis_period?: {
start_date?: Date;
end_date?: Date;
};
agent_behavior?: Record<string, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>;
health_metrics?: {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
};
recommendations?: {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}[];
next_analysis_due?: Date;
analysis_version?: number;
};
}, {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
metadata?: {
created_at?: Date;
last_updated?: Date;
retention_policy?: "permanent" | "standard" | "extended";
archive_after_days?: number;
compress_after_days?: number;
};
history_entries?: {
workspace_id?: string;
timestamp?: Date;
project_id?: string;
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
_id?: ObjectId;
version?: number;
context_type?: "active_context" | "product_context" | "decision" | "progress_entry" | "system_pattern" | "context_pattern";
context_item_id?: string;
change_source?: "user" | "system" | "ai_agent" | "api" | "automation";
change_type?: "delete" | "create" | "update" | "archive" | "restore";
previous_version?: number;
change_summary?: string;
change_details?: Record<string, any>;
content_before?: Record<string, any>;
content_after?: Record<string, any>;
content_diff?: Record<string, any>;
user_id?: string;
session_id?: string;
impact_score?: number;
related_changes?: string[];
}[];
workspace_evolution?: {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
created_at?: Date;
current_version?: number;
total_changes?: number;
change_velocity?: number;
change_frequency?: {
hourly?: number[];
daily?: number[];
weekly?: number[];
};
change_sources?: Record<string, number>;
agent_activity?: Record<string, number>;
context_growth?: {
progress_entries?: number;
decisions_added?: number;
patterns_created?: number;
total_content_size?: number;
};
stability_score?: number;
consistency_score?: number;
completeness_score?: number;
last_updated?: Date;
analysis_date?: Date;
};
snapshots?: {
workspace_id?: string;
project_id?: string;
_id?: ObjectId;
snapshot_version?: number;
snapshot_timestamp?: Date;
context_state?: {
decisions?: Record<string, any>[];
progress_entries?: Record<string, any>[];
system_patterns?: Record<string, any>[];
context_links?: Record<string, any>[];
active_context?: Record<string, any>;
product_context?: Record<string, any>;
};
created_by?: "user" | "system" | "ai_agent" | "scheduled";
snapshot_reason?: string;
retention_policy?: "permanent" | "long_term" | "short_term";
compressed?: boolean;
compression_ratio?: number;
original_size?: number;
}[];
change_analytics?: {
workspace_id?: string;
_id?: ObjectId;
patterns?: {
most_active_hours?: number[];
peak_activity_days?: string[];
common_change_types?: {
type?: string;
frequency?: number;
impact?: number;
}[];
};
analysis_date?: Date;
analysis_period?: {
start_date?: Date;
end_date?: Date;
};
agent_behavior?: Record<string, {
effectiveness_score?: number;
total_changes?: number;
avg_change_impact?: number;
preferred_change_types?: string[];
learning_velocity?: number;
}>;
health_metrics?: {
quality_score?: number;
consistency_trend?: number[];
completeness_trend?: number[];
stability_trend?: number[];
growth_rate?: number;
};
recommendations?: {
description?: string;
category?: "optimization" | "maintenance" | "expansion" | "cleanup";
priority?: "low" | "medium" | "high";
expected_impact?: number;
effort_estimate?: string;
}[];
next_analysis_due?: Date;
analysis_version?: number;
};
}>;
export type ContextHistoryEntry = z.infer<typeof ContextHistoryEntrySchema>;
export type WorkspaceEvolution = z.infer<typeof WorkspaceEvolutionSchema>;
export type ContextSnapshot = z.infer<typeof ContextSnapshotSchema>;
export type ChangeAnalytics = z.infer<typeof ChangeAnalyticsSchema>;
export type ContextHistory = z.infer<typeof ContextHistorySchema>;
export declare class ContextVersionManager {
/**
* Generate next version number for a context item
*/
static generateNextVersion(currentVersion?: number): number;
/**
* Create change diff between two context states
*/
static createChangeDiff(before: any, after: any): Record<string, any>;
/**
* Calculate impact score based on change magnitude
*/
static calculateImpactScore(changeDiff: Record<string, any>): number;
/**
* Create context snapshot for temporal queries
*/
static createSnapshot(workspaceId: string, projectId: string, version: number, contextState: any, reason?: string): ContextSnapshot;
}