Files
kandev/apps/backend/internal/utility/models/models.go
T
João Salavisa 01e4917df1 fix(utility): use claude-acp as default inference agent id (#1271)
* fix(utility): use claude-acp as default inference agent id

The utility-agent SQLite schema, frontend dialog defaults, and edit
fallback all pointed at the legacy "claude-code" identifier, but the
only registered Claude inference agent is "claude-acp" (since the ACP
migration in #566). Opening Settings > Utility Agents and picking
Claude resolved to an unknown agent id, so the Model dropdown rendered
"no model found" and the agent could not be configured.

Switch the defaults to "claude-acp" and migrate existing rows so
previously-seeded built-ins (which were saved with agent_id="" and
later coerced to "claude-code" by the dialog fallback) now populate
their model list correctly.

Closes #1269

* fix(utility): cover empty agent_id seeds and add migration test

Address PR review feedback on #1271:

- Extend the agent_id backfill migration to also rewrite rows seeded
  with an empty string. seedBuiltinAgents() inserts built-in rows with
  ON CONFLICT(id) DO NOTHING, so older deployments that landed
  agent_id="" never got repaired by re-seeding.
- Set AgentID = "claude-acp" explicitly in getBuiltinAgents() so future
  first-run seeds match the schema default without depending on the
  dialog fallback or the backfill migration.
- Add sqlite_migration_test.go covering both the legacy "claude-code"
  and empty-string backfill paths, plus a seed-contract assertion that
  every built-in row references "claude-acp" on first run.

* fix(utility): clarify migration comment and check rows.Err in test

Address PR review feedback (round 2) on #1271:

- Reword the agent_id backfill comment as a legacy-data backfill note
  and point at builtinSeedAgentID as the current seed path, so a future
  reader doesn't chase the old "seeds insert agent_id=''" behavior that
  this PR already fixed.
- Add rowsxDB.Err() check after the seed iteration loop, before the
  count guard, so a mid-scan error fails the test instead of silently
  shrinking the row count.

---------

Co-authored-by: Kandev Agent <agent@kandev.dev>
2026-06-04 03:16:39 +01:00

36 lines
1.8 KiB
Go

package models
import "time"
// UtilityAgent represents a configured utility agent for quick one-shot tasks.
// It references an inference-capable agent (like claude-acp, amp) by ID.
type UtilityAgent struct {
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Prompt string `json:"prompt" db:"prompt"`
AgentID string `json:"agent_id" db:"agent_id"` // Reference to inference agent (e.g., "claude-acp")
Model string `json:"model" db:"model"` // Model to use (e.g., "claude-haiku-4-5")
Builtin bool `json:"builtin" db:"builtin"` // Built-in agents cannot be deleted
Enabled bool `json:"enabled" db:"enabled"` // Whether agent is enabled
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
// UtilityAgentCall represents a single invocation of a utility agent.
type UtilityAgentCall struct {
ID string `json:"id" db:"id"`
UtilityID string `json:"utility_id" db:"utility_id"`
SessionID string `json:"session_id" db:"session_id"`
ResolvedPrompt string `json:"resolved_prompt" db:"resolved_prompt"`
Response string `json:"response" db:"response"`
Model string `json:"model" db:"model"`
PromptTokens int `json:"prompt_tokens" db:"prompt_tokens"`
ResponseTokens int `json:"response_tokens" db:"response_tokens"`
DurationMs int `json:"duration_ms" db:"duration_ms"`
Status string `json:"status" db:"status"` // "pending", "completed", "failed"
ErrorMessage string `json:"error_message" db:"error_message"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
CompletedAt *time.Time `json:"completed_at" db:"completed_at"`
}