Documentation
¶
Overview ¶
Package docx provides find/replace editing for DOCX documents: the write-side counterpart to internal/officetext's native DOCX read support, the same relationship internal/tools/files/excel has to XLSX. A DOCX body is just WordprocessingML XML in a zip - not something write_file/edit_file can touch (they'd corrupt the zip treating it as UTF-8 text) - so this pretty-prints word/document.xml into readable, addressable text, reuses edit_file's own exact-match/fuzzy-match/diff engine (internal/tools/files/edit) against that pretty-printed text, then compacts and repacks the result. Modeled on DesktopCommanderMCP's docx.ts, which uses the same pretty-print/compact round-trip.
Index ¶
- Constants
- type Tool
- func (t *Tool) BackfillInput(_ context.Context, input map[string]any) map[string]any
- func (t *Tool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)
- func (t *Tool) CheckPermissions(_ context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
- func (t *Tool) Definition() tool.Definition
- func (t *Tool) Description(_ context.Context) (string, error)
- func (t *Tool) FormatResult(data any) string
- func (t *Tool) IsConcurrencySafe(_ map[string]any) bool
- func (t *Tool) IsEnabled() bool
- func (t *Tool) IsReadOnly(_ map[string]any) bool
- func (t *Tool) ValidateInput(_ context.Context, input map[string]any) (map[string]any, error)
Constants ¶
const ( // ToolName is the name of the DOCX edit tool. ToolName = "docx_edit" // SearchHint is a hint for tool search functionality. SearchHint = "create or find/replace edit a Word (.docx) document" // ToolDescription is the description of the docx_edit tool. ToolDescription = "Create a new Word (.docx) document, or find/replace edit an existing one's text.\n\n" + "## When to use\n\n" + "- Creating a new .docx from plain text — omit old_string; new_string becomes the document body (lines starting with \"#\".. \"######\" become headings, blank lines become paragraph breaks)\n" + "- Editing text in an existing .docx — provide old_string (the exact text to find) and new_string (its replacement), same as FileEdit\n\n" + "## When NOT to use\n\n" + "- Reading .docx content — use FileRead instead (extracts it natively, no need to write anything first)\n" + "- Complex formatting, images, or tables — this only handles plain paragraph/heading text\n\n" + "## Rules\n\n" + "- Same read-before-edit rule as FileEdit: an existing file must have been read with FileRead first.\n" + "- old_string must match a run of actual document text exactly (or closely — a fuzzy fallback with a diff kicks in if the exact match fails, same as FileEdit).\n" + "- Set replace_all if old_string appears more than once and you want every occurrence replaced.\n" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool implements the docx_edit tool.
func (*Tool) BackfillInput ¶
func (*Tool) Call ¶
func (t *Tool) Call( ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn, ) (tool.CallResult, error)
func (*Tool) CheckPermissions ¶
func (t *Tool) CheckPermissions(_ context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
func (*Tool) Definition ¶
func (t *Tool) Definition() tool.Definition