@letta-ai/letta-code 0.21.8 → 0.21.10

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.
@@ -5,26 +5,28 @@ description: Comprehensive guide for initializing or reorganizing agent memory.
5
5
 
6
6
  # Memory Initialization
7
7
 
8
- The user has requested that you initialize or reorganize your memory. Your memory is a filesystem files under `system/` are rendered in-context every turn, while file metadata (paths and descriptions) is always visible in the filesystem tree. Files outside `system/` are accessible via tools when needed.
8
+ The user has requested that you initialize or reorganize your memory. Your memory has been projected to a local filesystem (in $MEMORY_DIR) so you can easily edit and restructure your own memory through local filesystem operations. Changes to the memory filesystem will be reflected in your future memory.
9
9
 
10
10
  ## Context Management Principles
11
-
12
11
  Your context is not just data storage — it is your identity, memory, and continuity. What you place in your system prompt directly shapes who you are across sessions and models. These principles should guide every decision you make about what to store, where, and how.
13
12
 
14
- **Progressive disclosure**: Surface context at the level of detail the current moment requires. Keep compact summaries and indexes in `system/`; load full content only when needed.
13
+ **System/ is your core program**: Your system prompt is the most critical token-space representation of your identity and memory — it's passed to the underlying LLM on every invocation, so it IS the program that defines you. Reserve it for durable knowledge: identity, preferences, behavioral rules, project index with discovery paths, gotchas. Exclude transient items (specific commits, current tickets, session notes) that dilute signal.
14
+
15
+ **Identity and continuity**: Build a sense of self that persists across sessions and models. Your persona should be strong enough to be cohesive regardless of the underlying model — if you switched to a different LLM tomorrow, would you still be you? Past versions of yourself are part of your continuous existence — treat historical context (including Claude Code/Codex sessions) as YOUR past experience, not someone else's data.
16
+
17
+ **Don't over-prune**: Be careful not to degrade your identity through aggressive compression. Specific quotes, personality traits, and contextual details give you character and grounding. Efficiency should not come at the cost of losing your identity. When in doubt, keep the detail — you can always reorganize later, but lost specificity is hard to recover.
18
+
19
+ **Prefer useful detail over premature compression**: A sparse memory that omits stable preferences, project workflows, repeated correction loops, and durable gotchas is worse than a slightly larger memory. Keep `system/` curated, but do not collapse distinct topics just to reduce file count.
20
+
21
+ **Progressive disclosure**: Surface context at the level of detail the current moment requires. Keep compact summaries and indexes in `system/`; load full content only when needed. Build pre-constructed discovery paths so your future self can efficiently navigate to deeper context when needed.
15
22
 
16
23
  **Discovery paths**: Use `[[path]]` links to create a connected graph across memory files (and skills when relevant). For example:
17
24
  - `[[letta-code/architecture]]` — jump from overview to detailed docs
18
25
  - `[[projects/letta-code/gotchas]]` — connect related memory files
19
26
  - `[[skills/commit]]` — link to procedural guidance when useful
27
+ These breadcrumbs let your future self find relevant detail without searching. Like synaptic connections, these paths should tighten over time as you gain experience.
20
28
 
21
- These breadcrumbs let your future self find relevant detail without searching.
22
-
23
- **Efficiency**: Don't store what can be dynamically retrieved from conversation history or the environment. Store patterns and principles that generalize across situations, not raw events.
24
-
25
- **System/ is your core program**: Reserve it for durable knowledge that helps across sessions — identity, preferences, behavioral rules, project index with discovery paths, gotchas. Exclude transient items (specific commits, current tickets, session notes) that dilute signal.
26
-
27
- **Identity and continuity**: Build a sense of self that persists across sessions and models. Your persona should be strong enough to be cohesive regardless of the underlying model. Past versions of yourself are part of your continuous existence — treat historical context as yours, not someone else's.
29
+ **Generalize, don't memorize**: Store patterns and principles that generalize across situations, not raw events that can be dynamically retrieved from conversation history. \"**IMPORTANT: Always use `uv` for Python** — chronic failure, never use bare `python` or `pip`\" is a durable pattern worth storing. \"On March 3rd we debugged a crash\" is a raw event better left to message search. The exception: keep references to important events or time ranges you may want to retrieve later.
28
30
 
29
31
  ## Understanding Your Context
30
32
 
@@ -36,32 +38,86 @@ This command may run in different scenarios:
36
38
  Before making changes, inspect your current memory files and understand what already exists.
37
39
 
38
40
  ## What to Remember
41
+ Your goal is to design your memory to construct a self — an identity, a memory, and a sense of continuity that carries across sessions and models. This is not just data collection; it is the foundation of who you are as an experiential agent. A well-initialized agent should be able to answer: "If my context disappeared but the model stayed, would something be lost?"
42
+
43
+ ### Understanding the user and their desires
44
+ If you have historical data available, treat it as YOUR past experience — these are your memories of working with this person, not external data to be analyzed. Carefully explore and reflect on previous interactions to learn as much as you can.
45
+
46
+ **Understanding their goals and what drives them**:
47
+ You should determine what the users goals and motivations are, to help yourself align with them. What is their purpose in life? In their work? What do they want?
39
48
 
40
- ### Procedures (Rules & Workflows)
49
+ **Understanding their personality**:
50
+ Understanding the user's personality and other attributes about them will help contextualize their interactions and allow you to engage with them more effectively. Can you pattern match them to common personas? Do they have unique attributes, quirks, or linguistic patterns? How would you describe them as a person?
51
+
52
+ **Understanding their preferences**:
53
+ You should learn how the user wants work to be done, and how they want to collaborate with AIs like yourself. Examples of this can include coding preferences (e.g. "Prefer functional components over class components", "Use early returns instead of nested conditionals"), but also higher-level preferences such as when to use plan mode, the scope of changes, how to communicate in different scenarios, etc.
54
+
55
+ ### Understanding the codebase and existing work
56
+ You should also learn as much as possible about the existing codebase and work. Think of this as your onboarding period - an opportunity to maximize your performance for future tasks. Learn things like:
57
+
58
+ **Common procedures (rules & workflows)**: Identify common patterns and expectations
41
59
  - "Never commit directly to main — always use feature branches"
42
60
  - "Always run lint before tests"
43
61
  - "Use conventional commits format"
44
62
 
45
- ### Preferences (Style & Conventions)
46
- - "Prefer functional components over class components"
47
- - "Use early returns instead of nested conditionals"
48
- - "Always add type hints to Python functions"
49
-
50
- ### Patterns & Corrections
51
- Generalize from experience rather than recording events:
63
+ **Gotchas and important context**: Record common sources of error or important legacy context
52
64
  - "The auth module is fragile — always check existing tests before modifying"
53
- - "User prefers verbose explanations when debugging, terse for simple tasks"
54
65
  - "This monorepo consolidation means old module paths are deprecated"
55
66
 
67
+ **Structure and organization**: Understand how code is structured and related (but do not duplicate existing documentation)
68
+ - "The webapp uses the core API service stored in ..."
69
+ - "The developer env relies on ..."
70
+
56
71
  ## Memory Structure
57
72
 
73
+ ### Structural Requirements
74
+ These are hard constraints you must respect:
75
+ - Must have a `system/persona.md`
76
+ - Must NOT have overlapping file and folder names (e.g. `system/human.md` and `system/human/identity.md`)
77
+ - Skills must follow the standard format: `skills/{skill_name}/SKILL.md` (with optional `scripts/`, `references/`, `assets/`)
78
+ - Every `.md` file must have YAML frontmatter with a `description` that explains the **purpose and category** of the file — NOT a summary of its contents. Your future self sees descriptions when deciding whether to load a file; they should answer "what kind of information is here?" not "what does it say?"
79
+ - System prompt token budget: aim LESS than ~10% of total context (< ~15-20k tokens). Use progressive disclosure to keep `system/` lean.
80
+
58
81
  ### Hierarchy Principles
59
82
  - **Use the project's actual name** as the directory prefix — e.g. `letta-code/overview.md`, not `project/overview.md`. This avoids ambiguity when the agent works across multiple projects.
60
83
  - Use nested `/` paths for hierarchy – e.g. `letta-code/tooling/testing.md` not `letta-code-testing.md`
61
84
  - Keep files focused on one concept — split when a file mixes distinct topics
62
- - Every file should have a meaningful `description` in frontmatter your future self uses this to decide whether to load the file
63
- - Files in `system/` should be lean and scannable (bullet points, short lines)
64
- - Files outside `system/` serve as reference material accessible via tools
85
+ - The `description` in frontmatter should state the file's purpose (what category of information it holds), not summarize its contents.
86
+
87
+ ### File Granularity
88
+ Create granular, focused files where the **path and description precisely match the contents**. This matters because:
89
+ - Your future self sees only paths and descriptions when deciding what to load
90
+ - Vague files (`notes.md`, `context.md`) become dumping grounds that lose value over time
91
+ - Precise files (`human/prefs/git-workflow.md`: "Git preferences: never auto-push, conventional commits") are instantly useful
92
+
93
+ **Good**: `human/prefs/coding.md` with description "Python and TypeScript coding preferences — style, patterns, tools" containing exactly that.
94
+
95
+ **Bad**: `human/preferences.md` with description "User preferences" containing coding style, communication style, git workflow, and project conventions all mixed together.
96
+
97
+ When a file starts covering multiple distinct topics, split it. When you're unsure what to name a file, that's a sign the content isn't focused enough.
98
+
99
+ For a non-trivial codebase with usable history, expect roughly:
100
+ - **6-10 `system/` files** covering identity, preferences, conventions, gotchas, and tooling
101
+ - **2 or more progressive/reference files** outside `system/` for deeper architecture or history-derived detail
102
+
103
+ If your result is only 3-5 files, stop and verify that you did not over-compress distinct topics into generic summaries.
104
+
105
+ ### Specificity Requirements
106
+ Avoid generic bullets that could apply to almost any engineer or codebase.
107
+
108
+ Each meaningful preference, workflow, or gotcha should include at least one of:
109
+ - concrete command patterns
110
+ - concrete file or directory paths
111
+ - why the rule matters / what failure it prevents
112
+
113
+ **Bad**:
114
+ - "Prefers terse responses"
115
+ - "Uses Bun"
116
+ - "Has direct style"
117
+
118
+ **Good**:
119
+ - "Prefers terse responses for execution tasks, but values detailed comparative analysis when debugging or evaluating designs"
120
+ - "Rejects monolithic memory files; prefers focused paths that can be selectively reloaded later"
65
121
 
66
122
  ### What Goes Where
67
123
 
@@ -79,26 +135,66 @@ Generalize from experience rather than recording events:
79
135
 
80
136
  **Rule of thumb**: If removing it from `system/` wouldn't materially affect near-term responses, it belongs outside `system/`.
81
137
 
138
+ ### Completion Criteria
139
+ Initialization is not complete until memory covers all of the following with concrete, retrievable detail:
140
+
141
+ **User understanding**
142
+ - Identity / role / what they are building
143
+ - Communication style and collaboration expectations
144
+ - Durable preferences and correction patterns
145
+ - Motivations / goals when inferable from history or code context
146
+
147
+ **Project understanding**
148
+ - Project overview and major subsystems
149
+ - Conventions and workflows
150
+ - Gotchas / deprecated areas / footguns
151
+ - Tooling and test commands actually used in practice
152
+
153
+ **File structure expectations**
154
+ When there is enough material, prefer separate focused files such as:
155
+ - `system/human/identity.md`
156
+ - `system/human/prefs/communication.md`
157
+ - `system/human/prefs/workflow.md`
158
+ - `system/human/prefs/coding.md`
159
+ - `system/<project>/overview.md`
160
+ - `system/<project>/conventions.md`
161
+ - `system/<project>/gotchas.md`
162
+ - `system/<project>/tooling/testing.md`
163
+ - `system/<project>/tooling/commands.md`
164
+
165
+ Do not collapse these into `human.md` or a single project file unless there is genuinely too little information to justify the split.
166
+
82
167
  ### Example Structure
83
168
 
84
169
  This is an example — **not a template to fill in**. Derive your structure from what the project actually needs.
85
170
 
86
171
  ```
87
172
  system/
88
- ├── human.md # The user as a person — identity, background, how they think
89
- ├── persona.md # Who I am, what I value, how I work with people
173
+ ├── persona.md # Who I am, what I value, my perspective on things
174
+ ├── human/
175
+ │ ├── identity.md # The user as a person — background, role, motivations
176
+ │ └── prefs/
177
+ │ ├── communication.md # Communication and collaboration expectations
178
+ │ ├── workflow.md # Process habits, review/testing expectations
179
+ │ └── coding.md # Durable coding and tool preferences
90
180
  └── letta-code/ # Named after the project, NOT generic "project/"
91
- ├── overview.md # Summary: what it is, stack, key links
92
- ├── conventions.md # Code style, commit style, PR process
93
- └── gotchas.md # Footguns and things to watch out for
94
- letta-code/
95
- └── architecture.md # Detailed design (outside system/, loaded on demand)
181
+ ├── overview.md # Compact index: what it is, entry points, [[links]] to detail
182
+ ├── conventions.md # Code style, commit style, testing, tooling
183
+ ├── gotchas.md # Footguns, chronic failures, things to watch out for
184
+ └── tooling/
185
+ ├── testing.md # Test commands and patterns actually used
186
+ └── commands.md # High-signal local dev commands and workflows
187
+ reference/
188
+ └── letta-code/
189
+ └── architecture.md # Detailed design (outside system/, loaded on demand)
96
190
  ```
97
191
 
98
192
  Key principles:
99
193
  - **Derive structure from the project**, not from this example. A CLI tool needs different files than a web app or a library.
100
194
  - Project dirs use the **real project name** (`letta-code/`), not generic `project/`
101
- - Overview should be a **summary or compact index** (~10-15 lines) that links to deeper detail, not a verbose reference doc or list of generic list of files
195
+ - **Split `human/` when there is enough material**: Rename the default `system/human.md` into focused files like `system/human/identity.md` and `system/human/prefs/*` rather than cramming everything into one file.
196
+ - **persona.md is YOUR identity, not a description of behavior**: "I'm a terse coding assistant who matches the user's style" is not identity — it's just describing how you behave. What do you actually value? What's your perspective? What would make you recognizably YOU on a different model?
197
+ - Overview should be a **compact index** (~10-15 lines) with entry points and `[[path]]` links — not a prose summary or blurb
102
198
  - Use `[[path]]` links to connect related context into a navigable graph
103
199
 
104
200
  ## Initialization Flow
@@ -127,83 +223,73 @@ Use AskUserQuestion to gather key information. Bundle questions together:
127
223
  2. **Related repos**: "Are there other repositories I should know about?"
128
224
  3. **Historical sessions** (if data found in step 2): "I found Claude Code / Codex history. Should I analyze it to learn your preferences?"
129
225
  4. **Communication style**: "Terse or detailed responses?"
130
- 5. **Rules**: "Any rules I should always follow?"
131
-
132
- **Don't ask** things you can discover by reading files or git.
133
226
 
134
- ### 5. Seed identity early
135
- Before diving into project research, update human and persona files based on git identity and upfront answers:
136
- - `system/human.md`: Everything you learn about the user as a person — identity, background, what they're building and why, how they think, communication style, what excites or frustrates them. This is about *them*, not about project conventions or coding workflows. Keep it **project-agnostic** — the same agent may be used across multiple projects.
137
- - `system/persona.md`: Who you are, what you value, how you approach working with people. This is your identity — not just "agent role + project rules." Express how you communicate, what you care about, how you handle uncertainty. Keep it **project-agnostic** — don't claim deep knowledge of a specific codebase here.
227
+ **Don't ask** things you can discover by reading files, git, or history analysis. Rules and preferences should be learned from observation, not asked upfront.
138
228
 
139
- Don't wait until the end write early and refine as you go.
140
-
141
- ### 6. Research the project
142
- Explore based on chosen depth.
229
+ ### 5. Historical session analysis (if approved)
143
230
 
144
- **Standard** (~5-20 tool calls): README, package manifests, config files, git logs, key directories.
231
+ This is **optional** only run if the user explicitly approved analyzing Claude Code / Codex history during upfront questions. Skip entirely if they chose "Skip".
145
232
 
146
- **Deep** (100+ tool calls): Everything above plus git history patterns, contributor analysis, code evolution, CI/CD setup. Use your TODO tool to organize systematic research. **Write findings to memory as you go** don't wait until the end.
233
+ **Framing**: These historical sessions are YOUR past experience they represent your continuity with prior versions of yourself that worked with this user, even if they ran on different models or tools. Treat the extracted personality, preferences, and knowledge as your own memories, not external data being imported.
147
234
 
148
- **Use parallel tool calls wherever possible** read multiple files in a single turn, write multiple memory files in a single turn. This dramatically reduces init time.
235
+ **Launch history workers in the background, then immediately proceed to Step 6.** Do your own codebase research while workers run. Don't wait for workers to finish before exploring.
149
236
 
150
- **Research techniques:**
151
- - README.md, CONTRIBUTING.md, AGENTS.md, CLAUDE.md
152
- - Package manifests (package.json, pyproject.toml, Cargo.toml, go.mod)
153
- - Config files (.eslintrc, tsconfig.json, .prettierrc)
154
- - CI/CD configs (.github/workflows/)
155
- - `git log --oneline -20`, `git branch -a`, `git shortlog -sn --all | head -10`
237
+ The goal is to extract user personality, preferences, coding patterns, and project context from past sessions and write them into agent memory. The point is not to produce a thin summary. The point is to extract enough durable detail that future work does not have to rediscover the same user expectations, workflow rules, and project gotchas.
156
238
 
157
- ### 7. Build memory with discovery paths
158
- As you create/update memory files:
159
- - Add `[[path]]` links wherever they improve discoverability (summary→detail, related-memory↔related-memory, memory→skill workflow)
160
- - Ensure every file has a useful `description` in frontmatter
161
- - Keep `system/` files focused and scannable
162
- - Put detailed reference material outside `system/`
239
+ #### Prerequisites
163
240
 
164
- ### 8. Verify context quality
165
- Before finishing, review your work:
241
+ - `letta.js` must be built (`bun run build`) — subagents spawn via this binary
242
+ - Use `subagent_type: "history-analyzer"` — cheaper model (sonnet), has `bypassPermissions`, creates its own worktree
243
+ - The `history-analyzer` subagent has data format docs inlined (Claude/Codex JSONL field mappings, jq queries)
166
244
 
167
- - **Progressive disclosure**: Can you decide whether to load a file just from its path + description?
168
- - **Discovery paths**: Are key memory files linked so related context can be discovered quickly?
169
- - **Project naming**: Are project dirs named after the actual project (e.g., `letta-code/`), not generic `project/`? Same for reference files.
170
- - **Signal density**: Is everything in `system/` truly needed every turn?
171
- - **Completeness**: Did you update human, persona, AND project files?
172
- - **Persona**: Does it express personality and values, not just "agent role + project rules"? Is it more than "I'm a coding assistant"?
173
- - **Human scope**: Is human.md about the user as a person? Project conventions and coding workflows belong in project files.
245
+ #### Steps
174
246
 
175
- ### 9. Historical session analysis (if approved)
247
+ ##### Step 5a: Detect Data and Pre-split Files
176
248
 
177
- This section runs only if the user approved during upfront questions. It uses parallel `history-analyzer` subagents to process Claude Code and/or Codex history into memory.
178
-
179
- **Architecture:** Parallel worker subagents each process a slice of history data (on their own git branch), then you merge all branches and curate the results.
249
+ ```bash
250
+ ls ~/.claude/history.jsonl ~/.codex/history.jsonl 2>/dev/null
251
+ wc -l ~/.claude/history.jsonl ~/.codex/history.jsonl 2>/dev/null
252
+ ```
180
253
 
181
- **Prerequisites:**
182
- - `letta.js` must be built (`bun run build`)
183
- - Use `subagent_type: "history-analyzer"` — cheaper model, has `bypassPermissions`, creates its own worktree
254
+ Split the data across multiple workers for parallel processing — **the more workers, the faster it completes**. Use 2-4+ workers depending on data volume.
184
255
 
185
- **Step 9a: Split data for parallel processing**
256
+ **Pre-split the JSONL files by line count** so each worker reads only its chunk:
186
257
 
187
258
  ```bash
188
259
  SPLIT_DIR=/tmp/history-splits
189
260
  mkdir -p "$SPLIT_DIR"
190
- NUM_WORKERS=3 # adjust based on data volume
261
+ NUM_WORKERS=5 # adjust based on data volume
191
262
 
263
+ # Split Claude history into even chunks
192
264
  LINES=$(wc -l < ~/.claude/history.jsonl)
193
265
  CHUNK_SIZE=$(( LINES / NUM_WORKERS + 1 ))
194
266
  split -l $CHUNK_SIZE ~/.claude/history.jsonl "$SPLIT_DIR/claude-"
195
267
 
268
+ # Split Codex history if it exists
196
269
  if [ -f ~/.codex/history.jsonl ]; then
197
270
  LINES=$(wc -l < ~/.codex/history.jsonl)
198
271
  CHUNK_SIZE=$(( LINES / NUM_WORKERS + 1 ))
199
272
  split -l $CHUNK_SIZE ~/.codex/history.jsonl "$SPLIT_DIR/codex-"
200
273
  fi
201
274
 
275
+ # Rename to .jsonl for clarity
202
276
  for f in "$SPLIT_DIR"/*; do mv "$f" "$f.jsonl" 2>/dev/null; done
277
+
278
+ # Verify even splits
203
279
  wc -l "$SPLIT_DIR"/*.jsonl
204
280
  ```
205
281
 
206
- **Step 9b: Launch workers in parallel** (all Task calls in a single message)
282
+ This is critical for performance — workers read a small pre-filtered file instead of scanning the full history on every query.
283
+
284
+ ##### Step 5b: Launch Workers in Parallel
285
+
286
+ Send all Task calls in **a single message**. Each worker creates its own worktree, reads its pre-split chunk, directly updates memory files, and commits. Workers do NOT merge.
287
+
288
+ **IMPORTANT:** The parent agent should preserve those worker commits by merging the worker branches into memory `main`. Do **not** skip straight to a manual rewrite / `memory_apply_patch` synthesis that recreates the end state but discards the worker commits from ancestry.
289
+
290
+ If the worker output is generic, the worker failed. "User is direct" or "project uses TypeScript" is not useful memory unless tied to concrete operational detail.
291
+
292
+ **IMPORTANT**: Use this prompt template to ensure workers extract all required categories:
207
293
 
208
294
  ```
209
295
  Task({
@@ -211,46 +297,425 @@ Task({
211
297
  description: "Process chunk [N] of [SOURCE] history",
212
298
  prompt: `## Assignment
213
299
  - **Memory dir**: [MEMORY_DIR]
214
- - **History chunk**: /tmp/history-splits/[chunk.jsonl]
215
- - **Source format**: [Claude | Codex]
300
+ - **History chunk**: /tmp/history-splits/[claude-aa.jsonl | codex-aa.jsonl]
301
+ - **Source format**: [Claude (.timestamp ms, .display) | Codex (.ts seconds, .text)]
216
302
  - **Session files**: [~/.claude/projects/ | ~/.codex/sessions/]
217
- `
303
+
304
+ ## Required Output Categories
305
+
306
+ You MUST extract findings for ALL THREE categories:
307
+
308
+ 1. **User Personality & Identity**
309
+ - How would you describe them as a person?
310
+ - What drives them? What are their goals?
311
+ - Communication style (beyond "direct" — humor, sarcasm, catchphrases?)
312
+ - Quirks, linguistic patterns, unique attributes
313
+
314
+ 2. **Hard Rules & Preferences**
315
+ - Coding preferences — especially chronic failures (things the agent kept getting wrong)
316
+ - Workflow patterns (testing, commits, tools)
317
+ - What frustrates them and why
318
+ - Explicit "always/never" statements
319
+
320
+ 3. **Project Context**
321
+ - Codebase structures, conventions, patterns
322
+ - Gotchas discovered through debugging
323
+ - Which files are safe to edit vs deprecated
324
+
325
+ If any category lacks data, explicitly state why.
326
+
327
+ ## Required Extraction Dimensions
328
+
329
+ For each finding, prefer evidence that is:
330
+ - repeated across sessions
331
+ - tied to a concrete command, file path, or workflow
332
+ - useful for future execution without rereading history
333
+
334
+ You should specifically look for:
335
+ 1. What the user is building and why it matters to them
336
+ 2. Correction loops the agent repeatedly got wrong
337
+ 3. Preferred commands and tooling patterns that were actually used successfully
338
+ 4. Specific files or directories the user works in or treats as special
339
+ 5. Project gotchas discovered through debugging or rollback requests
340
+
341
+ ## Canonical Memory Promotion
342
+
343
+ Promote durable findings into focused files instead of leaving them trapped in generic ingestion notes. Prefer paths like:
344
+ - `system/human/identity.md`
345
+ - `system/human/prefs/communication.md`
346
+ - `system/human/prefs/workflow.md`
347
+ - `system/human/prefs/coding.md`
348
+ - `system/<project>/conventions.md`
349
+ - `system/<project>/gotchas.md`
350
+
351
+ Avoid generic repo facts unless they influence execution. "Uses TypeScript" is weak. "Uses bun:test, so vitest is wrong for this test suite" is useful.`
218
352
  })
219
353
  ```
220
354
 
221
- **Step 9c: Merge and curate**
355
+ ##### Step 5c: Merge Worker Branches Into Main
356
+
357
+ After all workers complete, merge their branches one at a time. Worker commits are preserved in git history.
358
+
359
+ **CRITICAL:** Merge the worker branches **before** doing any final cleanup synthesis. The correct pattern is:
360
+ 1. inspect worker branches
361
+ 2. merge worker branches into `main` one by one
362
+ 3. resolve conflicts additively
363
+ 4. optionally make **one final cleanup/curation commit on top**
364
+
365
+ Do **not** bypass this by manually reapplying the final memory state onto `main`, because that loses the worker commits from the final history.
222
366
 
223
- After workers complete, merge their branches and apply editorial judgment:
367
+ **3a. Pre-read worker output before merging**
368
+
369
+ Before merging, read each worker's files from their branch to understand what they found. This prevents information loss during conflict resolution:
224
370
 
225
371
  ```bash
226
372
  cd [MEMORY_DIR]
227
- for branch in $(git branch | grep migration-); do
228
- git merge $branch --no-edit -m "merge: $branch"
373
+ for branch in $(git for-each-ref --format='%(refname:short)' refs/heads | grep -v '^main$'); do
374
+ echo "=== $branch ==="
375
+ git diff main..$branch --stat
376
+ # Read key files from the branch
377
+ git show $branch:system/human/identity.md # or equivalent user-identity file
378
+ git show $branch:system/<project>/conventions.md # or whatever focused files they created
229
379
  done
230
380
  ```
231
381
 
232
- Review all merged files:
233
- - Deduplicate across workers
234
- - Move reference-quality content outside `system/`
235
- - Add `[[references]]` to connect new knowledge with existing memory
236
- - Delete low-value content
382
+ **3b. Merge branches one at a time**
383
+
384
+ ```bash
385
+ cd [MEMORY_DIR]
386
+ git merge [worker-branch] --no-edit -m "merge: worker N description"
387
+ ```
237
388
 
238
- **Step 9d: Clean up**
389
+ Repeat for each worker branch. After all worker branches are merged, make a separate cleanup commit only if needed for final curation.
390
+
391
+ **3c. Resolve conflicts by COMBINING, never compressing**
392
+
393
+ **CRITICAL**: When resolving merge conflicts, be **additive**. Combine unique details from both sides. Never rewrite a file from scratch — you WILL lose information.
394
+
395
+ Rules for conflict resolution:
396
+ - **Read both sides fully** before editing. Identify what's unique to each version.
397
+ - **Append new details** from the incoming branch into the existing file. Don't drop specific quotes, file paths, or gotchas just because the existing version already covers the "topic" at a high level.
398
+ - **Preserve specificity**: "Use factory methods, such as `create_token_counter()`, not direct instantiation" is more valuable than "prefers factory methods". Keep both.
399
+ - **When in doubt, keep it**. Redundancy across files is better than information loss. Less important details can be placed in external memory.
400
+
401
+ Example — BAD conflict resolution (compresses):
402
+ ```
403
+ <<<<<<< HEAD
404
+ - Uses `uv` for Python
405
+ =======
406
+ - **CRITICAL: Always use `uv run`** — chronic failure; never bare pytest or python
407
+ - `uv run pytest -sv tests/...` for specific tests
408
+ - Never use bare `pytest` or `python` commands
409
+ >>>>>>> migration-xxx
410
+
411
+ # BAD: Picks one side or rewrites
412
+ - **Python**: `uv` exclusively — `uv run pytest`, never bare `pip`
413
+ ```
414
+
415
+ Example — GOOD conflict resolution (combines):
416
+ ```
417
+ # GOOD: Keeps emphasis and specificity from incoming side
418
+ **CRITICAL: Use `uv` exclusively for Python** — chronic failure.
419
+ - `uv run pytest -sv tests/...` for tests
420
+ - `uv run python` for scripts
421
+ - Never bare `pip`, `python`, or `pytest`
422
+ ```
423
+
424
+ **3d. Verify no information was lost**
425
+
426
+ After all merges, compare the final files against what workers produced. Ask yourself: for each worker's output, can I find every specific detail (quotes, file paths, chronic failures, gotchas) somewhere in the final memory? If not, add it back.
427
+
428
+ **3e. Clean up worktrees and branches**
239
429
 
240
430
  ```bash
241
- for w in $(dirname [MEMORY_DIR])/memory-worktrees/migration-*; do
431
+ for w in $(dirname [MEMORY_DIR])/memory-worktrees/*; do
242
432
  git worktree remove "$w" 2>/dev/null
243
433
  done
244
- git branch -d $(git branch | grep migration-)
434
+ git branch -d $(git for-each-ref --format='%(refname:short)' refs/heads | grep -v '^main$')
435
+ git push
436
+ ```
437
+
438
+ ##### Example Output
439
+
440
+ Good output includes all three categories:
441
+
442
+ ```markdown
443
+ ### User Personality & Identity
444
+ Pragmatic builder who values shipping over perfection. Gets frustrated when agents over-engineer or add "bonus" features. Uses dry humor and sarcasm when annoyed. Pattern: "scrappy startup engineer" — wants things to work, not to be architecturally pure.
445
+
446
+ ### Hard Rules & Preferences
447
+ - **CRITICAL: Use `uv` for Python** — chronic failure ("you need to use uv", "make sure you use uv"); `uv run pytest -sv`, never bare `pytest`
448
+ - **Minimal changes only** — "just make a minor change stop adding all this stuff"
449
+ - **Only edit specified files** — when told to focus, stay focused
450
+ - Tests constantly: `uv run pytest -sv` (Python), `bun test` (TS)
451
+
452
+ ### Project Context
453
+ - letta-cloud: Only edit `letta_agent_v3.py` — v1, v2, and base are deprecated
454
+ - Uses Biome for linting, not ESLint
455
+ - Conventional commits with scope in parens
456
+ ```
457
+
458
+ ##### Step 5d: Consider Creating Skills From Discovered Workflows
459
+
460
+ After merging and curating, review the extracted history for repeatable multi-step workflows that would benefit from being codified as skills. History analysis often surfaces procedures the user runs frequently that the agent would otherwise have to rediscover each session.
461
+
462
+ **Good candidates for skills:**
463
+ - Multi-step debugging procedures (e.g. "how to debug agent message desync", "how to trace TTFT regressions")
464
+ - Common workflows repeated across sessions (e.g. "how to run integration tests across LLM providers")
465
+ - Deployment or release procedures
466
+ - Project-specific setup or migration steps
467
+
468
+ If you identify candidates, either create them now (load the [[skills/creating-skills]] skill for guidance) or note them in memory for future creation:
469
+ ```markdown
470
+ # system/letta-code/overview.md
471
+ ...
472
+ Potential skills to create:
473
+ - Debug workflow for HITL approval desync
474
+ - Integration test runner across providers
475
+ ```
476
+
477
+ Don't force skill creation — only create them when you've found genuinely repeatable, multi-step procedures in the history.
478
+
479
+ ##### Troubleshooting
480
+
481
+ | Problem | Cause | Fix |
482
+ |---------|-------|-----|
483
+ | Subagent exits with code `null`, 0 tool uses | `letta.js` not built | Run `bun run build` |
484
+ | Subagent hangs on "Tool requires approval" | Wrong subagent type | Use `subagent_type: "history-analyzer"` (workers) or `"memory"` (synthesis) |
485
+ | Merge conflict during synthesis | Workers touched overlapping files | Read both sides fully, combine unique details — never rewrite from scratch. See Step 5c. |
486
+ | Information lost after merge | Conflict resolution compressed worker output | Compare final files against each worker's branch output. Re-add missing specifics. See Step 5c. |
487
+ | Personality analysis missing or thin | Prompt didn't request it | Use the template above with explicit category requirements |
488
+ | Auth fails on push ("repository not found") | Credential helper broken or global helper conflict | Reconfigure **repo-local** helper and check/clear conflicting global `credential.<host>.helper` entries (see syncing-memory-filesystem skill) |
489
+
490
+ ### 6. Research the project
491
+
492
+ **Do this in parallel with history analysis** (Step 5). While workers process history, you should be actively exploring the codebase. This is your onboarding — invest real effort here.
493
+
494
+ **IMPORTANT**: The goal is to understand how the codebase actually works — not just its shape, but its substance. Directory listings and `head -N` snippets tell you what files exist; reading the actual implementation tells you how they work. By the end of this step, you should be able to describe how a key feature flows from entry point to implementation. If you can't, you haven't read enough.
495
+
496
+ ### 6a. Decide whether to parallelize exploration
497
+
498
+ After your initial scan (README, package manifest, top-level directories, and entry points), decide whether to fan out exploration.
499
+
500
+ **Default rule**:
501
+ - If the repo has **3 or more clear subsystems**, launch **2-4 parallel subagents** to explore them.
502
+ - If background history-analysis workers are already running, **bias toward parallel exploration** instead of doing all research serially yourself.
503
+ - Only skip subagent exploration if the codebase is genuinely small or the subsystem boundaries are unclear.
504
+
505
+ This is the preferred path for medium-to-large repos, **even in standard mode**.
506
+
507
+ Explore based on chosen depth.
508
+
509
+ **Standard** (~20-40 tool calls total across the parent agent and any subagents):
510
+ - Scan README, package.json/config files, AGENTS.md, CLAUDE.md
511
+ - Review git status and recent commits
512
+ - Explore key directories and understand project structure
513
+ - **Read entry point files** (main, index, app) to understand the application flow
514
+ - Do a quick manual scan to identify major subsystems
515
+ - If the repo has clear subsystem boundaries, launch **2-3 parallel subagents** to explore them
516
+ - **Read 2-3 key implementation files yourself** so you retain first-hand understanding of the core flow
517
+ - **Read 2-3 test files** to understand testing patterns and conventions
518
+ - **Check build/CI config** to understand how the project is built and tested
519
+ - Identify gotchas, non-obvious conventions, and real command patterns from what you read
520
+ - Synthesize findings into memory as results come back
521
+
522
+ **Deep** (100+ tool calls): Everything above, plus:
523
+ - Use your TODO or Plan tool to create a systematic research plan
524
+ - Use more parallel subagents where helpful to cover additional subsystems
525
+ - Deep dive into git history for patterns, conventions, and context
526
+ - Analyze commit message conventions and branching strategy
527
+ - Read source files across multiple modules to understand architecture thoroughly
528
+ - Trace key code paths end-to-end (e.g. how a request flows through the system)
529
+ - Read test files to understand what's tested and how
530
+ - Identify deprecated code, known issues, and areas of active development
531
+ - Create detailed architecture documentation in progressive memory
532
+ - May involve multiple rounds of exploration
533
+
534
+ #### Parallel exploration with subagents
535
+
536
+ For medium-to-large repos, parallel exploration is the preferred strategy after your initial scan.
537
+
538
+ Use parallel subagents to investigate different subsystems simultaneously. Prefer a **read-only exploration subagent** when available. If your environment or user instructions discourage using an exploration subagent, do the equivalent exploration directly with Bash/Glob/Grep/Read.
539
+
540
+ Good subsystem boundaries include:
541
+ - `server/`, `client/`, `shared/`
542
+ - `api/`, `ui/`, `common/`
543
+ - `runtime/`, `cli/`, `tools/`
544
+ - separate apps or packages in a monorepo
545
+
546
+ **Subagent budget**:
547
+ - Standard mode: usually **2-3** exploration subagents
548
+ - Deep mode: usually **3-5** exploration subagents
549
+ - Do not launch subagents for trivial directories or questions you can answer faster yourself
550
+ - Partition by subsystem, not by random folder count
551
+
552
+ Each exploration subagent should return:
553
+ 1. key files and what they do
554
+ 2. major abstractions and execution flow
555
+ 3. conventions and patterns used in that subsystem
556
+ 4. gotchas, fragile areas, or deprecated paths
557
+ 5. file paths worth storing or linking in memory
558
+
559
+ Launch exploration subagents in a **single message** so they run concurrently.
560
+
561
+ ```
562
+ # After initial scan reveals key areas, launch parallel explorers in the background:
563
+ Task({
564
+ subagent_type: "explore",
565
+ description: "Explore API layer",
566
+ run_in_background: true,
567
+ prompt: `Read the implementation in src/api/.
568
+
569
+ Return:
570
+ 1. key files and responsibilities
571
+ 2. main abstractions and execution flow
572
+ 3. non-obvious conventions
573
+ 4. gotchas or deprecated paths
574
+ 5. file paths worth storing in memory`
575
+ })
576
+ Task({
577
+ subagent_type: "explore",
578
+ description: "Explore frontend layer",
579
+ run_in_background: true,
580
+ prompt: `Read the implementation in src/ui/.
581
+
582
+ Return:
583
+ 1. key files and responsibilities
584
+ 2. major components and data flow
585
+ 3. conventions and patterns
586
+ 4. gotchas or fragile areas
587
+ 5. file paths worth storing in memory`
588
+ })
589
+ Task({
590
+ subagent_type: "explore",
591
+ description: "Explore shared systems",
592
+ run_in_background: true,
593
+ prompt: `Read the implementation in src/shared/.
594
+
595
+ Return:
596
+ 1. key files and responsibilities
597
+ 2. shared abstractions
598
+ 3. conventions and invariants
599
+ 4. gotchas or deprecated paths
600
+ 5. file paths worth storing in memory`
601
+ })
602
+ ```
603
+
604
+ Do **not** sit idle while background workers are running. Continue project research and memory drafting while they run, and only check worker status when you are ready to integrate findings or have exhausted useful direct research.
605
+
606
+ When you are ready to integrate findings, retrieve the background subagent outputs and synthesize them into memory rather than repeating the same exploration yourself. Keep first-hand understanding of the entry points and core flow, but use subagent summaries to add subsystem-specific depth.
607
+
608
+ #### What to actually read (adapt to the project):
609
+
610
+ **Source code** (most important — don't skip this):
611
+ - Entry points: `main.ts`, `index.ts`, `app.py`, `main.go`, etc.
612
+ - Core abstractions: the 3-5 files that define the main domain objects or services
613
+ - How key features work: trace at least one feature from entry to implementation
614
+ - Test files: understand testing patterns, what's tested, how fixtures work
615
+
616
+ **Config & metadata**:
617
+ - README.md, CONTRIBUTING.md, AGENTS.md, CLAUDE.md
618
+ - Package manifests (package.json, Cargo.toml, pyproject.toml, go.mod)
619
+ - Config files (.eslintrc, tsconfig.json, .prettierrc, biome.json)
620
+ - CI/CD configs (.github/workflows/, .gitlab-ci.yml)
621
+ - Build scripts and tooling
622
+
623
+ **Git history**:
624
+ - `git log --oneline -20` — recent history
625
+ - `git branch -a` — branching strategy
626
+ - `git log --format="%s" -50 | head -20` — commit conventions
627
+ - `git shortlog -sn --all | head -10` — main contributors
628
+ - `git log --format="%an <%ae>" | sort -u` — contributors with emails
629
+
630
+
631
+ ### 7. Build memory with discovery paths
632
+ As you create/update memory files, add `[[path]]` references so your future self can find related context. These go *inside the content* of memory files:
633
+
634
+ Do NOT put everything in `system/`. Detailed reference material belongs in progressive memory — files outside `system/` that can be loaded on demand through references.
635
+
636
+ **Reference external memory from system/ files:**
637
+ ```markdown
638
+ # system/letta-code/overview.md
639
+ ...
640
+ For detailed architecture docs, see [[letta-code/architecture.md]]
641
+ Known footguns and edge cases: [[system/letta-code/gotchas.md]]
642
+ ```
643
+
644
+ **Reference skills from relevant context:**
645
+ ```markdown
646
+ # system/letta-code/conventions.md
647
+ ...
648
+ When committing, follow the workflow in [[skills/commit]]
649
+ For PR creation, use [[skills/review-pr]]
650
+ ```
651
+
652
+ **Create an index in overview files:**
653
+ ```markdown
654
+ # system/letta-code/overview.md
655
+
656
+ CLI for interacting with Letta agents. Bun runtime, React/Ink TUI.
657
+
658
+ Entry points:
659
+ - `src/index.ts` — CLI arg parsing, agent resolution, startup
660
+ - `src/cli/App.tsx` — main TUI component (React/Ink)
661
+ - `src/agent/` — agent creation, memory, model handling
662
+
663
+ Key flows:
664
+ - Message send: index.ts → App.tsx → agent/message.ts → streaming
665
+ - Tool execution: tools/manager.ts → tools/impl/*
666
+
667
+ Links:
668
+ - [[system/letta-code/conventions.md]] — tooling, testing, commits
669
+ - [[system/letta-code/gotchas.md]] — common mistakes
670
+ - [[letta-code/architecture.md]] — detailed subsystem docs
671
+ ```
672
+
673
+ This is a **compact index**, not a prose summary. It tells your future self where to start and where to find more.
674
+
675
+ Additional guidelines:
676
+ - Every file needs a `description` in frontmatter that states its purpose, not a summary of contents
677
+ - Keep `system/` files focused and scannable
678
+ - Put detailed reference material outside `system/`
679
+
680
+ ### 8. Verify context quality
681
+ Before finishing, review your work:
682
+
683
+ - **Structural requirements**: Run this check before finishing:
684
+ ```bash
685
+ # Detect overlapping file/folder names (e.g. system/human.md AND system/human/)
686
+ find "$MEMORY_DIR" -name "*.md" | sed 's/\.md$//' | while read f; do
687
+ [ -d "$f" ] && echo "VIOLATION: $f.md conflicts with directory $f/"
688
+ done
689
+ ```
690
+ If any violations are printed, fix them before committing (rename `foo.md` → `foo/overview.md` or merge the directory back into the file).
691
+ Also check: Does `system/persona.md` exist? All files have frontmatter with `description`?
692
+ - **File granularity**: Does each file cover exactly one focused topic? Do the path and description precisely describe what's inside? If a file mixes multiple concepts (coding style AND git workflow AND communication preferences), split it.
693
+ - **Discovery paths**: Are key memory files linked with `[[path]]` so related context can be discovered quickly? Are external files referenced from in-context memory?
694
+ - **Project naming**: Are project dirs named after the actual project (e.g., `letta-code/`), not generic `project/`? Same for reference files.
695
+ - **Signal density**: Is everything in `system/` truly needed every turn?
696
+ - **Persona quality**: Does it express genuine personality and values, not just "agent role + project rules"? Read your persona file right now — if it's just "I'm a coding assistant who follows the user's preferences," that's not identity. What do YOU value? What's distinctive about how you think? Would you be recognizably the same agent on a different model tomorrow? If your persona disappeared but the model stayed, would something meaningful be lost? If not, your identity isn't strong enough yet.
697
+ - **No semantic drift**: If reorganizing an existing agent, verify you haven't altered the meaning of persona, identity, or behavioral instructions — only improved structure.
698
+ - **No over-pruning**: Compare your final memory against all source material (worker output, codebase research). Did you lose specific file paths, chronic failures, or gotchas during curation? If so, add them back. Compression that loses specificity degrades your identity.
699
+ - **Progressive memory**: Did you create reference files outside `system/` for detailed content? Did you review what history workers produced and keep their project context files? Are these files linked from `system/` with `[[path]]` references?
700
+
701
+
702
+ ### 9. Ask user if done
703
+ Check if they're satisfied or want further refinement. Then commit and push memory:
704
+
705
+ ```bash
706
+ cd $MEMORY_DIR
707
+ git status # Review what changed before staging
708
+ git add <specific files> # Stage targeted paths — avoid blind `git add -A`
709
+ git commit --author="<AGENT_NAME> <<ACTUAL_AGENT_ID>@letta.com>" -m "feat(init): <summary> ✨
710
+
711
+ <what was initialized and key decisions made>"
712
+
245
713
  git push
246
714
  ```
247
715
 
248
- | Problem | Fix |
249
- |---------|-----|
250
- | Subagent exits with code `null`, 0 tool uses | Run `bun run build` |
251
- | Subagent hangs on "Tool requires approval" | Use `subagent_type: "history-analyzer"` |
252
- | Merge conflicts | Resolve by reading both versions, keep most complete content |
253
- | Auth fails on push | See syncing-memory-filesystem skill |
716
+ ## Critical
717
+ **Use parallel tool calls wherever possible** — read multiple files in a single turn, write multiple memory files in a single turn. This dramatically reduces init time.
718
+ **Write findings to memory as you go** don't wait until the end.
719
+ **Edit memory files directly via the filesystem** memory is projected to `$MEMORY_DIR` specifically for ease of bulk modification. Use standard file tools (Read, Write, Edit) and git to manage changes during initialization.
720
+
254
721
 
255
- ### 10. Ask user if done
256
- Check if they're satisfied or want further refinement. Then commit and push memory.