docx-redline v1.0.2
19

The renumbering cascade

Contracts number their clauses in the body text, so a structural change is never one edit. Ask for one move and the planner derives the rest. Numbers are never computed incrementally: after all structural work is done, ClauseTree.renumber() re-derives every number from its position and diffs that against a snapshot taken before anything moved. One pass, so a move that shifts two separate groups of siblings cannot double-count.

examples/19_renumbering_cascade.py — ran in 0.50s · exit 0

Console output

============================================================================
19 · The renumbering cascade
============================================================================

--- one move, nine consequences ---

  move 12.1 after 4.1
    action      AI-001 moved clause 12.1 after 4.1
      12.1 -> 4.2    Governing Law
       4.2 -> 4.3    Auto-Renewal
       4.3 -> 4.4    Termination for Cause
       4.4 -> 4.5    Effect of Termination
      12.2 -> 12.1   Assignment
      12.3 -> 12.2   Force Majeure
      12.4 -> 12.3   Notices
      12.5 -> 12.4   Entire Agreement
      12.6 -> 12.5   Severability
    reference   Section 4.2 -> Section 4.3

--- move to the top of a section — and the citation follows ---

  move 10.3 to the top of section 10
    action      AI-002 moved clause 10.3 to the top of section 10
      10.3 -> 10.1   Excluded Claims
      10.1 -> 10.2   Exclusion of Damages
      10.2 -> 10.3   Liability Cap
    reference   Section 10.2 -> Section 10.3
    reference   SECTION 10.3 -> SECTION 10.1

--- insert pushes later siblings down ---

  insert a definition before 1.1
    action      AI-003 inserted new clause 1.1 (Affiliate)
       1.1 -> 1.2    “Authorized Users” means Customer’s employee
       1.2 -> 1.3    “Customer Data” means all electronic data, t
       1.3 -> 1.4    “Documentation” means Provider’s user guides
       1.4 -> 1.5    “Order Form” means an ordering document spec
       1.5 -> 1.6    “Subscription Term” means the period of Cust
    warning     clause number 1.1 is carried by more than one paragraph; renumbering resolves it, but check the 

--- delete closes the ranks ---

  delete 2.3
    action      AI-004 deleted clause 2.3

--- reorder — only what must move, moves ---

  reorder section 8 as 8.1, 8.3, 8.2
    action      AI-005 reordered section 8: 8.1 -> 8.3 -> 8.2 (1 clause(s) moved, 2 left in place)
       8.3 -> 8.2    Exclusions
       8.2 -> 8.3    Obligations

--- a whole section moves as a unit ---

  move section 11 before section 10
    action      AI-006 moved section 11 before section 10
        11 -> 10     Indemnification
      11.1 -> 10.1   By Provider
      11.2 -> 10.2   By Customer
        10 -> 11     Limitation of Liability
      10.1 -> 11.1   Exclusion of Damages
      10.2 -> 11.2   Liability Cap
      10.3 -> 11.3   Excluded Claims
    reference   Section 10 -> Section 11
    reference   SECTION 10.3 -> SECTION 11.3
    reference   Section 10.2 -> Section 11.2

--- a reference to a deleted clause is flagged, never remapped ---

  delete section 5, which Exhibit B cites
    action      AI-007 deleted section 5 (+3 sub-clause(s))
         6 -> 5      Data Protection and Security
       6.1 -> 5.1    Security Measures
       6.2 -> 5.2    Data Processing Agreement
       6.3 -> 5.3    Security Certifications
       6.4 -> 5.4    Breach Notification
         7 -> 6      Intellectual Property
       7.1 -> 6.1    Provider IP
       7.2 -> 6.2    Customer Data
         8 -> 7      Confidentiality
       8.1 -> 7.1    Definition
       8.2 -> 7.2    Obligations
       8.3 -> 7.3    Exclusions
         9 -> 8      Warranties and Disclaimers
       9.1 -> 8.1    Mutual Warranties
       9.2 -> 8.2    Provider Warranty
       9.3 -> 8.3    Disclaimer
        10 -> 9      Limitation of Liability
      10.1 -> 9.1    Exclusion of Damages
      10.2 -> 9.2    Liability Cap
      10.3 -> 9.3    Excluded Claims
        11 -> 10     Indemnification
      11.1 -> 10.1   By Provider
      11.2 -> 10.2   By Customer
        12 -> 11     General Provisions
      12.1 -> 11.1   Governing Law
      12.2 -> 11.2   Assignment
      12.3 -> 11.3   Force Majeure
      12.4 -> 11.4   Notices
      12.5 -> 11.5   Entire Agreement
      12.6 -> 11.6   Severability
    reference   SECTION 9 -> SECTION 8
    reference   SECTION 10.3 -> SECTION 9.3
    reference   Section 8 -> Section 7
    reference   Section 10.2 -> Section 9.2
    reference   Section 10 -> Section 9

--- editing a clause and then moving it ---

  rewrite 6.4, then move section 6
    action      AI-008 rewrote clause 6.4
    action      AI-009 moved section 6 after section 2
         6 -> 3      Data Protection and Security
       6.1 -> 3.1    Security Measures
       6.2 -> 3.2    Data Processing Agreement
       6.3 -> 3.3    Security Certifications
       6.4 -> 3.4    Breach Notification
         3 -> 4      Fees and Payment
       3.1 -> 4.1    Fees
       3.2 -> 4.2    Invoicing
       3.3 -> 4.3    Late Payment
       3.4 -> 4.4    Taxes
         4 -> 5      Term, Renewal, and Termination
       4.1 -> 5.1    Term
       4.2 -> 5.2    Auto-Renewal
       4.3 -> 5.3    Termination for Cause
       4.4 -> 5.4    Effect of Termination
         5 -> 6      Service Level Agreement
       5.1 -> 6.1    Uptime Commitment
       5.2 -> 6.2    Service Credits
       5.3 -> 6.3    Support
    reference   Section 4.2 -> Section 5.2
    warning     a clause edited earlier in this run was moved: recorded as delete + insert rather than a Word mo
    Word's move revision cannot carry the source's own strikeouts, so this
    is recorded as delete + insert -- exactly as Word's own Compare does it

--- renumber=False turns the whole thing off ---
  0 renumbered, 0 references rewritten
  the clause moves, but the document is left internally inconsistent

--- numbering is derived as the document will read once accepted ---
  after accept, section 2 reads: ['2.1  Gra', '2.2  Res']

--- the saved file keeps the cascade as tracked changes ---
  kinds: ['delete', 'insert', 'move-from', 'move-to']

wrote /tmp/19_renumbering_cascade-b4fmldms/19_renumbering.docx

Source

"""19 · The renumbering cascade.

Contracts number their clauses in the body text, so a structural change is
never one edit. Ask for one move and the planner derives the rest.

Numbers are never computed incrementally: after all structural work is done,
ClauseTree.renumber() re-derives every number from its position and diffs that
against a snapshot taken before anything moved. One pass, so a move that shifts
two separate groups of siblings cannot double-count.
"""

from _shared import banner, fresh, save, section

from docx_redline import apply_actions

banner("19 · The renumbering cascade")


def cascade(title, items):
    rl = fresh()
    report = apply_actions(rl, items)
    print(f"\n  {title}")
    for res in report.results:
        print(f"    action      {res.id} {res.detail}")
    for r in report.renumbered:
        print(f"    {r['from']:>6} -> {r['to']:<6} {r['title'][:44]}")
    for ref in report.references:
        print(f"    reference   {ref['context']}")
    for ref in report.dangling_references:
        print(f"    DANGLING    {ref}")
    for warn in report.warnings:
        print(f"    warning     {warn[:96]}")
    return rl, report


section("one move, nine consequences")
cascade(
    "move 12.1 after 4.1",
    [
        {"id": "AI-001", "type": "move_clause", "clause": "12.1", "after_clause": "4.1"},
    ],
)

section("move to the top of a section — and the citation follows")
cascade(
    "move 10.3 to the top of section 10",
    [
        {
            "id": "AI-002",
            "type": "move_clause",
            "clause": "10.3",
            "into_section": "10",
            "position": "first",
        },
    ],
)

section("insert pushes later siblings down")
cascade(
    "insert a definition before 1.1",
    [
        {
            "id": "AI-003",
            "type": "insert_clause",
            "before_clause": "1.1",
            "title": "Affiliate",
            "text": "“Affiliate” means any entity under common control with a Party.",
        },
    ],
)

section("delete closes the ranks")
cascade("delete 2.3", [{"id": "AI-004", "type": "delete_clause", "clause": "2.3"}])

section("reorder — only what must move, moves")
cascade(
    "reorder section 8 as 8.1, 8.3, 8.2",
    [
        {"id": "AI-005", "type": "reorder_clauses", "section": "8", "order": ["8.1", "8.3", "8.2"]},
    ],
)

section("a whole section moves as a unit")
cascade(
    "move section 11 before section 10",
    [
        {"id": "AI-006", "type": "move_section", "section": "11", "before_section": "10"},
    ],
)

section("a reference to a deleted clause is flagged, never remapped")
cascade(
    "delete section 5, which Exhibit B cites",
    [
        {"id": "AI-007", "type": "delete_section", "section": "5"},
    ],
)

section("editing a clause and then moving it")
rl, report = cascade(
    "rewrite 6.4, then move section 6",
    [
        {
            "id": "AI-008",
            "type": "rewrite_clause",
            "clause": "6.4",
            "text": "Breach Notification. Provider will notify Customer within 48 hours.",
        },
        {"id": "AI-009", "type": "move_section", "section": "6", "after_section": "2"},
    ],
)
print("    Word's move revision cannot carry the source's own strikeouts, so this")
print("    is recorded as delete + insert -- exactly as Word's own Compare does it")

section("renumber=False turns the whole thing off")
rl = fresh()
off = apply_actions(
    rl,
    [{"id": "AI-010", "type": "move_clause", "clause": "12.1", "after_clause": "4.1"}],
    renumber=False,
)
print(f"  {len(off.renumbered)} renumbered, {len(off.references)} references rewritten")
print("  the clause moves, but the document is left internally inconsistent")

section("numbering is derived as the document will read once accepted")
rl = fresh()
apply_actions(rl, [{"id": "AI-011", "type": "delete_clause", "clause": "2.3"}])
rl.accept_all()
print(
    "  after accept, section 2 reads:",
    [rl.text_of(p)[:8] for p in rl.find_paragraphs(regex=r"^2\.\d")],
)

section("the saved file keeps the cascade as tracked changes")
# The section above accepts, which is the point it is making -- but an accepted
# document has no revisions left to look at. Save the move instead, unresolved,
# so the artefact shows the cascade a reviewer would actually open.
rl = fresh()
apply_actions(
    rl, [{"id": "AI-012", "type": "move_clause", "clause": "12.1", "after_clause": "4.1"}]
)
print("  kinds:", sorted({r.kind for r in rl.summary().revisions}))

save(rl, "19_renumbering.docx")

What it wrote

19_renumbering.docx 22 tracked changes Download .docx
delete × 9 insert × 9 move-from × 2 move-to × 2 Outside Counsel (22)

SAMPLE DOCUMENT — FOR TESTING / TEMPLATE PURPOSES ONLY

SOFTWARE LICENSE AND SUBSCRIPTION SERVICES AGREEMENT

Order Form Reference: NSS-2026-00142

This Software License and Subscription Services Agreement (“Agreement”) is entered into as of September 1, 2026 (“Effective Date”) by and between:

Nimbus Software Solutions, Inc., a Delaware corporation with its principal place of business at 400 Market Street, Suite 900, San Francisco, CA 94105 (“Provider”); and

Client Co., Inc., a company organized under the laws of the State of New York with its principal place of business at 88 Lexington Avenue, New York, NY 10016 (“Customer”).

Provider and Customer are each a “Party” and collectively the “Parties.” This Agreement governs Customer’s access to and use of Provider’s cloud-based software platform, “Nimbus Workflow,” together with any related support and professional services (collectively, the “Services”), as further described in one or more Order Forms executed under this Agreement.

1. Definitions

1.1 “Authorized Users” means Customer’s employees and independent contractors who are authorized by Customer to access and use the Services under the rights granted to Customer in this Agreement, subject to the user limits set out in the applicable Order Form.

1.2 “Customer Data” means all electronic data, text, files, or other content submitted to the Services by or on behalf of Customer or its Authorized Users.

1.3 “Documentation” means Provider’s user guides and technical documentation describing the functionality of the Services, as updated from time to time.

1.4 “Order Form” means an ordering document specifying the Services to be provided, executed by both Parties, that references and is governed by this Agreement.

1.5 “Subscription Term” means the period of Customer’s subscription to the Services set forth in the applicable Order Form, together with any renewal terms.

2. License Grant and Restrictions

2.1 Grant of Rights. Subject to the terms of this Agreement and the applicable Order Form, Provider grants Customer a non-exclusive, non-transferable, worldwide right to access and use the Services and Documentation during the Subscription Term, solely for Customer’s internal business operations.

2.2 Restrictions. Customer shall not, and shall not permit any third party to: (a) copy, modify, or create derivative works of the Services; (b) reverse engineer, decompile, or disassemble the Services except to the extent such restriction is prohibited by applicable law; (c) sell, resell, lease, or sublicense the Services to any third party; (d) use the Services to build a competing product; or (e) remove or obscure any proprietary notices.

2.3 Reservation of Rights. Provider reserves all rights not expressly granted to Customer in this Agreement. No rights are granted other than as expressly set forth herein.

3. Fees and Payment

3.1 Fees. Customer shall pay the fees set forth in the applicable Order Form (“Fees”). Unless otherwise specified, Fees are quoted and payable in U.S. dollars.

3.2 Invoicing. Provider shall invoice Customer annually in advance unless a different billing frequency is specified in the Order Form. Payment is due within thirty (30) days of the invoice date.

3.3 Late Payment. Amounts not paid when due shall accrue interest at the lesser of 1.5% per month or the maximum rate permitted by applicable law, and Provider may suspend access to the Services for accounts more than fifteen (15) days past due, upon prior written notice.

3.4 Taxes. Fees are exclusive of applicable taxes, which Customer is responsible for, excluding taxes based on Provider’s net income.

4. Term, Renewal, and Termination

4.1 Term. This Agreement commences on the Effective Date and continues until all Order Forms hereunder have expired or been terminated.

4.2 Governing Law. This Agreement is governed by the laws of the State of Delaware, without regard to its conflict of laws principles.

4.24.3 Auto-Renewal. Each Subscription Term shall automatically renew for successive periods equal to the expiring term, unless either Party provides written notice of non-renewal at least sixty (60) days prior to the end of the then-current Subscription Term.

4.34.4 Termination for Cause. Either Party may terminate this Agreement if the other Party materially breaches this Agreement and fails to cure such breach within thirty (30) days of written notice.

4.44.5 Effect of Termination. Upon expiration or termination, Customer’s right to access the Services immediately ceases. Provider shall make Customer Data available for export for thirty (30) days following termination, after which Provider may delete such data in accordance with its data retention policies.

5. Service Level Agreement

5.1 Uptime Commitment. Provider shall use commercially reasonable efforts to maintain 99.9% monthly uptime for the Services, excluding scheduled maintenance and events of Force Majeure, as detailed in Exhibit B (Service Level Agreement).

5.2 Service Credits. If Provider fails to meet the uptime commitment in a given calendar month, Customer’s sole and exclusive remedy is the service credit set forth in Exhibit B.

5.3 Support. Provider shall provide technical support in accordance with the support tier purchased under the applicable Order Form.

6. Data Protection and Security

6.1 Security Measures. Provider shall maintain administrative, physical, and technical safeguards designed to protect the confidentiality, integrity, and availability of Customer Data, consistent with industry standards.

6.2 Data Processing Agreement. To the extent Provider processes personal data on Customer’s behalf, the Data Processing Addendum attached as Exhibit C is incorporated by reference and shall govern such processing.

6.3 Security Certifications. Provider maintains SOC 2 Type II certification and shall provide Customer with a current copy of its audit report upon written request, no more than once per twelve-month period.

6.4 Breach Notification. Provider shall notify Customer without undue delay, and in no event later than seventy-two (72) hours, after becoming aware of a confirmed security breach affecting Customer Data.

7. Intellectual Property

7.1 Provider IP. Provider retains all right, title, and interest in and to the Services, Documentation, and all related intellectual property rights, including any improvements, enhancements, or feedback incorporated therein.

7.2 Customer Data. As between the Parties, Customer retains all right, title, and interest in and to Customer Data. Customer grants Provider a limited license to host, copy, and process Customer Data solely to provide the Services.

8. Confidentiality

8.1 Definition. “Confidential Information” means non-public information disclosed by one Party to the other that is designated as confidential or that reasonably should be understood to be confidential given the nature of the information and circumstances of disclosure.

8.2 Obligations. The receiving Party shall use the disclosing Party’s Confidential Information solely to perform its obligations under this Agreement and shall protect it using at least the same degree of care it uses for its own confidential information, and no less than a reasonable degree of care.

8.3 Exclusions. Confidential Information does not include information that is or becomes publicly available through no fault of the receiving Party, was rightfully known prior to disclosure, or is independently developed without use of the disclosing Party’s Confidential Information.

9. Warranties and Disclaimers

9.1 Mutual Warranties. Each Party represents that it has the legal power and authority to enter into this Agreement.

9.2 Provider Warranty. Provider warrants that the Services will perform materially in accordance with the Documentation. Customer’s sole remedy for breach of this warranty is prompt correction of the non-conforming Service.

9.3 Disclaimer. EXCEPT AS EXPRESSLY SET FORTH IN THIS SECTION 9, THE SERVICES ARE PROVIDED “AS IS,” AND PROVIDER DISCLAIMS ALL OTHER WARRANTIES, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.

10. Limitation of Liability

10.1 Exclusion of Damages. NEITHER PARTY SHALL BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS OR REVENUE, ARISING OUT OF OR RELATED TO THIS AGREEMENT, REGARDLESS OF THE THEORY OF LIABILITY.

10.2 Liability Cap. EXCEPT FOR EXCLUDED CLAIMS DEFINED IN SECTION 10.3, EACH PARTY’S TOTAL AGGREGATE LIABILITY ARISING OUT OF THIS AGREEMENT SHALL NOT EXCEED THE FEES PAID OR PAYABLE BY CUSTOMER IN THE TWELVE (12) MONTHS PRECEDING THE CLAIM.

10.3 Excluded Claims. The limitations in Section 10.2 shall not apply to: (a) either Party’s indemnification obligations; (b) breach of Section 8 (Confidentiality); (c) Customer’s payment obligations; or (d) either Party’s gross negligence or willful misconduct.

11. Indemnification

11.1 By Provider. Provider shall defend Customer against any third-party claim alleging that the Services infringe such third party’s intellectual property rights, and shall indemnify Customer for damages finally awarded, subject to Section 10.

11.2 By Customer. Customer shall defend and indemnify Provider against any third-party claim arising from Customer Data or Customer’s use of the Services in violation of this Agreement or applicable law.

12. General Provisions

12.1 Governing Law. This Agreement is governed by the laws of the State of Delaware, without regard to its conflict of laws principles.

12.212.1 Assignment. Neither Party may assign this Agreement without the other Party’s prior written consent, except in connection with a merger, acquisition, or sale of substantially all assets.

12.312.2 Force Majeure. Neither Party shall be liable for delays caused by circumstances beyond its reasonable control, including natural disasters, acts of government, or internet or utility failures.

12.412.3 Notices. All notices under this Agreement shall be in writing and delivered to the addresses set forth above, or such other address as a Party may designate in writing.

12.512.4 Entire Agreement. This Agreement, together with all Order Forms and Exhibits, constitutes the entire agreement between the Parties and supersedes all prior agreements relating to its subject matter.

12.612.5 Severability. If any provision of this Agreement is held unenforceable, the remaining provisions shall remain in full force and effect.

Signatures

IN WITNESS WHEREOF, the Parties have executed this Agreement as of the Effective Date.

NIMBUS SOFTWARE SOLUTIONS, INC.

Signature

Date

Name (print)

Title

CLIENT CO., INC.

Signature

Date

Name (print)

Title

Exhibit A — Order Form Summary

The following commercial terms apply to this Order Form and are incorporated into the Agreement by reference.

Subscription: Nimbus Workflow — Business Tier, up to 250 Authorized Users

Subscription Term: 12 months, commencing on the Effective Date, with auto-renewal per Section 4.24.3

Annual Fees: $186,000, payable annually in advance

Support Tier: Premium (24/5 support, 4-hour critical response SLA)

Billing Contact: accounts.payable@clientco.example

Renewal Notice Window: 60 days prior to Subscription Term end date

Exhibit B — Service Level Agreement

Provider commits to the following monthly uptime and remedy schedule for the Services:

Monthly Uptime Commitment: 99.9%

99.0%–99.89% uptime: 5% service credit of monthly Fees

95.0%–98.99% uptime: 10% service credit of monthly Fees

Below 95.0% uptime: 25% service credit of monthly Fees

Service credits must be requested in writing within thirty (30) days of the end of the affected month and will be applied to Customer’s next invoice.

Exhibit C — Data Processing Addendum (Summary)

Where Provider processes personal data on behalf of Customer in the course of providing the Services, the Parties agree that Customer is the data controller and Provider is the data processor, and that Provider shall: process personal data only on documented instructions from Customer; ensure personnel are bound by confidentiality obligations; implement appropriate technical and organizational security measures; assist Customer in responding to data subject requests; and delete or return personal data upon termination of the Services, except as required by applicable law.