Skip to content
Skills Library
Documents & office · Conversion & formats

sdo-docx-operations

/sdo-docx-operations

Cross-platform operational guardrails and deterministic helper scripts for officecli OOXML edits on .docx files. Use when editing .docx with officecli raw-set, fixing tab run issues, inserting bookmarks or field codes (SEQ/REF), validating XPath targeting, or preventing destructive raw-set mistakes. Applies across all SDOs -- concrete style names provided by the per-SDO drafting skill.

Repository
prompts ↗
Licence
MIT
Last repository change
02.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
19
Scripts
5
HTML comments
0
URLs in SKILL.md
4
Deprecation

No signals detected. Repository changed on 02.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What to check before installing
  • 5 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: scripts/add_bookmarks.py, scripts/fix_enum_tabs.py, scripts/fix_heading_tabs.py, scripts/fix_note_tabs.py, scripts/officecli_xml_common.py

What it does and when to use it

Cross-platform operational guardrails and deterministic helper scripts for officecli OOXML edits on .docx files. Use when editing .docx with officecli raw-set, fixing tab run issues, inserting bookmarks or field codes (SEQ/REF), validating XPath targeting, or preventing destructive raw-set mistakes. Applies across all SDOs -- concrete style names provided by the per-SDO drafting skill.

Original author description

Cross-platform operational guardrails and deterministic helper scripts for officecli OOXML edits on .docx files. Use when editing .docx with officecli raw-set, fixing tab run issues, inserting bookmarks or field codes (SEQ/REF), validating XPath targeting, or preventing destructive raw-set mistakes. Applies across all SDOs -- concrete style names provided by the per-SDO drafting skill.

How it works

  1. Workflow
  2. Script entry points
  3. JSON specs
  4. Idempotent updates — avoid hanging paragraphs
  5. Safety rules
  6. Python OOXML manipulation — namespace caveat
  7. References
  8. Cross-references
Original SKILL.md headings · 131 lines, 743 words
SKILL.md preview
---
name: sdo-docx-operations
description: Cross-platform operational guardrails and deterministic helper scripts for officecli OOXML edits on .docx files. Use when editing .docx with officecli raw-set, fixing tab run issues, inserting bookmarks or field codes (SEQ/REF), validating XPath targeting, or preventing destructive raw-set mistakes. Applies across all SDOs -- concrete style names provided by the per-SDO drafting skill.
---

# SDO DOCX Operations -- officecli guardrails

Use this skill for reliable, repeatable officecli operations that require
XML-level edits on standards documents.

## Workflow

1. Open the document in resident mode before multi-step edits:
   `officecli open <doc>`
2. Run one mutation command at a time and check exit codes.
3. Use style/ordinal or explicit XPath targeting, not paraId targeting.
4. **Prefer `officecli batch` for template population, text updates, and paragraph additions.**
   Python zipfile/ElementTree scripts can strip namespace declarations from the
   root element (see "Python OOXML manipulation — namespace caveat" below).
   Reserve Python scripts for edits that officecli cannot express.
5. Validate with `officecli view`/`get`/`query` before and after mutation.
6. Close the document at the end: `officecli close <doc>`

## Script entry points

- `scripts/add_bookmarks.py` -- figure/table/reference bookmark insertion
  and reference run replacement.
- `scripts/fix_heading_tabs.py` -- heading number-tab-title run repair.
- `scripts/fix_enum_tabs.py` -- enumeration dash-tab-text run repair.
- `scripts/fix_note_tabs.py` -- NOTE number-tab-text run repair and
  sequence validation.
- `scripts/officecli_xml_common.py` -- shared helpers (run_officecli,
  raw_set, validate_doc, load_json_spec).

All scripts declare PEP 723 inline metadata and are run via `uv run`:

```bash
uv run scripts/add_bookmarks.py --doc <doc> --spec assets/specs/add_bookmarks.example.json
uv run scripts/fix_heading_tabs.py --doc <doc> --mapping assets/specs/fix_heading_tabs.example.json
uv run scripts/fix_enum_tabs.py --doc <doc> --items assets/specs/fix_enum_tabs.example.json
uv run scripts/fix_note_tabs.py --doc <doc> --notes assets/specs/fix_note_tabs.example.json
```

## JSON specs

- `assets/schemas/` -- JSON Schema contracts for each script input.
- `assets/specs/` -- example specs for reuse across projects.

## Idempotent updates — avoid hanging paragraphs

When a script inserts paragraphs (figures, tables) that are later refreshed by
re-running the same script, **hanging paragraphs** accumulate — old inserted
elements are left behind and new ones are added on each run.

**Rules:**

- Before inserting Figure-style image paragraphs: query and remove ALL existing
  `style=Figure` paragraphs (exact match, not contains).
  - Use `paragraph[style=Figure]` — **not** `paragraph[style~=Figure]`.
  - Captions (`style=Figure_No & title` / `FigureNotitle0`) are
    updated **in-place** via `set`; do NOT remove them — they serve as stable
    anchor paraIds for the insertion `--before` target.
- Before rebuilding a table section: remove all dynamic tables by iterating
  `remove /body/tbl[N]` in a `while True / except RuntimeError: break` loop
  rather than a fixed count. A fixed count fails on repeated runs once tables
  have already been removed.
- Before removing paragraphs by paraId: wrap each removal in try/except
  (or check existence first) so the script is safe to run multiple times.
  ParaIds that were already removed on a previous run must not abort the script.
- **Exact vs contains style match matters:**
  - `paragraph[style=Figure]` — exact match (image containers only)
  - `paragraph[style~=Figure_No]` — contains match (would also remove captions)

## Safety rules

- Never use `raw-set --action replace` with an empty XML payload.
- Always keep bookmark names and IDs unique.
- Always preserve non-breaking spaces and explicit tab runs where required.
- Keep scripts platform-independent and executable via `uv run`.
- Always use `uv run python`, never bare `python`.

## Python OOXML manipulation — namespace caveat

When using Python `zipfile` + `ElementTree` to manipulate OOXML directly,
`ET.register_namespace()` must be called for **every** namespace prefix used
in the document — otherwise `ET.tostring()` strips undeclared prefixes from
the root element, causing OpenXML schema validation errors and potentially
breaking the document in Word.

**Safer alternative:** Prefer `officecli batch` for template population,
text updates, and paragraph additions. `officecli batch` preserves all
namespace declarations automatically and handles the OOXML schema correctly.
Reserve Python zipfile/ElementTree for cases where officecli cannot express
the required edit (e.g., inserting hyperlink relationships in `.rels` files).

```python
# Required namespace registrations for even a simple docx:
ET.register_namespace(
    "w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
)
ET.register_namespace(
    "r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
)
ET.register_namespace("w14", "http://schemas.microsoft.com/office/word/2010/wordml")
ET.register_namespace("w15", "http://schemas.microsoft.com/office/word/2012/wordml")
# ... and potentially 20+ more (wp14, w16, w16se, w16cid, w16sdtdh, etc.)
```

If even one namespace is missing, the document's root element loses those
declarations on serialization and the file fails validation.

- Use `extract_paragraphs()` from `references/raw-xml-manipulation.md`
  — never the naive `<w:p ...>.*?</w:p>` regex (breaks on self-closing `<w:p/>`).
- When extracting `<w:rPr>`, use balanced `<w:rPr>` token matching
  — never `find('<w:rPr', ...)` which also matches `<w:rPrChange>`.
- Validate replacement XML with `validate_para_xml()` before batching.
- Check for `' REF REF_' in pxml` before tag-scanning to avoid
  double-replacement after a paragraph is already fixed.

## References

- [references/tool-usage.md](references/tool-usage.md)
- [references/constraints.md](references/constraints.md)
- [references/xpath-patterns.md](references/xpath-patterns.md)
- [references/field-code-patterns.md](references/field-code-patterns.md)
- [references/tracked-changes.md](references/tracked-changes.md)
- [references/raw-xml-manipulation.md](references/raw-xml-manipulation.md)

## Cross-references

- `sdo-docx-formatting` -- formatting rules that these operations implement
- `3gpp-drafting` / `etsi-drafting` / `itut-drafting` -- concrete style names
  required for XPath targeting (e.g. `Heading1`, `B1`, `NO`, `TF`)
- `docx-svg` -- SVG image insertion when officecli is not available
Files in this package (19)
  • SKILL.md 7 KB
  • assets/schemas/add_bookmarks.schema.json 2 KB
  • assets/schemas/fix_heading_tabs.schema.json 1 KB
  • assets/schemas/heading_style_map.schema.json 1 KB
  • assets/specs/add_bookmarks.example.json 1 KB
  • assets/specs/fix_enum_tabs.example.json 1 KB
  • assets/specs/fix_heading_tabs.example.json 1 KB
  • assets/specs/fix_note_tabs.example.json 1 KB
  • references/constraints.md 8 KB
  • references/field-code-patterns.md 3 KB
  • references/raw-xml-manipulation.md 14 KB
  • references/tool-usage.md 1 KB
  • references/tracked-changes.md 9 KB
  • references/xpath-patterns.md 1 KB
  • scripts/add_bookmarks.py 3 KB
  • scripts/fix_enum_tabs.py 2 KB
  • scripts/fix_heading_tabs.py 2 KB
  • scripts/fix_note_tabs.py 2 KB
  • scripts/officecli_xml_common.py 2 KB

Versions

The database has no other skills named sdo-docx-operations.

Database snapshot: 13.11.2026 · package version 5902bb4fe5d8 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 903gpp-drafting
    3GPP-specific TDoc authoring conventions: metadata schema, template substitution, revision workflow, DOCX property sync, project layout, and 3GPP style-name mapping. Use when preparing, updating, or validating 3GPP TDoc .docx files for meeting submissions. Delegates formatting…
  • 95itut-drafting
    ITU-T-specific contribution document drafting: template structure, header table fields, style-name mapping, equation conventions, and batch workflows. Use when preparing or editing ITU-T contribution .docx files (C-series or TD-series). Delegates formatting rules to…
  • 100officecli
    Use the optional iOfficeAI/OfficeCLI engine for advanced inspection, validation, copy-on-write editing, template merge, or visual rendering of existing .docx, .xlsx, and .pptx files. Prefer MateClaw's built-in renderDocx/renderXlsx/renderPptx tools for simple new documents. Use…
  • 100officecli
    Create, analyze, proofread, and modify Office documents (.docx, .xlsx, .pptx) using the officecli CLI tool. Use when the user wants to create, inspect, check formatting, find issues, add charts, or modify Office documents. Renders documents to check them (render, look, fix).
  • 100docx
    Word文档全生命周期处理工具。支持新建文档(docx-js)、编辑现有文档(OOXML)、审阅修订(标记批改痕迹)、内容解析与格式保真。本技能应在用户需要创建、修改、审阅或提取.docx文件内容时使用。
  • 100ooxml-edit
    Propose and apply changes to the Agentic OOXML knowledge parts of a .docx, .pptx or .xlsx (agents, design, intent, sources) without touching native document content. Use when the user asks to record editing rules, design notes, intent or source claims in the file, or to refresh stale source claims.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.