facebook twitter hatena line email

「AI/OpenCode/インストール」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(macにインストール)
(権限エラーが出る場合)
 
(同じ利用者による、間の4版が非表示)
行7: 行7:
 
cd project1
 
cd project1
 
</pre>
 
</pre>
 +
 +
===Aiエンジンを選択===
 +
[[Mac/インストール/ollama]] [ショートカット]
 +
 +
oss-gpt用のopencode.jsonを作成
 +
 +
<pre>
 +
//gpt-oss-120b用
 +
{
 +
  "$schema": "https://opencode.ai/config.json",
 +
 +
  "provider": {
 +
    "ollama": {
 +
      "npm": "@ai-sdk/openai-compatible",
 +
      "name": "Ollama (local)",
 +
      "options": {
 +
        "baseURL": "http://localhost:11434/v1"
 +
      },
 +
      "models": {
 +
        "gpt-oss:120b": { "name": "gpt-oss 120B (local)" }
 +
      }
 +
    }
 +
  },
 +
 +
  "model": "ollama/gpt-oss:120b",
 +
 +
  "agent": {
 +
    "build": {
 +
      "description": "Default coding mode with only OpenCode tools.",
 +
      "tools": {
 +
        "read": true,
 +
        "write": true,
 +
        "edit": true,
 +
        "bash": true,
 +
        "grep": true,
 +
        "glob": true,
 +
        "list": true,
 +
        "webfetch": true,
 +
        "patch": true,
 +
        "todoread": true,
 +
        "todowrite": true
 +
      },
 +
      "prompt": "{file:./AGENTS.md}"
 +
    }
 +
  },
 +
 +
  "instructions": ["AGENTS.md"]
 +
}
 +
</pre>
 +
 +
===ツール使用ルール===
 +
AGENTS.md
 +
<pre>
 +
# Tooling rules for OpenCode
 +
- Use OpenCode tools only: read, write, edit, list, glob, grep, webfetch, bash, task, todowrite, todoread.
 +
- Do NOT call non-existent tools like Repo_browser.* .
 +
- Prefer `edit` for modifying existing files; use `read` to inspect before editing.
 +
</pre>
 +
 +
AGENTS.mdの意味
 +
<pre>
 +
ツール名 用途
 +
read ファイルの内容を読む
 +
write 新しいファイルを作成する/上書きする
 +
edit 既存ファイルを部分的に修正する(差分更新)
 +
list ディレクトリ内のファイル一覧を取得
 +
glob パターンにマッチするファイルを検索 (*.md など)
 +
grep テキスト検索を行う
 +
webfetch URLからファイルやデータを取得
 +
bash シェルコマンドを実行
 +
task 特定のビルドや自動処理を実行(タスクランナー)
 +
todowrite / todoread TODOリストに関する読み書き操作
 +
</pre>
 +
 +
===opencode起動===
 +
<pre>
 +
opencode
 +
</pre>
 +
 +
===権限エラーが出る場合===
 +
権限変更する
 +
sudo chown  hoge:staff /Users/hoge1/.local/state
 +
 +
===日本語がおかしい===
 +
2バイト文字の幅がおかしい。
  
 
==参考==
 
==参考==

2026年3月10日 (火) 09:02時点における最新版

macにインストール

brew install sst/tap/opencode

サンプル

mkdir project1
cd project1

Aiエンジンを選択

Mac/インストール/ollama [ショートカット]

oss-gpt用のopencode.jsonを作成

//gpt-oss-120b用
{
  "$schema": "https://opencode.ai/config.json",

  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "gpt-oss:120b": { "name": "gpt-oss 120B (local)" }
      }
    }
  },

  "model": "ollama/gpt-oss:120b",

  "agent": {
    "build": {
      "description": "Default coding mode with only OpenCode tools.",
      "tools": {
        "read": true,
        "write": true,
        "edit": true,
        "bash": true,
        "grep": true,
        "glob": true,
        "list": true,
        "webfetch": true,
        "patch": true,
        "todoread": true,
        "todowrite": true
      },
      "prompt": "{file:./AGENTS.md}"
    }
  },

  "instructions": ["AGENTS.md"]
}

ツール使用ルール

AGENTS.md

# Tooling rules for OpenCode
- Use OpenCode tools only: read, write, edit, list, glob, grep, webfetch, bash, task, todowrite, todoread.
- Do NOT call non-existent tools like Repo_browser.* .
- Prefer `edit` for modifying existing files; use `read` to inspect before editing.

AGENTS.mdの意味

ツール名	用途
read	ファイルの内容を読む
write	新しいファイルを作成する/上書きする
edit	既存ファイルを部分的に修正する(差分更新)
list	ディレクトリ内のファイル一覧を取得
glob	パターンにマッチするファイルを検索 (*.md など)
grep	テキスト検索を行う
webfetch	URLからファイルやデータを取得
bash	シェルコマンドを実行
task	特定のビルドや自動処理を実行(タスクランナー)
todowrite / todoread	TODOリストに関する読み書き操作

opencode起動

opencode

権限エラーが出る場合

権限変更する

sudo chown  hoge:staff /Users/hoge1/.local/state

日本語がおかしい

2バイト文字の幅がおかしい。

参考

gpt-oss × opencode × vibe kanban https://zenn.dev/y_ta/articles/gpt-oss-opencode-vibe-kanban-tutorial

gpt-ossを使って無料でAIエージェントを使えるコーディング環境を構築する https://zenn.dev/is0383kk/articles/460e87170f3e7e