UNPKG

@ooples/token-optimizer-mcp

Version:

Intelligent context window optimization for Claude Code - store content externally via caching and compression, freeing up your context window for what matters

258 lines 6.94 kB
/** * SmartUser - Intelligent User & Permission Management * * Track 2C - Tool #7: User/permission management with smart caching (86%+ token reduction) * * Capabilities: * - User/group information retrieval * - Permission analysis and ACL management * - Sudo/privilege escalation checks * - Security audit recommendations * - Cross-platform support (Linux/Windows/macOS) * * Token Reduction Strategy: * - Cache user/group databases (95% reduction) * - Incremental permission changes (86% reduction) * - Compressed ACL trees (88% reduction) */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export type UserOperation = 'list-users' | 'list-groups' | 'check-permissions' | 'audit-security' | 'get-acl' | 'get-user-info' | 'get-group-info' | 'check-sudo'; export interface SmartUserOptions { operation: UserOperation; username?: string; groupname?: string; path?: string; includeSystemUsers?: boolean; includeSystemGroups?: boolean; useCache?: boolean; ttl?: number; } export interface UserInfo { username: string; uid: number; gid: number; fullName?: string; homeDirectory?: string; shell?: string; groups: string[]; isSystemUser?: boolean; isSudoer?: boolean; lastLogin?: number; passwordExpiry?: number; accountLocked?: boolean; } export interface GroupInfo { groupname: string; gid: number; members: string[]; isSystemGroup?: boolean; } export interface PermissionInfo { path: string; owner: string; group: string; permissions: string; numericMode: number; specialBits?: { setuid?: boolean; setgid?: boolean; sticky?: boolean; }; acl?: ACLEntry[]; canRead: boolean; canWrite: boolean; canExecute: boolean; } export interface ACLEntry { type: 'user' | 'group' | 'mask' | 'other'; name?: string; permissions: string; isDefault?: boolean; } export interface SecurityIssue { severity: 'critical' | 'high' | 'medium' | 'low' | 'info'; category: 'permission' | 'sudo' | 'password' | 'group' | 'file' | 'configuration'; description: string; recommendation: string; affectedEntity: string; details?: Record<string, unknown>; } export interface SecurityAuditReport { summary: { totalIssues: number; critical: number; high: number; medium: number; low: number; info: number; }; issues: SecurityIssue[]; users: { total: number; sudoers: number; systemUsers: number; noPassword: number; lockedAccounts: number; }; groups: { total: number; privileged: number; empty: number; }; recommendations: string[]; } export interface SmartUserResult { success: boolean; operation: UserOperation; data: { users?: UserInfo[]; user?: UserInfo; groups?: GroupInfo[]; group?: GroupInfo; permissions?: PermissionInfo; acl?: ACLEntry[]; auditReport?: SecurityAuditReport; canSudo?: boolean; output?: string; error?: string; }; metadata: { tokensUsed: number; tokensSaved: number; cacheHit: boolean; executionTime: number; }; } export declare class SmartUser { private cache; private tokenCounter; private metricsCollector; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector); /** * Main entry point for user/permission operations */ run(options: SmartUserOptions): Promise<SmartUserResult>; /** * List all users with smart caching (95% reduction) */ private listUsers; /** * List all groups with smart caching (95% reduction) */ private listGroups; /** * Get detailed user information with caching */ private getUserInfo; /** * Get detailed group information with caching */ private getGroupInfo; /** * Check file/directory permissions with incremental caching (86% reduction) */ private checkPermissions; /** * Get ACL information with compressed tree representation (88% reduction) */ private getACL; /** * Check sudo privileges */ private checkSudo; /** * Comprehensive security audit with smart caching */ private auditSecurity; /** * Get all users from the system */ private getAllUsers; /** * Get all groups from the system */ private getAllGroups; /** * Get detailed user information */ private getUserDetails; /** * Get detailed group information */ private getGroupDetails; /** * Get user's group memberships */ private getUserGroups; /** * Get permission information for a path */ private getPermissionInfo; /** * Get ACL entries for a path */ private getACLEntries; /** * Check if user can use sudo */ private canUserSudo; /** * Get current username */ private getCurrentUser; /** * Perform comprehensive security audit */ private performSecurityAudit; } export declare function getSmartUser(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector): SmartUser; export declare function runSmartUser(options: SmartUserOptions, cache?: CacheEngine, tokenCounter?: TokenCounter, metricsCollector?: MetricsCollector): Promise<SmartUserResult>; export declare const SMART_USER_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: "object"; properties: { operation: { type: "string"; enum: string[]; description: string; }; username: { type: "string"; description: string; }; groupname: { type: "string"; description: string; }; path: { type: "string"; description: string; }; includeSystemUsers: { type: "boolean"; description: string; default: boolean; }; includeSystemGroups: { type: "boolean"; description: string; default: boolean; }; useCache: { type: "boolean"; description: string; default: boolean; }; ttl: { type: "number"; description: string; }; }; required: string[]; }; }; //# sourceMappingURL=smart-user.d.ts.map