Session ops and ContextPolicy in hx-core #145

Merged
hermes merged 2 commits from refactor/session-ops into main 2026-10-09 19:37:56 +00:00
Collaborator

Candidates 1+2 from the architecture feedback.

Session ops (hx-core)

  • Agent::new_session(dir), new_session_here(), resume(path), compact_now(), session_dir(). TUI /new, /clear, /resume and RPC new, clear, resume all go through them.
  • One constant KEEP_MESSAGES = 6 replaces the hard-coded 4 (manual, TUI + RPC) and 6 (auto).
  • Behavior changes: RPC clear is now an alias of new (new session file, old one stays resumable) as in the TUI; Agent::clear is removed. RPC new writes next to the current session file (was: startup dir). /compact and RPC compact keep 6 messages instead of 4.

ContextPolicy (hx-core/window.rs)

  • ContextPolicy::{Fixed(n), FromModel{window}}; the threshold is computed from policy + reserve (max_tokens), so set_max_tokens and the policy can be set in any order.
  • Removed: Agent::set_compact_at, fit_window, Switcher's auto_compact flag/arg. Switcher calls Agent::set_model_window, which a Fixed policy ignores.

Tests: new session_ops_share_one_path, policy_is_order_independent; existing compaction/switch tests ported. fmt, clippy -D warnings, tests/all.sh green. Token counts of the prefix are unchanged (no tool or prompt change), so no hx prefix run.

Candidates 1+2 from the architecture feedback. **Session ops (hx-core)** - `Agent::new_session(dir)`, `new_session_here()`, `resume(path)`, `compact_now()`, `session_dir()`. TUI `/new`, `/clear`, `/resume` and RPC `new`, `clear`, `resume` all go through them. - One constant `KEEP_MESSAGES = 6` replaces the hard-coded 4 (manual, TUI + RPC) and 6 (auto). - Behavior changes: RPC `clear` is now an alias of `new` (new session file, old one stays resumable) as in the TUI; `Agent::clear` is removed. RPC `new` writes next to the current session file (was: startup dir). `/compact` and RPC `compact` keep 6 messages instead of 4. **ContextPolicy (hx-core/window.rs)** - `ContextPolicy::{Fixed(n), FromModel{window}}`; the threshold is computed from policy + reserve (`max_tokens`), so `set_max_tokens` and the policy can be set in any order. - Removed: `Agent::set_compact_at`, `fit_window`, `Switcher`'s `auto_compact` flag/arg. Switcher calls `Agent::set_model_window`, which a Fixed policy ignores. **Tests**: new `session_ops_share_one_path`, `policy_is_order_independent`; existing compaction/switch tests ported. fmt, clippy -D warnings, `tests/all.sh` green. Token counts of the prefix are unchanged (no tool or prompt change), so no `hx prefix` run.
hermes added 1 commit 2026-10-09 19:35:11 +00:00
hermes added 1 commit 2026-10-09 19:37:09 +00:00
hermes merged commit 44d8dacb88 into main 2026-10-09 19:37:56 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: johannes/hx#145