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:
2026-03-13 03:32:20 +00:00
committed by jason.woltje
parent 7f6815feaf
commit f3a7eadcea
19 changed files with 1873 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
import { Controller, Get, NotFoundException, Param, Query, UseGuards } from '@nestjs/common';
import { AuthGuard } from '../auth/auth.guard.js';
import { CoordService } from './coord.service.js';
@Controller('api/coord')
@UseGuards(AuthGuard)
export class CoordController {
constructor(private readonly coordService: CoordService) {}
@Get('status')
async missionStatus(@Query('projectPath') projectPath?: string) {
const resolvedPath = projectPath ?? process.cwd();
const status = await this.coordService.getMissionStatus(resolvedPath);
if (!status) throw new NotFoundException('No active coord mission found');
return status;
}
@Get('tasks')
async listTasks(@Query('projectPath') projectPath?: string) {
const resolvedPath = projectPath ?? process.cwd();
return this.coordService.listTasks(resolvedPath);
}
@Get('tasks/:taskId')
async taskStatus(@Param('taskId') taskId: string, @Query('projectPath') projectPath?: string) {
const resolvedPath = projectPath ?? process.cwd();
const detail = await this.coordService.getTaskStatus(resolvedPath, taskId);
if (!detail) throw new NotFoundException(`Task ${taskId} not found in coord mission`);
return detail;
}
}

View File

@@ -0,0 +1,49 @@
export interface CoordMissionStatusDto {
mission: {
id: string;
name: string;
status: string;
projectPath: string;
};
milestones: {
total: number;
completed: number;
current?: {
id: string;
name: string;
status: string;
};
};
tasks: {
total: number;
done: number;
inProgress: number;
pending: number;
blocked: number;
cancelled: number;
};
nextTaskId?: string;
activeSession?: {
sessionId: string;
runtime: string;
startedAt: string;
};
}
export interface CoordTaskDetailDto {
missionId: string;
task: {
id: string;
title: string;
status: string;
milestone?: string;
pr?: string;
notes?: string;
};
isNextTask: boolean;
activeSession?: {
sessionId: string;
runtime: string;
startedAt: string;
};
}

View File

@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { CoordService } from './coord.service.js';
import { CoordController } from './coord.controller.js';
@Module({
providers: [CoordService],
controllers: [CoordController],
exports: [CoordService],
})
export class CoordModule {}

View 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 [];
}
}
}