import type { ReflectionResult } from './types.js';

// JSON Schema in the OpenAI tools format.
export const REFLECTION_TOOL_SCHEMA = {
  type: 'function',
  function: {
    name: 'submit_reflection',
    description: 'Submit zero or more durable lessons learned from the job that just finished.',
    parameters: {
      type: 'object',
      additionalProperties: false,
      required: ['memory_changes', 'piece_changes', 'reasoning'],
      properties: {
        memory_changes: {
          type: 'array',
          maxItems: 3,
          items: {
            type: 'object',
            additionalProperties: false,
            required: ['op', 'name', 'type', 'description', 'body'],
            properties: {
              op: { type: 'string', enum: ['add', 'update', 'merge_into', 'remove'] },
              name: { type: 'string', minLength: 1, maxLength: 96 },
              type: { type: 'string', enum: ['user', 'feedback', 'project', 'reference'] },
              description: { type: 'string', maxLength: 240 },
              body: { type: 'string', maxLength: 16384 }, // hard ceiling; semantic validator narrows
              merge_target: { type: 'string', maxLength: 96 },
            },
          },
        },
        piece_changes: {
          type: 'object',
          additionalProperties: false,
          required: ['should_edit'],
          properties: {
            should_edit: { type: 'boolean' },
            target_piece: { type: 'string' },
            diff_summary: { type: 'string', maxLength: 240 },
            new_yaml: { type: ['string', 'null'] },
          },
        },
        reasoning: { type: 'string', maxLength: 2000 },
        abstain_reason: { type: 'string', maxLength: 500 },
      },
    },
  },
} as const;
