mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user