# DOCX Modifier Plugin - For AnythingLLM Desktop

A custom agent skill for modifying existing Microsoft Word (.docx) documents.

## Installation

This plugin is **self-contained** - all dependencies are bundled.

### Method 1: Import via UI (Recommended)
1. Use `docx-modifier-bundled.zip` (includes dependencies)
2. In AnythingLLM Desktop: Settings → Agent Skills → Import
3. Upload the zip file
4. Enable the skill

### Method 2: Direct Copy
```bash
# macOS: ~/Library/Application Support/anythingllm-desktop/storage/plugins/agent-skills/
# Windows: %APPDATA%\anythingllm-desktop\storage\plugins\agent-skills\
# Linux: ~/.config/anythingllm-desktop/storage/plugins/agent-skills/

# Copy entire folder (including node_modules!)
cp -r docx-modifier-plugin [STORAGE]/plugins/agent-skills/docx-modifier
```

## What's Included

```
docx-modifier-plugin/
├── plugin.json           # Skill manifest
├── handler.js            # Implementation
├── README.md             # This file
└── node_modules/         # Bundled dependencies
    └── adm-zip/          # ZIP manipulation library
```

**Key**: The `node_modules/` folder must be included - this is how AnythingLLM loads dependencies for custom skills.

## Features

- **Read** - Extract text and metadata from DOCX files
- **Replace Text** - Find and replace text throughout document
- **Append Content** - Add new paragraphs at the end
- **Update Properties** - Modify metadata (title, author, subject, keywords)
- **Add Tables** - Insert tables with custom data

## Configuration

After installation, configure via Settings → Agent Skills → docx-modifier:

- **allowedDirectories** - Comma-separated paths where DOCX files can be accessed
  - macOS example: `/Users/yourname/Documents`
  - Windows example: `C:\Users\YourName\Documents`
  - Linux example: `/home/yourname/Documents`
  
- **outputSuffix** - Suffix for modified files
  - Default: `_modified` (creates `file_modified.docx`)
  - Set empty to overwrite originals (⚠️ destructive)

## Usage Examples

### 1. Read Document
```
"Read the content of /Users/john/Documents/report.docx"
```

### 2. Replace Text (Template Filling)
```
"Replace {{NAME}} with John Doe in /Users/john/Documents/contract.docx"
```

### 3. Append Content
```
"Add '## Conclusion\n\nThis is complete.' to /Users/john/Documents/draft.docx"
```

### 4. Update Metadata
```
"Change the title to 'Final Report' in /Users/john/Documents/draft.docx"
```

### 5. Add Table
```
"Add a table with Product and Price columns to /Users/john/Documents/quote.docx"
```

## How It Works

1. **DOCX = ZIP archive** - Word documents are ZIP files containing XML
2. **adm-zip library** - Extracts/modifies ZIP contents
3. **XML manipulation** - Edits `word/document.xml` and `docProps/core.xml`
4. **Self-contained** - No external dependencies needed

## Technical Details

### Dependencies (Bundled)
- `adm-zip` v0.5.x - ZIP file operations (included in `node_modules/`)
- Node.js built-ins: `fs`, `path`

### Why Bundled Dependencies?
According to AnythingLLM's developer guide:
> "You can bundle any NodeJS package you want within your custom agent skill, but it must be present in the folder structure"

This ensures the plugin works in the Desktop app without requiring users to install anything.

## Security

- Path validation (only allowed directories)
- Tool approval for destructive operations
- XML escaping prevents injection
- No external network calls

## Limitations

- Basic text operations (no advanced formatting)
- Simple table insertion
- No image manipulation
- Preserves existing formatting on replacement

## Troubleshooting

**"Cannot find module 'adm-zip'"**
- Ensure `node_modules/adm-zip/` folder is present
- Re-download the bundled zip

**"Access denied"**
- Add the file's directory to `allowedDirectories`

**"File not found"**
- Use absolute paths (not `~`)
- Check file exists

## Files

- `plugin.json` - Skill manifest
- `handler.js` - Implementation
- `node_modules/adm-zip/` - Bundled dependency
- `README.md` - Documentation

## License

MIT
