Skip to content

feat(commands): align /branch /plan /context /memory with conversation-state semantics (#36 #38 #45 #46) - #84

Merged
Crsei merged 1 commit into
Crsei:rust-litefrom
yaohaowei0914:claude/dazzling-montalcini-ab3588
Apr 21, 2026
Merged

feat(commands): align /branch /plan /context /memory with conversation-state semantics (#36 #38 #45 #46)#84
Crsei merged 1 commit into
Crsei:rust-litefrom
yaohaowei0914:claude/dazzling-montalcini-ab3588

Conversation

@yaohaowei0914

Copy link
Copy Markdown
Contributor

Summary

Aligns four slash commands with the Bun reference around the shared concept of conversation state + AppState:

Why

Each command already existed in cc-rust but did a different thing than the Bun reference — /branch was a git wrapper, /context used a ~4 chars/token heuristic, /memory had no selector, and /plan wasn't wired at all. These four issues were grouped because they all touch conversation state + AppState; bundling them avoided churn on overlapping files (especially commands/mod.rs).

New files

  • crates/cc-session/src/fork.rsfork_session() orchestrator
  • crates/cc-compact/src/context_analysis.rs — categorized token analysis service
  • crates/claude-code-rs/src/commands/plan.rs/plan handler
  • crates/claude-code-rs/src/commands/gbranch.rs — moved git-branch wrapper
  • crates/claude-code-rs/tests/e2e_plan_cmd.rs
  • crates/claude-code-rs/tests/e2e_context_cmd.rs
  • crates/claude-code-rs/tests/e2e_memory_scopes.rs

Reviewer notes

  • /plan only mutates AppState.tool_permission_context via CommandContext — the TUI sync_app_runtime_from_state picks that up, but ipc::ingress::* currently only syncs additional_working_directories + team_context, so daemon-side mode propagation is a follow-up (TODO in-source).
  • /branch prints a resume hint instead of auto-switching sessions — an automatic switch requires coordinated QueryEngine state surgery (abort in-flight work, swap SessionId, redirect transcript flush). TODO recorded in commands/branch.rs.
  • MemoryScope::Team/Auto paths are wired for storage regardless of FEATURE_TEAMMEM / auto_memory_enabled; those flags gate prompt injection only, so legacy data is never stranded.
  • auto_memory_enabled persists the toggle, but the actual auto-capture hook in the query loop is a separate change (flagged in the commands/memory.rs module doc).
  • Team D's two new memdir tests needed #[serial_test::serial] to avoid a CC_RUST_HOME race with Team A's fork tests — added.

Test plan

  • cargo check --workspace — clean (only 2 pre-existing session_id dead-code warnings in web/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 pass
  • cargo test -p claude-code-rs --test 'e2e_{plan,context,memory_scopes}_cmd' — 18/18 pass
  • Manual: /plan/plan open → edit file → /plan show flow (requires interactive TUI)
  • Manual: /branch from a session with >2 messages → verify resume hint + new transcript file
  • Manual: /context json | jq in headless mode
  • Manual: /memory auto on/memory default view shows ON

🤖 Generated with Claude Code

…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>
@Crsei
Crsei merged commit 91a96f5 into Crsei:rust-lite Apr 21, 2026
1 of 4 checks passed
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.

2 participants