Fragments
Setup Check
- 1. Read
~/.config/fragments.json (Windows: %USERPROFILE%\.config\fragments.json). - If file missing → first install. Detect current platform, read the matching setup guide:
- Claude Code →
references/setup-claude-code.md
- OpenCode →
references/setup-opencode.md
- OpenClaw →
references/setup-openclaw.md
- 3. If file exists → verify MCP is configured. If incomplete → read the matching setup guide.
- All good → proceed to normal usage.
Platform Detection
Detect the current platform by checking for platform-specific markers:
| Platform | Detection Marker |
|---|
| Claude Code | INLINECODE5 directory exists |
| OpenCode |
~/.config/opencode/ directory exists |
| OpenClaw |
~/.openclaw/ directory exists |
Modes
memo — Full Lifecycle Management
Create, search, update, delete, and comment on memos via MCP tools.
Workflows:
- - Create & dedup → INLINECODE8
- Update & delete → INLINECODE9
- Comments → INLINECODE10
Write operations require user confirmation before calling.
daily-log — Daily Work Journal
One structured log per user per day. Content follows .plan format
enforced by the Memos server.
Format rules, diff-merge logic, and hook trigger workflow:
→ INLINECODE12
search — Semantic Search
Server-side full-text retrieval via MCP, optional client-side
TF-IDF + LSA rerank for semantic/fuzzy queries.
Pipeline details and tuning parameters:
→ INLINECODE13
Retrieval Strategy
Data volume can be large. Always prefer targeted retrieval over bulk listing.
Memos
- 1. Search first:
memos_search_memos(query=...) — use when the user has
any intent, keyword, or topic. Returns bounded results.
- 2. Get by ID:
memos_get_memo(name=...) — use when you already know the
memo name. Expand full content only for shortlisted results.
- 3. List as fallback:
memos_list_memos(page_size=10) — use only for
explicit "show recent" requests. Always set a small
page_size.
- 4. Client-side rerank: pipe search results through INLINECODE18
for semantic ranking when server-side results need refinement.
Comments
- - List comments:
memos_list_memo_comments(name=...) — retrieve all comments
on a memo. Comments inherit the parent memo's visibility.
Daily Logs
- 1. Get by date:
memos_get_daily_log(date=YYYY-MM-DD) — single log lookup.
Pass
creator="users/{id}" to view another user's log (PROTECTED visibility).
- 2. List with date range: INLINECODE22
— use only for explicit "show this week/month" requests. Always bound the range.
Tags
- -
memos_list_tags — lightweight, use to discover available tags for filtering.
No read operations require user confirmation.
Write Operations
All write operations require explicit user confirmation before calling.
Read operations need no confirmation. Never echo PAT tokens to the conversation.
Memo Writes
| Operation | MCP Tool | When to Use |
|---|
| Create | INLINECODE24 | New idea, note, snippet |
| Update |
memos_update_memo | Modify content, visibility, pin |
| Delete |
memos_delete_memo | Remove memo (irreversible) |
| Add comment |
memos_create_memo_comment | Append discussion to memo |
Daily Log Writes
- -
memos_save_daily_log(date=..., content=...) — full replacement save.
Always include complete content (existing + new lines).
Hook Workflow (Passive Trigger)
When triggered by agent task completion:
- 1. Assess whether this session performed meaningful work. Skip if trivial.
- Call
memos_get_daily_log for today's date. - Format new entries in
.plan style. - Diff against existing content. Skip if no new information.
- Long-form content → suggest creating a memo first, reference in daily log.
- Show user the full merged log (existing + new). Wait for confirmation.
- Call
memos_save_daily_log with complete content (full replacement).
片段
安装检查
- 1. 读取 ~/.config/fragments.json(Windows:%USERPROFILE%\.config\fragments.json)。
- 如果文件缺失 → 首次安装。检测当前平台,读取匹配的安装指南:
- Claude Code → references/setup-claude-code.md
- OpenCode → references/setup-opencode.md
- OpenClaw → references/setup-openclaw.md
- 3. 如果文件存在 → 验证 MCP 是否已配置。如果配置不完整 → 读取匹配的安装指南。
- 一切正常 → 进入正常使用。
平台检测
通过检查特定于平台的标记来检测当前平台:
| 平台 | 检测标记 |
|---|
| Claude Code | ~/.claude/ 目录存在 |
| OpenCode |
~/.config/opencode/ 目录存在 |
| OpenClaw | ~/.openclaw/ 目录存在 |
模式
memo — 完整生命周期管理
通过 MCP 工具创建、搜索、更新、删除和评论备忘录。
工作流程:
- - 创建与去重 → references/memo-capture.md
- 更新与删除 → references/memo-capture.md#lifecycle
- 评论 → references/memo-comments.md
写入操作在调用前需要用户确认。
daily-log — 每日工作日志
每个用户每天一个结构化日志。内容遵循由 Memos 服务器强制执行的 .plan 格式。
格式规则、差异合并逻辑和钩子触发工作流程:
→ references/daily-log.md
search — 语义搜索
通过 MCP 进行服务器端全文检索,可选客户端 TF-IDF + LSA 重排序用于语义/模糊查询。
管道详情和调优参数:
→ references/search-strategy.md
检索策略
数据量可能很大。始终优先使用定向检索而非批量列出。
备忘录
- 1. 先搜索:memossearchmemos(query=...) — 当用户有任何意图、关键词或主题时使用。返回有限结果。
- 按 ID 获取:memosgetmemo(name=...) — 当您已知备忘录名称时使用。仅对入围结果展开完整内容。
- 列出作为备选:memoslistmemos(pagesize=10) — 仅用于明确的显示最近请求。始终设置较小的 pagesize。
- 客户端重排序:当服务器端结果需要优化时,将搜索结果通过 scripts/fragments_search.py 进行语义排序。
评论
- - 列出评论:memoslistmemo_comments(name=...) — 检索备忘录上的所有评论。评论继承父备忘录的可见性。
每日日志
- 1. 按日期获取:memosgetdailylog(date=YYYY-MM-DD) — 单个日志查找。传递 creator=users/{id} 查看其他用户的日志(受保护的可见性)。
- 按日期范围列出:memoslistdailylogs(startdate, enddate, page_size=10) — 仅用于明确的显示本周/本月请求。始终限定范围。
标签
- - memoslisttags — 轻量级,用于发现可用的过滤标签。
读取操作无需用户确认。
写入操作
所有写入操作在调用前都需要明确的用户确认。读取操作无需确认。切勿将 PAT 令牌回显到对话中。
备忘录写入
| 操作 | MCP 工具 | 使用时机 |
|---|
| 创建 | memoscreatememo | 新想法、笔记、片段 |
| 更新 |
memos
updatememo | 修改内容、可见性、置顶 |
| 删除 | memos
deletememo | 删除备忘录(不可逆) |
| 添加评论 | memos
creatememo_comment | 在备忘录上追加讨论 |
每日日志写入
- - memossavedaily_log(date=..., content=...) — 完整替换保存。始终包含完整内容(现有内容 + 新行)。
钩子工作流程(被动触发)
当由代理任务完成触发时:
- 1. 评估本次会话是否执行了有意义的工作。如果微不足道则跳过。
- 调用 memosgetdailylog 获取今天的日期。
- 以 .plan 格式格式化新条目。
- 与现有内容进行差异对比。如果没有新信息则跳过。
- 长格式内容 → 建议先创建备忘录,在每日日志中引用。
- 向用户显示完整的合并日志(现有 + 新内容)。等待确认。
- 使用完整内容(完整替换)调用 memossavedailylog。