openclawsetup 2.8.3 → 2.8.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.
- package/bin/cli.mjs +51 -5
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -856,6 +856,13 @@ function getDashboardToken(config) {
|
|
|
856
856
|
return extractAuthToken(config?.raw || '') || '';
|
|
857
857
|
}
|
|
858
858
|
|
|
859
|
+
function maskToken(token = '') {
|
|
860
|
+
if (!token || token === '<未配置>' || token === '<你的token>') return token;
|
|
861
|
+
const text = String(token);
|
|
862
|
+
if (text.length <= 8) return '***';
|
|
863
|
+
return `${text.slice(0, 4)}...${text.slice(-4)}`;
|
|
864
|
+
}
|
|
865
|
+
|
|
859
866
|
function parseStatusOutput(statusOutput) {
|
|
860
867
|
const text = (statusOutput || '').toLowerCase();
|
|
861
868
|
const stoppedRegex = [
|
|
@@ -1149,6 +1156,39 @@ function selectHealthPort(config, strongMode = false) {
|
|
|
1149
1156
|
return strongMode ? STRONG_PORT_CANDIDATES[0] : DEFAULT_GATEWAY_PORT;
|
|
1150
1157
|
}
|
|
1151
1158
|
|
|
1159
|
+
function parsePortFromText(raw = '') {
|
|
1160
|
+
const matches = String(raw).match(/\b(\d{2,5})\b/g) || [];
|
|
1161
|
+
for (const item of matches) {
|
|
1162
|
+
const port = Number(item);
|
|
1163
|
+
if (Number.isInteger(port) && port > 0 && port <= 65535) {
|
|
1164
|
+
return port;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
function getRuntimeGatewayPort(cliName, timeout = STATUS_CMD_TIMEOUT_MS) {
|
|
1171
|
+
if (!cliName) return null;
|
|
1172
|
+
const result = safeExec(`${cliName} config get gateway.port`, { timeout });
|
|
1173
|
+
if (!result.ok || !result.output) return null;
|
|
1174
|
+
return parsePortFromText(result.output);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
function resolveHealthPort(cliName, config, strongMode = false) {
|
|
1178
|
+
const runtimePort = getRuntimeGatewayPort(cliName);
|
|
1179
|
+
if (runtimePort) return { port: runtimePort, source: 'runtime' };
|
|
1180
|
+
|
|
1181
|
+
const candidate = Number(config?.port || DEFAULT_GATEWAY_PORT);
|
|
1182
|
+
if (Number.isInteger(candidate) && candidate > 0) {
|
|
1183
|
+
return { port: candidate, source: 'config' };
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
return {
|
|
1187
|
+
port: strongMode ? STRONG_PORT_CANDIDATES[0] : DEFAULT_GATEWAY_PORT,
|
|
1188
|
+
source: 'default',
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1152
1192
|
async function tryFixPortConflict(cliName, currentPort) {
|
|
1153
1193
|
const availablePort = await findAvailablePort(currentPort);
|
|
1154
1194
|
if (!availablePort || availablePort === currentPort) {
|
|
@@ -1909,8 +1949,9 @@ function showCompletionInfo(cliName) {
|
|
|
1909
1949
|
function showDashboardAccessInfo() {
|
|
1910
1950
|
const config = getConfigInfo();
|
|
1911
1951
|
const port = config.port || 18789;
|
|
1912
|
-
const
|
|
1913
|
-
const
|
|
1952
|
+
const tokenRaw = getDashboardToken(config) || '<你的token>';
|
|
1953
|
+
const tokenMasked = maskToken(tokenRaw);
|
|
1954
|
+
const dashboardUrl = `http://127.0.0.1:${port}/?token=${tokenMasked}`;
|
|
1914
1955
|
|
|
1915
1956
|
if (detectVps()) {
|
|
1916
1957
|
const serverIp = getServerIp() || '<服务器IP>';
|
|
@@ -2089,7 +2130,8 @@ async function runHealthCheck(cliName, autoFix = false, strongMode = false) {
|
|
|
2089
2130
|
console.log(colors.cyan('检查 Gateway 进程...'));
|
|
2090
2131
|
const statusProbe = probeGatewayStatus(activeCli, STATUS_CMD_TIMEOUT_MS);
|
|
2091
2132
|
const statusState = statusProbe.state;
|
|
2092
|
-
const
|
|
2133
|
+
const statusPortResolved = resolveHealthPort(activeCli, config, strongMode);
|
|
2134
|
+
const portForStatus = statusPortResolved.port;
|
|
2093
2135
|
const statusPortResult = getPortCheckOutput(portForStatus, PORT_CHECK_TIMEOUT_MS);
|
|
2094
2136
|
const statusPortListening = Boolean(statusPortResult.ok && statusPortResult.output);
|
|
2095
2137
|
|
|
@@ -2127,7 +2169,7 @@ async function runHealthCheck(cliName, autoFix = false, strongMode = false) {
|
|
|
2127
2169
|
|
|
2128
2170
|
// 4. 检查端口监听
|
|
2129
2171
|
config = getConfigInfo();
|
|
2130
|
-
let port =
|
|
2172
|
+
let port = resolveHealthPort(activeCli, config, strongMode).port;
|
|
2131
2173
|
console.log(colors.cyan(`检查端口监听 (${port})...`));
|
|
2132
2174
|
let portHealthy = false;
|
|
2133
2175
|
|
|
@@ -2408,7 +2450,8 @@ function testModelChat(cliName, timeoutMs = MODEL_CHAT_TIMEOUT_MS) {
|
|
|
2408
2450
|
|
|
2409
2451
|
async function showStatusInfo(cliName) {
|
|
2410
2452
|
const config = getConfigInfo();
|
|
2411
|
-
const
|
|
2453
|
+
const portResolved = resolveHealthPort(cliName, config, false);
|
|
2454
|
+
const port = portResolved.port;
|
|
2412
2455
|
const token = getDashboardToken(config) || '<未配置>';
|
|
2413
2456
|
const dashboardUrl = `http://127.0.0.1:${port}/?token=${token}`;
|
|
2414
2457
|
|
|
@@ -2449,6 +2492,9 @@ async function showStatusInfo(cliName) {
|
|
|
2449
2492
|
if (statusTimedOut) {
|
|
2450
2493
|
console.log(colors.yellow(' ⚠ 状态命令超时,已自动切换端口探测模式'));
|
|
2451
2494
|
}
|
|
2495
|
+
if (portResolved.source === 'runtime' && Number(config?.port) !== Number(port)) {
|
|
2496
|
+
console.log(colors.gray(` … 运行时端口为 ${port}(与本地配置文件不一致)`));
|
|
2497
|
+
}
|
|
2452
2498
|
|
|
2453
2499
|
if (statusState === 'running') {
|
|
2454
2500
|
console.log(colors.green(' ✓ Gateway 服务正在运行'));
|