Sixian-Li/knowledge-base-kit / skills/process_docs
process_docs
UnverifiedIngest documents into this local knowledge workspace, preserving source content, drafting full text and summaries, validating, classifying and updating the catalog. Also supports check, batch, group, delete and teach requests.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.5 KB |
| config.defaults.yaml | config | 792 B |
| references/agent-compatibility.md | markdown | 1.4 KB |
| references/extraction-methods.md | markdown | 2.2 KB |
| references/generation-templates.md | markdown | 3.1 KB |
| references/group-mode.md | markdown | 1.2 KB |
| references/modes.md | markdown | 1.5 KB |
| references/stages-5-6.md | markdown | 1.3 KB |
| references/usage-guide.md | markdown | 1.0 KB |
| scripts/_config.py | script | 5.9 KB |
| scripts/check_agent_setup.py | script | 4.9 KB |
| scripts/check_tex.js | script | 1.1 KB |
| scripts/extract_document.py | script | 4.6 KB |
| scripts/extract_docx.py | script | 4.4 KB |
| scripts/extract_html.py | script | 3.1 KB |
| scripts/extract_notebook.py | script | 16.9 KB |
| scripts/extract_pdf.py | script | 6.1 KB |
| scripts/fold_archives.py | script | 1.7 KB |
| scripts/generate_output.py | script | 1.2 KB |
| scripts/kb_tree.py | script | 11.4 KB |
| scripts/orchestrate_workers.py | script | 8.6 KB |
| scripts/render_rmd.py | script | 6.1 KB |
| scripts/validate_generated.py | script | 14.2 KB |
| scripts/worker_backends.py | script | 9.3 KB |
scripts/extract_docx.py
View on GitHub"""Extract DOCX body order, tables and inline images without executing content."""
from pathlib import Path
import zipfile
from docx import Document
from docx.oxml import parse_xml
from docx.oxml.ns import qn
from docx.table import Table
def extract(source, output_dir):
document = Document(source)
output = Path(output_dir).resolve()
images, failed, warnings, chunks = [], [], [], []
counter = 0
def paragraph(element, part):
nonlocal counter
text = []
for node in element.iter():
if node.tag == qn("w:t"):
text.append(node.text or "")
elif node.tag == qn("w:tab"):
text.append("\t")
elif node.tag in (qn("w:br"), qn("w:cr")):
text.append("\n")
elif node.tag in (qn("w:footnoteReference"), qn("w:endnoteReference")):
text.append(f" [note {node.get(qn('w:id'))}] ")
elif node.tag == qn("a:blip"):
counter += 1
try:
rid = node.get(qn("r:embed"))
image = part.related_parts[rid]
ext = Path(str(image.partname)).suffix.lower()
if ext not in (".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif", ".tiff"):
raise ValueError(f"Unsupported embedded image {ext}; export the page or image as PNG")
path = output / "images" / f"image_{counter}{ext}"
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(image.blob)
images.append({"page": counter, "path": str(path), "size": len(image.blob)})
text.append(f"\n\n.as_posix()})\n\n")
except (KeyError, ValueError) as exc:
failed.append({"page": counter, "error": str(exc)})
text.append(f"[Image {counter} unavailable]")
return "".join(text)
def blocks(container):
result = []
for block in container.iter_inner_content():
if isinstance(block, Table):
rows = []
for row in block.rows:
cells = ["<br>".join(blocks(cell)).replace("|", "\\|").replace("\n", "<br>") for cell in row.cells]
rows.append("| " + " | ".join(cells) + " |")
if rows:
rows.insert(1, "| " + " | ".join("---" for _ in block.rows[0].cells) + " |")
result.append("\n".join(rows))
else:
content = paragraph(block._p, block.part)
style = block.style.name if block.style else ""
if style.startswith("Heading ") and style.split()[-1].isdigit():
content = "#" * min(6, int(style.split()[-1])) + " " + content
if content:
result.append(content)
return result
chunks.extend(blocks(document))
seen = set()
for section in document.sections:
for name in ("header", "footer", "first_page_header", "first_page_footer", "even_page_header", "even_page_footer"):
item = getattr(section, name)
if item.is_linked_to_previous:
continue
key = str(item.part.partname)
if key not in seen:
seen.add(key)
content = blocks(item)
if content:
chunks.extend([f"## {name.replace('_', ' ').title()}", *content])
with zipfile.ZipFile(source) as archive:
for name in ("word/footnotes.xml", "word/endnotes.xml", "word/comments.xml"):
if name in archive.namelist():
xml = parse_xml(archive.read(name))
content = ["".join(p.itertext()) for p in xml.iter(qn("w:p"))]
chunks.extend([f"## {Path(name).stem.title()}", *content])
warnings.append(f"Review note/comment numbering against {name}; complex layouts need visual comparison.")
body = archive.read("word/document.xml")
if any(tag in body for tag in (b"<w:ins", b"<w:del", b"<m:oMath", b"<w:txbxContent", b"<c:chart")):
warnings.append("Tracked changes, equations, text boxes or charts detected; export to PDF and review visually.")
return {"text": "\n\n".join(chunks) + "\n", "image_files": images,
"failed_images": failed, "warnings": warnings}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |