課題
Visual Studio CodeでDev Containers環境を利用し、GitHub Copilot Agentモードでタスクを実行した場合に、いつ完了したか分からないので他の作業に集中できず、生産性が上がらない。
解決策
タスク完了時に、Macデスクトップ通知スクリプトを実行するように指示しておく
方法
ローカルのターミナルで以下を実行し、コマンドが通るか確認する。
osascript -e 'display notification "test message" with title "test title"'
Macの設定から、スクリプトエディタを選択して、通知を有効にする。
試験的な機能ですが、Visual Studio CodeでAuto Approveを有効にする
{
"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(`ここにメッセージを記載すること`)')"`
これでタスク完了時に通知コマンドを発行して、デスクトップに通知されるようになります。
Q&A
なんでわざわざサーバを立てるの?
コンテナ環境からホストコマンドを叩くのを迂回するために、できるだけ疎結合にした構成を選んでいます
なんでAuto Approveが必要なの?
これがないと、通知コマンドを叩くための許可を求めてくるので。
Mac設定画面にスクリプトエディタが出ないんだけど
一度ローカルでコマンド実行してみてください。通知の実績を作らないと出てこないみたいです。
他にやり方ないの?