Skip to content

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

Open
littlekirkycode wants to merge 3 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 3 commits intoPostHog:mainfrom
littlekirkycode:feat/plan-clear-and-continue

Conversation

@littlekirkycode
Copy link
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

littlekirkycode added 3 commits March 15, 2026 06:19
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.
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

1 participant