0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dev Containers環境のGitHub Copilot Agentモードの完了通知をMacデスクトップに表示する

Last updated at Posted at 2025-07-01

課題

Visual Studio CodeでDev Containers環境を利用し、GitHub Copilot Agentモードでタスクを実行した場合に、いつ完了したか分からないので他の作業に集中できず、生産性が上がらない。

解決策

タスク完了時に、Macデスクトップ通知スクリプトを実行するように指示しておく

方法

ローカルのターミナルで以下を実行し、コマンドが通るか確認する。

osascript -e 'display notification "test message" with title "test title"'

image.png

Macの設定から、スクリプトエディタを選択して、通知を有効にする。
SCR-20250701-keef.png

試験的な機能ですが、Visual Studio CodeでAuto Approveを有効にする
SCR-20250701-khqg.png

例. hoge.code-workspace
{
	"settings": {
		"chat.tools.autoApprove": true
	}
}

以下のサーバファイルnotify-server.jsをローカルに作成する

// notify-server.js
const http = require('http');
const { exec } = require('child_process');
const port = 8100;

const server = http.createServer((req, res) => {
  const url = new URL(req.url, `http://${req.headers.host}`);

  if (url.pathname === '/notify') {
    const title = url.searchParams.get('title') || '通知がありました';
    const message = url.searchParams.get('message') || '';

    exec(`osascript -e 'display notification "${message}" with title "${title}"'`);

    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('OK\n');
  } else {
    res.writeHead(404);
    res.end();
  }
});

server.listen(port, () => {
  console.log(`通知サーバーがポート${port}で待機中...`);
});

ローカルでサーバを起動する

nohup node notify-server.js &

Dev Containersのターミナルから、以下を実行して、テストする。

curl "http://host.docker.internal:8100/notify?title=GitHub%20Copilot&message=$(node -p 'encodeURIComponent(`ここにメッセージを記載すること`)')"

.github/copilot-instructions.mdに以下を書く

- 実行が完了した時質問がある時許可が必要な時は以下のコマンドを実行すること
    - `curl "http://host.docker.internal:8100/notify?title=GitHub%20Copilot&message=$(node -p 'encodeURIComponent(`ここにメッセージを記載すること`)')"`

これでタスク完了時に通知コマンドを発行して、デスクトップに通知されるようになります。

SCR-20250701-kgtf.png

Q&A

なんでわざわざサーバを立てるの?

コンテナ環境からホストコマンドを叩くのを迂回するために、できるだけ疎結合にした構成を選んでいます

なんでAuto Approveが必要なの?

これがないと、通知コマンドを叩くための許可を求めてくるので。

Mac設定画面にスクリプトエディタが出ないんだけど

一度ローカルでコマンド実行してみてください。通知の実績を作らないと出てこないみたいです。

他にやり方ないの?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?