/** * Config Writer * * Provides safe config file writing with atomic operations and proper permissions. * * Security features: * - Global config (contains API key) written with mode 0600 (owner read/write only) * - Global directory created with mode 0700 (owner access only) * - Project config written with standard permissions (0644) * - Path validation to prevent writes outside allowed directories */ import { GlobalConfig, ProjectConfig } from './types.js'; import type { ActiveSpecification, AgentTeamsConfig } from './agent-teams.types.js'; /** * Ensure global config directory exists with secure permissions * * Creates ~/.specforge/ if it doesn't exist, with mode 0700 (owner-only access). * Idempotent - safe to call multiple times. * * @throws Error if directory creation fails * * @example * ```typescript * ensureGlobalDir(); * // ~/.specforge/ now exists with drwx------ permissions * ``` */ export declare function ensureGlobalDir(): void; /** * Save global configuration * * Merges the provided config with existing global config and writes to * ~/.specforge/config.json with secure permissions (0600). * * Undefined values are removed from the final config. * * @param config - Partial global config to save * @throws Error if write fails * * @example * ```typescript * // Save API key * saveGlobalConfig({ apiKey: 'sf_live_...' }); * * // Update format, keeping existing apiKey * saveGlobalConfig({ format: 'json' }); * ``` */ export declare function saveGlobalConfig(config: Partial): void; /** * Delete a field from global config * * Loads existing config, removes the specified field, and saves. * No-op if the field doesn't exist. * * @param field - Field name to remove * @throws Error if read/write fails * * @example * ```typescript * deleteGlobalConfigField('apiKey'); * deleteGlobalConfigField('defaultProjectId'); * ``` */ export declare function deleteGlobalConfigField(field: keyof GlobalConfig): void; /** * Save project configuration * * Merges the provided config with existing project config and writes to * .specforge.json in the current directory. * * Undefined values are removed from the final config. * * @param config - Partial project config to save * @param targetDir - Directory to write .specforge.json to (defaults to cwd) * @throws Error if write fails * * @example * ```typescript * // Initialize project * saveProjectConfig({ * projectId: 'proj_123', * specificationId: 'spec_456', * }); * * // Update format setting * saveProjectConfig({ format: 'json' }); * ``` */ export declare function saveProjectConfig(config: Partial, targetDir?: string): void; /** * Set the active specification in .specforge.json * * Updates only the `activeSpecification` section, preserving all other fields. * Pass `null` to remove the active specification entirely. * * @param spec - ActiveSpecification to set, or null to clear * @param targetDir - Directory containing .specforge.json (defaults to cwd) * * @example * ```typescript * // Set active specification * setActiveSpecification({ id: 'spec_123', title: 'My Spec', activatedAt: new Date().toISOString() }); * * // Clear active specification * setActiveSpecification(null); * ``` */ export declare function setActiveSpecification(spec: ActiveSpecification | null, targetDir?: string): void; /** * Update the Agent Teams configuration in .specforge.json * * Merges the provided partial config with the existing `agentTeams` section, * preserving all other fields. Only the keys present in `config` are overwritten. * * @param config - Partial AgentTeamsConfig to merge * @param targetDir - Directory containing .specforge.json (defaults to cwd) * * @example * ```typescript * // Enable agent teams * setAgentTeamsConfig({ enabled: true }); * * // Update strategy and timeout, keeping other settings * setAgentTeamsConfig({ strategy: 'parallel', timeoutMinutes: 30 }); * ``` */ export declare function setAgentTeamsConfig(config: Partial, targetDir?: string): void; /** * MCP server configuration with optional environment variables */ interface McpServerConfig { command: string; args: string[]; env?: Record; } /** * MCP configuration structure */ interface McpConfigFile { mcpServers: { specforge: McpServerConfig; }; } /** * Generate MCP configuration for Claude Code integration * * Creates a .mcp.json configuration that registers the SpecForge MCP server * for Claude Code. The server is registered under the "specforge" name. * * If an API key is provided, it will be included in the env section so that * Claude Code can start the MCP server with proper authentication. * * @param apiKey - Optional API key to include in the configuration * @returns MCP config object * * @example * ```typescript * // Without API key * const mcpConfig = generateMcpConfig(); * * // With API key (recommended) * const mcpConfig = generateMcpConfig('sf_live_...'); * console.log(mcpConfig.mcpServers.specforge.env?.SPECFORGE_API_KEY); * ``` */ export declare function generateMcpConfig(apiKey?: string): McpConfigFile; /** * Save MCP configuration file * * Writes .mcp.json to the current directory (or specified directory) * to enable Claude Code integration with the SpecForge MCP server. * * Automatically includes the API key from global config (~/.specforge/config.json) * if available, so Claude Code can start the MCP server with proper authentication. * * @param targetDir - Directory to write .mcp.json to (defaults to cwd) * @throws Error if write fails * * @example * ```typescript * saveMcpConfig(); * // .mcp.json created in current directory with API key from global config * ``` */ export declare function saveMcpConfig(targetDir?: string): void; /** * Add an entry to .gitignore if it exists * * Does not create .gitignore if it doesn't exist. * Does not duplicate existing entries. * * @param entry - Line to add to .gitignore * @param targetDir - Directory containing .gitignore (defaults to cwd) * @returns true if entry was added, false if already exists or no .gitignore * * @example * ```typescript * const added = addToGitignore('.specforge.json'); * if (added) { * console.log('Added .specforge.json to .gitignore'); * } * ``` */ export declare function addToGitignore(entry: string, targetDir?: string): boolean; /** * Remove API key from global config (logout) * * @example * ```typescript * clearApiKey(); * console.log('Logged out successfully'); * ``` */ export declare function clearApiKey(): void; /** * Check if global config file exists * * @returns true if ~/.specforge/config.json exists */ export declare function hasGlobalConfig(): boolean; /** * Check if project config file exists in cwd * * @returns true if .specforge.json exists */ export declare function hasProjectConfig(): boolean; export {}; //# sourceMappingURL=writer.d.ts.map