Skip to content

refactor(cli): create and index sessions through one helper - #548

Merged
ajianaz merged 1 commit into
developfrom
refactor/session-lifecycle-primitives
Nov 10, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/session-lifecycle-primitives

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

Part 2a of #525 (UI epic #523): session_host::create_session(dir, id, system_prompt, name, face) creates a session file and registers it in the global session index in one call. Every face that created a session used to do JsonlStorage::create_* and then session_index::record(...) by hand; they now share the helper. Refs #525, does not close it.

Why

#525 is about not keeping the same session lifecycle logic in several places. Part 2 was agreed with the owner on 2026-11-10 as shared primitives with the TUI keeping a thin single-session wrapper (not a literal merge of TuiSession into Sessions), delivered as small behavior-preserving PRs: this is the lifecycle one (create + index registration); a shared turn runner and the register settings follow. With one place that creates AND registers, a face cannot create a session and forget to index it.

Changes

  • session_host.rs: create_session (calls JsonlStorage::create_named, then session_index::record when face is Some; None = do not index, which the TUI host uses when it was built without an index, i.e. in tests).
  • Adopted at six sites: run and chat and the TUI start in main.rs, mission.rs, open_session (server faces, face server), and TuiSession::new_session (/new). Each keeps its own error context and any directory creation it already did, so error messages and index contents are unchanged.
  • Not changed on purpose: branch and import register sessions created through other APIs (fork, import), and opening an existing session has about six variants with different id rules and messages (not the same duplication).
  • CHANGELOG (Changed) and docs/epics.md updated in the same PR (AGENTS.md §7); README unaffected.

Testing

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo check -p tole-cli --no-default-features, cargo test --workspace (1179 passed: the previous 1178 plus one new test)
  • Local cora review --staged: not run (cora is not installed in this environment); the CI Cora Review job is the verdict.
  • New integration test tests/session_create.rs (one test, one process, because the index path is global state read from CODECORA_HOME): a created session has the file, the pinned system prompt and alias, and one index row under its face with the right file path; face: None indexes nothing; TOLE_NO_SESSION_INDEX=1 wins over a face; a second face gets its own row; an unsafe id (../evil) is refused and nothing is indexed. Before this the only index coverage was run (session_index_e2e.rs); chat, tui, mission and the server faces had none.
  • Mutation: removing the index registration from the helper fails the new test.

Next in #525

Part 2b: one turn runner (build the provider, resume a parked turn, optional compaction, run) shared by run_session_turn and TuiSession::run_turn. Part 2c: the register settings (model, effort, name, compaction request).

Related Issues

Refs #525, part of #523.


Generated by Claude Code

session_host::create_session creates the session file and registers it in the global index in one call. run, chat, tui, mission, the server faces and the TUI /new use it instead of create + record by hand. Error messages and index contents are unchanged.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit f685ce4 into develop Nov 10, 2026
15 of 16 checks passed
ajianaz added a commit that referenced this pull request Nov 10, 2026
## What

Part 2c of #525 (UI epic #523): `session_settings` owns a session's
durable settings: the register names (`fact/model`,
`fact/reasoning_effort`, `fact/session_name`), the label validation and
the writers. The TUI's `/model`, `/effort`, `/name` and `/compact` and
ACP's model picker write through it, and the readers use the same
constants. Refs #525.

## Why

The same registers were written in two places (`tui_host.rs` and ACP's
`set_model_option`) and named by repeated string literals in the writers
and readers (`turn_runner`, `status`, `acp`). A rename or a validation
tweak had to be found in each. Agreed with the owner on 2026-11-10 as
the last piece of the shared-primitives plan for #525.

## Changes

- `session_settings.rs` (new): `MODEL` / `EFFORT` / `NAME` register
constants; `clean_label` (moved from `tui_host.rs`: non-blank, at most
120 chars, no control characters); `set_model`, `set_effort` (validated
and canonicalised, or `None` clears the override back to the process
default), `set_name`, `request_compaction` (the forced pass of #481),
and `write_model` (store as given, for ACP, which validates against its
own model list first).
- `tui_host.rs`: the setters call the module (its private `commit`
helper and `clean_label` are gone; the window cache is still reset after
a model switch).
- `acp.rs`: `set_model_option` writes through `write_model` (its own
validation, busy check and error text stay); `MODEL_REGISTER` is the
shared constant.
- `turn_runner.rs` (`session_model`, `session_effort`) and `status.rs`
read through the constants.
- CHANGELOG and `docs/epics.md` updated in the same PR (AGENTS.md §7);
README unaffected.

Behavior and error text are unchanged (`invalid model id`, `invalid
name`, `invalid reasoning effort ...`, and the `storage error:` prefix
on a failed write).

## Testing

- [x] `cargo fmt --all -- --check`, `cargo clippy --workspace
--all-targets -- -D warnings`, `cargo check -p tole-cli
--no-default-features`, `cargo test --workspace` (1187 passed: the
previous 1182 plus 5)
- [ ] Local `cora review --staged`: not run (cora is not installed in
this environment); the CI Cora Review job is the verdict.
- [x] 5 new unit tests: label rules (trim, blank, control characters,
the 120-char limit); the model is stored where the readers look and a
bad id writes nothing; effort is validated, canonicalised (` HIGH ` →
`high`), a rejected level changes nothing, and `None` clears to the
process default; the name register renames and a bad name is refused
(the core's `session_name()` reads it); a compaction request is a
durable pending flag. The existing `tui_host` tests
(`switches_write_the_registers_the_next_call_and_resume_read`,
`name_and_compact_request_are_durable_registers`) run unchanged through
the new module.
- Mutations, each caught by the new tests and by those unchanged
`tui_host` tests: the name register key drifting from what the core
reads, clearing the effort being a no-op, and label validation disabled.

## What #525 looks like after this

Done as shared primitives inside `tole-cli`, per the owner's decision
(no new crate until a second consumer exists, sync API): tool
registration moved to the roster (#547), session create + index
registration (#548), one turn runner (#549), session settings (this PR).
I will post the acceptance-criteria status on the issue, including what
is not done: `TuiSession` still owns its single swappable storage handle
and `switch_session` (open an existing session by id through the index),
and the crate/publish decision is deferred with the crate.

## Related Issues

Refs #525, part of #523.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01GwJr9GzLbDFeXo3HZHZpyP)_

Co-authored-by: Claude <[email protected]>
@ajianaz
ajianaz deleted the refactor/session-lifecycle-primitives branch November 11, 2026 04:10
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