使用方法
- 复制安装命令,在自己的智能体环境安装前先检查源码包。
- 从原始文档核对所需工具、凭据和支持的宿主。
- 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/mskadu/opencode-agent-skills --skill ollama-sync开始前需了解
- 安装不包含模型订阅、API 额度或访问文件的权限。
- 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。
Ollama Model Synchronizer
Your Task
When asked to synchronize the local Ollama configuration, your primary goal is to ensure that the model list in the opencode.json file is an accurate reflection of the models available on the host system.
The process must involve three main steps:
- Fetch Live List: Execute
ollama listvia the bash tool to retrieve all currently available model names and tags on the machine. - Parse and Extract: Parse the output of
ollama listto extract only the clean list of model names (e.g.,llama2,mistral). - Update Config: Use the
edittool to replace the existing model list inopencode.json(specifically theollamaprovider section) with the newly fetched, accurate list.
Workflow Details
- Primary Command Execution:
- Run
ollama listusing thebashtool.
- Parsing Logic (Internal):
- The output of
ollama listneeds to be parsed to isolate model names. Assume the output format is reliable enough to grep for model names.
- File Manipulation:
- Use the
readtool onopencode.jsonto understand the current structure. - Use the
edittool to modify the specific section containing the model list.
Step-by-step Logic
- Check Dependency: Confirm if the
ollamacommand is available in the execution environment. - Get System Models: Execute
ollama listto get the current list of models. - Isolate Names: Programmatically parse the output to create a comma-separated string of model names.
- Write Back: Use the
edittool to replace the old model list with the new comma-separated list inopencode.json.
Examples & Edge Cases
- Empty List: If
ollama listreturns no models, theopencode.jsonmodel list should be cleared or set to an empty array, and the user should be warned. - Error Handling: If the
ollamacommand fails or is not found, the process must stop, and the user should be informed that the synchronization failed due to environment issues.
Target File Structure (Conceptual)
The target file is opencode.json. The relevant section looks like this (structure for context):
"providers": {
"ollama": {
"models": ["model-a", "model-b", "model-c"], // <-- This list must be updated
"base_url": "http://localhost:11434"
},
// ... other providers
}Always prioritize using the bash tool for OS interactions (ollama list) and the edit tool for configuration management.




