feat: first round of mcp standalone server
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
import { getGitEngine } from './GitEngine';
|
||||
import { getProjectEngine } from './ProjectEngine';
|
||||
import type {
|
||||
GitAvailability,
|
||||
RepoState,
|
||||
GitStatusDto,
|
||||
GitHistoryEntry,
|
||||
GitRemoteStateDto,
|
||||
GitActionResult,
|
||||
} from './GitEngine';
|
||||
import type { GitEngine, GitAvailability, RepoState, GitStatusDto, GitHistoryEntry, GitRemoteStateDto, GitActionResult } from './GitEngine';
|
||||
import type { ProjectEngine } from './ProjectEngine';
|
||||
|
||||
export type { GitAvailability, RepoState, GitStatusDto, GitHistoryEntry, GitRemoteStateDto, GitActionResult };
|
||||
|
||||
@@ -17,8 +9,13 @@ export type { GitAvailability, RepoState, GitStatusDto, GitHistoryEntry, GitRemo
|
||||
* don't need to pass it.
|
||||
*/
|
||||
export class GitApiAdapter {
|
||||
constructor(
|
||||
private readonly gitEngine: GitEngine,
|
||||
private readonly projectEngine: ProjectEngine,
|
||||
) {}
|
||||
|
||||
private async resolveProjectPath(): Promise<string> {
|
||||
const project = await getProjectEngine().getActiveProject();
|
||||
const project = await this.projectEngine.getActiveProject();
|
||||
if (!project?.dataPath) {
|
||||
throw new Error('No active project with a data path');
|
||||
}
|
||||
@@ -26,55 +23,47 @@ export class GitApiAdapter {
|
||||
}
|
||||
|
||||
async checkAvailability(): Promise<GitAvailability> {
|
||||
return getGitEngine().checkAvailability();
|
||||
return this.gitEngine.checkAvailability();
|
||||
}
|
||||
|
||||
async getRepoState(): Promise<RepoState> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().getRepoState(projectPath);
|
||||
return this.gitEngine.getRepoState(projectPath);
|
||||
}
|
||||
|
||||
async getStatus(): Promise<GitStatusDto> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().getStatus(projectPath);
|
||||
return this.gitEngine.getStatus(projectPath);
|
||||
}
|
||||
|
||||
async getHistory(limit?: number): Promise<GitHistoryEntry[]> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().getHistory(projectPath, limit);
|
||||
return this.gitEngine.getHistory(projectPath, limit);
|
||||
}
|
||||
|
||||
async getRemoteState(): Promise<GitRemoteStateDto> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().getRemoteState(projectPath);
|
||||
return this.gitEngine.getRemoteState(projectPath);
|
||||
}
|
||||
|
||||
async fetch(): Promise<GitActionResult> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().fetch(projectPath);
|
||||
return this.gitEngine.fetch(projectPath);
|
||||
}
|
||||
|
||||
async pull(): Promise<GitActionResult> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().pull(projectPath);
|
||||
return this.gitEngine.pull(projectPath);
|
||||
}
|
||||
|
||||
async push(): Promise<GitActionResult> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().push(projectPath);
|
||||
return this.gitEngine.push(projectPath);
|
||||
}
|
||||
|
||||
async commitAll(message: string): Promise<GitActionResult> {
|
||||
const projectPath = await this.resolveProjectPath();
|
||||
return getGitEngine().commitAll(projectPath, message);
|
||||
return this.gitEngine.commitAll(projectPath, message);
|
||||
}
|
||||
}
|
||||
|
||||
let instance: GitApiAdapter | null = null;
|
||||
|
||||
export function getGitApiAdapter(): GitApiAdapter {
|
||||
if (!instance) {
|
||||
instance = new GitApiAdapter();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user