codexmate 0.1.32 → 0.1.34
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/README.md +18 -2
- package/README.vi.md +18 -2
- package/README.zh.md +18 -2
- package/cli/claude-proxy.js +2 -2
- package/cli/local-bridge.js +10 -6
- package/cli/openai-chat-routing.js +38 -0
- package/cli/prompt-history.js +2 -0
- package/cli/routing-bridge.js +143 -0
- package/cli/system-prompt-files.js +75 -53
- package/cli.js +325 -215
- package/lib/cli-config-engine.js +6 -1
- package/lib/cli-file-utils.js +6 -1
- package/lib/config-change-fs.js +132 -0
- package/lib/config-changes.js +293 -0
- package/lib/file-sharing-lan.js +111 -0
- package/lib/file-sharing.js +196 -0
- package/lib/handoff-mcp.js +18 -2
- package/lib/local-feature-store.js +39 -0
- package/lib/model-test-client.js +61 -0
- package/lib/model-test.js +126 -0
- package/lib/routing-groups.js +161 -0
- package/lib/session-bookmarks.js +72 -0
- package/lib/session-context-health.js +23 -3
- package/lib/session-diagnostics.js +75 -0
- package/lib/session-feature-settings.js +21 -0
- package/lib/session-features.js +63 -0
- package/lib/session-handoff-draft.js +43 -0
- package/lib/session-projects.js +76 -0
- package/lib/session-search-index.js +188 -0
- package/lib/thread-handoff.js +8 -0
- package/lib/web-server.js +216 -0
- package/package.json +1 -1
- package/plugins/file-sharing/manifest.mjs +10 -0
- package/plugins/file-sharing/methods.mjs +101 -0
- package/plugins/file-sharing/overview.mjs +3 -0
- package/plugins/file-sharing/ownership.mjs +5 -0
- package/plugins/registry.mjs +3 -0
- package/web-ui/app.js +22 -3
- package/web-ui/index.html +4 -2
- package/web-ui/logic.context-window.mjs +15 -0
- package/web-ui/modules/api.mjs +72 -39
- package/web-ui/modules/app.computed.main-tabs.mjs +3 -0
- package/web-ui/modules/app.methods.agents.mjs +17 -0
- package/web-ui/modules/app.methods.claude-config.mjs +2 -0
- package/web-ui/modules/app.methods.codex-config.mjs +9 -0
- package/web-ui/modules/app.methods.config-changes.mjs +124 -0
- package/web-ui/modules/app.methods.install.mjs +23 -3
- package/web-ui/modules/app.methods.kilocode-config.mjs +2 -0
- package/web-ui/modules/app.methods.navigation.mjs +2 -0
- package/web-ui/modules/app.methods.openclaw-persist.mjs +2 -0
- package/web-ui/modules/app.methods.opencode-config.mjs +2 -0
- package/web-ui/modules/app.methods.pi-config.mjs +12 -3
- package/web-ui/modules/app.methods.prompts-editor.mjs +7 -4
- package/web-ui/modules/app.methods.provider-cache.mjs +9 -3
- package/web-ui/modules/app.methods.providers.mjs +6 -0
- package/web-ui/modules/app.methods.session-actions.mjs +2 -2
- package/web-ui/modules/app.methods.startup-claude.mjs +8 -47
- package/web-ui/modules/app.methods.system-prompt.mjs +88 -17
- package/web-ui/modules/app.methods.theme.mjs +4 -3
- package/web-ui/modules/app.methods.web-ui-preferences.mjs +7 -0
- package/web-ui/modules/config-change-actions.mjs +9 -0
- package/web-ui/modules/i18n/locales/en.mjs +254 -8
- package/web-ui/modules/i18n/locales/ja.mjs +254 -8
- package/web-ui/modules/i18n/locales/vi.mjs +254 -8
- package/web-ui/modules/i18n/locales/zh-tw.mjs +254 -8
- package/web-ui/modules/i18n/locales/zh.mjs +254 -8
- package/web-ui/modules/model-test.mjs +82 -0
- package/web-ui/modules/plugins.methods.mjs +3 -1
- package/web-ui/modules/prompt-ecosystem.methods.mjs +4 -3
- package/web-ui/modules/request-deadline.mjs +33 -0
- package/web-ui/modules/routing.mjs +206 -0
- package/web-ui/modules/session-features.mjs +279 -0
- package/web-ui/modules/thread-handoff.mjs +1 -1
- package/web-ui/partials/index/config-changes.html +25 -0
- package/web-ui/partials/index/context-window-reference.html +17 -0
- package/web-ui/partials/index/layout-header.html +40 -42
- package/web-ui/partials/index/modal-openclaw-config.html +0 -2
- package/web-ui/partials/index/modal-skills.html +0 -1
- package/web-ui/partials/index/modals-basic.html +15 -8
- package/web-ui/partials/index/modals-pi-provider.html +0 -1
- package/web-ui/partials/index/panel-config-codex.html +0 -3
- package/web-ui/partials/index/panel-config-openclaw.html +16 -13
- package/web-ui/partials/index/panel-dashboard.html +0 -2
- package/web-ui/partials/index/panel-plugins.html +3 -10
- package/web-ui/partials/index/panel-prompts.html +13 -8
- package/web-ui/partials/index/panel-routing.html +3 -0
- package/web-ui/partials/index/panel-sessions.html +9 -0
- package/web-ui/partials/index/panel-settings.html +12 -13
- package/web-ui/partials/index/panel-trash.html +0 -1
- package/web-ui/partials/index/plugin-file-sharing.html +47 -0
- package/web-ui/partials/index/routing-model-test.html +53 -0
- package/web-ui/partials/index/session-diagnostics.html +32 -0
- package/web-ui/partials/index/session-features.html +107 -0
- package/web-ui/partials/index/thread-handoff.html +6 -3
- package/web-ui/res/web-ui-render.precompiled.js +1689 -246
- package/web-ui/styles/base-theme.css +1 -1
- package/web-ui/styles/config-changes.css +30 -0
- package/web-ui/styles/modals-core.css +6 -5
- package/web-ui/styles/navigation-panels.css +4 -0
- package/web-ui/styles/openclaw-structured.css +205 -189
- package/web-ui/styles/plugins-panel.css +40 -1
- package/web-ui/styles/responsive.css +10 -5
- package/web-ui/styles/routing.css +78 -0
- package/web-ui/styles/session-features.css +258 -0
- package/web-ui/styles/settings-panel.css +30 -0
- package/web-ui/styles/system-prompt.css +8 -7
- package/web-ui/styles/theme-violet-tokens.css +52 -0
- package/web-ui/styles/theme-violet.css +1736 -0
- package/web-ui/styles.css +5 -1
package/cli.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const { createRoutingGroups, OPENAI_CHAT_TARGET } = require('./lib/routing-groups');
|
|
3
|
+
const { createRoutingBridgeHttpHandler, OPENAI_CHAT_BASE_PATH, OPENAI_CHAT_MODEL } = require('./cli/routing-bridge');
|
|
4
|
+
const { createOpenaiChatRoutingHandler } = require('./cli/openai-chat-routing');
|
|
5
|
+
const { fs, isConfigStaging, stageConfigWrites } = require('./lib/config-change-fs');
|
|
6
|
+
const { createConfigChanges } = require('./lib/config-changes');
|
|
3
7
|
const path = require('path');
|
|
4
8
|
const os = require('os');
|
|
5
9
|
const crypto = require('crypto');
|
|
@@ -46,6 +50,7 @@ const {
|
|
|
46
50
|
formatTimestampForFileName
|
|
47
51
|
} = require('./lib/cli-file-utils');
|
|
48
52
|
const { buildLineDiff } = require('./lib/text-diff');
|
|
53
|
+
const { createModelTestService } = require('./lib/model-test');
|
|
49
54
|
const { cmdThread, handleThreadAction } = require('./lib/thread-handoff');
|
|
50
55
|
const { createStartupAuth } = require('./lib/web-startup-auth');
|
|
51
56
|
const {
|
|
@@ -96,6 +101,7 @@ const {
|
|
|
96
101
|
executeWorkflowDefinition
|
|
97
102
|
} = require('./lib/workflow-engine');
|
|
98
103
|
const { createWorkflowRunner } = require('./lib/workflow-runner');
|
|
104
|
+
const { createWebServerLifecycle } = require('./lib/web-server');
|
|
99
105
|
const {
|
|
100
106
|
ALLOWED_EVENTS: WEBHOOK_ALLOWED_EVENTS,
|
|
101
107
|
defaultConfigPath: defaultWebhookConfigPath,
|
|
@@ -121,7 +127,7 @@ const {
|
|
|
121
127
|
resolveOpenaiBridgeUpstream
|
|
122
128
|
} = require('./cli/openai-bridge');
|
|
123
129
|
const {
|
|
124
|
-
createLocalBridgeHttpHandler
|
|
130
|
+
createLocalBridgeHttpHandler, buildUpstreamPool, buildClaudeUpstreamPool
|
|
125
131
|
} = require('./cli/local-bridge');
|
|
126
132
|
const {
|
|
127
133
|
createOpenclawConfigController
|
|
@@ -138,8 +144,12 @@ const {
|
|
|
138
144
|
const {
|
|
139
145
|
createPromptHistoryController
|
|
140
146
|
} = require('./cli/prompt-history');
|
|
147
|
+
const { createFileSharingRoutes } = require('./lib/file-sharing');
|
|
141
148
|
const { createPluginConfigController } = require('./cli/plugin-config');
|
|
142
149
|
const { createSessionContextHealthController } = require('./lib/session-context-health');
|
|
150
|
+
const { createSessionFeatures } = require('./lib/session-features');
|
|
151
|
+
const { listHandoffs } = require('./lib/thread-handoff');
|
|
152
|
+
const { discoverServers, probeServer } = require('./lib/handoff-mcp');
|
|
143
153
|
const {
|
|
144
154
|
createArchiveHelperController
|
|
145
155
|
} = require('./cli/archive-helpers');
|
|
@@ -435,6 +445,123 @@ const localBridgeHandler = createLocalBridgeHttpHandler({
|
|
|
435
445
|
httpsAgent: HTTPS_KEEP_ALIVE_AGENT
|
|
436
446
|
});
|
|
437
447
|
|
|
448
|
+
|
|
449
|
+
const routingGroups = createRoutingGroups({
|
|
450
|
+
filePath: path.join(CODEXMATE_DIR, 'routing-groups.json'),
|
|
451
|
+
assertAllowed: target => assertToolConfigWriteAllowed(target === OPENAI_CHAT_TARGET ? 'codex' : target),
|
|
452
|
+
catalog: getRoutingCatalog
|
|
453
|
+
});
|
|
454
|
+
const routingBridgeHandler = createRoutingBridgeHttpHandler({
|
|
455
|
+
groups: routingGroups,
|
|
456
|
+
maxBodySize: MAX_API_BODY_SIZE,
|
|
457
|
+
expectedToken: typeof process.env.CODEXMATE_HTTP_TOKEN === 'string' ? process.env.CODEXMATE_HTTP_TOKEN.trim() : '',
|
|
458
|
+
createHandler(target, member) {
|
|
459
|
+
if (target === OPENAI_CHAT_TARGET) {
|
|
460
|
+
const provider = readConfig().model_providers[member.name];
|
|
461
|
+
const settings = readOpenaiBridgeSettings(OPENAI_BRIDGE_SETTINGS_FILE);
|
|
462
|
+
const upstream = settings.providers && settings.providers[member.name];
|
|
463
|
+
const normalized = resolveOpenaiBridgeUpstream(OPENAI_BRIDGE_SETTINGS_FILE, member.name);
|
|
464
|
+
const configuredKey = !normalized.error && normalized.apiKey || upstream && upstream.apiKey || provider.experimental_bearer_token
|
|
465
|
+
|| (provider.env_key ? process.env[provider.env_key] : '');
|
|
466
|
+
const key = typeof configuredKey === 'string' ? configuredKey.trim() : '';
|
|
467
|
+
return createOpenaiChatRoutingHandler({
|
|
468
|
+
member, authorization: key ? (key.startsWith('Bearer ') ? key : `Bearer ${key}`) : '',
|
|
469
|
+
upstreamHeaders: normalized.error ? undefined : normalized.headers,
|
|
470
|
+
httpAgent: HTTP_KEEP_ALIVE_AGENT, httpsAgent: HTTPS_KEEP_ALIVE_AGENT
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
return createLocalBridgeHttpHandler({
|
|
474
|
+
readConfigFn: () => ({ model_providers: { [member.name]: {
|
|
475
|
+
base_url: member.baseUrl, preferred_auth_method: member.authMethod,
|
|
476
|
+
requires_openai_auth: member.requiresOpenaiAuth
|
|
477
|
+
} } }),
|
|
478
|
+
openaiBridgeFile: OPENAI_BRIDGE_SETTINGS_FILE,
|
|
479
|
+
claudeProvidersFile: CLAUDE_LOCAL_PROVIDERS_FILE,
|
|
480
|
+
readClaudeProviders: () => ({ providers: { [member.name]: member } }),
|
|
481
|
+
expectedToken: typeof process.env.CODEXMATE_HTTP_TOKEN === 'string' ? process.env.CODEXMATE_HTTP_TOKEN.trim() : '',
|
|
482
|
+
requestMaxRetries: 0,
|
|
483
|
+
maxBodySize: MAX_API_BODY_SIZE,
|
|
484
|
+
httpAgent: HTTP_KEEP_ALIVE_AGENT, httpsAgent: HTTPS_KEEP_ALIVE_AGENT
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
function getRoutingCatalog(target) {
|
|
490
|
+
let config;
|
|
491
|
+
const result = target === 'claude'
|
|
492
|
+
? buildClaudeUpstreamPool(CLAUDE_LOCAL_PROVIDERS_FILE, readClaudeLocalBridgeSettings().excludedProviders)
|
|
493
|
+
: buildUpstreamPool(() => { config = readConfig(); return config; }, OPENAI_BRIDGE_SETTINGS_FILE, readLocalBridgeSettings().excludedProviders);
|
|
494
|
+
const pool = result.pool || [];
|
|
495
|
+
if (target !== OPENAI_CHAT_TARGET) return pool;
|
|
496
|
+
return pool.map(entry => {
|
|
497
|
+
const marked = config.model_providers[entry.name].codexmate_bridge === 'openai';
|
|
498
|
+
if (!marked && !new URL(entry.baseUrl).pathname.startsWith('/bridge/openai/')) return entry;
|
|
499
|
+
const upstream = resolveOpenaiBridgeUpstream(OPENAI_BRIDGE_SETTINGS_FILE, entry.name);
|
|
500
|
+
if (upstream.error) return marked ? null : entry;
|
|
501
|
+
return { ...entry, baseUrl: upstream.baseUrl };
|
|
502
|
+
}).filter(Boolean);
|
|
503
|
+
}
|
|
504
|
+
const modelTests = createModelTestService({ providers: getModelTestProviders });
|
|
505
|
+
function getModelTestProviders(target) {
|
|
506
|
+
if (target === 'pi') {
|
|
507
|
+
const state = readPiModels();
|
|
508
|
+
if (state.error) throw new Error(state.error);
|
|
509
|
+
const apis = { 'openai-responses': 'responses', 'openai-completions': 'chat_completions' };
|
|
510
|
+
return Object.entries(state.providers).map(([name, provider]) => {
|
|
511
|
+
const key = typeof provider.apiKey === 'string' ? provider.apiKey.trim() : '';
|
|
512
|
+
const models = Array.isArray(provider.models) ? provider.models : [];
|
|
513
|
+
return { name, baseUrl: provider.baseUrl, api: apis[provider.api] || provider.api,
|
|
514
|
+
apiKey: process.env[key] || key, headers: provider.headers,
|
|
515
|
+
error: key.startsWith('!') ? '命令式凭据暂不支持真实测试,请使用已有环境变量配置' : '',
|
|
516
|
+
models: models.map(model => model.id).filter(id => typeof id === 'string' && id.trim()),
|
|
517
|
+
modelOptions: Object.fromEntries(models.filter(model => model && model.id).map(model => [model.id, {
|
|
518
|
+
api: apis[model.api || provider.api] || model.api || provider.api,
|
|
519
|
+
baseUrl: model.baseUrl || provider.baseUrl, headers: { ...provider.headers, ...model.headers },
|
|
520
|
+
maxTokens: model.maxTokens, compat: model.compat || provider.compat
|
|
521
|
+
}])) };
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
const config = readConfig();
|
|
525
|
+
const currentModels = readCurrentModels();
|
|
526
|
+
const savedModels = readModels();
|
|
527
|
+
return Object.entries(config.model_providers || {}).filter(([, provider]) => provider.base_url).map(([name, provider]) => {
|
|
528
|
+
const isBridge = provider.codexmate_bridge === 'openai' || provider.preferred_auth_method === 'openai-bridge';
|
|
529
|
+
const upstream = isBridge ? resolveOpenaiBridgeUpstream(OPENAI_BRIDGE_SETTINGS_FILE, name) : {};
|
|
530
|
+
const apiKey = upstream.apiKey || provider.experimental_bearer_token || (provider.env_key ? process.env[provider.env_key] : '');
|
|
531
|
+
const model = currentModels[name] || config.model || '';
|
|
532
|
+
return { name, models: [...new Set([model, ...savedModels].filter(Boolean))],
|
|
533
|
+
baseUrl: upstream.baseUrl || provider.base_url, apiKey,
|
|
534
|
+
headers: { ...provider.http_headers, ...Object.fromEntries(Object.entries(provider.env_http_headers || {})
|
|
535
|
+
.filter(([, variable]) => process.env[variable]).map(([header, variable]) => [header, process.env[variable]])), ...upstream.headers },
|
|
536
|
+
reasoningEffort: config.model_reasoning_effort, reasoningSummary: config.model_reasoning_summary,
|
|
537
|
+
verbosity: config.model_verbosity,
|
|
538
|
+
api: provider.codexmate_bridge === 'claude' ? 'unsupported' : upstream.targetApi || normalizeWireApi(provider.wire_api),
|
|
539
|
+
error: upstream.error || (provider.requires_openai_auth && !apiKey ? '登录凭据暂不支持此测试,请选择已配置 API Key 的供应商' : '') };
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
function getRoutingState() {
|
|
543
|
+
const state = routingGroups.read();
|
|
544
|
+
const catalogs = Object.fromEntries(['codex', 'claude', OPENAI_CHAT_TARGET].map(target => [target, getRoutingCatalog(target).map(entry => ({
|
|
545
|
+
name: entry.name, model: entry.model || '', origin: new URL(entry.baseUrl).origin
|
|
546
|
+
}))]));
|
|
547
|
+
const codex = getLocalBridgeStatus();
|
|
548
|
+
const claude = getClaudeLocalBridgeStatus();
|
|
549
|
+
return { ...state, catalogs, openaiChat: { basePath: OPENAI_CHAT_BASE_PATH, model: OPENAI_CHAT_MODEL, requiresToken: !!(process.env.CODEXMATE_HTTP_TOKEN || '').trim() }, bridges: {
|
|
550
|
+
codex: { enabled: codex.enabled, active: codex.active },
|
|
551
|
+
claude: { enabled: claude.enabled, active: claude.active },
|
|
552
|
+
[OPENAI_CHAT_TARGET]: { enabled: !!state.bindings[OPENAI_CHAT_TARGET], active: !!state.bindings[OPENAI_CHAT_TARGET] }
|
|
553
|
+
} };
|
|
554
|
+
}
|
|
555
|
+
function mutateRoutingGroup(operation, params) {
|
|
556
|
+
try {
|
|
557
|
+
if (configChanges.isBusy()) return { error: '已有配置变更正在执行', errorCode: 'config-change-busy' };
|
|
558
|
+
routingGroups[operation](params || {});
|
|
559
|
+
return { success: true, ...getRoutingState() };
|
|
560
|
+
} catch (error) {
|
|
561
|
+
return { error: error.message, errorCode: error.code || 'routing-storage-error' };
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
438
565
|
function resolveWebPort() {
|
|
439
566
|
const raw = process.env.CODEXMATE_PORT;
|
|
440
567
|
if (!raw) return DEFAULT_WEB_PORT;
|
|
@@ -1043,7 +1170,7 @@ function normalizeSettingsTabPreference(value) {
|
|
|
1043
1170
|
|
|
1044
1171
|
function normalizeMainTabPreference(value) {
|
|
1045
1172
|
const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
1046
|
-
const allowed = new Set(['dashboard', 'config', 'sessions', 'usage', 'market', 'plugins', 'docs', 'settings', 'trash', 'prompts']);
|
|
1173
|
+
const allowed = new Set(['dashboard', 'config', 'routing', 'sessions', 'usage', 'market', 'plugins', 'docs', 'settings', 'trash', 'prompts']);
|
|
1047
1174
|
return allowed.has(normalized) ? normalized : 'dashboard';
|
|
1048
1175
|
}
|
|
1049
1176
|
|
|
@@ -1081,7 +1208,7 @@ function normalizeSidebarCollapsedPreference(value) {
|
|
|
1081
1208
|
|
|
1082
1209
|
function normalizeThemePreference(value) {
|
|
1083
1210
|
const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
1084
|
-
return normalized === 'dark' || normalized === 'ocean' ? normalized : 'light';
|
|
1211
|
+
return normalized === 'dark' || normalized === 'ocean' || normalized === 'violet' ? normalized : 'light';
|
|
1085
1212
|
}
|
|
1086
1213
|
|
|
1087
1214
|
function normalizeSessionFilterSourcePreference(value) {
|
|
@@ -1169,6 +1296,7 @@ function normalizeWebUiPreferences(value = {}) {
|
|
|
1169
1296
|
navigation: {
|
|
1170
1297
|
mainTab: normalizeMainTabPreference(navigation.mainTab),
|
|
1171
1298
|
configMode: normalizeConfigModePreference(navigation.configMode),
|
|
1299
|
+
modelTestTarget: navigation.modelTestTarget === 'pi' ? 'pi' : 'codex',
|
|
1172
1300
|
settingsTab: normalizeSettingsTabPreference(navigation.settingsTab),
|
|
1173
1301
|
skillsTargetApp: navigation.skillsTargetApp === 'claude' || navigation.skillsTargetApp === 'pi'
|
|
1174
1302
|
? navigation.skillsTargetApp
|
|
@@ -1293,6 +1421,74 @@ function getApiToolConfigWriteTarget(action) {
|
|
|
1293
1421
|
return '';
|
|
1294
1422
|
}
|
|
1295
1423
|
|
|
1424
|
+
const CONFIG_CHANGE_ACTIONS = Object.freeze({
|
|
1425
|
+
'apply-config-template': 'codex', 'add-provider': 'codex', 'update-provider': 'codex',
|
|
1426
|
+
'delete-provider': 'codex', 'reset-config': 'codex', 'add-model': 'codex', 'delete-model': 'codex',
|
|
1427
|
+
'apply-claude-settings-raw': 'claude', 'apply-claude-config': 'claude',
|
|
1428
|
+
'apply-opencode-config': 'opencode', 'update-opencode-selection': 'opencode',
|
|
1429
|
+
'apply-kilocode-config': 'kilocode', 'apply-openclaw-config': 'openclaw',
|
|
1430
|
+
'write-pi-models': 'pi', 'write-pi-settings': 'pi', 'apply-pi-config-history': 'pi'
|
|
1431
|
+
});
|
|
1432
|
+
const CONFIG_CHANGE_READERS = Object.freeze({
|
|
1433
|
+
'get-config-template': { target: 'codex', read: getConfigTemplate },
|
|
1434
|
+
'get-claude-settings-raw': { target: 'claude', read: readClaudeSettingsRaw },
|
|
1435
|
+
'get-openclaw-config': { target: 'openclaw', read: params => readOpenclawConfigFile(params) },
|
|
1436
|
+
'get-opencode-config': { target: 'opencode', read: readOpencodeConfigInfo },
|
|
1437
|
+
'get-kilocode-config': { target: 'kilocode', read: readKilocodeConfigInfo },
|
|
1438
|
+
'read-pi-models': { target: 'pi', read: readPiModels },
|
|
1439
|
+
'read-pi-settings': { target: 'pi', read: readPiSettings }
|
|
1440
|
+
});
|
|
1441
|
+
const configChanges = createConfigChanges({
|
|
1442
|
+
journalPath: path.join(CODEXMATE_DIR, 'config-change-last.json'),
|
|
1443
|
+
getTarget: action => Object.prototype.hasOwnProperty.call(CONFIG_CHANGE_ACTIONS, action) ? CONFIG_CHANGE_ACTIONS[action] : '',
|
|
1444
|
+
isTarget: target => TOOL_CONFIG_PERMISSION_TARGETS.has(target),
|
|
1445
|
+
isAllowed: isToolConfigWriteAllowed,
|
|
1446
|
+
isPathAllowed(filePath) {
|
|
1447
|
+
if (OPENCODE_CONFIG_ENV_FILE && filePath === OPENCODE_CONFIG_ENV_FILE) return true;
|
|
1448
|
+
const roots = [CONFIG_DIR, CODEXMATE_DIR, CLAUDE_DIR, OPENCLAW_DIR, OPENCODE_CONFIG_DIR, KILOCODE_CONFIG_DIR, getPiAgentDir()];
|
|
1449
|
+
return roots.some(root => {
|
|
1450
|
+
const relative = path.relative(root, filePath);
|
|
1451
|
+
return relative && !relative.startsWith('..' + path.sep) && relative !== '..' && !path.isAbsolute(relative);
|
|
1452
|
+
});
|
|
1453
|
+
},
|
|
1454
|
+
execute(action, params) {
|
|
1455
|
+
const handlers = {
|
|
1456
|
+
'apply-config-template': applyConfigTemplate,
|
|
1457
|
+
'add-provider': values => addProviderToConfig({ ...values, requireModel: true }),
|
|
1458
|
+
'update-provider': updateProviderInConfig, 'delete-provider': deleteProviderFromConfig,
|
|
1459
|
+
'reset-config': resetConfigToDefault,
|
|
1460
|
+
'add-model': values => { cmdAddModel(values.model, true); return { success: true }; },
|
|
1461
|
+
'delete-model': values => { cmdDeleteModel(values.model, true); return { success: true }; },
|
|
1462
|
+
'apply-claude-settings-raw': applyClaudeSettingsRaw,
|
|
1463
|
+
'apply-claude-config': values => applyToClaudeSettings(values.config),
|
|
1464
|
+
'apply-opencode-config': applyOpencodeConfigRaw, 'update-opencode-selection': updateOpencodeSelection,
|
|
1465
|
+
'apply-kilocode-config': applyKilocodeConfig, 'apply-openclaw-config': applyOpenclawConfig,
|
|
1466
|
+
'write-pi-models': writePiModels, 'write-pi-settings': writePiSettings,
|
|
1467
|
+
'apply-pi-config-history': applyPiConfigHistory
|
|
1468
|
+
};
|
|
1469
|
+
return handlers[action](params);
|
|
1470
|
+
},
|
|
1471
|
+
beforeWrite(plan, entry) {
|
|
1472
|
+
if (plan.target !== 'pi') return;
|
|
1473
|
+
const bucket = path.basename(entry.path) === 'models.json' ? 'pi-models' : 'pi-settings';
|
|
1474
|
+
const backup = historyBackup(bucket, entry.path);
|
|
1475
|
+
if (backup && backup.error) throw new Error('保存 Pi 历史备份失败');
|
|
1476
|
+
},
|
|
1477
|
+
runtimeState(plan) {
|
|
1478
|
+
return plan.action === 'apply-claude-config' ? { running: getBuiltinClaudeProxyStatus().running === true } : null;
|
|
1479
|
+
},
|
|
1480
|
+
async reconcileRuntime(plan, rollback, state) {
|
|
1481
|
+
if (plan.action !== 'apply-claude-config') return;
|
|
1482
|
+
await stopBuiltinClaudeProxyRuntime();
|
|
1483
|
+
const saved = readJsonObjectFromFile(BUILTIN_CLAUDE_PROXY_SETTINGS_FILE, DEFAULT_BUILTIN_CLAUDE_PROXY_SETTINGS);
|
|
1484
|
+
if (!saved.ok) throw new Error('读取 Claude 兼容代理配置失败');
|
|
1485
|
+
if (rollback ? state && state.running : saved.data.enabled) {
|
|
1486
|
+
const result = await startBuiltinClaudeProxyRuntime(saved.data, { skipWrite: true });
|
|
1487
|
+
if (result.error) throw new Error('恢复 Claude 兼容代理失败');
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1296
1492
|
function getPiAgentDir() {
|
|
1297
1493
|
const homeDir = (typeof os.homedir === 'function' ? os.homedir() : null) || process.env.HOME || process.env.USERPROFILE || '';
|
|
1298
1494
|
return path.join(homeDir, '.pi', 'agent');
|
|
@@ -3013,6 +3209,7 @@ const {
|
|
|
3013
3209
|
});
|
|
3014
3210
|
|
|
3015
3211
|
const {
|
|
3212
|
+
listSystemPromptFiles,
|
|
3016
3213
|
readSystemPromptFile,
|
|
3017
3214
|
saveSystemPromptFile,
|
|
3018
3215
|
buildSystemPromptDiff
|
|
@@ -8099,6 +8296,9 @@ const {
|
|
|
8099
8296
|
});
|
|
8100
8297
|
|
|
8101
8298
|
const {
|
|
8299
|
+
saveBuiltinClaudeProxySettings,
|
|
8300
|
+
buildBuiltinClaudeProxyListenUrl,
|
|
8301
|
+
resolveBuiltinClaudeProxyUpstream,
|
|
8102
8302
|
startBuiltinClaudeProxyRuntime,
|
|
8103
8303
|
stopBuiltinClaudeProxyRuntime,
|
|
8104
8304
|
getBuiltinClaudeProxyStatus
|
|
@@ -9826,10 +10026,33 @@ async function extractMessagesFromFile(filePath, source, options = {}) {
|
|
|
9826
10026
|
return state;
|
|
9827
10027
|
}
|
|
9828
10028
|
|
|
9829
|
-
const { readSessionContextHealth, readSessionContextNode } = createSessionContextHealthController({
|
|
10029
|
+
const { readSessionContextHealth, readSessionContextNode, iterateSessionContextNodes } = createSessionContextHealthController({
|
|
9830
10030
|
fs, normalizeSessionSourceName, resolveSessionFilePath, queryOpencodeSessionMessages, queryZedSessionMessages
|
|
9831
10031
|
});
|
|
9832
10032
|
|
|
10033
|
+
const sessionFeatures = createSessionFeatures({ root: path.join(CODEXMATE_DIR, 'session-features'),
|
|
10034
|
+
readNode: readSessionContextNode, nodes: iterateSessionContextNodes,
|
|
10035
|
+
diagnostics: {
|
|
10036
|
+
home: os.homedir(),
|
|
10037
|
+
secrets: () => [readServerToken()],
|
|
10038
|
+
local: async () => {
|
|
10039
|
+
const report = await buildDoctorReport({ remote: false, includeInstall: false, includeUsage: false }, {
|
|
10040
|
+
getStatusPayload: buildMcpStatusPayload, buildConfigHealthReport, listSkills });
|
|
10041
|
+
return { ok: report.ok, issues: report.issues.map((item) => ({ id: item.id, severity: item.severity,
|
|
10042
|
+
problem: item.problem, impact: item.impact, actions: item.actions })),
|
|
10043
|
+
command: 'codexmate doctor --format md' };
|
|
10044
|
+
},
|
|
10045
|
+
provider: async () => {
|
|
10046
|
+
const report = await buildConfigHealthReport({ remote: true });
|
|
10047
|
+
return { ok: report.ok, issues: (report.issues || []).map((item) => ({ code: item.code, statusCode: item.statusCode })),
|
|
10048
|
+
command: 'codexmate doctor --format md' };
|
|
10049
|
+
},
|
|
10050
|
+
mcp: (name, options) => probeServer(name, options),
|
|
10051
|
+
mcpTargets: (cwd) => discoverServers({ cwd, allServers: true }).map((server) => server.name)
|
|
10052
|
+
},
|
|
10053
|
+
handoffs: (threadId) => listHandoffs(threadId),
|
|
10054
|
+
inventory: (source, limit) => listSessionInventoryBySource(source, limit, { scanCount: limit, maxFilesScanned: limit * 4 }, { forceRefresh: true }) });
|
|
10055
|
+
|
|
9833
10056
|
async function readSessionDetail(params = {}) {
|
|
9834
10057
|
const source = normalizeSessionSourceName(params.source, '');
|
|
9835
10058
|
if (!source) {
|
|
@@ -12373,9 +12596,9 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12373
12596
|
error: 'chat_completions 模式需要显式的上游 Base URL 或可解析的 provider 名称'
|
|
12374
12597
|
};
|
|
12375
12598
|
}
|
|
12376
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12599
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12377
12600
|
const proxyToken = crypto.randomBytes(24).toString('hex');
|
|
12378
|
-
|
|
12601
|
+
const proxyPayload = {
|
|
12379
12602
|
enabled: true,
|
|
12380
12603
|
host: DEFAULT_BUILTIN_CLAUDE_PROXY_SETTINGS.host,
|
|
12381
12604
|
provider: upstreamProviderName,
|
|
@@ -12385,9 +12608,18 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12385
12608
|
upstreamProviderName,
|
|
12386
12609
|
...(configuredBaseUrl ? { upstreamBaseUrl: configuredBaseUrl } : {}),
|
|
12387
12610
|
upstreamApiKey: apiKey
|
|
12388
|
-
}
|
|
12611
|
+
};
|
|
12612
|
+
if (isConfigStaging()) {
|
|
12613
|
+
const saved = saveBuiltinClaudeProxySettings(proxyPayload);
|
|
12614
|
+
if (saved.error) return { error: saved.error };
|
|
12615
|
+
const upstream = configuredBaseUrl ? null : resolveBuiltinClaudeProxyUpstream(saved.settings);
|
|
12616
|
+
if (upstream && upstream.error) return { error: upstream.error };
|
|
12617
|
+
proxyResult = { success: true, listenUrl: buildBuiltinClaudeProxyListenUrl(saved.settings), upstreamProvider: upstreamProviderName };
|
|
12618
|
+
} else {
|
|
12619
|
+
proxyResult = await startBuiltinClaudeProxyRuntime(proxyPayload);
|
|
12620
|
+
}
|
|
12389
12621
|
if (!proxyResult || proxyResult.error || proxyResult.success === false || !proxyResult.listenUrl) {
|
|
12390
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12622
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12391
12623
|
resetBuiltinClaudeProxySavedSettingsToResponses();
|
|
12392
12624
|
return {
|
|
12393
12625
|
success: false,
|
|
@@ -12399,14 +12631,14 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12399
12631
|
settingsBaseUrl = proxyResult.listenUrl;
|
|
12400
12632
|
settingsApiKey = proxyToken;
|
|
12401
12633
|
} else {
|
|
12402
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12634
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12403
12635
|
resetBuiltinClaudeProxySavedSettingsToResponses();
|
|
12404
12636
|
}
|
|
12405
12637
|
|
|
12406
12638
|
const readResult = readJsonObjectFromFile(CLAUDE_SETTINGS_FILE, {});
|
|
12407
12639
|
if (!readResult.ok) {
|
|
12408
12640
|
if (proxyStarted) {
|
|
12409
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12641
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12410
12642
|
resetBuiltinClaudeProxySavedSettingsToResponses();
|
|
12411
12643
|
}
|
|
12412
12644
|
return { success: false, mode: 'settings-file', error: readResult.error };
|
|
@@ -12469,7 +12701,7 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12469
12701
|
return result;
|
|
12470
12702
|
} catch (e) {
|
|
12471
12703
|
if (proxyStarted) {
|
|
12472
|
-
try { await stopBuiltinClaudeProxyRuntime(); } catch (_) {}
|
|
12704
|
+
try { if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime(); } catch (_) {}
|
|
12473
12705
|
try { resetBuiltinClaudeProxySavedSettingsToResponses(); } catch (_) {}
|
|
12474
12706
|
}
|
|
12475
12707
|
return {
|
|
@@ -14196,137 +14428,12 @@ const PUBLIC_WEB_UI_STATIC_ASSETS = new Set([
|
|
|
14196
14428
|
]);
|
|
14197
14429
|
|
|
14198
14430
|
function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser }) {
|
|
14199
|
-
|
|
14431
|
+
|
|
14432
|
+
const fileSharing = createFileSharingRoutes();
|
|
14200
14433
|
const startupAuth = createStartupAuth(readServerToken());
|
|
14201
14434
|
const httpToken = startupAuth.token;
|
|
14202
14435
|
const accessControlMiddleware = createWebAccessControlMiddleware(host);
|
|
14203
|
-
const probeWebUiReadiness = (callback) => {
|
|
14204
|
-
const payload = JSON.stringify({ action: 'health-check', params: {} });
|
|
14205
|
-
const requestOptions = {
|
|
14206
|
-
hostname: openHost,
|
|
14207
|
-
port,
|
|
14208
|
-
path: '/api',
|
|
14209
|
-
method: 'POST',
|
|
14210
|
-
headers: {
|
|
14211
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
14212
|
-
'Content-Length': Buffer.byteLength(payload, 'utf-8'),
|
|
14213
|
-
...(httpToken ? { Authorization: `Bearer ${httpToken}` } : {})
|
|
14214
|
-
}
|
|
14215
|
-
};
|
|
14216
|
-
let settled = false;
|
|
14217
|
-
const finish = (ready) => {
|
|
14218
|
-
if (settled) return;
|
|
14219
|
-
settled = true;
|
|
14220
|
-
callback(ready);
|
|
14221
|
-
};
|
|
14222
|
-
const req = http.request(requestOptions, (probeRes) => {
|
|
14223
|
-
if (typeof probeRes.resume === 'function') {
|
|
14224
|
-
probeRes.resume();
|
|
14225
|
-
}
|
|
14226
|
-
probeRes.on('end', () => {
|
|
14227
|
-
finish(probeRes.statusCode === 200);
|
|
14228
|
-
});
|
|
14229
|
-
});
|
|
14230
|
-
req.on('error', () => finish(false));
|
|
14231
|
-
req.setTimeout(1000, () => {
|
|
14232
|
-
try { req.destroy(); } catch (_) { }
|
|
14233
|
-
finish(false);
|
|
14234
|
-
});
|
|
14235
|
-
req.end(payload, 'utf-8');
|
|
14236
|
-
};
|
|
14237
|
-
const probeWebUiAssetReadiness = (callback) => {
|
|
14238
|
-
const requestOptions = {
|
|
14239
|
-
hostname: openHost,
|
|
14240
|
-
port,
|
|
14241
|
-
path: '/web-ui/app.js',
|
|
14242
|
-
method: 'GET',
|
|
14243
|
-
headers: httpToken ? { Authorization: `Bearer ${httpToken}` } : {}
|
|
14244
|
-
};
|
|
14245
|
-
let settled = false;
|
|
14246
|
-
const finish = (ready) => {
|
|
14247
|
-
if (settled) return;
|
|
14248
|
-
settled = true;
|
|
14249
|
-
callback(ready);
|
|
14250
|
-
};
|
|
14251
|
-
const req = http.request(requestOptions, (probeRes) => {
|
|
14252
|
-
if (typeof probeRes.resume === 'function') {
|
|
14253
|
-
probeRes.resume();
|
|
14254
|
-
}
|
|
14255
|
-
probeRes.on('end', () => {
|
|
14256
|
-
finish(probeRes.statusCode === 200);
|
|
14257
|
-
});
|
|
14258
|
-
});
|
|
14259
|
-
req.on('error', () => finish(false));
|
|
14260
|
-
req.setTimeout(1000, () => {
|
|
14261
|
-
try { req.destroy(); } catch (_) { }
|
|
14262
|
-
finish(false);
|
|
14263
|
-
});
|
|
14264
|
-
req.end();
|
|
14265
|
-
};
|
|
14266
|
-
const openBrowserAfterReady = (url) => {
|
|
14267
|
-
// Some environments may start the listener before the bundled web-ui assets
|
|
14268
|
-
// are ready for the first browser hit; wait until both API and assets respond.
|
|
14269
|
-
const maxAttempts = 120;
|
|
14270
|
-
const retryDelayMs = 200;
|
|
14271
|
-
let finished = false;
|
|
14272
|
-
|
|
14273
|
-
const finish = (ready) => {
|
|
14274
|
-
if (finished) return;
|
|
14275
|
-
finished = true;
|
|
14276
|
-
if (!ready) {
|
|
14277
|
-
console.warn('! Web UI 就绪探测超时,未自动打开浏览器,请手动访问:', url);
|
|
14278
|
-
return;
|
|
14279
|
-
}
|
|
14280
|
-
|
|
14281
|
-
const platform = process.platform;
|
|
14282
|
-
const commandSpec = platform === 'win32'
|
|
14283
|
-
? { command: 'cmd', args: ['/c', 'start', '', url] }
|
|
14284
|
-
: (platform === 'darwin'
|
|
14285
|
-
? { command: 'open', args: [url] }
|
|
14286
|
-
: { command: 'xdg-open', args: [url] });
|
|
14287
14436
|
|
|
14288
|
-
try {
|
|
14289
|
-
const child = spawn(commandSpec.command, commandSpec.args, {
|
|
14290
|
-
stdio: 'ignore',
|
|
14291
|
-
detached: true,
|
|
14292
|
-
windowsHide: true
|
|
14293
|
-
});
|
|
14294
|
-
child.on('error', () => {
|
|
14295
|
-
console.warn('无法自动打开浏览器,请手动访问:', url);
|
|
14296
|
-
});
|
|
14297
|
-
if (typeof child.unref === 'function') {
|
|
14298
|
-
child.unref();
|
|
14299
|
-
}
|
|
14300
|
-
} catch (_) {
|
|
14301
|
-
console.warn('无法自动打开浏览器,请手动访问:', url);
|
|
14302
|
-
}
|
|
14303
|
-
};
|
|
14304
|
-
const scheduleProbe = (attempt) => {
|
|
14305
|
-
probeWebUiReadiness((apiReady) => {
|
|
14306
|
-
if (!apiReady) {
|
|
14307
|
-
if (attempt >= maxAttempts) {
|
|
14308
|
-
finish(false);
|
|
14309
|
-
return;
|
|
14310
|
-
}
|
|
14311
|
-
setTimeout(() => scheduleProbe(attempt + 1), retryDelayMs);
|
|
14312
|
-
return;
|
|
14313
|
-
}
|
|
14314
|
-
probeWebUiAssetReadiness((assetReady) => {
|
|
14315
|
-
if (assetReady) {
|
|
14316
|
-
finish(true);
|
|
14317
|
-
return;
|
|
14318
|
-
}
|
|
14319
|
-
if (attempt >= maxAttempts) {
|
|
14320
|
-
finish(false);
|
|
14321
|
-
return;
|
|
14322
|
-
}
|
|
14323
|
-
setTimeout(() => scheduleProbe(attempt + 1), retryDelayMs);
|
|
14324
|
-
});
|
|
14325
|
-
});
|
|
14326
|
-
};
|
|
14327
|
-
|
|
14328
|
-
scheduleProbe(1);
|
|
14329
|
-
};
|
|
14330
14437
|
const writeWebUiAssetError = (res, requestPath, error) => {
|
|
14331
14438
|
const message = error && error.message ? error.message : String(error);
|
|
14332
14439
|
console.error(`! Web UI 资源读取失败 [${requestPath}]:`, message);
|
|
@@ -14381,6 +14488,7 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
14381
14488
|
});
|
|
14382
14489
|
res.end(body, 'utf-8');
|
|
14383
14490
|
};
|
|
14491
|
+
if (routingBridgeHandler(req, res)) return;
|
|
14384
14492
|
if (typeof localBridgeHandler === 'function' && localBridgeHandler(req, res)) {
|
|
14385
14493
|
return;
|
|
14386
14494
|
}
|
|
@@ -14421,6 +14529,10 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
14421
14529
|
}
|
|
14422
14530
|
}
|
|
14423
14531
|
}
|
|
14532
|
+
if (fileSharing.match(requestPath)) {
|
|
14533
|
+
fileSharing.serve(req, res, requestPath);
|
|
14534
|
+
return;
|
|
14535
|
+
}
|
|
14424
14536
|
if (requestPath === '/api/import-skills-zip') {
|
|
14425
14537
|
void handleImportSkillsZipUpload(req, res);
|
|
14426
14538
|
return;
|
|
@@ -14462,10 +14574,31 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
14462
14574
|
let result;
|
|
14463
14575
|
|
|
14464
14576
|
const guardedToolConfigTarget = getApiToolConfigWriteTarget(action);
|
|
14465
|
-
if (guardedToolConfigTarget &&
|
|
14577
|
+
if (guardedToolConfigTarget && configChanges.isBusy()) {
|
|
14578
|
+
result = { error: '已有配置变更正在执行', errorCode: 'config-change-busy' };
|
|
14579
|
+
} else if (guardedToolConfigTarget && !isToolConfigWriteAllowed(guardedToolConfigTarget)) {
|
|
14466
14580
|
result = buildToolConfigWriteDeniedPayload(guardedToolConfigTarget);
|
|
14581
|
+
} else if (Object.prototype.hasOwnProperty.call(CONFIG_CHANGE_READERS, action)) {
|
|
14582
|
+
const reader = CONFIG_CHANGE_READERS[action];
|
|
14583
|
+
const observed = await stageConfigWrites(() => reader.read(params || {}), { maxFileBytes: Infinity, allowSymlinks: true });
|
|
14584
|
+
result = { ...observed.result, configChangeTarget: reader.target, configChangeBaseline: observed.files.map(entry => ({ path: entry.path, exists: entry.before.exists, hash: entry.before.hash, mode: entry.before.mode })) };
|
|
14467
14585
|
} else {
|
|
14468
14586
|
switch (action) {
|
|
14587
|
+
case 'preview-config-change':
|
|
14588
|
+
result = await configChanges.preview(params || {});
|
|
14589
|
+
break;
|
|
14590
|
+
case 'apply-config-change':
|
|
14591
|
+
result = await configChanges.apply(params || {});
|
|
14592
|
+
if (result.change && result.change.action === 'apply-claude-config') {
|
|
14593
|
+
notifyWebhook('provider-switch', 'Claude provider configuration applied', { changeId: result.change.id }).catch(function () { });
|
|
14594
|
+
}
|
|
14595
|
+
break;
|
|
14596
|
+
case 'get-last-config-change':
|
|
14597
|
+
result = configChanges.last(params || {});
|
|
14598
|
+
break;
|
|
14599
|
+
case 'undo-config-change':
|
|
14600
|
+
result = await configChanges.undo(params || {});
|
|
14601
|
+
break;
|
|
14469
14602
|
case 'health-check':
|
|
14470
14603
|
result = { ok: true };
|
|
14471
14604
|
break;
|
|
@@ -14784,6 +14917,9 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
14784
14917
|
case 'apply-openclaw-workspace-file':
|
|
14785
14918
|
result = applyOpenclawWorkspaceFile(params || {});
|
|
14786
14919
|
break;
|
|
14920
|
+
case 'list-system-prompt-files':
|
|
14921
|
+
result = listSystemPromptFiles(params || {});
|
|
14922
|
+
break;
|
|
14787
14923
|
case 'get-system-prompt':
|
|
14788
14924
|
result = readSystemPromptFile(params || {});
|
|
14789
14925
|
break;
|
|
@@ -15049,6 +15185,27 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
15049
15185
|
case 'thread-handoff-ack':
|
|
15050
15186
|
result = await handleThreadAction(action, params || {});
|
|
15051
15187
|
break;
|
|
15188
|
+
case 'session-diagnostics-targets':
|
|
15189
|
+
case 'session-diagnostics-start':
|
|
15190
|
+
case 'session-diagnostics-status':
|
|
15191
|
+
case 'session-diagnostics-cancel':
|
|
15192
|
+
case 'session-feature-settings-get':
|
|
15193
|
+
case 'session-feature-settings-save':
|
|
15194
|
+
case 'session-projects':
|
|
15195
|
+
case 'session-project-map':
|
|
15196
|
+
case 'session-project-prompt':
|
|
15197
|
+
case 'session-handoff-draft':
|
|
15198
|
+
case 'session-index-status':
|
|
15199
|
+
case 'session-index-refresh':
|
|
15200
|
+
case 'session-index-cancel':
|
|
15201
|
+
case 'session-index-search':
|
|
15202
|
+
case 'session-index-node':
|
|
15203
|
+
case 'session-bookmarks-list':
|
|
15204
|
+
case 'session-bookmark-save':
|
|
15205
|
+
case 'session-bookmark-remove':
|
|
15206
|
+
case 'session-bookmark-locate':
|
|
15207
|
+
result = await sessionFeatures.handle(action, params || {});
|
|
15208
|
+
break;
|
|
15052
15209
|
case 'session-context-health':
|
|
15053
15210
|
result = await readSessionContextHealth(params || {});
|
|
15054
15211
|
break;
|
|
@@ -15125,6 +15282,24 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
15125
15282
|
case 'proxy-apply-provider':
|
|
15126
15283
|
result = applyBuiltinProxyProvider(params || {});
|
|
15127
15284
|
break;
|
|
15285
|
+
case 'model-test-catalog':
|
|
15286
|
+
result = { catalogs: modelTests.catalog() };
|
|
15287
|
+
break;
|
|
15288
|
+
case 'model-test-run':
|
|
15289
|
+
result = await modelTests.run(params || {});
|
|
15290
|
+
break;
|
|
15291
|
+
case 'routing-get':
|
|
15292
|
+
result = getRoutingState();
|
|
15293
|
+
break;
|
|
15294
|
+
case 'routing-save':
|
|
15295
|
+
result = mutateRoutingGroup('save', params);
|
|
15296
|
+
break;
|
|
15297
|
+
case 'routing-delete':
|
|
15298
|
+
result = mutateRoutingGroup('remove', params);
|
|
15299
|
+
break;
|
|
15300
|
+
case 'routing-bind':
|
|
15301
|
+
result = mutateRoutingGroup('bind', params);
|
|
15302
|
+
break;
|
|
15128
15303
|
case 'local-bridge-toggle':
|
|
15129
15304
|
result = toggleLocalBridgeProvider(params || {});
|
|
15130
15305
|
break;
|
|
@@ -15414,83 +15589,18 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
15414
15589
|
handleRequest(req, res);
|
|
15415
15590
|
}));
|
|
15416
15591
|
});
|
|
15417
|
-
|
|
15418
|
-
|
|
15419
|
-
|
|
15420
|
-
|
|
15421
|
-
});
|
|
15422
|
-
|
|
15423
|
-
const printPortOverrideHint = () => {
|
|
15424
|
-
const examplePort = port === 8080 ? 8081 : 8080;
|
|
15425
|
-
console.error(` 临时换端口(macOS/Linux): CODEXMATE_PORT=${examplePort} codexmate run`);
|
|
15426
|
-
console.error(` 临时换端口(Windows PowerShell): $env:CODEXMATE_PORT=${examplePort}; codexmate run`);
|
|
15427
|
-
console.error(` 临时换端口(Windows CMD): set CODEXMATE_PORT=${examplePort} && codexmate run`);
|
|
15428
|
-
};
|
|
15429
|
-
|
|
15430
|
-
server.once('error', (err) => {
|
|
15431
|
-
if (err && err.code === 'EADDRINUSE') {
|
|
15432
|
-
console.error(`! 启动失败: 端口 ${port} 已被占用,可能有残留的 codexmate run 实例。`);
|
|
15433
|
-
console.error(' 请先停止旧实例或更换端口后重试。');
|
|
15434
|
-
printPortOverrideHint();
|
|
15435
|
-
} else if (err && err.code === 'EACCES') {
|
|
15436
|
-
console.error(`! 启动失败: 没有权限监听 ${host}:${port}。`);
|
|
15437
|
-
console.error(' 请检查系统/安全软件限制,或更换端口后重试。');
|
|
15438
|
-
printPortOverrideHint();
|
|
15439
|
-
} else {
|
|
15440
|
-
console.error('! 启动 Web UI 失败:', err && err.message ? err.message : err);
|
|
15441
|
-
}
|
|
15442
|
-
process.exit(1);
|
|
15443
|
-
});
|
|
15444
|
-
|
|
15445
|
-
const openHost = host === '::'
|
|
15446
|
-
? '::1'
|
|
15447
|
-
: (host === '0.0.0.0' ? DEFAULT_WEB_OPEN_HOST : host);
|
|
15448
|
-
const openUrl = `http://${formatHostForUrl(openHost)}:${port}/?token=${encodeURIComponent(httpToken)}`;
|
|
15449
|
-
server.listen(port, host, () => {
|
|
15450
|
-
getUnattendedWorkflowRunner().recover();
|
|
15451
|
-
console.log('\n✓ Web UI 已启动');
|
|
15452
|
-
const willOpenBrowser = !!openBrowser && !process.env.CODEXMATE_NO_BROWSER;
|
|
15453
|
-
console.log(` ${willOpenBrowser ? '已打开' : '待访问'}: ${openUrl}`);
|
|
15454
|
-
if (host && host !== openHost) {
|
|
15455
|
-
console.log(' 监听地址:', host);
|
|
15456
|
-
}
|
|
15457
|
-
console.log(' 退出: Ctrl+C\n');
|
|
15458
|
-
if (isAnyAddressHost(host)) {
|
|
15459
|
-
console.warn('! 安全提示: 当前监听所有网卡,局域网访问需要访问令牌。');
|
|
15460
|
-
console.warn(' 远程 /bridge/ 请求需携带 Authorization: Bearer <访问令牌>。');
|
|
15461
|
-
const allowedIps = (process.env.CODEXMATE_ALLOWED_IPS || '').trim();
|
|
15462
|
-
if (allowedIps) {
|
|
15463
|
-
console.warn(` 已启用的来源 IP 白名单: ${allowedIps}`);
|
|
15464
|
-
}
|
|
15465
|
-
}
|
|
15466
|
-
|
|
15467
|
-
if (willOpenBrowser) {
|
|
15468
|
-
openBrowserAfterReady(openUrl);
|
|
15469
|
-
}
|
|
15592
|
+
const lifecycle = createWebServerLifecycle({ server, host, port, httpToken, openBrowser }, {
|
|
15593
|
+
http, process, console, setTimeout, formatHostForUrl, DEFAULT_WEB_OPEN_HOST, isAnyAddressHost,
|
|
15594
|
+
spawn: (...args) => spawn(...args),
|
|
15595
|
+
getUnattendedWorkflowRunner: () => getUnattendedWorkflowRunner()
|
|
15470
15596
|
});
|
|
15471
|
-
|
|
15472
|
-
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
|
|
15476
|
-
done = true;
|
|
15477
|
-
for (const socket of connections) {
|
|
15478
|
-
try { socket.destroy(); } catch (_) { }
|
|
15479
|
-
}
|
|
15480
|
-
connections.clear();
|
|
15481
|
-
resolve();
|
|
15482
|
-
};
|
|
15483
|
-
|
|
15484
|
-
if (!server.listening) {
|
|
15485
|
-
finish();
|
|
15486
|
-
return;
|
|
15597
|
+
return {
|
|
15598
|
+
...lifecycle,
|
|
15599
|
+
async stop() {
|
|
15600
|
+
await lifecycle.stop();
|
|
15601
|
+
await fileSharing.dispose().catch(() => console.warn('! 文件共享临时目录清理失败'));
|
|
15487
15602
|
}
|
|
15488
|
-
|
|
15489
|
-
server.close(() => finish());
|
|
15490
|
-
setTimeout(() => finish(), 800);
|
|
15491
|
-
});
|
|
15492
|
-
|
|
15493
|
-
return { server, stop };
|
|
15603
|
+
};
|
|
15494
15604
|
}
|
|
15495
15605
|
|
|
15496
15606
|
// Region markers are used by unit tests that extract these helpers directly.
|