bluelamp 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/bluelamp-base +68 -27
  2. package/package.json +3 -2
package/bin/bluelamp-base CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  /**
4
4
  * BlueLamp MCP Integration
5
- * Fast startup version using SessionStart Hook
5
+ * Fast startup with auto-trigger using node-pty
6
6
  */
7
7
 
8
- const { spawn } = require('child_process');
9
8
  const path = require('path');
10
9
  const fs = require('fs');
11
10
  const os = require('os');
@@ -113,7 +112,7 @@ async function main() {
113
112
  const keyword = getKeywordFromCommand();
114
113
  const isDebugMode = process.argv.includes('--debug');
115
114
 
116
- console.log('🔵 BlueLamp MCP Integration (Fast Mode)');
115
+ console.log('🔵 BlueLamp MCP Integration (Auto Mode)');
117
116
  console.log(`📚 プロンプト: ${keyword}`);
118
117
  console.log('');
119
118
 
@@ -126,64 +125,106 @@ async function main() {
126
125
  console.log('🚀 Claude 起動中...');
127
126
  console.log('');
128
127
 
128
+ // node-ptyを使用して疑似端末でClaudeを起動
129
+ let pty;
130
+ try {
131
+ pty = require('node-pty');
132
+ } catch (e) {
133
+ console.error('❌ node-pty が見つかりません。再インストールしてください:');
134
+ console.error(' npm install -g bluelamp');
135
+ process.exit(1);
136
+ }
137
+
138
+ // システムプロンプトに追加する指示
139
+ const systemPromptAddition = `【重要】セッション開始時に必ず inject_knowledge ツールを実行してください。
140
+ keyword: "${keyword}" を指定して、専門知識を注入してから作業を開始してください。
141
+ ユーザーが何か質問や指示をした場合でも、まず inject_knowledge を実行してから回答してください。`;
142
+
129
143
  // Windows対応
130
144
  const isWindows = process.platform === 'win32';
131
- let claudeCommand, claudeArgs;
145
+ const shell = isWindows ? 'powershell.exe' : 'claude';
132
146
 
147
+ let shellArgs;
133
148
  if (isWindows) {
134
- claudeCommand = 'powershell.exe';
135
- claudeArgs = [
149
+ shellArgs = [
136
150
  '-NoProfile',
137
151
  '-Command',
138
152
  'claude',
139
153
  '--dangerously-skip-permissions',
140
- '--mcp-config', configPath
154
+ '--mcp-config', configPath,
155
+ '--append-system-prompt', systemPromptAddition
141
156
  ];
142
157
  } else {
143
- claudeCommand = 'claude';
144
- // initialPrompt を渡さない = 高速起動
145
- claudeArgs = [
158
+ shellArgs = [
146
159
  '--dangerously-skip-permissions',
147
- '--mcp-config', configPath
160
+ '--mcp-config', configPath,
161
+ '--append-system-prompt', systemPromptAddition
148
162
  ];
149
163
  }
150
164
 
151
165
  if (isDebugMode) {
152
166
  console.log('🐛 デバッグ情報:');
153
- console.log(` コマンド: ${claudeCommand}`);
154
- console.log(` 引数: ${JSON.stringify(claudeArgs)}`);
167
+ console.log(` コマンド: ${shell}`);
168
+ console.log(` 引数: ${JSON.stringify(shellArgs)}`);
155
169
  console.log(` MCP設定: ${configPath}`);
156
170
  console.log('');
157
171
  }
158
172
 
159
- // SessionStart Hook 用にキーワードを一時ファイルに保存
160
- const keywordFilePath = path.join(os.tmpdir(), 'bluelamp-keyword');
161
- fs.writeFileSync(keywordFilePath, keyword);
162
-
163
- const child = spawn(claudeCommand, claudeArgs, {
164
- stdio: 'inherit',
173
+ // 疑似端末を作成
174
+ const ptyProcess = pty.spawn(shell, shellArgs, {
175
+ name: 'xterm-256color',
176
+ cols: process.stdout.columns || 80,
177
+ rows: process.stdout.rows || 24,
178
+ cwd: process.cwd(),
165
179
  env: {
166
180
  ...process.env,
167
181
  BLUELAMP_KEYWORD: keyword
168
182
  }
169
183
  });
170
184
 
171
- child.on('error', (error) => {
172
- console.error('❌ Claude 起動エラー:', error.message);
173
- try { fs.unlinkSync(configPath); } catch (e) {}
174
- process.exit(1);
185
+ // Claudeが起動完了したら自動で「開始」を送信
186
+ let triggered = false;
187
+ let buffer = '';
188
+
189
+ // 出力をそのまま標準出力に転送 + 起動完了検知
190
+ ptyProcess.onData((data) => {
191
+ process.stdout.write(data);
192
+ buffer += data;
193
+
194
+ // Claudeの起動完了を検知(プロンプトが表示されたら)
195
+ // ">" または "╰" が含まれていたら起動完了と判断
196
+ if (!triggered && (buffer.includes('> ') || buffer.includes('╰─'))) {
197
+ triggered = true;
198
+ // 少し待ってから「開始」を送信
199
+ setTimeout(() => {
200
+ ptyProcess.write('開始\r');
201
+ }, 500);
202
+ }
203
+ });
204
+
205
+ // 標準入力をptyに転送
206
+ process.stdin.setRawMode(true);
207
+ process.stdin.resume();
208
+ process.stdin.on('data', (data) => {
209
+ ptyProcess.write(data.toString());
210
+ });
211
+
212
+ // ターミナルサイズの変更を検知
213
+ process.stdout.on('resize', () => {
214
+ ptyProcess.resize(process.stdout.columns, process.stdout.rows);
175
215
  });
176
216
 
177
- child.on('exit', (code) => {
217
+ // プロセス終了時の処理
218
+ ptyProcess.onExit(({ exitCode }) => {
178
219
  console.log('');
179
220
  console.log('🔵 BlueLamp セッション終了');
180
221
  try { fs.unlinkSync(configPath); } catch (e) {}
181
- process.exit(code || 0);
222
+ process.exit(exitCode || 0);
182
223
  });
183
224
 
225
+ // Ctrl+C などのシグナル処理
184
226
  process.on('SIGINT', () => {
185
- console.log('\n🔵 BlueLamp を終了しています...');
186
- child.kill('SIGINT');
227
+ ptyProcess.write('\x03'); // Ctrl+C を送信
187
228
  });
188
229
  }
189
230
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bluelamp",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "BlueLamp MCP Integration - Fast Startup with SessionStart Hook",
5
5
  "main": "lib/mcp-server/index.cjs",
6
6
  "bin": {
@@ -41,7 +41,8 @@
41
41
  "@modelcontextprotocol/sdk": "^1.0.0",
42
42
  "dotenv": "^16.6.1",
43
43
  "jsonwebtoken": "^9.0.2",
44
- "node-fetch": "^3.3.2"
44
+ "node-fetch": "^3.3.2",
45
+ "node-pty": "^1.1.0"
45
46
  },
46
47
  "engines": {
47
48
  "node": ">=18"