Session Management Command
Relevant Source Files
The palee session command suite manages the real-time learning lifecycle, active focus tracking, and persistence of study session records. It maintains a short-term "working memory" file (.palee/hot.md), a chronological session index (.palee/index.md), and durable session notes in .palee/sessions/.
1. Session Lifecycle & Architecture
A session represents an active period of study focused on a single PALEE topic. The lifecycle encompasses topic resolution, working memory synchronization, interim draft checkpoints, and final session confirmation.
Topic Resolution Hierarchy
When running commands that require an active study target (draft, end), PALEE resolves the target topic using a strict three-tier hierarchy via resolveSessionTopic() src/cli/session.ts#24-54:
- CLI Flag Override: Explicitly specified via
--topic <id>(e.g.--topic "T-rust-ownership"). - Working Memory Inspection: Extracted from the
active_topicfrontmatter property of.palee/hot.md. - Missing Topic Error: If neither is present or the value is
(none), the command terminates with exit code2.
Working Memory (hot.md), Index (index.md) & True Duration Tracking
.palee/hot.md(Working Memory): Automatically generated and refreshed byrebuildHotAndIndex()src/storage/memory.ts. Contains metadata on the current active topic (active_topic), session start timestamp (started_at), timestamp of last update (updated_at), and a truncated 250-word working memory excerpt of the note body for quick context recovery..palee/index.md(Session Index): Chronological index of completed learning sessions, cross-referenced with topic IDs and formatted as Obsidian-style links.- True Session Duration Persistence: When a session starts or checkpoints, its precise ISO-8601 start timestamp (
started_at) is written to.palee/hot.mdand interim draft checkpoints. Upon session completion, PALEE computes the exact elapsed study time in minutes and persistsstarted_at,ended_at, andduration_minutesto the permanent session note.
Draft Recovery Protocol
If an unexpected interruption occurs (such as terminal closure or system reboot), PALEE leaves an unconfirmed draft note (DRAFT-S-<hex>.md) in .palee/sessions/ preserving the original started_at timestamp.
When palee session start is executed:
- Non-Interactive Mode: Alerts the user that unconfirmed drafts exist and suggests running
palee session start --interactive(exiting with code2or emittingstatus: 'drafts_pending'in JSON mode). - Interactive Mode (
-i, --interactive): Prompts the user with four recovery options for each orphaned draft src/cli/session.ts#96-112:[R]esume: Continues the previous session, retaining the draft.[S]ave: Immediately finalizes and converts the draft into a confirmed session note (S-*.md), calculating true elapsed duration from itsstarted_attimestamp, and unlinks the draft.[D]iscard: Safely unlinks the orphaned draft checkpoint viadeleteSessionNote().[I]gnore: Leaves the draft file untouched on disk.
2. Command Subactions
The palee session command accepts four distinct action arguments:
1. palee session start
Initializes the study environment:
- Scans
.palee/sessions/for unconfirmed draft checkpoints. - Rebuilds
hot.mdif missing or corrupted usingresetHotMemory()andrebuildHotAndIndex(). - Records the current timestamp as
started_atin.palee/hot.mdfor the resolved topic. - Prints the active topic ID, last session timestamp, and the working memory body excerpt from
hot.md.
# Start study session in interactive recovery mode
palee session start --interactive
# Query session start status as structured JSON (emits drafts_pending on unconfirmed checkpoints)
palee session start --json2. palee session draft
Captures an interim checkpoint during an ongoing study session without closing the session:
- Resolves the study topic (
--topicor active topic fromhot.md). - Inherits the
started_attimestamp from active hot memory if available, or records current timestamp. - Generates a unique draft identifier (
DRAFT-S-<random_hex>). - Persists a draft markdown file in
.palee/sessions/containingtopic_id,started_at, andstatus: 'draft'.
# Capture a checkpoint for the active topic
palee session draft
# Capture a checkpoint for an explicit topic
palee session draft --topic "T-20260814T120000-abcd"3. palee session end
Concludes the study period, calculates actual elapsed time, and formalizes the session:
- Resolves the target topic ID (via
--topicorhot.md). - 3-Tier Start Timestamp Recovery Algorithm:
- Tier 1 (Topic Draft Checkpoints): Queries
getTopicDrafts(vaultPath, topicId)for active drafts matching the topic, sorting chronologically to recover the earlieststarted_at. - Tier 2 (Active Working Memory): Reads
started_atfrom.palee/hot.mdifactive_topicmatches the session topic. - Tier 3 (Current Instant Fallback): Falls back to the current instant
ended_atif no prior timestamp exists.
- Tier 1 (Topic Draft Checkpoints): Queries
- Duration Calculation:typescript
const endedAt = new Date().toISOString(); const durationMs = Math.max(0, new Date(endedAt).getTime() - new Date(startedAt).getTime()); const durationMinutes = Math.round(durationMs / 60000); - Generates a confirmed session ID (
S-YYYYMMDDTHHMMSS-<hex>.md) and writes the permanent session note viawriteSessionNote()containingstarted_at,ended_at,duration_minutes, andstatus: 'completed'. - Deletes matching draft checkpoints via storage helper
deleteTopicDrafts(vaultPath, topicId). - Executes
rebuildHotAndIndex()to refreshhot.mdandindex.md.
# Finalize the current study session
palee session end --topic "T-20260814T120000-abcd"4. palee session list
Displays session history and pending drafts:
- Lists the most recent 10 confirmed sessions in chronological order.
- Lists all active draft checkpoints awaiting resolution.
- Supports
--jsonfor machine-readable integrations.
# List sessions in terminal
palee session list
# Output structured session JSON
palee session list --json3. Options Reference for palee session
The following table lists all supported arguments and options for palee session src/types.ts#464-474:
| Parameter / Flag | Type | Default | Description | Example |
|---|---|---|---|---|
<action> | string | Required | Session action to perform: start, draft, end, or list. | palee session start |
-i, --interactive | boolean | false | Enable interactive prompt mode for draft recovery during palee session start. | palee session start -i |
--topic <id> | string | undefined | Target topic ID. Overrides the active_topic defined in .palee/hot.md. | palee session end --topic "T-01" |
--json | boolean | false | Output results as structured JSON (supported for palee session start and palee session list). | palee session start --json |
4. Physical Storage Layout & Boundary Isolation
All session metadata is isolated within the .palee/ directory at the vault root. CLI command handlers interact with this storage strictly via dedicated storage helpers (src/storage/index.ts), with zero direct fs.unlinkSync or fs.mkdirSync calls in CLI handlers:
<vaultPath>/
├── .palee/
│ ├── hot.md # Active working memory, topic context & started_at
│ ├── index.md # Chronological session index
│ └── sessions/
│ ├── S-20260814T120000-abcd.md # Confirmed session record (with duration_minutes)
│ ├── S-20260814T153000-efgh.md # Confirmed session record (with duration_minutes)
│ └── DRAFT-S-98765432.md # Unconfirmed draft checkpoint (with started_at)
└── Topics/
└── Topic-Note.mdFile Naming & Schema Specifications
| File Type | Path Pattern | Frontmatter Key Fields |
|---|---|---|
| Working Memory | .palee/hot.md | palee_schema: 1, memory_id: "H-active", active_topic: string | null, started_at: string | null, last_session: string | null, updated_at: string |
| Confirmed Session | .palee/sessions/S-<TIMESTAMP>-<HEX>.md | palee_schema: 1, session_id: string, topic_id: string, started_at: string, ended_at: string, duration_minutes: number, status: "completed" |
| Draft Checkpoint | .palee/sessions/DRAFT-S-<HEX>.md | palee_schema: 1, session_id: string, topic_id: string, started_at: string, ended_at: null, status: "draft" |
5. Exit Codes for Session Management
| Command | Exit Code 0 | Exit Code 1 | Exit Code 2 | Exit Code 3 | Exit Code 4 | Exit Code 5 |
|---|---|---|---|---|---|---|
palee session | Session action (start, draft, end, list) completed successfully. | N/A | Vault path not configured, missing --topic for draft/end when no active topic exists, unconfirmed drafts blocking non-interactive session start, or unknown action specified. | N/A | OCC conflict during session note write or hot.md update (isConflictError). | Unexpected runtime exception or storage boundary violation error. |
