Codumentor logo Codumentor

Document Editor Plugin

The Document Editor plugin provides DOCX document editing tools via a dynamic tool-injection pattern. When the user asks the agent to edit a document, doc_open loads the file and conditionally injects a full suite of editing tools into the LLM's available tool set.

Overview

The Document Editor plugin:

  1. Always registers a doc_open tool so the agent can open DOCX files
  2. When a document is opened, injects 13 editing tools (read, search, replace, table editing, etc.)
  3. When the document is closed, removes the editing tools from the tool set
  4. Provides a download endpoint so users can retrieve edited documents via the UI
  5. Emits UI events for transcript cards (e.g., file-saved notifications)

Configuration

Basic Configuration

plugins:
  - module: codumentor.plugins.doc_editor
    class: DocEditorPlugin
    args:
      enabled: true
      target_agents: "main"  # "main", "subagent", or "all" (default: "main")

Configuration Parameters

Tool Reference

Always Available

ToolDescription
doc_openOpen a DOCX file for editing. Triggers injection of editing tools.

Injected When Document Is Open

ToolDescription
doc_read_structureRead the document's paragraph/heading structure
doc_read_sectionRead content of a specific section
doc_searchSearch for text within the document
doc_replace_textReplace text content
doc_insert_paragraphInsert a new paragraph
doc_delete_paragraphDelete a paragraph
doc_list_tablesList all tables in the document
doc_edit_table_cellEdit a specific table cell
doc_read_headers_footersRead headers and footers
doc_set_propertySet document properties (title, author, etc.)
doc_pythonExecute arbitrary python-docx code for advanced edits
doc_saveSave the document (emits plugin.doc_editor.file_saved UI event)
doc_closeClose the document and remove editing tools

How It Works

Tool Injection Pattern

The plugin uses the onPromptAssemble hook (priority 10) to dynamically manage tools:

  1. Before every LLM call, the hook checks whether the current session has an open document
  2. If no document is open: only doc_open is in the tool list
  3. When doc_open is called: the plugin records the session as having an open document
  4. On the next LLM turn: onPromptAssemble sees the open session and injects all 13 editing tools
  5. When doc_close is called: the session is cleared and editing tools are removed on the next turn

This pattern keeps the tool set clean — the LLM only sees editing tools when they are relevant.

Session State

UI Integration

The plugin provides:

Example Interaction

User: Open the report.docx file and update the title to "Q4 Summary"

Agent calls: doc_open(path="report.docx")
  → Plugin state: session marked as open, editing tools injected

Agent calls: doc_read_structure()
  → Returns document outline with headings and paragraphs

Agent calls: doc_replace_text(old="Q3 Report", new="Q4 Summary")
  → Text replaced in document

Agent calls: doc_save()
  → Document saved, UI shows file-saved card with download link

Agent calls: doc_close()
  → Plugin state: session cleared, editing tools removed

Testing

Run the document editor tests with:

python -m unittest tests.test_doc_editor_plugin -v