Lazy-loading context restore with 3 levels. Fast startup with minimal tokens. Keywords: context, memory, session, restore, recap, remember, resume, continue.
Khoi phuc context voi 3 cap do de tiet kiem token.
| Level | Tokens | Khi nao | Gi duoc load |
|---|---|---|---|
| 1 | ~200 | Luon luon | summary, current task, blockers |
| 2 | ~800 | /recap full | + decisions, pending tasks, recent files |
| 3 | ~2000 | /recap deep | + full history, all errors, conversation |
/recap ā Level 1 (nhanh)/recap full ā Level 1 + 2/recap deep ā Level 1 + 2 + 3/recap [topic] ā Smart searchload_level_1():
summary = session.summary
show:
"""
š Chao mung tro lai!
š Project: {summary.project}
š Dang lam: {summary.current_feature}
āā Task: {summary.current_task}
āā Status: {summary.status} ({summary.progress_percent}%)
āļø Buoc tiep: {summary.next_step}
š Last saved: {format_time(updated_at)}
"""
# Token cost: ~200
load_level_2():
load_level_1()
decisions = session.decisions_made[-5:] # Last 5
pending = session.pending_tasks[:5] # Next 5
files = session.working_on.files
show:
"""
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Quyet dinh gan day:
{format_decisions(decisions)}
š Viec can lam:
{format_pending(pending)}
š Files dang sua:
{format_files(files)}
"""
# Token cost: ~800 total
load_level_3():
load_level_2()
errors = session.errors_encountered
checkpoints = session.context_checkpoints
changes = session.recent_changes
show:
"""
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Lich su loi:
{format_errors(errors)}
š¾ Checkpoints:
{format_checkpoints(checkpoints)}
š Thay doi gan day:
{format_changes(changes)}
"""
# Token cost: ~2000 total
recap_topic(topic):
# Search in all tiers
results = search_session(topic)
results += search_brain(topic)
show:
"""
š Tim kiem: "{topic}"
{format_search_results(results)}
"""
# Only load relevant context
Khi bat dau session, inject Level 1 vao system prompt:
## Session Context (Auto-loaded)
- Project: {project}
- Feature: {current_feature}
- Task: {current_task}
- Status: {status} ({progress}%)
- Blockers: {blockers_count}
[Conversation continues below...]
Total context: 128K tokens
āāā System prompt: 10K (fixed)
āāā Conversation: 100K (dynamic)
āāā Session load: 8K max
ā āāā Level 1: 200 (always)
ā āāā Level 2: 600 (on-demand)
ā āāā Level 3: 1200 (explicit)
āāā Buffer: 10K (safety)
š Chao mung tro lai!
š Project: ThaoCoffe
š Dang lam: User Authentication
āā Task: Login form validation
āā Status: coding (65%)
āļø Buoc tiep: Add password validation
š Last saved: 2 gio truoc
š” Go /recap full de xem chi tiet.
[Level 1 output]
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Quyet dinh gan day:
⢠Dung NextAuth (don gian hon)
⢠Validation bang Zod
⢠Session-based auth
š Viec can lam:
1. [HIGH] Add password validation
2. [MED] Implement remember me
3. [LOW] Add forgot password
š Files dang sua:
⢠src/app/login/page.tsx
⢠src/lib/auth.ts
[Level 1+2 output]
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Lich su loi:
⢠CORS error ā Fixed: added middleware
⢠Type error ā Fixed: added null check
š¾ Checkpoints (7 ngay):
⢠2024-01-15 14:30 - workflow_end
⢠2024-01-16 09:00 - user_leaving
š Thay doi gan day:
⢠[feature] Added login form
⢠[bugfix] Fixed CORS issue
if session.json not found:
show: "Chua co session. Bat dau moi nhe!"
skip restore
if session.json corrupted:
try: restore from latest snapshot
if success:
show: "Da khoi phuc tu backup."
else:
show: "Session bi loi. Bat dau fresh!"
create new session
if summary missing:
generate summary from available data
save to session.json