<img width="2318" height="1448" alt="image" src="https://github.com/user-attachments/assets/bca71d69-4972-420c-b14e-c8cf74a17de9" /> ## Summary Everything a knowledge base could not read, and the pieces it cut them into saying what they are. **Reading a PDF.** A PDF records glyphs at coordinates; whether they are a heading, a table cell or a running footer is inferred from how they look. There are now two readers. The geometric one infers structure from type size and position and needs nothing but the file. The other asks deepdoc's models, ported into `raven/knowledge/parser/deepdoc`: a layout model that says what each region is, a detector and recognizer that read a page carrying no text at all, and a table-structure model that rebuilds a grid from a picture of one. Detecting boxes around text the file already spells out exactly costs an inference pass per page to learn less, and recognising it costs accuracy. The layout graph answers with a shape its own postprocessing raises on, and its classes are DocLayout-YOLO's order rather than the list Both were established by running the model, and the label order is pinned by a test. **Tables go in as tables.** `<table>` is the only shape that keeps what a grid states -- which column a cell stood under, which cells are merged, which row is the header -- and it is the shape a model reads a table in, which is what these chunks are for. PDF, Word and PowerPoint all state their merges exactly, and they now survive as `colspan` and `rowspan`. The flat form this replaces had to repeat a header standing over two columns across both of them, because there was nowhere to record a span; it had no callers left afterwards and is gone. Two deviations from upstream, both about what the string is for: every cell's text is escaped, where upstream interpolates it raw and a cell holding a `<` produces markup that is no longer a table, and the span attributes are written only where there is a span, where upstream emits `<td >` for every ordinary cell. **A picture of where each chunk came from.** A chunk is a few hundred words with a page number on it, which is enough to cite and not enough to answer whether the parser read the page correctly. So every PDF chunk that knows where it sits carries one image: the regions it covers, cropped out of the rendered pages and stacked. here they are already structured in the parser's element spans, so the markers would only put text nobody wrote into the thing being embedded. The panel draws a chunk's tables as tables, parsed and rebuilt as elements rather than injected: a person can rewrite any piece from that same panel, so what comes back from the store is user input however it got there. **The page that reads them.** Upstream retired the knowledge page while this branch was out; it is rebuilt against the new architecture, and the half that never existed is the one a reader needs -- what a document actually became once it was cut and embedded. Documents sit in one-level folders and arrive by four routes: a file, a folder, a URL, a written note. Adding and indexing are two calls on the contract and nothing drains that queue on its own, so a page that stopped after the first left every upload saying Queued for good. Opening a file takes the whole page: the document on the left, the pieces the index holds of it on the right. The left half is the file drawn as its own pages rather than framed by the browser's PDF viewer, which reads where to open once and answers to nothing afterwards -- and which nothing can be drawn on. Pages are rendered once and kept, and the region a piece was cut from is washed over the page it came from, placed in fractions of the page so the picture's own scale never enters the arithmetic. Clicking a piece takes the file there; double-clicking opens it for rewriting. The pieces can be searched, filtered by state, turned on and off, deleted, rewritten and added to, one at a time or in a batch. Every one of those was already on the contract with no reader for it. A base's settings are back and fuller: how many pieces a search returns, how documents are cut, and how much prose comes with a table or a figure. The embedding model is a picker while the base holds no pieces and a stated fact once it does -- moving it then is the collection made again at the new width and every document re-cut, which is not a thing a panel does by being saved. **An agent can read them.** The retrieval engine was there and nothing could reach it: no agent had a tool that opened a library. A reader now points a conversation at bases from the composer, the way they pin a working directory, and the selection rides in the same place -- the session's metadata, bound around the turn. The tool takes a query and never a base. The scope is the reader's choice, so a model cannot reach material nobody offered it, and it is withheld where nothing was picked rather than offered and refused. A hit says which document and page it came from, because a hit a reader cannot place is a hit they cannot check -- and the passages are pressable in the transcript, walking into the base, the document, the folder it is filed under and then the piece. A citation a reader cannot follow is a claim they have to take on trust, and the whole point of searching their own material is that they can go and look. **The word segmenter and the resources.** `raven.core.Tokenizer` is Infinity's `rag_tokenizer`, ported: a forward and backward maximum match over a dictionary trie, with stemming and lemmatisation on the latin path. XGBoost is not carried over. None of the data lives in git -- the dictionary, the NLTK corpora and the ONNX graphs run to about a hundred megabytes, so `make fetch-resources` on an install and an optional Docker layer behind `RAVEN_RESOURCES` both point at one script. A checkout that could not reach the network still works, and every feature that reads this data says so when asked. ## Type - [ ] Fix - [x] Feature - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification Run on macOS against Python 3.12, with the deepdoc weights fetched (the model tests skip without them): ``` uv run pytest 27450 passed, 111 skipped, 3 failed npm run test --prefix ui-web 3276 passed npm run test --prefix ui-tui 2106 passed npm run type-check --prefix ui-web clean (tsc) npm run lint --prefix ui-web clean (4 pre-existing hook warnings) make lint-python clean (ruff check + format) make lint-types clean (ty) make lint-imports 10 contracts kept, 0 broken make check-source-language clean make check-large-files clean make build-ui built, both boot snapshots match node ui-web/scripts/check-css.mjs clean node ui-web/scripts/check-class-namespace.mjs clean ``` The three Python failures are not this branch's and were each confirmed on the base alone: one asks a host without LibreOffice to refuse a render and this host has LibreOffice installed, and two simulation cases fail on an unmodified checkout of the base commit. The RPC contract was regenerated for both consumers and both match it (`npm run gen --prefix ui-web`, `npm run gen:rpc --prefix ui-tui`, then `gen:check`). The page's boot snapshots and region goldens were refreshed where the composer bar gained a button, and each records that button and nothing else. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk A PDF's tables, and a Word or PowerPoint file's, are now indexed as HTML rather than as header-prefixed lines. Chunk text changes shape for those documents, so a base indexed before this and searched after it holds both forms until its documents are reindexed; retrieval keeps working either way, because both forms are text. The same applies to how much prose a table or a figure carries with it: the setting now reaches as far as it says, where before it stopped at the nearest paragraph, so a chunk cut before this keeps the narrower context until its document is rebuilt. Rolling back is reverting the branch and reindexing. The deepdoc models are optional. An install that never ran `make fetch-resources` reads PDFs geometrically, exactly as before, and says so when the models are asked for by name. Nothing here reaches the network at request time. Chunk crops and rendered pages are written at index time and on first view, both under the state directory rather than in the repository, and both are deleted with their document. A page is immutable for the life of its document id, so the route serving them caches; the document route does not. All three routes take ids and no path, and the two image routes answer under the strictest sandbox in the tree. What an agent may search is the reader's choice and nothing else. The tool takes no base argument, so a model cannot name one, and it is absent from the schema entirely for a conversation that named none -- a lane nobody pointed at a base is unchanged by this branch. The bases a session carries are stored beside its working directory and travel no further. - [x] Security impact considered - [x] Backward compatibility considered - [x] Rollback path is clear for risky changes ## Related Issues N/A --------- Co-authored-by: Claude (claude-opus-5) <noreply@anthropic.com>
229 lines
10 KiB
Makefile
229 lines
10 KiB
Makefile
.PHONY: help install install-deps fetch-resources lint lint-python lint-imports lint-deps lint-types lint-tui lint-bridge test test-python test-tui build build-tui build-bridge build-ui build-core check-commits check-pr-title check-large-files check-source-language check-core-wheel fetch-templates verify-templates beta ci clean coverage coverage-shard coverage-combine coverage-summary coverage-diff coverage-ratchet coverage-baseline-check coverage-baseline-candidate docker-build docker-up docker-down docs-serve docs-build
|
|
|
|
PYTHON ?= python3
|
|
PYTHON_VERSION ?= 3.12
|
|
PYTHON_LINT_TARGETS ?= raven evolver agents plugins-dist tests scripts docs-site
|
|
COMMIT_RANGE ?= origin/main..HEAD
|
|
COVERAGE_BASE_REF ?= origin/main
|
|
# Required coverage percentage for executable lines changed by a PR.
|
|
COVERAGE_DIFF_THRESHOLD ?= 90
|
|
# Allowed line or branch regression in percentage points to absorb rounding noise.
|
|
COVERAGE_RATCHET_TOLERANCE ?= 0.05
|
|
DOCKER_IMAGE ?= raven:local
|
|
COVERAGE_REPORT_ARGS = --cov=raven --cov=raven_everos --cov-branch --cov-report=term-missing:skip-covered --cov-report=xml --cov-report=json --cov-report=html
|
|
# One slice of the suite, K/N; the shard writes its .coverage data and no report.
|
|
COVERAGE_SHARD ?= 1/1
|
|
# Without an explicit encoding= Python opens text files in the locale encoding.
|
|
# On a GBK-locale Windows checkout, the suite would read and write cp936
|
|
# wherever a test forgot encoding=. Exported, so every recipe runs in UTF-8
|
|
# mode; a bare `uv run pytest` does not go through this file, and
|
|
# tests/conftest.py refuses that run instead.
|
|
export PYTHONUTF8 := 1
|
|
# Extra pytest flags for a shard; CI passes --idle-ceiling-strict, a local run stays warning-only.
|
|
PYTEST_ARGS ?=
|
|
COVERAGE_DATA_ARGS = --cov=raven --cov=raven_everos --cov-branch --cov-report=
|
|
# Where the shards' .coverage.* files are gathered before they are combined.
|
|
COVERAGE_DATA_DIR ?= coverage-data
|
|
|
|
help:
|
|
@echo "Targets:"
|
|
@echo " install Install Python deps, Node deps, git hooks and the fetched resources"
|
|
@echo " fetch-resources Download the tokenizer dictionary and the deepdoc models (idempotent)"
|
|
@echo " install-deps Install Python deps only (CI uses this)"
|
|
@echo " lint Run Python, TUI, and bridge lint gates"
|
|
@echo " lint-python Ruff check + format gate over raven/, evolver/, tests/, scripts/"
|
|
@echo " lint-tui TypeScript lint + RPC drift check"
|
|
@echo " lint-bridge Bridge package build check"
|
|
@echo " test Run focused Python checks and TUI tests"
|
|
@echo " coverage Run the default Python suite with line and branch coverage"
|
|
@echo " coverage-shard Run slice COVERAGE_SHARD (K/N) of the suite, writing .coverage data only"
|
|
@echo " coverage-combine Combine the shards' .coverage.* files in COVERAGE_DATA_DIR (CI downloads them there) into coverage.json and coverage.xml"
|
|
@echo " coverage-diff Check changed executable lines against COVERAGE_BASE_REF"
|
|
@echo " coverage-ratchet Check total line and branch coverage against the baseline"
|
|
@echo " coverage-baseline-check Ensure a proposed baseline never lowers the target branch"
|
|
@echo " check-commits Validate Conventional Commit subjects"
|
|
@echo " check-pr-title Validate the PR title in PR_TITLE"
|
|
@echo " check-large-files Validate PR files avoid blocked assets and size bloat"
|
|
@echo " check-source-language Validate PR-added lines stay English outside the exemption zones"
|
|
@echo " check-core-wheel Build the raven-core wheel and smoke it in a clean venv"
|
|
@echo " fetch-templates Re-pull the deck engine's ten bundled templates over the tracked copies (maintainers; needs GITLAB_TOKEN)"
|
|
@echo " verify-templates Hash the tracked deck templates against their pins"
|
|
@echo " docker-build Build the container image (page + engine + nginx)"
|
|
@echo " docker-up Build if needed and start the stack from docker/"
|
|
@echo " docker-down Stop the stack (the data volume is kept)"
|
|
@echo " beta Build this checkout and publish it to the beta channel"
|
|
@echo " ci Run the local CI gate"
|
|
@echo " clean Remove generated caches and build output"
|
|
|
|
install-deps:
|
|
uv sync --frozen --python $(PYTHON_VERSION) --extra dev --dev
|
|
|
|
install: install-deps fetch-resources
|
|
uv run --frozen --python $(PYTHON_VERSION) pre-commit install
|
|
uv run --frozen --python $(PYTHON_VERSION) pre-commit install --hook-type commit-msg
|
|
npm ci
|
|
npm ci --prefix ui-web
|
|
npm ci --prefix ui-tui
|
|
npm ci --prefix bridge
|
|
|
|
# The word dictionary, the nltk corpora beside it and the deepdoc vision
|
|
# models: ~160 MB that cannot live in git (AGENTS.md section 7 caps a file at
|
|
# 1 MiB). Idempotent, so `make install` can call it every time.
|
|
#
|
|
# `--optional` on purpose: a developer behind a firewall that cannot reach
|
|
# huggingface should still get a working checkout. What they lose is Chinese
|
|
# segmentation and PDF layout, and both say so when asked rather than failing
|
|
# the install that would have told them nothing.
|
|
fetch-resources:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/fetch_resources.py --optional
|
|
|
|
lint: lint-python lint-imports lint-deps lint-types lint-ui lint-tui lint-bridge
|
|
|
|
lint-python:
|
|
uv run --frozen --python $(PYTHON_VERSION) --extra dev ruff check $(PYTHON_LINT_TARGETS)
|
|
uv run --frozen --python $(PYTHON_VERSION) --extra dev ruff format --check $(PYTHON_LINT_TARGETS)
|
|
|
|
lint-deps:
|
|
uv run --frozen --python $(PYTHON_VERSION) --all-extras deptry raven
|
|
|
|
lint-imports:
|
|
uv run --frozen --python $(PYTHON_VERSION) lint-imports
|
|
|
|
# Call correctness, not typing strictness -- which rules are on, and the backlog
|
|
# behind each one that is off, are in [tool.ty] in pyproject.toml. The target
|
|
# roster is read from PYTHON_LINT_TARGETS so it cannot drift from ruff's; tests
|
|
# are filtered out there because they are executed, and the gate is for code
|
|
# that is not. docs-site is filtered out for a different reason: its build
|
|
# hooks import mkdocs, which install-deps does not install, so ty would read
|
|
# a resolvable import as a missing module. ruff still covers that tree.
|
|
lint-types:
|
|
uv run --frozen --python $(PYTHON_VERSION) --all-extras ty check $(filter-out tests docs-site,$(PYTHON_LINT_TARGETS))
|
|
|
|
lint-ui:
|
|
npm run gen:check --prefix ui-web
|
|
npm run lint --prefix ui-web
|
|
npm run type-check --prefix ui-web
|
|
|
|
lint-tui:
|
|
npm run lint --prefix ui-tui
|
|
npm run lint:rpc --prefix ui-tui
|
|
npm run lint:i18n --prefix ui-tui
|
|
npm run type-check --prefix ui-tui
|
|
|
|
lint-bridge:
|
|
npm run build --prefix bridge
|
|
|
|
test: test-python test-ui test-tui
|
|
|
|
test-ui:
|
|
npm test --prefix ui-web
|
|
|
|
test-python:
|
|
uv run --frozen --python $(PYTHON_VERSION) --all-extras pytest -q
|
|
|
|
coverage:
|
|
TERM=dumb uv run --frozen --python $(PYTHON_VERSION) --all-extras pytest -q $(COVERAGE_REPORT_ARGS)
|
|
|
|
coverage-shard:
|
|
TERM=dumb uv run --frozen --python $(PYTHON_VERSION) --all-extras pytest -q --shard $(COVERAGE_SHARD) --durations=25 $(PYTEST_ARGS) $(COVERAGE_DATA_ARGS)
|
|
|
|
coverage-combine:
|
|
uv run --frozen --python $(PYTHON_VERSION) coverage combine --keep $(COVERAGE_DATA_DIR)
|
|
uv run --frozen --python $(PYTHON_VERSION) coverage json
|
|
uv run --frozen --python $(PYTHON_VERSION) coverage xml
|
|
|
|
coverage-summary:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/coverage_gate.py summary
|
|
|
|
coverage-diff:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/coverage_gate.py diff --base-ref $(COVERAGE_BASE_REF) --threshold $(COVERAGE_DIFF_THRESHOLD)
|
|
|
|
coverage-ratchet:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/coverage_gate.py ratchet --tolerance $(COVERAGE_RATCHET_TOLERANCE)
|
|
|
|
coverage-baseline-check:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/coverage_gate.py baseline-check --base-ref $(COVERAGE_BASE_REF)
|
|
|
|
coverage-baseline-candidate:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/coverage_gate.py baseline
|
|
|
|
test-tui:
|
|
npm test --prefix ui-tui
|
|
|
|
build: build-tui build-bridge build-ui
|
|
|
|
build-tui:
|
|
npm run build --prefix ui-tui
|
|
|
|
build-ui:
|
|
npm ci --prefix ui-web
|
|
npm run --prefix ui-web build
|
|
# Through uv like every other python line here, rather than through
|
|
# whatever `python3` the shell resolves. The assembler writes the page
|
|
# with `Path.write_text(newline="")`, which is 3.10 and later; a stock
|
|
# macOS resolves `python3` to 3.9 and the build fails on a keyword
|
|
# argument, which reads as a defect in the script rather than as the
|
|
# wrong interpreter.
|
|
uv run --frozen --python $(PYTHON_VERSION) python ui-web/build.py
|
|
|
|
build-bridge:
|
|
npm run build --prefix bridge
|
|
|
|
build-core:
|
|
uv run --frozen --python $(PYTHON_VERSION) python scripts/build_core_wheel.py
|
|
|
|
check-commits:
|
|
npx commitlint --from origin/main --to HEAD --config commitlint.config.cjs
|
|
PYTHONPATH=. uv run --frozen --python $(PYTHON_VERSION) --extra dev python scripts/check_commit_messages.py $(COMMIT_RANGE)
|
|
|
|
check-pr-title:
|
|
PYTHONPATH=. uv run --frozen --python $(PYTHON_VERSION) --extra dev python scripts/check_pr_title.py
|
|
|
|
check-large-files:
|
|
PYTHONPATH=. uv run --frozen --python $(PYTHON_VERSION) --extra dev python scripts/check_large_files.py $(COMMIT_RANGE)
|
|
|
|
check-source-language:
|
|
PYTHONPATH=. uv run --frozen --python $(PYTHON_VERSION) --extra dev python scripts/check_source_language.py $(COMMIT_RANGE)
|
|
|
|
# Out of the default pytest scope by norecursedirs (it builds a wheel and a
|
|
# venv); this target is what CI and `make ci` run so the artifact stays honest.
|
|
check-core-wheel:
|
|
uv run --frozen --python $(PYTHON_VERSION) pytest tests/integration/test_kernel_wheel_smoke.py -q -o addopts=""
|
|
|
|
# The image builds the page and the Python environment itself, so these need
|
|
# no prior `make build`. Compose reads docker/.env for ports and extras.
|
|
docker-build:
|
|
docker build -t $(DOCKER_IMAGE) .
|
|
|
|
docker-up:
|
|
cd docker && docker compose up --build $(COMPOSE_ARGS)
|
|
|
|
docker-down:
|
|
cd docker && docker compose down
|
|
|
|
beta:
|
|
PYTHONPATH=. uv run python scripts/publish_beta.py $(BETA_ARGS)
|
|
|
|
ci: lint test build check-core-wheel
|
|
|
|
clean:
|
|
rm -rf .pytest_cache .ruff_cache .uv-cache .mypy_cache htmlcov coverage.xml coverage.json coverage-baseline-candidate.json dist build
|
|
rm -rf ui-tui/dist ui-tui/coverage ui-tui/.vitest-cache ui-tui/packages/hermes-ink/dist
|
|
rm -rf bridge/dist
|
|
rm -rf ui-web/dist
|
|
find . -type d -name __pycache__ -prune -exec rm -rf {} +
|
|
|
|
# Not an install step: the ten templates are tracked, and a clone already has
|
|
# them. This lands a fresh cut over them, to be committed with rewritten pins.
|
|
fetch-templates:
|
|
python3 plugins-dist/ppt-engine/fetch_templates.py
|
|
|
|
verify-templates:
|
|
python3 plugins-dist/ppt-engine/fetch_templates.py --verify
|
|
|
|
docs-serve:
|
|
uv run --frozen --python $(PYTHON_VERSION) --group docs mkdocs serve -f docs-site/mkdocs.yml
|
|
|
|
docs-build:
|
|
uv run --frozen --python $(PYTHON_VERSION) --group docs mkdocs build -f docs-site/mkdocs.yml --strict
|