| 技能 | 配置方式 | 自動偵測 | 版本 |
|---|---|---|---|
| upload-html | .wb-config.json | ✅ 自動搜尋 ./ ../ ../.. | v3.0 |
| updatememo | .wb-config.json | ✅ 自動搜尋 ./ ../ ../.. | v2.0 |
| updatesk | .wb-config.json | ✅ 自動搜尋 ./ ../ ../.. | v2.0 |
| merge-docx | ❌ Hardcode | ❌ 需手動指定 | v1.0 |
| 欄位 | 說明 | 預設值 |
|---|---|---|
| project | 專案名稱 | aiworkforme |
| docx.source | 構想來源檔(ideatorich.docx) | ideatorich.docx |
| docx.target | 目標主檔(aiworkforme.docx) | aiworkforme.docx |
| docx.outputDir | 輸出目錄 | 同 docx.source 位置 |
| docx.outputPrefix | 輸出檔前綴 | aiworkforme_v |
{
"project": "aiworkforme",
"docx": {
"source": "ideatorich.docx",
"target": "aiworkforme.docx",
"outputDir": "C:\\Users\\Administrator\\WorkBuddy\\工作備忘",
"outputPrefix": "aiworkforme_v"
}
}
{
"project": "aiworkforme",
"docx": {
"source": "ideatorich.docx",
"target": "aiworkforme.docx",
"outputDir": "C:\\Users\\Administrator\\WorkBuddy\\工作備忘"
}
}
{
"project": "aiworkforme-student",
"docx": {
"source": "my-ideas.docx",
"target": "aiworkforme-練習.docx",
"outputDir": "C:\\Users\\Administrator\\Documents\\AiWorkForMe"
}
}
.wb-config.json| 觸發方式 | 說明 | 自動化程度 |
|---|---|---|
| 「執行 merge-docx」 | 直接執行,使用配置檔自動偵測 | ★★★ 完全自動 |
| 「合併構想進文檔」 | 自然語言觸發 | ★★★ 完全自動 |
| 「合併到 aiworkforme」 | 手動指定目標 | ★ 需確認 |
import docx
import os
import json
from datetime import datetime
def find_config():
"""自動偵測 .wb-config.json"""
search_paths = ['.', '..', '../..']
for path in search_paths:
config_path = os.path.join(path, '.wb-config.json')
if os.path.exists(config_path):
with open(config_path, 'r', encoding='utf-8') as f:
return json.load(f)
return None # 使用預設值
def merge_docx(config):
"""合併 docx"""
# 讀取配置
source = config['docx']['source']
target = config['docx']['target']
output_dir = config['docx']['outputDir']
# 讀取源文檔(ideatorich)
source_doc = docx.Document(source)
# 讀取目標文檔(aiworkforme)
target_doc = docx.Document(target)
# 分析源文檔結構
sections = parse_sections(source_doc)
# 合併到目標
changes = merge_to_target(target_doc, sections)
# 版本化輸出
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_file = f"{config['docx']['outputPrefix']}{timestamp}.docx"
output_path = os.path.join(output_dir, output_file)
target_doc.save(output_path)
return output_path, changes
def parse_sections(doc):
"""解析章節結構"""
sections = []
current = None
content = []
for para in doc.paragraphs:
if para.style.name.startswith('Heading'):
if current:
sections.append({'title': current, 'content': content})
current = para.text
content = []
elif current:
content.append(para.text)
if current:
sections.append({'title': current, 'content': content})
return sections
def merge_to_target(doc, sections):
"""合併章節到目標文檔"""
changes = []
for section in sections:
# 找對應位置
pos = find_section_position(doc, section['title'])
if pos:
changes.append(f"替換:{section['title']}")
else:
changes.append(f"新增:{section['title']}")
# 執行合併(新增或替換)
return changes