M31A keeps conversation history locally. Nothing about a session is sent to a remote storage service; the only network call is the model request described in The agent loop.
The main implementation files are:
| File | Responsibility |
|---|---|
packages/core/src/config/storage.ts | Resolves global and per-project paths. |
packages/core/src/services/chatRecordingService.ts | Appends records to the session file. |
packages/core/src/services/chatRecordingTypes.ts | Defines the record shapes. |
packages/core/src/utils/checkpointUtils.ts | Maps restorable tool calls to snapshots. |
packages/core/src/services/gitService.ts | Creates and restores shadow-Git snapshots. |
packages/core/src/services/sessionSearchIndex.ts | SQLite + FTS5 search index. |
1. Where records live
Global configuration lives in ~/.m31a (or M31A_HOME). Runtime state uses ~/.m31a normally; under macOS Seatbelt it is redirected to ~/.cache/.m31a because the home directory is not writable by the profile.
Per-project state lives under a hash-derived project temp directory returned by Storage.getProjectTempDir(). Inside it:
<project-temp>/
chats/
session-20260101-1200-abcd1234.jsonl # main sessions
<parent-session-id>/
<subagent-session-id>.jsonl # nested subagents
checkpoints/
logs/
tool-outputs/
memory/
plans/
tracker/New sessions are named session-<timestamp>-<short-id>.jsonl. Legacy .json records are migrated to .jsonl on resume. A session ID can also be supplied with --session-id or loaded from --session-file.
2. What is stored
A ConversationRecord contains:
sessionId,projectHash,startTime,lastUpdated, andkind(mainorsubagent);directoriesadded during the session;messages, each with an ID, timestamp, role (user, model turns namedgemini,info,error,warning), content parts, and optional display content;- tool calls with ID, name, arguments, result, status, timestamp, and optional agent ID;
- thoughts and token summaries attached to model turns;
- an optional
summaryandmemoryScratchpadwith workflow metadata; - patch records (
$patch), rewind markers ($rewindTo), and metadata updates ($set).
Writing is append-oriented: new records are appended, and in-place changes such as a tool result arriving after a scheduled call are represented as patches. This keeps a durable trail and allows recovery from an interrupted process. Scheduled tool calls are recorded before execution for exactly that reason.
3. Listing, resuming, exporting
m31a --list-sessions
m31a --resume latest
m31a --resume 5
m31a --session-file /path/to/session.jsonl
m31a --session-id my-custom-id
m31a --delete-session 3--resume, --session-id, and --session-file are mutually exclusive. Inside the app, /chat list|save|resume|delete|share|checkpoints, /resume, /clear, and /export-session cover the same ground.
On resume, M31aChat reconstructs history with the canonical converter so tool calls and thought parts survive the round trip. See Sessions and context for the user-facing commands.
4. Checkpoints and rewind
Checkpointing is opt-in:
{
"general": {"checkpointing": {"enabled": true}}
}When enabled, GitService maintains a shadow Git repository independent of your project's Git history. Before a restorable edit, it creates a file snapshot commit and keeps it reachable under refs/m31a/checkpoints/.... processRestorableToolCalls() maps each tool call to a checkpoint file named from the timestamp, file name, and tool name.
/chat checkpointslists available snapshots./rewindreturns the conversation to an earlier message./restorerestores files from a selected snapshot.
Restores are transactional: the service commits a pre-restore backup under refs/m31a/restore-transactions/... and rolls back to it if the restore fails. Git must be installed for checkpointing; if it is missing, startup fails with an explicit error rather than silently disabling the feature.
5. Retention
general.sessionRetention controls startup cleanup:
| Key | Default | Meaning |
|---|---|---|
enabled | true | Run cleanup at startup. |
maxAge | 30d | Delete sessions older than this. |
maxCount | unset | Keep at most this many recent sessions. |
minRetention | 1d | Safety floor; younger sessions are kept. |
Durations accept h, d, w, and m suffixes. Cleanup requires at least one of maxAge or maxCount; invalid values are rejected. Deleting a session also removes its logs, spilled tool outputs, and nested subagent directories. Spilled tool outputs have their own cleanup path with a default age of seven days.
WARNING
Retention deletes local records. Export anything you need with /export-session before tightening maxAge or maxCount.
6. Session search index
The session_search tool searches across past sessions using a SQLite FTS5 index at ~/.m31a/sessions-fts.sqlite. It indexes session metadata, summaries, and message text from the project's chats/ directory, with a porter unicode61 tokenizer and WAL journaling.
node:sqlite is required, so full-text search is available on Node.js 22 or newer even though M31A itself supports Node.js 20. On Node 20 the tool returns a clear message instead of crashing. Results include the session ID, timestamp, summary, and a matching snippet.
This index is separate from the session files: deleting a session file also removes its artifacts, and the index is refreshed from the directory when the tool runs.
7. Privacy considerations
Session records include full message content, tool arguments, and tool results. Tool output masking and distillation reduce what is sent to the model, not necessarily what is written to disk. Spilled output files live under tool-outputs/ and are cleaned up by age.
Keep credentials out of prompts and tool arguments. Use security.environmentVariableRedaction for environment-derived content, and advanced.excludedEnvVars or advanced.ignoreLocalEnv to keep .env values out of project context. See Sandbox hardening.
Next steps
- Read Context lifecycle for history compaction.
- Read Worktrees for isolated sessions.
- Try Parallel worktrees.