Skip to content

feat(core): introduce Turn domain type and CommandRegistry (#2895, #2896)#2912

Merged
bug-ops merged 3 commits intomainfrom
2895-2896-turn-command-registry
Apr 11, 2026
Merged

feat(core): introduce Turn domain type and CommandRegistry (#2895, #2896)#2912
bug-ops merged 3 commits intomainfrom
2895-2896-turn-command-registry

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 11, 2026

Summary

  • Turn domain type (#2895): Turn struct in zeph-core::agent::turn with TurnId (per-conversation monotonic newtype), TurnInput, TurnMetrics (Phase 1 wraps TurnTimings), and begin_turn/end_turn lifecycle methods in Agent. Sets the foundation for per-turn metrics, tracing, and future turn replay (Phase 2).
  • CommandRegistry (#2896): CommandHandler<C> trait, CommandRegistry<C> (Vec-backed, word-boundary dispatch), CommandContext<'_, C> (lifetime-bound subsystem borrows), CommandOutput enum. Batch 1 (8 commands) migrated. Dead legacy branches removed.

Wave 2 of architecture epic #2909

Depends on: #2897 (MemoryState decomposition, closed), #2899 (AgentBuilder consolidation, closed).
Enables: #2898 (run loop event handler — depends on Turn).

Changes

  • crates/zeph-core/src/agent/turn.rs — new file
  • crates/zeph-core/src/agent/command_registry.rs — new file
  • crates/zeph-core/src/agent/commands/ — 7 new files (Batch 1 handlers + mod.rs)
  • crates/zeph-core/src/agent/mod.rs — begin_turn/end_turn, command_registry field, run loop dispatch
  • crates/zeph-core/src/agent/slash_commands.rs — dead Batch 1 branches removed

Test plan

  • 8071 tests pass (cargo nextest run --workspace --features desktop,ide,server,chat,pdf,scheduler --lib --bins)
  • cargo clippy --workspace --features desktop,ide,server,chat,pdf,scheduler -- -D warnings clean
  • cargo +nightly fmt --check clean
  • Live: /exit, /clear, /debug-dump, /log debug behave identically to pre-PR (see .local/testing/playbooks/turn-command-registry.md)
  • Live: non-migrated commands (/new, /compact, /model) unaffected

)

Turn domain type (Phase 1):
- Add Turn struct in agent::turn with TurnId, TurnInput, TurnMetrics, cancel_token
- TurnId is a per-conversation monotonic newtype (resets on /new)
- TurnMetrics wraps TurnTimings only in Phase 1; token/cost deferred to Phase 2
- Agent gains begin_turn/end_turn lifecycle methods; process_user_message_inner
  now takes &mut Turn instead of individual (text, image_parts, iteration_index)
- end_turn copies timings into pending_timings and flushes them

CommandRegistry (Batch 1):
- Add CommandHandler<C> trait (object-safe via Pin<Box<dyn Future>>)
- Add CommandContext<'_, C> (lifetime-bound borrows of agent subsystems)
- Add CommandOutput enum: Message / Silent / Exit / Continue
- Add CommandRegistry<C> (Vec-backed, word-boundary dispatch via std::mem::take)
- Migrate 8 commands to Batch 1 handlers: /exit, /quit, /clear, /reset,
  /clear-queue, /debug-dump, /dump-format, /log
- Remove dead legacy branches from handle_builtin_command and dispatch_slash_command
- Batch 2/3 migration deferred (remaining commands fall through to legacy path)

Closes #2895, closes #2896
@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate enhancement New feature or request size/XL Extra large PR (500+ lines) labels Apr 11, 2026
@bug-ops bug-ops enabled auto-merge (squash) April 11, 2026 20:00
@bug-ops bug-ops merged commit 6efcbef into main Apr 11, 2026
30 checks passed
@bug-ops bug-ops deleted the 2895-2896-turn-command-registry branch April 11, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(core): extract slash command dispatch into CommandRegistry refactor(core): introduce Turn as first-class domain entity

1 participant