{"_id":"@aigentic/shared","_rev":"2-8fa5f80df592b916667f227a5a7d906f","name":"@aigentic/shared","dist-tags":{"alpha":"3.0.0-alpha.8","latest":"3.0.0-alpha.8"},"versions":{"3.0.0-alpha.8":{"name":"@aigentic/shared","version":"3.0.0-alpha.8","_id":"@aigentic/shared@3.0.0-alpha.8","maintainers":[{"name":"aigentic","email":"engineering@aigentic.net"}],"dist":{"shasum":"5cfbdf53f9e54f40878bbe0a45d44ad5594abcdd","tarball":"https://registry.npmjs.org/@aigentic/shared/-/shared-3.0.0-alpha.8.tgz","fileCount":86,"integrity":"sha512-D/3FPOj5raN1ZM+/IEF0DY1yvlE0qSMtTrikvY3rFPVAxpHwmiGt7MLJCf+BKDtXDKdMFM2AQRsr7M1dOHR12g==","signatures":[{"sig":"MEUCIQDjQNcQ8M4uOAZzJEo0577iJVMikPF+84IbXBe+FcyEKwIgML1bGEKAw7jwcM3fyre8bVbV+T7gEP4oPQktGurM9nc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":680308},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":"./dist/index.js","./mcp":"./dist/mcp/index.js","./core":"./dist/core/index.js","./hooks":"./dist/hooks/index.js","./types":"./dist/types/index.js","./events":"./dist/events/index.js","./security":"./dist/security/index.js","./resilience":"./dist/resilience/index.js","./src/plugin-interface.js":"./dist/plugin-interface.js"},"scripts":{"test":"vitest run","build":"tsc"},"_npmUser":{"name":"aigentic","email":"engineering@aigentic.net"},"_npmVersion":"11.12.0","description":"Shared module - common types, events, utilities, core interfaces","directories":{},"_nodeVersion":"22.22.1","dependencies":{"sql.js":"^1.10.3"},"publishConfig":{"tag":"v3alpha","access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ws":"^8.16.0","zod":"^3.22.4","cors":"^2.8.5","helmet":"^7.1.0","vitest":"^4.0.16","express":"^4.21.0","@types/ws":"^8.5.10","@types/cors":"^2.8.17","@types/node":"^20.0.0","@types/sql.js":"^1.4.9","@types/express":"^4.17.21"},"_npmOperationalInternal":{"tmp":"tmp/shared_3.0.0-alpha.8_1779262106260_0.12649236743388448","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-05-20T07:28:26.125Z","modified":"2026-09-13T15:30:34.309Z","3.0.0-alpha.8":"2026-05-20T07:28:26.394Z"},"description":"Shared module - common types, events, utilities, core interfaces","maintainers":[{"email":"engineering@aigentic.net","name":"aiggy"}],"readme":"# @claude-flow/shared\n\n[![npm version](https://img.shields.io/npm/v/@claude-flow/shared.svg)](https://www.npmjs.com/package/@claude-flow/shared)\n[![npm downloads](https://img.shields.io/npm/dm/@claude-flow/shared.svg)](https://www.npmjs.com/package/@claude-flow/shared)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)\n[![Core](https://img.shields.io/badge/Module-Core-blue.svg)](https://github.com/ruvnet/claude-flow)\n\n> Shared utilities, types, and core infrastructure for Claude Flow V3 - the foundation module used by all other @claude-flow packages.\n\n## Features\n\n- **Core Types** - Agent, Task, Memory, MCP, and Swarm type definitions\n- **Core Interfaces** - Agent, Task, Memory, Event, and Coordinator interfaces\n- **Configuration** - Schema validation, loading, and default values\n- **Event System** - Event bus, coordinator, and handler utilities\n- **Hooks System** - Pre/post execution hooks for extensibility\n- **MCP Infrastructure** - Server, transport, connection pool, and tool registry\n- **Health Monitoring** - Health checks and monitoring utilities\n\n## Installation\n\n```bash\nnpm install @claude-flow/shared\n```\n\n## Quick Start\n\n```typescript\nimport {\n  AgentState,\n  TaskDefinition,\n  MemoryEntry,\n  EventBus,\n  ConfigLoader\n} from '@claude-flow/shared';\n\n// Use shared types\nconst agent: AgentState = {\n  id: { id: 'agent-1', swarmId: 'swarm-1', type: 'coder' },\n  name: 'Code Agent',\n  type: 'coder',\n  status: 'idle'\n};\n\n// Use configuration\nconst config = await ConfigLoader.load('./config.json');\n\n// Use event system\nconst eventBus = new EventBus();\neventBus.on('task.completed', (event) => {\n  console.log(`Task ${event.taskId} completed`);\n});\n```\n\n## Package Exports\n\n```typescript\n// Main entry (recommended - includes all modules)\nimport { ... } from '@claude-flow/shared';\n\n// Submodule exports (for tree-shaking or specific imports)\nimport { ... } from '@claude-flow/shared/types';      // Type definitions\nimport { ... } from '@claude-flow/shared/core';       // Config, interfaces, orchestrator\nimport { ... } from '@claude-flow/shared/events';     // Event sourcing (ADR-007)\nimport { ... } from '@claude-flow/shared/hooks';      // Hooks system\nimport { ... } from '@claude-flow/shared/mcp';        // MCP server infrastructure\nimport { ... } from '@claude-flow/shared/security';   // Security utilities\nimport { ... } from '@claude-flow/shared/resilience'; // Retry, circuit breaker, rate limiter\n```\n\n## API Reference\n\n### Types\n\n```typescript\nimport type {\n  // Agent types\n  AgentId,\n  AgentState,\n  AgentType,\n  AgentStatus,\n  AgentCapabilities,\n  AgentMetrics,\n\n  // Task types\n  TaskId,\n  TaskDefinition,\n  TaskType,\n  TaskStatus,\n  TaskPriority,\n\n  // Memory types\n  MemoryEntry,\n  MemoryType,\n  SearchResult,\n\n  // Swarm types\n  SwarmId,\n  SwarmStatus,\n  SwarmEvent,\n  CoordinatorConfig,\n\n  // MCP types\n  MCPTool,\n  MCPRequest,\n  MCPResponse\n} from '@claude-flow/shared/types';\n```\n\n### Core Interfaces\n\n```typescript\nimport type {\n  IAgent,\n  ITask,\n  IMemory,\n  ICoordinator,\n  IEventHandler\n} from '@claude-flow/shared/core';\n\n// Agent interface\ninterface IAgent {\n  getId(): AgentId;\n  getState(): AgentState;\n  execute(task: TaskDefinition): Promise<TaskResult>;\n  handleMessage(message: Message): Promise<void>;\n}\n\n// Memory interface\ninterface IMemory {\n  store(entry: MemoryEntry): Promise<string>;\n  retrieve(id: string): Promise<MemoryEntry | null>;\n  search(query: SearchQuery): Promise<SearchResult[]>;\n  delete(id: string): Promise<boolean>;\n}\n\n// Coordinator interface\ninterface ICoordinator {\n  initialize(): Promise<void>;\n  shutdown(): Promise<void>;\n  registerAgent(agent: IAgent): Promise<string>;\n  submitTask(task: TaskDefinition): Promise<string>;\n}\n```\n\n### Configuration\n\n```typescript\nimport {\n  ConfigLoader,\n  ConfigValidator,\n  defaultConfig,\n  ConfigSchema\n} from '@claude-flow/shared/core';\n\n// Load configuration\nconst config = await ConfigLoader.load('./config.json');\nconst config2 = await ConfigLoader.loadFromEnv();\n\n// Validate configuration\nconst errors = ConfigValidator.validate(config);\nif (errors.length > 0) {\n  console.error('Invalid config:', errors);\n}\n\n// Default configuration\nconst defaults = defaultConfig();\n```\n\n### Event System\n\n```typescript\nimport { EventBus, EventCoordinator } from '@claude-flow/shared/events';\n\nconst eventBus = new EventBus();\n\n// Subscribe to events\neventBus.on('agent.joined', (event) => {\n  console.log(`Agent ${event.agentId} joined`);\n});\n\neventBus.on('task.*', (event) => {\n  console.log(`Task event: ${event.type}`);\n});\n\n// Emit events\neventBus.emit({\n  type: 'task.completed',\n  taskId: 'task-1',\n  result: { success: true }\n});\n\n// Event coordinator for complex workflows\nconst coordinator = new EventCoordinator();\ncoordinator.orchestrate([\n  { event: 'step1.done', handler: () => startStep2() },\n  { event: 'step2.done', handler: () => startStep3() }\n]);\n```\n\n### Hooks System\n\n```typescript\nimport { HooksManager, Hook } from '@claude-flow/shared/hooks';\n\nconst hooks = new HooksManager();\n\n// Register pre-execution hook\nhooks.register('pre:task', async (context) => {\n  console.log(`Starting task: ${context.taskId}`);\n  return { ...context, startTime: Date.now() };\n});\n\n// Register post-execution hook\nhooks.register('post:task', async (context, result) => {\n  const duration = Date.now() - context.startTime;\n  console.log(`Task completed in ${duration}ms`);\n});\n\n// Execute with hooks\nconst result = await hooks.execute('task', context, async (ctx) => {\n  return await runTask(ctx);\n});\n```\n\n### MCP Infrastructure\n\n```typescript\nimport {\n  createMCPServer,\n  createToolRegistry,\n  createConnectionPool,\n  createSessionManager,\n  defineTool,\n  quickStart,\n} from '@claude-flow/shared/mcp';\n\n// Quick start - simplest way to create an MCP server\nconst server = await quickStart({\n  transport: 'stdio',\n  name: 'My MCP Server',\n});\n\n// Tool registry\nconst registry = createToolRegistry();\nregistry.register(defineTool({\n  name: 'swarm_init',\n  description: 'Initialize a swarm',\n  inputSchema: { type: 'object', properties: { topology: { type: 'string' } } },\n  handler: async (params) => ({ result: 'initialized' }),\n}));\n\n// Connection pool\nconst pool = createConnectionPool({\n  maxConnections: 10,\n  acquireTimeoutMs: 30000,\n});\n\n// Session manager\nconst sessions = createSessionManager({ timeoutMs: 3600000 });\nconst session = await sessions.create({ clientInfo: { name: 'client' } });\n```\n\n### Health Monitor\n\n```typescript\nimport { HealthMonitor, HealthCheck } from '@claude-flow/shared/core';\n\nconst monitor = new HealthMonitor();\n\n// Register health checks\nmonitor.register('database', async () => {\n  const connected = await db.ping();\n  return { healthy: connected, latency: pingTime };\n});\n\nmonitor.register('memory', async () => {\n  const usage = process.memoryUsage();\n  return { healthy: usage.heapUsed < MAX_HEAP, usage };\n});\n\n// Run health checks\nconst report = await monitor.check();\n// { overall: 'healthy', checks: { database: {...}, memory: {...} } }\n```\n\n## TypeScript Types\n\nAll types are fully exported and documented:\n\n```typescript\n// Re-export all types\nexport * from './types/agent.types';\nexport * from './types/task.types';\nexport * from './types/memory.types';\nexport * from './types/swarm.types';\nexport * from './types/mcp.types';\n```\n\n## Dependencies\n\n- `sql.js` - SQLite WASM for cross-platform persistence\n\n## Used By\n\nThis package is a dependency of all other @claude-flow modules:\n\n- [@claude-flow/cli](../cli) - CLI module\n- [@claude-flow/security](../security) - Security & validation\n- [@claude-flow/memory](../memory) - AgentDB & HNSW indexing\n- [@claude-flow/neural](../neural) - SONA learning & RL algorithms\n- [@claude-flow/performance](../performance) - Benchmarking & optimization\n- [@claude-flow/swarm](../swarm) - 15-agent coordination\n- [@claude-flow/integration](../integration) - agentic-flow@alpha bridge\n- [@claude-flow/testing](../testing) - TDD framework & fixtures\n- [@claude-flow/deployment](../deployment) - Release management\n- [@claude-flow/embeddings](../embeddings) - Embedding service\n- [@claude-flow/hooks](../hooks) - Hooks system\n\n## License\n\nMIT\n","readmeFilename":"README.md"}