Metadata-Version: 2.5
Name: igrep2
Version: 0.1.171
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: xxhash>=3.5.0
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: nltk>=3.9.0; 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'
Description-Content-Type: text/markdown

# igrep

`igrep` 为 Agent 在本地代码和文档里检索证据，结果可定位到文件和行。普通文本无需先建索引。公开 Web 与内部源也有各自的检索入口。

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

## 安装

公开 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`。

安装需要目标平台的 Python 3.14 原生 wheel。Linux amd64 wheel 以 glibc 为基线。

## 选择 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 index build ~/Documents --full       # 在本进程运行档位允许且已配置的模型车道
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`。后台准备需要先注册项目。词法索引在有效维护租约下只为 ripgrep 提名文件。档位见 `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 auto               # 按源内容自动选源，回执列出下一批候选
igrep isearch "支付失败如何重试" --source team-docs        # 换成 source list 中的来源 ID
```

内部源有两种接入方式：任何能输出 JSONL 命中的 CLI 用 command-backed source 桥接，单文件 Python 插件实现 `igrep.plugin_api` 的 `Source` 契约。安装插件必须用 3–5 条真实查询通过资质验证：

```bash
igrep source cmd check --cmd '<输出 JSONL 的命令>'           # 校验协议（查询经 $IGREP_QUERY 传入）
igrep source cmd add team-wiki --cmd '<输出 JSONL 的命令>'   # 之后 igrep isearch "…" -s team-wiki
igrep source plugin test my_source.py --queries 词1,词2,词3  # 先看资质验证结果
igrep source plugin install my_source.py --queries 词1,词2,词3
```

JSONL 字段见 `igrep source cmd --help`；插件契约与插件配置见[内部搜索插件指南][plugin-guide]。

## 接入编码 Agent

```bash
igrep setup claude-code      # MCP（semantic_search）+ CLI skill + CLAUDE.md 路由块 + SessionStart hook
igrep setup codex            # 同类组合，写 ~/.codex/config.toml、~/.agents/skills/{igrep,igrep-deep-research}、~/.codex/AGENTS.md
```

MCP server 是 `igrep-mcp`，本地检索只暴露一个工具 `semantic_search`；`agent` toolset 在配置了 Web provider 或内部源时再追加 `web_search` 与 `isearch`。只装其中一部分时：

```bash
igrep mcp install --target cursor --scope project   # 只注册 MCP；--toolset code|repo|agent 显式选工具集
igrep skill install --target claude                 # 只装 CLI skill（教 Agent 何时、如何调用 igrep 命令）
igrep skill render --format agents-md >> AGENTS.md  # 其他宿主：渲染路由块或 SKILL.md
```

各平台的命令、默认工具集、写入位置与宿主记忆接入见 [Agent 安装指南][agent-install]。

按名字查定义和引用用宿主的 `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                  # 模型随时按问题检索
```

宿主通过 `wake` 注入笔记和遗忘约束。单用户用 workspace 隔离，多用户按 `--store ROOT --user U [--tenant T]` 寻址。Pi、DeepSeek Harness、Hermes、OpenClaw 已有现成插件，由 `igrep setup <宿主>` 安装（见 [Agent 安装指南][agent-install]）；自己接入笔记、遗忘与可选的 Dream 见 [记忆宿主接入指南][mem-host-guide]，存储模型见[记忆设计][mem-design]。

## 管理台与项目

```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]。

## 配置

把自管端点写入 `~/.igreprc/.env`。以下示例使用同一个 HTTP 服务。

```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]
- [内部搜索插件指南][plugin-guide]
- [项目领域上下文][project-context]
- [记忆宿主接入指南][mem-host-guide]
- [记忆设计][mem-design]

## 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
[mem-host-guide]: https://github.com/piboye/igrep/blob/main/docs/MEM_HOST_GUIDE.md
[mem-design]: https://github.com/piboye/igrep/blob/main/docs/MEM_DESIGN.md
[project-context]: https://github.com/piboye/igrep/blob/main/docs/PROJECT_CONTEXT_DESIGN.md
