import type { ServiceContract } from '../ServiceContract';

export const IShellService: ServiceContract = {
  id: 'shell',
  description: 'Omega REPL sessions — persistent Lisp evaluation with effects',
  ops: {
    'shell.create-session': {
      description: 'Create a new shell session',
      payload: {
        sessionId: { type: 'string', required: false, description: 'Session ID (auto-generated if omitted)' },
        owner: { type: 'string', required: false, description: 'Session owner for isolation' },
        maxSteps: { type: 'number', required: false, description: 'CESK step budget' },
        subtreeRoot: { type: 'string', required: false, description: 'Restrict shell to subtree' },
        allowedEffects: { type: 'string[]', required: false, description: 'Effect whitelist' },
      },
      response: { ok: { type: 'boolean' }, sessionId: { type: 'string' }, status: { type: 'string' } },
    },
    'shell.evaluate': {
      description: 'Evaluate Lisp code in a session',
      payload: {
        sessionId: { type: 'string', required: true },
        code: { type: 'string', required: true, description: 'Lisp expression to evaluate' },
        owner: { type: 'string', required: false },
      },
      response: {
        ok: { type: 'boolean' },
        value: { type: 'object', description: 'Omega Val result' },
        display: { type: 'string', description: 'Human-readable result' },
        sessionId: { type: 'string' },
      },
    },
    'shell.destroy-session': {
      description: 'Destroy a shell session',
      payload: { sessionId: { type: 'string', required: true }, owner: { type: 'string', required: false } },
      response: { ok: { type: 'boolean' } },
    },
    'shell.list-sessions': {
      description: 'List active sessions',
      payload: { owner: { type: 'string', required: false } },
      response: { ok: { type: 'boolean' }, sessions: { type: 'object[]' } },
    },
    'shell.fork-session': {
      description: 'COW fork a session with capability attenuation',
      payload: {
        sourceSessionId: { type: 'string', required: true },
        newSessionId: { type: 'string', required: false },
        owner: { type: 'string', required: false },
        allowedEffects: { type: 'string[]', required: false },
      },
      response: { ok: { type: 'boolean' }, sessionId: { type: 'string' } },
    },
    'shell.get-session': {
      description: 'Get session metadata',
      payload: { sessionId: { type: 'string', required: true }, owner: { type: 'string', required: false } },
      response: { ok: { type: 'boolean' }, session: { type: 'object' } },
    },
  },
};
