Repository navigation
feat: add chat project instructions API - #30368
Conversation
…oject before other chat updates
…l/chat-project-memories # Conflicts: # coderd/database/dump.sql # coderd/database/unique_constraint.go
…drains, and gate memory lists on the memory resource
…to f0ssel/chat-memory-consolidation # Conflicts: # coderd/x/chatd/memory_extract.go
…l/chat-project-memories # Conflicts: # coderd/database/dump.sql # coderd/database/foreign_key_constraint.go # coderd/database/unique_constraint.go # docs/admin/security/audit-logs.md
…to f0ssel/chat-memory-consolidation
… window and reject overlapping mutations
…' into f0ssel/chat-projects-ui-folders
…es in the chat sidebar and composer
# Conflicts: # coderd/chat_routes.go # codersdk/chats.go # site/src/api/typesGenerated.ts
…l/chat-project-memories # Conflicts: # coderd/chat_routes.go # codersdk/chats.go
…to f0ssel/chat-memory-consolidation # Conflicts: # coderd/chat_routes.go
…' into f0ssel/chat-projects-ui-folders # Conflicts: # site/src/pages/AgentsPage/components/AgentCreateForm.tsx # site/src/pages/AgentsPage/components/ChatsSidebar/chats/ChatsPanel.tsx
…del was not shown
…' into f0ssel/chat-projects-ui-folders
…ries to project permission and move-menu failures
…d runs at the cap, and record empty applies as skipped
…' into f0ssel/chat-projects-ui-folders
…d of remounting it
…lete memory bodies
…' into f0ssel/chat-projects-ui-folders
…ope the memory audit docs
…to f0ssel/chat-memory-consolidation
… and overlap name-sorted windows
…' into f0ssel/chat-projects-ui-folders
…l/chat-project-memories # Conflicts: # coderd/x/chatd/ARCHITECTURE.md
…to f0ssel/chat-memory-consolidation
<img width="1506" height="734" alt="Project page" src="https://github.com/user-attachments/assets/bfcfba12-f229-4dfe-87a2-304bc0551ae1" /> Lists the project's unarchived chats below the composer, loaded from `GET /api/v2/chats?project_id=` with infinite scroll. Each row shows the status, title, PR state, owner, and AI Gateway cost (when enabled), with the chat actions menu when the agents layout provides it. Row links keep the sidebar's filter query string. Adds the `projectChats` query factory, whose caches the previous PR keeps in sync. --- Stack (merge top to bottom). #30377 through #29583 are f0ssel's split of the original #29583, and this stack sits on #29583: - #30377 data layer and project dialog (f0ssel) - #30378 new-chat form locked to a project (f0ssel) - #30379 project page route (f0ssel) - #29583 sidebar folders (f0ssel), the base of this stack - #30291 composer frame - #30292 project chat list caches - #30293 project page header - #30294 project chats list 👈 - #30367 instructions storage and prompt injection - #30368 instructions API - #30369 instructions editor dialog - #30370 instructions Details panel --------- Co-authored-by: Garrett Delfosse <delfossegarrett@gmail.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tructions-storage
| Instructions string `json:"instructions"` | ||
| // UpdatedBy is the user who last changed the instructions. It is nil | ||
| // when the instructions are unset or the user was deleted. | ||
| UpdatedBy *MinimalUser `json:"updated_by"` |
There was a problem hiding this comment.
Do we need this in the API? Maybe audit log suffices for now?
There was a problem hiding this comment.
I was planning on having a separate minimal logging of project context changes. I think there will be cases where it will be useful for users to see directly on the project when something changed and by who. Especially, for users who don't have access to audit logs
…igration to 000619
Record PUT and DELETE on chat project instructions in the audit log as a new chat_project_instructions resource. Entries name the project, diff the instruction text, and skip no-op saves and deletes.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0036e4bcc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ion (#30367) Adds storage for project-level instructions in Coder Agents chat projects and injects them into every chat in the project. This is the first of four stacked PRs that replace #30349. A new `chat_project_instructions` table (migration 000613) holds at most one row per project, scoped to the project's organization. It records `updated_by` and cascades on project delete. The dbauthz wrappers authorize against the parent project: read access to get the instructions, update access to upsert or delete them. No new RBAC resource is added; project RBAC comes in a later PR. chatd loads the instructions on every turn, so edits reach existing chats on their next turn. They are added to the system prompt as a `<project-instructions>` block after the memory guidance and before personal instructions, so a user's personal instructions still win a conflict. Subagent chats carry no `project_id`, so they use their root chat's project. A load error other than no rows is logged, and the turn continues without instructions. **What to scrutinize:** the prompt ordering in `buildSystemPrompt`, and the choice to inject per turn rather than snapshot at chat creation. Per-turn injection costs one prompt-cache miss after each edit; the org instructions in #30272 use a creation-time snapshot instead. **Generated** (`make gen` from the migration and `queries/chatprojectinstructions.sql`): `dump.sql`, `models.go`, `querier.go`, `queries.sql.go`, `dbmetrics/querymetrics.go`, `dbmock/dbmock.go`, and the `*_constraint.go` files. `coderd/x/chatd/ARCHITECTURE.md` gets two TODOs for the PR author to replace with the real description, per AGENTS.md. **Validation:** `make gen` leaves no diff. `go test ./coderd/database/dbauthz -run TestMethodTestSuite/TestChats`, `go test ./coderd/x/chatd -run 'SystemPrompt|ProjectInstructions|Memory'`, and `go test ./coderd/database/migrations/...` pass. --- Stack (merge top to bottom). #30377 through #29583 are f0ssel's split of the original #29583, and this stack sits on #29583: - #30377 data layer and project dialog (f0ssel) - #30378 new-chat form locked to a project (f0ssel) - #30379 project page route (f0ssel) - #29583 sidebar folders (f0ssel), the base of this stack - #30291 composer frame - #30292 project chat list caches - #30293 project page header - #30294 project chats list - #30367 instructions storage and prompt injection 👈 - #30368 instructions API - #30369 instructions editor dialog - #30370 instructions Details panel --------- Co-authored-by: Garrett Delfosse <delfossegarrett@gmail.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
# Conflicts: # enterprise/audit/table.go
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
Adds the experimental API for chat project instructions:
GET,PUT, andDELETE /api/experimental/organizations/{organization}/chats/projects/{project}/instructions, behind thechat-projectsexperiment.GETreturns 200 with empty instructions and nullupdated_by/updated_atwhen nothing is set, so clients don't need a 404 path.PUTrequires update access only (the read-back runs under a system context, so a custom role with update but not read can save). It sanitizes the text withSanitizePromptText. It rejects blank text with 400, pointing the caller toDELETE, and rejects text over the chat prompt byte limit. It records the caller asupdated_by. The upsert and the read-back that returns the editor's profile run in one transaction.DELETEreturns 204, including when nothing is set.PUTandDELETEare audited as a newchat_project_instructionsresource (writeanddelete), with the project as the resource ID and its name as the target. The diff tracks only the instruction text. Saving unchanged text and deleting unset instructions are not audited. A per-project advisory lock serializes reading the previous value with the write, so concurrent edits produce accurate diffs. Migration000615adds the enum value.The codersdk client gains
ChatProjectInstructions,UpdateChatProjectInstructions, andDeleteChatProjectInstructions.What to scrutinize: writes are last-writer-wins with no version precondition, matching the deployment, user, and organization prompt settings.
Generated:
coderd/apidoc/docs.go,coderd/apidoc/swagger.json, anddocs/reference/api/schemas.mdcome from the Swagger annotations;site/src/api/typesGenerated.tscomes fromcodersdk;docs/admin/security/audit-logs.md,coderd/database/dump.sql, andcoderd/database/models.gocome from the audit table and migration. Together they are about 400 of this PR's lines.Validation:
make genleaves no diff.go test ./coderd -run TestChatProjectandgo test ./enterprise/coderd -run TestChatProjectInstructionspass.TestChatProjectInstructionsAuditchecks the audit entries for create, update, and delete, and that no-op saves and deletes are not audited. It covers unset GET, create, update, blank and oversized PUT, delete, access denial, and cascade on project delete.Stack (merge top to bottom). #30377 through #29583 are f0ssel's split of the original #29583, and this stack sits on #29583: