feat: report pinned chat context resources on chat API - #26570
Merged
Conversation
Surface a chat's pinned workspace-context resources (instruction files,
skills, and MCP configs/servers) on the single-chat GET and refresh
responses, metadata only (no bodies). Each resource carries its
per-resource status so the UI can explain why a resource was dropped from
the prompt instead of silently omitting it.
- codersdk: add ChatContextResource{,Kind,Status} and ChatContextMCPTool;
add Chat.Context.Resources, populated only on the single-chat GET.
- coderd/x/chatd: add Server.ContextResources, building the metadata-only
list from the chat's pinned chat_context_resources rows; extract the
shared protojson body decoders so the prompt and detail paths share them.
- coderd: enrich the getChat and refreshChatContext responses with the
resource list (non-fatal on error; list/watch payloads stay lightweight).
Split from #26466. The pinned-context drift diff (the per-source change
set and "View changes" UI) is deferred to a later split; this PR reports
only the resource inventory, with the existing dirty bit still signaling
that context changed.
Docs preview📖 View docs preview for |
…prompt.go Consolidate the chat context resource listing (ContextResources, pinnedContextResources, contextResourceKind) into context_prompt.go next to the prompt builder, removing context_detail.go. The two paths walk the same pinned rows and now share the body decode-and-validate helpers (decodeInstructionContent, decodeSkillIdentity), so an instruction file or skill is interpreted identically whether it feeds the prompt or the API resource list. Tests move alongside the code; no behavior change.
…ce field to Tools Name the pinned-context tool type and the ChatContextResource field generically rather than MCP-specific, since the field hangs off the generic resource and may carry tools from other sources later. Regenerate apidoc, swagger, docs, and typesGenerated.ts.
sreya
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Surfaces a chat's pinned workspace-context resources on the single-chat GET and refresh responses, so clients can show what context the prompt was built from, not just whether it drifted.
What's included
ChatContextResource(plusChatContextResourceKindandChatContextResourceStatus) andChatContextMCPTool, and a newChat.Context.Resourcesfield (metadata only, no bodies). It is populated only on the single-chat GET/refresh response; list and watch payloads stay nil to remain lightweight.Server.ContextResources, which builds the metadata-only list from the chat's pinnedchat_context_resourcesrows. Non-OK resources (invalid / unreadable / oversize / excluded) are reported with their status and error so the UI can explain why a resource was dropped from the prompt instead of silently omitting it. The shared protojson body decoders are extracted so the prompt and detail paths reuse them.getChatandrefreshChatContextenrich the response with the resource list. Failures are non-fatal (the chat stays usable without the detail).Scope / what's deferred
This is an incremental split from #26466. This PR reports only the resource inventory. The pinned-context drift diff (the per-source
changesset and the "View changes" dialog) is intentionally deferred to a later split; the existingdirtybit already signals that context changed. MCP resources are reported for display only; they are not injected into the prompt (a future RFC item).Design notes
source ASCorder. OK-but-empty instruction files, OK skills with no name, and untracked kinds (reserved plugin/hook/subagent/command) are skipped."<server>__"prefix stripped so they read as the server exposes them.refreshChatContextenriches its own response (mirroringgetChat) so the client reflects a refresh immediately, without a full reload.Testing
go test ./coderd/x/chatd/ -run 'TestPinnedContextResources|TestContextResources|TestChatContextDirtyFromAgentPush'(unit + integration on embedded Postgres) passes. The integration test exercises the GET and refresh enrichment end-to-end.go build,go vet,golangci-lint, andgofmtare clean.make genregeneratedapidoc,swagger.json,docs/reference/api/*, andtypesGenerated.ts.This PR was created by Coder Agents on behalf of @kylecarbs.