mirror of
https://github.com/thedotmack/claude-mem.git
synced 2026-09-20 04:23:02 +08:00
fix: use health oracle and configured worker endpoint
(cherry picked from commit 3695d11601)
This commit is contained in:
@@ -3,6 +3,8 @@ import * as path from "path";
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import * as os from "os";
|
||||
import { SettingsDefaultsManager } from "../../src/shared/SettingsDefaultsManager.js";
|
||||
import { USER_SETTINGS_PATH } from "../../src/shared/paths.js";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
@@ -106,9 +108,9 @@ async function getOsVersion(): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkWorkerHealth(port: number): Promise<any> {
|
||||
async function checkWorkerHealth(host: string, port: number): Promise<any> {
|
||||
try {
|
||||
const response = await fetch(`http://127.0.0.1:${port}/health`, {
|
||||
const response = await fetch(`http://${host}:${port}/api/health`, {
|
||||
signal: AbortSignal.timeout(2000),
|
||||
});
|
||||
return await response.json();
|
||||
@@ -117,9 +119,9 @@ async function checkWorkerHealth(port: number): Promise<any> {
|
||||
}
|
||||
}
|
||||
|
||||
async function getWorkerStats(port: number): Promise<any> {
|
||||
async function getWorkerStats(host: string, port: number): Promise<any> {
|
||||
try {
|
||||
const response = await fetch(`http://127.0.0.1:${port}/api/stats`, {
|
||||
const response = await fetch(`http://${host}:${port}/api/stats`, {
|
||||
signal: AbortSignal.timeout(2000),
|
||||
});
|
||||
return await response.json();
|
||||
@@ -244,11 +246,16 @@ export async function collectDiagnostics(
|
||||
};
|
||||
|
||||
const pidInfo = await readPidFile(dataDir);
|
||||
const workerPort = pidInfo?.port || 37777;
|
||||
const workerSettings = SettingsDefaultsManager.loadFromFile(USER_SETTINGS_PATH);
|
||||
const workerHost = process.env.CLAUDE_MEM_WORKER_HOST || workerSettings.CLAUDE_MEM_WORKER_HOST;
|
||||
const configuredWorkerPort = process.env.CLAUDE_MEM_WORKER_PORT || workerSettings.CLAUDE_MEM_WORKER_PORT;
|
||||
const workerPort = typeof pidInfo?.port === "number"
|
||||
? pidInfo.port
|
||||
: parseInt(configuredWorkerPort, 10);
|
||||
|
||||
const [health, stats] = await Promise.all([
|
||||
checkWorkerHealth(workerPort),
|
||||
getWorkerStats(workerPort),
|
||||
checkWorkerHealth(workerHost, workerPort),
|
||||
getWorkerStats(workerHost, workerPort),
|
||||
]);
|
||||
|
||||
const worker = {
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
const DEFAULT_WORKER_PORT = 37777;
|
||||
import { SettingsDefaultsManager } from '../src/shared/SettingsDefaultsManager.js';
|
||||
import { USER_SETTINGS_PATH } from '../src/shared/paths.js';
|
||||
|
||||
function resolveWorkerPort(): number {
|
||||
const workerSettings = SettingsDefaultsManager.loadFromFile(USER_SETTINGS_PATH);
|
||||
const DEFAULT_WORKER_HOST = workerSettings.CLAUDE_MEM_WORKER_HOST;
|
||||
const DEFAULT_WORKER_PORT = workerSettings.CLAUDE_MEM_WORKER_PORT;
|
||||
|
||||
function resolveWorkerHost(): string {
|
||||
return process.env.CLAUDE_MEM_WORKER_HOST || DEFAULT_WORKER_HOST;
|
||||
}
|
||||
|
||||
function resolveWorkerPort(): string {
|
||||
const raw = process.env.CLAUDE_MEM_WORKER_PORT;
|
||||
if (raw === undefined || raw === '') return DEFAULT_WORKER_PORT;
|
||||
const parsed = parseInt(raw, 10);
|
||||
@@ -13,11 +22,12 @@ function resolveWorkerPort(): number {
|
||||
);
|
||||
return DEFAULT_WORKER_PORT;
|
||||
}
|
||||
return parsed;
|
||||
return String(parsed);
|
||||
}
|
||||
|
||||
const WORKER_HOST = resolveWorkerHost();
|
||||
const WORKER_PORT = resolveWorkerPort();
|
||||
const WORKER_URL = `http://127.0.0.1:${WORKER_PORT}`;
|
||||
const WORKER_URL = `http://${WORKER_HOST}:${WORKER_PORT}`;
|
||||
const WORKER_FETCH_TIMEOUT_MS = 10_000;
|
||||
|
||||
interface ProcessingStatusResponse {
|
||||
@@ -127,7 +137,8 @@ Options:
|
||||
--process Trigger processing without prompting
|
||||
|
||||
Environment:
|
||||
CLAUDE_MEM_WORKER_PORT Worker port (default: 37777)
|
||||
CLAUDE_MEM_WORKER_HOST Worker host (default: ${DEFAULT_WORKER_HOST})
|
||||
CLAUDE_MEM_WORKER_PORT Worker port (default: ${DEFAULT_WORKER_PORT})
|
||||
|
||||
Examples:
|
||||
# Check queue status interactively
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { SettingsDefaultsManager } from '../src/shared/SettingsDefaultsManager.js';
|
||||
import { USER_SETTINGS_PATH } from '../src/shared/paths.js';
|
||||
|
||||
const WORKER_PORT = process.env.CLAUDE_MEM_WORKER_PORT || 37777;
|
||||
const WORKER_URL = `http://127.0.0.1:${WORKER_PORT}`;
|
||||
const workerSettings = SettingsDefaultsManager.loadFromFile(USER_SETTINGS_PATH);
|
||||
const WORKER_HOST = process.env.CLAUDE_MEM_WORKER_HOST || workerSettings.CLAUDE_MEM_WORKER_HOST;
|
||||
const WORKER_PORT = process.env.CLAUDE_MEM_WORKER_PORT || workerSettings.CLAUDE_MEM_WORKER_PORT;
|
||||
const WORKER_URL = `http://${WORKER_HOST}:${WORKER_PORT}`;
|
||||
|
||||
async function importMemories(inputFile: string) {
|
||||
if (!existsSync(inputFile)) {
|
||||
|
||||
@@ -51,7 +51,7 @@ if (branch && branch !== 'main' && !isForce) {
|
||||
console.log('\x1b[33m%s\x1b[0m', 'Running rsync would overwrite beta code.');
|
||||
console.log('');
|
||||
console.log('Options:');
|
||||
console.log(' 1. Use UI at http://localhost:37777 to update beta');
|
||||
console.log(' 1. Use the claude-mem UI on the configured worker port to update beta');
|
||||
console.log(' 2. Switch to stable in UI first, then run sync');
|
||||
console.log(' 3. Force rsync: npm run sync-marketplace:force');
|
||||
console.log('');
|
||||
|
||||
Reference in New Issue
Block a user