claude-brain 0.24.1 → 0.24.2
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.
- package/VERSION +1 -1
- package/package.json +1 -1
- package/scripts/postinstall.mjs +3 -3
- package/src/cli/auto-start.ts +5 -5
- package/src/cli/commands/serve.ts +142 -124
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.24.
|
|
1
|
+
0.24.2
|
package/package.json
CHANGED
package/scripts/postinstall.mjs
CHANGED
|
@@ -342,7 +342,7 @@ function buildAutoStartSnippet(profilePath) {
|
|
|
342
342
|
'if (Get-Command claude-brain -ErrorAction SilentlyContinue) {',
|
|
343
343
|
' $listening = Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue',
|
|
344
344
|
' if (-not $listening) {',
|
|
345
|
-
' Start-Process -NoNewWindow -FilePath "claude-brain" -ArgumentList "serve" -WindowStyle Hidden',
|
|
345
|
+
' Start-Process -NoNewWindow -FilePath "claude-brain" -ArgumentList "serve","--http-only" -WindowStyle Hidden',
|
|
346
346
|
' }',
|
|
347
347
|
'}',
|
|
348
348
|
AUTO_END_MARKER,
|
|
@@ -350,9 +350,9 @@ function buildAutoStartSnippet(profilePath) {
|
|
|
350
350
|
}
|
|
351
351
|
return [
|
|
352
352
|
AUTO_START_MARKER,
|
|
353
|
-
'# Auto-start claude-brain server if not already running',
|
|
353
|
+
'# Auto-start claude-brain HTTP server if not already running',
|
|
354
354
|
'(command -v claude-brain >/dev/null 2>&1 && ! lsof -ti :3000 >/dev/null 2>&1) && {',
|
|
355
|
-
' nohup claude-brain serve >/dev/null 2>&1 &',
|
|
355
|
+
' nohup claude-brain serve --http-only >/dev/null 2>&1 &',
|
|
356
356
|
' disown 2>/dev/null',
|
|
357
357
|
'}',
|
|
358
358
|
AUTO_END_MARKER,
|
package/src/cli/auto-start.ts
CHANGED
|
@@ -32,9 +32,9 @@ export interface AutoStartResult {
|
|
|
32
32
|
function buildUnixSnippet(port: number): string {
|
|
33
33
|
return [
|
|
34
34
|
START_MARKER,
|
|
35
|
-
'# Auto-start claude-brain server if not already running',
|
|
35
|
+
'# Auto-start claude-brain HTTP server if not already running',
|
|
36
36
|
`(command -v claude-brain >/dev/null 2>&1 && ! lsof -ti :${port} >/dev/null 2>&1) && {`,
|
|
37
|
-
' nohup claude-brain serve >/dev/null 2>&1 &',
|
|
37
|
+
' nohup claude-brain serve --http-only >/dev/null 2>&1 &',
|
|
38
38
|
' disown 2>/dev/null',
|
|
39
39
|
'}',
|
|
40
40
|
END_MARKER,
|
|
@@ -48,9 +48,9 @@ function buildUnixSnippet(port: number): string {
|
|
|
48
48
|
function buildFishSnippet(port: number): string {
|
|
49
49
|
return [
|
|
50
50
|
START_MARKER,
|
|
51
|
-
'# Auto-start claude-brain server if not already running',
|
|
51
|
+
'# Auto-start claude-brain HTTP server if not already running',
|
|
52
52
|
`if command -v claude-brain >/dev/null 2>&1; and not lsof -ti :${port} >/dev/null 2>&1`,
|
|
53
|
-
' nohup claude-brain serve >/dev/null 2>&1 &',
|
|
53
|
+
' nohup claude-brain serve --http-only >/dev/null 2>&1 &',
|
|
54
54
|
'end',
|
|
55
55
|
END_MARKER,
|
|
56
56
|
].join('\n')
|
|
@@ -66,7 +66,7 @@ function buildPowerShellSnippet(port: number): string {
|
|
|
66
66
|
` $port = ${port}`,
|
|
67
67
|
' $listening = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue',
|
|
68
68
|
' if (-not $listening) {',
|
|
69
|
-
' Start-Process -NoNewWindow -FilePath "claude-brain" -ArgumentList "serve" -WindowStyle Hidden',
|
|
69
|
+
' Start-Process -NoNewWindow -FilePath "claude-brain" -ArgumentList "serve","--http-only" -WindowStyle Hidden',
|
|
70
70
|
' }',
|
|
71
71
|
'}',
|
|
72
72
|
END_MARKER,
|
|
@@ -18,17 +18,22 @@ export async function runServe() {
|
|
|
18
18
|
// Auto-initialize home directory on first run
|
|
19
19
|
ensureHomeDirectory()
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// --http-only: run HTTP server + services but no MCP stdio transport.
|
|
22
|
+
// Used by auto-start background process (stdin is /dev/null, no Claude Code attached).
|
|
23
|
+
const httpOnly = process.argv.includes('--http-only')
|
|
24
|
+
|
|
25
|
+
// Determine instance role:
|
|
26
|
+
// - httpOnly → always primary (background HTTP daemon)
|
|
27
|
+
// - otherwise → secondary if primary is already running (Claude Code MCP session)
|
|
22
28
|
const pidManager = new ServerPidManager()
|
|
23
29
|
const existingPid = pidManager.getRunningPid()
|
|
24
|
-
|
|
25
|
-
console.error(`[claude-brain] Server already running (PID: ${existingPid}). Exiting.`)
|
|
26
|
-
process.exit(0)
|
|
27
|
-
}
|
|
30
|
+
const isSecondaryInstance = !httpOnly && !!existingPid
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
if (!isSecondaryInstance) {
|
|
33
|
+
// Primary instance: write PID file and register cleanup
|
|
34
|
+
pidManager.writePidFile()
|
|
35
|
+
pidManager.registerCleanupHandlers()
|
|
36
|
+
}
|
|
32
37
|
|
|
33
38
|
// Auto-install Claude Code hooks (idempotent, non-fatal)
|
|
34
39
|
try {
|
|
@@ -162,141 +167,147 @@ export async function runServe() {
|
|
|
162
167
|
await shutdownServices()
|
|
163
168
|
})
|
|
164
169
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
// ── Primary instance only: HTTP server + background services ──
|
|
171
|
+
// Secondary instances (when auto-start already running) only start MCP stdio
|
|
172
|
+
if (!isSecondaryInstance) {
|
|
173
|
+
// Clean up PID file during graceful shutdown
|
|
174
|
+
cleanup.register(async () => {
|
|
175
|
+
pidManager.cleanup()
|
|
176
|
+
})
|
|
169
177
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
// Start HTTP API server alongside MCP server
|
|
179
|
+
const { HttpApiServer } = await import('@/server/http-api')
|
|
180
|
+
const httpServer = new HttpApiServer(config, logger)
|
|
173
181
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
182
|
+
cleanup.register(async () => {
|
|
183
|
+
await httpServer.stop()
|
|
184
|
+
})
|
|
177
185
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
// Phase 21: Use session tracker from services (promoted from local creation)
|
|
187
|
+
{
|
|
188
|
+
const { getSessionTracker } = await import('@/server/services')
|
|
189
|
+
const sessionTracker = getSessionTracker()
|
|
190
|
+
if (sessionTracker) {
|
|
191
|
+
httpServer.setSessionTracker(sessionTracker)
|
|
192
|
+
mainLogger.info('Session tracker wired to HTTP server')
|
|
193
|
+
}
|
|
185
194
|
}
|
|
186
|
-
}
|
|
187
195
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
+
// Phase 28: Wire code intelligence to HTTP server
|
|
197
|
+
{
|
|
198
|
+
const { getCodeIndexer, getCodeQuery } = await import('@/server/services')
|
|
199
|
+
const codeIndexer = getCodeIndexer()
|
|
200
|
+
const codeQuery = getCodeQuery()
|
|
201
|
+
if (codeIndexer && codeQuery) {
|
|
202
|
+
httpServer.setCodeIntelligence(codeIndexer, codeQuery)
|
|
203
|
+
mainLogger.info('Code intelligence wired to HTTP server')
|
|
204
|
+
}
|
|
196
205
|
}
|
|
197
|
-
}
|
|
198
206
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
// Phase 29: Wire code linker to HTTP server
|
|
208
|
+
{
|
|
209
|
+
const { getCodeLinker } = await import('@/server/services')
|
|
210
|
+
const codeLinker = getCodeLinker()
|
|
211
|
+
if (codeLinker) {
|
|
212
|
+
httpServer.setCodeLinker(codeLinker)
|
|
213
|
+
mainLogger.info('Code linker wired to HTTP server')
|
|
214
|
+
}
|
|
206
215
|
}
|
|
207
|
-
}
|
|
208
216
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
217
|
+
// Phase 30: Activity log pruning on startup + periodic cleanup
|
|
218
|
+
{
|
|
219
|
+
const memory = getMemoryService()
|
|
220
|
+
if (memory?.isInitialized()) {
|
|
221
|
+
try {
|
|
222
|
+
const { startPeriodicPruning } = await import('@/memory/pruning')
|
|
223
|
+
const db = memory.database.getDb()
|
|
224
|
+
const stopPruning = startPeriodicPruning(db, logger, 30)
|
|
225
|
+
cleanup.register(async () => {
|
|
226
|
+
stopPruning()
|
|
227
|
+
mainLogger.info('Activity log pruning stopped')
|
|
228
|
+
})
|
|
229
|
+
mainLogger.info('Activity log pruning initialized')
|
|
230
|
+
} catch (error) {
|
|
231
|
+
mainLogger.warn({ error }, 'Failed to initialize activity log pruning')
|
|
232
|
+
}
|
|
224
233
|
}
|
|
225
234
|
}
|
|
226
|
-
}
|
|
227
235
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
// Phase 30: Optional LLM compression
|
|
237
|
+
if (config.compression?.enabled) {
|
|
238
|
+
try {
|
|
239
|
+
const { ObservationCompressor } = await import('@/memory/compression')
|
|
240
|
+
const { getBrainRouter } = await import('@/routing/router')
|
|
241
|
+
const compressor = new ObservationCompressor(config.compression, logger)
|
|
242
|
+
const router = getBrainRouter(logger)
|
|
243
|
+
router.setCompressor(compressor)
|
|
244
|
+
mainLogger.info({ provider: config.compression.provider, model: config.compression.model }, 'LLM compression enabled')
|
|
245
|
+
} catch (error) {
|
|
246
|
+
mainLogger.warn({ error }, 'Failed to initialize LLM compression')
|
|
247
|
+
}
|
|
239
248
|
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Phase 31: Auto-update checker
|
|
243
|
-
let autoUpdater: InstanceType<typeof import('@/server/auto-updater').AutoUpdater> | null = null
|
|
244
|
-
if (config.autoUpdate?.enabled !== false) {
|
|
245
|
-
try {
|
|
246
|
-
const { AutoUpdater } = await import('@/server/auto-updater')
|
|
247
|
-
autoUpdater = new AutoUpdater(
|
|
248
|
-
{
|
|
249
|
-
enabled: config.autoUpdate?.enabled ?? true,
|
|
250
|
-
checkIntervalHours: config.autoUpdate?.checkIntervalHours ?? 24,
|
|
251
|
-
autoRestart: config.autoUpdate?.autoRestart ?? true,
|
|
252
|
-
},
|
|
253
|
-
mainLogger
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
// Check for updates on startup (non-blocking)
|
|
257
|
-
autoUpdater.check().then(result => {
|
|
258
|
-
if (result.updateAvailable && result.latestVersion) {
|
|
259
|
-
mainLogger.info(
|
|
260
|
-
{ current: result.currentVersion, latest: result.latestVersion },
|
|
261
|
-
'Update available! Run: claude-brain update'
|
|
262
|
-
)
|
|
263
|
-
}
|
|
264
|
-
}).catch(() => {})
|
|
265
249
|
|
|
266
|
-
|
|
267
|
-
|
|
250
|
+
// Phase 31: Auto-update checker
|
|
251
|
+
let autoUpdater: InstanceType<typeof import('@/server/auto-updater').AutoUpdater> | null = null
|
|
252
|
+
if (config.autoUpdate?.enabled !== false) {
|
|
253
|
+
try {
|
|
254
|
+
const { AutoUpdater } = await import('@/server/auto-updater')
|
|
255
|
+
autoUpdater = new AutoUpdater(
|
|
256
|
+
{
|
|
257
|
+
enabled: config.autoUpdate?.enabled ?? true,
|
|
258
|
+
checkIntervalHours: config.autoUpdate?.checkIntervalHours ?? 24,
|
|
259
|
+
autoRestart: config.autoUpdate?.autoRestart ?? true,
|
|
260
|
+
},
|
|
261
|
+
mainLogger
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
// Check for updates on startup (non-blocking)
|
|
265
|
+
autoUpdater.check().then(result => {
|
|
266
|
+
if (result.updateAvailable && result.latestVersion) {
|
|
267
|
+
mainLogger.info(
|
|
268
|
+
{ current: result.currentVersion, latest: result.latestVersion },
|
|
269
|
+
'Update available! Run: claude-brain update'
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
}).catch(() => {})
|
|
273
|
+
|
|
274
|
+
// Schedule periodic checks
|
|
275
|
+
autoUpdater.schedulePeriodicCheck()
|
|
268
276
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
277
|
+
cleanup.register(async () => {
|
|
278
|
+
autoUpdater?.stopPeriodicCheck()
|
|
279
|
+
mainLogger.info('Auto-updater stopped')
|
|
280
|
+
})
|
|
273
281
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
mainLogger.info('Auto-updater initialized')
|
|
283
|
+
} catch (error) {
|
|
284
|
+
mainLogger.warn({ error }, 'Failed to initialize auto-updater')
|
|
285
|
+
}
|
|
277
286
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Start HTTP server after MCP server is ready
|
|
281
|
-
setTimeout(async () => {
|
|
282
|
-
try {
|
|
283
|
-
await httpServer.start()
|
|
284
|
-
mainLogger.info({ port: config.port }, 'HTTP API server started')
|
|
285
287
|
|
|
286
|
-
|
|
288
|
+
// Start HTTP server after MCP server is ready
|
|
289
|
+
setTimeout(async () => {
|
|
287
290
|
try {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
291
|
+
await httpServer.start()
|
|
292
|
+
mainLogger.info({ port: config.port }, 'HTTP API server started')
|
|
293
|
+
|
|
294
|
+
// Drain hook queue after HTTP server is ready
|
|
295
|
+
try {
|
|
296
|
+
const { drainQueue } = await import('@/hooks/queue')
|
|
297
|
+
const drained = await drainQueue(config.port)
|
|
298
|
+
if (drained > 0) {
|
|
299
|
+
mainLogger.info({ drained }, 'Drained hook queue')
|
|
300
|
+
}
|
|
301
|
+
} catch (error) {
|
|
302
|
+
mainLogger.debug({ error }, 'No hook queue to drain')
|
|
292
303
|
}
|
|
293
304
|
} catch (error) {
|
|
294
|
-
mainLogger.
|
|
305
|
+
mainLogger.error({ error }, 'Failed to start HTTP API server')
|
|
295
306
|
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
}
|
|
307
|
+
}, 2000)
|
|
308
|
+
} else {
|
|
309
|
+
mainLogger.info({ existingPid }, 'Secondary instance — HTTP server already running, starting MCP stdio only')
|
|
310
|
+
}
|
|
300
311
|
|
|
301
312
|
const shutdown = async (signal: string) => {
|
|
302
313
|
mainLogger.info({ signal }, 'Shutting down...')
|
|
@@ -307,7 +318,14 @@ export async function runServe() {
|
|
|
307
318
|
process.on('SIGTERM', () => shutdown('SIGTERM'))
|
|
308
319
|
process.on('SIGINT', () => shutdown('SIGINT'))
|
|
309
320
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
321
|
+
if (httpOnly) {
|
|
322
|
+
// HTTP-only mode: no MCP stdio. Keep process alive for HTTP server.
|
|
323
|
+
mainLogger.info('HTTP-only mode — MCP stdio disabled (background daemon)')
|
|
324
|
+
// Keep the event loop alive with a long interval
|
|
325
|
+
const keepAlive = setInterval(() => {}, 60_000 * 60)
|
|
326
|
+
cleanup.register(async () => { clearInterval(keepAlive) })
|
|
327
|
+
} else {
|
|
328
|
+
await mcpServer.start()
|
|
329
|
+
mainLogger.info('Claude Brain MCP server ready and listening for connections')
|
|
330
|
+
}
|
|
313
331
|
}
|