feat: improve codex app controls and recovery

This commit is contained in:
shiyue
2026-06-15 13:22:36 +08:00
parent 3a4006b7d3
commit ed3238fa49
8 changed files with 448 additions and 29 deletions

View File

@@ -1,5 +1,10 @@
'use strict';
const CODEX_APP_ONCE_NOTICE_PATTERNS = [
/^Under-development features enabled:/i,
/^Heads up: Long threads and multiple compactions/i,
];
function createCodexAppRuntime(deps = {}) {
const {
wsSend,
@@ -14,6 +19,23 @@ function createCodexAppRuntime(deps = {}) {
return text.length > maxLen ? `${text.slice(0, maxLen)}...` : value;
}
const shownOnceNoticeKeys = new Set();
function normalizeNoticeMessage(message) {
return String(message || '').trim().replace(/\s+/g, ' ');
}
function shouldShowRuntimeNotice(method, message) {
const normalized = normalizeNoticeMessage(message);
const isOnceNotice = CODEX_APP_ONCE_NOTICE_PATTERNS.some((pattern) => pattern.test(normalized));
if (!isOnceNotice) return true;
const key = `${method}:${normalized}`;
if (shownOnceNoticeKeys.has(key)) return false;
shownOnceNoticeKeys.add(key);
return true;
}
function sendRuntime(entry, sessionId, payload) {
wsSend(entry.ws, { ...payload, sessionId });
}
@@ -483,7 +505,9 @@ function createCodexAppRuntime(deps = {}) {
const message = params.message || params.title || '';
if (message) {
if (method === 'error') entry.lastError = message;
sendRuntime(entry, sessionId, { type: 'system_message', message });
if (method === 'error' || shouldShowRuntimeNotice(method, message)) {
sendRuntime(entry, sessionId, { type: 'system_message', message });
}
}
return { done: false };
}

View File

@@ -133,6 +133,10 @@ function createCodexAppServerClient(options = {}) {
sendRaw({ method, params });
}
function reloadMcpServers() {
return request('config/mcpServer/reload', {}, 30000);
}
function start() {
if (initPromise) return initPromise;
exited = false;
@@ -212,6 +216,7 @@ function createCodexAppServerClient(options = {}) {
stop,
request,
notification,
reloadMcpServers,
isRunning,
pid: () => proc?.pid || null,
};