feat: add chat context source CLI and agent-token refresh - #26577
Merged
Conversation
Add `coder exp chat context` subcommands for managing the workspace context sources the agent resolves, over its local IPC socket: - list: show the registered scan roots - show <path>: show a source and the resources it contributes - add <path>: register a source, or with --chat keep the legacy one-shot inject into a single chat - remove <path>: unregister a source - refresh [<chat>]: re-pin a chat to the agent's latest snapshot With a <chat> argument, refresh uses the existing user-facing endpoint. With no argument it runs inside the workspace: it re-resolves the agent's sources over the context socket, then asks the agent (using its own token) to re-pin every drifted chat. That path adds agentsdk.RefreshChatContext and the POST /api/v2/workspaceagents/me/experimental/chat-context/refresh handler, mirroring the clear endpoint's auth model, covered by TestChatContextRefreshFromAgentToken. Split from #26466. The context changes/diff view is deferred to the final split.
This comment has been minimized.
This comment has been minimized.
…osts resolveContextSourcePath used filepath.Abs, which is host-OS specific: on a Windows CLI host a POSIX absolute path like /home/coder/AGENTS.md is not absolute, so filepath.Abs prepended the drive and produced C:\home\coder\AGENTS.md, failing TestResolveContextSourcePath on windows-2022. The agent's filesystem is always POSIX, so a leading / is already workspace-absolute. Clean and pass it through, reserving filepath.Abs for relative paths. This also renames the one-shot helper's path parameter to dir to avoid shadowing the new path import.
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.
Adds the
coder exp chat contextCLI for managing workspace context sources, plus the agent-token refresh endpoint the in-workspace refresh relies on. Part of breaking the "Workspace Context Sources for Coder Agents" RFC (#26466) into small, reviewable PRs.What this adds
CLI (
coder exp chat context), talking to the agent's local IPC socket from inside the workspace:listlists the registered scan roots (built-in defaults are not shown).show <path>shows a source and the resources the agent resolves from it, including failures.add <path>registers a path as an additional context source. With--chat, it keeps the legacy one-shot behavior (read context from the path once and inject it into a single chat).remove <path>unregisters a source.refresh [<chat>]re-pins chat context to the agent's latest snapshot.Agent-token refresh path for the no-argument
refresh:refresh <chat>uses the existing user-facingExperimentalClient.RefreshChatContext(already on main) and works from anywhere.refreshwith no argument runs inside the workspace: it re-resolves the agent's sources over the context socket (catching freshly-cloned repos and startup-script writes), then asks the agent, authenticating with its own token, to re-pin every drifted chat. Nocoder loginrequired.agentsdk.RefreshChatContextandPOST /api/v2/workspaceagents/me/experimental/chat-context/refresh(workspaceAgentRefreshChatContext), mirroring the existing clear endpoint's agent-token auth model.Testing
go test ./cli(TestExpChatContextAdd,TestParseChatID,TestResolveContextSourcePath)go test ./coderd/x/chatd -run TestChatContextRefreshFromAgentToken(end-to-end: echo-provisioned agent pushes a snapshot, drifts a bound chat, the agent-token refresh re-pins it, and an agent-less chat stays untouched)go build ./...,go vet,golangci-lint,make gen(no generated changes; experimental commands are excluded from CLI golden/doc generation)Design notes
This is Split 4 of #26466. Split sequence:
codersdkcontext resource types (merged)changes,ChatContextResourceChange, the changes dialog,buildContentPatch) - last.Key points:
agent/agentsocketIPC for source CRUD, snapshot, resync), the user-facingExperimentalClient.RefreshChatContext, and the per-chatchatd.RefreshChatContextall already exist on main, so this split is the CLI surface plus the small agent-token refresh endpoint that fans out per-chat refresh across an agent's drifted chats.add <path>resolves relative paths to absolute before handing them to the agent (which requires canonical paths) but preserves a leading~for the agent to expand against its own home.TestResolveContextSourcePathcovers this.@x-apidocgen {"skip": true}, matching the other agent-token chat-context endpoints.This PR was created by Coder Agents on behalf of @kylecarbs.