/**
* Repository Operations Tool Handlers
* Pull and clone repository operations on Komodo
*/
import type { KomodoClient } from '../../core/KomodoClient';
import { Logger } from '../../utils/logger';
export interface PullRepoOptions {
branch?: string;
force?: boolean;
submodules?: boolean;
}
export interface CloneRepoOptions {
branch?: string;
depth?: number;
submodules?: boolean;
overwrite?: boolean;
}
export interface PullRepoRequest {
id: string;
options?: PullRepoOptions;
}
export interface CloneRepoRequest {
id: string;
options?: CloneRepoOptions;
}
export interface RepoOperationResponse {
success: boolean;
repoId: string;
operation: 'pull' | 'clone';
status: 'queued' | 'running' | 'completed' | 'failed';
message: string;
timestamp: string;
branch?: string;
commit?: {
hash?: string;
author?: string;
message?: string;
timestamp?: string;
};
changes?: {
files_changed?: number;
insertions?: number;
deletions?: number;
};
path?: string;
logs?: string[];
}
/**
* Pull latest changes from a repository
*/
export async function pullRepo(
client: KomodoClient,
request: PullRepoRequest
): Promise<RepoOperationResponse> {
const logger = Logger.getInstance();
try {
logger.info('Pulling repository', {
repoId: request.id,
branch: request.options?.branch
});
const response = await client.post<RepoOperationResponse>(
`/execute/repo/${request.id}/pull`,
request.options || {}
);
logger.info('Repository pull initiated', {
repoId: request.id,
status: response.status,
branch: response.branch,
commit: response.commit?.hash
});
return response;
} catch (error) {
logger.error('Failed to pull repository', {
repoId: request.id,
error: error instanceof Error ? error.message : String(error)
});
throw error;
}
}
/**
* Clone a repository
*/
export async function cloneRepo(
client: KomodoClient,
request: CloneRepoRequest
): Promise<RepoOperationResponse> {
const logger = Logger.getInstance();
try {
logger.info('Cloning repository', {
repoId: request.id,
branch: request.options?.branch,
depth: request.options?.depth
});
const response = await client.post<RepoOperationResponse>(
`/execute/repo/${request.id}/clone`,
request.options || {}
);
logger.info('Repository clone initiated', {
repoId: request.id,
status: response.status,
branch: response.branch,
path: response.path
});
return response;
} catch (error) {
logger.error('Failed to clone repository', {
repoId: request.id,
error: error instanceof Error ? error.message : String(error)
});
throw error;
}
}