# kiencang/luka-loop architecture

> Architecture diagram of the GitHub repository kiencang/luka-loop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kiencang/luka-loop
- Repository: https://github.com/kiencang/luka-loop

## Overview

Luka-Loop is an agent-operated PDF translation tool: a user gives a PDF and translation/layout request to a desktop coding agent, which uses the workspace tools to extract assets and prepare translated HTML and, when a browser is available, PDF output. A separate workflow detects a book’s table of contents and splits it into chapter PDFs. The source excerpts show detector internals and safety/HTML checks; the README documents the agent-led translation and output steps. Translation itself is agent-driven and is not represented as an inspected code subsystem.

Main entry points: [`tools/src/figure_detector/pipeline.py`](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/pipeline.py) (Detection pipeline), [`tools/src/book_splitter/actions.py`](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/actions.py) (Book split actions), [`tools/src/extract_assets.py`](https://github.com/kiencang/luka-loop/blob/main/tools/src/extract_assets.py) (Asset tool), [`tools/src/packager.py`](https://github.com/kiencang/luka-loop/blob/main/tools/src/packager.py) (Output packaging)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Agent workflows"]
  node_agent["Desktop agent"]
  node_tool["Asset tool<br/>[extract_assets.py]"]
  node_image_ops["PDF image operations<br/>[image_ops.py]"]
end

subgraph group_detect["Figure detection"]
  node_fig_extract["Figure extraction<br/>[extract.py]"]
  node_fig_pipeline["Detection pipeline<br/>[pipeline.py]"]
  node_fig_text["Page text analysis<br/>[text.py]"]
  node_fig_raster["Raster detection<br/>[raster.py]"]
  node_fig_vector["Vector detection<br/>[vector.py]"]
  node_fig_merge["Candidate merging<br/>[merge.py]"]
  node_fig_captions["Caption matching<br/>[captions.py]"]
  node_fig_match["Caption primitives<br/>[caption_match.py]"]
  node_fig_geometry["Geometry helpers<br/>[geometry.py]"]
  node_fig_model["Detection models<br/>[model.py]"]
end

subgraph group_output["Output and safety"]
  node_html["HTML quality checks<br/>[html_qa.py]"]
  node_reader["Reader shell<br/>[reader_shell.py]"]
  node_packager["Output packaging<br/>[packager.py]"]
  node_pdf_export["Browser PDF export<br/>[pdf_export.py]"]
  node_path_guards["Path safety<br/>[path_guards.py]"]
  node_output_paths["Output paths<br/>[output_paths.py]"]
end

subgraph group_books["Book splitting"]
  node_book_tool["Book split actions<br/>[actions.py]"]
  node_book_toc["TOC detection<br/>[toc.py]"]
  node_book_planner["Chapter planner<br/>[planner.py]"]
  node_book_align["Page alignment<br/>[alignment.py]"]
  node_book_features["TOC features<br/>[features.py]"]
  node_book_confine["Split confinement<br/>[confinement.py]"]
  node_book_constants["Split rules<br/>[constants.py]"]
end

node_user(("PDF user"))
node_pdf["Source PDF"]
node_outputs["HTML and PDF files"]
node_chapter_pdfs["Chapter PDFs"]

node_user -->|"requests translation"| node_agent
node_agent -->|"invokes tools"| node_tool
node_user -->|"provides PDF"| node_pdf
node_tool -->|"extracts figures"| node_fig_extract
node_tool -->|"uses image operations"| node_image_ops
node_tool -->|"dispatches splitting"| node_book_tool
node_tool -->|"packages output"| node_packager
node_tool -->|"exports PDF"| node_pdf_export
node_tool -->|"checks paths"| node_path_guards
node_fig_extract -->|"runs detection"| node_fig_pipeline
node_fig_pipeline -->|"analyzes text"| node_fig_text
node_fig_pipeline -->|"detects raster"| node_fig_raster
node_fig_pipeline -->|"detects vectors"| node_fig_vector
node_fig_pipeline -->|"merges candidates"| node_fig_merge
node_fig_pipeline -->|"matches captions"| node_fig_captions
node_fig_captions -->|"uses primitives"| node_fig_match
node_fig_pipeline -->|"uses models"| node_fig_model
node_fig_pipeline -->|"uses geometry"| node_fig_geometry
node_fig_pipeline -->|"uses image operations"| node_image_ops
node_packager -->|"checks HTML"| node_html
node_packager -->|"uses shell"| node_reader
node_packager -->|"resolves output paths"| node_output_paths
node_packager -->|"validates paths"| node_path_guards
node_packager -->|"requests PDF export"| node_pdf_export
node_pdf_export -->|"checks HTML"| node_html
node_pdf_export -->|"uses shell"| node_reader
node_pdf_export -->|"resolves paths"| node_output_paths
node_agent -->|"returns translation"| node_outputs
node_book_tool -->|"finds contents"| node_book_toc
node_book_tool -->|"plans chapters"| node_book_planner
node_book_tool -->|"aligns pages"| node_book_align
node_book_tool -->|"uses TOC features"| node_book_features
node_book_tool -->|"confines outputs"| node_book_confine
node_book_tool -->|"uses split rules"| node_book_constants
node_book_tool -->|"writes chapters"| node_chapter_pdfs

click node_tool "https://github.com/kiencang/luka-loop/blob/main/tools/src/extract_assets.py"
click node_fig_extract "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/extract.py"
click node_fig_pipeline "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/pipeline.py"
click node_fig_text "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/text.py"
click node_fig_raster "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/raster.py"
click node_fig_vector "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/vector.py"
click node_fig_merge "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/merge.py"
click node_fig_captions "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/captions.py"
click node_fig_match "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/caption_match.py"
click node_fig_geometry "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/geometry.py"
click node_fig_model "https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/model.py"
click node_image_ops "https://github.com/kiencang/luka-loop/blob/main/tools/src/image_ops.py"
click node_html "https://github.com/kiencang/luka-loop/blob/main/tools/src/html_qa.py"
click node_reader "https://github.com/kiencang/luka-loop/blob/main/tools/src/reader_shell.py"
click node_packager "https://github.com/kiencang/luka-loop/blob/main/tools/src/packager.py"
click node_pdf_export "https://github.com/kiencang/luka-loop/blob/main/tools/src/pdf_export.py"
click node_path_guards "https://github.com/kiencang/luka-loop/blob/main/tools/src/path_guards.py"
click node_output_paths "https://github.com/kiencang/luka-loop/blob/main/tools/src/output_paths.py"
click node_book_tool "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/actions.py"
click node_book_toc "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/toc.py"
click node_book_planner "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/planner.py"
click node_book_align "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/alignment.py"
click node_book_features "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/features.py"
click node_book_confine "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/confinement.py"
click node_book_constants "https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/constants.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent,node_tool,node_image_ops,node_user toneBlue
class node_fig_extract,node_fig_pipeline,node_fig_text,node_fig_raster,node_fig_vector,node_fig_merge,node_fig_captions,node_fig_match,node_fig_geometry,node_fig_model toneAmber
class node_html,node_reader,node_packager,node_pdf_export,node_path_guards,node_output_paths toneMint
class node_book_tool,node_book_toc,node_book_planner,node_book_align,node_book_features,node_book_confine,node_book_constants toneRose
class node_pdf,node_outputs,node_chapter_pdfs toneIndigo
```

## Components

### Agent workflows

- **Desktop agent**
- [Asset tool](https://github.com/kiencang/luka-loop/blob/main/tools/src/extract_assets.py): `tools/src/extract_assets.py`
- [PDF image operations](https://github.com/kiencang/luka-loop/blob/main/tools/src/image_ops.py): `tools/src/image_ops.py`

### Figure detection

- [Figure extraction](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/extract.py): `tools/src/figure_detector/extract.py`
- [Detection pipeline](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/pipeline.py): `tools/src/figure_detector/pipeline.py`
- [Page text analysis](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/text.py): `tools/src/figure_detector/text.py`
- [Raster detection](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/raster.py): `tools/src/figure_detector/raster.py`
- [Vector detection](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/vector.py): `tools/src/figure_detector/vector.py`
- [Candidate merging](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/merge.py): `tools/src/figure_detector/merge.py`
- [Caption matching](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/captions.py): `tools/src/figure_detector/captions.py`
- [Caption primitives](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/caption_match.py): `tools/src/figure_detector/caption_match.py`
- [Geometry helpers](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/geometry.py): `tools/src/figure_detector/geometry.py`
- [Detection models](https://github.com/kiencang/luka-loop/blob/main/tools/src/figure_detector/model.py): `tools/src/figure_detector/model.py`

### Output and safety

- [HTML quality checks](https://github.com/kiencang/luka-loop/blob/main/tools/src/html_qa.py): `tools/src/html_qa.py`
- [Reader shell](https://github.com/kiencang/luka-loop/blob/main/tools/src/reader_shell.py): `tools/src/reader_shell.py`
- [Output packaging](https://github.com/kiencang/luka-loop/blob/main/tools/src/packager.py): `tools/src/packager.py`
- [Browser PDF export](https://github.com/kiencang/luka-loop/blob/main/tools/src/pdf_export.py): `tools/src/pdf_export.py`
- [Path safety](https://github.com/kiencang/luka-loop/blob/main/tools/src/path_guards.py): `tools/src/path_guards.py`
- [Output paths](https://github.com/kiencang/luka-loop/blob/main/tools/src/output_paths.py): `tools/src/output_paths.py`

### Book splitting

- [Book split actions](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/actions.py): `tools/src/book_splitter/actions.py`
- [TOC detection](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/toc.py): `tools/src/book_splitter/toc.py`
- [Chapter planner](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/planner.py): `tools/src/book_splitter/planner.py`
- [Page alignment](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/alignment.py): `tools/src/book_splitter/alignment.py`
- [TOC features](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/features.py): `tools/src/book_splitter/features.py`
- [Split confinement](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/confinement.py): `tools/src/book_splitter/confinement.py`
- [Split rules](https://github.com/kiencang/luka-loop/blob/main/tools/src/book_splitter/constants.py): `tools/src/book_splitter/constants.py`

### Other components

- **PDF user**
- **Source PDF**
- **HTML and PDF files**
- **Chapter PDFs**

## Connections

- PDF user → Desktop agent: requests translation
- Desktop agent → Asset tool: invokes tools
- PDF user → Source PDF: provides PDF
- Asset tool → Figure extraction: extracts figures (evidence: `tools/src/extract_assets.py`)
- Asset tool → PDF image operations: uses image operations (evidence: `tools/src/extract_assets.py`)
- Asset tool → Book split actions: dispatches splitting (evidence: `tools/src/extract_assets.py`)
- Asset tool → Output packaging: packages output (evidence: `tools/src/extract_assets.py`)
- Asset tool → Browser PDF export: exports PDF (evidence: `tools/src/extract_assets.py`)
- Asset tool → Path safety: checks paths (evidence: `tools/src/extract_assets.py`)
- Figure extraction → Detection pipeline: runs detection (evidence: `tools/src/figure_detector/extract.py`)
- Detection pipeline → Page text analysis: analyzes text (evidence: `tools/src/figure_detector/pipeline.py`)
- Detection pipeline → Raster detection: detects raster (evidence: `tools/src/figure_detector/pipeline.py`)
- Detection pipeline → Vector detection: detects vectors (evidence: `tools/src/figure_detector/pipeline.py`)
- Detection pipeline → Candidate merging: merges candidates (evidence: `tools/src/figure_detector/pipeline.py`)
- Detection pipeline → Caption matching: matches captions (evidence: `tools/src/figure_detector/pipeline.py`)
- Caption matching → Caption primitives: uses primitives (evidence: `tools/src/figure_detector/captions.py`)
- Detection pipeline → Detection models: uses models (evidence: `tools/src/figure_detector/pipeline.py`)
- Detection pipeline → Geometry helpers: uses geometry (evidence: `tools/src/figure_detector/pipeline.py`)
- Detection pipeline → PDF image operations: uses image operations (evidence: `tools/src/figure_detector/pipeline.py`)
- Output packaging → HTML quality checks: checks HTML (evidence: `tools/src/packager.py`)
- Output packaging → Reader shell: uses shell (evidence: `tools/src/packager.py`)
- Output packaging → Output paths: resolves output paths (evidence: `tools/src/packager.py`)
- Output packaging → Path safety: validates paths (evidence: `tools/src/packager.py`)
- Output packaging → Browser PDF export: requests PDF export (evidence: `tools/src/packager.py`)
- Browser PDF export → HTML quality checks: checks HTML (evidence: `tools/src/pdf_export.py`)
- Browser PDF export → Reader shell: uses shell (evidence: `tools/src/pdf_export.py`)
- Browser PDF export → Output paths: resolves paths (evidence: `tools/src/pdf_export.py`)
- Desktop agent → HTML and PDF files: returns translation
- Book split actions → TOC detection: finds contents (evidence: `tools/src/book_splitter/actions.py`)
- Book split actions → Chapter planner: plans chapters (evidence: `tools/src/book_splitter/actions.py`)
- Book split actions → Page alignment: aligns pages (evidence: `tools/src/book_splitter/actions.py`)
- Book split actions → TOC features: uses TOC features (evidence: `tools/src/book_splitter/actions.py`)
- Book split actions → Split confinement: confines outputs (evidence: `tools/src/book_splitter/actions.py`)
- Book split actions → Split rules: uses split rules (evidence: `tools/src/book_splitter/actions.py`)
- Book split actions → Chapter PDFs: writes chapters
