Template-Apply Dynamic Gates
Use this guide for all template-driven tasks (including fill, patch, and rebuild variants).
Purpose
Let the model edit freely while engineering gates enforce constraints derived from the actual user template.
Two Execution Lanes
createlane (no template): C# OpenXML generation.template-applylane (template/reference provided): dynamic constraints + gated execution.
This guide applies only to template-apply.
Dynamic Constraint Sheet (Per Task)
Build a task-specific constraint sheet from template analysis before editing:
topology_constraints: section topology, break positions, anchor regions.frozen_constraints: signature blocks, legal fixed clauses, non-edit zones.derived_constraints: TOC, cross-references, numbering summaries (derived from source content).style_constraints: style IDs and key formatting contracts that must remain stable.
Treat the sheet as runtime contract for gates, not a static prompt checklist.
Mapping-Driven Fill Trigger
Fill/patch mode is allowed only when mapping table is complete.
Generate a scaffold first (do not handcraft from empty file):
python3 <skill-path>/docx_engine.py map-template mapping.json --require R1,R2
A mapping table is complete when:
- every row has
id,requirement_ids,selector,action,status. actionis one ofreplace|delete|insert.statusisresolvedfor all executable rows.replaceandinsertrows contain non-emptytarget_value.- all required requirement IDs are covered by resolved rows.
Use:
python3 <skill-path>/docx_engine.py map-gate mapping.json --require R1,R2
Gate fail means fill/patch mode is blocked.
Mapping Schema Contract
- Canonical schema file:
schemas/mapping.schema.json - Schema version:
minimax-docx.map.v1 - Generate scaffold first:
python3 <skill-path>/docx_engine.py map-template mapping.json --require R1,R2
Model should edit only:
rows[].selectorrows[].actionrows[].target_valuerows[].statusrows[].notes(optional)
Model should keep stable unless requirements change:
schema_versionrequired_requirement_idsrequirements[].idrows[].idrows[].requirement_ids
Mode Decision
map-gate pass-> execute deterministic fill/patch (Python stdlib XML executor):python3 <skill-path>/docx_engine.py map-apply <input.docx> <mapping.json> <output.docx> --require R1,R2.map-gate fail-> do not run fill/patch; either:- request mapping completion, or
- switch to template-apply rebuild mode (still under template constraints).
Forbidden Outcomes
- leaving stale template sample values mixed with new values.
- modifying frozen zones without explicit user instruction.
- preserving stale derived content after source edits.
- shipping output when any dynamic gate fails.