mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-05 01:29:32 +01:00
fix(preview): COD-152 address upstream review
This commit is contained in:
1 parent
ac4ab8cf23
commit
b02816c1cc
13 files changed
+368
-53
No files matched your search
+48
-18
@@ -3211,9 +3211,11 @@ class CodemanApp {
|
||||
const backdrop = document.getElementById('responseViewerBackdrop');
|
||||
viewer.classList.remove('visible');
|
||||
if (backdrop) backdrop.classList.remove('visible');
|
||||
if (this.terminal) {
|
||||
const terminal = this._responseViewerReturnTerminal;
|
||||
this._responseViewerReturnTerminal = null;
|
||||
if (terminal && terminal.element?.isConnected !== false && this._shouldFocusTerminalForTabSwitch()) {
|
||||
try {
|
||||
this.terminal.focus();
|
||||
terminal.focus();
|
||||
} catch {
|
||||
/* terminal may be detached mid-teardown */
|
||||
}
|
||||
@@ -3221,14 +3223,35 @@ class CodemanApp {
|
||||
return true;
|
||||
}
|
||||
|
||||
_findCodexResponseFile(messages, label, session, sidebar = false) {
|
||||
_supportsCodexResponseFiles(sessionId) {
|
||||
const mode = this.sessions?.get(sessionId)?.mode;
|
||||
return window.__codemanCliCatalog?.find((entry) => entry.id === mode)?.transcript === 'codex-rollout';
|
||||
}
|
||||
|
||||
_findCodexResponseFile(messages, label, sessionId, sidebar = false) {
|
||||
const [prefix, suffix, ...extra] = sidebar ? label.split('…') : [];
|
||||
const abbreviated = Boolean(prefix && suffix && extra.length === 0);
|
||||
const containsFilename = (text) => abbreviated ? text.includes(prefix) && text.includes(suffix) : text.includes(label);
|
||||
let match = null;
|
||||
for (const message of messages) {
|
||||
if (message.role !== 'assistant' || typeof message.text !== 'string' || (!sidebar && !message.text.includes(label))) continue;
|
||||
const { text } = message;
|
||||
if (message.role !== 'assistant' || typeof text !== 'string') continue;
|
||||
if (sidebar && !containsFilename(text)) {
|
||||
// Markdown destinations can URI-encode the filename. Leave Markdown
|
||||
// escapes and HTML entities to the renderer when present.
|
||||
const decoded = text.replace(/(?:%[\da-f]{2})+/gi, (escapes) => {
|
||||
try {
|
||||
return decodeURIComponent(escapes);
|
||||
} catch {
|
||||
return escapes;
|
||||
}
|
||||
});
|
||||
if (!containsFilename(decoded) && !/\\[!-~]|&(?:#\w+|[a-z]+);/i.test(decoded)) continue;
|
||||
} else if (!sidebar && !text.includes(label)) {
|
||||
continue;
|
||||
}
|
||||
const rendered = document.createElement('template');
|
||||
rendered.innerHTML = this._renderMarkdown(message.text, { localFileLinks: true });
|
||||
rendered.innerHTML = this._renderMarkdown(text, { localFileLinks: true });
|
||||
const links = Array.from(rendered.content.querySelectorAll('a')).filter(
|
||||
(link) => sidebar || link.textContent.trim() === label
|
||||
);
|
||||
@@ -3236,7 +3259,7 @@ class CodemanApp {
|
||||
|
||||
this._linkifyFilePaths(rendered.content);
|
||||
for (const link of links) {
|
||||
const path = resolveLinkedFilePath(link.dataset.path, session.workingDir);
|
||||
const path = this._resolveLinkedFilePath(link.dataset.path, sessionId);
|
||||
if (sidebar) {
|
||||
const basename = path.split('/').pop();
|
||||
// Codex preserves both ends of a filename when it shortens the tab.
|
||||
@@ -3257,11 +3280,12 @@ class CodemanApp {
|
||||
}
|
||||
|
||||
_openResponseFile(path, sessionId) {
|
||||
if (this.filePreviewEdit?.dirty && !confirm('Discard unsaved changes?')) return;
|
||||
const discard = 'Discard unsaved changes?';
|
||||
if (this.filePreviewEdit?.dirty && !confirm(window.codemanT?.(discard) || discard)) return;
|
||||
return this.openFilePreview(path, sessionId, null, { dock: true });
|
||||
}
|
||||
|
||||
_renderResponseFiles(body, responses, sessionId, session) {
|
||||
_renderResponseFiles(body, responses, sessionId) {
|
||||
const list = document.createElement('ul');
|
||||
const seen = new Set();
|
||||
for (const response of responses) {
|
||||
@@ -3270,7 +3294,7 @@ class CodemanApp {
|
||||
this._linkifyFilePaths(rendered.content);
|
||||
for (const link of rendered.content.querySelectorAll('a.rv-path')) {
|
||||
if (link.dataset.folder) continue;
|
||||
const path = resolveLinkedFilePath(link.dataset.path, session.workingDir);
|
||||
const path = this._resolveLinkedFilePath(link.dataset.path, sessionId);
|
||||
if (!/^\/(?!\/)/.test(path) || !previewsInFileViewer(path) || seen.has(path)) continue;
|
||||
seen.add(path);
|
||||
const item = document.createElement('li');
|
||||
@@ -3289,7 +3313,10 @@ class CodemanApp {
|
||||
}
|
||||
}
|
||||
if (seen.size) body.replaceChildren(list);
|
||||
else body.textContent = 'No previewable files in the latest response.';
|
||||
else {
|
||||
const empty = 'No previewable files in the latest response.';
|
||||
body.textContent = window.codemanT?.(empty) || empty;
|
||||
}
|
||||
}
|
||||
|
||||
async toggleResponseViewer(filesOnly = false) {
|
||||
@@ -3306,7 +3333,8 @@ class CodemanApp {
|
||||
if (!this.activeSessionId) return;
|
||||
const responseSessionId = this.activeSessionId;
|
||||
const session = this.sessions?.get?.(responseSessionId);
|
||||
if (filesOnly && session?.mode !== 'codex') return;
|
||||
if (filesOnly && !this._supportsCodexResponseFiles(responseSessionId)) return;
|
||||
const returnTerminal = isOpen ? this._responseViewerReturnTerminal : this._focusedPane?.().terminal;
|
||||
const request = Symbol('response-viewer');
|
||||
this._responseViewerRequest = request;
|
||||
try {
|
||||
@@ -3352,7 +3380,7 @@ class CodemanApp {
|
||||
const body = document.getElementById('responseViewerBody');
|
||||
if (filesOnly) {
|
||||
const responses = turnMessages.length ? turnMessages.map((message) => message.text) : [lastResponse];
|
||||
this._renderResponseFiles(body, responses, responseSessionId, session);
|
||||
this._renderResponseFiles(body, responses, responseSessionId);
|
||||
} else if (turnMessages.length > 0) {
|
||||
// The whole last turn, rendered exactly as the full view renders that
|
||||
// turn: one badge, then badge-less continuation segments. The same
|
||||
@@ -3383,13 +3411,14 @@ class CodemanApp {
|
||||
const title = document.getElementById('responseViewerTitle');
|
||||
const moreBtn = document.getElementById('responseViewerMore');
|
||||
viewer.dataset.filesOnly = String(filesOnly);
|
||||
if (title) title.textContent = filesOnly ? 'Response files' : 'Last Response';
|
||||
const titleText = filesOnly ? 'Response files' : 'Last Response';
|
||||
if (title) title.textContent = window.codemanT?.(titleText) || titleText;
|
||||
if (moreBtn) {
|
||||
moreBtn.style.display = data.hasContext ? '' : 'none';
|
||||
moreBtn.textContent = 'More';
|
||||
moreBtn.style.display = '';
|
||||
moreBtn.textContent = window.codemanT?.('More') || 'More';
|
||||
}
|
||||
// Last Response is a single rendered block, not a transcript — no filters here.
|
||||
|
||||
this._responseViewerReturnTerminal = returnTerminal;
|
||||
viewer.classList.add('visible');
|
||||
backdrop.classList.add('visible');
|
||||
// A multi-row turn opens at its NEWEST text, matching loadFullContext's
|
||||
@@ -3401,7 +3430,8 @@ class CodemanApp {
|
||||
} catch (err) {
|
||||
console.error('Failed to load response:', err);
|
||||
if (filesOnly && this._responseViewerRequest === request && this.activeSessionId === responseSessionId) {
|
||||
this.showToast('Unable to load response files', 'error');
|
||||
const message = 'Unable to load response files';
|
||||
this.showToast(window.codemanT?.(message) || message, 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6572,7 +6602,7 @@ class CodemanApp {
|
||||
|
||||
renderSessionTabs({ immediate = false } = {}) {
|
||||
const responseFilesButton = this.$('responseFilesBtn');
|
||||
if (responseFilesButton) responseFilesButton.hidden = this.sessions.get(this.activeSessionId)?.mode !== 'codex';
|
||||
if (responseFilesButton) responseFilesButton.hidden = !this._supportsCodexResponseFiles(this.activeSessionId);
|
||||
// Don't re-render while user is typing in the inline rename input
|
||||
if (this._inlineRenameActive) return;
|
||||
if (immediate) {
|
||||
|
||||
@@ -244,6 +244,12 @@
|
||||
'No response yet — send a message in this session first.': '暂无回复,请先在此会话中发送一条消息。',
|
||||
'No full conversation history available for this session': '此会话没有可显示的完整对话历史',
|
||||
'Last Response': '最近一次回复',
|
||||
'Response files': '回复中的文件',
|
||||
'Open Codex response files': '打开 Codex 回复中的文件',
|
||||
'Dock preview': '停靠预览',
|
||||
'No previewable files in the latest response.': '最新回复中没有可预览的文件。',
|
||||
'Unable to load response files': '无法加载回复中的文件',
|
||||
'Discard unsaved changes?': '放弃未保存的更改?',
|
||||
More: '更多',
|
||||
'Copy Markdown': '复制 Markdown',
|
||||
'Copy response as Markdown': '将回复复制为 Markdown',
|
||||
|
||||
@@ -3762,10 +3762,16 @@ Object.assign(CodemanApp.prototype, {
|
||||
|
||||
_setFilePreviewDocked(dock) {
|
||||
const overlay = this.$('filePreviewOverlay');
|
||||
if (!overlay || dock === overlay.classList.contains('is-docked')) return;
|
||||
if (!overlay) return;
|
||||
const terminalWrap = this.$('terminalContainer')?.closest('.terminal-wrap');
|
||||
dock = Boolean(
|
||||
dock &&
|
||||
terminalWrap?.parentElement?.matches('.main:not(.tiles-active, .webview-active)') &&
|
||||
window.matchMedia?.('(min-width: 1180px)').matches
|
||||
);
|
||||
if (dock === overlay.classList.contains('is-docked')) return;
|
||||
if (dock) {
|
||||
const terminalWrap = this.$('terminalContainer')?.closest('.terminal-wrap');
|
||||
if (!terminalWrap || !overlay.parentElement) return;
|
||||
if (!overlay.parentElement) return;
|
||||
this._filePreviewOverlayHome = overlay.parentElement;
|
||||
terminalWrap.after(overlay);
|
||||
} else {
|
||||
|
||||
@@ -4179,8 +4179,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
/** Keep the launch surfaces in sync with Settings mutations without a reload. */
|
||||
_syncCliLaunchCatalog() {
|
||||
if (!Array.isArray(this._cliList) || this._cliList.length === 0) return;
|
||||
// /api/clis rows carry no capabilities, so keep the served catalog's `external`
|
||||
// (isExternalCliSession() reads it). A new custom CLI has none and falls back to `kind`.
|
||||
// /api/clis rows carry no capabilities, so retain them from the served catalog.
|
||||
const previous = new Map(
|
||||
(Array.isArray(window.__codemanCliCatalog) ? window.__codemanCliCatalog : []).map((cli) => [cli.id, cli])
|
||||
);
|
||||
@@ -4191,6 +4190,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
order: cli.order,
|
||||
kind: cli.kind,
|
||||
external: previous.get(cli.id)?.external,
|
||||
transcript: previous.get(cli.id)?.transcript,
|
||||
enabled: cli.enabled,
|
||||
available: cli.kind === 'shell' || (cli.enabled && cli.installed),
|
||||
}));
|
||||
|
||||
@@ -13647,7 +13647,7 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
|
||||
}
|
||||
|
||||
#responseFilesBtn[hidden],
|
||||
.response-viewer[data-files-only='true'] :is(#responseViewerMore, #responseViewerCopy, #responseViewerCopyMarkdown) {
|
||||
.response-viewer[data-files-only='true'] :is(#responseViewerMore, #responseViewerCopyMarkdown) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,6 +207,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
headerA.el.classList.add('terminal-pane-a-header');
|
||||
this._splitHeaders = { a: headerA, b: headerB };
|
||||
|
||||
this._setFilePreviewDocked?.(false);
|
||||
parent.insertBefore(container, wrap);
|
||||
wrap.insertBefore(headerA.el, wrap.firstChild);
|
||||
container.appendChild(wrap);
|
||||
|
||||
@@ -2553,7 +2553,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
if (self.sessions?.get(getSessionId())?.mode === 'codex') {
|
||||
if (self._supportsCodexResponseFiles?.(getSessionId())) {
|
||||
const sidebar = codexSidebarFileRow(terminal, bufferLineNumber - 1);
|
||||
if (sidebar) {
|
||||
const lineEnd = bufferLineNumber * terminal.cols + terminal.cols;
|
||||
@@ -6569,7 +6569,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
return label && label.length <= 240 ? { label, row, start, end } : null;
|
||||
},
|
||||
|
||||
async _openCodexTerminalResponseFile(terminal, sessionId, session, point, clicked, stillCurrent, forward) {
|
||||
async _openCodexTerminalResponseFile(terminal, sessionId, point, clicked, stillCurrent, forward) {
|
||||
let path;
|
||||
try {
|
||||
const response = await fetch(`/api/sessions/${encodeURIComponent(sessionId)}/last-response?context=full`, {
|
||||
@@ -6577,7 +6577,10 @@ Object.assign(CodemanApp.prototype, {
|
||||
});
|
||||
if (response.ok) {
|
||||
const { data } = await response.json();
|
||||
if (Array.isArray(data?.messages)) path = this._findCodexResponseFile(data.messages, clicked.label, session, clicked.sidebar);
|
||||
if (!stillCurrent()) return;
|
||||
if (Array.isArray(data?.messages)) {
|
||||
path = this._findCodexResponseFile(data.messages, clicked.label, sessionId, clicked.sidebar);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Preserve the native click if the transcript cannot be resolved.
|
||||
@@ -6620,7 +6623,6 @@ Object.assign(CodemanApp.prototype, {
|
||||
if (performance.now() <= (this._trustedTapMouseSuppressUntil || 0)) return;
|
||||
if (!ev.target?.closest?.('.xterm-screen')) return;
|
||||
const sessionId = target.sessionId || this.activeSessionId;
|
||||
const session = this.sessions?.get(sessionId);
|
||||
const { clientX, clientY } = ev;
|
||||
const forward = () => {
|
||||
if (this._shouldReportMouseToCli(sessionId)) this._sendSyntheticSgrTap(clientX, clientY, target);
|
||||
@@ -6628,7 +6630,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
this._codexTerminalLinkClicks ??= new WeakMap();
|
||||
const click = Symbol();
|
||||
this._codexTerminalLinkClicks.set(terminal, click);
|
||||
const link = session?.mode === 'codex' && this._codexTerminalLinkLabel(terminal, clientX, clientY);
|
||||
const link = this._supportsCodexResponseFiles?.(sessionId) && this._codexTerminalLinkLabel(terminal, clientX, clientY);
|
||||
if (!link) {
|
||||
forward();
|
||||
return;
|
||||
@@ -6637,7 +6639,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
const stillCurrent = () =>
|
||||
this._codexTerminalLinkClicks.get(terminal) === click &&
|
||||
(target.sessionId ? terminal.element?.isConnected : this.activeSessionId === sessionId && this.terminal === terminal);
|
||||
void this._openCodexTerminalResponseFile(terminal, sessionId, session, { clientX, clientY }, link, stillCurrent, forward)
|
||||
void this._openCodexTerminalResponseFile(terminal, sessionId, { clientX, clientY }, link, stillCurrent, forward)
|
||||
.catch((error) => console.error('Unable to open Codex terminal response file:', error));
|
||||
},
|
||||
|
||||
|
||||
@@ -2094,6 +2094,7 @@ export class WebServer extends EventEmitter {
|
||||
order: entry.order,
|
||||
kind: entry.kind,
|
||||
external: entry.capabilities.external,
|
||||
transcript: entry.capabilities.transcript,
|
||||
enabled,
|
||||
available: enabled && installed,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user