Repository navigation
feat: add plan mode with restricted tool boundary - #24236
Conversation
c4bb5c6 to
485e020
Compare
6b8948f to
b069f01
Compare
f2311be to
2a723e2
Compare
8918ef3 to
008233e
Compare
Documentation CheckUpdates Needed
New Documentation Needed
Automated review via Coder Tasks |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 008233e2e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
d6c0bf1 to
8203c24
Compare
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8203c24dcd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8203c24 to
f8d521d
Compare
Adds a chat-level plan mode that restricts the LLM to read-only investigation and a single writable plan artifact. The mode is stored on the chats table and persists across page reloads and turns. Backend: - Database migration 000469 adds chat_plan_mode enum and plan_mode column - Plan mode gates tools via allowedPlanToolNames() and stopAfterPlanTools() - PlanningOverlayPrompt with dynamic plan file path via ResolvePlanPath - Tool restrictions: write_file/edit_files limited to plan path - ask_user_question tool for structured clarification during planning - Chat PATCH API supports plan_mode field for toggling - Moved propose_plan references out of default prompt into plan-mode overlay - Plan turns stop after both propose_plan and ask_user_question Frontend: - Plan mode toggle in AgentChatPage from chat.plan_mode query state - updateChatPlanMode mutation with optimistic cache updates - AskUserQuestionTool wizard UI with radio options and keyboard support - ConversationTimeline reconstructs answered-question views - PlanModeInstructionsSettings for admin deployment-wide instructions
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de2c024435
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review
|
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0ab8353d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
@codex review Latest push relaxes plan mode so root chats and subagents can use |
|
@codex review
Please review the latest push. |
Requesting a fresh exact Codex trigger because the previous comments included extra text and may not have matched the repository's expected trigger format. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e736ab6a24
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
|
|
||
| const DEFAULT_CHAT_PAGE_LIMIT = 50; | ||
| const nilUUID = "00000000-0000-0000-0000-000000000000"; |
There was a problem hiding this comment.
i think this is probably a bad use of nilUUID const re-defining
| planMode?: ChatPlanModeOrClear; | ||
| }; | ||
|
|
||
| const clearPlanMode = "" satisfies ChatPlanModeOrClear; |
There was a problem hiding this comment.
this feels wrong, why is clear plan mode an empty string?
| let latestAskUserQuestionToolId: string | undefined; | ||
| let hasUserResponseAfterAskQuestion = false; | ||
| const askUserQuestionResponseTextByToolId = new Map<string, string>(); | ||
| let pendingAskUserQuestionToolId: string | undefined; | ||
| for (const { message, parsed } of parsedMessages) { | ||
| let askUserQuestionToolIdInMessage: string | undefined; | ||
| for (const tool of parsed.tools) { | ||
| if (tool.name === "ask_user_question") { | ||
| askUserQuestionToolIdInMessage = tool.id; | ||
| latestAskUserQuestionToolId = tool.id; | ||
| hasUserResponseAfterAskQuestion = false; | ||
| } | ||
| } | ||
|
|
||
| if (askUserQuestionToolIdInMessage) { | ||
| pendingAskUserQuestionToolId = askUserQuestionToolIdInMessage; | ||
| } | ||
|
|
||
| if (pendingAskUserQuestionToolId && message.role === "user") { | ||
| hasUserResponseAfterAskQuestion = | ||
| pendingAskUserQuestionToolId === latestAskUserQuestionToolId; | ||
| const responseText = getChatMessageTextContent(message.content); | ||
| if (responseText !== undefined) { | ||
| askUserQuestionResponseTextByToolId.set( | ||
| pendingAskUserQuestionToolId, | ||
| responseText, | ||
| ); | ||
| } | ||
| pendingAskUserQuestionToolId = undefined; | ||
| } | ||
| } | ||
| const historicalAskUserQuestionResponseTextByToolId = | ||
| askUserQuestionResponseTextByToolId.size > 0 | ||
| ? askUserQuestionResponseTextByToolId | ||
| : undefined; | ||
|
|
There was a problem hiding this comment.
We're massively bloating the complexity of this component. This can cause React Compiler to bail out. Please move some/most of this out into a helper.
| const cloneAnswer = ( | ||
| answer: QuestionAnswer | undefined, | ||
| ): QuestionAnswer | undefined => { | ||
| if (!answer) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (answer.kind === "other") { | ||
| return { kind: "other", text: answer.text }; | ||
| } | ||
|
|
||
| return { | ||
| kind: "option", | ||
| label: answer.label, | ||
| optionIndex: answer.optionIndex, | ||
| }; | ||
| }; |
There was a problem hiding this comment.
is this just a hand-rolled structuredClone? https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
| .join("\n"); | ||
| }; | ||
|
|
||
| export const AskUserQuestionTool: FC<AskUserQuestionToolProps> = ({ |
There was a problem hiding this comment.
this entire component is a bit of a mess.
- We should be using
formik - We're manually adding
setIsSubmitting. Again, formik and mutation helpers help here - We have a
mapcall where the content should absolutely be pulled out into a separate component. - There are more issues but I'd be here all day so pls get your agent to do this properly
| const handleImplementPlanClick = async () => { | ||
| if (!onImplementPlan || isSubmitting) { | ||
| return; | ||
| } | ||
| setIsSubmitting(true); | ||
| try { | ||
| await onImplementPlan(); | ||
| setIsSubmitting(false); | ||
| } catch { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; |
There was a problem hiding this comment.
setIsSubmitting no. Proper useMutation work should avoid this.
Your agent should look at how we handle this elsewhere, because I think this is probably wrong.
| const toolBadgeClassName = | ||
| "inline-flex shrink-0 items-center gap-1 rounded-full bg-surface-secondary px-2 py-0.5 text-xs font-medium text-content-secondary"; |
There was a problem hiding this comment.
We should never be promoting class variable names up like this. Inline this where it is used.
| const planModeInvisibleCharCount = countInvisibleCharacters( | ||
| form.values.plan_mode_instructions, | ||
| ); | ||
| const planModeInvisibleCharWarning = `This text contains ${planModeInvisibleCharCount} invisible Unicode ${planModeInvisibleCharCount !== 1 ? "characters" : "character"} that could hide content. These will be stripped on save.`; |
There was a problem hiding this comment.
why is this a variable? just inline it
> This PR was authored by Mux on behalf of Mike. Address all 8 frontend review comments from DanielleMaywood on #24236. ## Changes **Low-risk cleanups:** - Inlined module-level `toolBadgeClassName` in `AgentChatInput.tsx` - Inlined `planModeInvisibleCharWarning` variable in `PlanModeInstructionsSettings.tsx` - Replaced loose `nilUUID` and `clearPlanMode` sentinels in `chats.ts` with a `toChatPlanModePayload()` helper and inline nil UUID. Page-level mutation callers now pass `undefined` to clear plan mode instead of `""`. **Tool state management:** - Replaced manual `isSubmitting`/`setIsSubmitting` in `ProposePlanTool.tsx` with `useMutation` - Overhauled `AskUserQuestionTool.tsx`: replaced `cloneAnswer` with `structuredClone`, replaced `setIsSubmitting` with `useMutation`, extracted `QuestionStep`, `QuestionOption`, `OtherQuestionOption`, and `AnsweredQuestionText` components **Timeline complexity reduction:** - Extracted `deriveMessageDisplayState()` into `messageHelpers.ts` (pure, testable) - Extracted user-message rendering into `UserMessageContent.tsx` - Reduced `ConversationTimeline.tsx` by ~285 lines ## Validation - TypeScript: pass - Lint (Biome + ESLint): pass - React Compiler: 247 functions, 0 diagnostics - Storybook tests: 42/42 pass (ProposePlanTool 9, ConversationTimeline 22, AskUserQuestionTool 11)
`attach_file` was registered for plan-mode turns but never added to `builtinPlanToolAllowed`, so the per-turn `ActiveTools` allowlist filtered it out and calls failed with `Tool not active in this turn: attach_file`. This was an omission rather than a deliberate block — the tool (#24280) landed shortly after plan mode (#24236) and no subsequent edit to the allowlist picked it up. Add `attach_file` under the `isRootChat` case, matching how other artifact-producing tools (`propose_plan`, `write_file`, `edit_files`) are gated. The tool only reads from the workspace and writes to chat-attachment storage, so it preserves plan mode's invariant of not making implementation changes to the workspace. Subagents in plan mode remain restricted to the minimal read-only surface.
…be resolved (#30983) Removes the 404 bypass from the plan-turn symlink guard in `write_file` and `edit_files`. `ensurePlanPathResolvesToItself` treated a 404 from the agent's `resolve-path` endpoint as success, so a plan turn on an agent without that endpoint wrote the plan file with no symlink check. Now every `ResolvePath` error fails the tool call. The PR deletes the status predicate and its `net/http` import, the two tests that expected a write after a 404, and the test-only `statusError` file. The PR adds 77 lines and removes 147. **Behavior change, approved by Mike:** an agent too old to serve the `resolve-path` endpoint can no longer write plan files during plan turns. The tool returns `resolve plan path: ...` instead. The endpoint arrived with plan mode in #24236. Coder does not support mixed coderd and agent versions, and upgrades happen in maintenance windows. **Why it is safe:** the agent's `resolve-path` handler never answers 404. It returns 400 for a relative path, 403 for a permission error, and 500 for other errors, and it resolves a path whose last components do not exist yet, such as a new plan file. So a 404 means that the route is missing. - In each tool's tests, the symlink case is now a table with three more rows: a 404 and a 500 built with `codersdk.NewError`, and a connection error without a status code. No row expects a write, and the strict gomock controller fails on any `WriteFile` or `EditFiles` call. - With the old resolver (`go test -overlay`), the 404 row fails for both tools. - A mutant that ignores every `ResolvePath` error fails all three error rows for both tools. On `main`, the whole `chattool` package passes with that mutant. - A mutant that ignores only errors without a status code, such as a dropped connection, fails the connection error row for both tools. Without that row, both tools' tests pass with it. - The success, shared plan path, and mixed-path tests do not change and pass. **Review focus:** the behavior change. Only `write_file` and `edit_files` call the guard. `propose_plan` does not call `ResolvePath`, and this PR does not change it. Validation: `go test ./coderd/x/chatd/chattool -count=1` passes, `go vet ./coderd/x/chatd/chattool` is clean, and the pre-commit hook passed. > Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.
Summary
ask_user_questionandpropose_planwrite_fileandedit_filesconstrained to the chat-specific plan file during plan turnsexecuteandprocess_output