Files
coder/coderd/x/chatd/chattool/planpathmessage.go
T
Michael Suchacz a554de372a fix: use per-chat plan file paths (#24268)
> This PR was authored by Mux on behalf of Mike.

Chats sharing one workspace (e.g. sibling subagents) all wrote to
`/home/coder/PLAN.md`, causing plan file collisions. This change derives
a unique plan path per chat from the workspace home directory and chat
ID.

## Changes

* `write_file`, `edit_files`, and `propose_plan` reject any `plan.md`
variant (case-insensitive) at the workspace home root, with a clear
error pointing to the chat-specific path.
* Root chats receive a `<plan-file-path>` block inlined in the main
system prompt with the concrete path.
* Prompt and tool descriptions no longer hardcode `/home/coder/PLAN.md`.
* Plan path handling is POSIX-only (forward-slash), relying on the
contract that workspace agent paths are normalized before reaching
chatd.
* Updated `ProposePlanTool.stories.tsx` to use per-chat path examples.
* Full test coverage for plan path detection, legacy-path rejection in
all three tools, inline prompt rendering, and fallback behavior.
2026-04-14 10:50:40 +02:00

55 lines
1.5 KiB
Go

package chattool
import (
"fmt"
"charm.land/fantasy"
)
// rejectSharedPlanPath reports whether requestedPath targets the shared
// home-root plan file and, if so, returns a rejection response that
// points callers at the chat-specific plan path.
func rejectSharedPlanPath(
requestedPath string,
home string,
chatPath string,
planPathErr error,
) (fantasy.ToolResponse, bool) {
if planPathErr != nil {
// When the resolver fails, we cannot determine the actual
// home directory. Fall back to rejecting only the exact
// legacy shared path (case-insensitive) rather than every
// file named plan.md.
if !looksLikeLegacySharedPlanPath(requestedPath) {
return fantasy.ToolResponse{}, false
}
return fantasy.NewTextErrorResponse(
planPathVerificationMessage(requestedPath),
), true
}
if !LooksLikeHomePlanFile(requestedPath, home) && !looksLikeLegacySharedPlanPath(requestedPath) {
return fantasy.ToolResponse{}, false
}
return fantasy.NewTextErrorResponse(
sharedPlanPathMessage(requestedPath, chatPath),
), true
}
func sharedPlanPathMessage(requestedPath, chatPath string) string {
return fmt.Sprintf(
"the plan path %s is no longer supported at the home root; use the chat-specific plan path: %s",
requestedPath,
chatPath,
)
}
func planPathVerificationMessage(requestedPath string) string {
return fmt.Sprintf(
"the plan path %s could not be verified because the workspace is currently unavailable to resolve the chat-specific plan path, try again shortly",
requestedPath,
)
}