Skip to content

feat: add plan mode with restricted tool boundary - #24236

Merged
ibetitsmike merged 28 commits into
mainfrom
mike/plan-mode-turn-scoped
Apr 16, 2026
Merged

ibetitsmike merged 28 commits into
mainfrom
mike/plan-mode-turn-scoped

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Apr 10, 2026 •

Copy link
Copy Markdown
Collaborator

This PR was authored by Mux on behalf of Mike.

Summary

  • add persistent plan mode for chats and the chat-specific plan file flow
  • add structured planning tools such as ask_user_question and propose_plan
  • keep write_file and edit_files constrained to the chat-specific plan file during plan turns
  • allow shell exploration in plan mode, including subagents, via execute and process_output
  • block implementation-oriented, provider-native, MCP, dynamic, and computer-use tools during plan turns
  • update the chat UI, tests, and docs for the new planning flow

@ibetitsmike
ibetitsmike force-pushed the mike/plan-mode-turn-scoped branch from c4bb5c6 to 485e020 Compare April 10, 2026 14:25
@ibetitsmike ibetitsmike changed the title feat(coderd/x/chatd): add turn-scoped plan mode feat: add turn-scoped plan mode for chat Apr 10, 2026
@ibetitsmike
ibetitsmike force-pushed the mike/plan-mode-turn-scoped branch 5 times, most recently from 6b8948f to b069f01 Compare April 13, 2026 20:21
@ibetitsmike ibetitsmike changed the title feat: add turn-scoped plan mode for chat feat(coderd/x/chatd): add plan mode with restricted tool boundary Apr 14, 2026
@ibetitsmike
ibetitsmike force-pushed the mike/plan-mode-turn-scoped branch from f2311be to 2a723e2 Compare April 15, 2026 12:42
@ibetitsmike ibetitsmike changed the title feat(coderd/x/chatd): add plan mode with restricted tool boundary feat: add plan mode with restricted tool boundary Apr 15, 2026
@ibetitsmike
ibetitsmike force-pushed the mike/plan-mode-turn-scoped branch 4 times, most recently from 8918ef3 to 008233e Compare April 15, 2026 14:19
@ibetitsmike
ibetitsmike marked this pull request as ready for review April 15, 2026 14:24
@coderagents

coderagents Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/ai-coder/agents/index.md — Add ask_user_question to the built-in tools table. (addressed in cdf5055)
  • docs/ai-coder/agents/architecture.md — Add ask_user_question to the platform tools table. (addressed in cdf5055)
    • Clarify that propose_plan and ask_user_question are only available when plan mode is active. (addressed in de66812)
  • docs/ai-coder/agents/platform-controls/index.md — Document the new Plan mode instructions admin-only setting. (addressed in de66812)

New Documentation Needed

  • docs/ai-coder/agents/index.md — Explain the plan mode feature for end users: what it is, how to toggle it, what it restricts, and how it persists. (addressed in de66812)

Automated review via Coder Tasks

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread coderd/x/chatd/subagent.go Resolved
Comment thread coderd/x/chatd/chatd.go Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/plan-mode-turn-scoped branch 2 times, most recently from d6c0bf1 to 8203c24 Compare April 15, 2026 15:50
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Mux working on behalf of Mike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread coderd/x/chatd/chatd.go Resolved
Comment thread coderd/x/chatd/subagent.go Resolved
Comment thread coderd/exp_chats.go Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/plan-mode-turn-scoped branch from 8203c24 to f8d521d Compare April 15, 2026 16:08
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
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 15, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Mux working on behalf of Mike.

@codex review

@ibetitsmike ibetitsmike reopened this Apr 15, 2026
@coder coder unlocked this conversation Apr 15, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread coderd/x/chatd/chatd.go Resolved
@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux is working on behalf of Mike.

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

Mux requested this follow-up Codex review on Mike's behalf after fixing the latest dynamic tool regression.

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

Mux requested this follow-up Codex review on Mike's behalf after preserving the composer on chat-setting sync failures.

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

ghost commented Apr 16, 2026

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ 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".

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

Mux working on behalf of Mike.

@codex review

Latest push relaxes plan mode so root chats and subagents can use execute and process_output for exploration, while write_file and edit_files stay limited to the chat-specific plan file.

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux working on behalf of Mike.

Please review the latest push.

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

Mux working on behalf of Mike.

Requesting a fresh exact Codex trigger because the previous comments included extra text and may not have matched the repository's expected trigger format.

@ibetitsmike

ghost commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread coderd/x/chatd/chatd.go Resolved
@ibetitsmike
ibetitsmike merged commit 1cf0354 into main Apr 16, 2026
@ibetitsmike
ibetitsmike deleted the mike/plan-mode-turn-scoped branch April 16, 2026 09:12
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 2026
@coder coder unlocked this conversation Apr 16, 2026
};

const DEFAULT_CHAT_PAGE_LIMIT = 50;
const nilUUID = "00000000-0000-0000-0000-000000000000";

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is probably a bad use of nilUUID const re-defining

planMode?: ChatPlanModeOrClear;
};

const clearPlanMode = "" satisfies ChatPlanModeOrClear;

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels wrong, why is clear plan mode an empty string?

Comment on lines +1110 to +1145
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;

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +59 to +75
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,
};
};

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.join("\n");
};

export const AskUserQuestionTool: FC<AskUserQuestionToolProps> = ({

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this entire component is a bit of a mess.

  1. We should be using formik
  2. We're manually adding setIsSubmitting. Again, formik and mutation helpers help here
  3. We have a map call where the content should absolutely be pulled out into a separate component.
  4. There are more issues but I'd be here all day so pls get your agent to do this properly

Comment on lines +70 to +81
const handleImplementPlanClick = async () => {
if (!onImplementPlan || isSubmitting) {
return;
}
setIsSubmitting(true);
try {
await onImplementPlan();
setIsSubmitting(false);
} catch {
setIsSubmitting(false);
}
};

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +174 to +175
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";

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.`;

ghost Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a variable? just inline it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants