Principle:AI Shell Team Aish Shell Session Restoration
| Knowledge Sources | |
|---|---|
| Domains | Session_Management, Shell |
| Last Updated | 2026-10 00:00 GMT |
Overview
Pattern for restoring a complete interactive shell session from persisted state, assembling the LLM session, context manager, PTY, and session store into a functional shell.
Description
Shell Session Restoration is the mechanism that ties together all the resume components into a working AishShell instance. The AishShell::resume constructor creates a new shell instance and immediately calls resume_session_with_options, which loads the session from the store, reconstructs the LLM session from stored credentials, seeds the context manager with the transcript, starts a PTY in the saved working directory, and wires up the security manager and session store.
The resume_session_with_options method handles the full flow: optionally persisting the current session before switching, loading the target session, seeding context, reconstructing the LLM session, starting the PTY, and optionally printing a resume confirmation. If the resume fails, the transient session is cleaned up.
This pattern solves the problem of resuming an interrupted AI shell session exactly where it left off, with the same provider, model, working directory, and conversation context.
Usage
Use this principle when an application must support session resume. The restoration should be atomic: either the full shell is restored or the transient state is cleaned up.
Theoretical Basis
The restoration is an atomic assembly of components:
# Abstract algorithm (NOT real implementation)
def AishShell_resume(config, session_id):
shell = AishShell.new(config) # transient
try:
shell.resume_session_with_options(session_id, persist_current=False, print_success=False)
except error:
shell.session_store.delete(shell.transient_uuid)
raise
# Clean up transient if a different session was loaded
if shell.session_uuid != transient_uuid:
shell.session_store.delete(transient_uuid)
return shell
def resume_session_with_options(session_id, persist_current, print_success):
if persist_current:
persist_current_session()
session = store.get_session(session_id)
messages = store.get_ai_messages(session_id)
context_manager.seed_from_snapshot(messages)
llm_session = LlmSession.new(session.api_base, session.api_key, session.model, ...)
pty = PersistentPty.start(session.cwd, rows, cols)
# Wire up security, tools, event handlers
Key design ideas:
- Atomic assembly: all components (LLM, context, PTY, security) are assembled together; failure cleans up
- Transient cleanup: if resume succeeds with a different session, the transient session is deleted
- Optional persistence: the current session can be saved before switching