Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2b43db3
feat: report optional parsing progress across formats and batches
syw2014 Sep 16, 2026
a9eb98e
docs: record parsing progress verification results
syw2014 Sep 16, 2026
62850bb
docs: add shared agent collaboration contract
syw2014 Sep 16, 2026
f649adc
docs: plan staged issue remediation
syw2014 Oct 10, 2026
189bd0d
style: format historical DeepDoc plan examples
syw2014 Oct 10, 2026
67bea56
chore: enforce clean repository-wide Ruff gates
syw2014 Oct 10, 2026
45a3772
fix: classify timeouts by type before backend text
syw2014 Oct 10, 2026
057ac34
feat(excel): preserve typed reference facts and dependency lineage
syw2014 Oct 10, 2026
67b8792
fix(excel): diagnose dynamic names and unsupported reference forms
syw2014 Oct 10, 2026
c408683
feat(chunkers): add registered token and sliding window strategies
syw2014 Oct 10, 2026
1e41ea7
feat(excel): expose source-grounded chart and image blocks
syw2014 Oct 10, 2026
33b4f67
feat(excel): expose lineage in results and analysis chunks
syw2014 Oct 10, 2026
1b1fe5c
feat(excel): gate formula facts and dependency retention
syw2014 Oct 10, 2026
12d85eb
feat(excel): add versioned workbook bundle and query API
syw2014 Oct 10, 2026
d692d9e
docs(excel): publish bundle schema and compatibility contract
syw2014 Oct 10, 2026
538612b
docs: provide Agent skill and executable ingestion example
syw2014 Oct 10, 2026
300a8ae
test(excel): freeze fact truth and strengthen public quality gates
syw2014 Oct 10, 2026
431ce9a
test(excel): apply versioned fact annotations without changing fixtures
syw2014 Oct 10, 2026
d601a12
test(excel): verify bundle consumption in workbook quality gates
syw2014 Oct 10, 2026
e7c9bfe
test(excel): preserve a frozen v1 consumption example
syw2014 Oct 10, 2026
733a9ae
fix(excel): validate drawing anchors independently from used cells
syw2014 Oct 10, 2026
920e549
fix(excel): preserve unknown bundle extension semantics
syw2014 Oct 10, 2026
9a4eb6a
fix(excel): reject malformed and out-of-bounds reference ranges
syw2014 Oct 10, 2026
483f1f1
fix(excel): report drawing reader losses as partial results
syw2014 Oct 10, 2026
f10d4c9
fix: retain unresolved chart references without invalid bundle sources
syw2014 Oct 10, 2026
403e2f7
docs: record scoped remediation and package compatibility fixtures
syw2014 Oct 10, 2026
02b1788
docs: record installed wheel validation results
syw2014 Oct 10, 2026
468a128
fix: reject bundles missing query fields
syw2014 Oct 10, 2026
1087b76
fix: preserve quoted sheet names and index direct formula dependencies
syw2014 Oct 10, 2026
bf5380b
docs: record independent review and focused fixes
syw2014 Oct 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:

- name: Run static checks
run: |
uv run ruff check langparse tests scripts/verify_*.py
uv run ruff format --check langparse tests scripts/verify_*.py
uv run ruff check .
uv run ruff format --check .

- name: Audit all published extras
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
run: uv sync --extra dev --locked

- name: Lint
run: uv run ruff check langparse tests scripts/verify_*.py
run: uv run ruff check .

- name: Check formatting
run: uv run ruff format --check langparse tests scripts/verify_*.py
run: uv run ruff format --check .
62 changes: 62 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# AGENTS.md

本文件为在 `langparse`(开发者友好的通用文档解析工具集 + 精确丰富的 Excel 解析引擎)工作的 AI 智能体(Codex、Claude Code、Antigravity、Cursor 等)提供统一的工程与协作契约。

## 1. 协作心态与执行准则 (Core Working Principles)

1. **行动优先与端到端交付 (Bias towards Action & Autonomous Completion)**:
- 当用户给出带有行动倾向的提示词(如 "can you...", "帮我...", "我想...", "fix...", "优化..."),一律视为端到端执行指令,直接推进至完整交付。
- 严禁停步在仅承认能力(如 "Yes, I can...")、列举未经要求的方案步骤、或询问用户是否要继续。
- 严禁为节省思考或 token 输出“看起来差不多/部分完成”的妥协方案。面对需要多步推进的任务,必须自主完成全部必要链路直至目标交付。
- 代码探索、只读检索、修复、临时脚本验证、可逆改动、新建临时 worktree/分支、解决合并冲突与单测编写一律无需请示,直接自主推进。
2. **交付后审批 (Review Concrete Results, Not Plans)**:
- 只有在准备好具体、可审查的结果(已完成改动且测试通过)后,才提示用户做最终合并或不可逆操作的确认。审批是最后一步,决不能作为动手前的阻碍。
- 严禁因假设性风险主动引入未经请求的警告、免责声明、阻断性审批流或安全合规清单。
3. **指令层级与规则溯源 (Instruction Hierarchy & Rule Provenance)**:
- 用户在当前会话中的显式指令严格优先于本文件及任何外部 Skills/规则。如果显式指令与本规范冲突,优先执行用户指令并简短报备。
- 若因任何 Skill 或规范约束导致你必须暂停、确认、留有未完成工作或偏离用户初衷,必须**明确标注所引用的具体文件路径(如 `SKILL.md` 或 `AGENTS.md`)、原样摘录相关条款,并简要解释其如何适用**。清晰区分硬性规则与你的主观解读。
4. **输出文风与去套话纪律 (Direct Prose & Radical Anti-Slop)**:
- 默认采用清晰短小的段落,单段阐明一个核心观点;仅在内容严格并列、有序或需对比时使用列表,严禁无意义的多层嵌套列表。
- 结论与动作直接陈述。严禁套话与大词(如 "Bottom Line:", "delve", "foster", "leverage", "it's worth noting", "importantly", "Question? Answer.", "This isn't about X. It's about Y." 等)。
- 严禁总结陈词(如 "In short:", "The simplest mental model is:")与对比式否定铺垫("X, not Y" 或 "X—not Y");不主动引入用户未提及的对比项,不罗列未发生的事情。
- 杜绝生造复合概念(如 "exact-head checks", "editorial-row layouts"),使用自然精准的动词与介词描述真实关系。
5. **智能体委派与并行纪律 (Subagent Delegation & Inter-Agent Protocol)**:
- 跨格式解析器走查、多模型基准对比或样本集分析时,若能通过子代理并发节省时间或提升质量,应主动并行化委派。
- 发送给其他 Agent 的指令与最终答复均会被人类审查,必须保证语义通畅、词间间距正确、排版规整。

## 2. 领域核心认知与术语契约 (Domain Invariants)

严格对齐根目录 [`CONTEXT.md`](CONTEXT.md),使用统一词汇,禁止自创概念:
- **文档解析工具集 (Document Parsing Toolkit)**:通用、低接入成本、可预测输出。强调面向程序与 Agent 的即插即用,避免自称“多引擎平台”或“解析器排行榜”。
- **Excel 解析引擎 (Excel Parsing Engine)**:保留源证据的丰富结构,这是 LangParse 的核心壁垒。避免称作“表格读取器”或“Excel 转 Markdown”。
- **工作簿事实 (Workbook Facts)** 与 **工作簿结构 (Workbook Structure)**:
- “事实”对应未经语义推断的底层信息(单元格、公式、格式、可见性、合并关系);
- “结构”对应识别出的逻辑表、表单、矩阵、文本区域及跨 Sheet 关系。
- 必须始终保留对源范围(Range)的引用证据,严禁扁平化降级。
- **可消费结果 (Consumable Result)**:调用方无需理解内部实现即可直接查询、导出或供 Agent 消费的文档结果。避免直接暴露内部中间表示或原始转储。

## 3. 工程硬约束 (Engineering Invariants)

1. **零基础运行时依赖 (Zero Core Dependencies)**:
- `pyproject.toml` 中的核心 `dependencies = []` 严禁变动!
- 任何格式支持必须通过可选 extra 安装(`pdf`, `docx`, `excel`, `model`, `ocr`, `mineru`, `deepdoc` 等)。核心基础链路绝不引入重量级三方库。宿主未配置时保持静默(`logging.NullHandler`)。
2. **数据模型单一派生源**:
- 结构化数据以 `ParsedDocumentResult`(pages/elements/tables/images)为准,Markdown 视图 `Document` 必须且仅能由 `core/rendering.py` 单点派生,确保两套视图永不分叉。
3. **DeepDoc 镜像保护**:
- `langparse/engines/pdf/deepdoc/` 属于从 RAGFlow 迁移的原生模块,严格保持上游 diff 友好性。已在 ruff 中配置格式化与 lint 豁免,禁止随意重构其内部实现风格。
4. **严格代码风格**:
- 代码检查执行 `ruff check .` 与 `ruff format --check .`,行宽上限 100。
- 严禁重新引入 `loguru`,统一使用标准库 `logging`。

## 4. 测试与适度化验证 (Calibrated Verification)

1. **测试适度原则 (Calibrated Testing)**:
- 严禁为低影响、可逆改动、纯类型定义、常量导出及简单镜像代码编写冗余单测。
- 核心测试必须覆盖实质性逻辑:解析器边界、状态机流转、TEDS 保真度评分与 Excel 复杂结构识别。
2. **精准回归命令**:
- 单模块单测:`pytest tests/test_<module>.py -q`
- 真实样本回归走查:`python scripts/verify_real_samples.py`
- 测试通过即推进交付,不无休止全量重跑。
3. **小功能轻量验证 (Token Economy)**:
- 小功能迭代严禁跑全量测试套件或全量样本走查,避免无谓耗尽 token 与撑爆上下文。
- 仅针对改动涉及的具体模块或测试用例执行最小化验证,单测通过即推进交付。
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ the pre-release development history.

## [Unreleased]

### Added

- Workbook reference facts and conservative dependency queries; chart/image semantic blocks
with source evidence and partial-result diagnostics.
- Versioned Workbook Bundle v1, queries, `workbook-json` CLI export and frozen compatibility fixture.
- Fixed-token and sliding-window chunkers, registry and CLI options; repository Agent Skill.
- Optional formula/name/table/visibility/dependency truth metrics and Bundle contract metrics.

### Fixed

- Classify typed timeout causes without misclassifying invalid timeout options.
- Preserve drawing-reader loss and unresolved chart source diagnostics; unify repository Ruff gates.

### Added

- Optional immutable progress events for parsing and concurrent batches, with
PDF page/engine progress, Excel stages, callback failure isolation, and CLI
`--progress` output on stderr. Unknown progress remains unspecified; no new
core dependencies or persisted task service.

## [0.1.0rc2] - 2026-09-08

### Added
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

### 新增

- 新增可选 `progress_callback` 与不可变进度事件,覆盖 PDF 页/引擎进度、Excel
阶段和并发批次完成数;CLI `--progress` 输出到 stderr。未知进度保持空值,
普通回调异常不影响解析,不增加核心依赖。

- 新增真实样本本地回归脚本:固定源文件 hash,独立核对源事实、分块值与来源引用,
执行显式语义标注和本地 OCR 检查,并生成源文件与解析结果对照报告。私有数据保持
Git 忽略;语义差异返回非零退出码,不自动宣称生产就绪。
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include SKILLS.md
include docs/WORKBOOK_BUNDLE.md docs/CHUNKING.md
recursive-include skills/langparse *.md
include examples/agent_ingestion.py
recursive-include tests/fixtures *.json
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,51 @@ where LangParse goes deliberately deeper.

---

## Parsing progress (unreleased)

Pass `progress_callback` to `AutoParser`, `ParseService`, `PDFParser`, or
`BatchParseService.run`. The callback receives immutable `ProgressEvent` objects:

```python
from langparse import AutoParser

result = AutoParser.parse_result(
"budget.xlsx",
progress_callback=lambda event: print(event.phase, event.state, event.percent),
)
```

Events contain `source`, `phase`, `state`, `completed_units`, `total_units`, `unit`,
`percent`, and `message`. Percent is phase-local (0–100), not an ETA; unknown
values remain `None`. Only a `file` event with `completed`/`failed` marks the end
of parsing and requested chunking, before any caller-side export. A completed
parse can still have partial quality diagnostics.

Simple PDF reports page counts; DeepDoc forwards its internal weighted-stage or
page-batch progress; MinerU reports preparation, remote parsing, and rendering
without an internal percentage. Excel reports extraction, assembly (including
optional model disambiguation), and rendering. Direct `ExcelParser` calls also
emit those stages; the facade/service supplies the file lifecycle.

Batch events use `phase="batch"`, `source=""`, and `unit="files"`. Notifications
follow completion order while returned results retain the batch's sorted file order. Success,
failure, and skip all count as finished files. Batch completion follows report
writing and does not mean every file succeeded. Each `batch_item` event names
the source and reports `completed`/`failed`/`skipped` after that item's output
write. Empty batches report 0/0 with
unknown percent. Ordinary callback exceptions are logged by type and isolated
from parsing. Callbacks are synchronous: keep them brief. One batch serializes
its callbacks, which can run on different threads; callers coordinate callbacks
shared across independent runs. There is no task store, background execution,
cancellation, heartbeat, or HTTP query endpoint.

CLI `--progress` writes line-oriented updates to stderr, leaving stdout intact:

```bash
langparse parse budget.xlsx --format json --progress > result.json
langparse parse docs/ --batch --output-dir out --progress
```

## Project status

The current release candidate is `0.1.0rc2`. Core multi-format parsing,
Expand Down Expand Up @@ -657,3 +702,9 @@ See [CHANGELOG.md](CHANGELOG.md) ([中文](CHANGELOG_cn.md)) for release notes a

## License
This project is licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).

### 新增能力(Unreleased)

- [Workbook Bundle 与查询](docs/WORKBOOK_BUNDLE.md)
- [分块策略与 CLI](docs/CHUNKING.md)
- [Agent Skill 与接入示例](SKILLS.md)
55 changes: 55 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,61 @@ langparse benchmark samples/public.example.json --engine mineru --output-dir rep

benchmark 报告会记录成功率、耗时、页数/秒、表格数量、OCR 指标、多列顺序告警、页眉页脚过滤数量,以及图像/图表 metadata 覆盖情况。

### 解析进度(未发布)

`AutoParser`、`ParseService` 和 `PDFParser` 的解析调用支持可选的
`progress_callback`。回调接收不可变的 `ProgressEvent`,默认不输出进度、不增加依赖。

```python
from langparse import AutoParser, ProgressEvent
from langparse.services.batch_service import BatchParseService


def on_progress(event: ProgressEvent):
print(event.source, event.phase, event.state, event.percent)


result = AutoParser.parse_result("budget.xlsx", progress_callback=on_progress)
batch = BatchParseService().run(
"docs/",
output_dir="out",
progress_callback=on_progress,
)
```

事件字段为 `source`、`phase`、`state`、`completed_units`、`total_units`、`unit`、
`percent` 和 `message`。`percent` 是当前阶段的 0–100 百分比,未知时为 `None`,
不表示剩余时间。文件结束以 `phase="file"` 且 `state="completed"/"failed"` 为准;
成功返回的结果仍可能带有 `partial` 质量诊断。`file` 完成涵盖解析及请求的分块,
不涵盖调用方后续导出/落盘。

- Simple PDF:报告 `parsing` 阶段已处理/总页数,`unit="pages"`。
- DeepDoc:转发内部解析进度;其百分比来自引擎阶段权重或页面批次,达到 100 后仍需
渲染结果。首次模型准备、等待解析锁期间只报告准备状态。
- MinerU:报告服务准备、远程解析等待、结果组装阶段;远端内部进度未知。
- Excel:报告事实提取 `extracting`、结构装配 `assembling`(包含可选模型消歧)、
渲染 `rendering`;CSV/旧版 Excel 为提取、渲染两阶段。
直接调用 `ExcelParser.parse_result(..., progress_callback=...)` 也能获得这些阶段;
统一的 `file` 生命周期由 `AutoParser`/`ParseService` 提供。
- 批处理:`phase="batch"`、`source=""`、`unit="files"`;按实际完成顺序通知,
返回结果仍按既有的文件路径排序排列。成功、失败、跳过都计入已完成数量。
每项处理完毕另发 `batch_item`,包含该文件的 `source` 和
`completed`/`failed`/`skipped` 状态,涵盖该项输出写入。
汇总 `completed` 表示批次处理及报告写入结束,逐项结果仍可能失败;异常退出报告
`failed`。空批次为 0/0,百分比未知。

回调同步执行,应保持简短。批处理会串行调用同一次运行的回调,但执行线程可能不同;
GUI/异步应用应转交自己的事件循环。同一回调用于多个独立运行时,由调用方协调线程。
普通回调异常仅通过标准日志记录异常类型,不改变解析结果。该接口不提供后台任务、
持久化任务 ID、取消、心跳或 HTTP 查询;应用可用事件维护自己的任务状态。

CLI 加 `--progress` 后逐行写入 stderr,stdout 继续输出 Markdown/JSON:

```bash
langparse parse budget.xlsx --format json --progress > result.json
langparse parse docs/ --batch --output-dir out --progress
```

## 🛠️ 本地开发与测试

LangParse 使用 [`uv`](https://github.com/astral-sh/uv) 管理环境和依赖。仓库内的 `.venv` 由 uv 管理,**不含 `pip`**,因此请统一通过 `uv run` 运行命令(直接用 shell 里的 `pip`/`python` 可能指向其他解释器,例如 Anaconda)。
Expand Down
22 changes: 22 additions & 0 deletions SKILLS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# LangParse Agent 接入

可复用 Skill 位于 [skills/langparse/SKILL.md](skills/langparse/SKILL.md)。可将 `skills/langparse/` 复制到支持目录式 Skill 的宿主;本仓库不自动修改宿主配置。其他 Agent 可直接读取该文件并包装统一 API。

## 工具参数契约

示例函数 `examples.agent_ingestion.ingest_document` 接受:

| 参数 | 类型与默认值 | 含义 |
| --- | --- | --- |
| `path` | string,必填 | 已授权的本地文件路径 |
| `profile` | `retrieval` / `analysis`,默认 retrieval | 分块消费用途 |
| `engine` | `simple` / `mineru` / `deepdoc`,默认 simple | PDF 后端,其他格式按内容路由 |

返回 `{result, chunks}`:OOXML 的 `result` 是 Workbook Bundle v1;其他格式是统一 ParsedDocumentResult JSON。`chunks` 是统一的 `{content, metadata, structured_payload}` 数组。Python 调用失败时保留异常,由宿主处理;示例命令行失败时返回非零退出码与 JSON 错误。

```bash
python -m examples.agent_ingestion budget.xlsx --profile analysis
python -m examples.agent_ingestion notes.md --profile retrieval
```

模型消歧不在此基础示例中隐式开启。独立 provider、业务验收和网络能力按用户任务显式配置。
51 changes: 51 additions & 0 deletions docs/CHUNKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 分块策略

`--chunk` 默认沿用 Markdown 结构感知的 `SemanticChunker`;DOCX 标题也通过统一
Markdown 视图使用此能力。工作簿始终优先使用 `WorkbookStructuralChunker`,保留
源范围、逻辑表与规范记录,可通过 `--chunk-profile retrieval|analysis` 选择用途。
全局文本策略和大小选项不会覆盖工作簿结构策略,工作簿大小仍由 profile 决定。
未知策略和非法文本策略参数会在解析前报错。

```sh
langparse parse report.md --chunk --chunk-strategy fixed-token --chunk-size 256
langparse parse report.docx --chunk --chunk-strategy sliding-window --chunk-size 1000 --chunk-overlap 100
```

`fixed-token` 默认按可逆词法单元计数:Unicode 单词、连续空白、单个标点各算一个
单元;这不是模型 token,也不能代表模型上下文预算。中文连续文字可能构成一个
词法单元。它忽略 Markdown 结构,严格按编码序列切分,元数据记录 tokenizer、
token_start、token_end(右开)和 token_count。需要模型 token 时注入配套编解码器:

```python
from langparse import FixedTokenChunker, Document

# tokenizer 由调用方安装和配置;应确保切片解码符合其 Unicode/特殊 token 契约。
chunker = FixedTokenChunker(
max_chunk_size=256,
overlap=32,
encoder=tokenizer.encode,
decoder=tokenizer.decode,
)
chunks = chunker.chunk(Document(content=text))
```

`sliding-window` 使用 Python 字符数跨段落滑动,保留空白,元数据记录字符起止偏移。
两种策略均要求大小为正整数、`0 <= overlap < max_chunk_size`,空输入返回空列表,
最后一个窗口到达末尾即停止,避免追加完全包含于上一窗口的尾段。

```python
from langparse import AutoParser, register_chunker, BaseChunker

result = AutoParser.parse_result(
"report.md",
chunk=True,
chunk_strategy="sliding-window",
chunk_options={"max_chunk_size": 1000, "overlap": 100},
)

# 注册工厂必须返回 BaseChunker 实例;名称不能覆盖已注册策略。
register_chunker("my-strategy", MyChunker)
```

注册表属于当前 Python 进程;CLI 构建参数时读取已注册名称。CLI 暂不提供加载任意
插件路径的选项。文本策略不会把工作簿按 Sheet 压平;已有结构分块承担格式专用职责。
Loading
Loading