feat: add bd slot commands for agent bead slot management (gt-h5sza)
Add slot management commands: - bd slot set <agent> <slot> <bead> - set slot (error if occupied) - bd slot clear <agent> <slot> - clear slot - bd slot show <agent> - show all slots These enforce cardinality constraints for agent bead slots. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,6 +46,7 @@ var migrationsList = []Migration{
|
||||
{"gate_columns", migrations.MigrateGateColumns},
|
||||
{"tombstone_closed_at", migrations.MigrateTombstoneClosedAt},
|
||||
{"created_by_column", migrations.MigrateCreatedByColumn},
|
||||
{"agent_fields", migrations.MigrateAgentFields},
|
||||
}
|
||||
|
||||
// MigrationInfo contains metadata about a migration for inspection
|
||||
|
||||
53
internal/storage/sqlite/migrations/030_agent_fields.go
Normal file
53
internal/storage/sqlite/migrations/030_agent_fields.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// MigrateAgentFields adds agent-specific fields to the issues table.
|
||||
// These fields support the agent-as-bead pattern (gt-v2gkv, gt-h5sza):
|
||||
// - hook_bead: current work attached to agent's hook (0..1 cardinality)
|
||||
// - role_bead: reference to role definition bead
|
||||
// - agent_state: agent-reported state (idle|running|stuck|stopped)
|
||||
// - last_activity: timestamp for timeout detection
|
||||
// - role_type: agent role (polecat|crew|witness|refinery|mayor|deacon)
|
||||
// - rig: rig name (empty for town-level agents)
|
||||
func MigrateAgentFields(db *sql.DB) error {
|
||||
columns := []struct {
|
||||
name string
|
||||
sqlType string
|
||||
}{
|
||||
{"hook_bead", "TEXT DEFAULT ''"},
|
||||
{"role_bead", "TEXT DEFAULT ''"},
|
||||
{"agent_state", "TEXT DEFAULT ''"},
|
||||
{"last_activity", "DATETIME"},
|
||||
{"role_type", "TEXT DEFAULT ''"},
|
||||
{"rig", "TEXT DEFAULT ''"},
|
||||
}
|
||||
|
||||
for _, col := range columns {
|
||||
// Check if column already exists
|
||||
var columnExists bool
|
||||
err := db.QueryRow(`
|
||||
SELECT COUNT(*) > 0
|
||||
FROM pragma_table_info('issues')
|
||||
WHERE name = ?
|
||||
`, col.name).Scan(&columnExists)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check %s column: %w", col.name, err)
|
||||
}
|
||||
|
||||
if columnExists {
|
||||
continue
|
||||
}
|
||||
|
||||
// Add the column
|
||||
_, err = db.Exec(fmt.Sprintf(`ALTER TABLE issues ADD COLUMN %s %s`, col.name, col.sqlType))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add %s column: %w", col.name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -272,6 +272,13 @@ func (s *SQLiteStorage) GetIssue(ctx context.Context, id string) (*types.Issue,
|
||||
var awaitID sql.NullString
|
||||
var timeoutNs sql.NullInt64
|
||||
var waiters sql.NullString
|
||||
// Agent fields (gt-h5sza)
|
||||
var hookBead sql.NullString
|
||||
var roleBead sql.NullString
|
||||
var agentState sql.NullString
|
||||
var lastActivity sql.NullTime
|
||||
var roleType sql.NullString
|
||||
var rig sql.NullString
|
||||
|
||||
var contentHash sql.NullString
|
||||
var compactedAtCommit sql.NullString
|
||||
@@ -282,7 +289,8 @@ func (s *SQLiteStorage) GetIssue(ctx context.Context, id string) (*types.Issue,
|
||||
compaction_level, compacted_at, compacted_at_commit, original_size, source_repo, close_reason,
|
||||
deleted_at, deleted_by, delete_reason, original_type,
|
||||
sender, ephemeral, pinned, is_template,
|
||||
await_type, await_id, timeout_ns, waiters
|
||||
await_type, await_id, timeout_ns, waiters,
|
||||
hook_bead, role_bead, agent_state, last_activity, role_type, rig
|
||||
FROM issues
|
||||
WHERE id = ?
|
||||
`, id).Scan(
|
||||
@@ -294,6 +302,7 @@ func (s *SQLiteStorage) GetIssue(ctx context.Context, id string) (*types.Issue,
|
||||
&deletedAt, &deletedBy, &deleteReason, &originalType,
|
||||
&sender, &wisp, &pinned, &isTemplate,
|
||||
&awaitType, &awaitID, &timeoutNs, &waiters,
|
||||
&hookBead, &roleBead, &agentState, &lastActivity, &roleType, &rig,
|
||||
)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -372,6 +381,25 @@ func (s *SQLiteStorage) GetIssue(ctx context.Context, id string) (*types.Issue,
|
||||
if waiters.Valid && waiters.String != "" {
|
||||
issue.Waiters = parseJSONStringArray(waiters.String)
|
||||
}
|
||||
// Agent fields (gt-h5sza)
|
||||
if hookBead.Valid {
|
||||
issue.HookBead = hookBead.String
|
||||
}
|
||||
if roleBead.Valid {
|
||||
issue.RoleBead = roleBead.String
|
||||
}
|
||||
if agentState.Valid {
|
||||
issue.AgentState = types.AgentState(agentState.String)
|
||||
}
|
||||
if lastActivity.Valid {
|
||||
issue.LastActivity = &lastActivity.Time
|
||||
}
|
||||
if roleType.Valid {
|
||||
issue.RoleType = roleType.String
|
||||
}
|
||||
if rig.Valid {
|
||||
issue.Rig = rig.String
|
||||
}
|
||||
|
||||
// Fetch labels for this issue
|
||||
labels, err := s.GetLabels(ctx, issue.ID)
|
||||
@@ -617,6 +645,13 @@ var allowedUpdateFields = map[string]bool{
|
||||
"pinned": true,
|
||||
// NOTE: replies_to, relates_to, duplicate_of, superseded_by removed per Decision 004
|
||||
// Use AddDependency() to create graph edges instead
|
||||
// Agent slot fields (gt-h5sza)
|
||||
"hook_bead": true,
|
||||
"role_bead": true,
|
||||
"agent_state": true,
|
||||
"last_activity": true,
|
||||
"role_type": true,
|
||||
"rig": true,
|
||||
}
|
||||
|
||||
// validatePriority validates a priority value
|
||||
|
||||
Reference in New Issue
Block a user