Files
Codewalkers/apps/server/agent/schema.ts
Lukas May 34578d39c6 refactor: Restructure monorepo to apps/server/ and apps/web/ layout
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
2026-03-03 11:22:53 +01:00

98 lines
2.8 KiB
TypeScript

/**
* Agent Signal Schema
*
* Agents communicate via a trivial JSON signal: done, questions, or error.
* All structured output is file-based (see file-io.ts).
*/
import { z } from 'zod';
// =============================================================================
// SHARED SCHEMAS
// =============================================================================
const optionSchema = z.object({
label: z.string(),
description: z.string().optional(),
});
export const questionItemSchema = z.object({
id: z.string(),
question: z.string(),
options: z.array(optionSchema).optional(),
multiSelect: z.boolean().optional(),
});
export type QuestionItem = z.infer<typeof questionItemSchema>;
// =============================================================================
// UNIVERSAL SIGNAL SCHEMA
// =============================================================================
export const agentSignalSchema = z.discriminatedUnion('status', [
z.object({ status: z.literal('done') }),
z.object({ status: z.literal('questions'), questions: z.array(questionItemSchema) }),
z.object({ status: z.literal('error'), error: z.string() }),
]);
export type AgentSignal = z.infer<typeof agentSignalSchema>;
export const agentSignalJsonSchema = {
type: 'object',
oneOf: [
{
properties: {
status: { const: 'done' },
},
required: ['status'],
},
{
properties: {
status: { const: 'questions' },
questions: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'string' },
question: { type: 'string' },
options: {
type: 'array',
items: {
type: 'object',
properties: {
label: { type: 'string' },
description: { type: 'string' },
},
required: ['label'],
},
},
multiSelect: { type: 'boolean' },
},
required: ['id', 'question'],
},
},
},
required: ['status', 'questions'],
},
{
properties: {
status: { const: 'error' },
error: { type: 'string' },
},
required: ['status', 'error'],
},
],
};
// =============================================================================
// BACKWARD COMPATIBILITY
// =============================================================================
/** @deprecated Use agentSignalSchema */
export const agentOutputSchema = agentSignalSchema;
/** @deprecated Use AgentSignal */
export type AgentOutput = AgentSignal;
/** @deprecated Use agentSignalJsonSchema */
export const agentOutputJsonSchema = agentSignalJsonSchema;