Skip to content

feat(code): Add "clear and continue from plan" option in plan mode#1249

Open
littlekirkycode wants to merge 4 commits intoPostHog:mainfrom
littlekirkycode:feat/plan-clear-and-continue
Open

feat(code): Add "clear and continue from plan" option in plan mode#1249
littlekirkycode wants to merge 4 commits intoPostHog:mainfrom
littlekirkycode:feat/plan-clear-and-continue

Conversation

@littlekirkycode
Copy link
Copy Markdown
Contributor

@littlekirkycode littlekirkycode commented Mar 15, 2026

Base branch: feat/clear-command — depends on resetSession()
with clearHistory

Closes #704

Screenshot 2026-03-15 at 16 03 31 Screenshot 2026-03-15 at 16 04 23

Summary

Adds a third option when exiting plan mode: "Yes, clear history and
continue from plan"
. Clears the conversation and re-sends the approved
plan as the first prompt — useful when the context window filled up
during planning and you want the agent to start implementing with maximum
available context.

Note: /clear resets the conversation by reconnecting with empty
history — previous messages are no longer visible in the UI. The session
log on S3 is not deleted, but the UI won't replay it.
That way if the you wants a softer version (e.g. keep history scrollable
but start a fresh context), please bear this in mind.

Flow

User exits plan mode
  → Permission dialog shows 3 options:
    1. "Yes, and auto-accept edits" (existing)
    2. "Yes, and manually approve edits" (existing)
    3. "Yes, clear history and continue from plan" ← NEW
  → Agent switches to default mode
  → Sends _posthog/clear_and_continue notification with plan text
  → Renderer queues plan in pendingPlanContinuations
  → After current turn completes:
    1. resetSession() clears history
    2. sendPrompt() re-injects the plan

Agent-side

The permission handler extracts the plan text and signals the renderer
via extNotification:

if (response.outcome.optionId === "clearAndContinue") {
  const planText = extractPlanText(updatedInput);
  // Switch to default mode, then signal renderer
  await context.client.extNotification(
    POSTHOG_NOTIFICATIONS.CLEAR_AND_CONTINUE,
    { sessionId: context.sessionId, plan: planText },
  );
}

Renderer-side

SessionService detects the notification, queues the plan, and executes
after the turn completes:

private async executeClearAndContinue(taskId: string, repoPath: string,
plan: string): Promise<void> {
  await this.resetSession(taskId, repoPath);
  await this.sendPrompt(taskId, `Continue implementing this approved
plan:\n\n${plan}`);
}

The plan is queued (not executed immediately) because the notification
arrives mid-turn — we wait for the current turn to finish before
clearing.

Changes

File What
acp-extensions.ts New CLEAR_AND_CONTINUE notification constant
permission-options.ts Add clearAndContinue option to plan exit dialog
permission-handlers.ts Handle clearAndContinue — switch mode, send notification
package.json Export ./acp-extensions subpath
tsup.config.ts Add acp-extensions.ts build entry
service.ts pendingPlanContinuations map, notification detection, executeClearAndContinue()

Test plan

  • Enter plan mode → create a plan → exit → new option appears
  • Selecting it clears history, switches to default mode, sends plan
    as first prompt
  • Agent continues implementing the plan in fresh context
  • Existing "auto-accept" and "manually approve" options still work
    unchanged

Adds /clear slash command that resets conversation history and starts a
fresh session. Suppresses the SDK's built-in /clear (which doesn't work
in our context) and replaces it with our own implementation.
resetSession() now clears UI history by skipping log replay on reconnect.
Remove inline import in commands.ts. Rewrite resetSession() to create a new task run via createNewLocalSession() instead of clearing in-memory logs, ensuring old messages don't reappear on app restart.
Adds "Yes, clear history and continue from plan" option when exiting
plan mode. Clears conversation history and re-injects the approved plan
as the first prompt. Useful when context window is filling up during
planning — lets the agent start fresh with just the plan.
) {
const planText = extractPlanText(updatedInput);

session.permissionMode = "default";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why would we approve a plan and then go to Default instead of Accept edits?

});
await context.updateConfigOption("mode", "default");

// Signal the renderer to clear the session and re-inject the plan
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab Mar 31, 2026

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is the renderer responsible for clearing the session and reinjecting the plan?
If we're going to be creating a new local session, do we need this notification at all?

Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! It unfortunately does not seem to work for me:

10:21:30.815 (agent-service)              › Failed to create session {
  code: -32603,
  message: 'Internal error',
  data: { details: 'Query closed before response received' }
}
10:21:30.816 (session-service)            › Failed to clear and continue from plan {
  taskId: '98c4f413-d7d4-4903-8fcf-346256f3d420',
  error: 'TRPCClientError: Internal error\n' +
    '    at TRPCClientError2.from (http://localhost:5173/node_modules/.vite/deps/chunk-3EEZN4XF.js?v=2a9e1145:2031:44)\n' +
    '    at Object.next (http://localhost:5173/@fs/Users/jonathan/dev/twig/packages/electron-trpc/src/renderer/ipcLink.ts:80:46)\n' +
    '    at #handleResponse (http://localhost:5173/@fs/Users/jonathan/dev/twig/packages/electron-trpc/src/renderer/ipcLink.ts:31:23)\n' +
    '    at http://localhost:5173/@fs/Users/jonathan/dev/twig/packages/electron-trpc/src/renderer/ipcLink.ts:23:27'
}

Above happened after creating a plan, then clicking clear and continue.

Also left some concerns w.r.t how we make the client responsible for this logic.

});
await context.updateConfigOption("mode", "default");

// Signal the renderer to clear the session and re-inject the plan
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is the renderer responsible for clearing the session and reinjecting the plan?
If we're going to be creating a new local session, do we need this notification at all?

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.

Plan mode - clear and continue

2 participants