StackMemory is a lossless, project-scoped memory runtime for AI coding and writing tools that preserves full project context across sessions using a call stack metaphor instead of linear chat logs. It organizes memory as nested frames with smart retrieval, enabling AI tools to maintain context across thread resets, model switches, and long-running projects.
memory_model:
structure: "call_stack" # Not linear chat log
max_depth: 10000 # Maximum frames in stack
retention: 30_days # Local retention window
storage:
local: "SQLite" # Fast local storage
remote: "TimeSeries DB + S3" # Infinite remote storageframe:
metadata:
id: "uuid"
title: "descriptive_name"
type: "task|debug|feature|architecture"
owner: "user_id"
created: "timestamp"
contents:
events: [] # Tool calls, messages, observations
anchors: [] # Decisions, constraints, interfaces
digest: {} # 60% deterministic, 40% AI-generated summary
score: 0.0-1.0 # Importance score for retentionlocal_storage:
young:
age: "< 1 day"
retention: "complete" # Full events, all tool calls
memory_strategy: "hot" # RAM for instant access
compression: "none"
mature:
age: "1-7 days"
retention: "selective" # Digests + anchors + high-score events
memory_strategy: "warm" # SQLite with memory cache
compression: "lz4"
score_threshold: 0.4
old:
age: "7-30 days"
retention: "critical" # Anchors + decisions only
memory_strategy: "cold" # SQLite, no cache
compression: "zstd"
score_threshold: 0.7
max_size: 2GB
overflow_strategy: "promote_to_remote"
remote_storage:
retention: "infinite"
indexing:
primary: "timeseries" # ClickHouse/TimescaleDB
secondary: "inverted" # Elasticsearch
graph: "relationships" # Neo4j for frame deps
retrieval:
cache_layer: "redis"
p50_latency: 50ms
p99_latency: 500ms
prefetch: true
cost_model:
storage: "$0.02/GB/month"
retrieval: "$0.0004/1000_reads"
tiers:
hot: "< 7 days" # S3 Standard
warm: "7-90 days" # S3 Standard-IA
cold: "> 90 days" # S3 Glacier
archive: "> 1 year" # Glacier Deep Archivelocal_to_remote_migration:
triggers:
age_based:
schedule: "0 */6 * * *" # Every 6 hours
migrate_after: 24h
size_pressure:
soft_limit: 75% # Start migration
hard_limit: 90% # Force migration
strategy: "lowest_score_first"
importance_based:
score_thresholds:
"< 0.3": 2h # Low importance
"< 0.5": 12h # Medium
"< 0.7": 24h # High
">= 0.7": 7d # Critical
upload_strategy:
mode: "hybrid"
continuous_streaming:
for_events: ["decision", "constraint", "api_change"]
latency: "< 1 minute"
batch_upload:
for_events: ["tool_call", "observation", "message"]
batch_size: 100
interval: 300s
compression: true
smart_batching:
group_by: "frame"
wait_for_frame_close: true
max_wait: 1htool_scores:
# Discovery & Intelligence (0.8-1.0)
search: 0.95 # Finding context/code
task_creation: 0.90 # Planning work
decision_recording: 0.90 # Architectural choices
context_retrieval: 0.85 # Loading memory
# Structural Changes (0.6-0.8)
write_new_file: 0.75
major_refactor: 0.70
api_change: 0.70
# Modifications (0.3-0.6)
edit: 0.50
test: 0.45
bash_execution: 0.40
# Simple Reads (0.1-0.3)
read: 0.25
ls: 0.20
grep: 0.15 # Simple pattern matchingscoring:
formula: |
score = (base_score * weights.base) +
(impact_multiplier * weights.impact) +
(persistence_bonus * weights.persistence) +
(reference_count * weights.reference)
weights:
configurable: true # Per-project tuning
defaults:
base: 0.4
impact: 0.3
persistence: 0.2
reference: 0.1
profiles:
security_focused:
impact: 0.5 # Changes matter more
exploration_heavy:
reference: 0.5 # Discovery paths matter
production_system:
persistence: 0.3 # Permanent changes criticalcontext_retrieval:
compressed_summary:
# Provided to LLM for analysis
recent_session:
frames: 15
dominant_operations: []
files_touched: []
errors_encountered: []
historical_patterns:
topic_frame_counts: {}
key_decisions: []
recurring_issues: []
queryable_indices:
by_error_type: {}
by_timeframe: {}
by_contributor: {}
llm_analysis:
inputs:
- current_query
- compressed_summary
- token_budget
output:
reasoning: "visible/auditable"
frames_to_retrieve: []
confidence_score: 0.0-1.0
generation:
when: "on_demand" # Not pre-computed
visibility: "settings/on_request" # Auditablenlp_queries:
time_based:
- "provide context from the last day"
- "show me what happened yesterday"
- "get all work from December 15-20"
- "what did Alice work on last week"
topic_based:
- "find all authentication work"
- "show database migration frames"
- "get frames about the login bug"
- "what decisions were made about caching"
combined:
- "show Alice's auth work from last week"
- "get high-priority bug fixes from yesterday"
- "find security decisions in the last month"interface StackMemoryQuery {
// Time filters
time?: {
last?: string; // "1d", "3h", "1w", "2m"
since?: Date; // ISO timestamp
until?: Date;
between?: [Date, Date];
specific?: Date; // Exact date
};
// Content filters
content?: {
topic?: string[]; // ["auth", "database"]
files?: string[]; // ["src/*.ts", "tests/*"]
errors?: string[]; // ["timeout", "null pointer"]
tools?: string[]; // ["search", "edit", "test"]
};
// Frame filters
frame?: {
type?: FrameType[]; // ["bug", "feature", "refactor"]
status?: Status[]; // ["open", "closed", "stalled"]
score?: {
min?: number; // 0.0-1.0
max?: number;
};
depth?: {
min?: number; // Stack depth
max?: number;
};
};
// People filters
people?: {
owner?: string[]; // ["alice", "bob"]
contributors?: string[];
team?: string; // "backend-team"
};
// Output control
output?: {
limit?: number; // Max frames to return
sort?: SortBy; // "time" | "score" | "relevance"
include?: string[]; // ["digests", "events", "anchors"]
format?: Format; // "full" | "summary" | "ids"
};
}// Last day's context
{
time: { last: "1d" },
output: { format: "summary" }
}
// High-importance auth work
{
content: { topic: ["auth", "oauth"] },
frame: { score: { min: 0.7 } },
output: { sort: "score", limit: 20 }
}
// Team's recent critical work
{
time: { last: "3d" },
people: { team: "backend-team" },
frame: { score: { min: 0.8 } },
output: { sort: "time" }
}# Command-line style
stackmemory query "auth work" --since="2024-12-20" --owner=alice
# Inline modifiers
"show auth work @alice #high-priority since:yesterday depth:10"
# Template style
"context from {time.last=1d} about {topic=authentication}"shortcuts:
# Time shortcuts
"today": { time: { last: "24h" } }
"yesterday": { time: { between: ["yesterday 00:00", "yesterday 23:59"] } }
"this week": { time: { last: "7d" } }
# Topic shortcuts
"bugs": { frame: { type: ["bug", "error", "fix"] } }
"features": { frame: { type: ["feature", "enhancement"] } }
"critical": { frame: { score: { min: 0.8 } } }
# Workflow shortcuts
"my work": { people: { owner: ["$current_user"] } }
"team work": { people: { team: "$current_team" } }
"recent": { time: { last: "4h" } }interface QueryResponse {
query: {
original: string; // User's input
interpreted: Query; // Parsed query
expanded: Query; // After expansion
};
results: {
frames: Frame[]; // Matching frames
count: number; // Total matches
score: number; // Query confidence
};
metadata: {
execution_time: number; // ms
tokens_used: number;
cache_hit: boolean;
};
suggestions: {
refine: string[]; // "Try adding time filter"
related: string[]; // "See also: auth decisions"
};
}trace_detection:
definition: "Chain of related tool calls"
boundaries:
time_proximity: 30s # Tools within 30 seconds
same_target: true # Same file/directory
causal_relationship: true # Error → fix → test
compression:
strategy: "single_trace" # Bundle as one unit
scoring: "max(all_tools)" # Use highest score
example:
raw: "Search → Read(10) → Edit(3) → Test → Fix → Test"
compressed: "Fixed auth bug via search-driven refactor [0.95]"garbage_collection:
type: "incremental" # Avoid stop-the-world
process:
frames_per_cycle: 100 # Process in chunks
cycle_interval: 60s # Every minute
generational:
young: "< 1 day"
mature: "1-7 days"
old: "7-30 days"
priorities:
protect:
- current_session
- pinned_frames
- unsynced_changes
- high_score_frames
evict_first:
- low_score_frames
- orphaned_frames
- duplicate_tracesdigest_generation:
deterministic: 60% # Reliable extraction
ai_generated: 40% # AI-generated summary
deterministic_fields:
- files_modified
- tests_run
- errors_encountered
- tool_call_count
- duration
- exit_status
ai_generated_fields:
- summary # 1-2 sentences
- key_decisions
- learned_insights
- next_steps
processing:
when: "batch_during_idle" # Not immediate
max_tokens: 200
fallback: "deterministic_only"stack_types:
individual:
owner: "single_user"
visibility: "private"
can_promote: true
shared:
team: "team_id"
visibility: "team"
participants: []
handoff_enabled: true
interaction:
promote: "individual → shared"
fork: "shared → individual"
merge: "individual → shared"
handoff: "alice → bob"frame_ownership:
creator: "original_author"
contributors: []
last_active: "current_user"
permissions:
read: "team"
continue: "team"
close: "owner_or_admin"
delete: "owner_only"
handoff:
explicit: "transfer_command"
implicit: "continue_working"
timeout: "idle_24h"# .stackmemory/config.yaml
version: 1.0
scoring:
weights:
base: 0.4
impact: 0.3
persistence: 0.2
reference: 0.1
tool_scores:
# Custom overrides
custom_tool: 0.75
retention:
local:
young: 1d
mature: 7d
old: 30d
max_size: 2GB
remote:
enabled: true
retention: infinite
performance:
max_stack_depth: 10000
retrieval_timeout_ms: 500
profiles:
environment: "production"$ stackmemory config validate
validation_checks:
- syntax_validation
- semantic_validation
- performance_analysis
- compatibility_check
- environment_verification
output:
errors: []
warnings: []
suggestions: []
auto_fix_available: truemcp_tools:
# Context Management
- get_context # Smart retrieval with LLM
- add_decision # Record decisions
- start_frame # Begin new frame
- close_frame # Close with digest
# Task Management
- create_task
- update_task_status
- get_active_tasks
- get_task_metrics
# Linear Integration
- linear_sync
- linear_update_task
- linear_get_tasks
# Analytics
- get_metrics
- get_frame_history
- search_frames{
"compressed_summary": {
"recent_activity": {},
"historical_patterns": {},
"statistics": {}
},
"hot_frames": [],
"relevant_anchors": [],
"query_endpoints": {
"deep_search": "endpoint",
"replay_session": "endpoint",
"get_specific_frames": "endpoint"
}
}secret_detection:
patterns:
- api_keys: "regex_patterns"
- passwords: "regex_patterns"
- tokens: "regex_patterns"
- custom: "user_defined"
action:
detection: "real_time"
handling: "redact" # Not block
notification: "warn_user"
storage:
hashed: true
reversible: falseprivacy:
data_residency: "configurable"
encryption:
at_rest: "AES-256"
in_transit: "TLS 1.3"
retention:
deletion_on_request: true
audit_trail: "maintained"
sharing:
default: "private"
team_opt_in: true
org_visibility: "admin_only"performance_slas:
retrieval:
p50: 50ms
p95: 200ms
p99: 500ms
storage:
write_throughput: "10K events/sec"
batch_upload: "100MB/min"
availability:
uptime: "99.9%"
data_durability: "99.999999999%" # 11 nines
scale:
max_frames: 10000
max_events_per_frame: 5000
max_storage_per_project: "unlimited"episodic_memory:
definition: "Capture and reuse past agent experiences"
episode_structure:
trigger: "significant_event" # Decision, error, breakthrough
context_snapshot:
- pre_state # State before episode
- action_sequence # Tools and decisions
- outcome # Result and impact
- learned_pattern # Extracted insight
retrieval_strategy:
similarity_matching:
current_context: true
embedding_distance: "cosine"
threshold: 0.85
temporal_relevance:
recent_weight: 0.7
historical_weight: 0.3
injection_mechanism:
when: "similar_context_detected"
format: "Past episode: {summary} led to {outcome}"
max_episodes: 3log_synthesis:
pattern_extraction:
frequency_analysis:
- common_error_sequences
- repeated_tool_patterns
- decision_reversals
causality_detection:
error_to_fix_chains: true
search_to_discovery: true
test_to_refactor: true
synthesis_output:
workflow_patterns:
- "Search → Read → Edit → Test → Fix"
- "Error → Analyze → Search → Solution"
anti_patterns:
- "Repeated failed attempts"
- "Circular dependencies"
optimization_opportunities:
- "Batch similar operations"
- "Cache frequent queries"reflection_loop:
trigger_conditions:
- frame_completion
- significant_error
- milestone_reached
- context_switch
reflection_process:
analyze:
- what_worked: "successful patterns"
- what_failed: "error patterns"
- alternative_approaches: "unexplored paths"
synthesize:
key_insights: []
patterns_identified: []
improvements_suggested: []
persist:
to_anchors: true # Save as decisions
to_digest: true # Include in summary
score_boost: 0.2 # Important for learningself_critique:
evaluation_dimensions:
code_quality:
- correctness: "Does it work?"
- efficiency: "Is it optimal?"
- maintainability: "Is it clean?"
decision_quality:
- rationale: "Was reasoning sound?"
- alternatives: "Were options considered?"
- evidence: "Was it data-driven?"
process_quality:
- methodology: "Was approach systematic?"
- tool_usage: "Were tools used effectively?"
- time_management: "Was effort proportional?"
critique_storage:
attach_to_frame: true
influence_scoring: true
guide_future_retrieval: true
continuous_improvement:
track_critique_patterns: true
adjust_weights_based_on_outcomes: true
share_learnings_across_team: truefeedback_sources:
automated:
- test_results
- linting_output
- performance_metrics
- security_scans
human:
- code_review_comments
- user_satisfaction
- explicit_feedback
environmental:
- build_success_rate
- deployment_outcomes
- production_incidents
integration:
collection: "multi_channel"
correlation: "cross_reference"
weight_by_reliability: true
feedback_to_memory:
positive: "boost_frame_score"
negative: "annotate_with_lessons"
neutral: "record_for_pattern"context_minimization:
strategies:
intelligent_filtering:
remove_redundant: true
compress_similar: true
prioritize_relevant: true
hierarchical_summarization:
detail_levels:
- full: "complete events"
- medium: "key operations"
- summary: "outcomes only"
dynamic_windowing:
expand_on: "high_relevance"
contract_on: "low_relevance"
adaptive_sizing: true
benefits:
reduced_token_usage: "40-60%"
faster_processing: true
clearer_focus: truedynamic_injection:
triggers:
- context_switch_detected
- new_error_type
- unfamiliar_codebase_area
- performance_degradation
injection_sources:
- relevant_documentation
- similar_past_solutions
- team_knowledge_base
- external_references
injection_timing:
just_in_time: true # Right before needed
predictive: true # Anticipate needs
on_demand: true # User requested
injection_format:
inline_hints: "minimal disruption"
sidebar_context: "additional detail"
full_frame: "comprehensive context"anxiety_management:
monitoring:
track_usage: "continuous"
alert_threshold: 70%
critical_threshold: 90%
mitigation_strategies:
progressive_compression:
- summarize_old_frames
- drop_low_score_events
- archive_to_retrieval
selective_loading:
- load_only_relevant
- defer_deep_history
- use_pointers_not_content
smart_truncation:
preserve: "decisions_and_outcomes"
truncate: "intermediate_steps"
compress: "repetitive_patterns"tool_discovery:
learning_progression:
basic: ["read", "write", "search"]
intermediate: ["edit", "test", "analyze"]
advanced: ["refactor", "optimize", "architect"]
discovery_mechanism:
observation: "watch_usage_patterns"
suggestion: "recommend_when_relevant"
education: "explain_tool_benefits"
tool_introduction:
gradual: true
context_appropriate: true
with_examples: trueparallel_execution:
conditions:
can_parallelize:
- independent_files
- different_subsystems
- non_conflicting_operations
must_serialize:
- dependent_changes
- shared_resources
- ordered_operations
orchestration:
plan: "identify_parallelizable"
execute: "batch_similar_operations"
synchronize: "merge_results"
handle_conflicts: "retry_or_serialize"
benefits:
speed: "3-5x improvement"
efficiency: "reduced_overhead"
atomicity: "group_related_changes"sub_agent_spawning:
spawn_triggers:
- complex_subtask
- specialized_domain
- parallel_workstream
- exploratory_analysis
agent_types:
analyzer: "deep_investigation"
builder: "implementation"
reviewer: "quality_check"
documenter: "knowledge_capture"
coordination:
handoff: "clear_context_transfer"
results: "structured_return"
state: "shared_memory_access"
lifecycle:
spawn: "with_specific_context"
execute: "autonomous_operation"
report: "structured_findings"
terminate: "clean_resource_release"debate_pattern:
participants:
proposer: "suggests_solution"
critic: "identifies_issues"
synthesizer: "merges_perspectives"
debate_process:
rounds: 3
convergence_required: true
consensus_threshold: 0.8
decision_recording:
all_perspectives: true
final_consensus: true
dissenting_opinions: true
benefits:
better_decisions: "multiple viewpoints"
error_reduction: "critical analysis"
learning: "exposed reasoning"anti_reward_hacking:
diverse_metrics:
- outcome_based: "actual_results"
- process_based: "methodology_quality"
- efficiency_based: "resource_usage"
- learning_based: "knowledge_gained"
dynamic_weights:
adjust_based_on:
- gaming_detection
- metric_reliability
- context_importance
validation:
cross_check_metrics: true
human_spot_checks: true
anomaly_detection: truecalibration:
feedback_loop:
collect: "outcome_data"
analyze: "prediction_vs_actual"
adjust: "scoring_weights"
calibration_frequency:
minor: "daily"
major: "weekly"
reset: "monthly"
drift_detection:
monitor: "score_distributions"
alert: "significant_changes"
auto_adjust: "within_bounds"planned_features:
# Original features
- cross_repository_memory
- team_memory_spaces
- background_project_compilers
- fine_grained_retention_policies
- ml_based_importance_scoring
- predictive_context_loading
- ide_frame_boundary_visualization
# New pattern-based features
- episodic_memory_retrieval
- reflection_loop_automation
- multi_agent_orchestration
- context_anxiety_management
- progressive_tool_discovery
- debate_based_decision_making
- continuous_self_improvementintegrations:
current:
- claude_code
- linear
- github
planned:
- vscode
- cursor
- jetbrains
- gitlab
- jira
- slack
pattern_integrations:
- langchain: "memory_patterns"
- autogen: "multi_agent"
- guidance: "structured_generation"
- dspy: "optimization_loops"- Frame stack management
- Local SQLite storage
- MCP server
- Basic scoring
- Claude Code integration
- LLM-driven retrieval
- Hybrid digest generation
- Smart trace detection
- Configurable scoring
- Shared team stacks
- Frame handoff
- Merge conflict resolution
- Team analytics
- Remote infinite storage
- Incremental GC
- Performance optimization
- Enterprise features
adoption:
- daily_active_projects: 10000
- frames_created_per_day: 1M
- context_retrievals_per_day: 10M
quality:
- retrieval_relevance: "> 90%"
- digest_accuracy: "> 85%"
- user_satisfaction: "> 4.5/5"
performance:
- retrieval_latency: "< 100ms p50"
- zero_context_loss: true
- uptime: "> 99.9%"scoring:
weights:
impact: 0.5
persistence: 0.3
tool_scores:
security_scan: 0.95
retention:
local:
old: 90d # Keep security decisions longerscoring:
weights:
reference: 0.5
base: 0.2
tool_scores:
search: 0.99
performance:
retrieval_timeout_ms: 1000 # Allow deeper searcheshigh_impact_easy:
# Implement first - quick wins
- context_minimization # 40-60% token savings
- reflection_loop # Improves decision quality
- parallel_tool_execution # 3-5x speed improvement
- episodic_memory # Reuse past solutions
high_impact_complex:
# Phase 2 - significant value
- self_critique_system # Continuous improvement
- multi_agent_debate # Better decisions
- dynamic_context_injection # Just-in-time context
- log_synthesis # Learn from patterns
moderate_impact:
# Phase 3 - refinements
- progressive_tool_discovery # Gradual capability
- anti_reward_hacking # Robust metrics
- sub_agent_spawning # Task delegation
- context_anxiety_mgmt # Proactive optimizationprinciples:
1_externalize_state:
rationale: "Enable persistence across sessions"
implementation: "Filesystem + database hybrid"
2_minimize_context:
rationale: "Maximize efficiency and clarity"
implementation: "Hierarchical summarization"
3_learn_continuously:
rationale: "Improve over time"
implementation: "Reflection loops + pattern extraction"
4_orchestrate_intelligently:
rationale: "Use right tool for task"
implementation: "Progressive discovery + conditional execution"
5_critique_systematically:
rationale: "Ensure quality"
implementation: "Multi-dimensional evaluation"step_1_baseline:
- implement_frame_stack
- add_basic_scoring
- create_sqlite_storage
- build_mcp_interface
step_2_memory_patterns:
- add_episodic_retrieval
- implement_log_synthesis
- create_reflection_loops
- build_pattern_detection
step_3_optimization:
- add_context_minimization
- implement_dynamic_injection
- create_parallel_execution
- optimize_retrieval_speed
step_4_intelligence:
- add_self_critique
- implement_debate_patterns
- create_continuous_calibration
- build_learning_system
step_5_scale:
- add_multi_agent_coordination
- implement_distributed_memory
- create_team_collaboration
- optimize_for_productionStackMemory provides a revolutionary approach to AI tool memory management through:
- Lossless storage with smart retrieval
- Frame-based organization replacing linear chat logs
- Two-tier storage balancing performance and capacity
- LLM-driven context selection for optimal relevance
- Team collaboration through shared and individual stacks
- Configurable scoring adapting to project needs
- Advanced patterns from agentic AI research
- Continuous learning through reflection and synthesis
- Intelligent orchestration of tools and agents
- Context optimization for efficiency at scale
The system ensures AI tools never lose context while maintaining performance at scale, incorporating state-of-the-art patterns from the agentic AI community.