File size: 2,539 Bytes
391c43e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
 * Agent System - Defines different agent types and their capabilities
 */

export type AgentType = 'orchestrator' | 'explore' | 'task' | 'plan' | 'setup' | 'interview';

interface AgentConfig {
  type: AgentType;
  tools: string[]; // Tool IDs from registry
  maxIterations: number;
  isReadOnly?: boolean; // If true, only allow read operations
  writeScope?: string; // If set, writes are restricted to this directory prefix (reads unrestricted)
}

/**
 * Agent class - Represents a specialized AI agent with specific capabilities
 */
export class Agent {
  public readonly type: AgentType;
  public readonly tools: string[];
  public readonly maxIterations: number;
  public readonly isReadOnly: boolean;
  public readonly writeScope?: string;

  constructor(config: AgentConfig) {
    this.type = config.type;
    this.tools = config.tools;
    this.maxIterations = config.maxIterations;
    this.isReadOnly = config.isReadOnly ?? false;
    this.writeScope = config.writeScope;
  }

  /**
   * Check if this agent has access to a specific tool
   */
  hasTool(toolId: string): boolean {
    return this.tools.includes(toolId);
  }
}

/**
 * Agent Registry - Manages available agent types
 */
export class AgentRegistry {
  private agents: Map<AgentType, Agent> = new Map();

  constructor() {
    this.registerBuiltInAgents();
  }

  /**
   * Register all built-in agent types
   */
  private registerBuiltInAgents(): void {
    this.register(new Agent({
      type: 'orchestrator',
      tools: ['bash'],
      maxIterations: 100
    }));

    this.register(new Agent({
      type: 'explore',
      tools: ['bash'],
      maxIterations: 5,
      isReadOnly: true
    }));

    this.register(new Agent({
      type: 'task',
      tools: ['bash'],
      maxIterations: 30
    }));

    this.register(new Agent({
      type: 'plan',
      tools: ['bash'],
      maxIterations: 10,
      isReadOnly: true
    }));

    this.register(new Agent({
      type: 'setup',
      tools: ['bash'],
      maxIterations: 20
    }));

    // Interview agent: reads the project freely, writes only into /.interviews/
    // (enforced by writeScope).
    this.register(new Agent({
      type: 'interview',
      tools: ['bash'],
      maxIterations: 30,
      writeScope: '/.interviews/',
    }));
  }

  private register(agent: Agent): void {
    this.agents.set(agent.type, agent);
  }

  get(type: AgentType): Agent | undefined {
    return this.agents.get(type);
  }
}

// Singleton instance
export const agentRegistry = new AgentRegistry();