Skip to content

Latest commit

 

History

History
309 lines (232 loc) · 16.9 KB

CONTRIBUTING.md

File metadata and controls

309 lines (232 loc) · 16.9 KB

Contributing to InkDoc

Thank you for your interest in contributing to InkDoc! We welcome code contributions, bug reports, documentation enhancements, and feature suggestions.

Your first contribution in 10 minutes

  1. Pick something small. Issues labeled good first issue are scoped for newcomers; comment on one to claim it. Questions are welcome on the issue itself.
  2. Set up and run it:
    git clone https://github.com/<your-username>/InkDoc.git   # your fork
    cd InkDoc
    python -m venv .venv
    # Windows: .venv\Scripts\Activate.ps1   macOS/Linux: source .venv/bin/activate
    python -m pip install -r requirements.txt
    python -m pip install ruff==0.16.8 pytest==9.1.1 httpx==0.28.1 httpx2==2.13.0
    python main.py            # the desktop app; add --headless for the API only
  3. Check it the way CI does: ruff check . then python -m pytest tests/.
  4. Open a pull request. The template asks what you changed and how you tested it. A focused PR with one change is reviewed fastest.

The rest of this guide is the detail behind those steps.


1. Getting Started

Fork and Clone

git clone https://github.com/AbdoslamB/inkdoc.git
cd inkdoc

Environment Setup

Create a virtual environment and install development dependencies:

python -m venv .venv

# On Windows (PowerShell)
.venv\Scripts\Activate.ps1

# On macOS / Linux
source .venv/bin/activate

# Install dependencies
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install ruff

Running Locally

# Run the Desktop Application (Edge WebView2 / WebKit)
python main.py

# Run in Headless API mode
python main.py --headless --port 13118

2. Project Architecture

The codebase follows a domain-driven structure:

inkdoc/
├── app/
│   ├── core/                  # Conversion business logic & engine adapters
│   │   ├── converter.py       # MarkItDown wrapper, option mapping & collision-safe auto-save
│   │   ├── save_location.py   # Save folder setting (Downloads by default) & its fallback
│   │   ├── queue_model.py     # EngineKind enum, QueueItem data definitions
│   │   └── engines/           # IBM Docling, Markit & GLM-OCR engine adapters
│   ├── server/                # Embedded FastAPI backend
│   │   └── server.py          # Local REST endpoints (/convert, /health, /extensions)
│   ├── desktop/               # Native desktop runner
│   │   └── runner.py          # pywebview window manager & loopback orchestration
│   └── ui/                    # Shared Web & Desktop user interface
│       ├── index.html         # DOM layout, dropzone canvas, engine selector pills
│       ├── style.css          # Inkbench Obsidian design system (CSS custom properties)
│       └── app.js             # Reactive client-side logic & marked.js preview
├── tests/                     # Automated integration tests (test_server.py)
├── examples/                  # Developer client scripts & demos
├── API.md                     # REST API reference manual
└── main.py                    # Unified desktop & headless CLI entry point

Each area of the code has a developer guide in guides/: how it works, the rules it must keep, the tests that cover it, and lessons from earlier work there. AGENTS.md says which guide covers which file; read that guide before you change the file, and update it in the same pull request when the code changes how the area works.


3. Development Guidelines

Code Style & Quality

  • Backend (Python):
    • Write clean, readable Python 3.10+ code with explicit type annotations where appropriate.
    • Conversions must never block the main loop; engine operations run asynchronously or in background workers.
    • Follow PEP 8 guidelines. Verify your code with ruff check ..
  • Frontend (Web/Desktop UI):
    • The UI in app/ui/ is the single source of truth for both the desktop app and the web bench.
    • Use Vanilla HTML5, CSS Custom Properties, and modern standard JavaScript (ES6+ async/await).
    • Adhere to the Inkbench Obsidian design system defined in app/ui/style.css.
  • Cross-Platform Compatibility:
    • Keep all features compatible with Windows, macOS, and Linux.
    • Use pathlib.Path for filesystem operations rather than platform-specific string concatenation.

Core feature or download?

A new feature ships inside InkDoc unless at least one of these is true. If one is, it becomes a download (an engine pack or add-on that users install from Settings):

  • it needs model weights or a native runtime;
  • it adds more than 25 MB to the app or slows its startup;
  • it needs separate builds per platform;
  • its license isn't a permissive one like MIT, BSD or Apache-2.0 (for example GPL, LGPL, AGPL, MPL, or a model license that restricts use);
  • it uses the network.

Not sure? Open an issue first. The full rule is in AGENTS.md.

Adding an Auto quality step

Steps are what Balanced and Thorough add to an engine's result (for example the table check or chart text). Each one is core code and gets its own switch under Settings → General → Auto quality → Steps automatically. To add one:

  1. Register it in app/core/thorough_passes.py: a PassInfo whose place in PASSES is its order, with its lowest level, its stage, the engines it needs (needs_all / needs_any) and modules, the modules that do its work.
  2. Write the work in its own module under app/core/, pure where possible. It may import the standard library, InkDoc's own code and the PDF libraries InkDoc ships (pypdfium2, pdfplumber, pdfminer.six); import those libraries inside the function that uses them. tests/test_step_imports.py checks this.
  3. Call it where its stage runs (run_auto or _check_tables in app/core/auto_engine.py), only when plan.on("<name>"), and record what it did with log.ran(...) or log.skipped(...). That record is the response's tables.passes.
  4. Test it: the step's own behaviour, and its tables.passes entry (see tests/test_thorough_passes.py).

A step that needs a model is still core code; the model is an add-on. Put the code that runs the model under app/core/engines/ (it runs in the MarkItDown worker, so InkDoc's own process never loads its runtime), describe the model in app/core/addons.json, and name it in the step's needs_all. "Tables on scanned pages" is the example: scanned_tables.py is the step, engines/layout_model.py runs the layout_model add-on.


4. Optional Engine Packs (Docling) & Manifest Management

InkDoc supports optional deep layout parsing via isolated engine packs (IBM Docling). Engine packs are distributed as signed release assets and must satisfy strict cryptographic verification.

Integrity & Fail-Closed Policy

  • No Placeholders: Never commit placeholder hashes (e.g. PLACEHOLDER_*), empty hashes, or truncated hashes to app/core/manifest.json.
  • Fail Closed: Any missing hash, empty hash, placeholder, or hash that is not a 64-character hex SHA-256 aborts the installation before any archive extraction and marks the engine pack as unsupported for that build.
  • Release Guard: CI and Release workflows enforce python scripts/generate_engine_manifest.py --verify-manifest. Builds fail immediately if the manifest contains placeholder or malformed entries.

Building Packs and Generating Hashes

  1. Build the Pack:
    python scripts/build_pack.py --output-dir dist/packs
  2. Compute Real SHA-256 Hashes and File Tree:
    python scripts/generate_engine_manifest.py --archive dist/packs/docling-windows-x86_64.zip --platform windows-x86_64
  3. Update Manifest Directly:
    python scripts/generate_engine_manifest.py --archive dist/packs/docling-windows-x86_64.zip --platform windows-x86_64 --update-manifest
  4. Verify Manifest Integrity:
    python scripts/generate_engine_manifest.py --verify-manifest

The layout model add-on

The layout_model entry in app/core/addons.json ships unreleased, which is valid: with the Docling engine installed, InkDoc uses the identical copy that comes with it, and otherwise the add-on is not offered for download. To publish it:

  1. Build it: python scripts/build_layout_addon.py --release-tag layout-addon-v1 (add --model-dir <folder> to use a local copy instead of downloading the pinned Hugging Face revision). It refuses any model.onnx but the one pack_copy pins, and writes dist/addons/inkdoc-addon-layout_model.tar.gz and dist/addons/addons.json with the asset URL derived from the tag. The archive is reproducible.
  2. Publish the archive on that release tag, not marked Latest (the in-app updater uses /releases/latest).
  3. Commit dist/addons/addons.json as app/core/addons.json. scripts/verify_addon_catalogue.py checks it in CI.

5. Testing & Verification

Before submitting a pull request, run the complete verification suite locally:

# 1. Syntax check all source directories
python -m compileall -q main.py app tests examples scripts

# 2. Run the manifest release guard
python scripts/generate_engine_manifest.py --verify-manifest

# 3. Run the whole test suite, exactly as CI does
python -m pytest tests/

# 4. UI logic tests (need Node.js; CI runs every tests/*.test.js on Linux)
(for t in tests/*.test.js; do node "$t" || exit 1; done)

# Optional: how engines read tables, before and after the table check
# (synthetic test pages, plus your own PDFs with NAME.tables.json; see the script)
python scripts/table_bench.py --engines markitdown

# 5. Verify code style with ruff
ruff check .

6. Submitting Pull Requests

  1. Open an Issue First: For non-trivial changes, new features, or architectural adjustments, open an issue first to discuss the design.
  2. Keep PRs Focused: Keep pull requests focused on a single feature or bug fix.
  3. Describe Your Verification: Document the exact commands you ran and operating systems tested in the PR description using the template.
  4. Using AI Tools: They're welcome. You are the author of everything you submit: say which parts an AI tool wrote, and review and test all of it. The details are in the AI Policy.

Dependency Updates

All dependency updates (whether submitted manually or generated automatically by Dependabot) must satisfy the following requirements before merging:

  1. Automated CI Validation: The PR must cleanly pass all checks in .github/workflows/ci.yml across all supported platforms (Windows, macOS, and Linux).
  2. Smoke Test of Built App: Changes to core desktop runtime dependencies (including pywebview, fastapi, and uvicorn) require a local smoke test of a built application package to verify that desktop window events, pywebview loopback orchestration, and PyInstaller bundling continue to function without regressions.

Licenses for new dependencies, models and binaries

Any pull request that adds or upgrades a dependency, a model, or a bundled or downloaded binary must, in the same pull request:

  1. Check the license at the source. Read the component's own LICENSE file, model card or package metadata for the exact version. Don't rely on memory or on another project's summary. Model weights often have a different license from the code that runs them, so check both.
  2. Update THIRD_PARTY_NOTICES.md. Add or update its row: what InkDoc uses it for, upstream URL, copyright holder, exact license, and whether InkDoc bundles it, re-hosts it, mirrors it or lets the user's machine fetch it. If the upstream doesn't state something, write UNVERIFIED instead of guessing.
  3. Add the full license text to LICENSES/. Copy it unchanged, keeping the original copyright lines, and include any NOTICE file (Apache-2.0 requires it). For Python dependency changes, regenerate the affected list (LICENSES/python-packages-desktop.txt or LICENSES/docling-pack-packages.md) the way its header describes.
  4. Flag copyleft, restricted or unclear licenses. If anything is GPL, LGPL or AGPL, restricts commercial use (for example a non-commercial or research-only model license), or has unclear or custom terms, say so in the pull request description so a maintainer can decide. Don't add it quietly.

Dependabot pull requests need the same check before merging.

Bundled UI libraries (app/ui/vendor/)

The page's JavaScript, CSS and fonts (marked, DOMPurify, highlight.js, KaTeX) are bundled, never fetched at runtime, and pinned by SHA-256 in app/ui/vendor/VENDOR.json. Dependabot does not see them. To update one:

  1. Download the exact version (npm pack <name>@<version>) into an empty folder and check that the tarball's sha512 matches npm view <name>@<version> dist.integrity. Prefer a release that has been out for at least two weeks.
  2. Copy only the files VENDOR.json lists for that library, unchanged.
  3. Update the library's version, upstream_integrity and file hashes in VENDOR.json, its row in THIRD_PARTY_NOTICES.md, and its file in LICENSES/ (see above).
  4. Run python -m pytest tests/test_vendor_manifest.py, then the UI tests and a manual look at the preview.

Files in app/ui/vendor/ are never line-ending converted (see .gitattributes), so their hashes match on every OS.


7. Security Policy

Supported Versions

Only the latest release is supported with security fixes:

Version Supported
Latest ✅
Older ❌

Reporting a Vulnerability

If you find a security issue (for example, unsafe handling of untrusted input during file conversion, or something that could execute code from a malicious file), please do not open a public issue.

Instead, report it privately via GitHub Security Advisories for this repository. Include:

  • A description of the vulnerability and its impact
  • Steps to reproduce it, or a proof-of-concept file if relevant
  • The affected version/commit

You will receive an initial response within a few days. Once a fix is available, a new release will be published and the advisory disclosed.

Note

This app wraps Microsoft's markitdown package for primary file parsing and IBM docling for layout analysis. If the issue originates upstream in markitdown or docling itself rather than in InkDoc's code, please also report it upstream following their security policies.


8. Code of Conduct

Everyone taking part in InkDoc is expected to follow the Code of Conduct.


9. Release Runbook

Maintainers follow a strict release candidate rehearsal procedure before publishing a stable release:

1. Release Candidate (RC) Rehearsal

  1. Prepare Branch: Verify CHANGELOG.md is updated and CI is green on main. Always tag only from an up-to-date main branch:
    git checkout main
    git pull origin main
  2. Push RC Tag:
    git tag v1.0.2-rc1
    git push origin v1.0.2-rc1
  3. Automated Pipeline:
    • create-draft-release initializes a draft release marked as pre-release (--prerelease).
    • build matrix builds all platforms, runs full end-to-end smoke testing (--selftest, multi-format document conversions) against built artifacts, and uploads them to the draft.
    • publish-release publishes a release-candidate tag automatically as a pre-release. A stable tag is left as a draft so the update manifest can be signed offline and attached before it becomes Latest; publish it by hand with Set as the latest release checked. See docs/RELEASE_RUNBOOK.md.
  4. Validation: Test the uploaded artifacts on real hardware.

2. Recovery After a Failed Tag Run

If a build step or smoke test fails during a release run, the pipeline aborts without publishing:

  1. Delete the Draft Release and Remote Tag: Use gh release delete with --cleanup-tag to delete both the GitHub draft release and the remote git tag:
    gh release delete v1.0.2-rc1 --yes --cleanup-tag
  2. Delete the Local Git Tag:
    git tag -d v1.0.2-rc1
  3. Fix and Retry as Next RC: Fix the issue on a feature/fix branch, merge to main, and push the next release candidate tag (v1.0.2-rc2). Never re-use or force-push an existing tag.

3. Stable Release

Once an RC is fully verified, tag only from an up-to-date main:

git checkout main
git pull origin main
git tag v1.0.2
git push origin v1.0.2

A stable tag (no hyphen) stops at a draft: the update manifest is signed offline and attached first, and only then is the release published as Latest. See docs/RELEASE_RUNBOOK.md.