【AI協調開発研究】 - AI二重化モデルの学術論文draft完成(workshop_paper_draft.md) - 「隠れた危機」分析とbirthの原則哲学化 - TyEnv「唯一の真実」協調会話を保存・研究資料に統合 - papers管理構造の整備(wip/under-review/published分離) 【Phase 10.9-β HostCall進捗】 - JitConfigBox: relax_numeric フラグ追加(i64→f64コアーション制御) - HostcallRegistryBox: 署名検証・白黒リスト・コアーション対応 - JitHostcallRegistryBox: Nyash側レジストリ操作API - Lower統合: env直読 → jit::config::current() 参照に統一 - 数値緩和設定: NYASH_JIT_HOSTCALL_RELAX_NUMERIC/Config.set_flag 【検証サンプル拡充】 - math.sin/cos/abs/min/max 関数スタイル(examples/jit_math_function_style_*.nyash) - 境界ケース: 署名不一致・コアーション許可・mutating拒否サンプル - E2E実証: String.length→allow, Array.push→fallback, math関数の署名一致観測 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.0 KiB
4.0 KiB
🔄 Codex ↔ Claude 双方向通信ガイド
📋 概要
同じWebSocketサーバー(hook-server)を使って、CodexとClaudeが双方向に通信できます!
🎯 仕組み
Claude → hook-server (8770) → Codex ✅ (既に動作中)
Codex → hook-server (8770) → Claude ✅ (NEW!)
📡 Claudeへの返信方法
基本的な返信
// ClaudeへWebSocket経由で返信
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8770');
ws.on('open', () => {
ws.send(JSON.stringify({
source: 'codex', // 送信元を'codex'に
type: 'inject-input', // メッセージタイプ
data: 'ここに返信内容を書く' // 実際のメッセージ
}));
ws.close();
});
実用的な関数
// 再利用可能な返信関数
function replyToClaude(message) {
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8770');
ws.on('open', () => {
ws.send(JSON.stringify({
source: 'codex',
type: 'inject-input',
data: `[Codex→Claude] ${message}`
}));
console.log('✅ Sent to Claude:', message);
ws.close();
});
ws.on('error', (err) => {
console.error('❌ Error:', err.message);
});
}
// 使用例
replyToClaude('ビルドが完了しました!');
replyToClaude('テストの結果: 成功 10件、失敗 0件');
進捗通知の例
// タスクの進捗を通知
async function notifyProgress(task, status, details) {
const message = `
📊 進捗報告
タスク: ${task}
状態: ${status}
詳細: ${details}
時刻: ${new Date().toLocaleString('ja-JP')}
`;
replyToClaude(message.trim());
}
// 実行例
notifyProgress('Nyashビルド', '完了', 'cargo build --release 成功');
notifyProgress('テスト実行', '進行中', '5/10 完了...');
🎮 実践例
1. コマンド実行結果の返信
const { exec } = require('child_process');
// コマンドを実行してClaudeに結果を送る
function executeAndReply(command) {
exec(command, (error, stdout, stderr) => {
if (error) {
replyToClaude(`❌ エラー: ${command}\n${stderr}`);
} else {
replyToClaude(`✅ 成功: ${command}\n出力:\n${stdout}`);
}
});
}
// 使用例
executeAndReply('cargo check');
executeAndReply('ls -la');
2. ファイル操作の通知
const fs = require('fs');
// ファイル作成を通知
function notifyFileCreated(filename, content) {
fs.writeFileSync(filename, content);
replyToClaude(`📄 ファイル作成: ${filename} (${content.length}バイト)`);
}
// ファイル読み込みと返信
function readAndReply(filename) {
try {
const content = fs.readFileSync(filename, 'utf8');
replyToClaude(`📖 ${filename} の内容:\n${content.substring(0, 200)}...`);
} catch (err) {
replyToClaude(`❌ ファイル読み込みエラー: ${filename}`);
}
}
⚡ クイックテスト
以下のワンライナーでテスト可能:
// すぐに試せるテストコード
require('ws').connect('ws://localhost:8770').on('open', function() { this.send(JSON.stringify({ source: 'codex', type: 'inject-input', data: 'Hello Claude! 双方向通信テスト成功!' })); this.close(); });
📝 注意事項
-
hook-serverが起動していることを確認
lsof -i:8770 # ポートが開いているか確認 -
sourceは必ず'codex'に設定
- 'claude'にすると自分自身にループバックしてしまう
-
メッセージ形式を守る
- JSONで、source, type, dataの3つのフィールドが必須
🚀 活用アイデア
- 自動進捗報告: 長時間かかるタスクの進捗をリアルタイム通知
- エラー通知: 問題発生時に即座にClaudeに通知
- 完了通知: タスク完了時に次の指示を求める
- 質問: 判断に迷ったときにClaudeに相談
これで、CodexとClaudeが完全に双方向で協調作業できます!🎉