UNPKG

@ace-sdk/cli

Version:

ACE CLI - Command-line tool for intelligent pattern learning and playbook management

63 lines 2.47 kB
/** * CLI Configuration Types and Helpers * * Re-exports types from @ace-sdk/core and provides CLI-specific convenience functions. * * @package @ace-sdk/cli */ export { DEFAULT_RUNTIME_SETTINGS, loadConfig, resolveContext, getTokenForOrg } from '@ace-sdk/core'; import { DEFAULT_RUNTIME_SETTINGS, loadConfig, resolveContext, getTokenForOrg } from '@ace-sdk/core'; /** * Get config (legacy) - DEPRECATED * * @deprecated Commands should use createContext() instead * This function is kept temporarily for backwards compatibility during migration */ export function getConfig() { return loadConfig(); } /** * Create AceContext from CLI flags, environment, and config files * * This function implements the complete context resolution flow: * 1. Resolve org/project using 4-tier precedence (flags > env > .claude/settings.json > error) * 2. Load global config to get server URL and tokens * 3. Get the correct token for the resolved organization * 4. Merge with server-derived runtime settings * * @param options - CLI flags for org/project override * @param serverConfig - Optional server configuration (fetched via AceClient.getConfig()) * @returns Complete runtime context with merged settings * @throws Error if context cannot be resolved */ export async function createContext(options = {}, serverConfig) { // Step 1: Resolve org and project IDs using precedence chain const resolved = resolveContext(options); const { orgId, projectId } = resolved; // Step 2: Load global config const globalConfig = loadConfig(); // Step 3: Get the correct API token for this organization const apiToken = getTokenForOrg(globalConfig, orgId); // Step 4: Merge server runtime settings with defaults const runtimeSettings = { ...DEFAULT_RUNTIME_SETTINGS, ...(serverConfig?.runtime_settings || {}) }; // Step 5: Override with environment variables if present if (process.env.ACE_SEARCH_THRESHOLD) { runtimeSettings.searchThreshold = parseFloat(process.env.ACE_SEARCH_THRESHOLD); } if (process.env.ACE_LEARNING_ENABLED) { runtimeSettings.learningEnabled = process.env.ACE_LEARNING_ENABLED === 'true'; } // Step 6: Return complete context return { serverUrl: globalConfig.serverUrl, apiToken, projectId, orgId, cacheTtlMinutes: globalConfig.cacheTtlMinutes, runtimeSettings }; } //# sourceMappingURL=config.js.map