@letta-ai/letta-code 0.13.11 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letta-ai/letta-code",
3
- "version": "0.13.11",
3
+ "version": "0.14.0",
4
4
  "description": "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,7 +40,7 @@
40
40
  "@vscode/ripgrep": "^1.17.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/bun": "latest",
43
+ "@types/bun": "^1.3.7",
44
44
  "@types/diff": "^8.0.0",
45
45
  "@types/picomatch": "^4.0.2",
46
46
  "@types/react": "^19.2.9",
@@ -1,17 +1,26 @@
1
1
  ---
2
2
  name: defragmenting-memory
3
- description: Decomposes and reorganizes agent memory blocks into focused, single-purpose components. Use when memory has large multi-topic blocks, redundancy, or poor organization. Backs up memory, uses a subagent to decompose and clean it up, then restores the improved version.
3
+ description: Decomposes and reorganizes agent memory blocks into focused, single-purpose components. Use when memory has large multi-topic blocks, redundancy, or poor organization.
4
4
  ---
5
5
 
6
6
  # Memory Defragmentation Skill
7
7
 
8
+ > **Requires Memory Filesystem (memfs)**
9
+ >
10
+ > This skill works by directly editing memory files on disk. It requires the memory filesystem feature to be enabled.
11
+ >
12
+ > **To check:** Look for a `memory_filesystem` block in your system prompt. If it shows a tree structure starting with `/memory/` including a `system/` directory, memfs is enabled.
13
+ >
14
+ > **To enable:** Ask the user to run `/memfs enable`, then reload the CLI.
15
+
8
16
  This skill helps you maintain clean, well-organized memory blocks by:
9
- 1. Dumping current memory to local files and backing up the agent file
10
- 2. Using a subagent to decompose and reorganize the files
11
- 3. Restoring the cleaned files back to memory
17
+ 1. Creating a safety backup of the memfs directory
18
+ 2. Using a subagent to decompose and reorganize the memory files in-place
12
19
 
13
20
  The focus is on **decomposition**—splitting large, multi-purpose blocks into focused, single-purpose components—rather than consolidation.
14
21
 
22
+ Memory files live at `~/.letta/agents/$LETTA_AGENT_ID/memory/` and are synced to API blocks automatically by **memfs sync** on CLI startup. There is no separate backup/restore step needed.
23
+
15
24
  ## When to Use
16
25
 
17
26
  - Memory blocks have redundant information
@@ -23,36 +32,62 @@ The focus is on **decomposition**—splitting large, multi-purpose blocks into f
23
32
 
24
33
  ## Workflow
25
34
 
26
- ⚠️ **CRITICAL SAFETY REQUIREMENT**: You MUST complete Step 1 (backup) before proceeding to Step 2. The backup is your safety net. Do not spawn the subagent until the backup is guaranteed to have succeeded.
35
+ ### Step 1: Safety Backup
27
36
 
28
- ### Step 1: Backup Memory to Files
37
+ Before the subagent edits files, create a timestamped backup of the memfs directory:
29
38
 
30
39
  ```bash
31
- npx tsx <SKILL_DIR>/scripts/backup-memory.ts $LETTA_AGENT_ID .letta/backups/working
40
+ cp -r ~/.letta/agents/$LETTA_AGENT_ID/memory/ ~/.letta/agents/$LETTA_AGENT_ID/memory-backup-$(date +%Y%m%d-%H%M%S)/
32
41
  ```
33
42
 
34
- This creates:
35
- - `.letta/backups/<agent-id>/<timestamp>/` - Timestamped memory blocks backup
36
- - `.letta/backups/working/` - Working directory with editable files
37
- - Each memory block as a `.md` file: `persona.md`, `human.md`, `project.md`, etc.
43
+ ⚠️ **CRITICAL**: You MUST complete the backup before proceeding to Step 2. The backup is your safety net.
38
44
 
39
- ### Step 2: Spawn Subagent to Clean Files
45
+ ### Step 2: Spawn Subagent to Edit Memory Files
46
+
47
+ The memory subagent works directly on the memfs `system/` directory. After it finishes, memfs sync will propagate changes to the API on next CLI startup.
40
48
 
41
49
  ```typescript
42
50
  Task({
43
51
  subagent_type: "memory",
44
- description: "Clean up and decompose memory files",
45
- prompt: `⚠️ CRITICAL PREREQUISITE: The agent memory blocks MUST be backed up to .letta/backups/working/ BEFORE you begin this task. The main agent must have run backup-memory.ts first. You are ONLY responsible for editing the files in that working directory—the backup is your safety net.
46
-
47
- You are decomposing and reorganizing memory block files in .letta/backups/working/ to improve clarity and focus. "Decompose" means take large memory blocks with multiple sections and split them into smaller memory blocks, each with fewer sections and a single focused purpose.
52
+ description: "Decompose and reorganize memory files",
53
+ prompt: `You are decomposing and reorganizing memory files in ~/.letta/agents/${LETTA_AGENT_ID}/memory/system/ to improve clarity and focus.
54
+
55
+ These files ARE the agent's memory they sync directly to API memory blocks via memfs. Changes you make here will be picked up automatically.
56
+
57
+ ## Directory Structure
58
+
59
+ ~/.letta/agents/<agent-id>/memory/
60
+ ├── system/ ← Attached blocks (always loaded in system prompt) — EDIT THESE
61
+ ├── notes.md ← Detached blocks at root level (on-demand) — can create here
62
+ ├── archive/ ← Detached blocks can be nested too
63
+ └── .sync-state.json ← DO NOT EDIT (internal sync tracking)
64
+
65
+ ## Files to Skip (DO NOT edit)
66
+ - memory_filesystem.md (auto-generated tree view)
67
+ - skills.md (auto-generated)
68
+ - loaded_skills.md (system-managed)
69
+ - .sync-state.json (internal)
70
+
71
+ ## What to Edit
72
+ - persona.md → Consider splitting into: persona/identity.md, persona/values.md, persona/approach.md
73
+ - project.md → Consider splitting into: project/overview.md, project/architecture.md, project/conventions.md, etc.
74
+ - human.md → Consider splitting into: human/identity.md, human/preferences.md, etc.
75
+ - Any other non-system blocks present
76
+
77
+ ## How Memfs File ↔ Block Mapping Works
78
+ - File path relative to memory root becomes the block label (system/ prefix for attached, root level for detached)
79
+ - Example: system/project/tooling/bun.md → block label "project/tooling/bun"
80
+ - New files you create will become new memory blocks on next sync
81
+ - Files you delete will cause the corresponding blocks to be deleted on next sync
82
+ - YAML frontmatter is supported for metadata (label, description, limit, read_only)
48
83
 
49
84
  ## Evaluation Criteria
50
85
 
51
86
  1. **DECOMPOSITION** - Split large, multi-purpose blocks into focused, single-purpose components
52
- - Example: A "persona" block mixing Git operations, communication style, AND behavioral preferences should become separate blocks like "communication-style.md", "behavioral-preferences.md", "version-control-practices.md"
53
- - Example: A "project" block with structure, patterns, rendering, error handling, and architecture should split into specialized blocks like "architecture.md", "patterns.md", "rendering-approach.md", "error-handling.md"
54
- - Goal: Each block should have ONE clear purpose that can be described in a short title
55
- - Create new files when splitting (e.g., communication-style.md, behavioral-preferences.md)
87
+ - Example: A "persona" block mixing identity, values, AND approach should become persona/identity.md, persona/values.md, persona/approach.md
88
+ - Example: A "project" block with overview, architecture, conventions, and gotchas should split into project/overview.md, project/architecture.md, project/conventions.md, project/gotchas.md
89
+ - Goal: Each block should have ONE clear purpose described by its filename
90
+ - Use hierarchical / naming (e.g., project/tooling/bun.md, not project-tooling-bun.md)
56
91
 
57
92
  2. **STRUCTURE** - Organize content with clear markdown formatting
58
93
  - Use headers (##, ###) for subsections
@@ -80,8 +115,7 @@ You are decomposing and reorganizing memory block files in .letta/backups/workin
80
115
  - Flag blocks where subtopics could be their own focused blocks
81
116
 
82
117
  2. **Decompose** - Split multi-purpose blocks into specialized files
83
- - Create new .md files for each focused purpose
84
- - Use clear, descriptive filenames (e.g., "keyboard-protocols.md", "error-handling-patterns.md")
118
+ - Create new files using hierarchical paths (e.g., project/tooling/bun.md)
85
119
  - Ensure each new block has ONE primary purpose
86
120
 
87
121
  3. **Clean Up** - For remaining blocks (or new focused blocks):
@@ -91,16 +125,10 @@ You are decomposing and reorganizing memory block files in .letta/backups/workin
91
125
  - Improve clarity
92
126
 
93
127
  4. **Delete** - Remove files only when appropriate
94
- - After consolidating into other blocks (rare - most blocks should stay focused)
128
+ - After moving all content to new decomposed files
95
129
  - Never delete a focused, single-purpose block
96
130
  - Only delete if a block contains junk/irrelevant data with no value
97
131
 
98
- ## Files to Edit
99
- - persona.md → Consider splitting into: communication-style.md, behavioral-preferences.md, technical-practices.md
100
- - project.md → Consider splitting into: architecture.md, patterns.md, rendering.md, error-handling.md, etc.
101
- - human.md → OK to keep as-is if focused on understanding the user
102
- - DO NOT edit: skills.md (auto-generated), loaded_skills.md (system-managed)
103
-
104
132
  ## Success Indicators
105
133
  - No block tries to cover 2+ distinct topics
106
134
  - Each block title clearly describes its single purpose
@@ -118,86 +146,63 @@ Provide a detailed report including:
118
146
  ```
119
147
 
120
148
  The subagent will:
121
- - Read the files from `.letta/backups/working/`
122
- - Edit them to reorganize and consolidate redundancy
123
- - Merge related blocks together for better organization
149
+ - Read files from `~/.letta/agents/<agent-id>/memory/system/` (and root level for detached)
150
+ - Edit them to reorganize and decompose large blocks
151
+ - Create new hierarchically-named files (e.g., `project/overview.md`)
124
152
  - Add clear structure with markdown formatting
125
- - Delete source files after merging their content into other blocks
126
- - Provide a detailed report of changes (including what was merged where)
127
-
128
- ### Step 3: Restore Cleaned Files to Memory
153
+ - Delete source files after decomposing their content into focused children
154
+ - Provide a detailed report of changes
129
155
 
130
- ```bash
131
- npx tsx <SKILL_DIR>/scripts/restore-memory.ts $LETTA_AGENT_ID .letta/backups/working
132
- ```
133
-
134
- This will:
135
- - Compare each file to current memory blocks
136
- - Update only the blocks that changed
137
- - Show before/after character counts
138
- - Skip unchanged blocks
156
+ After the subagent finishes, **memfs sync will automatically propagate changes** to API blocks on the next CLI startup. No manual restore step is needed.
139
157
 
140
158
  ## Example Complete Flow
141
159
 
142
160
  ```typescript
143
- // ⚠️ STEP 1 IS MANDATORY: Backup memory to files
144
- // This MUST complete successfully before proceeding to Step 2
161
+ // Step 1: Safety backup (MANDATORY)
145
162
  Bash({
146
- command: "npx tsx <SKILL_DIR>/scripts/backup-memory.ts $LETTA_AGENT_ID .letta/backups/working",
147
- description: "Backup memory to files (MANDATORY prerequisite)"
163
+ command: "cp -r ~/.letta/agents/$LETTA_AGENT_ID/memory/ ~/.letta/agents/$LETTA_AGENT_ID/memory-backup-$(date +%Y%m%d-%H%M%S)/",
164
+ description: "Backup memfs directory before defrag"
148
165
  })
149
166
 
150
- // ⚠️ STEP 2 CAN ONLY BEGIN AFTER STEP 1 SUCCEEDS
151
- // The subagent works on the backed-up files, with the original memory safe
167
+ // Step 2: Spawn subagent to decompose and reorganize
152
168
  Task({
153
169
  subagent_type: "memory",
154
- description: "Clean up and decompose memory files",
155
- prompt: "Decompose and reorganize memory block files in .letta/backups/working/. Be aggressive about splitting large multi-section blocks into many smaller, single-purpose blocks with fewer sections. Prefer creating new focused files over keeping large blocks. Structure with markdown headers and bullets. Remove redundancy and speculation. Resolve contradictions. Organize logically. Each block should have ONE clear purpose. Create new files for decomposed blocks rather than consolidating. Report files created, modified, deleted, before/after character counts, and rationale for changes."
170
+ description: "Decompose and reorganize memory files",
171
+ prompt: "Decompose and reorganize memory files in ~/.letta/agents/$LETTA_AGENT_ID/memory/system/. These files sync directly to API blocks via memfs. Be aggressive about splitting large multi-section blocks into many smaller, single-purpose blocks using hierarchical / naming. Skip memory_filesystem.md, skills.md, loaded_skills.md, and .sync-state.json. Structure with markdown headers and bullets. Remove redundancy and speculation. Resolve contradictions. Organize logically. Each block should have ONE clear purpose. Report files created, modified, deleted, before/after character counts, and rationale for changes."
156
172
  })
157
173
 
158
- // Step 3: Restore (only after cleanup is approved)
159
- // Review the subagent's report before running this
160
- Bash({
161
- command: "npx tsx <SKILL_DIR>/scripts/restore-memory.ts $LETTA_AGENT_ID .letta/backups/working",
162
- description: "Restore cleaned memory blocks"
163
- })
174
+ // No Step 3 needed memfs sync handles propagation to API blocks
164
175
  ```
165
176
 
166
177
  ## Rollback
167
178
 
168
- If something goes wrong, restore from a previous backup:
179
+ If something goes wrong, restore from the safety backup:
169
180
 
170
181
  ```bash
171
- # Find the backup directory
172
- ls -la .letta/backups/<agent-id>/
182
+ # Find backups
183
+ ls -la ~/.letta/agents/$LETTA_AGENT_ID/memory-backup-*/
173
184
 
174
- # Restore from specific timestamp
175
- npx tsx <SKILL_DIR>/scripts/restore-memory.ts $LETTA_AGENT_ID .letta/backups/<agent-id>/<timestamp>
185
+ # Restore from a specific backup (replace the current memory dir)
186
+ rm -rf ~/.letta/agents/$LETTA_AGENT_ID/memory/
187
+ cp -r ~/.letta/agents/$LETTA_AGENT_ID/memory-backup-<TIMESTAMP>/ ~/.letta/agents/$LETTA_AGENT_ID/memory/
176
188
  ```
177
189
 
178
- ## Dry Run
179
-
180
- Preview changes without applying them:
181
-
182
- ```bash
183
- npx tsx <SKILL_DIR>/scripts/restore-memory.ts $LETTA_AGENT_ID .letta/backups/working --dry-run
184
- ```
190
+ On next CLI startup, memfs sync will detect the changes and update API blocks accordingly.
185
191
 
186
192
  ## What the Subagent Does
187
193
 
188
194
  The subagent focuses on decomposing and cleaning up files. It has full tool access (including Bash) and:
189
- - Discovers `.md` files in `.letta/backups/working/` (via Glob or Bash)
195
+ - Discovers `.md` files in `~/.letta/agents/<agent-id>/memory/system/` (via Glob or Bash)
190
196
  - Reads and examines each file's content
191
197
  - Identifies multi-purpose blocks that serve 2+ distinct purposes
192
- - Splits large blocks into focused, single-purpose components
198
+ - Splits large blocks into focused, single-purpose components with hierarchical naming
193
199
  - Modifies/creates .md files for decomposed blocks
194
200
  - Improves structure with headers and bullet points
195
201
  - Removes redundancy and speculation across blocks
196
202
  - Resolves contradictions with clear, concrete guidance
197
203
  - Organizes content logically (general to specific, by importance)
198
204
  - Provides detailed before/after reports including decomposition rationale
199
- - Does NOT run backup scripts (main agent does this)
200
- - Does NOT run restore scripts (main agent does this)
205
+ - Does NOT run any backup or restore scripts
201
206
 
202
207
  The focus is on decomposition—breaking apart large monolithic blocks into focused, specialized components rather than consolidating them together.
203
208
 
@@ -212,17 +217,17 @@ The focus is on decomposition—breaking apart large monolithic blocks into focu
212
217
 
213
218
  **Decomposition Strategy:**
214
219
  - Split blocks that serve 2+ distinct purposes into focused components
215
- - Create new specialized blocks with clear, single-purpose titles
216
- - Example: A "persona" mixing communication style + Git practices → split into "communication-style.md" and "version-control-practices.md"
217
- - Example: A "project" with structure + patterns + rendering → split into "architecture.md", "patterns.md", "rendering.md"
220
+ - Use hierarchical `/` naming: `project/tooling/bun.md`, not `project-bun.md`
221
+ - Create parent index files that reference children
222
+ - Example: A "persona" mixing identity + values + approach → split into `persona/identity.md`, `persona/values.md`, `persona/approach.md`
223
+ - Example: A "project" with overview + architecture + conventions → split into `project/overview.md`, `project/architecture.md`, `project/conventions.md`
218
224
  - Add clear headers and bullet points for scannability
219
225
  - Group similar information together within focused blocks
220
226
 
221
227
  **When to DELETE a file:**
222
228
  - Only delete if file contains junk/irrelevant data with no project value
223
- - Don't delete after decomposing - Each new focused block is valuable
229
+ - Delete source files after fully decomposing content into child files
224
230
  - Don't delete unique information just to reduce file count
225
- - Exception: Delete source files only if consolidating multiple blocks into one (rare)
226
231
 
227
232
  **What to preserve:**
228
233
  - User preferences (sacred - never delete)
@@ -236,3 +241,4 @@ The focus is on decomposition—breaking apart large monolithic blocks into focu
236
241
  - Organize with bullet points
237
242
  - Keep related information together
238
243
  - Make it scannable at a glance
244
+ - Use `/` hierarchy for discoverability