ワンクリックで
debug-socketio-connection
调试 Socket.IO 连接问题,特别是 "Document not connected" 错误。当 Add-In 已连接但执行命令时报文档未连接错误时使用此 skill。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
调试 Socket.IO 连接问题,特别是 "Document not connected" 错误。当 Add-In 已连接但执行命令时报文档未连接错误时使用此 skill。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | debug-socketio-connection |
| description | 调试 Socket.IO 连接问题,特别是 "Document not connected" 错误。当 Add-In 已连接但执行命令时报文档未连接错误时使用此 skill。 |
当看到如下错误时,说明 Add-In 与 Server 之间存在 URI 匹配问题:
✅ Add-In 已连接
📝 执行: 获取文档统计...
❌ 获取失败: Document not connected: file:///path/to/doc.docx
核心矛盾:Add-In 确实已连接(日志显示 "Client registered"),但执行命令时却报 "Document not connected"。
这类问题的根本原因是 URI 不匹配。ConnectionManager 使用 document_uri 作为 key 来路由请求,如果注册时和查询时的 URI 不一致,就会找不到连接。
| 场景 | 注册时 URI | 查询时 URI | 原因 |
|---|---|---|---|
| URL 编码 | file:///%2Fvar%2Ffolders%2F... | file:///var/folders/... | Add-In 对路径进行了 URL 编码 |
| 符号链接 | file:///var/folders/... | file:///private/var/folders/... | macOS /var → /private/var |
| 路径格式 | file:////server/share/... | file:///server/share/... | UNC 路径的斜杠数量 |
查看 Add-In 连接时的日志,找到 注册时的 URI:
Client registered: word-client-xxx (socket_id) for <注册URI> on /word
对比 查询时的 URI(错误信息中):
Document not connected: <查询URI>
URI 规范化函数位于 connection_manager.py 的 normalize_document_uri() 函数。
该函数处理:
%2F → /)/var → /private/var)以下方法必须在处理前调用 normalize_document_uri():
register_client() - 注册时规范化get_socket_by_document() - 查询时规范化get_clients_by_document() - 查询时规范化is_document_active() - 查询时规范化参考 test_connection_manager.py 中的 TestNormalizeDocumentUri 类,确保:
def test_lookup_with_different_uri_formats(self, connection_manager):
"""注册和查询使用不同格式的 URI 应该能匹配"""
# 用 URL 编码格式注册
connection_manager.register_client(
"socket1", "client1", "file:///%2Ftmp%2Ftest.docx", "/word"
)
# 用解码格式查询应该能找到
socket_id = connection_manager.get_socket_by_document("file:///tmp/test.docx")
assert socket_id == "socket1"
避免使用系统临时目录(如 /var/folders/),因为可能涉及符号链接。
参考 e2e_base.py 的做法,使用项目内目录:
# 使用项目内目录,避免符号链接问题
TEMP_ROOT = Path(__file__).parent / ".test_working"
确保 URI 生成函数使用 os.path.realpath() 解析符号链接:
def path_to_file_uri(path: Path) -> str:
abs_path = path.resolve() # 解析符号链接
encoded = quote(str(abs_path), safe="/")
return f"file://{encoded}"
测试结束后的清理顺序必须正确,否则会导致长时间等待:
❌ 错误顺序(等待 ~2 分钟):
1. workspace.stop() ← 等待 Socket.IO 连接超时
2. close_document() ← 关闭文档
✅ 正确顺序(~1 秒完成):
1. close_document() ← 先关闭文档,Add-In 自动断开
2. workspace.stop() ← 没有活跃连接,立即完成
原因:Socket.IO 服务器在关闭时会等待所有活跃连接断开或超时。如果先关闭服务器,而文档还开着(Add-In 还连接着),就会等待 ping 超时(默认 60-120 秒)。
参考 e2e_base.py 中 run_with_workspace 的 finally 块实现。
执行 Office4AI MCP Server 验收测试 —— Phase 1 注册验收(tools/resources/收敛) + Phase 2 功能验收(manual_test E2E)
Edit an existing Word / PowerPoint / Excel file — especially template operations (fill {{placeholders}} and SDT content controls, reuse slide masters, change spreadsheet data while preserving charts) — by submitting a short Python script to the office4ai `office_run_script` tool. Works with no Office Add-In connection. Use when the user asks to fill a template, update a report/deck/workbook, replace placeholders, or edit a .docx / .pptx / .xlsx while keeping its styling intact.
Extract a reusable template from a reference Word / PowerPoint / Excel file — turn concrete values into placeholders — by submitting a short Python script to the office4ai `office_run_script` tool. Word headings become named SDT content controls, concrete text becomes {{tokens}} for docxtpl, a designed slide becomes a reusable master layout, an Excel named range becomes a blanked template region. Works with no Office Add-In connection. Use when the user has a finished/reference document but no template, and wants to reuse its structure/branding to generate more files.
Create Word / PowerPoint / Excel files from scratch or from a reusable template by submitting a short Python script to the office4ai `office_run_script` tool. Works with no Office Add-In connection. Use when the user asks to generate a .docx / .pptx / .xlsx, produce a report / deck / workbook, or instantiate a corporate template.
Demo authoring SKILL fixture — exercises the skill:// resources source mode (root + scripts + references + binary asset). Triggers in S3 producer tests only.
以架构师视角审查代码变更,关注模块边界、DTO 规范、测试完整性和长期可维护性。 当需要审查 PR、工作区变更或提交代码时使用。