feat: @mosaic/coord — migrate from v0, gateway integration (P2-005) (#77)
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #77.
This commit is contained in:
73
apps/gateway/src/coord/coord.service.ts
Normal file
73
apps/gateway/src/coord/coord.service.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import {
|
||||
loadMission,
|
||||
getMissionStatus,
|
||||
getTaskStatus,
|
||||
parseTasksFile,
|
||||
type Mission,
|
||||
type MissionStatusSummary,
|
||||
type MissionTask,
|
||||
type TaskDetail,
|
||||
} from '@mosaic/coord';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
@Injectable()
|
||||
export class CoordService {
|
||||
private readonly logger = new Logger(CoordService.name);
|
||||
|
||||
async loadMission(projectPath: string): Promise<Mission | null> {
|
||||
try {
|
||||
return await loadMission(projectPath);
|
||||
} catch (err) {
|
||||
this.logger.debug(
|
||||
`No coord mission at ${projectPath}: ${err instanceof Error ? err.message : String(err)}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getMissionStatus(projectPath: string): Promise<MissionStatusSummary | null> {
|
||||
const mission = await this.loadMission(projectPath);
|
||||
if (!mission) return null;
|
||||
|
||||
try {
|
||||
return await getMissionStatus(mission);
|
||||
} catch (err) {
|
||||
this.logger.error(
|
||||
`Failed to get mission status: ${err instanceof Error ? err.message : String(err)}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getTaskStatus(projectPath: string, taskId: string): Promise<TaskDetail | null> {
|
||||
const mission = await this.loadMission(projectPath);
|
||||
if (!mission) return null;
|
||||
|
||||
try {
|
||||
return await getTaskStatus(mission, taskId);
|
||||
} catch (err) {
|
||||
this.logger.error(
|
||||
`Failed to get task status for ${taskId}: ${err instanceof Error ? err.message : String(err)}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async listTasks(projectPath: string): Promise<MissionTask[]> {
|
||||
const mission = await this.loadMission(projectPath);
|
||||
if (!mission) return [];
|
||||
|
||||
const tasksFile = path.isAbsolute(mission.tasksFile)
|
||||
? mission.tasksFile
|
||||
: path.join(mission.projectPath, mission.tasksFile);
|
||||
|
||||
try {
|
||||
const content = await fs.readFile(tasksFile, 'utf8');
|
||||
return parseTasksFile(content);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user