From c4d76a4009eb07dcc0bcfd4ce43d06952c0729bb Mon Sep 17 00:00:00 2001 From: Jaayden Halko Date: Fri, 23 Oct 2026 20:32:08 +0800 Subject: [PATCH] feat: add skill action and automatic-use settings (#30882) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds two per-skill settings that the project skills UI will expose next: - `action` marks a project skill to show as an action button above project chat composers. A `skills_action_project_only` check keeps it to project skills; the personal and organization routes reject `action` with 400. - `model_invocable` (default true, every stored source) controls automatic use. When it's false the skill is left out of `` and `read_skill` reports it as not found, but a structured skill invocation (a chip from the `/` menu or an action) still loads it, as long as the skill is enabled and the chat owner can read it. Workspace skills always count as model-invocable. Migration 000625 adds both columns with defaults, so existing skills keep today's behavior. The list, get, insert and update queries, `codersdk.SkillMetadata` and the create/update requests carry both fields, and the audit table tracks them. `coderd/x/chatd/ARCHITECTURE.md` gets TODO notes for the author. **NOTE**: the migration adds two columns with constant defaults and a CHECK constraint to `skills`. Stack (merge top to bottom): - #30826 - #30827 - #30838 - #30840 - #30854 - #30855 - #30856 - #30861 - #30880 - #30881 - #30882 👈 - #30884 - #31122 - #31126 --------- Co-authored-by: Cursor Co-authored-by: Nick Vigilante --- Makefile | 1 + coderd/apidoc/docs.go | 31 +++ coderd/apidoc/swagger.json | 31 +++ coderd/chat_project_skills.go | 28 +-- coderd/chat_project_skills_test.go | 19 +- coderd/database/check_constraint.go | 1 + coderd/database/db2sdk/db2sdk.go | 56 ++--- coderd/database/dbgen/dbgen.go | 3 +- coderd/database/dump.sql | 3 + ...0633_skill_action_model_invocable.down.sql | 4 + ...000633_skill_action_model_invocable.up.sql | 7 + coderd/database/modelqueries.go | 2 + coderd/database/models.go | 2 + coderd/database/queries.sql.go | 198 ++++++++++++------ coderd/database/queries/skills.sql | 22 +- coderd/database/user_skills_test.go | 18 +- coderd/organizationskills.go | 8 +- coderd/userskills.go | 109 +++++++--- coderd/userskills_test.go | 30 +++ coderd/x/chatd/ARCHITECTURE.md | 2 - coderd/x/chatd/chatd_internal_test.go | 63 +++--- coderd/x/chatd/organization_skills_test.go | 46 ++-- coderd/x/chatd/project_skills_test.go | 21 +- coderd/x/chatd/skill_invocation.go | 9 +- .../x/chatd/skill_invocation_internal_test.go | 14 +- coderd/x/chatd/turn_environment.go | 47 +++-- codersdk/skills.go | 19 +- docs/admin/security/audit-logs.md | 6 + docs/reference/api/schemas.md | 68 +++--- enterprise/audit/table.go | 6 + .../api/queries/organizationSkills.test.ts | 2 + site/src/api/queries/userSkills.test.ts | 4 + site/src/api/typesGenerated.ts | 25 +++ .../AgentChatPage/AgentChatPage.stories.tsx | 2 + .../src/pages/AgentsPage/utils/skills.test.ts | 2 + site/src/testHelpers/skills.ts | 2 + 36 files changed, 666 insertions(+), 245 deletions(-) create mode 100644 coderd/database/migrations/000633_skill_action_model_invocable.down.sql create mode 100644 coderd/database/migrations/000633_skill_action_model_invocable.up.sql diff --git a/Makefile b/Makefile index cabddca1a15..778b0f64c94 100644 --- a/Makefile +++ b/Makefile @@ -1489,6 +1489,7 @@ docs/reference/api-key-scopes.md: node_modules/.installed $(wildcard scripts/sco coderd/apidoc/.gen: \ node_modules/.installed \ + site/node_modules/.installed \ scripts/apidocgen/node_modules/.installed \ site/node_modules/.installed \ $(wildcard coderd/*.go) \ diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index 3d7731e3746..031adc5a303 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -24461,9 +24461,17 @@ const docTemplate = `{ "codersdk.CreateSkillRequest": { "type": "object", "properties": { + "action": { + "description": "Action is only accepted for project skills and defaults to false.", + "type": "boolean" + }, "content": { "description": "Content must be SKILL.md-format Markdown with YAML frontmatter. The\nfrontmatter must include name, may include description, and must be\nfollowed by a non-empty body.", "type": "string" + }, + "model_invocable": { + "description": "ModelInvocable defaults to true.", + "type": "boolean" } } }, @@ -30828,6 +30836,10 @@ const docTemplate = `{ "codersdk.Skill": { "type": "object", "properties": { + "action": { + "description": "Action reports whether a project skill is offered as a one-click\naction above project composers. It is always false for personal and\norganization skills.", + "type": "boolean" + }, "content": { "type": "string" }, @@ -30845,6 +30857,10 @@ const docTemplate = `{ "type": "string", "format": "uuid" }, + "model_invocable": { + "description": "ModelInvocable reports whether agents can discover and load the skill\non their own. Users can still invoke a skill explicitly when it is\nfalse.", + "type": "boolean" + }, "name": { "type": "string" }, @@ -30857,6 +30873,10 @@ const docTemplate = `{ "codersdk.SkillMetadata": { "type": "object", "properties": { + "action": { + "description": "Action reports whether a project skill is offered as a one-click\naction above project composers. It is always false for personal and\norganization skills.", + "type": "boolean" + }, "created_at": { "type": "string", "format": "date-time" @@ -30871,6 +30891,10 @@ const docTemplate = `{ "type": "string", "format": "uuid" }, + "model_invocable": { + "description": "ModelInvocable reports whether agents can discover and load the skill\non their own. Users can still invoke a skill explicitly when it is\nfalse.", + "type": "boolean" + }, "name": { "type": "string" }, @@ -32736,12 +32760,19 @@ const docTemplate = `{ "codersdk.UpdateSkillRequest": { "type": "object", "properties": { + "action": { + "description": "Action is only accepted for project skills.", + "type": "boolean" + }, "content": { "description": "Content must be SKILL.md-format Markdown with YAML frontmatter. The\nfrontmatter must include name, may include description, and must be\nfollowed by a non-empty body.", "type": "string" }, "enabled": { "type": "boolean" + }, + "model_invocable": { + "type": "boolean" } } }, diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index 968c5d54393..979efb36dd5 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -22232,9 +22232,17 @@ "codersdk.CreateSkillRequest": { "type": "object", "properties": { + "action": { + "description": "Action is only accepted for project skills and defaults to false.", + "type": "boolean" + }, "content": { "description": "Content must be SKILL.md-format Markdown with YAML frontmatter. The\nfrontmatter must include name, may include description, and must be\nfollowed by a non-empty body.", "type": "string" + }, + "model_invocable": { + "description": "ModelInvocable defaults to true.", + "type": "boolean" } } }, @@ -28356,6 +28364,10 @@ "codersdk.Skill": { "type": "object", "properties": { + "action": { + "description": "Action reports whether a project skill is offered as a one-click\naction above project composers. It is always false for personal and\norganization skills.", + "type": "boolean" + }, "content": { "type": "string" }, @@ -28373,6 +28385,10 @@ "type": "string", "format": "uuid" }, + "model_invocable": { + "description": "ModelInvocable reports whether agents can discover and load the skill\non their own. Users can still invoke a skill explicitly when it is\nfalse.", + "type": "boolean" + }, "name": { "type": "string" }, @@ -28385,6 +28401,10 @@ "codersdk.SkillMetadata": { "type": "object", "properties": { + "action": { + "description": "Action reports whether a project skill is offered as a one-click\naction above project composers. It is always false for personal and\norganization skills.", + "type": "boolean" + }, "created_at": { "type": "string", "format": "date-time" @@ -28399,6 +28419,10 @@ "type": "string", "format": "uuid" }, + "model_invocable": { + "description": "ModelInvocable reports whether agents can discover and load the skill\non their own. Users can still invoke a skill explicitly when it is\nfalse.", + "type": "boolean" + }, "name": { "type": "string" }, @@ -30182,12 +30206,19 @@ "codersdk.UpdateSkillRequest": { "type": "object", "properties": { + "action": { + "description": "Action is only accepted for project skills.", + "type": "boolean" + }, "content": { "description": "Content must be SKILL.md-format Markdown with YAML frontmatter. The\nfrontmatter must include name, may include description, and must be\nfollowed by a non-empty body.", "type": "string" }, "enabled": { "type": "boolean" + }, + "model_invocable": { + "type": "boolean" } } }, diff --git a/coderd/chat_project_skills.go b/coderd/chat_project_skills.go index 580354a4465..86a49fbe987 100644 --- a/coderd/chat_project_skills.go +++ b/coderd/chat_project_skills.go @@ -77,13 +77,15 @@ func (api *API) postChatProjectSkill(rw http.ResponseWriter, r *http.Request) { } defer commitAudit() - skill, ok := createSkill(ctx, rw, r, chatProjectSkillCreateErrors, func(parsed skills.ParsedSkill, content string) (database.Skill, error) { + skill, ok := createSkill(ctx, rw, r, chatProjectSkillCreateErrors, skillOwnerProject, func(parsed skills.ParsedSkill, create skillCreate) (database.Skill, error) { return api.Database.InsertProjectSkill(ctx, database.InsertProjectSkillParams{ - ID: uuid.New(), - ProjectID: project.ID, - Name: parsed.Name, - Description: parsed.Description, - Content: content, + ID: uuid.New(), + ProjectID: project.ID, + Name: parsed.Name, + Description: parsed.Description, + Content: create.Content, + Action: create.Action, + ModelInvocable: create.ModelInvocable, }) }) if !ok { @@ -150,7 +152,7 @@ func (api *API) patchChatProjectSkill(rw http.ResponseWriter, r *http.Request) { } defer commitAudit() - oldSkill, skill, ok := api.updateSkill(ctx, rw, r, name, skillWriteErrors{}, func(tx database.Store, update skillUpdate) (database.Skill, database.Skill, error) { + oldSkill, skill, ok := api.updateSkill(ctx, rw, r, name, skillWriteErrors{}, skillOwnerProject, func(tx database.Store, update skillUpdate) (database.Skill, database.Skill, error) { // Update on the project was checked above and the update below // rechecks it, so reads use a system context for update-only roles. //nolint:gocritic // See above. @@ -168,11 +170,13 @@ func (api *API) patchChatProjectSkill(rw http.ResponseWriter, r *http.Request) { return database.Skill{}, database.Skill{}, xerrors.Errorf("lock project skill: %w", err) } updated, err := tx.UpdateProjectSkillByProjectIDAndName(ctx, database.UpdateProjectSkillByProjectIDAndNameParams{ - Description: update.Description, - Content: update.Content, - Enabled: update.Enabled, - ProjectID: project.ID, - Name: locked.Name, + Description: update.Description, + Content: update.Content, + Enabled: update.Enabled, + Action: update.Action, + ModelInvocable: update.ModelInvocable, + ProjectID: project.ID, + Name: locked.Name, }) if err != nil { return database.Skill{}, database.Skill{}, xerrors.Errorf("update project skill: %w", err) diff --git a/coderd/chat_project_skills_test.go b/coderd/chat_project_skills_test.go index 101cd805737..0f13f7dcfd8 100644 --- a/coderd/chat_project_skills_test.go +++ b/coderd/chat_project_skills_test.go @@ -25,9 +25,15 @@ func TestChatProjectSkills(t *testing.T) { member := codersdk.NewExperimentalClient(memberRaw) content := userSkillMarkdown("deploy", "Deploy the app", "Run make deploy.") - created, err := client.CreateChatProjectSkill(ctx, orgID, project.ID, codersdk.CreateSkillRequest{Content: content}) + created, err := client.CreateChatProjectSkill(ctx, orgID, project.ID, codersdk.CreateSkillRequest{ + Content: content, + Action: ptr.Ref(true), + ModelInvocable: ptr.Ref(false), + }) require.NoError(t, err) require.Equal(t, "Deploy the app", created.Description) + require.True(t, created.Action) + require.False(t, created.ModelInvocable) list, err := client.ChatProjectSkills(ctx, orgID, project.ID) require.NoError(t, err) require.Equal(t, []codersdk.SkillMetadata{created.SkillMetadata}, list) @@ -39,6 +45,17 @@ func TestChatProjectSkills(t *testing.T) { require.NoError(t, err) require.Equal(t, "Ship the app", updated.Description) require.False(t, updated.Enabled) + // Omitted settings keep their values, and set ones flip independently. + require.True(t, updated.Action) + require.False(t, updated.ModelInvocable) + updated, err = client.UpdateChatProjectSkill(ctx, orgID, project.ID, "deploy", codersdk.UpdateSkillRequest{ + Action: ptr.Ref(false), + ModelInvocable: ptr.Ref(true), + }) + require.NoError(t, err) + require.False(t, updated.Action) + require.True(t, updated.ModelInvocable) + require.Equal(t, "Ship the app", updated.Description) _, err = client.CreateChatProjectSkill(ctx, orgID, project.ID, codersdk.CreateSkillRequest{Content: content}) requireSDKErrorStatus(t, err, http.StatusConflict) diff --git a/coderd/database/check_constraint.go b/coderd/database/check_constraint.go index 14ffbbfc8d4..d22202341d2 100644 --- a/coderd/database/check_constraint.go +++ b/coderd/database/check_constraint.go @@ -74,6 +74,7 @@ const ( CheckMaxProvisionerLogsLength CheckConstraint = "max_provisioner_logs_length" // provisioner_jobs CheckNatsPortValidTcp CheckConstraint = "nats_port_valid_tcp" // replicas CheckSkillsAclOnlyOnOrganizationSkills CheckConstraint = "skills_acl_only_on_organization_skills" // skills + CheckSkillsActionProjectOnly CheckConstraint = "skills_action_project_only" // skills CheckSkillsContentSize CheckConstraint = "skills_content_size" // skills CheckSkillsDescriptionSize CheckConstraint = "skills_description_size" // skills CheckSkillsGroupAclIsObject CheckConstraint = "skills_group_acl_is_object" // skills diff --git a/coderd/database/db2sdk/db2sdk.go b/coderd/database/db2sdk/db2sdk.go index 3c3276d18a8..1cbc3c70c53 100644 --- a/coderd/database/db2sdk/db2sdk.go +++ b/coderd/database/db2sdk/db2sdk.go @@ -2468,12 +2468,14 @@ func WorkspaceBuildSecret(secret database.GetWorkspaceSecretsHistoryRow) codersd func Skill(skill database.Skill) codersdk.Skill { return codersdk.Skill{ SkillMetadata: codersdk.SkillMetadata{ - ID: skill.ID, - Name: skill.Name, - Description: skill.Description, - Enabled: skill.Enabled, - CreatedAt: skill.CreatedAt, - UpdatedAt: skill.UpdatedAt, + ID: skill.ID, + Name: skill.Name, + Description: skill.Description, + Enabled: skill.Enabled, + Action: skill.Action, + ModelInvocable: skill.ModelInvocable, + CreatedAt: skill.CreatedAt, + UpdatedAt: skill.UpdatedAt, }, Content: skill.Content, } @@ -2485,12 +2487,14 @@ func ProjectSkillMetadataList(rows []database.ListProjectSkillMetadataByProjectI metadata := make([]codersdk.SkillMetadata, 0, len(rows)) for _, row := range rows { metadata = append(metadata, codersdk.SkillMetadata{ - ID: row.ID, - Name: row.Name, - Description: row.Description, - Enabled: row.Enabled, - CreatedAt: row.CreatedAt, - UpdatedAt: row.UpdatedAt, + ID: row.ID, + Name: row.Name, + Description: row.Description, + Enabled: row.Enabled, + Action: row.Action, + ModelInvocable: row.ModelInvocable, + CreatedAt: row.CreatedAt, + UpdatedAt: row.UpdatedAt, }) } return metadata @@ -2502,12 +2506,14 @@ func OrganizationSkillMetadataList(rows []database.ListOrganizationSkillMetadata metadata := make([]codersdk.SkillMetadata, 0, len(rows)) for _, row := range rows { metadata = append(metadata, codersdk.SkillMetadata{ - ID: row.ID, - Name: row.Name, - Description: row.Description, - Enabled: row.Enabled, - CreatedAt: row.CreatedAt, - UpdatedAt: row.UpdatedAt, + ID: row.ID, + Name: row.Name, + Description: row.Description, + Enabled: row.Enabled, + Action: row.Action, + ModelInvocable: row.ModelInvocable, + CreatedAt: row.CreatedAt, + UpdatedAt: row.UpdatedAt, }) } return metadata @@ -2518,12 +2524,14 @@ func UserSkillMetadataList(rows []database.ListUserSkillMetadataByUserIDRow) []c metadata := make([]codersdk.SkillMetadata, 0, len(rows)) for _, row := range rows { metadata = append(metadata, codersdk.SkillMetadata{ - ID: row.ID, - Name: row.Name, - Description: row.Description, - Enabled: row.Enabled, - CreatedAt: row.CreatedAt, - UpdatedAt: row.UpdatedAt, + ID: row.ID, + Name: row.Name, + Description: row.Description, + Enabled: row.Enabled, + Action: row.Action, + ModelInvocable: row.ModelInvocable, + CreatedAt: row.CreatedAt, + UpdatedAt: row.UpdatedAt, }) } return metadata diff --git a/coderd/database/dbgen/dbgen.go b/coderd/database/dbgen/dbgen.go index 541376a4d84..b1060201d65 100644 --- a/coderd/database/dbgen/dbgen.go +++ b/coderd/database/dbgen/dbgen.go @@ -1189,7 +1189,7 @@ func Organization(t testing.TB, db database.Store, orig database.Organization) d } // OrganizationSkill inserts a skill owned by seed.OrganizationID, which is -// required. Inserted skills are enabled. +// required. Inserted skills are enabled and model-invocable. func OrganizationSkill(t testing.TB, db database.Store, seed database.Skill) database.Skill { t.Helper() @@ -1202,6 +1202,7 @@ func OrganizationSkill(t testing.TB, db database.Store, seed database.Skill) dat Name: name, Description: description, Content: takeFirst(seed.Content, fmt.Sprintf("---\nname: %s\ndescription: %s\n---\n\nFixture instructions.\n", name, description)), + ModelInvocable: sql.NullBool{}, GroupACL: seed.GroupACL, UserACL: seed.UserACL, }) diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 1f5afd43d2c..299593f9c84 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -3310,7 +3310,10 @@ CREATE TABLE skills ( enabled boolean DEFAULT true NOT NULL, group_acl jsonb DEFAULT '{}'::jsonb NOT NULL, user_acl jsonb DEFAULT '{}'::jsonb NOT NULL, + action boolean DEFAULT false NOT NULL, + model_invocable boolean DEFAULT true NOT NULL, CONSTRAINT skills_acl_only_on_organization_skills CHECK (((organization_id IS NOT NULL) OR ((group_acl = '{}'::jsonb) AND (user_acl = '{}'::jsonb)))), + CONSTRAINT skills_action_project_only CHECK (((NOT action) OR (project_id IS NOT NULL))), CONSTRAINT skills_content_size CHECK ((octet_length(content) <= 65536)), CONSTRAINT skills_description_size CHECK ((octet_length(description) <= 4096)), CONSTRAINT skills_group_acl_is_object CHECK ((jsonb_typeof(group_acl) = 'object'::text)), diff --git a/coderd/database/migrations/000633_skill_action_model_invocable.down.sql b/coderd/database/migrations/000633_skill_action_model_invocable.down.sql new file mode 100644 index 00000000000..be8cc7ea5f1 --- /dev/null +++ b/coderd/database/migrations/000633_skill_action_model_invocable.down.sql @@ -0,0 +1,4 @@ +ALTER TABLE skills + DROP CONSTRAINT skills_action_project_only, + DROP COLUMN model_invocable, + DROP COLUMN action; diff --git a/coderd/database/migrations/000633_skill_action_model_invocable.up.sql b/coderd/database/migrations/000633_skill_action_model_invocable.up.sql new file mode 100644 index 00000000000..7fcdd50a116 --- /dev/null +++ b/coderd/database/migrations/000633_skill_action_model_invocable.up.sql @@ -0,0 +1,7 @@ +-- action marks a project skill as a one-click action above project +-- composers. model_invocable controls whether agents see and load the skill +-- on their own; users can still invoke manual-only skills explicitly. +ALTER TABLE skills + ADD COLUMN action boolean NOT NULL DEFAULT false, + ADD COLUMN model_invocable boolean NOT NULL DEFAULT true, + ADD CONSTRAINT skills_action_project_only CHECK (NOT action OR project_id IS NOT NULL); diff --git a/coderd/database/modelqueries.go b/coderd/database/modelqueries.go index 07de77216b3..3787595fec1 100644 --- a/coderd/database/modelqueries.go +++ b/coderd/database/modelqueries.go @@ -1386,6 +1386,8 @@ func (q *sqlQuerier) GetAuthorizedOrganizationSkillMetadata(ctx context.Context, &i.Name, &i.Description, &i.Enabled, + &i.Action, + &i.ModelInvocable, &i.CreatedAt, &i.UpdatedAt, ); err != nil { diff --git a/coderd/database/models.go b/coderd/database/models.go index cdb852ba936..2af901d3d77 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -6221,6 +6221,8 @@ type Skill struct { Enabled bool `db:"enabled" json:"enabled"` GroupACL ChatACL `db:"group_acl" json:"group_acl"` UserACL ChatACL `db:"user_acl" json:"user_acl"` + Action bool `db:"action" json:"action"` + ModelInvocable bool `db:"model_invocable" json:"model_invocable"` } // We keep this separate from replicas in case we need to break the coordinator out into its own service diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 5529cffa599..5a379f53fc1 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -28838,7 +28838,7 @@ func (q *sqlQuerier) UpsertWebpushVAPIDKeys(ctx context.Context, arg UpsertWebpu const deleteOrganizationSkillByOrganizationIDAndName = `-- name: DeleteOrganizationSkillByOrganizationIDAndName :one DELETE FROM skills WHERE organization_id = $1::uuid AND name = $2 -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type DeleteOrganizationSkillByOrganizationIDAndNameParams struct { @@ -28862,6 +28862,8 @@ func (q *sqlQuerier) DeleteOrganizationSkillByOrganizationIDAndName(ctx context. &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } @@ -28869,7 +28871,7 @@ func (q *sqlQuerier) DeleteOrganizationSkillByOrganizationIDAndName(ctx context. const deleteProjectSkillByProjectIDAndName = `-- name: DeleteProjectSkillByProjectIDAndName :one DELETE FROM skills WHERE project_id = $1::uuid AND name = $2 -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type DeleteProjectSkillByProjectIDAndNameParams struct { @@ -28893,6 +28895,8 @@ func (q *sqlQuerier) DeleteProjectSkillByProjectIDAndName(ctx context.Context, a &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } @@ -28900,7 +28904,7 @@ func (q *sqlQuerier) DeleteProjectSkillByProjectIDAndName(ctx context.Context, a const deleteUserSkillByUserIDAndName = `-- name: DeleteUserSkillByUserIDAndName :one DELETE FROM skills WHERE user_id = $1::uuid AND name = $2 -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type DeleteUserSkillByUserIDAndNameParams struct { @@ -28924,12 +28928,14 @@ func (q *sqlQuerier) DeleteUserSkillByUserIDAndName(ctx context.Context, arg Del &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const getOrganizationSkillByIDForUpdate = `-- name: GetOrganizationSkillByIDForUpdate :one -SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable FROM skills WHERE id = $1::uuid AND organization_id IS NOT NULL FOR UPDATE @@ -28951,12 +28957,14 @@ func (q *sqlQuerier) GetOrganizationSkillByIDForUpdate(ctx context.Context, id u &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const getOrganizationSkillByOrganizationIDAndName = `-- name: GetOrganizationSkillByOrganizationIDAndName :one -SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable FROM skills WHERE organization_id = $1::uuid AND name = $2 ` @@ -28982,12 +28990,14 @@ func (q *sqlQuerier) GetOrganizationSkillByOrganizationIDAndName(ctx context.Con &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const getProjectSkillByIDForUpdate = `-- name: GetProjectSkillByIDForUpdate :one -SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable FROM skills WHERE id = $1::uuid AND project_id IS NOT NULL FOR UPDATE @@ -29009,12 +29019,14 @@ func (q *sqlQuerier) GetProjectSkillByIDForUpdate(ctx context.Context, id uuid.U &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const getProjectSkillByProjectIDAndName = `-- name: GetProjectSkillByProjectIDAndName :one -SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable FROM skills WHERE project_id = $1::uuid AND name = $2 ` @@ -29040,12 +29052,14 @@ func (q *sqlQuerier) GetProjectSkillByProjectIDAndName(ctx context.Context, arg &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const getUserSkillByUserIDAndName = `-- name: GetUserSkillByUserIDAndName :one -SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +SELECT id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable FROM skills WHERE user_id = $1::uuid AND name = $2 ` @@ -29071,24 +29085,27 @@ func (q *sqlQuerier) GetUserSkillByUserIDAndName(ctx context.Context, arg GetUse &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const insertOrganizationSkill = `-- name: InsertOrganizationSkill :one -INSERT INTO skills (id, organization_id, name, description, content, group_acl, user_acl) -VALUES ($1::uuid, $2::uuid, $3::text, $4::text, $5::text, $6, $7) -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +INSERT INTO skills (id, organization_id, name, description, content, model_invocable, group_acl, user_acl) +VALUES ($1::uuid, $2::uuid, $3::text, $4::text, $5::text, COALESCE($6::boolean, true), $7, $8) +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type InsertOrganizationSkillParams struct { - ID uuid.UUID `db:"id" json:"id"` - OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"` - Name string `db:"name" json:"name"` - Description string `db:"description" json:"description"` - Content string `db:"content" json:"content"` - GroupACL ChatACL `db:"group_acl" json:"group_acl"` - UserACL ChatACL `db:"user_acl" json:"user_acl"` + ID uuid.UUID `db:"id" json:"id"` + OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"` + Name string `db:"name" json:"name"` + Description string `db:"description" json:"description"` + Content string `db:"content" json:"content"` + ModelInvocable sql.NullBool `db:"model_invocable" json:"model_invocable"` + GroupACL ChatACL `db:"group_acl" json:"group_acl"` + UserACL ChatACL `db:"user_acl" json:"user_acl"` } func (q *sqlQuerier) InsertOrganizationSkill(ctx context.Context, arg InsertOrganizationSkillParams) (Skill, error) { @@ -29098,6 +29115,7 @@ func (q *sqlQuerier) InsertOrganizationSkill(ctx context.Context, arg InsertOrga arg.Name, arg.Description, arg.Content, + arg.ModelInvocable, arg.GroupACL, arg.UserACL, ) @@ -29115,22 +29133,26 @@ func (q *sqlQuerier) InsertOrganizationSkill(ctx context.Context, arg InsertOrga &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const insertProjectSkill = `-- name: InsertProjectSkill :one -INSERT INTO skills (id, project_id, name, description, content) -VALUES ($1::uuid, $2::uuid, $3::text, $4::text, $5::text) -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +INSERT INTO skills (id, project_id, name, description, content, action, model_invocable) +VALUES ($1::uuid, $2::uuid, $3::text, $4::text, $5::text, COALESCE($6::boolean, false), COALESCE($7::boolean, true)) +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type InsertProjectSkillParams struct { - ID uuid.UUID `db:"id" json:"id"` - ProjectID uuid.UUID `db:"project_id" json:"project_id"` - Name string `db:"name" json:"name"` - Description string `db:"description" json:"description"` - Content string `db:"content" json:"content"` + ID uuid.UUID `db:"id" json:"id"` + ProjectID uuid.UUID `db:"project_id" json:"project_id"` + Name string `db:"name" json:"name"` + Description string `db:"description" json:"description"` + Content string `db:"content" json:"content"` + Action sql.NullBool `db:"action" json:"action"` + ModelInvocable sql.NullBool `db:"model_invocable" json:"model_invocable"` } func (q *sqlQuerier) InsertProjectSkill(ctx context.Context, arg InsertProjectSkillParams) (Skill, error) { @@ -29140,6 +29162,8 @@ func (q *sqlQuerier) InsertProjectSkill(ctx context.Context, arg InsertProjectSk arg.Name, arg.Description, arg.Content, + arg.Action, + arg.ModelInvocable, ) var i Skill err := row.Scan( @@ -29155,22 +29179,25 @@ func (q *sqlQuerier) InsertProjectSkill(ctx context.Context, arg InsertProjectSk &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const insertUserSkill = `-- name: InsertUserSkill :one -INSERT INTO skills (id, user_id, name, description, content) -VALUES ($1::uuid, $2::uuid, $3::text, $4::text, $5::text) -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +INSERT INTO skills (id, user_id, name, description, content, model_invocable) +VALUES ($1::uuid, $2::uuid, $3::text, $4::text, $5::text, COALESCE($6::boolean, true)) +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type InsertUserSkillParams struct { - ID uuid.UUID `db:"id" json:"id"` - UserID uuid.UUID `db:"user_id" json:"user_id"` - Name string `db:"name" json:"name"` - Description string `db:"description" json:"description"` - Content string `db:"content" json:"content"` + ID uuid.UUID `db:"id" json:"id"` + UserID uuid.UUID `db:"user_id" json:"user_id"` + Name string `db:"name" json:"name"` + Description string `db:"description" json:"description"` + Content string `db:"content" json:"content"` + ModelInvocable sql.NullBool `db:"model_invocable" json:"model_invocable"` } func (q *sqlQuerier) InsertUserSkill(ctx context.Context, arg InsertUserSkillParams) (Skill, error) { @@ -29180,6 +29207,7 @@ func (q *sqlQuerier) InsertUserSkill(ctx context.Context, arg InsertUserSkillPar arg.Name, arg.Description, arg.Content, + arg.ModelInvocable, ) var i Skill err := row.Scan( @@ -29195,13 +29223,15 @@ func (q *sqlQuerier) InsertUserSkill(ctx context.Context, arg InsertUserSkillPar &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } const listOrganizationSkillMetadataByOrganizationID = `-- name: ListOrganizationSkillMetadataByOrganizationID :many SELECT - id, organization_id, name, description, enabled, created_at, updated_at + id, organization_id, name, description, enabled, action, model_invocable, created_at, updated_at FROM skills WHERE organization_id = $1::uuid -- Authorize Filter clause will be injected below in GetAuthorizedOrganizationSkillMetadata @@ -29215,6 +29245,8 @@ type ListOrganizationSkillMetadataByOrganizationIDRow struct { Name string `db:"name" json:"name"` Description string `db:"description" json:"description"` Enabled bool `db:"enabled" json:"enabled"` + Action bool `db:"action" json:"action"` + ModelInvocable bool `db:"model_invocable" json:"model_invocable"` CreatedAt time.Time `db:"created_at" json:"created_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` } @@ -29234,6 +29266,8 @@ func (q *sqlQuerier) ListOrganizationSkillMetadataByOrganizationID(ctx context.C &i.Name, &i.Description, &i.Enabled, + &i.Action, + &i.ModelInvocable, &i.CreatedAt, &i.UpdatedAt, ); err != nil { @@ -29252,20 +29286,22 @@ func (q *sqlQuerier) ListOrganizationSkillMetadataByOrganizationID(ctx context.C const listProjectSkillMetadataByProjectID = `-- name: ListProjectSkillMetadataByProjectID :many SELECT - id, project_id, name, description, enabled, created_at, updated_at + id, project_id, name, description, enabled, action, model_invocable, created_at, updated_at FROM skills WHERE project_id = $1::uuid ORDER BY name ASC ` type ListProjectSkillMetadataByProjectIDRow struct { - ID uuid.UUID `db:"id" json:"id"` - ProjectID uuid.NullUUID `db:"project_id" json:"project_id"` - Name string `db:"name" json:"name"` - Description string `db:"description" json:"description"` - Enabled bool `db:"enabled" json:"enabled"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + ID uuid.UUID `db:"id" json:"id"` + ProjectID uuid.NullUUID `db:"project_id" json:"project_id"` + Name string `db:"name" json:"name"` + Description string `db:"description" json:"description"` + Enabled bool `db:"enabled" json:"enabled"` + Action bool `db:"action" json:"action"` + ModelInvocable bool `db:"model_invocable" json:"model_invocable"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` } func (q *sqlQuerier) ListProjectSkillMetadataByProjectID(ctx context.Context, projectID uuid.UUID) ([]ListProjectSkillMetadataByProjectIDRow, error) { @@ -29283,6 +29319,8 @@ func (q *sqlQuerier) ListProjectSkillMetadataByProjectID(ctx context.Context, pr &i.Name, &i.Description, &i.Enabled, + &i.Action, + &i.ModelInvocable, &i.CreatedAt, &i.UpdatedAt, ); err != nil { @@ -29301,20 +29339,22 @@ func (q *sqlQuerier) ListProjectSkillMetadataByProjectID(ctx context.Context, pr const listUserSkillMetadataByUserID = `-- name: ListUserSkillMetadataByUserID :many SELECT - id, user_id, name, description, enabled, created_at, updated_at + id, user_id, name, description, enabled, action, model_invocable, created_at, updated_at FROM skills WHERE user_id = $1::uuid ORDER BY name ASC ` type ListUserSkillMetadataByUserIDRow struct { - ID uuid.UUID `db:"id" json:"id"` - UserID uuid.NullUUID `db:"user_id" json:"user_id"` - Name string `db:"name" json:"name"` - Description string `db:"description" json:"description"` - Enabled bool `db:"enabled" json:"enabled"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + ID uuid.UUID `db:"id" json:"id"` + UserID uuid.NullUUID `db:"user_id" json:"user_id"` + Name string `db:"name" json:"name"` + Description string `db:"description" json:"description"` + Enabled bool `db:"enabled" json:"enabled"` + Action bool `db:"action" json:"action"` + ModelInvocable bool `db:"model_invocable" json:"model_invocable"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` } func (q *sqlQuerier) ListUserSkillMetadataByUserID(ctx context.Context, userID uuid.UUID) ([]ListUserSkillMetadataByUserIDRow, error) { @@ -29332,6 +29372,8 @@ func (q *sqlQuerier) ListUserSkillMetadataByUserID(ctx context.Context, userID u &i.Name, &i.Description, &i.Enabled, + &i.Action, + &i.ModelInvocable, &i.CreatedAt, &i.UpdatedAt, ); err != nil { @@ -29355,7 +29397,7 @@ SET user_acl = $2, updated_at = now() WHERE id = $3::uuid AND organization_id IS NOT NULL -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type UpdateOrganizationSkillACLByIDParams struct { @@ -29380,6 +29422,8 @@ func (q *sqlQuerier) UpdateOrganizationSkillACLByID(ctx context.Context, arg Upd &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } @@ -29390,15 +29434,17 @@ SET description = COALESCE($1::text, description), content = COALESCE($2::text, content), enabled = COALESCE($3::boolean, enabled), + model_invocable = COALESCE($4::boolean, model_invocable), updated_at = now() -WHERE organization_id = $4::uuid AND name = $5 -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +WHERE organization_id = $5::uuid AND name = $6 +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type UpdateOrganizationSkillByOrganizationIDAndNameParams struct { Description sql.NullString `db:"description" json:"description"` Content sql.NullString `db:"content" json:"content"` Enabled sql.NullBool `db:"enabled" json:"enabled"` + ModelInvocable sql.NullBool `db:"model_invocable" json:"model_invocable"` OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"` Name string `db:"name" json:"name"` } @@ -29408,6 +29454,7 @@ func (q *sqlQuerier) UpdateOrganizationSkillByOrganizationIDAndName(ctx context. arg.Description, arg.Content, arg.Enabled, + arg.ModelInvocable, arg.OrganizationID, arg.Name, ) @@ -29425,6 +29472,8 @@ func (q *sqlQuerier) UpdateOrganizationSkillByOrganizationIDAndName(ctx context. &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } @@ -29435,17 +29484,21 @@ SET description = COALESCE($1::text, description), content = COALESCE($2::text, content), enabled = COALESCE($3::boolean, enabled), + model_invocable = COALESCE($4::boolean, model_invocable), + action = COALESCE($5::boolean, action), updated_at = now() -WHERE project_id = $4::uuid AND name = $5 -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +WHERE project_id = $6::uuid AND name = $7 +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type UpdateProjectSkillByProjectIDAndNameParams struct { - Description sql.NullString `db:"description" json:"description"` - Content sql.NullString `db:"content" json:"content"` - Enabled sql.NullBool `db:"enabled" json:"enabled"` - ProjectID uuid.UUID `db:"project_id" json:"project_id"` - Name string `db:"name" json:"name"` + Description sql.NullString `db:"description" json:"description"` + Content sql.NullString `db:"content" json:"content"` + Enabled sql.NullBool `db:"enabled" json:"enabled"` + ModelInvocable sql.NullBool `db:"model_invocable" json:"model_invocable"` + Action sql.NullBool `db:"action" json:"action"` + ProjectID uuid.UUID `db:"project_id" json:"project_id"` + Name string `db:"name" json:"name"` } func (q *sqlQuerier) UpdateProjectSkillByProjectIDAndName(ctx context.Context, arg UpdateProjectSkillByProjectIDAndNameParams) (Skill, error) { @@ -29453,6 +29506,8 @@ func (q *sqlQuerier) UpdateProjectSkillByProjectIDAndName(ctx context.Context, a arg.Description, arg.Content, arg.Enabled, + arg.ModelInvocable, + arg.Action, arg.ProjectID, arg.Name, ) @@ -29470,6 +29525,8 @@ func (q *sqlQuerier) UpdateProjectSkillByProjectIDAndName(ctx context.Context, a &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } @@ -29480,17 +29537,19 @@ SET description = COALESCE($1::text, description), content = COALESCE($2::text, content), enabled = COALESCE($3::boolean, enabled), + model_invocable = COALESCE($4::boolean, model_invocable), updated_at = now() -WHERE user_id = $4::uuid AND name = $5 -RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl +WHERE user_id = $5::uuid AND name = $6 +RETURNING id, user_id, name, description, content, created_at, updated_at, organization_id, project_id, enabled, group_acl, user_acl, action, model_invocable ` type UpdateUserSkillByUserIDAndNameParams struct { - Description sql.NullString `db:"description" json:"description"` - Content sql.NullString `db:"content" json:"content"` - Enabled sql.NullBool `db:"enabled" json:"enabled"` - UserID uuid.UUID `db:"user_id" json:"user_id"` - Name string `db:"name" json:"name"` + Description sql.NullString `db:"description" json:"description"` + Content sql.NullString `db:"content" json:"content"` + Enabled sql.NullBool `db:"enabled" json:"enabled"` + ModelInvocable sql.NullBool `db:"model_invocable" json:"model_invocable"` + UserID uuid.UUID `db:"user_id" json:"user_id"` + Name string `db:"name" json:"name"` } func (q *sqlQuerier) UpdateUserSkillByUserIDAndName(ctx context.Context, arg UpdateUserSkillByUserIDAndNameParams) (Skill, error) { @@ -29498,6 +29557,7 @@ func (q *sqlQuerier) UpdateUserSkillByUserIDAndName(ctx context.Context, arg Upd arg.Description, arg.Content, arg.Enabled, + arg.ModelInvocable, arg.UserID, arg.Name, ) @@ -29515,6 +29575,8 @@ func (q *sqlQuerier) UpdateUserSkillByUserIDAndName(ctx context.Context, arg Upd &i.Enabled, &i.GroupACL, &i.UserACL, + &i.Action, + &i.ModelInvocable, ) return i, err } diff --git a/coderd/database/queries/skills.sql b/coderd/database/queries/skills.sql index 97163d2bea3..8b31cdd6d38 100644 --- a/coderd/database/queries/skills.sql +++ b/coderd/database/queries/skills.sql @@ -1,6 +1,6 @@ -- name: InsertUserSkill :one -INSERT INTO skills (id, user_id, name, description, content) -VALUES (@id::uuid, @user_id::uuid, @name::text, @description::text, @content::text) +INSERT INTO skills (id, user_id, name, description, content, model_invocable) +VALUES (@id::uuid, @user_id::uuid, @name::text, @description::text, @content::text, COALESCE(sqlc.narg('model_invocable')::boolean, true)) RETURNING *; -- name: GetUserSkillByUserIDAndName :one @@ -10,7 +10,7 @@ WHERE user_id = @user_id::uuid AND name = @name; -- name: ListUserSkillMetadataByUserID :many SELECT - id, user_id, name, description, enabled, created_at, updated_at + id, user_id, name, description, enabled, action, model_invocable, created_at, updated_at FROM skills WHERE user_id = @user_id::uuid ORDER BY name ASC; @@ -21,6 +21,7 @@ SET description = COALESCE(sqlc.narg('description')::text, description), content = COALESCE(sqlc.narg('content')::text, content), enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled), + model_invocable = COALESCE(sqlc.narg('model_invocable')::boolean, model_invocable), updated_at = now() WHERE user_id = @user_id::uuid AND name = @name RETURNING *; @@ -31,8 +32,8 @@ WHERE user_id = @user_id::uuid AND name = @name RETURNING *; -- name: InsertOrganizationSkill :one -INSERT INTO skills (id, organization_id, name, description, content, group_acl, user_acl) -VALUES (@id::uuid, @organization_id::uuid, @name::text, @description::text, @content::text, @group_acl, @user_acl) +INSERT INTO skills (id, organization_id, name, description, content, model_invocable, group_acl, user_acl) +VALUES (@id::uuid, @organization_id::uuid, @name::text, @description::text, @content::text, COALESCE(sqlc.narg('model_invocable')::boolean, true), @group_acl, @user_acl) RETURNING *; -- name: GetOrganizationSkillByOrganizationIDAndName :one @@ -42,7 +43,7 @@ WHERE organization_id = @organization_id::uuid AND name = @name; -- name: ListOrganizationSkillMetadataByOrganizationID :many SELECT - id, organization_id, name, description, enabled, created_at, updated_at + id, organization_id, name, description, enabled, action, model_invocable, created_at, updated_at FROM skills WHERE organization_id = @organization_id::uuid -- Authorize Filter clause will be injected below in GetAuthorizedOrganizationSkillMetadata @@ -55,6 +56,7 @@ SET description = COALESCE(sqlc.narg('description')::text, description), content = COALESCE(sqlc.narg('content')::text, content), enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled), + model_invocable = COALESCE(sqlc.narg('model_invocable')::boolean, model_invocable), updated_at = now() WHERE organization_id = @organization_id::uuid AND name = @name RETURNING *; @@ -80,8 +82,8 @@ WHERE id = @id::uuid AND organization_id IS NOT NULL RETURNING *; -- name: InsertProjectSkill :one -INSERT INTO skills (id, project_id, name, description, content) -VALUES (@id::uuid, @project_id::uuid, @name::text, @description::text, @content::text) +INSERT INTO skills (id, project_id, name, description, content, action, model_invocable) +VALUES (@id::uuid, @project_id::uuid, @name::text, @description::text, @content::text, COALESCE(sqlc.narg('action')::boolean, false), COALESCE(sqlc.narg('model_invocable')::boolean, true)) RETURNING *; -- name: GetProjectSkillByProjectIDAndName :one @@ -91,7 +93,7 @@ WHERE project_id = @project_id::uuid AND name = @name; -- name: ListProjectSkillMetadataByProjectID :many SELECT - id, project_id, name, description, enabled, created_at, updated_at + id, project_id, name, description, enabled, action, model_invocable, created_at, updated_at FROM skills WHERE project_id = @project_id::uuid ORDER BY name ASC; @@ -102,6 +104,8 @@ SET description = COALESCE(sqlc.narg('description')::text, description), content = COALESCE(sqlc.narg('content')::text, content), enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled), + model_invocable = COALESCE(sqlc.narg('model_invocable')::boolean, model_invocable), + action = COALESCE(sqlc.narg('action')::boolean, action), updated_at = now() WHERE project_id = @project_id::uuid AND name = @name RETURNING *; diff --git a/coderd/database/user_skills_test.go b/coderd/database/user_skills_test.go index 624b7f4c204..e2aaa117774 100644 --- a/coderd/database/user_skills_test.go +++ b/coderd/database/user_skills_test.go @@ -87,7 +87,7 @@ func TestSkillOwners(t *testing.T) { type skillRow struct { owners name string - enabled bool + enabled, action bool groupACL, userACL string } insertSkill := func(ctx context.Context, q interface { @@ -104,9 +104,9 @@ func TestSkillOwners(t *testing.T) { row.userACL = "{}" } _, err := q.ExecContext(ctx, ` - INSERT INTO skills (id, user_id, organization_id, project_id, name, description, content, enabled, group_acl, user_acl) - VALUES ($1, $2, $3, $4, $5, 'desc', 'body', $6, $7::jsonb, $8::jsonb)`, - uuid.New(), row.user, row.org, row.project, row.name, row.enabled, row.groupACL, row.userACL) + INSERT INTO skills (id, user_id, organization_id, project_id, name, description, content, enabled, action, group_acl, user_acl) + VALUES ($1, $2, $3, $4, $5, 'desc', 'body', $6, $7, $8::jsonb, $9::jsonb)`, + uuid.New(), row.user, row.org, row.project, row.name, row.enabled, row.action, row.groupACL, row.userACL) return err } countSkills := func(ctx context.Context, column string, id uuid.UUID) int { @@ -158,6 +158,16 @@ func TestSkillOwners(t *testing.T) { require.True(t, database.IsCheckViolation(err, database.CheckSkillsUserAclIsObject), err) }) + t.Run("ActionOnlyOnProjectSkills", func(t *testing.T) { + t.Parallel() + ctx := testutil.Context(t, testutil.WaitMedium) + for _, o := range []owners{{user: valid(newUser())}, {org: valid(newOrg())}} { + err := insertSkill(ctx, sqlDB, skillRow{owners: o, action: true}) + require.True(t, database.IsCheckViolation(err, database.CheckSkillsActionProjectOnly), "owners %+v: %v", o, err) + } + require.NoError(t, insertSkill(ctx, sqlDB, skillRow{owners: owners{project: valid(newProject())}, action: true})) + }) + // TestUserSkillLimit and TestUserSkillLimitConcurrentCreates in coderd // cover the user branch of the cap trigger. t.Run("CapPerProject", func(t *testing.T) { diff --git a/coderd/organizationskills.go b/coderd/organizationskills.go index 6979abfa07e..67de335d6a1 100644 --- a/coderd/organizationskills.go +++ b/coderd/organizationskills.go @@ -58,13 +58,14 @@ func (api *API) postOrganizationSkill(rw http.ResponseWriter, r *http.Request) { return } - skill, ok := createSkill(ctx, rw, r, organizationSkillCreateErrors, func(parsed skills.ParsedSkill, content string) (database.Skill, error) { + skill, ok := createSkill(ctx, rw, r, organizationSkillCreateErrors, skillOwnerOrganization, func(parsed skills.ParsedSkill, create skillCreate) (database.Skill, error) { return api.Database.InsertOrganizationSkill(ctx, database.InsertOrganizationSkillParams{ ID: uuid.New(), OrganizationID: organization.ID, Name: parsed.Name, Description: parsed.Description, - Content: content, + Content: create.Content, + ModelInvocable: create.ModelInvocable, // The Everyone group shares the organization's ID, so new skills // reach every member until an admin narrows the ACL. GroupACL: database.ChatACL{ @@ -147,7 +148,7 @@ func (api *API) patchOrganizationSkill(rw http.ResponseWriter, r *http.Request) defer commitAudit() aReq.Old = database.AuditableOrganizationSkill{Skill: oldSkill} - current, skill, ok := api.updateSkill(ctx, rw, r, oldSkill.Name, organizationSkillUpdateErrors, func(tx database.Store, update skillUpdate) (database.Skill, database.Skill, error) { + current, skill, ok := api.updateSkill(ctx, rw, r, oldSkill.Name, organizationSkillUpdateErrors, skillOwnerOrganization, func(tx database.Store, update skillUpdate) (database.Skill, database.Skill, error) { //nolint:gocritic // The update below reauthorizes the locked row for update. locked, err := tx.GetOrganizationSkillByIDForUpdate(dbauthz.AsSystemRestricted(ctx), oldSkill.ID) if err != nil { @@ -157,6 +158,7 @@ func (api *API) patchOrganizationSkill(rw http.ResponseWriter, r *http.Request) Description: update.Description, Content: update.Content, Enabled: update.Enabled, + ModelInvocable: update.ModelInvocable, OrganizationID: locked.OrganizationID.UUID, Name: locked.Name, }) diff --git a/coderd/userskills.go b/coderd/userskills.go index 24208b5a40b..eea9429b97a 100644 --- a/coderd/userskills.go +++ b/coderd/userskills.go @@ -61,13 +61,14 @@ func (api *API) postUserSkill(rw http.ResponseWriter, r *http.Request) { ) defer commitAudit() - skill, ok := createSkill(ctx, rw, r, userSkillCreateErrors, func(parsed skills.ParsedSkill, content string) (database.Skill, error) { + skill, ok := createSkill(ctx, rw, r, userSkillCreateErrors, skillOwnerPersonal, func(parsed skills.ParsedSkill, create skillCreate) (database.Skill, error) { return api.Database.InsertUserSkill(ctx, database.InsertUserSkillParams{ - ID: uuid.New(), - UserID: user.ID, - Name: parsed.Name, - Description: parsed.Description, - Content: content, + ID: uuid.New(), + UserID: user.ID, + Name: parsed.Name, + Description: parsed.Description, + Content: create.Content, + ModelInvocable: create.ModelInvocable, }) }) if !ok { @@ -160,7 +161,7 @@ func (api *API) patchUserSkill(rw http.ResponseWriter, r *http.Request) { ) defer commitAudit() - oldSkill, skill, ok := api.updateSkill(ctx, rw, r, name, userSkillUpdateErrors, func(tx database.Store, update skillUpdate) (database.Skill, database.Skill, error) { + oldSkill, skill, ok := api.updateSkill(ctx, rw, r, name, userSkillUpdateErrors, skillOwnerPersonal, func(tx database.Store, update skillUpdate) (database.Skill, database.Skill, error) { fetched, err := tx.GetUserSkillByUserIDAndName(ctx, database.GetUserSkillByUserIDAndNameParams{ UserID: user.ID, Name: name, @@ -169,11 +170,12 @@ func (api *API) patchUserSkill(rw http.ResponseWriter, r *http.Request) { return database.Skill{}, database.Skill{}, xerrors.Errorf("fetch user skill: %w", err) } updated, err := tx.UpdateUserSkillByUserIDAndName(ctx, database.UpdateUserSkillByUserIDAndNameParams{ - UserID: user.ID, - Name: name, - Description: update.Description, - Content: update.Content, - Enabled: update.Enabled, + UserID: user.ID, + Name: name, + Description: update.Description, + Content: update.Content, + Enabled: update.Enabled, + ModelInvocable: update.ModelInvocable, }) if err != nil { return database.Skill{}, database.Skill{}, xerrors.Errorf("update user skill: %w", err) @@ -272,11 +274,35 @@ func (e skillWriteErrors) write(ctx context.Context, rw http.ResponseWriter, err httpapi.Write(ctx, rw, http.StatusConflict, e.limitReached) case e.nameIndex != "" && database.IsUniqueViolation(err, e.nameIndex): writeSkillNameConflict(ctx, rw) + case database.IsCheckViolation(err, database.CheckSkillsActionProjectOnly): + writeSkillActionNotAllowed(ctx, rw) default: httpapi.InternalServerError(rw, err) } } +// skillOwnerKind is the kind of owner a skill route manages. +type skillOwnerKind int + +const ( + skillOwnerPersonal skillOwnerKind = iota + skillOwnerOrganization + skillOwnerProject +) + +// allowsAction reports whether skills of this owner kind can be actions. +func (k skillOwnerKind) allowsAction() bool { + return k == skillOwnerProject +} + +// skillCreate holds the columns a skill create request writes. Unset +// optional columns keep their database defaults. +type skillCreate struct { + Content string + Action sql.NullBool + ModelInvocable sql.NullBool +} + // createSkill parses a skill create request, stores the skill with insert, // and writes the response. It returns false when it wrote an error. func createSkill( @@ -284,18 +310,27 @@ func createSkill( rw http.ResponseWriter, r *http.Request, errs skillWriteErrors, - insert func(parsed skills.ParsedSkill, content string) (database.Skill, error), + kind skillOwnerKind, + insert func(parsed skills.ParsedSkill, create skillCreate) (database.Skill, error), ) (database.Skill, bool) { var req codersdk.CreateSkillRequest if !httpapi.ReadLimit(ctx, rw, r, maxSkillRequestBytes, &req) { return database.Skill{}, false } + if req.Action != nil && !kind.allowsAction() { + writeSkillActionNotAllowed(ctx, rw) + return database.Skill{}, false + } parsed, err := skills.ParsePersonalSkillMarkdown([]byte(req.Content)) if err != nil { writeInvalidSkillContent(ctx, rw, err) return database.Skill{}, false } - skill, err := insert(parsed, req.Content) + skill, err := insert(parsed, skillCreate{ + Content: req.Content, + Action: nullBool(req.Action), + ModelInvocable: nullBool(req.ModelInvocable), + }) if err != nil { errs.write(ctx, rw, err) return database.Skill{}, false @@ -314,9 +349,10 @@ func (api *API) updateSkill( r *http.Request, name string, errs skillWriteErrors, + kind skillOwnerKind, apply func(tx database.Store, update skillUpdate) (old database.Skill, updated database.Skill, err error), ) (old database.Skill, updated database.Skill, ok bool) { - update, ok := readSkillUpdate(ctx, rw, r, name) + update, ok := readSkillUpdate(ctx, rw, r, name, kind) if !ok { return database.Skill{}, database.Skill{}, false } @@ -335,30 +371,37 @@ func (api *API) updateSkill( // skillUpdate holds the optional columns a skill PATCH writes. type skillUpdate struct { - Description sql.NullString - Content sql.NullString - Enabled sql.NullBool + Description sql.NullString + Content sql.NullString + Enabled sql.NullBool + Action sql.NullBool + ModelInvocable sql.NullBool } // readSkillUpdate reads and validates a PATCH request for the skill named -// name. It writes the error response and returns false when the request is -// invalid. -func readSkillUpdate(ctx context.Context, rw http.ResponseWriter, r *http.Request, name string) (skillUpdate, bool) { +// name for an owner of the given kind. It writes the error response and +// returns false when the request is invalid. +func readSkillUpdate(ctx context.Context, rw http.ResponseWriter, r *http.Request, name string, kind skillOwnerKind) (skillUpdate, bool) { var req codersdk.UpdateSkillRequest if !httpapi.ReadLimit(ctx, rw, r, maxSkillRequestBytes, &req) { return skillUpdate{}, false } - if req.Content == nil && req.Enabled == nil { + if req.Action != nil && !kind.allowsAction() { + writeSkillActionNotAllowed(ctx, rw) + return skillUpdate{}, false + } + if req.Content == nil && req.Enabled == nil && req.Action == nil && req.ModelInvocable == nil { httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ Message: "No skill fields to update.", - Detail: "Set content, enabled, or both.", + Detail: "Set at least one of content, enabled, action, or model_invocable.", }) return skillUpdate{}, false } - var update skillUpdate - if req.Enabled != nil { - update.Enabled = sql.NullBool{Bool: *req.Enabled, Valid: true} + update := skillUpdate{ + Enabled: nullBool(req.Enabled), + Action: nullBool(req.Action), + ModelInvocable: nullBool(req.ModelInvocable), } if req.Content == nil { return update, true @@ -380,6 +423,20 @@ func readSkillUpdate(ctx context.Context, rw http.ResponseWriter, r *http.Reques return update, true } +func nullBool(value *bool) sql.NullBool { + if value == nil { + return sql.NullBool{} + } + return sql.NullBool{Bool: *value, Valid: true} +} + +func writeSkillActionNotAllowed(ctx context.Context, rw http.ResponseWriter) { + httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ + Message: "Only project skills can be actions.", + Detail: "Remove the action field; personal and organization skills cannot be shown as actions.", + }) +} + func writeSkillNameConflict(ctx context.Context, rw http.ResponseWriter) { httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{ Message: "A skill with that name already exists.", diff --git a/coderd/userskills_test.go b/coderd/userskills_test.go index 7e2a5f192f8..113bac2d709 100644 --- a/coderd/userskills_test.go +++ b/coderd/userskills_test.go @@ -148,6 +148,8 @@ func TestSkillsCRUD(t *testing.T) { assert.Equal(t, "Initial description", created.Description) assert.Equal(t, content, created.Content) assert.True(t, created.Enabled) + assert.True(t, created.ModelInvocable) + assert.False(t, created.Action) assert.NotZero(t, created.CreatedAt) assert.NotZero(t, created.UpdatedAt) @@ -188,6 +190,15 @@ func TestSkillsCRUD(t *testing.T) { require.NoError(t, err) assert.False(t, got.Enabled) + manual, err := owner.update(ctx, "crud-skill", codersdk.UpdateSkillRequest{ModelInvocable: ptr.Ref(false)}) + require.NoError(t, err) + assert.False(t, manual.ModelInvocable) + assert.False(t, manual.Enabled) + list, err = owner.list(ctx) + require.NoError(t, err) + require.Len(t, list, 1) + assert.False(t, list[0].ModelInvocable) + require.NoError(t, owner.delete(ctx, "crud-skill")) _, err = owner.get(ctx, "crud-skill") requireSDKErrorStatus(t, err, http.StatusNotFound) @@ -287,6 +298,25 @@ func TestSkillValidationAndConflicts(t *testing.T) { assert.Equal(t, "No skill fields to update.", sdkErr.Message) }) + // Only project skills can be actions, so personal and + // organization routes reject the field even when it is false. + t.Run("ActionRejected", func(t *testing.T) { + t.Parallel() + + ctx := testutil.Context(t, testutil.WaitMedium) + content := userSkillMarkdown("action-rejected", "Valid", "Body.") + _, err := owner.create(ctx, codersdk.CreateSkillRequest{Content: content, Action: ptr.Ref(true)}) + sdkErr := requireSDKErrorStatus(t, err, http.StatusBadRequest) + assert.Equal(t, "Only project skills can be actions.", sdkErr.Message) + _, err = owner.create(ctx, codersdk.CreateSkillRequest{Content: content, ModelInvocable: ptr.Ref(false)}) + require.NoError(t, err) + for _, action := range []bool{true, false} { + _, err = owner.update(ctx, "action-rejected", codersdk.UpdateSkillRequest{Action: ptr.Ref(action)}) + sdkErr = requireSDKErrorStatus(t, err, http.StatusBadRequest) + assert.Equal(t, "Only project skills can be actions.", sdkErr.Message) + } + }) + t.Run("PatchNameMismatch", func(t *testing.T) { t.Parallel() diff --git a/coderd/x/chatd/ARCHITECTURE.md b/coderd/x/chatd/ARCHITECTURE.md index 83c75bfe997..a3cd50b6780 100644 --- a/coderd/x/chatd/ARCHITECTURE.md +++ b/coderd/x/chatd/ARCHITECTURE.md @@ -503,8 +503,6 @@ Setting `title` writes a `user` title. The write happens even when the text is u ### `POST /api/v2/chats/{chat}/messages` -TODO (project-skills): `skill-invocation` content parts are resolved when a message is created, sent, or edited: chatd loads each invoked skill body as the chat owner (personal, organization, project via the chat's project, workspace from the pinned context snapshot), stores it on the part, and rejects the request with a 400 when the skill is not available. The prompt renders the stored body inside ``. Describe this here. - For `busy_behavior=queue`, `SendMessage(m, queue)` supports: - `W -> SendMessage(m, queue) -> R0` diff --git a/coderd/x/chatd/chatd_internal_test.go b/coderd/x/chatd/chatd_internal_test.go index b25cd6a8ca7..1d06bace93d 100644 --- a/coderd/x/chatd/chatd_internal_test.go +++ b/coderd/x/chatd/chatd_internal_test.go @@ -2177,10 +2177,11 @@ func TestFetchPersonalSkillMetadata(t *testing.T) { requireUserSkillContextActor(ctx, t, userID) require.Equal(t, userID, gotUserID) return []database.ListUserSkillMetadataByUserIDRow{{ - UserID: uuid.NullUUID{UUID: userID, Valid: true}, - Name: "personal-review", - Description: "Personal review process", - Enabled: true, + UserID: uuid.NullUUID{UUID: userID, Valid: true}, + Name: "personal-review", + Description: "Personal review process", + Enabled: true, + ModelInvocable: true, }}, nil }, ) @@ -2245,15 +2246,16 @@ func TestLoadPersonalSkillBody(t *testing.T) { requireUserSkillContextActor(ctx, t, userID) require.Equal(t, params, gotParams) return database.Skill{ - UserID: uuid.NullUUID{UUID: userID, Valid: true}, - Name: "personal-review", - Content: "---\nname: personal-review\ndescription: Personal review process\n---\n\nUpdated instructions.\n", - Enabled: true, + UserID: uuid.NullUUID{UUID: userID, Valid: true}, + Name: "personal-review", + Content: "---\nname: personal-review\ndescription: Personal review process\n---\n\nUpdated instructions.\n", + Enabled: true, + ModelInvocable: true, }, nil }, ) - got, err := server.loadPersonalSkillBody(context.Background(), userID, "personal-review") + got, err := server.loadPersonalSkillBody(context.Background(), userID, "personal-review", skillLoaderModel) require.NoError(t, err) require.Equal(t, "personal-review", got.Name) require.Equal(t, "Personal review process", got.Description) @@ -2281,7 +2283,7 @@ func TestLoadPersonalSkillBody(t *testing.T) { }, ) - _, err := server.loadPersonalSkillBody(context.Background(), userID, "missing-skill") + _, err := server.loadPersonalSkillBody(context.Background(), userID, "missing-skill", skillLoaderModel) require.ErrorIs(t, err, skillspkg.ErrSkillNotFound) }) @@ -2299,7 +2301,7 @@ func TestLoadPersonalSkillBody(t *testing.T) { Content: "---\nname: disabled-skill\ndescription: Disabled\n---\n\nInstructions.\n", }, nil) - _, err := server.loadPersonalSkillBody(context.Background(), userID, "disabled-skill") + _, err := server.loadPersonalSkillBody(context.Background(), userID, "disabled-skill", skillLoaderModel) require.ErrorIs(t, err, skillspkg.ErrSkillNotFound) }) @@ -2325,7 +2327,7 @@ func TestLoadPersonalSkillBody(t *testing.T) { }, ) - _, err := server.loadPersonalSkillBody(context.Background(), userID, "error-skill") + _, err := server.loadPersonalSkillBody(context.Background(), userID, "error-skill", skillLoaderModel) require.ErrorContains(t, err, "load personal skill body") require.ErrorIs(t, err, dbErr) @@ -2354,15 +2356,16 @@ func TestLoadPersonalSkillBody(t *testing.T) { requireUserSkillContextActor(ctx, t, userID) require.Equal(t, params, gotParams) return database.Skill{ - UserID: uuid.NullUUID{UUID: userID, Valid: true}, - Name: "broken-skill", - Content: "---\nname: broken-skill\ndescription: Broken\n---\n\n \n", - Enabled: true, + UserID: uuid.NullUUID{UUID: userID, Valid: true}, + Name: "broken-skill", + Content: "---\nname: broken-skill\ndescription: Broken\n---\n\n \n", + Enabled: true, + ModelInvocable: true, }, nil }, ) - _, err := server.loadPersonalSkillBody(context.Background(), userID, "broken-skill") + _, err := server.loadPersonalSkillBody(context.Background(), userID, "broken-skill", skillLoaderModel) require.ErrorContains(t, err, "parse personal skill body") require.ErrorIs(t, err, skillspkg.ErrSkillBodyRequired) @@ -2425,7 +2428,7 @@ func TestLoadOrganizationSkillBody(t *testing.T) { return got } - got, err := server.loadOrganizationSkillBody(ctx, subject(member.ID), org.ID, "team-review") + got, err := server.loadOrganizationSkillBody(ctx, subject(member.ID), org.ID, "team-review", skillLoaderModel) require.NoError(t, err) require.Equal(t, skillspkg.SourceOrganization, got.Source) require.Equal(t, "Team instructions.", got.Body) @@ -2439,7 +2442,7 @@ func TestLoadOrganizationSkillBody(t *testing.T) { {name: "Disabled", reader: member.ID, skill: "disabled-review"}, {name: "Missing", reader: member.ID, skill: "missing-review"}, } { - _, err := server.loadOrganizationSkillBody(ctx, subject(tc.reader), org.ID, tc.skill) + _, err := server.loadOrganizationSkillBody(ctx, subject(tc.reader), org.ID, tc.skill, skillLoaderModel) require.ErrorIs(t, err, skillspkg.ErrSkillNotFound, tc.name) } } @@ -2462,12 +2465,13 @@ func TestLoadProjectSkillBody(t *testing.T) { owner := dbgen.User(t, db, database.User{}) dbgen.OrganizationMember(t, db, database.OrganizationMember{UserID: owner.ID, OrganizationID: org.ID}) project := dbgen.ChatProject(t, db, database.ChatProject{OrganizationID: org.ID, OwnerID: owner.ID}) - for _, name := range []string{"project-review", "disabled-review"} { + for _, name := range []string{"project-review", "disabled-review", "manual-review"} { _, err := db.InsertProjectSkill(ctx, database.InsertProjectSkillParams{ - ID: uuid.New(), - ProjectID: project.ID, - Name: name, - Content: "---\nname: " + name + "\ndescription: Review\n---\n\nProject instructions.\n", + ID: uuid.New(), + ProjectID: project.ID, + Name: name, + Content: "---\nname: " + name + "\ndescription: Review\n---\n\nProject instructions.\n", + ModelInvocable: sql.NullBool{Bool: name != "manual-review", Valid: true}, }) require.NoError(t, err) } @@ -2479,11 +2483,18 @@ func TestLoadProjectSkillBody(t *testing.T) { require.NoError(t, err) chatdCtx := dbauthz.AsChatd(ctx) - got, err := server.loadProjectSkillBody(chatdCtx, project.ID, "project-review") + got, err := server.loadProjectSkillBody(chatdCtx, project.ID, "project-review", skillLoaderModel) require.NoError(t, err) require.Equal(t, skillspkg.SourceProject, got.Source) require.Equal(t, "Project instructions.", got.Body) + // A skill that is not model-invocable loads only for user invocations. + _, err = server.loadProjectSkillBody(chatdCtx, project.ID, "manual-review", skillLoaderModel) + require.ErrorIs(t, err, skillspkg.ErrSkillNotFound) + got, err = server.loadProjectSkillBody(chatdCtx, project.ID, "manual-review", skillLoaderUser) + require.NoError(t, err) + require.Equal(t, "Project instructions.", got.Body) + for _, tc := range []struct { name string projectID uuid.UUID @@ -2493,7 +2504,7 @@ func TestLoadProjectSkillBody(t *testing.T) { {name: "Missing", projectID: project.ID, skill: "missing-review"}, {name: "MissingProject", projectID: uuid.New(), skill: "project-review"}, } { - _, err := server.loadProjectSkillBody(chatdCtx, tc.projectID, tc.skill) + _, err := server.loadProjectSkillBody(chatdCtx, tc.projectID, tc.skill, skillLoaderUser) require.ErrorIs(t, err, skillspkg.ErrSkillNotFound, tc.name) } } diff --git a/coderd/x/chatd/organization_skills_test.go b/coderd/x/chatd/organization_skills_test.go index 083b3b9297d..e2a7cc1af2a 100644 --- a/coderd/x/chatd/organization_skills_test.go +++ b/coderd/x/chatd/organization_skills_test.go @@ -122,19 +122,33 @@ func TestOrganizationSkillsFollowChatOwnerAccess(t *testing.T) { GroupACL: everyone, UserACL: database.ChatACL{}, }) + dbgen.OrganizationSkill(t, db, database.Skill{ + OrganizationID: uuid.NullUUID{UUID: org.ID, Valid: true}, + Name: "org-manual", + Description: "Manual org process", + GroupACL: everyone, + UserACL: database.ChatACL{}, + }) _, err := db.UpdateOrganizationSkillByOrganizationIDAndName(ctx, database.UpdateOrganizationSkillByOrganizationIDAndNameParams{ Enabled: sql.NullBool{Bool: false, Valid: true}, OrganizationID: org.ID, Name: "org-disabled", }) require.NoError(t, err) - for _, name := range []string{"personal-on", "personal-off"} { + _, err = db.UpdateOrganizationSkillByOrganizationIDAndName(ctx, database.UpdateOrganizationSkillByOrganizationIDAndNameParams{ + ModelInvocable: sql.NullBool{Bool: false, Valid: true}, + OrganizationID: org.ID, + Name: "org-manual", + }) + require.NoError(t, err) + for _, name := range []string{"personal-on", "personal-off", "personal-manual"} { _, err := db.InsertUserSkill(ctx, database.InsertUserSkillParams{ - ID: uuid.New(), - UserID: member.ID, - Name: name, - Description: "Personal process " + name, - Content: "---\nname: " + name + "\ndescription: Personal process " + name + "\n---\n\nPersonal instructions.\n", + ID: uuid.New(), + UserID: member.ID, + Name: name, + Description: "Personal process " + name, + Content: "---\nname: " + name + "\ndescription: Personal process " + name + "\n---\n\nPersonal instructions.\n", + ModelInvocable: sql.NullBool{Bool: name != "personal-manual", Valid: true}, }) require.NoError(t, err) } @@ -189,18 +203,24 @@ func TestOrganizationSkillsFollowChatOwnerAccess(t *testing.T) { } // A team member sees enabled personal and org skills, including the - // team-only one, and can read it. Disabled skills are not offered. - memberChatID, calls := runTurn(t, member.ID, uuid.Nil, readSkillsDirective+"team-review,org-disabled,personal-off") + // team-only one, and can read it. Disabled skills and skills that are + // not model-invocable are not offered. + memberChatID, calls := runTurn(t, member.ID, uuid.Nil, readSkillsDirective+"team-review,org-disabled,personal-off,org-manual,personal-manual") require.Len(t, calls, 2) require.Contains(t, calls[0].system, "- team-review: Team review process\n") require.Contains(t, calls[0].system, "- org-wide: Org-wide process\n") require.Contains(t, calls[0].system, "- personal-on: Personal process personal-on\n") - require.NotContains(t, calls[0].system, "org-disabled") - require.NotContains(t, calls[0].system, "personal-off") - require.Len(t, calls[1].toolResults, 3) + for _, hidden := range []string{"org-disabled", "personal-off", "org-manual", "personal-manual"} { + require.NotContains(t, calls[0].system, hidden) + } + require.Len(t, calls[1].toolResults, 5) require.Contains(t, calls[1].toolResults[0], "Team review instructions.") - require.Equal(t, `skill "org-disabled" not found`, calls[1].toolResults[1]) - require.Equal(t, `skill "personal-off" not found`, calls[1].toolResults[2]) + require.Equal(t, []string{ + `skill "org-disabled" not found`, + `skill "personal-off" not found`, + `skill "org-manual" not found`, + `skill "personal-manual" not found`, + }, calls[1].toolResults[1:]) // An org member outside the team, with no personal or workspace skills, // gets read_skill for the org-wide skill only. diff --git a/coderd/x/chatd/project_skills_test.go b/coderd/x/chatd/project_skills_test.go index 91bed464d79..a286b96fb8f 100644 --- a/coderd/x/chatd/project_skills_test.go +++ b/coderd/x/chatd/project_skills_test.go @@ -50,13 +50,15 @@ func TestProjectSkillsFollowProjectAccess(t *testing.T) { {"project-review", "Project review process"}, {"shared", "Project shared process"}, {"project-disabled", "Disabled project process"}, + {"project-manual", "Manual project process"}, } { _, err := db.InsertProjectSkill(ctx, database.InsertProjectSkillParams{ - ID: uuid.New(), - ProjectID: project.ID, - Name: skill.name, - Description: skill.description, - Content: skillMarkdown(skill.name, skill.description, "Instructions for "+skill.name+"."), + ID: uuid.New(), + ProjectID: project.ID, + Name: skill.name, + Description: skill.description, + Content: skillMarkdown(skill.name, skill.description, "Instructions for "+skill.name+"."), + ModelInvocable: sql.NullBool{Bool: skill.name != "project-manual", Valid: true}, }) require.NoError(t, err) } @@ -131,16 +133,19 @@ func TestProjectSkillsFollowProjectAccess(t *testing.T) { inProject := chatd.CreateOptions{ProjectID: uuid.NullUUID{UUID: project.ID, Valid: true}} // A project chat lists enabled project skills. A name shared with a - // personal skill gets qualified aliases, and disabled skills are hidden. - projectChatID, calls := runTurn(t, owner.ID, uuid.Nil, inProject, readSkillsDirective+"project-review,project/shared,project-disabled") + // personal skill gets qualified aliases, and disabled skills and skills + // that are not model-invocable are hidden. + projectChatID, calls := runTurn(t, owner.ID, uuid.Nil, inProject, readSkillsDirective+"project-review,project/shared,project-disabled,project-manual") require.Contains(t, calls[0].system, "- project-review: Project review process\n") require.Contains(t, calls[0].system, "- project/shared: Project shared process\n") require.Contains(t, calls[0].system, "- personal/shared: Personal shared process\n") require.NotContains(t, calls[0].system, "project-disabled") - results := lastToolResults(calls[1], 3) + require.NotContains(t, calls[0].system, "project-manual") + results := lastToolResults(calls[1], 4) require.Contains(t, results[0], "Instructions for project-review.") require.Contains(t, results[1], "Instructions for shared.") require.Equal(t, `skill "project-disabled" not found`, results[2]) + require.Equal(t, `skill "project-manual" not found`, results[3]) // A chat outside the project does not see project skills. _, calls = runTurn(t, owner.ID, uuid.Nil, chatd.CreateOptions{}, readSkillsDirective+"project-review") diff --git a/coderd/x/chatd/skill_invocation.go b/coderd/x/chatd/skill_invocation.go index a4ed0b03274..8792b7fe174 100644 --- a/coderd/x/chatd/skill_invocation.go +++ b/coderd/x/chatd/skill_invocation.go @@ -58,7 +58,8 @@ func (p *Server) resolveChatSkillInvocations( // resolveSkillInvocations stores the current body of every invoked skill on // its part, read with the chat owner's permissions through the same loaders // as read_skill. Skills load by source and name, so an invocation does not -// depend on the skill being listed in the turn's skill index. Workspace +// depend on the skill being listed in the turn's skill index, and skills +// that are not model-invocable still load. Workspace // skills come from the chat's pinned context snapshot, so a chat without // one cannot invoke them. func (p *Server) resolveSkillInvocations( @@ -83,14 +84,14 @@ func (p *Server) resolveSkillInvocations( loadBody := func(part codersdk.ChatMessagePart) (string, error) { switch part.SkillSource { case codersdk.ChatSkillSourcePersonal: - parsed, err := p.loadPersonalSkillBody(ctx, chat.OwnerID, part.SkillName) + parsed, err := p.loadPersonalSkillBody(ctx, chat.OwnerID, part.SkillName, skillLoaderUser) return parsed.Body, err case codersdk.ChatSkillSourceOrganization: owner, err := loadOwner() if err != nil { return "", err } - parsed, err := p.loadOrganizationSkillBody(ctx, owner, chat.OrganizationID, part.SkillName) + parsed, err := p.loadOrganizationSkillBody(ctx, owner, chat.OrganizationID, part.SkillName, skillLoaderUser) return parsed.Body, err case codersdk.ChatSkillSourceProject: // Read as chatd behind the chat owner's project usability check, @@ -101,7 +102,7 @@ func (p *Server) resolveSkillInvocations( if !projectID.Valid { return "", skillspkg.ErrSkillNotFound } - parsed, err := p.loadProjectSkillBody(chatdCtx, projectID.UUID, part.SkillName) + parsed, err := p.loadProjectSkillBody(chatdCtx, projectID.UUID, part.SkillName, skillLoaderUser) return parsed.Body, err case codersdk.ChatSkillSourceWorkspace: skills, err := loadWorkspaceSkills() diff --git a/coderd/x/chatd/skill_invocation_internal_test.go b/coderd/x/chatd/skill_invocation_internal_test.go index 14d08c86cd5..a66c97a0490 100644 --- a/coderd/x/chatd/skill_invocation_internal_test.go +++ b/coderd/x/chatd/skill_invocation_internal_test.go @@ -2,6 +2,7 @@ package chatd import ( "context" + "database/sql" "errors" "slices" "testing" @@ -52,6 +53,9 @@ func TestResolveSkillInvocations(t *testing.T) { skillMarkdown := func(name string) string { return "---\nname: " + name + "\ndescription: Test\n---\n\nInstructions for " + name + ".\n" } + // Every invoked stored skill is hidden from the agent: users can + // invoke skills the agent cannot use on its own. + manualOnly := sql.NullBool{Bool: false, Valid: true} org := dbgen.Organization(t, db, database.Organization{}) owner := dbgen.User(t, db, database.User{}) other := dbgen.User(t, db, database.User{}) @@ -63,7 +67,7 @@ func TestResolveSkillInvocations(t *testing.T) { name string }{{owner.ID, "notes"}, {other.ID, "secret"}} { _, err := db.InsertUserSkill(ctx, database.InsertUserSkillParams{ - ID: uuid.New(), UserID: skill.userID, Name: skill.name, Content: skillMarkdown(skill.name), + ID: uuid.New(), UserID: skill.userID, Name: skill.name, Content: skillMarkdown(skill.name), ModelInvocable: manualOnly, }) require.NoError(t, err) } @@ -74,9 +78,13 @@ func TestResolveSkillInvocations(t *testing.T) { GroupACL: database.ChatACL{org.ID.String(): {Permissions: []policy.Action{policy.ActionRead}}}, UserACL: database.ChatACL{}, }) + _, err := db.UpdateOrganizationSkillByOrganizationIDAndName(ctx, database.UpdateOrganizationSkillByOrganizationIDAndNameParams{ + ModelInvocable: manualOnly, OrganizationID: org.ID, Name: "team-review", + }) + require.NoError(t, err) project := dbgen.ChatProject(t, db, database.ChatProject{OrganizationID: org.ID, OwnerID: owner.ID}) - _, err := db.InsertProjectSkill(ctx, database.InsertProjectSkillParams{ - ID: uuid.New(), ProjectID: project.ID, Name: "triage", Content: skillMarkdown("triage"), + _, err = db.InsertProjectSkill(ctx, database.InsertProjectSkillParams{ + ID: uuid.New(), ProjectID: project.ID, Name: "triage", Content: skillMarkdown("triage"), ModelInvocable: manualOnly, }) require.NoError(t, err) diff --git a/coderd/x/chatd/turn_environment.go b/coderd/x/chatd/turn_environment.go index 4581897a83a..184ba59dc8a 100644 --- a/coderd/x/chatd/turn_environment.go +++ b/coderd/x/chatd/turn_environment.go @@ -791,11 +791,11 @@ func (p *Server) buildTurnEnvironment( LoadStoredSkillBody: func(ctx context.Context, skill skillspkg.Skill) (skillspkg.ParsedSkill, error) { switch skill.Source { case skillspkg.SourceOrganization: - return p.loadOrganizationSkillBody(ctx, orgSkillReader, chat.OrganizationID, skill.Name) + return p.loadOrganizationSkillBody(ctx, orgSkillReader, chat.OrganizationID, skill.Name, skillLoaderModel) case skillspkg.SourceProject: - return p.loadProjectSkillBody(ctx, usableProjectID.UUID, skill.Name) + return p.loadProjectSkillBody(ctx, usableProjectID.UUID, skill.Name, skillLoaderModel) default: - return p.loadPersonalSkillBody(ctx, chat.OwnerID, skill.Name) + return p.loadPersonalSkillBody(ctx, chat.OwnerID, skill.Name, skillLoaderModel) } }, } @@ -2301,6 +2301,23 @@ func userSkillContext(ctx context.Context, userID uuid.UUID) context.Context { return dbauthz.As(ctx, actor) } +// skillLoader says who asked for a stored skill body. Skills that are not +// model-invocable stay hidden from the agent but load for users who invoke +// them explicitly. +type skillLoader int + +const ( + // skillLoaderModel loads a skill the agent asked for with read_skill. + skillLoaderModel skillLoader = iota + // skillLoaderUser loads a skill the user invoked in a message. + skillLoaderUser +) + +// hides reports whether the loader must treat a skill as missing. +func (l skillLoader) hides(enabled, modelInvocable bool) bool { + return !enabled || (l == skillLoaderModel && !modelInvocable) +} + func (p *Server) fetchPersonalSkillMetadata( ctx context.Context, userID uuid.UUID, @@ -2312,7 +2329,7 @@ func (p *Server) fetchPersonalSkillMetadata( personalSkills := make([]skillspkg.Skill, 0, len(rows)) for _, row := range rows { - if !row.Enabled { + if skillLoaderModel.hides(row.Enabled, row.ModelInvocable) { continue } personalSkills = append(personalSkills, skillspkg.Skill{ @@ -2328,6 +2345,7 @@ func (p *Server) loadPersonalSkillBody( ctx context.Context, userID uuid.UUID, name string, + loader skillLoader, ) (skillspkg.ParsedSkill, error) { row, err := p.db.GetUserSkillByUserIDAndName( userSkillContext(ctx, userID), @@ -2347,7 +2365,7 @@ func (p *Server) loadPersonalSkillBody( ) return skillspkg.ParsedSkill{}, xerrors.Errorf("load personal skill body: %w", err) } - if !row.Enabled { + if loader.hides(row.Enabled, row.ModelInvocable) { return skillspkg.ParsedSkill{}, skillspkg.ErrSkillNotFound } @@ -2391,7 +2409,7 @@ func (p *Server) fetchOrganizationSkillMetadata( organizationSkills := make([]skillspkg.Skill, 0, len(rows)) for _, row := range rows { - if !row.Enabled { + if skillLoaderModel.hides(row.Enabled, row.ModelInvocable) { continue } organizationSkills = append(organizationSkills, skillspkg.Skill{ @@ -2408,6 +2426,7 @@ func (p *Server) loadOrganizationSkillBody( owner rbac.Subject, organizationID uuid.UUID, name string, + loader skillLoader, ) (skillspkg.ParsedSkill, error) { //nolint:gocritic // Org skill ACLs are evaluated against the chat owner. row, err := p.db.GetOrganizationSkillByOrganizationIDAndName( @@ -2429,7 +2448,7 @@ func (p *Server) loadOrganizationSkillBody( ) return skillspkg.ParsedSkill{}, xerrors.Errorf("load organization skill body: %w", err) } - if !row.Enabled { + if loader.hides(row.Enabled, row.ModelInvocable) { return skillspkg.ParsedSkill{}, skillspkg.ErrSkillNotFound } @@ -2446,9 +2465,10 @@ func (p *Server) loadOrganizationSkillBody( return parsed, nil } -// fetchProjectSkillMetadata lists the enabled skills of a chat project. It -// reads as chatd, so callers must first check that the chat owner can use the -// project with usableChatProject, as for project instructions and memory. +// fetchProjectSkillMetadata lists the enabled, model-invocable skills of a +// chat project. It reads as chatd, so callers must first check that the chat +// owner can use the project with usableChatProject, as for project +// instructions and memory. func (p *Server) fetchProjectSkillMetadata( ctx context.Context, projectID uuid.UUID, @@ -2460,7 +2480,7 @@ func (p *Server) fetchProjectSkillMetadata( projectSkills := make([]skillspkg.Skill, 0, len(rows)) for _, row := range rows { - if !row.Enabled { + if skillLoaderModel.hides(row.Enabled, row.ModelInvocable) { continue } projectSkills = append(projectSkills, skillspkg.Skill{ @@ -2475,11 +2495,12 @@ func (p *Server) fetchProjectSkillMetadata( // loadProjectSkillBody loads the current body of a chat project skill. Like // fetchProjectSkillMetadata, it reads as chatd and relies on the caller's // project access check. It returns skillspkg.ErrSkillNotFound when the skill -// or project is gone, or the skill is disabled. +// or project is gone, or the skill is disabled or hidden from loader. func (p *Server) loadProjectSkillBody( ctx context.Context, projectID uuid.UUID, name string, + loader skillLoader, ) (skillspkg.ParsedSkill, error) { row, err := p.db.GetProjectSkillByProjectIDAndName(ctx, database.GetProjectSkillByProjectIDAndNameParams{ ProjectID: projectID, @@ -2496,7 +2517,7 @@ func (p *Server) loadProjectSkillBody( ) return skillspkg.ParsedSkill{}, xerrors.Errorf("load project skill body: %w", err) } - if !row.Enabled { + if loader.hides(row.Enabled, row.ModelInvocable) { return skillspkg.ParsedSkill{}, skillspkg.ErrSkillNotFound } diff --git a/codersdk/skills.go b/codersdk/skills.go index 29f634c0a62..8ba13b09b62 100644 --- a/codersdk/skills.go +++ b/codersdk/skills.go @@ -17,8 +17,16 @@ type SkillMetadata struct { Name string `json:"name"` Description string `json:"description"` Enabled bool `json:"enabled"` - CreatedAt time.Time `json:"created_at" format:"date-time"` - UpdatedAt time.Time `json:"updated_at" format:"date-time"` + // Action reports whether a project skill is offered as a one-click + // action above project composers. It is always false for personal and + // organization skills. + Action bool `json:"action"` + // ModelInvocable reports whether agents can discover and load the skill + // on their own. Users can still invoke a skill explicitly when it is + // false. + ModelInvocable bool `json:"model_invocable"` + CreatedAt time.Time `json:"created_at" format:"date-time"` + UpdatedAt time.Time `json:"updated_at" format:"date-time"` } // Skill represents a personal or organization skill with its raw Markdown @@ -34,6 +42,10 @@ type CreateSkillRequest struct { // frontmatter must include name, may include description, and must be // followed by a non-empty body. Content string `json:"content"` + // Action is only accepted for project skills and defaults to false. + Action *bool `json:"action,omitempty"` + // ModelInvocable defaults to true. + ModelInvocable *bool `json:"model_invocable,omitempty"` } // UpdateSkillRequest is the payload for updating a skill. At least one field @@ -44,6 +56,9 @@ type UpdateSkillRequest struct { // followed by a non-empty body. Content *string `json:"content,omitempty"` Enabled *bool `json:"enabled,omitempty"` + // Action is only accepted for project skills. + Action *bool `json:"action,omitempty"` + ModelInvocable *bool `json:"model_invocable,omitempty"` } // OrganizationSkillRole is a role a user or group holds in an organization diff --git a/docs/admin/security/audit-logs.md b/docs/admin/security/audit-logs.md index 69a0fc10a62..ff86a9914b4 100644 --- a/docs/admin/security/audit-logs.md +++ b/docs/admin/security/audit-logs.md @@ -147,12 +147,14 @@ Actions: `create`, `write`, `delete` + + @@ -218,12 +220,14 @@ Actions: `create`, `write`, `delete`
FieldTracked
actionYes
contentYes
created_atNo
descriptionYes
enabledYes
group_aclYes
idYes
model_invocableYes
nameYes
organization_idYes
project_idYes
+ + @@ -703,12 +707,14 @@ Actions: `create`, `write`, `delete`
FieldTracked
actionYes
contentYes
created_atNo
descriptionYes
enabledYes
group_aclYes
idYes
model_invocableYes
nameYes
organization_idYes
project_idYes
+ + diff --git a/docs/reference/api/schemas.md b/docs/reference/api/schemas.md index fe091db5310..74a6c0e3e4c 100644 --- a/docs/reference/api/schemas.md +++ b/docs/reference/api/schemas.md @@ -7252,15 +7252,19 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in ```json { - "content": "string" + "action": true, + "content": "string", + "model_invocable": true } ``` ### Properties -| Name | Type | Required | Restrictions | Description | -|-----------|--------|----------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `content` | string | false | | Content must be SKILL.md-format Markdown with YAML frontmatter. The frontmatter must include name, may include description, and must be followed by a non-empty body. | +| Name | Type | Required | Restrictions | Description | +|-------------------|---------|----------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `action` | boolean | false | | Action is only accepted for project skills and defaults to false. | +| `content` | string | false | | Content must be SKILL.md-format Markdown with YAML frontmatter. The frontmatter must include name, may include description, and must be followed by a non-empty body. | +| `model_invocable` | boolean | false | | Model invocable defaults to true. | ## codersdk.CreateTemplateRequest @@ -14931,11 +14935,13 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ```json { + "action": true, "content": "string", "created_at": "2019-08-24T14:15:22Z", "description": "string", "enabled": true, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", + "model_invocable": true, "name": "string", "updated_at": "2019-08-24T14:15:22Z" } @@ -14943,24 +14949,28 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ### Properties -| Name | Type | Required | Restrictions | Description | -|---------------|---------|----------|--------------|-------------| -| `content` | string | false | | | -| `created_at` | string | false | | | -| `description` | string | false | | | -| `enabled` | boolean | false | | | -| `id` | string | false | | | -| `name` | string | false | | | -| `updated_at` | string | false | | | +| Name | Type | Required | Restrictions | Description | +|-------------------|---------|----------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| +| `action` | boolean | false | | Action reports whether a project skill is offered as a one-click action above project composers. It is always false for personal and organization skills. | +| `content` | string | false | | | +| `created_at` | string | false | | | +| `description` | string | false | | | +| `enabled` | boolean | false | | | +| `id` | string | false | | | +| `model_invocable` | boolean | false | | Model invocable reports whether agents can discover and load the skill on their own. Users can still invoke a skill explicitly when it is false. | +| `name` | string | false | | | +| `updated_at` | string | false | | | ## codersdk.SkillMetadata ```json { + "action": true, "created_at": "2019-08-24T14:15:22Z", "description": "string", "enabled": true, "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", + "model_invocable": true, "name": "string", "updated_at": "2019-08-24T14:15:22Z" } @@ -14968,14 +14978,16 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ### Properties -| Name | Type | Required | Restrictions | Description | -|---------------|---------|----------|--------------|-------------| -| `created_at` | string | false | | | -| `description` | string | false | | | -| `enabled` | boolean | false | | | -| `id` | string | false | | | -| `name` | string | false | | | -| `updated_at` | string | false | | | +| Name | Type | Required | Restrictions | Description | +|-------------------|---------|----------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| +| `action` | boolean | false | | Action reports whether a project skill is offered as a one-click action above project composers. It is always false for personal and organization skills. | +| `created_at` | string | false | | | +| `description` | string | false | | | +| `enabled` | boolean | false | | | +| `id` | string | false | | | +| `model_invocable` | boolean | false | | Model invocable reports whether agents can discover and load the skill on their own. Users can still invoke a skill explicitly when it is false. | +| `name` | string | false | | | +| `updated_at` | string | false | | | ## codersdk.SlimRole @@ -17357,17 +17369,21 @@ The cursor is owner-scoped, so only the chat owner may set this. Opening a chat' ```json { + "action": true, "content": "string", - "enabled": true + "enabled": true, + "model_invocable": true } ``` ### Properties -| Name | Type | Required | Restrictions | Description | -|-----------|---------|----------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `content` | string | false | | Content must be SKILL.md-format Markdown with YAML frontmatter. The frontmatter must include name, may include description, and must be followed by a non-empty body. | -| `enabled` | boolean | false | | | +| Name | Type | Required | Restrictions | Description | +|-------------------|---------|----------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `action` | boolean | false | | Action is only accepted for project skills. | +| `content` | string | false | | Content must be SKILL.md-format Markdown with YAML frontmatter. The frontmatter must include name, may include description, and must be followed by a non-empty body. | +| `enabled` | boolean | false | | | +| `model_invocable` | boolean | false | | | ## codersdk.UpdateTemplateACL diff --git a/enterprise/audit/table.go b/enterprise/audit/table.go index 81dcd1c0d57..6face7ee431 100644 --- a/enterprise/audit/table.go +++ b/enterprise/audit/table.go @@ -606,6 +606,8 @@ var auditableResourcesTypes = map[any]map[string]Action{ "description": ActionTrack, "content": ActionTrack, "enabled": ActionTrack, + "action": ActionTrack, + "model_invocable": ActionTrack, "group_acl": ActionTrack, "user_acl": ActionTrack, "created_at": ActionIgnore, @@ -620,6 +622,8 @@ var auditableResourcesTypes = map[any]map[string]Action{ "description": ActionTrack, "content": ActionTrack, "enabled": ActionTrack, + "action": ActionTrack, + "model_invocable": ActionTrack, "group_acl": ActionTrack, "user_acl": ActionTrack, "created_at": ActionIgnore, @@ -634,6 +638,8 @@ var auditableResourcesTypes = map[any]map[string]Action{ "description": ActionTrack, "content": ActionTrack, "enabled": ActionTrack, + "action": ActionTrack, + "model_invocable": ActionTrack, "group_acl": ActionTrack, "user_acl": ActionTrack, "created_at": ActionIgnore, diff --git a/site/src/api/queries/organizationSkills.test.ts b/site/src/api/queries/organizationSkills.test.ts index 41c47bb13a4..4e1b92e4adf 100644 --- a/site/src/api/queries/organizationSkills.test.ts +++ b/site/src/api/queries/organizationSkills.test.ts @@ -27,6 +27,8 @@ const mockAlphaSkill: Skill = { name: "alpha", description: "alpha description", enabled: true, + action: false, + model_invocable: true, content: "---\nname: alpha\n---\nBody\n", created_at: "2026-05-21T00:00:00Z", updated_at: "2026-05-21T00:00:00Z", diff --git a/site/src/api/queries/userSkills.test.ts b/site/src/api/queries/userSkills.test.ts index b72fc9b23dc..9cf1c691ecb 100644 --- a/site/src/api/queries/userSkills.test.ts +++ b/site/src/api/queries/userSkills.test.ts @@ -26,6 +26,8 @@ const makeSkill = (name: string, overrides: Partial = {}): Skill => ({ name, description: `${name} description`, enabled: true, + action: false, + model_invocable: true, content: `---\nname: ${name}\n---\nBody\n`, created_at: "2026-05-21T00:00:00Z", updated_at: "2026-05-21T00:00:00Z", @@ -37,6 +39,8 @@ const toMetadata = (skill: Skill): SkillMetadata => ({ name: skill.name, description: skill.description, enabled: skill.enabled, + action: skill.action, + model_invocable: skill.model_invocable, created_at: skill.created_at, updated_at: skill.updated_at, }); diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index debf1cd2470..5d00cba9133 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -4540,6 +4540,14 @@ export interface CreateSkillRequest { * followed by a non-empty body. */ readonly content: string; + /** + * Action is only accepted for project skills and defaults to false. + */ + readonly action?: boolean; + /** + * ModelInvocable defaults to true. + */ + readonly model_invocable?: boolean; } // From codersdk/organizations.go @@ -9785,6 +9793,18 @@ export interface SkillMetadata { readonly name: string; readonly description: string; readonly enabled: boolean; + /** + * Action reports whether a project skill is offered as a one-click + * action above project composers. It is always false for personal and + * organization skills. + */ + readonly action: boolean; + /** + * ModelInvocable reports whether agents can discover and load the skill + * on their own. Users can still invoke a skill explicitly when it is + * false. + */ + readonly model_invocable: boolean; readonly created_at: string; readonly updated_at: string; } @@ -11085,6 +11105,11 @@ export interface UpdateSkillRequest { */ readonly content?: string; readonly enabled?: boolean; + /** + * Action is only accepted for project skills. + */ + readonly action?: boolean; + readonly model_invocable?: boolean; } // From codersdk/templates.go diff --git a/site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.stories.tsx b/site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.stories.tsx index a6431adb834..65c8bf90c92 100644 --- a/site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.stories.tsx +++ b/site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.stories.tsx @@ -3054,6 +3054,8 @@ export const SlashCompactYieldsToPersonalSkill: Story = { name: "compact", description: "Personal compact skill", enabled: true, + action: false, + model_invocable: true, created_at: "2024-01-01T00:00:00Z", updated_at: "2024-01-01T00:00:00Z", }, diff --git a/site/src/pages/AgentsPage/utils/skills.test.ts b/site/src/pages/AgentsPage/utils/skills.test.ts index 14a57e034f1..3443bd2b290 100644 --- a/site/src/pages/AgentsPage/utils/skills.test.ts +++ b/site/src/pages/AgentsPage/utils/skills.test.ts @@ -24,6 +24,8 @@ const skill = ( name, description, enabled: true, + action: false, + model_invocable: true, created_at: now, updated_at: now, }); diff --git a/site/src/testHelpers/skills.ts b/site/src/testHelpers/skills.ts index 9643ad9b034..79dfeb87405 100644 --- a/site/src/testHelpers/skills.ts +++ b/site/src/testHelpers/skills.ts @@ -6,6 +6,8 @@ export const MockSkill: SkillMetadata = { name: "skill", description: "", enabled: true, + action: false, + model_invocable: true, created_at: MOCK_TIMESTAMP, updated_at: MOCK_TIMESTAMP, };
FieldTracked
actionYes
contentYes
created_atNo
descriptionYes
enabledYes
group_aclYes
idYes
model_invocableYes
nameYes
organization_idYes
project_idYes