Skip to content

feat(desktop): opt-in clear history and continue from plan - #78968

Closed
igennova wants to merge 4 commits into
PostHog:posthog-code/clear-commandfrom
igennova:fix/704
Closed

feat(desktop): opt-in clear history and continue from plan#78968
igennova wants to merge 4 commits into
PostHog:posthog-code/clear-commandfrom
igennova:fix/704

Conversation

@igennova

@igennova igennova commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Ports PostHog/code#3961 onto the monorepo.

Summary

  • Adds an opt-in plan-approval option: Approve, clear history, and continue from plan (alongside normal approve + reject).
  • Normal Approve and proceed keeps planning history unchanged.

Why

Issue #76316: after planning, clearing context before implementation avoids auto-compaction mid-implementation. This mirrors Claude’s clear-on-plan-accept flow as an explicit choice.

How it works

  1. User is in plan mode → agent proposes a plan
  2. Plan card offers:
    • Approve and proceed (keep context)
    • Approve, clear history, and continue from plan (fresh context)
    • Reject with feedback
  3. Clear path: resolve permission UI locally → cancelPromptcreateNewLocalSession with plan seed
  4. Same task / title; new task run (chat thread resets by design)

Video

Screen.Recording.2026-07-15.at.12.49.28.PM.mov

Test plan

  • Enter plan mode → create a plan → confirm new clear option appears
  • Approve and proceed → planning history remains; agent continues in-place
  • Clear history and continue → chat resets; agent starts from plan only; no ACP/error toast
  • Mode selector still applies on clear path (e.g. auto / acceptEdits)
  • Reject with feedback still works
  • Error-state New Session still reconnects in place (resetSession unchanged)
  • Unit tests: planContinuation, sessionServicePlanContinuation, permission-options, PlanApprovalSelector

Replaces PostHog/code#3462 , which was closed during the pre-migration PR sweep (not actually stale).

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

@igennova wrote this change and opened it as PostHog/code#3961 before the desktop repo moved into this monorepo. I (Claude) only ported it.

  • Skills invoked: /porting-code-prs, /writing-pr-descriptions.
  • Applied with git am -3 --directory=products/desktop/, which keeps the original commit authorship. Four files needed the 3-way fallback because the tree moved on, and all merged without conflicts.
  • The diffstat matches the source PR at +746 / -40, so the path remap dropped nothing.

@trunk-io

trunk-io Bot commented Aug 6, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions github-actions Bot added the feature/desktop Feature Tag: Desktop label Aug 6, 2026
@igennova
igennova marked this pull request as ready for review August 6, 2026 14:38
@igennova

igennova commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@charlesvien opened this PR. You can review it when you have time. Thanks

@charlesvien

Copy link
Copy Markdown
Member

Hey @igennova can you stack this on the primitives haacked built here #76457

Closes PostHog#704. Lets users discard planning context and start a fresh local
run seeded with the approved plan, without changing resetSession.
@igennova
igennova changed the base branch from master to posthog-code/clear-command August 7, 2026 21:22
Clear-and-continue built its own clearing: it cancelled the turn and
started a fresh task run. That reset the chat thread, and it did nothing
at all on cloud sessions.

Use the adapter's /clear primitive instead. End the planning turn, clear
the conversation, then send the approved plan into the fresh context. The
task run, the ACP session and the visible thread all survive, and the
thread keeps a "Conversation cleared" boundary above the implementation.

Gate on the agent advertising conversationClear rather than skipping
cloud sessions. An agent predating the capability ignores the boundary
and rebuilds the conversation it was meant to retire, so fall back to a
normal approve instead of showing a clear that did not happen.

Extract the plan markdown before the clear and re-send it afterwards.
/clear deliberately wipes the adapter's plan state, so the host's copy is
the only thing that survives the boundary.
@igennova

igennova commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Hey @igennova can you stack this on the primitives haacked built here #76457

@charlesvien
Stacked on #76457, and reworked to actually consume it rather than just sit on top.

  • Rebased fix/704 onto posthog-code/clear-command, so this now diffs against your branch.
  • Dropped the new-task-run approach: the clear path ends the planning turn, sends /clear, then sends the approved plan into the fresh context.
  • Replaced my session.isCloud skip with a conversationClear capability check, so cloud works now.
  • The thread survives instead of resetting — your "Conversation cleared" boundary sits above the implementation.
  • Plan markdown is extracted before the clear and re-sent after, since your reset wipes lastPlanContent on purpose.

igennova and others added 2 commits August 8, 2026 04:36
Reading rawInput through an `as { plan?: unknown }` cast asserted a shape
nothing checked, so an upstream change would surface as a silent null and
quietly disable clear-and-continue. AGENTS.md asks for Zod-validated
metadata over raw SDK input.

Behavior is unchanged for well-formed and missing input alike. Cover the
wrong-typed plan the schema now rejects.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@trunk-io
trunk-io Bot deleted the branch PostHog:posthog-code/clear-command August 13, 2026 21:10
@trunk-io trunk-io Bot closed this Aug 13, 2026
@igennova

Copy link
Copy Markdown
Contributor Author

Hey @charlesvien, why did this PR get closed by the trunk bot?

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

Labels

feature/desktop Feature Tag: Desktop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants