Skip to content

feat(track-a): context-engine as a pure extraction library (ADR-037) - #2

Merged
hshekhar-git merged 5 commits into
mainfrom
feat/track-a-library
Jun 25, 2026
Merged

hshekhar-git merged 5 commits into
mainfrom
feat/track-a-library

Conversation

@avnsh

@avnsh avnsh commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What

Track A (ADR-037): turn @q1k-oss/context-engine into a pure, importable extraction library so the controlplane can consume Docling extraction + MINT + chunking in-process (no CE HTTP service).

  • Docling extraction (python/docling_extract.py) with an Apple-Silicon device fix (DOCLING_DEVICE, default cpu) + pyproject.toml/uv.lock so the Python subprocess ships with the package.
  • MINT serialization (mint-mapper.ts) + a new pure chunkDocument (chunker.ts, §-boundary chunks with overlap + page/section refs) + tests (__tests__/chunker.test.ts).
  • Barrel-free /extraction subpath (src/extraction.ts) exporting doclingClientService / structureToMint / chunkDocument + types — so importers don't load the Express app.
  • Removed the standalone orchestration (file-processor.service.ts, routes/files.routes.ts) — CE is a library now, not a service.
  • Bumps to 0.3.0; minimal CI (npm ci + build) on PRs.

⚠️ Draft — blocking before merge

  • package.json pins @q1k-oss/mint-format at a local tarball (file:../mint-format/...1.1.0.tgz). Depends on mint-format feat(track-a): context-engine as a pure extraction library (ADR-037) #2 — publish @q1k-oss/mint-format@1.1.0, re-pin to the real version. (CI npm ci will fail until then.)
  • Then publish @q1k-oss/context-engine@0.3.0 so the consumer can depend on it.

Pairs with

  • q1k-controlplane #102 consumes this library (extract → mint+chunk → embed → knowledge_chunks). That PR is also draft pending these publishes.

🤖 Generated with Claude Code

hshekhar-git and others added 4 commits May 29, 2026 03:11
Adds a Docling-based file extractor (python/docling_extract.py, spawned by
docling-client.service.ts) as the default, with graceful fallback to the
existing Gemini extractor on any failure. Extracted document structure is
serialized to MINT via the new mint-mapper (encodeDocument from
@q1k-oss/mint-format >=1.1.0) and stored in files.mint_content for
token-efficient prompt injection.

- file.types: DocumentStructure gains figures[] + section pageRef
- schema: files.mint_content column (apply via db:push)
- config: extractor option ('docling' | 'gemini')
- adds CLAUDE.md (extractor flow, Docling/uv setup, MINT usage)
- scripts/smoke-docling.ts verifies the structure -> MINT path
Make context-engine consumable in-process by q1k-controlplane's Temporal
activities (no HTTP service in the doc-ingestion path). Sprint M Track A.

- Docling device fix: python/docling_extract.py reads DOCLING_DEVICE (default
  cpu) and pins AcceleratorOptions — fixes the Apple-Silicon RT-DETR-v2
  float64-on-MPS crash. Verified: real PDF extracts cleanly, device=cpu, no patch.
- New pure chunker: chunkDocument(structure, opts) → DocumentChunk[] (§-boundary
  chunks + overlap, stable chunkIndex = idempotency key, provenance sectionRef/
  pageRef). +6 unit tests.
- Delete orchestration (A9): processFile/saveFile/integrateIntoGraph + the
  file-upload route. CE no longer owns ingestion state; controlplane drives it.
  No existing tests referenced these (60 existing tests still green).
- Clean library exports: doclingClientService, structureToMint/toMintDocument,
  chunkDocument + types from src/index.ts.
- Packaging: ship python/ + pyproject.toml in the npm `files` field so the
  Docling adapter travels with the library (the consuming worker resolves the
  Python env via DOCLING_CMD).
- Add `npm test` (vitest run) — repo had no test script.
- CLAUDE.md rewritten to the library role.

Verified real-stack: smoke-docling.ts → MINT round-trip + chunking + real
Docling on a sample SOP PDF all green; 66 unit tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The main index.ts barrel re-exports the Express routers, so importing it from
a pure-function consumer (controlplane's Temporal worker) drags in the whole
server stack. Add `@q1k-oss/context-engine/extraction` — a dependency-light
entry exporting only doclingClientService / structureToMint / chunkDocument +
types. Verified: controlplane imports it and runs chunk+mint with no express/
router load. Bump to 0.3.0 (library shape).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hshekhar-git
hshekhar-git marked this pull request as ready for review June 24, 2026 09:01
@avnsh
avnsh force-pushed the feat/track-a-library branch from c87c4dc to 7ebff50 Compare June 25, 2026 02:50
1.1.0 is now published; refresh the lockfile so npm ci resolves it.
Verified: npm ci + tsc build pass.
@hshekhar-git
hshekhar-git merged commit e6b6d51 into main Jun 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants