Skip to content

附录 A 源码地图 ​

概念 → letta-code(70ead335)中的位置 → mini-letta(v1.0)中的对应物。行号均在该提交上核对过。

A.1 路径与布局 ​

概念letta-codemini-letta
本地后端存储根src/utils/local-backend-paths.ts:19 getLocalBackendStorageDirsrc/store/paths.ts getHome(MINI_LETTA_HOME)
本地记忆仓库路径src/backend/local/paths.ts:48src/memory/memfs.ts getMemoryDir
Cloud 检出路径src/agent/memory-filesystem.ts:46 getMemoryFilesystemRoot—
当前作用域的记忆目录src/agent/memory-filesystem.ts:100 resolveScopedMemoryDirToolContext.memoryDir
本检出的 git 目录src/agent/memory-git-dir.ts:11 getMemoryGitDirsrc/memory/git.ts gitDir
v1/v2 判定src/agent/memory-format.ts:6 detectMemoryFormat只支持 v2
core 路径src/agent/memory-format.ts:13 isCoreMemoryPathsrc/memory/format.ts
被投影的路径src/agent/memory-format.ts:23 isProjectedMemoryPathsrc/memory/format.ts
MemFS 是否启用src/agent/memory-runtime.ts:13总是启用
后端能力src/backend/backend.ts:169 BackendCapabilities—

A.2 记忆的诞生 ​

概念letta-codemini-letta
默认块src/agent/memory.ts:16、src/agent/prompts/{persona,human}.mdxsrc/store/agent-store.ts DEFAULT_BLOCKS
根 MEMORY 块src/agent/create-agent-request.ts:44src/memory/memfs.ts ROOT_MEMORY_INDEX
块 → 文件src/backend/local/initial-memory.ts:41, 82src/memory/memfs.ts initialMemoryFiles
初始化仓库src/agent/memory-git.ts:1316 initializeLocalMemoryReposrc/memory/memfs.ts initMemoryRepo
本地仓库配置修正src/agent/memory-git.ts:1136同上(user、autocrlf、eol)
关闭签名src/agent/memory-git.ts:1151-1155、src/agent/memory-git-signing.ts:13—
harness 写入src/agent/memory-git.ts:1184, 1234src/memory/memfs.ts commitMemoryPaths

A.3 守门员 ​

概念letta-codemini-letta
frontmatter 规则src/memory-frontmatter.ts:18src/memory/frontmatter.ts validateMemoryFile
frontmatter 解析src/utils/frontmatter.ts:73src/memory/frontmatter.ts parseFrontmatter
树约束src/memory-constraints.ts:39src/memory/constraints.ts validateMemoryTree
默认预算src/memory-constraints.ts:302DEFAULT_MEMORY_CONSTRAINTS
配置保护src/agent/memory-constraints.ts:32, 132-146validator 脚本内
pre-commit 生成src/agent/memory-git-hooks.ts:38src/memory/hooks.ts
嵌入函数源码src/agent/memory-git-hooks.ts:90buildValidatorScript
布局策略文件src/agent/memory-git-hooks.ts:21, 224—
安装 hooksrc/agent/memory-git-hooks.ts:294installMemoryHooks
审计 HEADsrc/agent/memory-constraints-audit.ts:52, 107src/memory/audit.ts

A.4 编译与缓存 ​

概念letta-codemini-letta
编译入口src/backend/local/system-prompt-compilation.ts:432src/memory/compile.ts compileSystemPrompt
已提交版本号…/system-prompt-compilation.ts:65src/memory/git.ts headRevision
读已提交文件…/system-prompt-compilation.ts:81readCommittedMemory
v2 渲染…/system-prompt-compilation.ts:154renderCoreMemory
v1 渲染…/system-prompt-compilation.ts:305—
元信息(v1)…/system-prompt-compilation.ts:364agent-info 提醒代替
注入…/system-prompt-compilation.ts:380injectCoreMemory
技能列表…/system-prompt-compilation.ts:391—
按对话缓存src/backend/local/local-backend.ts:896src/agent/system-prompt.ts resolveSystemPrompt
<memory_update> 文案src/backend/local/local-backend.ts:165src/agent/reminders.ts formatMemoryUpdate
<memory_update> 注入src/backend/dev/pi-stream-adapter.ts:595src/agent/loop.ts(持久化的 user 提醒)
/recompilesrc/cli/commands/registry.ts:411bun src/cli.ts recompile
提示词选择src/agent/personality.ts:112、src/agent/prompt-assets.tsDEFAULT_SYSTEM_PROMPT
提示词src/agent/prompts/letta_root_memfs.md、letta_local_memfs.md—

A.5 提醒 ​

概念letta-codemini-letta
回合后同步 + 提醒src/reminders/memory-git-sync.ts:58, 162checkMemoryAfterTurn、formatSyncReminder
修复进行中提醒src/reminders/memory-git-sync.ts:40—
agent-infosrc/cli/helpers/agent-info.tsformatAgentInfo
调用点(三条路径)src/headless.ts:3097/4742、src/cli/app/use-submit-handler.ts:3746、src/websocket/listener/turn-cleanup.ts:51src/agent/loop.ts

A.6 上下文与 recall ​

概念letta-codemini-letta
token 估算src/backend/local/local-context-estimate.ts:79, 164src/context/tokens.ts
压缩阈值src/backend/dev/provider-turn-executor.ts:34, 241, 262src/context/compaction.ts compactionThreshold
地板检查src/backend/dev/provider-turn-executor.ts:215、pi-stream-adapter.ts:361—
请求前检查src/backend/dev/pi-stream-adapter.ts:562src/agent/loop.ts
滑动窗口规划src/backend/local/compaction.ts:584planSlidingWindow
全量规划src/backend/local/compaction.ts:652planAll
摘要提示词src/backend/local/compaction.ts:61, 85SLIDING_WINDOW_SUMMARY_PROMPT
摘要截断src/backend/local/compaction.ts:544clipSummary
摘要包装src/backend/local/compaction.ts:682packageSummary
压缩编排src/backend/local/local-backend.ts:727src/context/compact-conversation.ts
上下文 id 列表src/backend/local/local-store.ts:1157, 1201ConversationStore.inContext/setContext
摘要消息类型src/backend/local/local-message-projection.ts:196Message.kind = "summary"
检索src/backend/local/transcript-search.ts:523src/recall/search.ts
分词 / 词频 / BM25…/transcript-search.ts:229, 258, 317tokenize、termFrequency、searchRecall
问题降权…/transcript-search.ts:570-583latestUser
recall 子 agentsrc/agent/subagents/builtin/recall.md、src/agent/prompts/recall_subagent_local.mdrecall_search 工具

A.7 反思 ​

概念letta-codemini-letta
触发器类型src/reflection-settings.ts:1ReflectionTrigger
默认设置src/cli/helpers/memory-reminder.ts:15, 51DEFAULT_REFLECTION_SETTINGS
回合后判断src/cli/helpers/post-turn-reflection.ts:22src/reflection/post-turn.ts
transcript 与状态src/cli/helpers/reflection-transcript.ts:28, 911, 927src/reflection/transcript.ts
构造 payload…/reflection-transcript.ts:1644buildReflectionPayload
推进水位线…/reflection-transcript.ts:1870markReflected
多对话 payload…/reflection-transcript.ts:1756—
启动器src/cli/helpers/reflection-launcher.ts:769src/reflection/launcher.ts
预留 / 排队…/reflection-launcher.ts:286reflection.lock
重试退避src/cli/helpers/reflection-retry.ts—
任务提示src/cli/helpers/reflection-prompt.ts:9buildReflectionTaskPrompt
父记忆快照src/cli/helpers/reflection-memory-v2.ts:43编译 worktree HEAD
子 agent 提示词src/agent/subagents/builtin/reflection-v2.mdREFLECTION_SYSTEM_PROMPT
显式集成…/reflection-launcher.ts:458—

A.8 worktree、锁、worker ​

概念letta-codemini-letta
创建 worktreesrc/agent/memory-worktree.ts:125src/reflection/worktree.ts createMemoryWorktree
作用域src/agent/memory-worktree.ts:191src/agent/sandbox-profiles.ts reflectionProfile
状态枚举src/agent/memory-worktree.ts:215FinalizeStatus
消费 / 重编译判定src/agent/memory-worktree.ts:235, 241consumesTranscript
刷新父仓库src/agent/memory-worktree.ts:275src/sync/remote.ts refreshFromOrigin
收尾状态机src/agent/memory-worktree.ts:363, 659finalizeMemoryWorktree
worker 合并src/agent/memory-worktree.ts:685—
记忆操作锁src/agent/memory-operation.ts:20, 35src/utils/file-lock.ts
memory workersrc/agent/subagents/memory-worker.ts、builtin/memory.md—
冲突修复src/agent/memory-conflict-repair.ts:161—

A.9 同步 ​

概念letta-codemini-letta
远端 URLsrc/agent/memory-git.ts:228src/sync/remote.ts remoteUrlFor
认证参数src/agent/memory-git.ts:483—
非交互环境src/agent/memory-git.ts:533—
重试src/agent/memory-git.ts:632—
clone / pullsrc/agent/memory-git.ts:1504, 1589cloneMemory、pullMemory
回合后推送src/agent/memory-git.ts:1837syncAfterTurn
镜像仓库 hooksrc/agent/memory-git-hooks.ts:254, 280—

A.10 隔离与观察 ​

概念letta-codemini-letta
开关src/sandbox/availability.ts:65, 88src/sandbox/policy.ts
bwrap 探测src/sandbox/availability.ts:155isBwrapAvailable
bwrap 参数src/sandbox/bwrap.ts:38buildBwrapArgs
两种策略src/permissions/sandbox-policy.ts:255, 312src/agent/sandbox-profiles.ts
进程内守卫src/permissions/cross-agent-guard.ts:387assertNotOtherAgentsMemory
整进程封装src/memory-confinement.ts:22—
Memory Palacesrc/web/generate-memory-viewer.ts、registry.ts:139src/palace/*
反思提交识别src/web/generate-memory-viewer.ts:295history() 的 isReflection
/doctorregistry.ts:77、src/skills/builtin/context-doctor/SKILL.md—
遥测src/cli/helpers/reflection-launcher.ts:170, 188—

配套代码:github.com/luxiang0412/mini-letta