{"_id":"@55387.ai/context-engine","name":"@55387.ai/context-engine","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@55387.ai/context-engine","version":"1.0.0","description":"TypeScript implementation of Context Engineering for LLM agents - supporting Sessions, Memory, and dynamic context assembly","main":"dist/index.js","types":"dist/index.d.ts","bin":{"context-engine":"dist/cli/index.js"},"scripts":{"build":"npm run clean && tsc","clean":"rm -rf dist","dev":"tsc --watch","test":"vitest","test:coverage":"vitest --coverage","lint":"eslint src --ext .ts","prepublishOnly":"npm run build && npm test","example":"npx tsx examples/basic-usage.ts"},"keywords":["context-engineering","llm","agent","memory","session","gemini","ai","context","conversation","long-term-memory","rag"],"author":{"name":"Link Team"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/your-org/context-engine.git"},"bugs":{"url":"https://github.com/your-org/context-engine/issues"},"homepage":"https://github.com/your-org/context-engine#readme","devDependencies":{"@types/better-sqlite3":"^7.6.13","@types/node":"^20.10.0","@types/uuid":"^9.0.7","@typescript-eslint/eslint-plugin":"^6.13.0","@typescript-eslint/parser":"^6.13.0","eslint":"^8.55.0","ts-node":"^10.9.2","typescript":"^5.3.0","vitest":"^1.0.0"},"dependencies":{"@google/generative-ai":"^0.24.1","@types/crypto-js":"^4.2.2","better-sqlite3":"^12.5.0","crypto-js":"^4.2.0","dotenv":"^17.2.3","eventemitter3":"^5.0.1","p-retry":"^4.6.2","uuid":"^9.0.1"},"engines":{"node":">=18.0.0"},"_id":"@55387.ai/context-engine@1.0.0","_nodeVersion":"25.2.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-ceE/niku6VQHXmkI7KYAgcV/6QMYFqpsJIr2NBIqg7IDDwGIAi9xH9CjM9tb4ibCYuVGIzagffieq+Z5h3eQMQ==","shasum":"306553375c08a09dc5396fb9ed243ed12f4d136c","tarball":"https://registry.npmjs.org/@55387.ai/context-engine/-/context-engine-1.0.0.tgz","fileCount":177,"unpackedSize":356437,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCw4nYl2hFbea/c/yEDzLUNkRdZuxD2Alf66qD6PzD8DAIgP9kIm4RaWZ5bfRfAmuR1I7WHS/JPS/JLMEPV0ryAtJA="}]},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"directories":{},"maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/context-engine_1.0.0_1765033379283_0.6054271204581769"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-06T15:02:59.207Z","1.0.0":"2025-12-06T15:02:59.449Z","modified":"2025-12-06T15:03:00.031Z"},"maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"description":"TypeScript implementation of Context Engineering for LLM agents - supporting Sessions, Memory, and dynamic context assembly","homepage":"https://github.com/your-org/context-engine#readme","keywords":["context-engineering","llm","agent","memory","session","gemini","ai","context","conversation","long-term-memory","rag"],"repository":{"type":"git","url":"git+https://github.com/your-org/context-engine.git"},"author":{"name":"Link Team"},"bugs":{"url":"https://github.com/your-org/context-engine/issues"},"license":"MIT","readme":"# Context Engine\n\n[![npm version](https://badge.fury.io/js/%4055387.ai%2Fcontext-engine.svg)](https://www.npmjs.com/package/@55387.ai/context-engine)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA production-ready TypeScript implementation of Context Engineering for LLM agents, providing robust session management, long-term memory, and intelligent context assembly.\n\n## ✨ Features\n\n- 🧠 **Long-term Memory** - Intelligent memory extraction, consolidation, and retrieval with vector similarity search\n- 💬 **Session Management** - Turn-by-turn conversation history with automatic compaction strategies\n- 🎯 **Context Assembly** - Dynamic prompt construction with relevant memories and conversation history\n- 🔌 **Pluggable Architecture** - Support for multiple storage backends (Memory, FileSystem, SQLite)\n- 🤖 **Multi-LLM Support** - Gemini, DeepSeek, and extensible provider interface\n- 🔐 **Security** - Built-in authorization, audit logging, and encryption support\n- 📊 **Observability** - Comprehensive logging and metrics\n- 🛠️ **CLI Tool** - Interactive command-line interface for testing and management\n- 📘 **TypeScript** - Full type safety and IntelliSense support\n\n## 📦 Installation\n\n```bash\nnpm install @55387.ai/context-engine\n```\n\n## 🚀 Quick Start\n\n### Using the CLI\n\n```bash\n# Install globally\nnpm install -g @55387.ai/context-engine\n\n# Start an interactive chat\ncontext-engine chat -u alice\n\n# List memories for a user\ncontext-engine memories -u alice\n\n# Show recent sessions\ncontext-engine session -u alice\n```\n\n### Programmatic Usage\n\n```typescript\nimport {\n  ContextEngine,\n  SessionManager,\n  MemoryManager,\n  FileSystemSessionStorage,\n  FileSystemMemoryStorage,\n  GeminiLLMProvider,\n  ConfigLoader\n} from '@55387.ai/context-engine';\n\n// 1. Load configuration (from .env or defaults)\nconst config = ConfigLoader.load();\n\n// 2. Initialize storage\nconst sessionStorage = new FileSystemSessionStorage({ \n  baseDir: config.storage.baseDir \n});\n\nconst memoryStorage = new FileSystemMemoryStorage({\n  baseDir: config.storage.baseDir,\n  encryptionKey: config.storage.encryptionKey\n});\n\n// 3. Initialize LLM provider\nconst llmProvider = new GeminiLLMProvider(config.llm.apiKey!);\n\n// 4. Create managers\nconst sessionManager = new SessionManager(sessionStorage, {\n  llmProvider,\n  compactionConfig: { strategy: 'hybrid', maxTurns: 20 }\n});\n\nconst memoryManager = new MemoryManager(memoryStorage, llmProvider);\n\n// 5. Initialize the Context Engine\nconst engine = new ContextEngine({\n  sessionManager,\n  memoryManager,\n  llmProvider\n});\n\n// 6. Create a session and start chatting\nconst session = await sessionManager.createSession({ \n  userId: 'alice' \n});\n\nconst response = await engine.processTurn(\n  session.id, \n  \"Hello! I'm a software engineer working with TypeScript.\"\n);\n\nconsole.log('AI:', response);\n\n// Later, in a new conversation...\nconst response2 = await engine.processTurn(\n  session.id,\n  \"What programming languages do I use?\"\n);\n// AI will remember from long-term memory!\n```\n\n## 🏗️ Architecture\n\n### Core Components\n\n- **ContextEngine**: Main orchestrator that coordinates session and memory management\n- **SessionManager**: Manages short-term conversation context with automatic compaction\n- **MemoryManager**: Handles long-term memory extraction, consolidation, and retrieval\n- **Storage Backends**: Pluggable storage (In-Memory, FileSystem, SQLite)\n- **LLM Providers**: Abstracted interface supporting multiple LLM vendors\n\n### Storage Options\n\n```typescript\n// In-Memory (for testing)\nimport { InMemorySessionStorage, InMemoryMemoryStorage } from '@55387.ai/context-engine';\n\n// File System (for development)\nimport { FileSystemSessionStorage, FileSystemMemoryStorage } from '@55387.ai/context-engine';\n\n// SQLite (for production)\nimport { SQLiteMemoryStorage } from '@55387.ai/context-engine';\n\nconst memoryStorage = new SQLiteMemoryStorage({\n  dbPath: './data/memories.db',\n  encryptionKey: process.env.ENCRYPTION_KEY\n});\n```\n\n### LLM Providers\n\n```typescript\n// Google Gemini\nimport { GeminiLLMProvider } from '@55387.ai/context-engine';\nconst llm = new GeminiLLMProvider(process.env.GOOGLE_API_KEY!);\n\n// DeepSeek\nimport { DeepSeekLLMProvider } from '@55387.ai/context-engine';\nconst llm = new DeepSeekLLMProvider(process.env.DEEPSEEK_API_KEY!);\n\n// Mock (for testing)\nimport { MockLLMProvider } from '@55387.ai/context-engine';\nconst llm = new MockLLMProvider();\n```\n\n## ⚙️ Configuration\n\nCreate a `.env` file (see `.env.example`):\n\n```bash\n# LLM Provider\nGOOGLE_API_KEY=your_api_key_here\nLLM_PROVIDER=gemini\nLLM_MODEL=gemini-1.5-pro\n\n# Storage\nSTORAGE_TYPE=filesystem  # or 'memory', 'sqlite'\nSTORAGE_BASE_DIR=./data\nSQLITE_DB_PATH=./data/memories.db\n\n# Security\nAPP_SECRET=your_super_secret_key_at_least_32_chars_long_123\n\n# Session\nSESSION_MAX_TOKENS=4000\nSESSION_TTL_MS=86400000\n\n# Logging\nLOG_LEVEL=info\n```\n\n## 📖 Documentation\n\n- [CLI Guide](./docs/CLI_GUIDE.md) - Complete CLI usage guide\n- [Technical Docs](./docs/TECHNICAL_DOCS.md) - Detailed technical documentation\n- [Architecture](./docs/ARCHITECTURE_AUDIT.md) - System architecture and design\n- [Publishing Guide](./docs/NPM_PUBLISH_GUIDE.md) - Guide for maintaining this package\n\n## 🧪 Examples\n\nCheck out the [examples](./examples) directory:\n\n- `basic-usage.ts` - Simple example of the Context Engine\n- `full_demo.ts` - Comprehensive demonstration with all features\n\n## 🛠️ Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n\n# Run tests with coverage\nnpm test:coverage\n\n# Build the project\nnpm run build\n\n# Run linter\nnpm run lint\n\n# Watch mode (development)\nnpm run dev\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please read our contributing guidelines before submitting PRs.\n\n## 📝 License\n\nMIT License - see [LICENSE](./LICENSE) file for details\n\n## 🙏 Acknowledgments\n\nThis implementation is inspired by the Context Engineering whitepaper and best practices in LLM agent design.\n\n## 📬 Support\n\n- 📧 Email: support@example.com\n- 🐛 Issues: [GitHub Issues](https://github.com/your-org/context-engine/issues)\n- 💬 Discussions: [GitHub Discussions](https://github.com/your-org/context-engine/discussions)\n\n","readmeFilename":"README.md","_rev":"1-2be47ff274cd28873ea238fcd63a0eff"}