feat(commands): align /branch /plan /context /memory with conversation-state semantics (#36 #38 #45 #46) - #84
Merged
Crsei merged 1 commit intoApr 21, 2026
Conversation
…n-state semantics (Crsei#36 Crsei#38 Crsei#45 Crsei#46) Rewrite four slash commands around the same shared concept — conversation state + AppState — so the Rust port matches the Bun reference behavior: - /branch (Crsei#36): now forks the current transcript into a new session (writes a session_header, copies entries with rewritten session_id). The old git-branch wrapper moves to /gbranch (alias gitbranch). - /plan (Crsei#46): new command — enters Plan permission mode with pre_plan_mode handshake, shows/opens a project-or-global plan.md via ensure_and_open. - /context (Crsei#38): runs the post-compact pipeline and reports seven token categories (messages/system/skills/files/tools/hooks/free) with a unicode bar. Adds `/context json` for headless callers. - /memory (Crsei#45): default view becomes a selector with an auto-memory header, grouped entries across Global/Project/Team/Auto scopes, and directory shortcuts. Adds MemoryScope::Team and MemoryScope::Auto plus auto_memory_enabled in settings (Raw/Effective/Runtime/Schema). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns four slash commands with the Bun reference around the shared concept of conversation state + AppState:
/branch— now forks the current transcript (newsession_header+ entry copy with rewrittensession_id). Old git-branch behavior moved to/gbranch(aliasgitbranch)./plan— new command. Enters Plan permission mode withpre_plan_modesave/restore handshake (mirrorsEnterPlanModeTool), shows/opens.cc-rust/plan.md(project) or{data_root}/plan.md(global) viaensure_and_open./context— replaces the heuristic withanalyze_context_usageon the post-compact pipeline. Reports seven token categories (messages / system / skills / files / tools / hooks / free) with a unicode bar grid. Adds/context jsonfor headless callers./memory— default entry becomes a selector (auto-memory header, grouped entries across all scopes, directory shortcuts). AddsMemoryScope::TeamandMemoryScope::Autovariants plusauto_memory_enabledacrossRaw/Effective/Runtimesettings and the JSON schema.Why
Each command already existed in cc-rust but did a different thing than the Bun reference —
/branchwas a git wrapper,/contextused a ~4 chars/token heuristic,/memoryhad no selector, and/planwasn't wired at all. These four issues were grouped because they all touch conversation state + AppState; bundling them avoided churn on overlapping files (especiallycommands/mod.rs).New files
crates/cc-session/src/fork.rs—fork_session()orchestratorcrates/cc-compact/src/context_analysis.rs— categorized token analysis servicecrates/claude-code-rs/src/commands/plan.rs—/planhandlercrates/claude-code-rs/src/commands/gbranch.rs— moved git-branch wrappercrates/claude-code-rs/tests/e2e_plan_cmd.rscrates/claude-code-rs/tests/e2e_context_cmd.rscrates/claude-code-rs/tests/e2e_memory_scopes.rsReviewer notes
/planonly mutatesAppState.tool_permission_contextviaCommandContext— the TUIsync_app_runtime_from_statepicks that up, butipc::ingress::*currently only syncsadditional_working_directories+team_context, so daemon-side mode propagation is a follow-up (TODO in-source)./branchprints a resume hint instead of auto-switching sessions — an automatic switch requires coordinated QueryEngine state surgery (abort in-flight work, swapSessionId, redirect transcript flush). TODO recorded incommands/branch.rs.MemoryScope::Team/Autopaths are wired for storage regardless ofFEATURE_TEAMMEM/auto_memory_enabled; those flags gate prompt injection only, so legacy data is never stranded.auto_memory_enabledpersists the toggle, but the actual auto-capture hook in the query loop is a separate change (flagged in thecommands/memory.rsmodule doc).memdirtests needed#[serial_test::serial]to avoid aCC_RUST_HOMErace with Team A's fork tests — added.Test plan
cargo check --workspace— clean (only 2 pre-existingsession_iddead-code warnings inweb/handlers.rs)cargo test -p cc-config --lib— 60/60 pass (5 new plan-path tests)cargo test -p cc-session --lib— 68/68 pass (fork + transcript + memdir)cargo test -p cc-compact --lib— 30/30 pass (context_analysis)cargo test -p claude-code-rs --bin claude-code-rs 'commands::{plan,branch,context,memory}::'— 24/24 passcargo test -p claude-code-rs --test 'e2e_{plan,context,memory_scopes}_cmd'— 18/18 pass/plan→/plan open→ edit file →/plan showflow (requires interactive TUI)/branchfrom a session with >2 messages → verify resume hint + new transcript file/context json | jqin headless mode/memory auto on→/memorydefault view showsON🤖 Generated with Claude Code