# macOS MEDIA Protocol — Gateway Initialization Issue
# macOS — Gateway Initialization & MEDIA Protocol
> **Source:** conversation about file delivery on macOS (2026-07-22)
> **Symptom:** MEDIA paths returned as plain text instead of files, even after correct path and cache directory setup
## Problem Description
When using the MEDIA protocol on macOS after a gateway restart, the MEDIA directive is not being parsed by the gateway. Instead of sending the file as an attachment, the gateway returns the literal text `MEDIA:/path/to/file` to the user.
## Reproduction Steps
1. File exists in cache directory: `~/.hermes/cache/documents/test.md`
3. User receives plain text instead of downloadable file
4. Gateway logs show no MEDIA-related entries
5. Restart gateway with `hermes gateway restart`
6. MEDIA protocol starts working correctly
After a gateway restart, the MEDIA directive may not be parsed correctly. Instead of sending the file as an attachment, the gateway returns the literal text `MEDIA:/path/to/file` to the user.
## Root Cause
The MEDIA protocol parser in the gateway may not be fully initialized after a session starts or after a gateway restart. This appears to be a timing/initialization issue specific to the macOS gateway implementation.
The MEDIA protocol parser in the gateway may not be fully initialized after a session starts or after a gateway restart. This appears to be a timing/initialization issue.
## Detailed Diagnostic Steps
## Diagnostic Steps
1.**Verify file exists in cache directory**:
```bash
...
...
@@ -42,12 +33,7 @@ The MEDIA protocol parser in the gateway may not be fully initialized after a se
tail -100 ~/.hermes/logs/gateway.error.log
```
5. **Inspect `extract_media()` implementation**(located at `gateway/platforms/base.py:3605`):
- Uses `MEDIA_TAG_CLEANUP_RE` to extract tags
- Validates paths with `validate_media_delivery_path()`
- Masks protected regions (code blocks, inline code, blockquotes)
6. **Verify configuration**:
5. **Verify configuration**:
```bash
grep-r"MEDIA\|media" ~/.hermes/config.yaml
```
...
...
@@ -60,7 +46,7 @@ The MEDIA protocol parser in the gateway may not be fully initialized after a se
hermes gateway restart
sleep 10
```
3. **Verify gateway is ready** by checking worker status:
3. **Verify gateway is ready**:
```bash
hermes worker status
```
...
...
@@ -68,12 +54,14 @@ The MEDIA protocol parser in the gateway may not be fully initialized after a se
## Key Code Paths
- **MEDIA tag extraction**: `gateway/platforms/base.py:extract_media()`(line 3605)
# Windows MEDIA Protocol — Reproduction & Debugging
# Windows MEDIA Protocol — Path Debugging
> **Source:** conversation about file delivery issues on Windows/Linux (2026-07-15, 2026-07-22)
> **Symptoms:**
> - Windows: "Skipping unsafe MEDIA directive path"
> - Linux/Windows: Chinese filename files fail to download via Markdown links
## Issue 1: Windows Path Format (Path.resolve() Quirk)
### Reproduction Steps
### Root Cause
1. File created at `C:\Users\Administrator\markdown-test.md`
2. Sent `MEDIA:/c/Users/Administrator/markdown-test.md` — **rejected**
3. Copied to `/tmp/markdown-test.md`, sent `MEDIA:/tmp/markdown-test.md` — **rejected** (not in cache dir)
4. Copied to `~/.hermes/cache/documents/markdown-test.md`, sent `MEDIA:/c/Users/Administrator/.hermes/cache/documents/markdown-test.md` — **rejected**
5. Finally determined via log inspection that Python's `Path.resolve()` on Windows treats `/c/Users/` as a **relative path** (`\c\Users\...` off C: drive)
Python's `Path.resolve(strict=True)` on Windows treats `/c/Users/...` as a **relative** path (`\c\Users\...` off the current C: drive), not an absolute one. This causes the file to be reported as nonexistent and skipped as "unsafe".
### Key Log Output
### Correct vs Incorrect Paths (Windows)
```
WARNING gateway.platforms.base: Skipping unsafe MEDIA directive path: /c/Users/Administrator/some-file.md
```
| Format | Terminal (bash) | Python/Validation | Works? |
└─ 都不匹配 → 抛出 "File is outside the session and Hermes workspaces"
```
Hermes enforces that files must be within the **session workspace** for Markdown link delivery. Even though `~/.hermes/cache/` directories are listed as "safe roots" for MEDIA protocol, the **Markdown link delivery** path has stricter restrictions that only allow files within the **active session's workspace**.
### 允许的根目录
**Key point**: The workspace is the session-specific working directory (which may be `~/.hermes/workspace/` or another path configured for the session), NOT necessarily the default `~/.hermes/workspace/`.
1.**Always prefer workspace directory** for files you want to send via Markdown links
2.**For Chinese filenames, always use angle brackets**: `](</path/文件.md>)`
3.**When in doubt, use base64** — it works everywhere and bypasses all path restrictions
4.**For large files**, consider base64 or direct content display
5.**Test file delivery early** in a session to confirm behavior
## Related Issues
- Windows path format: Use `C:/...` not `/c/...` (see `windows-media-path-debugging.md`)
- Chinese filename parsing: Always use angle brackets
- MEDIA protocol initialization: May require gateway restart (see `macos-gateway-media-issue.md`)
- Cache directory restrictions: Not all "safe roots" work for Markdown links
2.**尝试 MEDIA 协议**:绕过 workspace 限制
## Key Takeaway
3.**拷贝到 workspace** 后重试
**Hermes security policy restricts Markdown file links to the session's workspace directory only. Files in `~/.hermes/cache/` directories will fail with "File is outside the session and Hermes workspaces" error, regardless of deployment platform.**
---
The workspace is the **session-specific working directory**, which may be:
- Default: `~/.hermes/workspace/`
- Custom: Configured per session via `workdir` parameter
## 相关文档
Use one of these alternatives:
1. Copy file to the session workspace (preferred for small/medium files)
2. Use base64 encoding (works for any file, any location)
3. Display content directly (for small files)
-[SKILL.md](../SKILL.md) — 主技能文档
-[windows-media-path-debugging.md](windows-media-path-debugging.md) — Windows 路径格式问题