🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

feat: report pinned chat context resources on chat API - #26570

Merged
kylecarbs merged 3 commits into
mainfrom
kylecarbs/chatd-context-resources
Jun 22, 2026
Merged

feat: report pinned chat context resources on chat API#26570
kylecarbs merged 3 commits into
mainfrom
kylecarbs/chatd-context-resources

Conversation

@kylecarbs

Copy link
Copy Markdown
Member

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

  • codersdk: ChatContextResource (plus ChatContextResourceKind and ChatContextResourceStatus) and ChatContextMCPTool, and a new Chat.Context.Resources field (metadata only, no bodies). It is populated only on the single-chat GET/refresh response; list and watch payloads stay nil to remain lightweight.
  • coderd/x/chatd: Server.ContextResources, which builds the metadata-only list from the chat's pinned chat_context_resources rows. 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.
  • coderd: getChat and refreshChatContext enrich 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 changes set and the "View changes" dialog) is intentionally deferred to a later split; the existing dirty bit 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
  • The resource list is the chat's full pinned inventory (instruction files, skills, and MCP configs/servers), preserving the query's source ASC order. OK-but-empty instruction files, OK skills with no name, and untracked kinds (reserved plugin/hook/subagent/command) are skipped.
  • MCP tool names are reported with the agent's "<server>__" prefix stripped so they read as the server exposes them.
  • The detail is computed on read and attached only on the single-chat GET and refresh responses; list and watch payloads omit it to stay lightweight.
  • refreshChatContext enriches its own response (mirroring getChat) 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, and gofmt are clean.
  • make gen regenerated apidoc, swagger.json, docs/reference/api/*, and typesGenerated.ts.

This PR was created by Coder Agents on behalf of @kylecarbs.

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.
@github-actions

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/reference/api/chats.md

@datadog-coder

datadog-coder Bot commented Jun 22, 2026

Copy link
Copy Markdown

Pipelines

⚠️ Warnings

🚦 1 Pipeline job failed

weekly-docs | audit-docs-paths   View in Datadog   GitHub Actions

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e43af2a | Docs | Give us feedback!

@kylecarbs kylecarbs changed the title feat(coderd): report pinned chat context resources on chat API feat: report pinned chat context resources on chat API Jun 22, 2026
…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.
@kylecarbs
kylecarbs merged commit c0f854c into main Jun 22, 2026
37 of 40 checks passed
@kylecarbs
kylecarbs deleted the kylecarbs/chatd-context-resources branch June 22, 2026 16:00
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants