@xec-sh/cli
Version:
Xec: The Universal Shell for TypeScript
367 lines (366 loc) • 9.09 kB
TypeScript
export interface Configuration {
version: string;
name?: string;
description?: string;
vars?: Record<string, any>;
targets?: TargetsConfig;
profiles?: Record<string, ProfileConfig>;
tasks?: Record<string, TaskConfig>;
scripts?: ScriptConfig;
commands?: Record<string, CommandConfig>;
secrets?: SecretsConfig;
extensions?: ExtensionConfig[];
}
export type TargetType = 'local' | 'ssh' | 'docker' | 'k8s';
export interface BaseTarget {
type: TargetType;
name?: string;
description?: string;
env?: Record<string, string>;
workdir?: string;
cwd?: string;
}
export interface HostConfig extends BaseTarget {
type: 'ssh';
host: string;
port?: number;
user?: string;
privateKey?: string;
password?: string;
passphrase?: string;
proxy?: string;
keepAlive?: boolean;
keepAliveInterval?: number;
connectionPool?: ConnectionPoolConfig;
sudo?: {
enabled?: boolean;
method?: string;
password?: string;
};
sftp?: {
enabled?: boolean;
concurrency?: number;
};
timeout?: number;
shell?: boolean | string;
encoding?: string;
maxBuffer?: number;
throwOnNonZeroExit?: boolean;
}
export interface ContainerConfig extends BaseTarget {
type: 'docker';
image?: string;
container?: string;
volumes?: string[];
ports?: string[];
network?: string;
restart?: string;
privileged?: boolean;
user?: string;
labels?: Record<string, string>;
healthcheck?: DockerHealthCheckConfig;
tty?: boolean;
autoRemove?: boolean;
socketPath?: string;
runMode?: 'exec' | 'run';
timeout?: number;
shell?: boolean | string;
encoding?: string;
maxBuffer?: number;
throwOnNonZeroExit?: boolean;
}
export interface PodConfig extends BaseTarget {
type: 'k8s';
namespace?: string;
pod?: string;
selector?: string;
container?: string;
context?: string;
kubeconfig?: string;
tty?: boolean;
stdin?: boolean;
execFlags?: string[];
timeout?: number;
shell?: boolean | string;
encoding?: string;
maxBuffer?: number;
throwOnNonZeroExit?: boolean;
}
export interface LocalConfig extends BaseTarget {
type: 'local';
timeout?: number;
shell?: boolean | string;
encoding?: string;
maxBuffer?: number;
throwOnNonZeroExit?: boolean;
}
export type TargetConfig = HostConfig | ContainerConfig | PodConfig | LocalConfig;
export interface TargetsConfig {
defaults?: TargetDefaults;
local?: LocalConfig;
hosts?: Record<string, Omit<HostConfig, 'type'>>;
containers?: Record<string, Omit<ContainerConfig, 'type'>>;
pods?: Record<string, Omit<PodConfig, 'type'>>;
kubernetes?: {
$context?: string;
$namespace?: string;
[key: string]: any;
};
$compose?: {
file?: string;
project?: string;
};
}
export interface TargetDefaults {
timeout?: number;
shell?: boolean | string;
encoding?: string;
maxBuffer?: number;
throwOnNonZeroExit?: boolean;
cwd?: string;
env?: Record<string, string>;
ssh?: SSHDefaults;
docker?: DockerDefaults;
kubernetes?: KubernetesDefaults;
}
export interface SSHDefaults {
port?: number;
keepAlive?: boolean;
keepAliveInterval?: number;
connectionPool?: {
enabled?: boolean;
maxConnections?: number;
idleTimeout?: number;
};
sudo?: {
enabled?: boolean;
method?: string;
password?: string;
};
sftp?: {
enabled?: boolean;
concurrency?: number;
};
}
export interface DockerDefaults {
tty?: boolean;
workdir?: string;
autoRemove?: boolean;
socketPath?: string;
user?: string;
runMode?: 'exec' | 'run';
}
export interface KubernetesDefaults {
namespace?: string;
tty?: boolean;
stdin?: boolean;
kubeconfig?: string;
context?: string;
execFlags?: string[];
}
export interface ProfileConfig {
vars?: Record<string, any>;
targets?: Partial<TargetsConfig>;
env?: Record<string, string>;
extends?: string;
}
export interface TaskParameter {
name: string;
type?: 'string' | 'number' | 'boolean' | 'array' | 'enum';
description?: string;
required?: boolean;
default?: any;
pattern?: string;
values?: any[];
min?: number;
max?: number;
minItems?: number;
maxItems?: number;
itemType?: string;
}
export interface TaskStep {
name?: string;
command?: string;
task?: string;
script?: string;
target?: string;
targets?: string[];
args?: string[];
env?: Record<string, string>;
when?: string;
onSuccess?: 'continue' | 'abort';
onFailure?: 'continue' | 'abort' | 'ignore' | TaskErrorHandler;
alwaysRun?: boolean;
register?: string;
parallel?: boolean;
}
export interface TaskErrorHandler {
retry?: number;
delay?: string;
task?: string;
command?: string;
}
export interface TaskHook {
name?: string;
command?: string;
task?: string;
}
export type TaskConfig = string | TaskDefinition;
export interface TaskDefinition {
command?: string;
script?: string;
description?: string;
target?: string;
targets?: string[];
params?: TaskParameter[];
steps?: TaskStep[];
env?: Record<string, string>;
workdir?: string;
timeout?: string | number;
parallel?: boolean;
failFast?: boolean;
maxConcurrent?: number;
hooks?: {
before?: TaskHook[];
after?: TaskHook[];
onError?: TaskHook[];
};
emits?: Array<{
name: string;
data?: any;
}>;
on?: Record<string, string>;
onSuccess?: {
emit?: string;
command?: string;
};
onError?: {
emit?: string;
command?: string;
};
cache?: {
key: string;
ttl?: number;
storage?: 'memory' | 'disk' | 'redis';
};
schedule?: string;
template?: string;
dependsOn?: string[];
private?: boolean;
}
export interface ScriptConfig {
env?: Record<string, string>;
globals?: string[];
sandbox?: {
enabled?: boolean;
restrictions?: ScriptRestriction[];
memoryLimit?: string;
cpuLimit?: number;
timeout?: string;
};
}
export type ScriptRestriction = 'no_network' | 'no_filesystem' | 'no_child_process';
export interface CommandConfig {
defaultTimeout?: string | number;
parallel?: boolean;
compress?: boolean;
progress?: boolean;
dynamic?: boolean;
interval?: number;
clear?: boolean;
[key: string]: any;
}
export interface SecretsConfig {
provider: 'local' | 'vault' | '1password' | 'aws-secrets' | 'env' | 'dotenv';
config?: {
address?: string;
path?: string;
region?: string;
file?: string;
storageDir?: string;
passphrase?: string;
[key: string]: any;
};
}
export interface ExtensionConfig {
source: string;
tasks?: string[];
config?: Record<string, any>;
}
export interface ConnectionPoolConfig {
min?: number;
max?: number;
idleTimeout?: string | number;
acquireTimeout?: string | number;
}
export interface DockerHealthCheckConfig {
test: string | string[];
interval?: string;
timeout?: string;
retries?: number;
startPeriod?: string;
}
export type VariableValue = string | number | boolean | null | VariableValue[] | {
[key: string]: VariableValue;
};
export interface TargetReference {
type: 'hosts' | 'containers' | 'pods' | 'local';
name?: string;
pattern?: string;
isWildcard?: boolean;
}
export interface ResolvedTarget extends BaseTarget {
id: string;
type: TargetType;
config: TargetConfig;
source: 'configured' | 'detected' | 'created';
}
export interface TaskResult {
task: string;
success: boolean;
duration: number;
output?: string;
error?: Error;
steps?: StepResult[];
}
export interface StepResult {
name?: string;
success: boolean;
duration: number;
output?: string;
error?: Error;
target?: string;
}
export interface ConfigSource {
type: 'builtin' | 'global' | 'project' | 'profile' | 'env' | 'cli';
path?: string;
name?: string;
priority: number;
config: Partial<Configuration>;
}
export interface VariableContext {
vars?: Record<string, any>;
env?: Record<string, string>;
params?: Record<string, any>;
secrets?: Record<string, string>;
profile?: string;
target?: ResolvedTarget;
}
export interface ValidationError {
path: string;
message: string;
value?: any;
rule?: string;
}
export interface ConfigManagerOptions {
projectRoot?: string;
globalConfigDir?: string;
profile?: string;
envPrefix?: string;
cache?: boolean;
strict?: boolean;
secretProvider?: {
type: 'local' | 'vault' | 'aws-secrets' | '1password' | 'env' | 'dotenv';
config?: Record<string, any>;
};
}