{“content”:”---\nname: custom-cli-builder\ndescription: 手工打造自訂 CLI 工具的方法論,適用於任何軟體。inspired by CLI-Anything但不需要 Codex/Claude Code。分析目標軟體的 API 或底層介面,設計並實作 CLI 封裝。當你需要為某個軟體建立 CLI 工具時加載此技能。\nversion: 1.0.0\nauthor: Hermes\nlicense: MIT\nmetadata:\n hermes:\n tags: [cli, tool-building, automation, scripting]\n trigger: “需要為某軟體建立 CLI 工具時”\n---\n\n# Custom CLI Builder\n\n## 核心方法論\n\ninspired by CLI-Anything,但純手工,不需要 Codex/Claude Code。\n\n步驟:\n1. 分析介面 — 找出目標軟體的 API / 底層介面(REST API、local executable、IPC)\n2. 設計命令 — 根據常見操作設計 CLI 命令格式\n3. 實作封裝 — 用 Python/Shell 封裝成可安裝的工具\n4. 驗證 — 實際操作確認可用\n\n## 目標介面類型\n\n### REST API(最常見)\n- Obsidian Local REST API: http://localhost:19789\n- Paperclip: http://localhost:9120\n- OpenClaw Gateway: http://localhost:18791\n\n### 命令列工具\n- ssh, curl, git 等通用工具\n- 軟體自帶的 CLI\n\n### Windows 專用\n- powershell -Command \"...\"\n- Get-ChildItem, Get-Content, Set-Content\n- Start-Process -Wait\n\n## 專案結構\n\n\n<software>-cli/\n├── <software>_cli.py # Click CLI 主程式\n├── core/\n│ └── <software>_api.py # API 封裝\n├── utils/\n│ └── <software>_backend.py # 後端實作\n├── setup.py\n└── README.md\n\n\n## Click CLI 模板\n\npython\nimport click\nimport requests\n\nAPI_BASE = \"http://localhost:PORT\"\n\n@click.group()\ndef cli():\n \"\"\"<software> CLI\"\"\"\n pass\n\n@cli.command()\n@click.argument(\"path\", default=\"\")\ndef list(path):\n \"\"\"List vault files\"\"\"\n r = requests.get(f\"{API_BASE}/vault/{path}\")\n click.echo(r.json())\n\n@cli.command()\n@click.argument(\"path\")\ndef read(path):\n \"\"\"Read a file\"\"\"\n r = requests.get(f\"{API_BASE}/vault/{path}\")\n click.echo(r.text)\n\n@cli.command()\n@click.argument(\"path\")\n@click.argument(\"content\")\ndef write(path, content):\n \"\"\"Write a file\"\"\"\n r = requests.post(f\"{API_BASE}/vault/{path}\", data=content)\n click.echo(f\"Status: {r.status_code}\")\n\nif __name__ == \"__main__\":\n cli()\n\n\n## SSH 遠端執行\n\n當需要對 PC 執行 Windows 命令時:\nbash\nssh -i ~/.ssh/id_ed25519 sozo@100.83.112.84 \"powershell -Command \\\"...\\\"\"\n\n\n常見 Windows 檔案操作:\nbash\n# 列出目錄\nssh ... \"dir \\\"PATH\\\\subfolder\\\" /b\"\n\n# 讀取檔案\nssh ... \"type \\\"PATH\\\\file.md\\\"\"\n\n# 寫入檔案(含空格 + UTF-8 路徑)\n# 注意:SSH 到 Windows 時不能用 `type file`(不識別)\n# ✅ 成功方法:用 pipe + PowerShell $input\nssh ... \"cat > /tmp/source.md\" # 先在本地准備檔案\ncat /local/file.md | ssh ... \"powershell -Command \\\"\\$input | Out-File -FilePath 'PATH\\\\file.md' -Encoding UTF8\\\"\"\n\n# ✅ 讀取檔案\nssh ... \"powershell -Command \\\"Get-Content 'PATH\\\\file.md' -Encoding UTF8\\\"\"\n\n# 檢查目錄是否存在\nssh ... \"if exist \\\"PATH\\\" (echo EXISTS) else (echo MISSING)\"\n\n\n## 安裝方式\n\nbash\npip install -e .\n# 或\npython setup.py develop\n\n\n## 已知 CLI 專案\n\n### Obsidian CLI ✅ 已建立\n- vault 路徑: H:\My Drive\Jakephone\Obsidian Vault (Google Drive 本地掛載)\n- API: Obsidian Local REST API (localhost:19789)\n- 狀態: 工具完成,待用戶確認 Obsidian 執行中\n- 安裝: pip install -e ~/.hermes/skills/productivity/obsidian-cli/\n- 入口: python3 ~/.hermes/skills/productivity/obsidian-cli/obsidian_cli.py\n\n### Obsidian CLI 注意事項(實踐發現)\n- 插件需在 Obsidian 內「啟用」,社群插件列表看到「已啟用」才算數\n- API 只在 Obsidian 執行時監聽 port 19789\n- vault 路徑含空格 + 中文,需用 URL encode 或 PowerShell 處理\n- curl 直接測試可能 timeout,改用 requests 或 ssh powershell test-netconnection\n”}