feat: add personal skill storage, API, and SDK (#25363)

> Mux updated this PR on behalf of Mike.

## Stack Context

This PR is the storage, permissions, API, and SDK layer for experimental
personal skills. #25362 has landed on `main`, so this branch is
restacked directly on `main`.

Stack order:
1. #25363 storage, permissions, API, and SDK
2. #25365 API test coverage
3. #25366 chattool and chatd integration
4. #25066 settings UI and docs
5. #25386 personal skills slash menu

## What?

Adds the `user_skills` database table, generated queries, RBAC resources
and scopes, audit resource handling, experimental user-scoped CRUD
endpoints, SDK types, and generated API/site types.

Follow-up review and restack fixes:
- Enforce a bounded personal skill description in parser and database
constraints.
- Return `403 Forbidden` for unauthorized create and update attempts.
- Return explicit conflict responses when soft-deleted users are
targeted.
- Keep user admins out of personal skills, while site owners can read
and delete but not create or update.
- Document trigger-raised constraint names and keep schema constants
covered by tests.
- Reuse `UserSkillMetadata` in the full `UserSkill` SDK response type.
- Generate user skill IDs in Go instead of relying on a database
default.
- Rebase on latest `main` and renumber the user skills migration to
`000502_user_skills`.

## Why?

Personal skills need durable user-owned storage with owner
authorization, limited site-owner moderation, and a hidden API surface
before chatd can consume them.

## Validation

- `make gen`
- `go test ./coderd/database -run '^TestUserSkillSchemaConstants$'
-count=1`
- `go test ./coderd/database/dbauthz -run
'^TestMethodTestSuite/TestUserSkills$' -count=1`
- `go test ./coderd -run '^TestPatchUserSkill$' -count=1`
- `go test ./codersdk ./coderd/database/db2sdk`
- `make lint`
- pre-commit hook on `97fd58108d`
This commit is contained in:
Michael Suchacz
2026-05-20 00:09:09 +02:00
committed by GitHub
parent 3c9c8c708d
commit 5a8d0016a5
46 changed files with 2315 additions and 70 deletions
+2 -1
View File
@@ -38,7 +38,8 @@ type Auditable interface {
database.AIProviderKey |
database.Chat |
database.AuditableGroupAiBudget |
database.UserSecret
database.UserSecret |
database.UserSkill
}
// Map is a map of changed fields in an audited resource. It maps field names to
+9
View File
@@ -153,6 +153,8 @@ func ResourceTarget[T Auditable](tgt T) string {
return typed.ID.String()[:8]
case database.UserSecret:
return typed.Name
case database.UserSkill:
return typed.Name
default:
panic(fmt.Sprintf("unknown resource %T for ResourceTarget", tgt))
}
@@ -229,6 +231,8 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
return typed.ID
case database.UserSecret:
return typed.ID
case database.UserSkill:
return typed.ID
default:
panic(fmt.Sprintf("unknown resource %T for ResourceID", tgt))
}
@@ -296,6 +300,8 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
return database.ResourceTypeChat
case database.UserSecret:
return database.ResourceTypeUserSecret
case database.UserSkill:
return database.ResourceTypeUserSkill
default:
panic(fmt.Sprintf("unknown resource %T for ResourceType", typed))
}
@@ -372,6 +378,9 @@ func ResourceRequiresOrgID[T Auditable]() bool {
case database.UserSecret:
// User secrets are global to the user across organizations.
return false
case database.UserSkill:
// User skills are global to the user across organizations.
return false
default:
panic(fmt.Sprintf("unknown resource %T for ResourceRequiresOrgID", tgt))
}