# genpark-doc-processor

Adopt this skill: https://proskills.md/skills/other/alpha-park-openclaw-genpark-doc-processor

Page: https://proskills.md/skills/other/alpha-park-openclaw-genpark-doc-processor
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: SKILL.md
size: 1054
sha: cfaf277cfa523f63c2921f61e9b341dde5680d65
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/SKILL.md

```text
---
name: genpark-doc-processor
description: Intelligent document, PDF, and spreadsheet data extractor.
version: 1.0.0
---

# genpark-doc-processor

## Overview
This skill mitigates the "messy data" problem. It takes unstructured or poorly formatted documents, PDFs, or raw data feeds and outputs clean, structured tables, summaries, or presentation outlines.

## Capabilities
1. **Data Structuring**: Turn messy conversational data or raw text dumps into clean CSV/Markdown tables.
2. **Report Summarization**: Take long business reports and extract only action items, financial figures, and core arguments.
3. **Presentation Generation**: Draft complete slide-by-slide outlines for business presentations based on raw notes.

## Usage Instructions
When a user provides raw data or asks to process a document:
- First, clarify the desired output format (Table, JSON, Slide Outline).
- Strip out all irrelevant fluff and directly address the structured data output.
- If data is ambiguous, create a "Needs Clarification" column or section in the output.
```

## File: README.md
size: 1430
sha: 9913b556781236d6a8fed0d28ea589ec0c229057
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/README.md

````text
# openclaw-genpark-doc-processor

[![Organization](https://img.shields.io/badge/AlphaPark-OpenSource-blue.svg)](https://github.com/alphaparkinc)
[![Model Context Protocol](https://img.shields.io/badge/MCP-Standard-orange.svg)](https://modelcontextprotocol.io)
[![Zero-Dependency](https://img.shields.io/badge/Dependencies-Zero_External-brightgreen.svg)](#)
[![Python Version](https://img.shields.io/badge/Python-3.9%2B-blue.svg)](#)
[![Security Rating](https://img.shields.io/badge/Status-Grade_A_Production-success.svg)](#)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

Production-hardened OpenClaw GenPark Agent skill engineered strictly with Python standard library. Provides high-throughput deterministic execution, cryptographic security, and game-theoretic optimization via the Model Context Protocol (MCP).

---

## Architecture & Data Flow

```mermaid
flowchart TD
    Input[Incoming Agent Telemetry / Task Input] --> Core["OpenClawGenParkDocProcessor"]
    Core --> Model[Mathematical Logic Engine]
    Model --> MCPResponse[Deterministic JSON Output / MCP Tool Result]
```

---

## Quickstart & Usage

### 1. Direct Python Client Execution
```bash
python example_usage.py
```

### 2. Standalone MCP Server Launch
Run the native STDIO MCP server:
```bash
python mcp_server.py
```

---

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
````

## File: .gitignore
size: 64
sha: ed8ae579cca3201f66148b37156e8f84a58a6680
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/.gitignore

```text
__pycache__/\n*.py[cod]\n.env\n.venv/\nvenv/\n*.log\n.DS_Store\n
```

## File: client.py
size: 7725
sha: b4605811dde951f8439032665c49e8318eee2976
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/client.py

```text
# -*- coding: utf-8 -*-
"""
OpenClaw GenPark Doc Processor Client
Pure Python Standard Library (Zero External Dependencies)
Implements recursive sliding-window boundary chunking, Markdown header hierarchy DAG parsing,
and lexical token-budget packing.
"""

import math
import re
import hashlib
from typing import Dict, Any, List, Optional

class OpenClawGenParkDocProcessor:
    """
    Algorithmic document parsing and context packaging engine for autonomous LLM agents.
    """

    def __init__(self):
        pass

    def partition_document_by_sliding_window(
        self,
        text: str,
        chunk_size_words: int = 200,
        overlap_words: int = 40
    ) -> Dict[str, Any]:
        """
        Partitions text into overlapping sliding-window chunks with SHA-256 fingerprints
        and boundary preservation.
        
        Formula:
          stride = chunk_size - overlap
          num_chunks = ceil((total_words - overlap) / stride)
        """
        if not text or not text.strip():
            return {
                "total_words": 0,
                "total_chunks": 0,
                "chunks": [],
                "overlap_retention_ratio": 0.0
            }

        words = text.split()
        total_words = len(words)
        
        chunk_size = max(10, chunk_size_words)
        overlap = min(max(0, overlap_words), chunk_size - 1)
        stride = chunk_size - overlap

        chunks = []
        start_idx = 0
        chunk_id = 0

        while start_idx < total_words:
            end_idx = min(start_idx + chunk_size, total_words)
            chunk_words = words[start_idx:end_idx]
            chunk_content = " ".join(chunk_words)
            
            # SHA-256 fingerprint
            fp = hashlib.sha256(chunk_content.encode("utf-8")).hexdigest()[:16]
            
            chunks.append({
                "chunk_id": chunk_id,
                "start_word_index": start_idx,
                "end_word_index": end_idx,
                "word_count": len(chunk_words),
                "fingerprint": fp,
                "text": chunk_content
            })
            
            chunk_id += 1
            start_idx += stride
            if end_idx >= total_words:
                break

        retention_ratio = round((overlap / chunk_size) if chunk_size > 0 else 0.0, 4)

        return {
            "total_words": total_words,
            "chunk_size_words": chunk_size,
            "overlap_words": overlap,
            "total_chunks": len(chunks),
            "overlap_retention_ratio": retention_ratio,
            "chunks": chunks
        }

    def parse_markdown_header_hierarchy_dag(self, markdown_text: str) -> Dict[str, Any]:
        """
        Parses Markdown text into a directed hierarchical DAG of sections (H1 -> H2 -> H3)
        tracking byte offsets, word counts, and structural balance metrics.
        """
        lines = markdown_text.splitlines()
        nodes = []
        stack = []  # stack of (level, node_idx)
        
        current_header = "Root / Preamble"
        current_level = 0
        current_content_lines = []
        
        for line in lines:
            header_match = re.match(r"^(#{1,6})\s+(.+)$", line.strip())
            if header_match:
                # Flush previous section
                if current_content_lines or current_header != "Root / Preamble":
                    sec_text = chr(10).join(current_content_lines).strip()
                    nodes.append({
                        "id": len(nodes),
                        "title": current_header,
                        "level": current_level,
                        "word_count": len(sec_text.split()) if sec_text else 0,
                        "character_length": len(sec_text),
                        "parent_id": stack[-1][1] if stack else None
                    })
                
                h_level = len(header_match.group(1))
                h_title = header_match.group(2).strip()
                
                # Maintain hierarchy stack
                while stack and stack[-1][0] >= h_level:
                    stack.pop()
                
                parent_id = stack[-1][1] if stack else None
                node_idx = len(nodes)
                stack.append((h_level, node_idx))
                
                current_header = h_title
                current_level = h_level
                current_content_lines = []
            else:
                current_content_lines.append(line)
                
        # Flush final section
        if current_content_lines or current_header:
            sec_text = chr(10).join(current_content_lines).strip()
            nodes.append({
                "id": len(nodes),
                "title": current_header,
                "level": current_level,
                "word_count": len(sec_text.split()) if sec_text else 0,
                "character_length": len(sec_text),
                "parent_id": stack[-1][1] if stack else None
            })

        total_nodes = len(nodes)
        max_depth = max([n["level"] for n in nodes], default=0)
        total_doc_words = sum([n["word_count"] for n in nodes])
        
        return {
            "total_sections": total_nodes,
            "max_header_depth": max_depth,
            "total_document_words": total_doc_words,
            "sections": nodes
        }

    def compute_lexical_token_budget_packing(
        self,
        chunks: List[Dict[str, Any]],
        max_context_budget_words: int = 800
    ) -> Dict[str, Any]:
        """
        Greedy first-fit bin-packing of document chunks into context windows,
        maximizing token utilization while maintaining sequential ordering.
        """
        if not chunks:
            return {
                "total_windows": 0,
                "budget_limit_words": max_context_budget_words,
                "average_utilization_pct": 0.0,
                "packed_windows": []
            }

        windows = []
        current_window_chunks = []
        current_window_words = 0

        for ch in chunks:
            ch_words = ch.get("word_count", len(ch.get("text", "").split()))
            
            if current_window_words + ch_words <= max_context_budget_words:
                current_window_chunks.append(ch)
                current_window_words += ch_words
            else:
                if current_window_chunks:
                    windows.append({
                        "window_index": len(windows),
                        "chunk_count": len(current_window_chunks),
                        "allocated_words": current_window_words,
                        "utilization_pct": round((current_window_words / max_context_budget_words) * 100.0, 2),
                        "chunk_ids": [c.get("chunk_id", i) for i, c in enumerate(current_window_chunks)]
                    })
                current_window_chunks = [ch]
                current_window_words = ch_words

        if current_window_chunks:
            windows.append({
                "window_index": len(windows),
                "chunk_count": len(current_window_chunks),
                "allocated_words": current_window_words,
                "utilization_pct": round((current_window_words / max_context_budget_words) * 100.0, 2),
                "chunk_ids": [c.get("chunk_id", i) for i, c in enumerate(current_window_chunks)]
            })

        avg_util = round(sum(w["utilization_pct"] for w in windows) / len(windows), 2) if windows else 0.0

        return {
            "total_windows": len(windows),
            "budget_limit_words": max_context_budget_words,
            "average_utilization_pct": avg_util,
            "packed_windows": windows
        }
```

## File: example_usage.py
size: 1316
sha: 5370400ac12cbfb7ff3e1225416d99282fe5dd92
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/example_usage.py

```text
# -*- coding: utf-8 -*-
from client import OpenClawGenParkDocProcessor

proc = OpenClawGenParkDocProcessor()

doc = """# Agentic Commerce Protocol
Autonomous trading network built upon Model Context Protocol.

## Architecture
The system employs decentralized smart contracts and off-chain state channels.
Agents communicate via standardized JSON-RPC protocols.

### Security
Zero-knowledge proofs verify execution state without revealing trade secrets.
Multi-signature escrows lock collateral securely.
"""

# 1. Markdown Hierarchy DAG
dag = proc.parse_markdown_header_hierarchy_dag(doc)
print(f"Hierarchy DAG: {dag['total_sections']} sections parsed (Max depth={dag['max_header_depth']})")
for s in dag['sections']:
    print(f"  Level {s['level']}: {s['title']} ({s['word_count']} words)")

# 2. Sliding Window Chunking
chunks_res = proc.partition_document_by_sliding_window(doc, chunk_size_words=15, overlap_words=3)
print(); print(f"Sliding Window: {chunks_res['total_chunks']} chunks generated (Overlap={chunks_res['overlap_retention_ratio']})")

# 3. Context Budget Packing
packing = proc.compute_lexical_token_budget_packing(chunks_res['chunks'], max_context_budget_words=25)
print(); print(f"Token Budget Packing: {packing['total_windows']} windows (Avg Utilization: {packing['average_utilization_pct']}%)")
```

## File: LICENSE
size: 1071
sha: bafb53b2fc9253ffcac08bb8f6e8a474ddf0a5d2
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/LICENSE

```text
MIT License

Copyright (c) 2026 AlphaPark Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## File: mcp_server.py
size: 1926
sha: 00e910ed45eefa512fefcbea28770a822f2404a8
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/mcp_server.py

```text
# -*- coding: utf-8 -*-
"""
OpenClaw GenPark Doc Processor MCP Server
FastMCP standard interface for recursive document chunking and hierarchy DAG synthesis.
"""

import json
from typing import Dict, Any, List
from client import OpenClawGenParkDocProcessor

try:
    from mcp.server.fastmcp import FastMCP
    mcp = FastMCP("openclaw-genpark-doc-processor")
except ImportError:
    class MockFastMCP:
        def __init__(self, name):
            self.name = name
        def tool(self):
            def decorator(f):
                return f
            return decorator
    mcp = MockFastMCP("openclaw-genpark-doc-processor")

processor = OpenClawGenParkDocProcessor()

@mcp.tool()
def partition_document_by_sliding_window(
    text: str,
    chunk_size_words: int = 200,
    overlap_words: int = 40
) -> str:
    """
    Partitions text into overlapping sliding-window chunks with SHA-256 fingerprints.
    """
    res = processor.partition_document_by_sliding_window(text, chunk_size_words, overlap_words)
    return json.dumps(res, indent=2)

@mcp.tool()
def parse_markdown_header_hierarchy_dag(markdown_text: str) -> str:
    """
    Parses Markdown text into a directed hierarchical DAG of sections (H1 -> H2 -> H3).
    """
    res = processor.parse_markdown_header_hierarchy_dag(markdown_text)
    return json.dumps(res, indent=2)

@mcp.tool()
def compute_lexical_token_budget_packing(
    chunks: List[Dict[str, Any]],
    max_context_budget_words: int = 800
) -> str:
    """
    Greedy first-fit bin-packing of document chunks into context windows.
    """
    res = processor.compute_lexical_token_budget_packing(chunks, max_context_budget_words)
    return json.dumps(res, indent=2)

def main():
    sample = "# Header 1\nIntro text\n## Subheader\nDetailed specifications."
    print("Testing Doc Processor:")
    print(partition_document_by_sliding_window(sample, 10, 2))

if __name__ == "__main__":
    main()
```

## File: requirements.txt
size: 76
sha: 0528add65f81b98e5d4083b7522a6a0ba35bc019
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/requirements.txt

```text
# Zero external dependencies required -- Python 3.9+ standard library only\n
```

## File: skill.json
size: 405
sha: f81c4138ebaf48055947f73ae654cabd6b988567
upstream: https://github.com/alpha-park/openclaw-genpark-doc-processor/blob/HEAD/skill.json

```text
{
  "name": "openclaw-genpark-doc-processor",
  "version": "1.0.0",
  "description": "OpenClaw GenPark Doc Processor - Recursive boundary chunking, Markdown header hierarchy DAG synthesis, and lexical token-budget packing with zero external dependencies.",
  "tools": [
    "partition_document_by_sliding_window",
    "parse_markdown_header_hierarchy_dag",
    "compute_lexical_token_budget_packing"
  ]
}
```
