bluelamp 4.0.2 → 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 +115 -34
  2. package/package.json +3 -2
package/bin/bluelamp-base CHANGED
@@ -2,7 +2,8 @@
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
+ * Fallback to spawn if pty fails
6
7
  */
7
8
 
8
9
  const { spawn } = require('child_process');
@@ -106,14 +107,111 @@ async function performPortalAuth() {
106
107
  }
107
108
  }
108
109
 
110
+ /**
111
+ * node-ptyを使用してClaudeを起動(自動トリガー付き)
112
+ */
113
+ function startWithPty(claudeCommand, claudeArgs, configPath, keyword) {
114
+ const pty = require('node-pty');
115
+
116
+ // 疑似端末を作成
117
+ const ptyProcess = pty.spawn(claudeCommand, claudeArgs, {
118
+ name: 'xterm-256color',
119
+ cols: process.stdout.columns || 80,
120
+ rows: process.stdout.rows || 24,
121
+ cwd: process.cwd(),
122
+ env: {
123
+ ...process.env,
124
+ BLUELAMP_KEYWORD: keyword
125
+ }
126
+ });
127
+
128
+ // Claudeが起動完了したら自動で「開始」を送信
129
+ let triggered = false;
130
+ let buffer = '';
131
+
132
+ // 出力をそのまま標準出力に転送 + 起動完了検知
133
+ ptyProcess.onData((data) => {
134
+ process.stdout.write(data);
135
+ buffer += data;
136
+
137
+ // Claudeの起動完了を検知(プロンプトが表示されたら)
138
+ if (!triggered && (buffer.includes('> ') || buffer.includes('╰─'))) {
139
+ triggered = true;
140
+ // 少し待ってから「開始」を送信
141
+ setTimeout(() => {
142
+ ptyProcess.write('開始\r');
143
+ }, 500);
144
+ }
145
+ });
146
+
147
+ // 標準入力をptyに転送
148
+ if (process.stdin.isTTY) {
149
+ process.stdin.setRawMode(true);
150
+ }
151
+ process.stdin.resume();
152
+ process.stdin.on('data', (data) => {
153
+ ptyProcess.write(data.toString());
154
+ });
155
+
156
+ // ターミナルサイズの変更を検知
157
+ process.stdout.on('resize', () => {
158
+ ptyProcess.resize(process.stdout.columns, process.stdout.rows);
159
+ });
160
+
161
+ // プロセス終了時の処理
162
+ ptyProcess.onExit(({ exitCode }) => {
163
+ console.log('');
164
+ console.log('🔵 BlueLamp セッション終了');
165
+ try { fs.unlinkSync(configPath); } catch (e) {}
166
+ process.exit(exitCode || 0);
167
+ });
168
+
169
+ // Ctrl+C などのシグナル処理
170
+ process.on('SIGINT', () => {
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');
203
+ });
204
+ }
205
+
109
206
  /**
110
207
  * メイン処理
111
208
  */
112
209
  async function main() {
113
210
  const keyword = getKeywordFromCommand();
114
211
  const isDebugMode = process.argv.includes('--debug');
212
+ const useSpawn = process.argv.includes('--no-auto');
115
213
 
116
- console.log('🔵 BlueLamp MCP Integration (Fast Mode)');
214
+ console.log('🔵 BlueLamp MCP Integration (Auto Mode)');
117
215
  console.log(`📚 プロンプト: ${keyword}`);
118
216
  console.log('');
119
217
 
@@ -126,15 +224,15 @@ async function main() {
126
224
  console.log('🚀 Claude 起動中...');
127
225
  console.log('');
128
226
 
129
- // Windows対応
130
- const isWindows = process.platform === 'win32';
131
- let claudeCommand, claudeArgs;
132
-
133
227
  // システムプロンプトに追加する指示
134
228
  const systemPromptAddition = `【重要】セッション開始時に必ず inject_knowledge ツールを実行してください。
135
229
  keyword: "${keyword}" を指定して、専門知識を注入してから作業を開始してください。
136
230
  ユーザーが何か質問や指示をした場合でも、まず inject_knowledge を実行してから回答してください。`;
137
231
 
232
+ // Windows対応
233
+ const isWindows = process.platform === 'win32';
234
+ let claudeCommand, claudeArgs;
235
+
138
236
  if (isWindows) {
139
237
  claudeCommand = 'powershell.exe';
140
238
  claudeArgs = [
@@ -162,35 +260,18 @@ keyword: "${keyword}" を指定して、専門知識を注入してから作業
162
260
  console.log('');
163
261
  }
164
262
 
165
- // SessionStart Hook 用にキーワードを一時ファイルに保存
166
- const keywordFilePath = path.join(os.tmpdir(), 'bluelamp-keyword');
167
- fs.writeFileSync(keywordFilePath, keyword);
168
-
169
- const child = spawn(claudeCommand, claudeArgs, {
170
- stdio: 'inherit',
171
- env: {
172
- ...process.env,
173
- BLUELAMP_KEYWORD: keyword
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);
174
273
  }
175
- });
176
-
177
- child.on('error', (error) => {
178
- console.error('❌ Claude 起動エラー:', error.message);
179
- try { fs.unlinkSync(configPath); } catch (e) {}
180
- process.exit(1);
181
- });
182
-
183
- child.on('exit', (code) => {
184
- console.log('');
185
- console.log('🔵 BlueLamp セッション終了');
186
- try { fs.unlinkSync(configPath); } catch (e) {}
187
- process.exit(code || 0);
188
- });
189
-
190
- process.on('SIGINT', () => {
191
- console.log('\n🔵 BlueLamp を終了しています...');
192
- child.kill('SIGINT');
193
- });
274
+ }
194
275
  }
195
276
 
196
277
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bluelamp",
3
- "version": "4.0.2",
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": {
@@ -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"