Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: make project memories generic by dropping the type enum
Memories keep a name, one-line description, and body. The guidance still
tells the agent what kinds of facts are worth saving, without asking it to
categorize them.
  • Loading branch information
f0ssel committed Sep 11, 2026
commit 032cac3ac6d587d139aff017c276bd7fc86f4a42
27 changes: 1 addition & 26 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 6 additions & 14 deletions coderd/chat_project_memories.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (api *API) postChatProjectMemory(rw http.ResponseWriter, r *http.Request) {
if !httpapi.Read(ctx, rw, r, &req) {
return
}
normalized, resp := validateChatProjectMemory(req.Type, req.Name, req.Description, req.Body)
normalized, resp := validateChatProjectMemory(req.Name, req.Description, req.Body)
if resp != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, *resp)
return
Expand All @@ -82,7 +82,7 @@ func (api *API) postChatProjectMemory(rw http.ResponseWriter, r *http.Request) {
}
aReq, commit := audit.InitRequest[database.ChatProjectMemory](rw, &audit.RequestParams{Audit: *api.Auditor.Load(), Log: api.Logger, Request: r, Action: database.AuditActionCreate, OrganizationID: project.OrganizationID})
defer commit()
memory, err := api.Database.InsertChatProjectMemory(ctx, database.InsertChatProjectMemoryParams{ID: uuid.NullUUID{}, ProjectID: project.ID, OrganizationID: project.OrganizationID, Type: database.ChatProjectMemoryType(normalized.Type), Name: normalized.Name, Description: normalized.Description, Body: normalized.Body, SourceChatID: uuid.NullUUID{}, CreatedBy: apiKey.UserID})
memory, err := api.Database.InsertChatProjectMemory(ctx, database.InsertChatProjectMemoryParams{ID: uuid.NullUUID{}, ProjectID: project.ID, OrganizationID: project.OrganizationID, Name: normalized.Name, Description: normalized.Description, Body: normalized.Body, SourceChatID: uuid.NullUUID{}, CreatedBy: apiKey.UserID})
if database.IsUniqueViolation(err) {
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{Message: "A chat project memory with this name already exists."})
return
Expand Down Expand Up @@ -148,10 +148,6 @@ func (api *API) patchChatProjectMemory(rw http.ResponseWriter, r *http.Request)
if !httpapi.Read(ctx, rw, r, &req) {
return
}
memoryType := codersdk.ChatProjectMemoryType(memory.Type)
if req.Type != nil {
memoryType = *req.Type
}
name := memory.Name
if req.Name != nil {
name = *req.Name
Expand All @@ -164,15 +160,15 @@ func (api *API) patchChatProjectMemory(rw http.ResponseWriter, r *http.Request)
if req.Body != nil {
body = *req.Body
}
normalized, resp := validateChatProjectMemory(memoryType, name, description, body)
normalized, resp := validateChatProjectMemory(name, description, body)
if resp != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, *resp)
return
}
aReq, commit := audit.InitRequest[database.ChatProjectMemory](rw, &audit.RequestParams{Audit: *api.Auditor.Load(), Log: api.Logger, Request: r, Action: database.AuditActionWrite, OrganizationID: project.OrganizationID})
defer commit()
aReq.Old = memory
updated, err := api.Database.UpdateChatProjectMemoryByID(ctx, database.UpdateChatProjectMemoryByIDParams{ID: memory.ID, Type: database.ChatProjectMemoryType(normalized.Type), Name: normalized.Name, Description: normalized.Description, Body: normalized.Body})
updated, err := api.Database.UpdateChatProjectMemoryByID(ctx, database.UpdateChatProjectMemoryByIDParams{ID: memory.ID, Name: normalized.Name, Description: normalized.Description, Body: normalized.Body})
if database.IsUniqueViolation(err) {
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{Message: "A chat project memory with this name already exists."})
return
Expand Down Expand Up @@ -222,28 +218,24 @@ func (api *API) deleteChatProjectMemory(rw http.ResponseWriter, r *http.Request)

type normalizedChatProjectMemory struct {
Name string
Type codersdk.ChatProjectMemoryType
Description string
Body string
}

func validateChatProjectMemory(memoryType codersdk.ChatProjectMemoryType, name, description, body string) (normalizedChatProjectMemory, *codersdk.Response) {
func validateChatProjectMemory(name, description, body string) (normalizedChatProjectMemory, *codersdk.Response) {
name = strings.ToLower(strings.TrimSpace(name))
description = chattool.NormalizeProjectMemoryText(description)
body = chattool.NormalizeProjectMemoryText(body)
if err := chattool.ValidateProjectMemoryName(name); err != nil {
return normalizedChatProjectMemory{}, &codersdk.Response{Message: err.Error()}
}
if !database.ChatProjectMemoryType(memoryType).Valid() {
return normalizedChatProjectMemory{}, &codersdk.Response{Message: "Invalid chat project memory type."}
}
if description == "" || utf8.RuneCountInString(description) > chattool.MaxProjectMemoryDescriptionChars {
return normalizedChatProjectMemory{}, &codersdk.Response{Message: "description must be at most 150 characters."}
}
if body == "" || len(body) > chattool.MaxProjectMemoryBodyBytes {
return normalizedChatProjectMemory{}, &codersdk.Response{Message: "body must be at most 8192 bytes."}
}
return normalizedChatProjectMemory{Name: name, Type: memoryType, Description: description, Body: body}, nil
return normalizedChatProjectMemory{Name: name, Description: description, Body: body}, nil
}

func rbacMemoryObject(organizationID uuid.UUID) database.ChatProjectMemory {
Expand Down
4 changes: 0 additions & 4 deletions coderd/chat_project_memories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestChatProjectMemoriesCRUD(t *testing.T) {
project := createChatProject(t, client, firstUser.OrganizationID, "Memory Project")

created, err := client.CreateChatProjectMemory(ctx, project.ID, codersdk.CreateChatProjectMemoryRequest{
Type: codersdk.ChatProjectMemoryTypeProject,
Name: "release-process",
Description: "Release process notes",
Body: "Use the release checklist before tagging.",
Expand All @@ -48,7 +47,6 @@ func TestChatProjectMemoriesCRUD(t *testing.T) {
require.Equal(t, updatedDescription, updated.Description)

_, err = client.CreateChatProjectMemory(ctx, project.ID, codersdk.CreateChatProjectMemoryRequest{
Type: codersdk.ChatProjectMemoryTypeProject,
Name: "release-process",
Description: "Duplicate",
Body: "Duplicate body.",
Expand Down Expand Up @@ -84,14 +82,12 @@ func TestChatProjectMemoryCap(t *testing.T) {
OrganizationID: firstUser.OrganizationID,
CreatedBy: firstUser.UserID,
Name: "memory-" + uuid.NewString() + string(rune('a'+i%26)),
Type: database.ChatProjectMemoryTypeProject,
Description: "Seeded memory",
Body: "Seeded durable memory.",
})
}

_, err := client.CreateChatProjectMemory(ctx, project.ID, codersdk.CreateChatProjectMemoryRequest{
Type: codersdk.ChatProjectMemoryTypeProject,
Name: "one-too-many",
Description: "Too many memories",
Body: "This should be rejected.",
Expand Down
1 change: 0 additions & 1 deletion coderd/database/db2sdk/db2sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,6 @@ func convertChatProjectMemory(memory database.ChatProjectMemory, createdByUserna
ID: memory.ID,
ProjectID: memory.ProjectID,
OrganizationID: memory.OrganizationID,
Type: codersdk.ChatProjectMemoryType(memory.Type),
Name: memory.Name,
Description: memory.Description,
Body: memory.Body,
Expand Down
1 change: 0 additions & 1 deletion coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func ChatProjectMemory(t testing.TB, db database.Store, seed database.ChatProjec
ID: uuid.NullUUID{UUID: seed.ID, Valid: seed.ID != uuid.Nil},
ProjectID: takeFirst(seed.ProjectID, uuid.New()),
OrganizationID: takeFirst(seed.OrganizationID, uuid.New()),
Type: takeFirst(seed.Type, database.ChatProjectMemoryTypeProject),
Name: takeFirst(seed.Name, testutil.GetRandomName(t)),
Description: seed.Description,
Body: seed.Body,
Expand Down
8 changes: 0 additions & 8 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ DROP TABLE chat_project_memory_cursors;
DROP INDEX idx_chat_project_memories_project_updated_at;
DROP INDEX idx_chat_project_memories_project_lower_name;
DROP TABLE chat_project_memories;
DROP TYPE chat_project_memory_type;
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'chat_project_memory:read';
ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'chat_project_memory:update';
ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'chat_project_memory:delete';

CREATE TYPE chat_project_memory_type AS ENUM ('user', 'feedback', 'project', 'reference');

CREATE TABLE chat_project_memories (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
project_id uuid NOT NULL REFERENCES chat_projects(id) ON DELETE CASCADE,
organization_id uuid NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
type chat_project_memory_type NOT NULL,
name text NOT NULL,
description text NOT NULL,
body text NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ INSERT INTO chat_project_memories (
id,
project_id,
organization_id,
type,
name,
description,
body,
Expand All @@ -12,7 +11,6 @@ VALUES (
'59500000-0000-4000-8000-000000000001',
'59400000-0000-4000-8000-000000000001',
'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1',
'project',
'fixture-memory',
'Fixture project memory.',
'This memory exists for migration fixtures.',
Expand Down
85 changes: 10 additions & 75 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading