01e4917df1
* 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>
67 lines
2.7 KiB
Go
67 lines
2.7 KiB
Go
package store
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
utilcfg "github.com/kandev/kandev/config/utilityagents"
|
|
"github.com/kandev/kandev/internal/utility/models"
|
|
)
|
|
|
|
// seedBuiltinAgents inserts the default built-in utility agents on first run.
|
|
// Existing agents are not overwritten, so user customizations are preserved.
|
|
func (r *sqliteRepository) seedBuiltinAgents() error {
|
|
for _, agent := range getBuiltinAgents() {
|
|
_, err := r.db.Exec(r.db.Rebind(`
|
|
INSERT INTO utility_agents (id, name, description, prompt, agent_id, model, builtin, enabled, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, 1, 0, ?, ?)
|
|
ON CONFLICT(id) DO NOTHING
|
|
`), agent.ID, agent.Name, agent.Description, agent.Prompt, agent.AgentID, agent.Model,
|
|
agent.CreatedAt, agent.UpdatedAt)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to upsert built-in agent %s: %w", agent.ID, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// builtinDef is a compact definition for a built-in utility agent.
|
|
type builtinDef struct {
|
|
id, name, description, promptFile string
|
|
}
|
|
|
|
var builtinDefs = []builtinDef{
|
|
{"builtin-commit-message", "commit-message", "Generate a commit message based on staged changes", "commit-message"},
|
|
{"builtin-commit-description", "commit-description", "Generate a detailed commit description explaining the changes", "commit-description"},
|
|
{"builtin-branch-name", "branch-name", "Generate a branch name based on task description", "branch-name"},
|
|
{"builtin-pr-title", "pr-title", "Generate a PR title based on commits and changes", "pr-title"},
|
|
{"builtin-pr-description", "pr-description", "Generate a PR description based on commits and changes", "pr-description"},
|
|
{"builtin-enhance-prompt", "enhance-prompt", "Enhance and expand a user prompt with context and clarity", "enhance-prompt"},
|
|
{"builtin-summarize-session", "summarize-session", "Summarize a session conversation for context handover", "summarize-session"},
|
|
}
|
|
|
|
// builtinSeedAgentID is the inference-agent ID embedded in seeded built-in
|
|
// rows. Kept aligned with the schema DEFAULT so a row that survives every
|
|
// migration path still maps to a registered inference agent.
|
|
const builtinSeedAgentID = "claude-acp"
|
|
|
|
// getBuiltinAgents returns the predefined built-in utility agents with prompts from embedded files.
|
|
func getBuiltinAgents() []*models.UtilityAgent {
|
|
now := time.Now().UTC()
|
|
agents := make([]*models.UtilityAgent, 0, len(builtinDefs))
|
|
for _, d := range builtinDefs {
|
|
agents = append(agents, &models.UtilityAgent{
|
|
ID: d.id,
|
|
Name: d.name,
|
|
Description: d.description,
|
|
Prompt: utilcfg.Get(d.promptFile),
|
|
AgentID: builtinSeedAgentID,
|
|
Builtin: true,
|
|
Enabled: false,
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
})
|
|
}
|
|
return agents
|
|
}
|