UNPKG

@hugsylabs/hugsy-compiler

Version:

Configuration compiler for Claude Code settings

157 lines 4.88 kB
/** * @hugsylabs/hugsy-compiler - Configuration compiler for Claude Code * Transforms simple .hugsyrc configurations into complete Claude settings.json */ import type { HugsyConfig, ClaudeSettings, SlashCommand } from '@hugsylabs/hugsy-types'; export interface CompilerOptions { projectRoot?: string; verbose?: boolean; throwOnError?: boolean; } export declare class CompilerError extends Error { details?: Record<string, string | number | boolean | string[]> | undefined; constructor(message: string, details?: Record<string, string | number | boolean | string[]> | undefined); } export declare class Compiler { private projectRoot; private presets; private plugins; private presetsCache; private compiledCommands; private options; constructor(optionsOrRoot?: CompilerOptions | string); /** * Validate generated settings.json format for Claude Code compatibility */ validateSettings(settings: ClaudeSettings): string[]; /** * Main compile function - transforms .hugsyrc to Claude settings.json */ compile(config: HugsyConfig): Promise<ClaudeSettings>; /** * Validate configuration structure */ private validateConfig; /** * Validate permission format - must be Tool(pattern) or Tool */ private validatePermissions; /** * Validate and return statusLine configuration */ private validateStatusLine; /** * Handle errors based on options */ private handleError; /** * Sanitize configuration values - remove zero-width and control characters */ private sanitizeConfigValues; /** * Log verbose messages */ private log; /** * Log changes made by plugins */ private logChanges; /** * Log compilation summary */ private logCompilationSummary; /** * Compile permissions from presets, plugins, and user config */ private compilePermissions; /** * Compile hooks from presets, plugins, and user config */ private compileHooks; /** * Convert hooks to Claude Code expected format * Transforms simple {matcher, command} format to {matcher, hooks: [{type, command, timeout}]} * IMPORTANT: Merges all hooks with the same matcher into a single entry per Claude Code docs * IMPORTANT: Converts "Tool(args)" format to just "Tool" as Claude Code only supports tool-level matching */ private normalizeHooksForClaude; /** * Normalize matcher format from "Tool(args)" to "Tool" * Claude Code only supports tool-level matching, not argument patterns */ private normalizeMatcherFormat; /** * Compile slash commands from presets, plugins, and user config */ private compileCommands; /** * Process user command configuration */ private processUserCommands; /** * Load commands from local markdown files */ private loadCommandFiles; /** * Extract command name from file path */ private extractCommandName; /** * Parse markdown command file with optional frontmatter */ private parseMarkdownCommand; /** * Simple YAML parser for frontmatter */ private parseSimpleYaml; /** * Merge commands into the target map */ private mergeCommands; /** * Get compiled commands (for use by CLI) */ getCompiledCommands(): Map<string, SlashCommand>; /** * Compile environment variables * Merge strategy: presets < plugins < user config (later overrides earlier) * All values are converted to strings as required by Claude settings */ private compileEnvironment; /** * Load presets (extends) - recursively loads nested extends with progress tracking */ private loadPresets; /** * Recursively load a preset and its extends */ private loadPresetRecursive; /** * Load plugins with progress tracking */ private loadPlugins; /** * Load a module (preset or plugin) */ private loadModule; /** * Merge hook configurations * Deduplication based on globs and hook commands */ private mergeHooks; /** * Normalize config field names (handle uppercase variants) */ private normalizeConfig; /** * Resolve conflicts in permissions (deny > ask > allow) */ private resolvePermissionConflicts; /** * Load configuration from file */ static loadConfig(configPath?: string): Promise<HugsyConfig | null>; } export type { HugsyConfig, ClaudeSettings, PermissionSettings, HookSettings, Plugin, Preset, StatusLineConfig, HookConfig, SlashCommand, SlashCommandsConfig, } from '@hugsylabs/hugsy-types'; export type { Plugin as HugsyPlugin } from '@hugsylabs/hugsy-types'; //# sourceMappingURL=index.d.ts.map