From 913e137d07117007adb187a7b198b12c9462e328 Mon Sep 17 00:00:00 2001 From: Daniel Rossier Date: Sat, 28 Nov 2026 12:15:56 +0100 Subject: [PATCH] Let several conversations share one corpus A corpus held a single conversation: two spear-chat processes on the same tree read and rewrote the same history file, and the last to save won. Conversations now have names. `spear-chat --session ` opens one and `/session [list|new|switch|rm]` manages them in the chat; each keeps its history beside the default one, which keeps the file it always had. A conversation is held by one process through an flock on a lock file beside its history, so a second spear-chat (another terminal, or another container on the same state directory) is refused it and pointed at another name, and the kernel drops the lock with a crashed process. A switch drops what the previous answer engaged, through the same helper as /clear. /cd keeps the conversation and takes its lock in the new corpus, staying put if that one is held elsewhere. Training episodes record the conversation's name in their provenance (None for the default one). --- client/cli/chat_settings.py | 3 + client/cli/conversation_sessions.py | 172 ++++++++++++++++++ client/cli/operator_input.py | 3 +- client/cli/rag_chat.py | 125 ++++++++++++- client/cli/session_workspace.py | 16 +- client/runtime/task_controller.py | 3 + client/tests/test_conversation_sessions.py | 197 +++++++++++++++++++++ client/training/training_data.py | 3 + doc/source/using/context.rst | 3 +- doc/source/using/usage.rst | 13 +- 10 files changed, 524 insertions(+), 14 deletions(-) create mode 100644 client/cli/conversation_sessions.py create mode 100644 client/tests/test_conversation_sessions.py diff --git a/client/cli/chat_settings.py b/client/cli/chat_settings.py index f10b2df..2bb23a2 100644 --- a/client/cli/chat_settings.py +++ b/client/cli/chat_settings.py @@ -44,6 +44,9 @@ # tools: one records what the model said, the other hands it back for # free so a harness change can be judged without paying for the model # twice. + "--session": ("SPEAR_SESSION", + "open this named conversation of the corpus instead of its " + "default one; each is held by one spear-chat at a time"), "--record": ("SPEAR_RECORD_TURNS", "record this session's model turns to a file"), "--replay": ("SPEAR_REPLAY_TURNS", diff --git a/client/cli/conversation_sessions.py b/client/cli/conversation_sessions.py new file mode 100644 index 0000000..31d2b9c --- /dev/null +++ b/client/cli/conversation_sessions.py @@ -0,0 +1,172 @@ +"""Named conversations on one corpus, and the lock that keeps each to one process. + +A corpus used to hold a single conversation: two spear-chat processes on the +same tree read and rewrote the same history file, and the last to save won. +A conversation now has a name; the unnamed one keeps the file it always had, +so nothing changes for whoever never names one. +""" + +import fcntl +import glob +import json +import os +import re +from datetime import datetime + + +NAME_PATTERN = re.compile(r"[A-Za-z0-9_.-]{1,40}") + +USAGE = ("usage: /session [list] | /session new | " + "/session switch | /session rm ") + + +class ConversationError(Exception): + """A conversation that cannot be named, opened or removed as asked.""" + + +def validate_name(name): + """The name itself, or ConversationError. None names the default one.""" + if name is None: + return None + + if not NAME_PATTERN.fullmatch(name) or name in (".", ".."): + raise ConversationError( + f"invalid session name {name!r}: 1 to 40 of A-Z a-z 0-9 _ . -") + + return name + + +def history_file(default_file, name): + """Where conversation `name` keeps its history, beside the default one.""" + if name is None: + return default_file + + return f"{default_file[:-len('.json')]}-{validate_name(name)}.json" + + +def describe(name): + return name if name is not None else "(default)" + + +class ConversationLock: + """An exclusive, advisory lock on one conversation, held while it is open. + + flock and not a pid file: the kernel drops it when the process dies, so a + crashed session never leaves its conversation unusable. + """ + + def __init__(self): + self.path = None + self._handle = None + + def acquire(self, history_path): + """Take the lock of `history_path`, or raise ConversationError.""" + path = history_path + ".lock" + + if path == self.path: + return + + os.makedirs(os.path.dirname(path) or ".", exist_ok=True) + handle = open(path, "a+") + + try: + fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB) + except BlockingIOError: + handle.close() + raise ConversationError( + "this session is open in another spear-chat; " + "pick another with --session or /session switch " + ) from None + + self.release() + self.path, self._handle = path, handle + + def release(self): + if self._handle is not None: + fcntl.flock(self._handle, fcntl.LOCK_UN) + self._handle.close() + + self.path, self._handle = None, None + + @staticmethod + def held_elsewhere(history_path): + """Whether another process holds `history_path` (a probe, not a take).""" + path = history_path + ".lock" + + if not os.path.exists(path): + return False + + with open(path, "a+") as handle: + try: + fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB) + except BlockingIOError: + return True + + fcntl.flock(handle, fcntl.LOCK_UN) + + return False + + +def list_conversations(default_file): + """(name, history path) for every conversation of this corpus, default first.""" + found = [(None, default_file)] + prefix = default_file[:-len(".json")] + "-" + + names = set() + + for suffix in (".json", ".json.lock"): + for path in glob.glob(glob.escape(prefix) + "*" + suffix): + name = path[len(prefix):-len(suffix)] + + if NAME_PATTERN.fullmatch(name) and ( + suffix == ".json" or ConversationLock.held_elsewhere( + path[:-len(".lock")])): + names.add(name) + + return found + [(name, f"{prefix}{name}.json") for name in sorted(names)] + + +def summary_lines(default_file, current, lock): + """The /session listing: name, messages, last change, who holds it.""" + lines = [] + + for name, path in list_conversations(default_file): + try: + with open(path) as handle: + count = len(json.load(handle)) + changed = datetime.fromtimestamp(os.path.getmtime(path)).strftime( + "%Y-%m-%d %H:%M") + except (OSError, ValueError): + count, changed = 0, "-" + + mark = "*" if name == current else " " + state = (" (open elsewhere)" if name != current + and ConversationLock.held_elsewhere(path) else "") + + lines.append(f" {mark} {describe(name):<24} {count:4d} messages " + f"{changed}{state}") + + return lines + + +def remove(default_file, name, current): + """Delete conversation `name`'s history; never the open or the default one.""" + validate_name(name) + + if name is None or name == current: + raise ConversationError("cannot remove the session in use") + + path = history_file(default_file, name) + + if not os.path.exists(path): + raise ConversationError(f"no session named {name}") + + if ConversationLock.held_elsewhere(path): + raise ConversationError(f"session {name} is open in another spear-chat") + + os.remove(path) + + try: + os.remove(path + ".lock") + except FileNotFoundError: + pass diff --git a/client/cli/operator_input.py b/client/cli/operator_input.py index 99675fa..7ef4678 100644 --- a/client/cli/operator_input.py +++ b/client/cli/operator_input.py @@ -312,7 +312,8 @@ def handle_bang_command(cmd_line): #: one list, so a command cannot be completed and go unlisted, or the reverse. SESSION_COMMANDS = ("/search", "/cd", "/reindex", "/corpus", "/history", "/skills", "/remember", "/recall", "/knowledge", "/forget", - "/good", "/bad", "/fix", "/undo", "/clear", "/model", "/tools") + "/good", "/bad", "/fix", "/undo", "/clear", "/session", + "/model", "/tools") OPERATOR_COMMANDS = ("/standard", "/finetune") diff --git a/client/cli/rag_chat.py b/client/cli/rag_chat.py index 7292ac6..07e8073 100755 --- a/client/cli/rag_chat.py +++ b/client/cli/rag_chat.py @@ -55,7 +55,10 @@ from standard.standard_commands import ( StandardCommandError, handle_standard_command, standard_help_lines, ) -from cli import corpus_search, model_io, session_workspace, standard_session +from cli import ( + conversation_sessions, corpus_search, model_io, session_workspace, + standard_session, +) from cli.chat_settings import ( APP_DIR, CHECKPOINT_ROOT, CONTEXT_ENGINE, LEARNED_RULES_FILE, LLAMA_SERVER_URL, RESULT_STORE, RULES_BUDGET, SESSION_STORE, @@ -90,7 +93,8 @@ ) from cli.session_history import ( HISTORY_INJECT, MAX_HISTORY, TRAJECTORY_FILE, archive_entry, - load_history, save_experience, save_history, save_trajectory, + fresh_session, load_history, save_experience, save_history, + save_trajectory, ) from cli.session_workspace import ( command_result_text, extra_roots_note, is_excluded_path, @@ -219,6 +223,83 @@ def corpus_prompt(): return system_instructions, system_source, global_rules, project_rules +def reset_conversation_state(): + """Forget what the last answer engaged: the turn a follow-up would refer + back to is gone with the history (/clear) or belongs to another + conversation (/session switch).""" + standard_session.STANDARD_ENGAGED_BEFORE = False + standard_session.STANDARD_PRIOR_CLAUSES = () + standard_session.STANDARD_PRIOR_ANSWER = "" + standard_session.STANDARD_PRIOR_REQUIREMENTS = requirement_set.RequirementSet() + + +def use_conversation(name, lock): + """Point the history at conversation `name` and hold its lock.""" + path = conversation_sessions.history_file( + session_workspace.DEFAULT_HISTORY_FILE, name) + lock.acquire(path) + session_workspace.CONVERSATION = name + session_workspace.HISTORY_FILE = path + + +def session_command(argument, history, lock): + """/session: list, create, switch to or remove a named conversation. + + Returns the history to continue with. + """ + words = argument.split() + action = words[0] if words else "list" + name = words[1] if len(words) == 2 else None + current = session_workspace.CONVERSATION + default_file = session_workspace.DEFAULT_HISTORY_FILE + + try: + if action == "list" and len(words) <= 1: + print("\n".join(conversation_sessions.summary_lines( + default_file, current, lock)) + "\n") + + return history + + if action in ("new", "switch") and len(words) == 2: + target = None if name == "default" else name + path = conversation_sessions.history_file(default_file, target) + + if action == "new" and os.path.exists(path): + raise conversation_sessions.ConversationError( + f"session {name} exists: /session switch {name}") + + if (action == "switch" and target not in (current, None) + and not os.path.exists(path) + and not conversation_sessions.ConversationLock.held_elsewhere(path)): + raise conversation_sessions.ConversationError( + f"no session named {name}: /session new {name}") + + save_history(history) + use_conversation(target, lock) + reset_conversation_state() + history = load_history() + + if not os.path.exists(path): + save_history(history) + + print(f"Session {conversation_sessions.describe(target)}: " + f"{len(history)} messages.\n") + + return history + + if action == "rm" and len(words) == 2: + conversation_sessions.remove(default_file, name, current) + print(f"Session {name} removed.\n") + + return history + + print(conversation_sessions.USAGE + "\n") + except conversation_sessions.ConversationError as exc: + print(f"{C_ERR}/session: {exc}{C_RST}\n") + + return history + + def main(): global TRACE_PROVIDER, TRACE_MODEL @@ -231,6 +312,16 @@ def main(): banner_art() set_project(resolve_project_at_startup()) + conversation_lock = conversation_sessions.ConversationLock() + + if not fresh_session(): + try: + conversation_lock.acquire(session_workspace.HISTORY_FILE) + except conversation_sessions.ConversationError as exc: + print(f"{C_ERR}session " + f"{conversation_sessions.describe(session_workspace.CONVERSATION)}" + f": {exc}{C_RST}") + return # Where /cd resolves a relative path from: the directory it last entered. @@ -521,8 +612,19 @@ def read_user_input(): f"session was launched — relaunch spear there{C_RST}\n") else: save_history(history) - focus = target + previous = dict(session_workspace.PROJECT_SPEC) set_project(corpus_at(target)) + + if not fresh_session(): + try: + conversation_lock.acquire(session_workspace.HISTORY_FILE) + except conversation_sessions.ConversationError as exc: + set_project(previous) + print(f"{C_ERR}/cd: {exc}{C_RST}\n") + + continue + + focus = target (system_instructions, system_source, global_rules, project_rules) = corpus_prompt() base_prompt = system_instructions + global_rules + project_rules + TOOL_GUIDE @@ -569,14 +671,18 @@ def read_user_input(): if user_input in ("/clear", "/new"): history = [] save_history(history) + reset_conversation_state() + print("History cleared.\n") - # The turn a follow-up would refer back to is gone with it. + continue - standard_session.STANDARD_ENGAGED_BEFORE = False - standard_session.STANDARD_PRIOR_CLAUSES = () - standard_session.STANDARD_PRIOR_ANSWER = "" - standard_session.STANDARD_PRIOR_REQUIREMENTS = requirement_set.RequirementSet() - print("History cleared.\n") + if user_input == "/session" or user_input.startswith("/session "): + if fresh_session(): + print(f"{C_ERR}/session: a --fresh session keeps no " + f"history{C_RST}\n") + else: + history = session_command(user_input[len("/session"):], + history, conversation_lock) continue @@ -1286,6 +1392,7 @@ def context_items_for(rendered): "data_origin": os.environ.get( "SPEAR_TRAINING_DATA_ORIGIN", "NORMAL_USAGE", ).upper(), + "conversation": session_workspace.CONVERSATION, "user_input_chars": len(user_input), "raw_content_recorded": False, }, diff --git a/client/cli/session_workspace.py b/client/cli/session_workspace.py index ba54278..376a1d2 100644 --- a/client/cli/session_workspace.py +++ b/client/cli/session_workspace.py @@ -20,6 +20,7 @@ from harness import attach_control, provenance, target_policy, write_protection from runtime.tracing import EventStatus, EventType, new_action_id from cli.chat_settings import AUDIT_LOGGER, STATE_DIR +from cli import conversation_sessions from cli.corpus_registry import load_projects from cli.terminal_ui import C_ACCENT, C_BOLD, C_DIM, C_RST, tool_result @@ -124,7 +125,8 @@ def set_project(spec): always operate on the current tree the user launched in, so an edit/bash can never touch the wrong checkout.""" global PROJECT, PROJECT_ROOT, CORPUS_ROOT, PROJECT_KIND, WORKSPACE - global COLLECTION_NAME, HISTORY_FILE, MEMORIES_FILE, PROJECT_SPEC + global COLLECTION_NAME, HISTORY_FILE, DEFAULT_HISTORY_FILE, MEMORIES_FILE + global PROJECT_SPEC # The resolved spec, kept because it is not always IN projects.json: an # umbrella session is synthesised from what sits under the cwd, and looking @@ -179,7 +181,9 @@ def set_project(spec): tag = hashlib.md5(CORPUS_ROOT.encode()).hexdigest()[:8] COLLECTION_NAME = spec.get("collection") or f"adhoc_{tag}" - HISTORY_FILE = f"{STATE_DIR}/history-adhoc-{tag}.json" + DEFAULT_HISTORY_FILE = f"{STATE_DIR}/history-adhoc-{tag}.json" + HISTORY_FILE = conversation_sessions.history_file(DEFAULT_HISTORY_FILE, + CONVERSATION) MEMORIES_FILE = f"{STATE_DIR}/memories-adhoc-{tag}.md" # One explicit memory store, named. The benchmark needs to hand a run its @@ -192,6 +196,14 @@ def set_project(spec): PROJECT_SPEC = {} +# The conversation this process holds, None for the corpus's default one. + +try: + CONVERSATION = conversation_sessions.validate_name( + os.environ.get("SPEAR_SESSION", "").strip() or None) +except conversation_sessions.ConversationError as exc: + raise SystemExit(f"--session: {exc}") from None + # Bound at import for piped/module use; re-resolved in main() for the CLI. # The current directory, because that is the one thing true of every # deployment -- it used to be a named checkout that existed on one machine. diff --git a/client/runtime/task_controller.py b/client/runtime/task_controller.py index 33fd4e6..0583db6 100644 --- a/client/runtime/task_controller.py +++ b/client/runtime/task_controller.py @@ -339,6 +339,9 @@ def run(self, request: TaskRequest) -> TaskResult: provider=context.provider, model=context.model, generation_config=generation, harness_commit=discover_git_commit(os.path.dirname(__file__)), + conversation=(str(context.task_trace_metadata.get("conversation")) + if context.task_trace_metadata.get("conversation") + else None), standard_binding=context.standard_binding, ) diff --git a/client/tests/test_conversation_sessions.py b/client/tests/test_conversation_sessions.py new file mode 100644 index 0000000..d5d2712 --- /dev/null +++ b/client/tests/test_conversation_sessions.py @@ -0,0 +1,197 @@ +"""Named conversations: one history file each, one process each, and a switch +that leaves nothing of the previous conversation's standard engagement.""" + +from __future__ import annotations + +import io +import json +import os +import subprocess +import sys +import tempfile +import textwrap +import unittest +from contextlib import redirect_stdout +from pathlib import Path +from unittest import mock + +ROOT = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(ROOT)) + +from cli import ( + chat_settings, conversation_sessions, operator_input, rag_chat, + session_workspace, standard_session, startup_banner, +) +from cli.conversation_sessions import ( + ConversationError, ConversationLock, history_file, list_conversations, + validate_name, +) + + +class Names(unittest.TestCase): + def test_valid_names_pass_and_none_is_the_default(self): + for name in ("ipi", "ft-2026.11", "A_b-9"): + self.assertEqual(validate_name(name), name) + + self.assertIsNone(validate_name(None)) + + def test_paths_and_oddities_are_refused(self): + for name in ("", "a/b", "../x", "..", ".", "a b", "x" * 41, "é"): + with self.assertRaises(ConversationError): + validate_name(name) + + +class HistoryFiles(unittest.TestCase): + def test_the_default_keeps_its_file_and_a_name_sits_beside_it(self): + default = "/state/history-adhoc-1a2b3c4d.json" + + self.assertEqual(history_file(default, None), default) + self.assertEqual(history_file(default, "ipi"), + "/state/history-adhoc-1a2b3c4d-ipi.json") + + def test_listing_finds_the_named_ones_and_not_the_locks(self): + directory = tempfile.mkdtemp() + default = os.path.join(directory, "history-adhoc-1a2b3c4d.json") + + for name in ("history-adhoc-1a2b3c4d-ipi.json", + "history-adhoc-1a2b3c4d-ipi.json.lock", + "history-adhoc-99999999.json"): + Path(directory, name).write_text("[]") + + self.assertEqual([name for name, _ in list_conversations(default)], + [None, "ipi"]) + + +class Locks(unittest.TestCase): + def setUp(self): + self.path = os.path.join(tempfile.mkdtemp(), "history-adhoc-t.json") + + def _hold_in_another_process(self): + holder = subprocess.Popen( + [sys.executable, "-c", textwrap.dedent(f""" + import fcntl, sys, time + handle = open({self.path + '.lock'!r}, "a+") + fcntl.flock(handle, fcntl.LOCK_EX) + print("held", flush=True) + sys.stdin.read() + """)], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + self.addCleanup(holder.wait) + self.addCleanup(holder.stdin.close) + self.addCleanup(holder.stdout.close) + self.assertEqual(holder.stdout.readline().strip(), "held") + + def test_a_second_process_is_refused_the_conversation(self): + self._hold_in_another_process() + + self.assertTrue(ConversationLock.held_elsewhere(self.path)) + + with self.assertRaises(ConversationError): + ConversationLock().acquire(self.path) + + def test_an_open_empty_conversation_is_listed(self): + # The holder locks the default's lock file; renamed, the lock follows + # the file, which is what a named conversation held before its first + # save looks like. + + self._hold_in_another_process() + os.rename(self.path + ".lock", history_file(self.path, "busy") + ".lock") + + self.assertIn("busy", [name for name, _ in list_conversations(self.path)]) + + def test_a_switch_releases_the_previous_lock(self): + lock = ConversationLock() + other = self.path.replace(".json", "-b.json") + lock.acquire(self.path) + lock.acquire(other) + + self.assertEqual(lock.path, other + ".lock") + + second = ConversationLock() + second.acquire(self.path) + second.release() + lock.release() + + def test_rm_refuses_the_current_and_the_default(self): + default = self.path + + with self.assertRaises(ConversationError): + conversation_sessions.remove(default, "a", "a") + + with self.assertRaises(ConversationError): + conversation_sessions.remove(default, None, "a") + + named = history_file(default, "b") + Path(named).write_text("[]") + conversation_sessions.remove(default, "b", None) + + self.assertFalse(os.path.exists(named)) + + +class SwitchCommand(unittest.TestCase): + def setUp(self): + directory = tempfile.mkdtemp() + self.default = os.path.join(directory, "history-adhoc-t.json") + Path(self.default).write_text(json.dumps([{"role": "user", "content": "a"}])) + + for name, value in (("DEFAULT_HISTORY_FILE", self.default), + ("HISTORY_FILE", self.default), + ("CONVERSATION", None)): + patcher = mock.patch.object(session_workspace, name, value) + patcher.start() + self.addCleanup(patcher.stop) + + self.lock = ConversationLock() + self.addCleanup(self.lock.release) + self.lock.acquire(self.default) + + def _run(self, argument, history): + with redirect_stdout(io.StringIO()), \ + mock.patch.dict(os.environ, {"SPEAR_FRESH": ""}): + return rag_chat.session_command(argument, history, self.lock) + + def test_new_switch_and_back_keep_each_history(self): + history = self._run(" new ipi", [{"role": "user", "content": "a"}]) + + self.assertEqual(history, []) + self.assertEqual(session_workspace.CONVERSATION, "ipi") + self.assertTrue(os.path.exists(history_file(self.default, "ipi"))) + + history = self._run(" switch default", [{"role": "user", "content": "b"}]) + + self.assertEqual(history, [{"role": "user", "content": "a"}]) + self.assertEqual(json.loads(Path(history_file(self.default, "ipi")) + .read_text()), + [{"role": "user", "content": "b"}]) + + def test_the_default_is_reachable_before_its_first_save(self): + os.remove(self.default) + self._run(" new ipi", []) + self._run(" switch default", []) + + self.assertIsNone(session_workspace.CONVERSATION) + + def test_a_switch_resets_the_standard_engagement(self): + standard_session.STANDARD_ENGAGED_BEFORE = True + standard_session.STANDARD_PRIOR_ANSWER = "previous" + self._run(" new other", []) + + self.assertFalse(standard_session.STANDARD_ENGAGED_BEFORE) + self.assertEqual(standard_session.STANDARD_PRIOR_ANSWER, "") + + +class Surfaces(unittest.TestCase): + def test_the_flag_and_the_command_are_listed(self): + with mock.patch.dict(os.environ, {}, clear=False): + os.environ.pop("SPEAR_SESSION", None) + remaining = chat_settings.apply_env_options(["--session", "ipi", "--auto"]) + + self.assertEqual(remaining, ["--auto"]) + self.assertEqual(os.environ["SPEAR_SESSION"], "ipi") + + self.assertIn("--session", startup_banner._env_option_lines()) + self.assertIn("/session", operator_input.SESSION_COMMANDS) + + +if __name__ == "__main__": + unittest.main() diff --git a/client/training/training_data.py b/client/training/training_data.py index 0fff0bd..140690e 100644 --- a/client/training/training_data.py +++ b/client/training/training_data.py @@ -408,6 +408,7 @@ def __init__(self, store: object, *, task_id: str, session_id: str | None, provider: str | None = None, model: str | None = None, generation_config: Mapping[str, object] | None = None, harness_commit: str | None = None, + conversation: str | None = None, redaction_policy: TrainingRedactionPolicy | None = None, standard_binding: Mapping[str, object] | None = None) -> None: self.store = store @@ -422,6 +423,7 @@ def __init__(self, store: object, *, task_id: str, session_id: str | None, self.model = model self.generation_config = dict(generation_config or {}) self.harness_commit = harness_commit + self.conversation = conversation self.redaction_policy = redaction_policy or TrainingRedactionPolicy.from_environment() self.standard_binding = dict(standard_binding) if standard_binding else None self.turns: list[TrainingTurn] = [] @@ -704,6 +706,7 @@ def finalize(self, *, state: WorkingState, task_status: str, "provenance": { "harness_git_commit": self.harness_commit, "project": self.project, "data_origin": self.data_origin, + "conversation": self.conversation, "workspace_fingerprint": workspace_fingerprint, "model_backend": self.provider, "model": self.model, "generation_configuration": self.generation_config, diff --git a/doc/source/using/context.rst b/doc/source/using/context.rst index 24dbf3a..56376ec 100644 --- a/doc/source/using/context.rst +++ b/doc/source/using/context.rst @@ -86,7 +86,8 @@ Practical consequences * To compare, say so. A comparison is a MIXED question and is given both sides. * ``/clear`` starts a fresh conversation when a session has drifted far from what you now want to ask; ``spear-chat --fresh`` starts a session without - the stored conversation and leaves it for later. + the stored conversation and leaves it for later. ``/session new `` + keeps both: it starts another conversation and leaves this one as it is. * ``/history`` shows what the session is carrying. .. seealso:: diff --git a/doc/source/using/usage.rst b/doc/source/using/usage.rst index 4ff20f7..b414a50 100644 --- a/doc/source/using/usage.rst +++ b/doc/source/using/usage.rst @@ -108,7 +108,7 @@ Direct tools, no model in the loop: Session commands: ``/search `` ``/reindex`` ``/history`` ``/skills`` ``/undo`` - ``/clear`` (``/new``) ``/tools`` ``/model`` (``/switch``) + ``/clear`` (``/new``) ``/session`` ``/tools`` ``/model`` (``/switch``) ``/model`` (or ``/switch``) Change backend or model without leaving the session. @@ -118,6 +118,17 @@ Session commands: are unaffected; only the conversation is dropped, from the store as well. To start one session without it and keep it for later, launch with ``--fresh``. +``/session [list|new |switch |rm ]`` + Named conversations on the same corpus. Each keeps its own history beside + the default one, so a second line of work does not overwrite the first. + ``spear-chat --session `` opens one from the start, and + ``switch default`` returns to the unnamed one. A conversation is open in + one spear-chat at a time: a second process, in another terminal or another + container on the same state directory, is refused it and told to pick + another, which is how two sessions run side by side on one tree. A switch + drops what the previous answer engaged, as ``/clear`` does. Training + episodes record the conversation's name in their provenance. + ``/corpus [list|add|rm|scan]`` The registry, without leaving the session. Registering does not switch corpus (``spear-chat --corpus `` does), but a tree registered inside