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:
Michael Suchacz
2026-04-14 10:50:40 +02:00
committed by GitHub
parent 116323d3cf
commit a554de372a
15 changed files with 1708 additions and 33 deletions
+20 -3
View File
@@ -11,6 +11,7 @@ import (
type WriteFileOptions struct {
GetWorkspaceConn func(context.Context) (workspacesdk.AgentConn, error)
ResolvePlanPath func(context.Context) (chatPath string, home string, err error)
}
type WriteFileArgs struct {
@@ -30,7 +31,7 @@ func WriteFile(options WriteFileOptions) fantasy.AgentTool {
if err != nil {
return fantasy.NewTextErrorResponse(err.Error()), nil
}
return executeWriteFileTool(ctx, conn, args)
return executeWriteFileTool(ctx, conn, args, options.ResolvePlanPath)
},
)
}
@@ -39,12 +40,28 @@ func executeWriteFileTool(
ctx context.Context,
conn workspacesdk.AgentConn,
args WriteFileArgs,
resolvePlanPath func(context.Context) (chatPath string, home string, err error),
) (fantasy.ToolResponse, error) {
if args.Path == "" {
requestedPath := strings.TrimSpace(args.Path)
if requestedPath == "" {
return fantasy.NewTextErrorResponse("path is required"), nil
}
if err := conn.WriteFile(ctx, args.Path, strings.NewReader(args.Content)); err != nil {
hasPlanFileName := looksLikePlanFileName(requestedPath)
if hasPlanFileName && !isAbsolutePath(requestedPath) {
return fantasy.NewTextErrorResponse(
"plan files must use absolute paths; use the chat-specific absolute plan path",
), nil
}
if resolvePlanPath != nil && hasPlanFileName {
chatPath, home, err := resolvePlanPath(ctx)
if resp, rejected := rejectSharedPlanPath(requestedPath, home, chatPath, err); rejected {
return resp, nil
}
}
if err := conn.WriteFile(ctx, requestedPath, strings.NewReader(args.Content)); err != nil {
return fantasy.NewTextErrorResponse(err.Error()), nil
}
return toolResponse(map[string]any{"ok": true}), nil