内容
# memgrep
本地代理内存、编码循环、从手机上的Cursor以及可调度的剧本。
**文档:** [https://memgrep.gitwork.dev](https://memgrep.gitwork.dev)
memgrep 是 Cursor 的本地控制平面。它最初作为可搜索的代理内存。 现在它的范围更大:
| 支柱 | 功能 |
| --- | --- |
| **内存** | 摄取 Cursor / Claude Code / Kiro 聊天记录。混合召回(向量 + 关键词)。`remember` 剧本和决策。完全本地(SQLite + HNSW + 设备内嵌入)。 |
| **循环** | 按项目编码循环:任务输入、退出条件、退出操作(包括 `github_pr`)。运行直到通过,然后可选的 PR / 跟进。`<cwd>/.memgrep/` 中的可编辑配置;`~/.memgrep/loops/<name>/` 下的命名指针。 |
| **Telegram** | 允许列出的机器人驱动真正的本地 Cursor 代理(`@cursor/sdk`),在真正的 cwd 中,带有 memgrep MCP 附件。 |
| **作业** | Cron + 记住的剧本 + Cursor。调度您已经信任的工作流。 |
| **MCP** | 代理的一个服务器:内存 + 作业 + 循环 + 文档(Word 模板)+ 可选套件(Cursor、Jira、Neon、gcloud、PostHog、Upstash、Product Hunt 等)。 |
**重点:** 锁定您已经确定的工作流。存储一次(`remember` / 摄取)。在任务中回忆而不是重新发明步骤。循环直到完成。调度应该在时钟上运行的内容。从 IDE 或手机驱动。
## 演示

## 为什么
代理网关每次会话都可以感受到工作流。那会烧掉您已经解决的步骤的令牌。
memgrep 是为了相反的目的:
1. **持久剧本** - 存储程序,附加到 MCP,必要时安排。
2. **跨工具内存** - 上个月 Cursor 聊天记录的修复可以在今天的代理中回忆。
3. **无需第二个平台的远程编码** - Telegram 是通道;Cursor 是运行时;memgrep 是内存、循环和调度器。
4. **完成工作循环** - 不是一次性提示:实施,验证退出,运行退出操作。
## 快速入门
需要 Node.js 18+。原生插件在安装时构建。嵌入模型(~25 MB)下载一次;之后内存搜索离线。
**1. 内存**
```bash
npm install -g memgrep
memgrep ingest
memgrep recall "我们如何修复身份验证竞赛?"
memgrep copy
```
**2. 编码循环**
```bash
memgrep loop init my-app --cwd ~/dev/my-app
memgrep loop use my-app
memgrep loop run --task "添加健康检查端点和测试"
memgrep loop status
memgrep loop runs
```
**3. 从手机上的Cursor**
```bash
memgrep telegram # BotFather token + Cursor API key + project cwd
memgrep telegram install # 或:memgrep telegram install --all
memgrep telegram service # Loaded: yes?
```
**4. 调度剧本** (`notify` 模式需要 Telegram)
```bash
memgrep remember "Smoke: reply with one line ok + time. Do not edit files." --title smoke-playbook
memgrep jobs add --name smoke-5m --cron "*/5 * * * *" \
--playbook-query "smoke playbook" --cwd ~/dev/project \
--prompt "Reply with one line: smoke ok and the current time. Do not edit files." \
--mode notify --profile default
memgrep jobs install
memgrep jobs run smoke-5m
memgrep jobs service
```
**一次性本地栈** (Telegram `--all`,作业 LaunchAgent,循环回路 MCP):
```bash
npm run build
node dist/cli.js cursor setup # 一次
node dist/cli.js loop init default --cwd ~/dev/project # 或 loop setup
npm start
npm stop
```
MCP 停留在 `http://127.0.0.1:3921/mcp`。公共隧道是可选的(任何供应商);请参阅 [可选公共 MCP](#可选公共mcp无关隧道).
### 在 macOS 上始终运行
| 服务 | 安装 | 状态 | 日志 |
| --- | --- | --- | --- |
| Telegram 机器人 + MCP | `memgrep telegram install` / `--all` | `memgrep telegram service` | `~/.memgrep/logs/telegram-launchd.log` |
| 作业调度器 | `memgrep jobs install` | `memgrep jobs service` | `~/.memgrep/logs/jobs-launchd.log` |
| 背景摄取 | `memgrep ingest install` | `memgrep ingest service` | `~/.memgrep/logs/ingest-launchd.log` |
| 边缘节点(云中心) | `memgrep edge pair` 然后 `edge install` | `memgrep edge service` | `~/.memgrep/logs/edge-*.log` |
升级后:停止前台轮询器,重新运行 `telegram install` / `jobs install` / `ingest install` / `edge install`,确认 **Loaded: yes**。重启:
```bash
launchctl kickstart -k gui/$(id -u)/com.memgrep.telegram
launchctl kickstart -k gui/$(id -u)/com.memgrep.jobs
launchctl kickstart -k gui/$(id -u)/com.memgrep.ingest
launchctl kickstart -k gui/$(id -u)/com.memgrep.edge
```
这些操作在 Mac 睡眠时暂停;超过 6 小时的宽限期后,错过的作业 tick 将被跳过。
## 命令映射
```bash
# 内存
memgrep scan | ingest | ingest install | remember | list | recall | show | copy | delete
# 边缘节点 ↔ 云中心(macOS / Linux / Windows)
memgrep edge token | pair | install | service | status
# 循环(每个项目配置文件)
memgrep loop init <name> [--cwd <path>]
memgrep loop use <name>
memgrep loop setup|status [--profile <name>]
memgrep loop run --task "..." [--profile <name>]
memgrep loop runs [runId]
memgrep loop input|exit|action set|rm ...
# Cursor 代理(MCP 套件)
memgrep cursor setup|status
# Telegram
memgrep telegram | telegram setup|list|status|install|service|uninstall
# 作业
memgrep jobs add|list|show|run|logs|daemon|install|service|...
# MCP 服务器
memgrep serve [--http] [--host 127.0.0.1] [--port 3921] [--token <token>] [--allowed-host <host>]
# 文档(Word 模板 → .memgrep/docs;MCP docs_* 始终在线)
memgrep docs setup|status|list|fill|edit
# 可选套件(省略工具,直到配置)
memgrep jira|neon|gcloud|posthog|upstash|producthunt setup|status
# 循环:使用 `loop init` / `loop setup`(不是 `<suite> setup`)
# 文件搜索(离线语义 grep)
memgrep index <dir>
memgrep search "query"
```
完整的操作指南: [文档](https://memgrep.gitwork.dev).
## 代理内存
**输入:** `ingest` (Cursor, Claude Code, Kiro)或 `remember` (您自己的笔记 / 剧本)。
**输出:** `recall` (默认混合:向量 + FTS5/BM25 via RRF),`list`,`show`,`copy`.
```bash
memgrep scan [--source kiro] [--new] [--last <n>]
memgrep ingest [--source cursor,claude,kiro]
memgrep ingest --pick 2,5
memgrep ingest --last [n]
memgrep ingest <file...>
memgrep remember "我们选择 X 而不是 Y,因为 Z" --title decision
memgrep recall "<query>" [-k <n>] [--mode hybrid|vector|keyword]
```
内存存储在 `~/.memgrep` (`MEMGREP_HOME` 来覆盖)。重新摄取是根据内容哈希的幂等。
| 工具 | 源 | 注意 |
| --- | --- | --- |
| Cursor | `~/.cursor/projects/*/agent-transcripts/` | 完整的用户 + 助手对话 |
| Claude Code | `~/.claude/projects/*/*.jsonl` | 完整的用户 + 助手对话 |
| Kiro IDE | Kiro `globalStorage` 工作区会话 | 用户对话和标题(助手输出不透明) |
| Antigravity | 还没有 | 加密protobuf;代理仍然可以通过MCP查询 |
| 其他 | `memgrep remember "<text>"` | 手动笔记,决策,事后总结 |
新源:实现 `TranscriptSource` 并将其传递给 `ingestTranscripts`.
### 给代理访问权限(MCP)
一个MCP服务器。每个客户端注册一次。
**无需全局安装** (推荐):
```json
{
"mcpServers": {
"memgrep": {
"command": "npx",
"args": ["-y", "memgrep", "serve"]
}
}
}
```
**全局安装:**
```json
{
"mcpServers": {
"memgrep": {
"command": "memgrep",
"args": ["serve"]
}
}
}
```
配置:Cursor `~/.cursor/mcp.json`,Claude Code `claude mcp add memgrep -- npx -y memgrep serve`,Kiro `~/.kiro/settings/mcp.json`.
**始终在线:** `recall`,`get_chat`,`list_chats`,`remember`,`resolve_open`,`jobs_*`,`docs_*`.
**配置后:** `loop_*`,`cursor_*`,以及以下可选套件。
### 可选 MCP 套件
未配置的凭证套件从工具列表中省略。 **文档** 始终已注册。
| 套件 | 配置 | 目的 |
| --- | --- | --- |
| `docs` | `memgrep docs setup` (可选;创建目录) | Jinja 样式的 Word 填充(`docs_fill`,`docs_serve`,...)在 `.memgrep/templates` → `.memgrep/docs` 下 |
| `cursor` | `memgrep cursor setup` | 本地 `@cursor/sdk` 代理(`cursor_workspaces`,`cursor_status`,`cursor_run`) |
| `loop` | `memgrep loop init` / `loop setup` | 编码循环(`loop_run`,`loop_status`,插入默认值) |
| `jira` | `memgrep jira setup` | 问题,评论,转换 |
| `neon` | `memgrep neon setup` | 只读 Neon 项目 / 分支元数据 |
| `gcloud` | `memgrep gcloud setup` | 日志 + GCE 检查(ADC / 服务帐户) |
| `posthog` | `memgrep posthog setup` | 分析查询 / 标志 |
| `upstash` | `memgrep upstash setup` | Redis REST 助手 |
| `producthunt` | `memgrep producthunt setup` | PH 读取 API |
### 可选公共 MCP(无关隧道)
1. `npm start` 或 `memgrep serve --http` 在 `127.0.0.1:3921`
2. 任意隧道指向该端口
3. 允许公共主机并需要承载令牌:
```bash
export MEMGREP_MCP_TOKEN="$(cat ~/.memgrep/mcp-token)"
export MEMGREP_PUBLIC_URL=https://your-tunnel.example/mcp
# 或 MEMGREP_PUBLIC_HOST / MEMGREP_ALLOWED_HOSTS / ~/.memgrep/mcp-public-url
```
## 编码循环
通用循环:自由文本 **任务**,可选 **输入**,**退出条件**,**退出操作**。循环实现,验证退出,然后运行内置操作(例如 `github_pr`)和任何剩余的代理操作。完成可以通过 Telegram 通知。
```bash
memgrep loop init prepaid --cwd ~/dev/prepaid
memgrep loop use prepaid
memgrep loop setup # 编辑 cwd / git 默认值
memgrep loop status --profile prepaid
memgrep loop run --task "Ship refunds health check" --profile prepaid # 前台(CLI)
memgrep loop runs
```
配置存储在项目中的 `<cwd>/.memgrep/` (在您的 IDE 中编辑;可以提交),包括 `AGENTS.md` (如何为代理添加输入/退出/操作)。 主目录在 `~/.memgrep/loops/<name>/project.json` 和模板在 `~/.memgrep/loop.base/` 处保存。 活动:`~/.memgrep/loop.active` 或 `MEMGREP_LOOP_PROFILE`. 旧的仅主目录 `loops/<name>/loop.json` 仍然有效,直到您重新初始化。
MCP:`loop_run` 在后台分离启动;也是 `loop_run_status`,`loop_status`,`loop_upsert_*` / `loop_remove_*`. 需要 Cursor;Jira 仅在 `jiraKey` 上可选。
## 调度剧本(作业)
一个 **作业** 是 cron + 指向一个记住的剧本。 守护进程在作业 cwd 中使用 memgrep MCP 启动 Cursor;代理 `get_chat` 剧本并运行您的提示。
```bash
memgrep jobs add \
--name email-scan-am \
--cron "30 8 * * 1-5" \
--playbook-query "email scan" \
--cwd ~/dev/career-ops \
--prompt "Scan unread mail and summarize; do not send replies" \
--mode auto
memgrep jobs list
memgrep jobs run email-scan-am
memgrep jobs logs email-scan-am
memgrep jobs install # LaunchAgent com.memgrep.jobs
```
存储在 `~/.memgrep/jobs/` 下。 默认模式是 `notify` (Telegram 摘要)。谨慎使用 `--mode auto` 进行只读作业。 相同的作业可以通过 Cursor 或 Telegram 上的 MCP 进行管理。
## 从手机上的Cursor(Telegram)
与本地 **Cursor** 代理从 Telegram 聊天。 您不需要相同的 Wi-Fi。 用量计入您的 Cursor 计划。 需要 [`CURSOR_API_KEY`](https://cursor.com/dashboard/integrations).
```bash
memgrep telegram
memgrep telegram setup career
memgrep telegram --profile career
memgrep telegram --all
memgrep telegram install --all
memgrep telegram service
```
配置文件:`~/.memgrep/telegram/<profile>.json`. 机器人嵌入回路 MCP,以便 Cursor 可以在任务中调用内存、作业、循环和配置的套件。
您的手机:自由文本 `/ask`,`/ws` 工作区,`/cwd`,`/new`,`/model`,`/mode`,`/status`,`/recall`,`/list`,`/show`,`/open`,`/help`. 只有允许的 Telegram 用户 ID 会收到答案。
**环境变量覆盖:`TELEGRAM_BOT_TOKEN`,`TELEGRAM_ALLOWED_USER_IDS`,`CURSOR_API_KEY`,`MEMGREP_TELEGRAM_CWD`,`MEMGREP_TELEGRAM_MODEL`,`MEMGREP_TELEGRAM_PROFILE`.
**进程分离:`memgrep serve --http` + `memgrep telegram --no-server` (`MEMGREP_MCP_URL` 覆盖).
## 文件搜索
对任何文件夹的语义 grep,完全离线:
```bash
npx memgrep index ./docs
npx memgrep search "how do I configure auth?"
```
`index` 选项: `--out` (默认 `.memgrep`), `--model` (任意 [Transformers.js兼容的](https://huggingface.co/models?library=transformers.js&pipeline_tag=feature-extraction) 嵌入模型)。
`search` 选项: `--index` (默认 `.memgrep`), `-k` 获取结果数量。
## 库使用
与嵌入式库使用相同的引擎(SQLite 进行语义搜索,而不是托管的 DB):
```typescript
import { VectorIndex } from 'memgrep';
const index = await VectorIndex.create({ model: 'Xenova/all-MiniLM-L6-v2' });
await index.add([
{ id: 'doc1', text: 'To reset your password, click the forgot password link.' },
{ id: 'doc2', text: 'Our refund policy allows returns within 30 days.', metadata: { url: '/refunds' } },
]);
const hits = await index.search('I forgot my login', { k: 5 });
await index.save('./my-index');
const loaded = await VectorIndex.load('./my-index');
```
也是导出:`Embedder`,`chunkText`,`MemoryStore`,`ingestTranscripts`,以及每个工具的解析器。 使用 `Embedder` + `chunkText` 如果您已经有 pgvector / LanceDB / Qdrant 并且只需要本地嵌入。
## 它如何工作
**块被搜索;聊天记录返回。
1. 转换脚本为干净的 `User:` / `Assistant:` 对话(剥离工具噪音)。
2. 文本被分块(~1000 个字符,200 个重叠)并本地嵌入(384-dim,Transformers.js)。
3. 向量进入 HNSW;聊天记录 + 文本到 SQLite; FTS5/BM25 保持同步,通过触发器同步。
4. 查询运行向量 + 关键词并行; **RRF** 合并。 确切的 ID 骑关键词;含义骑向量。
5. 摄取根据内容哈希幂等。 向量索引是可重建的缓存;SQLite 是源代码。 下一个 `recall` / `ingest` / `serve` 自愈发散的索引。
## 限制,诚实地
- 混合搜索帮助确切的 ID;非常短或大量标点符号的字符串仍然会错过。
- Kiro 吸入是部分的。 Antigravity 今天无法摄取。
- `delete` 不是永久的 re-ingest 如果源脚本仍然存在。
- 每次一个写入器;没有跨进程锁(自愈修复损失后下一个打开)。
- 回复质量跟踪对话中说的内容;仅在工具输出中生存的信号搜索效果不佳。 一行 `remember` 通常获胜。
- Telegram 和作业需要一个保持清醒的主机。 Mac 睡眠时,LaunchAgents 会暂停。
- 循环和 Cursor 套件需要有效的 Cursor API 密钥和允许列出的 cwd。
## 路线图
- Tombstones,因此 `delete` 生存 re-ingest
- 更多脚本来源(Antigravity 如果格式打开,Codex CLI,Windsurf)
- 文件监视摄取( `--watch` )基于间隔守护进程
- Linux systemd 单元与 macOS LaunchAgents 并行
- Telegram `/jobs` 斜杠快捷方式(MCP 已经涵盖从聊天中管理)
- 浏览器 / WASM HNSW 用于库
## 开发
```bash
npm install
npm run build
npm test
```
文档站点: `cd docs && npm install && npm run dev` (端口4401)。实时: [memgrep.gitwork.dev](https://memgrep.gitwork.dev).
## 许可
[MIT](LICENSE)
MCP 配置
以下是此 MCP Server 的配置信息,可直接复制到 Cursor 或其他 MCP 客户端中使用。
mcp.json
连接信息
猜你喜欢
暂无推荐服务器