API Overview

NikCLI provides a comprehensive set of APIs for integrating with external tools, extending functionality, and building custom applications. The APIs are designed following TypeScript-first principles with full type safety and extensive documentation.

Agent APIs

Create, manage, and interact with AI agents

Tool APIs

Extend functionality with custom tools

Configuration APIs

Manage settings and preferences programmatically

Streaming APIs

Real-time communication and progress tracking

Core Interfaces

AgentTask Interface

Represents a task that can be executed by an agent:
interface AgentTask {
  /** Unique identifier for the task */
  id: string;
  
  /** Human-readable description of the task */
  description: string;
  
  /** Task type for routing to appropriate agent */
  type?: 'development' | 'analysis' | 'refactoring' | 'testing' | 'documentation';
  
  /** Priority level (1-10, 10 = highest) */
  priority?: number;
  
  /** Project context and workspace information */
  context: WorkspaceContext;
  
  /** Specific requirements and constraints */
  requirements?: TaskRequirements;
  
  /** Files to focus on (optional) */
  focusFiles?: string[];
  
  /** Expected deliverables */
  deliverables?: string[];
  
  /** Timeout in milliseconds */
  timeout?: number;
  
  /** Recovery strategy in case of failure */
  recoveryStrategy?: RecoveryStrategy;
  
  /** Custom metadata */
  metadata?: Record<string, any>;
}

WorkspaceContext Interface

Provides context about the current project and environment:
interface WorkspaceContext {
  /** Absolute path to the project root */
  projectRoot: string;
  
  /** Detected project type */
  projectType: ProjectType;
  
  /** Technology stack information */
  techStack: TechStack;
  
  /** Package.json contents (if available) */
  packageJson?: PackageJson;
  
  /** Git repository information */
  gitInfo?: GitInfo;
  
  /** Environment configuration */
  environment: EnvironmentInfo;
  
  /** File structure summary */
  fileStructure: FileStructure;
  
  /** Recent changes */
  recentChanges?: RecentChanges[];
  
  /** Coding patterns and conventions */
  patterns: CodingPatterns;
}

AgentExecution Interface

Represents the execution of a task by an agent:
interface AgentExecution {
  /** Execution identifier */
  id: string;
  
  /** Associated task */
  taskId: string;
  
  /** Executing agent */
  agentId: string;
  
  /** Current execution status */
  status: ExecutionStatus;
  
  /** Start timestamp */
  startedAt: number;
  
  /** Completion timestamp (if finished) */
  completedAt?: number;
  
  /** Progress percentage (0-100) */
  progress: number;
  
  /** Current execution stage */
  currentStage: string;
  
  /** Execution results */
  results?: ExecutionResult[];
  
  /** Any errors encountered */
  errors?: AgentError[];
  
  /** Performance metrics */
  metrics: ExecutionMetrics;
  
  /** Real-time event stream */
  stream: EventEmitter;
}

Agent Management APIs

AgentService

Central service for managing agent lifecycle and operations:

BaseAgent Interface

All agents implement the BaseAgent interface:
abstract class BaseAgent {
  /** Agent unique identifier */
  readonly id: string;
  
  /** Agent name and description */
  readonly name: string;
  readonly description: string;
  
  /** Agent capabilities */
  abstract getCapabilities(): AgentCapability[];
  
  /** Agent permissions */
  abstract getPermissions(): AgentPermissions;
  
  /**
   * Execute a task
   */
  abstract executeTask(task: AgentTask): Promise<AgentExecution>;
  
  /**
   * Check if agent can handle a specific task
   */
  abstract canHandleTask(task: AgentTask): boolean;
  
  /**
   * Get current status
   */
  abstract getStatus(): AgentStatus;
  
  /**
   * Cleanup resources
   */
  abstract cleanup(): Promise<void>;
  
  /**
   * Configure agent settings
   */
  configure(config: Partial<AgentConfig>): void {
    Object.assign(this.config, config);
  }
  
  /**
   * Check if agent has specific capability
   */
  hasCapability(capability: AgentCapability): boolean {
    return this.getCapabilities().includes(capability);
  }
  
  /**
   * Subscribe to agent events
   */
  on(event: string, listener: (...args: any[]) => void): void {
    this.eventEmitter.on(event, listener);
  }
  
  /**
   * Emit agent event
   */
  protected emit(event: string, ...args: any[]): void {
    this.eventEmitter.emit(event, ...args);
  }
}

Tool System APIs

ToolService

Manages the tool system and provides secure tool execution:

Configuration APIs

ConfigManager

Provides programmatic access to configuration management:

Streaming APIs

Real-time Communication

NikCLI provides real-time APIs for monitoring agent progress and system events:

Error Handling

Error Types and Recovery

Next Steps

All APIs are fully typed with TypeScript. Use your IDE’s IntelliSense for comprehensive autocomplete and documentation while developing.