bluelamp 4.0.3 → 4.0.4

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 +112 -66
  2. package/package.json +1 -1
package/bin/bluelamp-base CHANGED
@@ -3,8 +3,10 @@
3
3
  /**
4
4
  * BlueLamp MCP Integration
5
5
  * Fast startup with auto-trigger using node-pty
6
+ * Fallback to spawn if pty fails
6
7
  */
7
8
 
9
+ const { spawn } = require('child_process');
8
10
  const path = require('path');
9
11
  const fs = require('fs');
10
12
  const os = require('os');
@@ -106,72 +108,13 @@ async function performPortalAuth() {
106
108
  }
107
109
 
108
110
  /**
109
- * メイン処理
111
+ * node-ptyを使用してClaudeを起動(自動トリガー付き)
110
112
  */
111
- async function main() {
112
- const keyword = getKeywordFromCommand();
113
- const isDebugMode = process.argv.includes('--debug');
114
-
115
- console.log('🔵 BlueLamp MCP Integration (Auto Mode)');
116
- console.log(`📚 プロンプト: ${keyword}`);
117
- console.log('');
118
-
119
- // Portal認証の実行
120
- const cliToken = await performPortalAuth();
121
-
122
- // MCP設定ファイルを作成
123
- const configPath = createMCPConfig(keyword, cliToken);
124
-
125
- console.log('🚀 Claude 起動中...');
126
- console.log('');
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
-
143
- // Windows対応
144
- const isWindows = process.platform === 'win32';
145
- const shell = isWindows ? 'powershell.exe' : 'claude';
146
-
147
- let shellArgs;
148
- if (isWindows) {
149
- shellArgs = [
150
- '-NoProfile',
151
- '-Command',
152
- 'claude',
153
- '--dangerously-skip-permissions',
154
- '--mcp-config', configPath,
155
- '--append-system-prompt', systemPromptAddition
156
- ];
157
- } else {
158
- shellArgs = [
159
- '--dangerously-skip-permissions',
160
- '--mcp-config', configPath,
161
- '--append-system-prompt', systemPromptAddition
162
- ];
163
- }
164
-
165
- if (isDebugMode) {
166
- console.log('🐛 デバッグ情報:');
167
- console.log(` コマンド: ${shell}`);
168
- console.log(` 引数: ${JSON.stringify(shellArgs)}`);
169
- console.log(` MCP設定: ${configPath}`);
170
- console.log('');
171
- }
113
+ function startWithPty(claudeCommand, claudeArgs, configPath, keyword) {
114
+ const pty = require('node-pty');
172
115
 
173
116
  // 疑似端末を作成
174
- const ptyProcess = pty.spawn(shell, shellArgs, {
117
+ const ptyProcess = pty.spawn(claudeCommand, claudeArgs, {
175
118
  name: 'xterm-256color',
176
119
  cols: process.stdout.columns || 80,
177
120
  rows: process.stdout.rows || 24,
@@ -192,7 +135,6 @@ keyword: "${keyword}" を指定して、専門知識を注入してから作業
192
135
  buffer += data;
193
136
 
194
137
  // Claudeの起動完了を検知(プロンプトが表示されたら)
195
- // ">" または "╰" が含まれていたら起動完了と判断
196
138
  if (!triggered && (buffer.includes('> ') || buffer.includes('╰─'))) {
197
139
  triggered = true;
198
140
  // 少し待ってから「開始」を送信
@@ -203,7 +145,9 @@ keyword: "${keyword}" を指定して、専門知識を注入してから作業
203
145
  });
204
146
 
205
147
  // 標準入力をptyに転送
206
- process.stdin.setRawMode(true);
148
+ if (process.stdin.isTTY) {
149
+ process.stdin.setRawMode(true);
150
+ }
207
151
  process.stdin.resume();
208
152
  process.stdin.on('data', (data) => {
209
153
  ptyProcess.write(data.toString());
@@ -224,10 +168,112 @@ keyword: "${keyword}" を指定して、専門知識を注入してから作業
224
168
 
225
169
  // Ctrl+C などのシグナル処理
226
170
  process.on('SIGINT', () => {
227
- ptyProcess.write('\x03'); // Ctrl+C を送信
171
+ ptyProcess.write('\x03');
172
+ });
173
+ }
174
+
175
+ /**
176
+ * 通常のspawnでClaudeを起動(フォールバック)
177
+ */
178
+ function startWithSpawn(claudeCommand, claudeArgs, configPath, keyword) {
179
+ const child = spawn(claudeCommand, claudeArgs, {
180
+ stdio: 'inherit',
181
+ env: {
182
+ ...process.env,
183
+ BLUELAMP_KEYWORD: keyword
184
+ }
185
+ });
186
+
187
+ child.on('error', (error) => {
188
+ console.error('❌ Claude 起動エラー:', error.message);
189
+ try { fs.unlinkSync(configPath); } catch (e) {}
190
+ process.exit(1);
191
+ });
192
+
193
+ child.on('exit', (code) => {
194
+ console.log('');
195
+ console.log('🔵 BlueLamp セッション終了');
196
+ try { fs.unlinkSync(configPath); } catch (e) {}
197
+ process.exit(code || 0);
198
+ });
199
+
200
+ process.on('SIGINT', () => {
201
+ console.log('\n🔵 BlueLamp を終了しています...');
202
+ child.kill('SIGINT');
228
203
  });
229
204
  }
230
205
 
206
+ /**
207
+ * メイン処理
208
+ */
209
+ async function main() {
210
+ const keyword = getKeywordFromCommand();
211
+ const isDebugMode = process.argv.includes('--debug');
212
+ const useSpawn = process.argv.includes('--no-auto');
213
+
214
+ console.log('🔵 BlueLamp MCP Integration (Auto Mode)');
215
+ console.log(`📚 プロンプト: ${keyword}`);
216
+ console.log('');
217
+
218
+ // Portal認証の実行
219
+ const cliToken = await performPortalAuth();
220
+
221
+ // MCP設定ファイルを作成
222
+ const configPath = createMCPConfig(keyword, cliToken);
223
+
224
+ console.log('🚀 Claude 起動中...');
225
+ console.log('');
226
+
227
+ // システムプロンプトに追加する指示
228
+ const systemPromptAddition = `【重要】セッション開始時に必ず inject_knowledge ツールを実行してください。
229
+ keyword: "${keyword}" を指定して、専門知識を注入してから作業を開始してください。
230
+ ユーザーが何か質問や指示をした場合でも、まず inject_knowledge を実行してから回答してください。`;
231
+
232
+ // Windows対応
233
+ const isWindows = process.platform === 'win32';
234
+ let claudeCommand, claudeArgs;
235
+
236
+ if (isWindows) {
237
+ claudeCommand = 'powershell.exe';
238
+ claudeArgs = [
239
+ '-NoProfile',
240
+ '-Command',
241
+ 'claude',
242
+ '--dangerously-skip-permissions',
243
+ '--mcp-config', configPath,
244
+ '--append-system-prompt', systemPromptAddition
245
+ ];
246
+ } else {
247
+ claudeCommand = 'claude';
248
+ claudeArgs = [
249
+ '--dangerously-skip-permissions',
250
+ '--mcp-config', configPath,
251
+ '--append-system-prompt', systemPromptAddition
252
+ ];
253
+ }
254
+
255
+ if (isDebugMode) {
256
+ console.log('🐛 デバッグ情報:');
257
+ console.log(` コマンド: ${claudeCommand}`);
258
+ console.log(` 引数: ${JSON.stringify(claudeArgs)}`);
259
+ console.log(` MCP設定: ${configPath}`);
260
+ console.log('');
261
+ }
262
+
263
+ // node-ptyを試行、失敗したらspawnにフォールバック
264
+ if (useSpawn) {
265
+ // --no-autoオプションが指定された場合は通常のspawnを使用
266
+ startWithSpawn(claudeCommand, claudeArgs, configPath, keyword);
267
+ } else {
268
+ try {
269
+ startWithPty(claudeCommand, claudeArgs, configPath, keyword);
270
+ } catch (e) {
271
+ console.log('⚠️ 自動モード利用不可、通常モードで起動します...');
272
+ startWithSpawn(claudeCommand, claudeArgs, configPath, keyword);
273
+ }
274
+ }
275
+ }
276
+
231
277
  main().catch((error) => {
232
278
  console.error('❌ 予期しないエラー:', error.message);
233
279
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bluelamp",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "BlueLamp MCP Integration - Fast Startup with SessionStart Hook",
5
5
  "main": "lib/mcp-server/index.cjs",
6
6
  "bin": {