/report-regeneration:rebind-officefrom report-regeneration
Surgically regenerates a Word .docx from a template and Binding Manifest, preserving frozen OPC parts and nodes via byte-identical edits. Uses stdlib zipfile/xml.etree and the rr_anchor OOXML resolver.
Ships in report-regeneration. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The Office (Word/.docx) surgical output engine for report-regeneration — pipeline
stage 3, the exact analogue of rebind-html. Given a .docx
template, a Binding Manifest
(../../knowledge/binding-manifest.schema.json,
format: "office"), and resolved new-source data, it produces a same-format review-ready
draft by performing schema-validated surgery on a copy of the template — never by
re-rendering from an abstract model. This is the "surgeon, not a renderer" model from
../../knowledge/core-architecture-spec.md
§1, applied to the Office/Word→PDF output format.
The engine works on a copy the whole way: it reads word/document.xml out of the OPC/ZIP
package with stdlib zipfile, edits only those bytes via the shared OOXML resolver
in ../../scripts/rr_anchor.py, then re-zips — every other OPC
part is copied through byte-for-byte. It consumes a manifest; it does not infer structure
or propose bindings (that is infer-office, an earlier stage) and
it does not run the fidelity harness (V1–V6 + period-coherence — a separate, downstream
track). Its one job: apply exactly what the manifest says, per node class, and prove the
frozen ones (parts and nodes) didn't move.
It never re-implements anchor resolution. Every anchor is resolved by rr_anchor's
ooxml_resolve / ooxml_try_resolve, which OWNS the shared OOXML grammar (body-rooted
body/p[3]/r[1] paths and bookmark(NAME) paths) that infer-office produces — so producer
and consumer cannot drift.
| Class | What this engine does |
|---|---|
frozen | No mutation. After every other binding is applied, the engine re-resolves the node in both template and output and proves its outer OOXML byte span is identical (_assert_frozen_unchanged) — a defensive proof, not an assumption. frozen is EARNED upstream (the manifest's job); rebind only guarantees a frozen node did not move. |
surgical | Strip, then write — two separate byte splices, in that order. _strip_value empties every w:t under the anchored run/cell (zero-literal); _write_value writes the new value into the first w:t. At the instant between the two calls the node provably carries no old instance value — by construction, not a downstream check. Run properties (w:rPr) and every other child are preserved; the edit touches only w:t text. |
regenerate | Same strip-then-write zero-literal invariant. A prose/run node is rebuilt from new data via stdlib string.Template (dotted-placeholder subclass — jinja2 is optional acceleration for native {{ }}/{% %} control syntax). A raster/w:drawing node is force-regenerated by replacing the referenced word/media/* binary with a fresh capture supplied in new-data — never by transplanting the old pixels, per the spec's construction rule: "a transplanted binary blob cannot be proven data-free." A regenerate raster with no fresh capture is a loud error, never a silent transplant. |
needs-review | Left completely untouched — content byte-for-byte unchanged — but a visible OOXML marker run (or a marker paragraph, for a table cell) carrying a machine-readable token ([[REBIND-NEEDS-REVIEW]]) is inserted adjacent to it, and it is logged in the change-manifest. Never ships silently — this is guarantee #2 made mechanical for Office output. |
Bindings are applied in reverse document order (RT1-F10): each anchor is a stable node identity re-resolved on the current bytes just before its edit, so processing from the end of the document backward means an earlier edit's byte/index shift can never invalidate a not-yet-applied anchor.
python3 plugins/report-regeneration/skills/rebind-office/rebind_office.py \
--template tests/fixtures/report-regeneration/sample-report.docx \
--manifest path/to/binding-manifest.json \
--new-data path/to/new-data.json \
--out tests/fixtures/report-regeneration/_out/regenerated.docx
Add --pretty to pretty-print the printed JSON change-manifest. Every invocation prints a
JSON object to stdout: {"schema": "report-regeneration/rebind-office@1", "ok": true|false, ..., "changes": [...]}. Exit code 0 = success; 2 = usage / path-guard / manifest-schema /
anchor-not-found / missing-data-query / missing-new-data-key / invalid-docx error (never a
silent partial write — a failure aborts the whole run and touches --out not at all).
--template/--manifest/--new-data/--out are relative (or in-repo absolute) paths,
path-guarded (mirrors ../rebind-html/rebind_html.py and
../../scripts/seed_defects.py): no .. traversal, must
resolve inside the repo root. --out may never equal --template — this script works on a
copy; the template file on disk is never mutated (verified in the CLI test via a
before/after SHA-256 hash of the template file).
A binding's data_query.expression is a dot-path into the --new-data JSON (e.g.
"revenue.total" looks up {"revenue": {"total": ...}}). surgical writes the resolved value
(XML-escaped) directly into the run's w:t. regenerate treats the resolved value as either:
${dotted.path} placeholders resolved against
the SAME new-data object (stdlib-only, always works); or a native Jinja template
({{ }}/{% %}) — rendered via jinja2 if importable, else a loud error (never a silent
stdlib mis-render of control-flow syntax); orw:drawing node, {"media_base64": "<fresh png/jpeg bytes>"}
(the fresh capture, base64-encoded); for a text node with an explicit template key,
{"template": "..."}.A missing dot-path segment, an unresolvable anchor, or a class/data_query mismatch against the
schema's rule (frozen carries no data_query; every other class must) is a loud error → exit
2 — never a guess.
Only anchor.kind == "ooxml_path" is resolvable — resolved via rr_anchor.ooxml_resolve
against the exact grammar infer-office emits (body/p[3]/r[1],
body/tbl[1]/tr[2]/tc[2]/p[1]/r[1], bookmark(revenue_total)). json_pointer /
element_id / css_selector anchors are HTML-lane anchors from the same manifest schema;
this engine rejects them loudly rather than guessing — HTML output is the separate
rebind-html lane.
Stdlib XML parsers are XXE / billion-laughs vulnerable and defusedxml is deliberately off
this plugin's dependency path, so this engine — like infer-office and rr_anchor — rejects
any DOCTYPE/DTD/ENTITY in any OOXML part it parses (word/document.xml, the .rels) before
xml.etree ever expands an entity. A valid OOXML part never carries one; the rejection closes
external-entity and entity-expansion attacks at the source and treats a hostile template as
data, never instructions (§6).
tests/test_rebind_office.py — stdlib unittest, no pytest
required, run end-to-end against the real
tests/fixtures/report-regeneration/sample-report.docx
corpus fixture:
TestRebindOffice — a hand-built manifest covering one binding of every class (frozen
heading run, surgical bookmarked currency value, regenerate narrative run, regenerate
raster, needs-review percent run): frozen OPC parts byte-identical (everything but the
edited word/document.xml + regenerated media) and [Content_Types].xml intact; a frozen
node byte-identical (+ a must-fail check that a genuinely mutated frozen node IS caught);
surgical value replaced with the OLD value absent from that run and the whole document;
strip-then-write asserted at the midpoint; regenerate text reflects new data; regenerate
raster swaps the media binary (old bytes gone, fresh in) and refuses a transplant with no
fresh capture; needs-review flagged + logged, content untouched; the output is a valid
docx (re-openable via zipfile + xml.etree, testzip() clean); manifest-schema
rejections (non-office format, non-ooxml anchor, frozen-with-data_query); DTD/XXE rejection.TestCLI — process-boundary: happy path (exit 0, valid docx written, $new present /
$old absent, template SHA-256 unchanged), --out == --template rejection, path-traversal
rejection, absolute-path rejection (all exit 2).Run: python3 plugins/report-regeneration/skills/rebind-office/tests/test_rebind_office.py -v
The producer↔resolver anchor cross-check lives in
../../scripts/tests/test_rr_anchor.py.
argparse, base64, io, json, posixpath, re, string, sys,
zipfile, xml.etree. No pip installs required. python-docx / docxtpl are detected for
parity only (the byte-splice engine is the sole code path); jinja2 is imported via a
graceful try/except and is optional acceleration for regenerate templates that use native
Jinja control syntax — every ${dotted.path}-only template works with jinja2 absent.from __future__ import annotations; no PEP 604 union
syntax (X | Y), no match statement.0/2; no partial write on failure.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
11 skills in this plugin
/infer-officeStage 1 of the report-regeneration OFFICE (docx) pipeline. Parses a Word .docx template into a schema-valid Report Structure Graph (RSG) via stdlib zipfile + xml.etree over word/document.xml: per-node OOXML body-walk anchor, role, rebind class, confidence, provenance, plus the deterministic data-shaped-literal detector reused from the HTML lane. Stdlib-only, Python 3.9; python-docx optional./infer-report-structureStage 1 of the report-regeneration HTML pipeline. Parses an HTML template into a schema-valid Report Structure Graph (RSG): per-node stable anchor, role, rebind class, confidence, provenance, plus the deterministic non-inference data-shaped-literal detector that drives the earned-frozen rule. Stdlib-only, runs on Python 3.9./powerbi-ingestPipeline-facing Power BI ingestion adapter, wrapping scripts/powerbi_probe.py for two modes: `data` runs every dax-kind Binding Manifest binding via REST executeQueries (service-principal/token from ENV ONLY), returning a data.json-shaped fragment keyed by data_query.expression with source_period stamped -- a genuinely independent V1 recompute source for a PBI-sourced value. `shot` captures a fresh report image via ExportToFile (Playwright fallback), packaging it as the embedded image for a regenerate-class PBI node with source_period stamped so period-coherence can catch a stale screenshot. Fail-closed throughout: no creds/route/period => not_captured + the named fallback (manual-figure-labeled-unverified for data, user-provided-image for shot), never a fabricated value or period. Token never logged. Reach for this to turn a Binding Manifest's PBI-sourced bindings into pipeline artifacts. NOT for manifest construction (rebind-manifest) or running the fidelity harness itself (report-fidelity-harness)./rebind-htmlPipeline stage 3 (the HTML surgical output engine) for report-regeneration. Applies a Binding Manifest to a COPY of an HTML report template and emits the regenerated HTML: frozen nodes stay byte-identical, surgical/regenerate nodes are rebuilt under the zero-literal construction rule (strip the old value, THEN write the new one), needs-review nodes are left untouched but visibly flagged + logged. Stdlib-only (re/html.parser/json), jinja2 optional acceleration, runs on Python 3.9.6. NOT for structure inference (that's an earlier pipeline stage) or the fidelity harness (a separate downstream track) or Office/docx output (a later release lane)./rebind-manifestPipeline stage 2 of report-regeneration (detect -> strip -> rebind): turn an RSG + the OLD template + the new dataset into a schema-valid Binding Manifest and a taint dictionary. Enforces the earned-frozen rule (a data-shaped literal / old-taint / new-dataset value demotes a candidate-frozen node to needs-review), forces raster/embedded-cache nodes to regenerate, and proposes each node's data_query. Reach for this when building or amending a Binding Manifest./report-a11y-gatereport-regeneration a11y gate: a11y_lint.py is a stdlib, machine-checkable WCAG-subset linter over an output HTML deliverable (the Tier-A a11y FLOOR, not axe-core/veraPDF -- that is the later Tier-B upgrade). BLOCKING rules: img-alt (non-decorative <img> with no alt), html-lang, link-name, button-name, control-label, table-headers. ADVISORY -> manual residue: th-scope, heading-order. Catches seeded defect D3 (missing alt-text) as a crisp img-alt BLOCK. Emits a sub-receipt folded into report-qa-gate (blocking a11y violation -> assembled verdict FAILs; manual residue -> reviewer checklist). HONEST about the ~30-50% machine-checkable floor: the rest is manual residue, never claimed passed. Stdlib-only, exit-coded, path-guarded, no network/subprocess.npx claudepluginhub mcorbett51090/ravenclaude --plugin report-regeneration