aicm
Version:
A TypeScript CLI tool for managing AI IDE rules across different projects and teams
119 lines (118 loc) • 4.51 kB
TypeScript
import { CosmiconfigResult } from "cosmiconfig";
import { HooksJson, HookFile } from "./hooks";
export interface RawConfig {
rootDir?: string;
targets?: string[];
presets?: string[];
mcpServers?: MCPServers;
workspaces?: boolean;
skipInstall?: boolean;
}
export interface Config {
rootDir?: string;
targets: string[];
presets?: string[];
mcpServers?: MCPServers;
workspaces?: boolean;
skipInstall?: boolean;
}
export type MCPServer = {
command: string;
args?: string[];
env?: Record<string, string>;
url?: never;
} | {
url: string;
env?: Record<string, string>;
command?: never;
args?: never;
} | false;
export interface MCPServers {
[serverName: string]: MCPServer;
}
export interface ManagedFile {
name: string;
content: string;
sourcePath: string;
source: "local" | "preset";
presetName?: string;
}
export interface AssetFile {
name: string;
content: Buffer;
sourcePath: string;
source: "local" | "preset";
presetName?: string;
}
export type RuleFile = ManagedFile;
export type CommandFile = ManagedFile;
export interface SkillFile {
name: string;
sourcePath: string;
source: "local" | "preset";
presetName?: string;
}
export type AgentFile = ManagedFile;
export interface RuleCollection {
[target: string]: RuleFile[];
}
export interface ResolvedConfig {
config: Config;
rules: RuleFile[];
commands: CommandFile[];
assets: AssetFile[];
skills: SkillFile[];
agents: AgentFile[];
mcpServers: MCPServers;
hooks: HooksJson;
hookFiles: HookFile[];
}
export declare const ALLOWED_CONFIG_KEYS: readonly ["rootDir", "targets", "presets", "mcpServers", "workspaces", "skipInstall"];
export declare const SUPPORTED_TARGETS: readonly ["cursor", "windsurf", "codex", "claude"];
export type SupportedTarget = (typeof SUPPORTED_TARGETS)[number];
export declare function detectWorkspacesFromPackageJson(cwd: string): boolean;
export declare function resolveWorkspaces(config: unknown, configFilePath: string, cwd: string): boolean;
export declare function applyDefaults(config: RawConfig, workspaces: boolean): Config;
export declare function validateConfig(config: unknown, configFilePath: string, cwd: string, isWorkspaceMode?: boolean): asserts config is Config;
export declare function loadRulesFromDirectory(directoryPath: string, source: "local" | "preset", presetName?: string): Promise<RuleFile[]>;
export declare function loadCommandsFromDirectory(directoryPath: string, source: "local" | "preset", presetName?: string): Promise<CommandFile[]>;
export declare function loadAssetsFromDirectory(directoryPath: string, source: "local" | "preset", presetName?: string): Promise<AssetFile[]>;
/**
* Load skills from a skills/ directory
* Each direct subdirectory containing a SKILL.md file is considered a skill
*/
export declare function loadSkillsFromDirectory(directoryPath: string, source: "local" | "preset", presetName?: string): Promise<SkillFile[]>;
/**
* Load agents from an agents/ directory
* Agents are markdown files (.md) with YAML frontmatter
*/
export declare function loadAgentsFromDirectory(directoryPath: string, source: "local" | "preset", presetName?: string): Promise<AgentFile[]>;
/**
* Extract namespace from preset path for directory structure
* Handles both npm packages and local paths consistently
*/
export declare function extractNamespaceFromPresetPath(presetPath: string): string[];
export declare function resolvePresetPath(presetPath: string, cwd: string): string | null;
export declare function loadPreset(presetPath: string, cwd: string): Promise<{
config: Config;
rootDir: string;
resolvedPath: string;
}>;
export declare function loadAllRules(config: Config, cwd: string): Promise<{
rules: RuleFile[];
commands: CommandFile[];
assets: AssetFile[];
skills: SkillFile[];
agents: AgentFile[];
mcpServers: MCPServers;
hooks: HooksJson;
hookFiles: HookFile[];
}>;
export declare function loadConfigFile(searchFrom?: string): Promise<CosmiconfigResult>;
/**
* Check if workspaces mode is enabled without loading all rules/presets
* This is useful for commands that only need to know the workspace setting
*/
export declare function checkWorkspacesEnabled(cwd?: string): Promise<boolean>;
export declare function loadConfig(cwd?: string): Promise<ResolvedConfig | null>;
export declare function saveConfig(config: Config, cwd?: string): boolean;