feat: Add agent preview integration with auto-teardown and simplified commands
- Add agentId label to preview containers (cw.agent-id) for tracking - Add startForAgent/stopByAgentId methods to PreviewManager - Auto-teardown: previews torn down on agent:stopped event - Conditional preview prompt injection for execute/refine/discuss agents - Agent-simplified CLI: cw preview start/stop --agent <id> - cw preview setup command with --auto mode for guided config generation - hasPreviewConfig hint on cw project register output - New tRPC procedures: startPreviewForAgent, stopPreviewByAgent
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
import { z } from 'zod';
|
||||
import type { ProcedureBuilder } from '../trpc.js';
|
||||
import { requirePreviewManager } from './_helpers.js';
|
||||
import { requirePreviewManager, requireAgentManager } from './_helpers.js';
|
||||
|
||||
export function previewProcedures(publicProcedure: ProcedureBuilder) {
|
||||
return {
|
||||
@@ -16,12 +16,29 @@ export function previewProcedures(publicProcedure: ProcedureBuilder) {
|
||||
branch: z.string().min(1),
|
||||
mode: z.enum(['preview', 'dev']).default('preview'),
|
||||
worktreePath: z.string().optional(),
|
||||
agentId: z.string().min(1).optional(),
|
||||
}))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const previewManager = requirePreviewManager(ctx);
|
||||
return previewManager.start(input);
|
||||
}),
|
||||
|
||||
startPreviewForAgent: publicProcedure
|
||||
.input(z.object({ agentId: z.string().min(1) }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const previewManager = requirePreviewManager(ctx);
|
||||
const agentManager = requireAgentManager(ctx);
|
||||
return previewManager.startForAgent(input.agentId, agentManager);
|
||||
}),
|
||||
|
||||
stopPreviewByAgent: publicProcedure
|
||||
.input(z.object({ agentId: z.string().min(1) }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const previewManager = requirePreviewManager(ctx);
|
||||
await previewManager.stopByAgentId(input.agentId);
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
stopPreview: publicProcedure
|
||||
.input(z.object({
|
||||
previewId: z.string().min(1),
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
import { join } from 'node:path';
|
||||
import { rm } from 'node:fs/promises';
|
||||
import { rm, access } from 'node:fs/promises';
|
||||
import type { ProcedureBuilder } from '../trpc.js';
|
||||
import { requireProjectRepository, requireProjectSyncManager } from './_helpers.js';
|
||||
import { cloneProject } from '../../git/clone.js';
|
||||
@@ -69,7 +69,17 @@ export function projectProcedures(publicProcedure: ProcedureBuilder) {
|
||||
}
|
||||
}
|
||||
|
||||
return project;
|
||||
// Check for preview config
|
||||
let hasPreviewConfig = false;
|
||||
if (ctx.workspaceRoot) {
|
||||
const clonePath = join(ctx.workspaceRoot, getProjectCloneDir(input.name, project.id));
|
||||
try {
|
||||
await access(join(clonePath, '.cw-preview.yml'));
|
||||
hasPreviewConfig = true;
|
||||
} catch { /* no config */ }
|
||||
}
|
||||
|
||||
return { ...project, hasPreviewConfig };
|
||||
}),
|
||||
|
||||
listProjects: publicProcedure
|
||||
|
||||
Reference in New Issue
Block a user