doctk - Document Toolkit¶
A composable, functional toolkit for structured document manipulation with interactive REPL, VS Code extension, and Language Server support.
Version: 0.1.0-dev (MVP Complete - Pre-Release)
Philosophy¶
Inspired by category theory, set theory, and the Zen of Python, doctk provides elegant primitives for document transformation:
- Composable: Complex operations built from simple primitives
- Pure: Operations transform rather than mutate
- Format-agnostic: Operates on universal document AST
- Type-safe: Well-typed transformations
- Pipeable: Unix-philosophy pipelines for documents
Features¶
Core Engine¶
- π Core abstractions - Document, Node hierarchy, operations
- π§ Markdown support - Full parser and writer with markdown-it-py
- π² Document outliner - Tree visualization with rich console output
- β 749 tests passing - Comprehensive test coverage (68.78%)
- π Type-safe - Full type annotations throughout
Operations¶
- π Selection & filtering - select, where predicates
- βοΈ Level operations - promote, demote, lift, lower
- π Structure operations - nest, unnest, move_up, move_down
- β‘ Pipe syntax -
doc | select(heading) | promote() - π§© Composable - Chain operations functionally
DSL and Execution¶
- π¬ Domain-Specific Language - Intuitive document manipulation DSL
- π₯οΈ Interactive REPL - Live document editing with state management
- π Script execution - Run
.tkfiles with doctk commands - π Code blocks - Execute DSL from Markdown documents
- β οΈ Error recovery - Line/column position tracking
VS Code Extension¶
- π² Tree view - Hierarchical document outline sidebar
- π±οΈ Drag-and-drop - Visual section reorganization
- β¨οΈ Keyboard shortcuts - Fast operations (promote, demote, move, delete, rename)
- π¨ Context menus - Right-click operations
- π Real-time sync - Bidirectional editor synchronization
- β‘ Performance - Optimized for 1000+ heading documents
- π¦ Ready to install - Packaged as
.vsix
Language Server (LSP)¶
- β¨ Auto-completion - Operation suggestions as you type
- π Hover docs - Rich documentation with examples
- π Syntax validation - Real-time diagnostics
- π‘ Signature help - Parameter hints and types
- πΊοΈ Document symbols - Navigate operations easily
- π€ AI support - Structured operation catalog for AI agents
- β‘ Fast - < 200ms response times
Integration & Architecture¶
- π JSON-RPC bridge - TypeScript β Python communication
- ποΈ Pluggable - Extensible architecture for new interfaces
- βοΈ Granular edits - Cursor position preservation
- π Centralized IDs - Consistent node identification
- πΎ Memory management - LRU cache for large documents
- π‘οΈ Error resilience - Automatic recovery and retry
- π§ͺ E2E tested - Comprehensive integration tests
Quick Examples¶
Python API¶
from doctk import Document
from doctk.operations import select, where, promote, demote
from doctk.integration import StructureOperations
# Load document
doc = Document.from_file("guide.md")
# Pipe-style transformations
result = doc | select(heading) | where(level=3) | promote()
# Save
result.to_file("guide_updated.md")
# Structure operations (static methods)
result = StructureOperations.move_up(doc, node_id="h2-intro")
result = StructureOperations.nest(doc, node_id="h3-details", under_id="h2-intro")
Interactive REPL¶
# Start REPL
$ doctk repl guide.md
# Execute operations
doctk> promote(1) # Promote first heading
doctk> move_up(2) # Move second section up
doctk> nest(3, under=1) # Nest section 3 under section 1
doctk> save output.md # Save changes
Script Execution¶
Execute with: doctk execute script.tk guide.md
Note: The script modifies the input file in place.
Documentation Structure¶
Getting Started¶
- Installation Guide - Get doctk installed
- Quick Start - Hands-on tutorial
Development¶
- Setup Guide - Development environment setup
- Testing Guide - Running and writing tests
- Tooling Guide - External tools and automation
- Quality Standards - Code quality and conventions
API Reference¶
- Core Integration - Document operations and structure
- DSL Reference - Domain-Specific Language syntax
- LSP Reference - Language Server Protocol features
Guides¶
- Adding New Interfaces - Extend doctk to new platforms
- Extending the DSL - Add custom DSL operations
Design & Architecture¶
Design documents are available in the repository but not included in the published docs site:
docs/design/02-pluggable-architecture.md- Current architecture overviewdocs/design/03-core-integration-decisions.md- Architecture Decision Records (ADRs)docs/design/04-lsp-architecture.md- Language Server designdocs/design/01-initial-design.md- β οΈ Historical: Original vision (superseded by specs)
Specifications¶
For current feature specifications and implementation tracking, see:
.kiro/specs/- Structured Kiro specs (requirements, design, tasks).kiro/steering/- Project conventions and AI assistant guidance
Historical Archive¶
Historical documents are available in the repository at docs/archive/:
- POC summary, session notes, original specification, reproduction guide
Roadmap¶
π Planned for v0.2.0:
- Enhanced node types (Section, Table, Inline)
- Path/CSS/XPath selection system
- Additional format support (reStructuredText, HTML, Confluence)
- Advanced tools (differ, validator, stats)
- Interactive TUI
License¶
MIT - see LICENSE for details.