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 };
}