Files
stack/apps/gateway/src/coord/coord.service.ts
Jarvis 774b76447d
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
ci/woodpecker/push/ci Pipeline failed
fix: rename all packages from @mosaic/* to @mosaicstack/*
- Updated all package.json name fields and dependency references
- Updated all TypeScript/JavaScript imports
- Updated .woodpecker/publish.yml filters and registry paths
- Updated tools/install.sh scope default
- Updated .npmrc registry paths (worktree + host)
- Enhanced update-checker.ts with checkForAllUpdates() multi-package support
- Updated CLI update command to show table of all packages
- Added KNOWN_PACKAGES, formatAllPackagesTable, getInstallAllCommand
- Marked checkForUpdate() with @deprecated JSDoc

Closes #391
2026-04-04 21:43:23 -05:00

78 lines
2.1 KiB
TypeScript

import { Injectable, Logger } from '@nestjs/common';
import {
loadMission,
getMissionStatus,
getTaskStatus,
parseTasksFile,
type Mission,
type MissionStatusSummary,
type MissionTask,
type TaskDetail,
} from '@mosaicstack/coord';
import { promises as fs } from 'node:fs';
import path from 'node:path';
/**
* File-based coord operations for agent tool consumption.
* DB-backed mission CRUD is handled directly by MissionsController via Brain repos.
*/
@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 [];
}
}
}