Metadata-Version: 2.5
Name: igrep2
Version: 0.1.167
Summary: Agent-first semantic grep — filesystem-native retrieval
Project-URL: Documentation, https://github.com/piboye/igrep/blob/main/docs/README.md
Project-URL: Repository, https://github.com/piboye/igrep
License-Expression: MIT
License-File: LICENSE
Requires-Python: <3.15,>=3.14
Requires-Dist: aiohttp>=3.13.0
Requires-Dist: charset-normalizer>=3.0.0
Requires-Dist: fastapi>=0.115.0
Requires-Dist: html2text>=2024.2.26
Requires-Dist: httpx2>=2.5.0
Requires-Dist: httpx[socks]>=0.27.0
Requires-Dist: huggingface-hub>=0.20.0
Requires-Dist: ltp-extension>=0.1.13
Requires-Dist: lxml>=5.0.0
Requires-Dist: mcp<3,>=2.1.1
Requires-Dist: numpy>=1.26.0
Requires-Dist: onnxruntime>=1.24.3; sys_platform != 'darwin' or (platform_machine == 'arm64' and platform_release >= '23')
Requires-Dist: openai>=1.107.0
Requires-Dist: openpyxl>=3.1.0
Requires-Dist: orjson>=3.11.8
Requires-Dist: pathspec>=0.12.0
Requires-Dist: pillow>=10.0.0
Requires-Dist: prompt-toolkit>=3.0.40
Requires-Dist: pymupdf>=1.28.2
Requires-Dist: python-docx>=1.0.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: python-pptx>=0.6.23
Requires-Dist: pyyaml>=6.0
Requires-Dist: rjieba>=0.1.13
Requires-Dist: trafilatura>=2.0.0
Requires-Dist: tree-sitter-c-sharp>=0.23.5
Requires-Dist: tree-sitter-c>=0.24.2
Requires-Dist: tree-sitter-cpp>=0.23.4
Requires-Dist: tree-sitter-dart>=0.1.0
Requires-Dist: tree-sitter-elixir>=0.3.5
Requires-Dist: tree-sitter-go>=0.25.0
Requires-Dist: tree-sitter-html>=0.23.2
Requires-Dist: tree-sitter-java>=0.23.5
Requires-Dist: tree-sitter-javascript>=0.25.0
Requires-Dist: tree-sitter-kotlin>=1.1.0
Requires-Dist: tree-sitter-lua>=0.5.0
Requires-Dist: tree-sitter-objc>=3.0.2
Requires-Dist: tree-sitter-php>=0.24.1
Requires-Dist: tree-sitter-python>=0.25.0
Requires-Dist: tree-sitter-ruby>=0.23.1
Requires-Dist: tree-sitter-rust>=0.24.2
Requires-Dist: tree-sitter-scala>=0.26.2
Requires-Dist: tree-sitter-sql>=0.3.11
Requires-Dist: tree-sitter-swift>=0.7.3
Requires-Dist: tree-sitter-typescript>=0.23.2
Requires-Dist: tree-sitter-zig>=1.1.2
Requires-Dist: tree-sitter>=0.25.2
Requires-Dist: uvicorn>=0.41.0
Requires-Dist: watchdog>=4.0.0
Requires-Dist: websockets>=13.0
Requires-Dist: xxhash>=3.5.0
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: nltk>=3.9.0; extra == 'dev'
Requires-Dist: psycopg[binary]>=3.2; extra == 'dev'
Requires-Dist: pytest-asyncio>=1.3.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
Provides-Extra: markitdown
Requires-Dist: markitdown>=0.1.0; extra == 'markitdown'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]>=3.2; extra == 'postgres'
Description-Content-Type: text/markdown

# igrep

面向 Agent 的 filesystem-native retrieval kernel。

`igrep` 直接在本地代码和文档上做自然语言检索，不需要预建向量索引；返回可定位到文件和行号的证据，也可以继续生成带引用的研究回答。CLI、MCP、Web 管理台和编辑器集成复用同一套检索语义。

```bash
igrep search "鉴权失败后在哪里重试" ~/code/my-project
igrep ask "这个项目如何加载配置？" ~/code/my-project
```

## 它解决什么问题

- **代码与文档检索**：自然语言查询、文件类型和 glob 过滤、git diff 范围、结构化输出。
- **无需向量索引**：文本和代码直接搜索；PDF、Office 文档和图片按需预处理成项目派生存储里的隐藏文本。
- **Agent 原生接入**：为主流编码 Agent 提供一键配置；精确符号导航交给宿主自己的 `rg` 和原生 LSP。
- **多种证据源**：本地文件、公开 Web、单个公开文档、内部搜索源和已授权网站各自保持清晰边界，不做隐式联邦融合。
- **Local-first**：可使用 Apple Silicon 上的本地 oMLX，也可连接自管或云端的 OpenAI-compatible 服务。

igrep 不是通用 RAG 平台。`igrep search` 是主入口；`ask`、`dig` 和 `chat` 在检索证据之上工作；`serve` 是本机管理与 host 层，不改变检索语义。

## 安装

公开 distribution 是 `igrep2`，安装后的命令和 import 仍是 `igrep`。需要 Python 3.14。

```bash
uv tool install --python 3.14 igrep2    # 推荐：隔离的 uv tool 环境
igrep --version
igrep upgrade                           # 升级已有安装
```

也可以安装到已有的 Python 3.14 环境：`python3.14 -m pip install igrep2`。

发行包是按系统和 CPU 构建的原生 wheel，不发布核心实现源码或 sdist；目标平台需要有对应 wheel，安装核心无需 Nuitka 或 C 编译器，第三方依赖按各自的平台支持安装。Linux amd64 使用 manylinux / glibc，不覆盖 Alpine / musl。组织可以用自己的 setup bundle 批量安装内部 source 插件与 Web provider 扩展；`igrep2` 本身不依赖任何此类 bundle。

## 选择 AI runtime

| 场景 | 命令 | 说明 |
|---|---|---|
| 自管、外部或云端 OpenAI-compatible 端点 | `igrep setup` | 安装轻量系统依赖并创建配置模板，不安装本地模型；端点写进 `~/.igreprc/.env`，见[配置](#配置) |
| Apple Silicon 全本地 | `igrep setup local` | 安装或复用 oMLX，下载默认模型并配置本地端点 |

完成后用 `igrep doctor` 检查能力状态。它默认只报告问题；CI 或安装脚本需要非零退出码时加 `--strict`。

## 5 分钟上手

### 搜本地代码和文档

```bash
igrep search "配置在哪里加载"                          # 当前目录
igrep search "重试策略" ~/code/my-project --type py    # 指定目录和文件类型
igrep search "鉴权逻辑" . -g 'src/**' -g '!**/test_*'  # rg 风格 glob，! 表示排除
igrep search "可能破坏兼容性的改动" . --diff           # 只搜相对 HEAD 的 git 变更文件
igrep search "错误处理" . --format json                # 程序消费：单个 JSON document（jsonl 为逐行）
git diff | igrep search "潜在回归" --stdin-format git  # 搜 Unix pipe 进来的内容
```

全部选项见 `igrep search --help`；stdout、退出码与机器输出见 [CLI 进程契约][cli-contract]。

### 选择检索强度

| 模式 | 适合场景 | 行为 |
|---|---|---|
| `fast` | 高频本地检索 | 本地关键词规划，不调用 LLM 做查询扩展；可使用已配置的 reranker 与 decision judge |
| `normal` | 日常使用，默认值 | 增加有界的 query-time LLM 扩展和最终排序 |
| `ultra` | 多跳或复杂问题 | 增加第二轮证据反馈与 LLM 最终排序，成本和延迟更高 |

```bash
igrep search "请求从入口到持久化的完整流程" . --mode ultra
```

模式只调整质量、延迟和远端调用量，不改变输出协议。缺少可选后端时，对应通道关闭，基础文件检索仍保留。

### 搜索后继续研究

```bash
igrep ask "配置优先级是什么？" .                # 单次、有界、带引用的回答
igrep dig "一次搜索请求经过哪些模块？" .        # 分阶段深度研究，stdout 只有最终答案
igrep chat                                      # 交互式多轮 REPL
```

## 多格式文件

代码、Markdown 和普通文本无需准备即可搜索。PDF、Office、EPUB 等文档要先转换，图片内容还需要 OCR/VLM：

```bash
igrep index build ~/Documents              # 转换后立即可搜；向量与图片描述交给 igrep serve（需 igrep project add）
igrep index build ~/Documents --full       # 在本进程跑完向量与 OCR/VLM 再返回
igrep prepare report.pdf --only convert    # 单文件或单阶段
igrep status ~/Documents                   # 准备欠账与存储占用
igrep clean ~/Documents --unserved         # 只删孤儿和被忽略文档的条目（预览，--yes 才删）
igrep store trust ~/Documents              # 信任从别的机器克隆或同步来的派生存储
```

派生产物写进项目的 `.igrep/derived/`（自带 ignore 文件，`git status` 看不到），不修改源目录和用户原始 Markdown，之后仍用普通的 `igrep search` 查询。`$HOME` 及其祖先不当项目根，此时先 `igrep init <dir>`。

每个根准备到哪一步由档位 `IGREP_INDEX_LEVEL` 决定（`none` < `lexical` < `vectors` < `augment`，默认 `augment`；`igrep index build --level` 写入项目 `.igrep/.env`），搜索在每一档、每个阶段建到一半时都可用。词法 store 只为 rg 提名文件，结果与无 store 时相同；`igrep index build` 负责构建，`igrep serve` 维护新鲜度，没有有效维护租约时走 rg 全扫。档位含义见 `igrep index build --help`，命令边界见 [CLI 进程契约][cli-contract] §1.1。

## Web、内部源与网站源

```bash
igrep setup web-search                                     # 配置 SearXNG / Tavily / Serper / Exa 等 provider
igrep web-search "Python 3.14 release notes"
igrep web-dig "比较 Python 3.13 与 3.14 的并发变化"
igrep page-search https://example.com/spec.pdf "timeout policy"   # 在调用方给定的一个公开文档内找证据

igrep source list                                          # 查看已配置的内部只读 source
igrep isearch "支付失败如何重试" --source <installed-plugin-source>
```

`igrep isearch` 还支持单文件 Python 插件和 command-backed source；安装插件前必须用 3–5 条真实查询通过资质验证，协议见[内部搜索插件指南][plugin-guide]。

只有你登录后的 Chrome 才能搜到的网站（公司 wiki、内网工具、个人账号应用）用网站源：它借用已登录的浏览器身份，把站点自己的搜索变成 `isearch` 来源。公开内容走 `web-search`，有 API/token 的系统写插件。

```bash
igrep serve start
igrep setup chrome
igrep source site list
igrep isearch "query" --site <source-id>
```

网站源只重放用户审核并启用的搜索请求，不跟随结果 URL 抓取正文，也不保存 cookie/token。网站改版导致搜索失效时，失败信息会给出修复命令（`igrep source site repair`）。上手与修复流程见[网站搜索源指南][website-guide]。

## 接入编码 Agent

```bash
igrep setup claude-code     # 同样：codex codebuddy workbuddy opencode cursor gemini copilot pi deepseek-harness
igrep setup openclaw --flavor search
igrep setup hermes --enable-plugin
```

各平台的接入面、替换宿主 memory 的显式选项、体检与回报流程见 [Agent 安装指南][agent-install]。

Claude Code 和 Codex 默认使用窄的 `code` toolset，只有 `semantic_search`；其余 MCP 宿主默认 `agent` toolset，按配置追加 web 与 isearch；`repo` 可显式选择。igrep 不提供符号 / LSP 导航：按名字查定义和引用用宿主的 `rg`，按光标的语义导航用宿主原生 LSP。

## Agent 记忆

`igrep mem` 是给 Agent 宿主用的 file-backed 记忆，存在 `<workspace>/.igrep/mem`：

```bash
igrep mem ingest --workspace ~/agent-ws --transcript turns.jsonl --session-id s1   # 增量、只追加，不必每轮调
igrep mem maintain --workspace ~/agent-ws                                          # 维护派生视图、处理遗忘
igrep mem wake --workspace ~/agent-ws --format markdown                            # session 开始读取记忆上下文
igrep mem recall "用户偏好什么 Python 工具" --workspace ~/agent-ws                  # 模型随时按问题检索
```

用户 profile 默认关闭；`IGREP_MEM_PROFILE=1` 让 `maintain` 抽取并发布供 `wake` 读取的 profile，关闭后由下一次 `maintain` 清理用户信息卡。Agent 自己保存的记忆由 `igrep mem record` 写入 `MEMORY.md`。

workspace 目录就是隔离单元。一个 agent 服务很多人时，用 `--store ROOT --user U [--tenant T]` 代替 `--workspace`。现成接入见 [Agent 安装指南][agent-install]，自己的宿主按[记忆宿主接入指南][mem-host-guide]接入。

## 管理台与项目

```bash
igrep project add ~/code/my-project
igrep serve run      # 前台运行；后台用 igrep serve start / status / stop
igrep serve open     # 在浏览器中打开 Web UI
```

`serve` 是唯一管理入口，提供项目、搜索、聊天、后端状态和诊断界面；`igrep serve install` 注册为 OS service。本机 Web UI 直接访问 `http://127.0.0.1:16800`，无需 token；对外监听时的鉴权见[管理生命周期规范][management]。

## 配置

优先级从高到低：

1. 当前进程的 `IGREP_*` 环境变量
2. `<project>/.igrep/.env`
3. `~/.igreprc/.env`
4. `OPENAI_*`（只作为 LLM fallback，`OPENAI_API_KEY` 是激活锚点；embedding、rerank 和 OCR 不读取）
5. 代码默认值

连接自管端点的最小示例：

```bash
IGREP_EMBEDDING_URL=http://localhost:8000/v1
IGREP_EMBED_MODEL=your-embedding-model

IGREP_LLM_URL=http://localhost:8000/v1
IGREP_LLM_MODEL=your-chat-model

IGREP_RERANK_URL=http://localhost:8000/v1
IGREP_RERANK_MODEL=your-reranker
```

凭证只放环境变量或 `.env`，不要写入 profile 或提交到仓库。`IGREP_API_KEY` 是全局 fallback，能力级 `IGREP_*_API_KEY` 可单独覆盖。

能力矩阵、凭证规则、显式空值语义、ask / final-sort 路由、图片向量与网关设置见[本地服务协议][service-protocol]；带注释的配置模板是 `env.sample`。

## 文档

- [文档导航][docs]
- [技术架构][architecture]
- [CLI 进程与机器输出契约][cli-contract]
- [管理生命周期规范][management]
- [HTTP OpenAPI][openapi]
- [本地服务协议][service-protocol]
- [Agent 安装指南][agent-install]
- [记忆宿主接入指南][mem-host-guide]

## License

MIT

[docs]: https://github.com/piboye/igrep/blob/main/docs/README.md
[architecture]: https://github.com/piboye/igrep/blob/main/docs/ARCHITECTURE.md
[cli-contract]: https://github.com/piboye/igrep/blob/main/docs/CLI_CONTRACT.md
[management]: https://github.com/piboye/igrep/blob/main/spec/management.md
[service-protocol]: https://github.com/piboye/igrep/blob/main/docs/LOCAL_SERVICE_PROTOCOL.md
[openapi]: https://github.com/piboye/igrep/blob/main/spec/openapi.yaml
[agent-install]: https://github.com/piboye/igrep/blob/main/docs/AGENT_INSTALL.md
[plugin-guide]: https://github.com/piboye/igrep/blob/main/docs/INTERNAL_SOURCE_DESIGN.md
[website-guide]: https://github.com/piboye/igrep/blob/main/docs/WEBSITE_SEARCH_SOURCE_GUIDE.md
[mem-host-guide]: https://github.com/piboye/igrep/blob/main/docs/MEM_HOST_GUIDE.md
