docling-studio/document-parser
Pier-Jean Malandrino e34ed03d05 feat(#205): promote chunks to first-class entities + audit trail
The data and domain layers for the chunks editor (#219-224 in 0.6.0).
Chunks were previously stored as a JSON blob in analysis_jobs.chunks_json;
this commit makes them first-class persisted entities with stable IDs,
soft-delete, and an immutable audit log.

Domain
- Chunk: persistent entity with id, document_id, sequence, text,
  headings, source_page, bboxes, doc_items, token_count, timestamps,
  deleted_at (soft delete)
- ChunkEdit: immutable audit row (action, actor, at, before, after,
  parents, children, reason)
- ChunkPush: snapshot of which chunk_ids landed in which store at push
- ChunkEditAction enum: insert/update/delete/merge/split
- domain/chunk_editing.py: pure operations on a chunkset (insert,
  update, delete, merge, split). Each returns a new chunkset and the
  affected chunk(s); errors raise ChunkEditingError.

Persistence
- Three new tables: chunks, chunk_edits, chunk_pushes (FK + indexes)
- SqliteChunkRepository (insert, insert_many, update, soft_delete,
  find_for_document, find_by_id; respects deleted_at)
- SqliteChunkEditRepository (append-only audit log; paginated reads
  ordered newest-first; per-chunk history)
- SqliteChunkPushRepository (per-(doc, store) latest snapshot)

Ports
- ChunkRepository, ChunkEditRepository, ChunkPushRepository protocols
  added to domain/ports.py

Tests
- 17 tests for the pure chunk-editing operations covering insert /
  update / delete / merge / split, sequence shifts, lineage, error
  paths (out-of-range, missing id, deleted target, cross-document)
- 11 tests for the three repositories: round-trips, soft-delete
  filtering, history ordering, lineage round-trip, cascade-delete with
  document, find_latest semantics

Service orchestration (ChunkEditingService — atomic chunk + audit
write) and the API endpoints land in a follow-up commit on the same
feature branch / next release. The data + domain foundation here is
what unblocks #219-224.

Refs #205
2026-04-29 17:09:59 +02:00
..
api feat(#202): introduce Document lifecycle state machine 2026-04-29 15:34:25 +02:00
domain feat(#205): promote chunks to first-class entities + audit trail 2026-04-29 17:09:59 +02:00
infra refactor(audit): remediate 0.5.0 audit findings — clean architecture, security, DRY, SOLID, perf 2026-04-29 14:00:00 +02:00
persistence feat(#205): promote chunks to first-class entities + audit trail 2026-04-29 17:09:59 +02:00
services feat(#202): introduce Document lifecycle state machine 2026-04-29 15:34:25 +02:00
tests feat(#205): promote chunks to first-class entities + audit trail 2026-04-29 17:09:59 +02:00
.dockerignore Work on full Docker integration 2026-03-17 13:33:36 +01:00
conftest.py Format backend codebase with ruff 2026-04-02 12:33:07 +02:00
Dockerfile Fix RapidOCR model download permission in local image 2026-04-03 10:44:20 +02:00
main.py refactor(audit): remediate 0.5.0 audit findings — clean architecture, security, DRY, SOLID, perf 2026-04-29 14:00:00 +02:00
package-lock.json Add slide on side bar in Studio mode 2026-03-20 16:24:38 +01:00
pyproject.toml Add qualityt check and contributing doc 2026-03-21 15:34:54 +01:00
pytest.ini Add a stronger testing strategy 2026-03-18 14:46:37 +01:00
requirements-local.txt Move bbox.py from domain/ to infra/ and unify coordinate logic 2026-04-03 13:17:26 +02:00
requirements-test.txt feat: add hexagonal architecture tests with pytestarch (#177) 2026-04-29 14:00:00 +02:00
requirements.txt refactor(audit): remediate 0.5.0 audit findings — clean architecture, security, DRY, SOLID, perf 2026-04-29 14:00:00 +02:00