Move src/ → apps/server/ and packages/web/ → apps/web/ to adopt standard monorepo conventions (apps/ for runnable apps, packages/ for reusable libraries). Update all config files, shared package imports, test fixtures, and documentation to reflect new paths. Key fixes: - Update workspace config to ["apps/*", "packages/*"] - Update tsconfig.json rootDir/include for apps/server/ - Add apps/web/** to vitest exclude list - Update drizzle.config.ts schema path - Fix ensure-schema.ts migration path detection (3 levels up in dev, 2 levels up in dist) - Fix tests/integration/cli-server.test.ts import paths - Update packages/shared imports to apps/server/ paths - Update all docs/ files with new paths
95 lines
3.3 KiB
TypeScript
95 lines
3.3 KiB
TypeScript
/**
|
|
* Phase Dispatch Router — queue, dispatch, state, child tasks
|
|
*/
|
|
|
|
import { TRPCError } from '@trpc/server';
|
|
import { z } from 'zod';
|
|
import type { Task } from '../../db/schema.js';
|
|
import type { ProcedureBuilder } from '../trpc.js';
|
|
import { requirePhaseDispatchManager, requireTaskRepository } from './_helpers.js';
|
|
|
|
export function phaseDispatchProcedures(publicProcedure: ProcedureBuilder) {
|
|
return {
|
|
queuePhase: publicProcedure
|
|
.input(z.object({ phaseId: z.string().min(1) }))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const phaseDispatchManager = requirePhaseDispatchManager(ctx);
|
|
await phaseDispatchManager.queuePhase(input.phaseId);
|
|
return { success: true };
|
|
}),
|
|
|
|
dispatchNextPhase: publicProcedure
|
|
.mutation(async ({ ctx }) => {
|
|
const phaseDispatchManager = requirePhaseDispatchManager(ctx);
|
|
return phaseDispatchManager.dispatchNextPhase();
|
|
}),
|
|
|
|
getPhaseQueueState: publicProcedure
|
|
.query(async ({ ctx }) => {
|
|
const phaseDispatchManager = requirePhaseDispatchManager(ctx);
|
|
return phaseDispatchManager.getPhaseQueueState();
|
|
}),
|
|
|
|
createChildTasks: publicProcedure
|
|
.input(z.object({
|
|
parentTaskId: z.string().min(1),
|
|
tasks: z.array(z.object({
|
|
number: z.number().int().positive(),
|
|
name: z.string().min(1),
|
|
description: z.string(),
|
|
type: z.enum(['auto', 'checkpoint:human-verify', 'checkpoint:decision', 'checkpoint:human-action']).default('auto'),
|
|
dependencies: z.array(z.number().int().positive()).optional(),
|
|
})),
|
|
}))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const taskRepo = requireTaskRepository(ctx);
|
|
|
|
const parentTask = await taskRepo.findById(input.parentTaskId);
|
|
if (!parentTask) {
|
|
throw new TRPCError({
|
|
code: 'NOT_FOUND',
|
|
message: `Parent task '${input.parentTaskId}' not found`,
|
|
});
|
|
}
|
|
if (parentTask.category !== 'detail') {
|
|
throw new TRPCError({
|
|
code: 'BAD_REQUEST',
|
|
message: `Parent task must have category 'detail', got '${parentTask.category}'`,
|
|
});
|
|
}
|
|
|
|
const numberToId = new Map<number, string>();
|
|
const created: Task[] = [];
|
|
|
|
for (const taskInput of input.tasks) {
|
|
const task = await taskRepo.create({
|
|
parentTaskId: input.parentTaskId,
|
|
phaseId: parentTask.phaseId,
|
|
initiativeId: parentTask.initiativeId,
|
|
name: taskInput.name,
|
|
description: taskInput.description,
|
|
type: taskInput.type,
|
|
order: taskInput.number,
|
|
status: 'pending',
|
|
});
|
|
numberToId.set(taskInput.number, task.id);
|
|
created.push(task);
|
|
}
|
|
|
|
for (const taskInput of input.tasks) {
|
|
if (taskInput.dependencies && taskInput.dependencies.length > 0) {
|
|
const taskId = numberToId.get(taskInput.number)!;
|
|
for (const depNumber of taskInput.dependencies) {
|
|
const dependsOnTaskId = numberToId.get(depNumber);
|
|
if (dependsOnTaskId) {
|
|
await taskRepo.createDependency(taskId, dependsOnTaskId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return created;
|
|
}),
|
|
};
|
|
}
|