Class: RubynCode::Teams::Manager
- Inherits:
-
Object
- Object
- RubynCode::Teams::Manager
- Defined in:
- lib/rubyn_code/teams/manager.rb
Overview
CRUD manager for teammates backed by SQLite.
Provides lifecycle management for agent teammates: spawning, listing, status updates, and removal.
Instance Method Summary collapse
-
#active_teammates ⇒ Array<Teammate>
Returns all teammates with status “active”.
-
#get(name) ⇒ Teammate?
Finds a teammate by name.
-
#initialize(db, mailbox:) ⇒ Manager
constructor
A new instance of Manager.
-
#list ⇒ Array<Teammate>
Returns all teammates.
-
#remove(name) ⇒ void
Removes a teammate by name.
-
#spawn(name:, role:, persona: nil, model: nil) ⇒ Teammate
Creates a new teammate record.
-
#update_status(name, status) ⇒ void
Updates a teammate’s status.
Constructor Details
#initialize(db, mailbox:) ⇒ Manager
Returns a new instance of Manager.
16 17 18 19 20 |
# File 'lib/rubyn_code/teams/manager.rb', line 16 def initialize(db, mailbox:) @db = db @mailbox = mailbox ensure_table! end |
Instance Method Details
#active_teammates ⇒ Array<Teammate>
Returns all teammates with status “active”.
113 114 115 116 117 118 119 |
# File 'lib/rubyn_code/teams/manager.rb', line 113 def active_teammates rows = @db.query( 'SELECT * FROM teammates WHERE status = ? ORDER BY created_at ASC', ['active'] ).to_a rows.map { |row| row_to_teammate(row) } end |
#get(name) ⇒ Teammate?
Finds a teammate by name.
70 71 72 73 74 75 |
# File 'lib/rubyn_code/teams/manager.rb', line 70 def get(name) rows = @db.query('SELECT * FROM teammates WHERE name = ? LIMIT 1', [name]).to_a return nil if rows.empty? row_to_teammate(rows.first) end |
#list ⇒ Array<Teammate>
Returns all teammates.
61 62 63 64 |
# File 'lib/rubyn_code/teams/manager.rb', line 61 def list rows = @db.query('SELECT * FROM teammates ORDER BY created_at ASC').to_a rows.map { |row| row_to_teammate(row) } end |
#remove(name) ⇒ void
This method returns an undefined value.
Removes a teammate by name.
103 104 105 106 107 108 |
# File 'lib/rubyn_code/teams/manager.rb', line 103 def remove(name) teammate = get(name) raise Error, "Teammate '#{name}' not found" unless teammate @db.execute('DELETE FROM teammates WHERE name = ?', [name]) end |
#spawn(name:, role:, persona: nil, model: nil) ⇒ Teammate
Creates a new teammate record.
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 |
# File 'lib/rubyn_code/teams/manager.rb', line 30 def spawn(name:, role:, persona: nil, model: nil) existing = get(name) raise Error, "Teammate '#{name}' already exists" if existing id = SecureRandom.uuid now = Time.now.utc.iso8601 = JSON.generate({}) @db.execute( <<~SQL, INSERT INTO teammates (id, name, role, persona, model, status, metadata, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) SQL [id, name, role, persona, model, 'idle', , now] ) Teammate.new( id: id, name: name, role: role, persona: persona, model: model, status: 'idle', metadata: {}, created_at: now ) end |
#update_status(name, status) ⇒ void
This method returns an undefined value.
Updates a teammate’s status.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rubyn_code/teams/manager.rb', line 84 def update_status(name, status) unless VALID_STATUSES.include?(status) raise ArgumentError, "Invalid status '#{status}'. Must be one of: #{VALID_STATUSES.join(', ')}" end teammate = get(name) raise Error, "Teammate '#{name}' not found" unless teammate @db.execute( 'UPDATE teammates SET status = ? WHERE name = ?', [status, name] ) end |