diff --git a/docs/architecture-invariants.md b/docs/architecture-invariants.md index 0051e973..38fff5c7 100644 --- a/docs/architecture-invariants.md +++ b/docs/architecture-invariants.md @@ -1377,7 +1377,7 @@ Tests: `test/mobile-prompt-composer.test.ts` (in the CI gate, deliberately not u ### Z-index layers -**Z-index layers**: subagent windows (1000), split picker menu (1000, `.split-picker-menu`), Tiles count menu (1000, `.tile-count-menu`), the closing grid's still copy (`.tile-grid-ghosts`, z-index 3 inside `.main`, over the single view coming back; hidden under `.main.webview-active`), mobile/tablet fixed header (1200, `mobile.css`), modals on ≤768px (1300 — must beat the fixed header or the modal close button is buried), log viewers (2000), connection-loss overlay (2500, above the fixed header and modals), image popups (3000), response viewer (5000, backdrop 4999), folder grid (5090, `#folderGridOverlay` — above the response viewer a folder link opens it from, below the file preview its tiles open, so a tile's preview and its ←/→ paging sit on top of the grid), file-preview overlay (5100 — must outrank the response viewer, which can launch it; at its old 2000 a path clicked in the chat opened BEHIND the chat), toasts/path picker (10000+, deliberately above the preview), the custom-model center-status banner (10001, `.center-status-banner` — `[hidden]` must re-assert `display: none` over its own `display: flex`, same trap as `.home-sessions[hidden]`, or `dismiss()` leaves an invisible click-blocker dead centre on screen), the swap-confirm and context-warning modals (10010, `#customModelSwapConfirmModal`/`#customModelContextWarningModal` — must clear both the plain `.modal` z-index of 1000 and the center-status banner it can appear over), terminal touch-selection bar (900 — above terminal content and the local-echo overlay, deliberately BELOW floating agent windows so it can never cover their controls), local echo overlay (7), iOS IME composition preview (EFFECTIVE layer depends on its home: with local echo on it is part of the local echo overlay at 7, drawn by `setComposition()` as an underlined tail after the pending text; with local echo off it is a span at z-index 6 inside `.xterm-helpers`, but `.xterm-helpers` is its own z-index 5 stacking context, so the span's effective layer is 5. That is below the overlay's 7, which is why the span cannot be used while the overlay holds text: typed text never reaches the PTY before Enter, the PTY cursor that places the span stays at the prompt start, and the overlay's opaque line div covers it). +**Z-index layers**: subagent windows (1000), split picker menu (1000, `.split-picker-menu`), Tiles count menu (1000, `.tile-count-menu`), the closing grid's still copy (`.tile-grid-ghosts`, z-index 3 inside `.main`, over the single view coming back; hidden under `.main.webview-active`), mobile/tablet fixed header (1200, `mobile.css`), modals on ≤768px (1300 — must beat the fixed header or the modal close button is buried), log viewers (2000), connection-loss overlay (2500, above the fixed header and modals), image popups (3000), response viewer (5000, backdrop 4999), folder grid (5090, `#folderGridOverlay` — above the response viewer a folder link opens it from, below the file preview its tiles open, so a tile's preview and its ←/→ paging sit on top of the grid), file-preview overlay (5100 — must outrank the response viewer, which can launch it; at its old 2000 a path clicked in the chat opened BEHIND the chat; DOCKED beside the terminal (the Codex files setting) it is `z-index: auto`, page content, since with nothing above it making a stacking context its 5100 would sit over every modal backdrop and the response viewer sheet), toasts/path picker (10000+, deliberately above the preview), the custom-model center-status banner (10001, `.center-status-banner` — `[hidden]` must re-assert `display: none` over its own `display: flex`, same trap as `.home-sessions[hidden]`, or `dismiss()` leaves an invisible click-blocker dead centre on screen), the swap-confirm and context-warning modals (10010, `#customModelSwapConfirmModal`/`#customModelContextWarningModal` — must clear both the plain `.modal` z-index of 1000 and the center-status banner it can appear over), terminal touch-selection bar (900 — above terminal content and the local-echo overlay, deliberately BELOW floating agent windows so it can never cover their controls), local echo overlay (7), iOS IME composition preview (EFFECTIVE layer depends on its home: with local echo on it is part of the local echo overlay at 7, drawn by `setComposition()` as an underlined tail after the pending text; with local echo off it is a span at z-index 6 inside `.xterm-helpers`, but `.xterm-helpers` is its own z-index 5 stacking context, so the span's effective layer is 5. That is below the overlay's 7, which is why the span cannot be used while the overlay holds text: typed text never reaches the PTY before Enter, the PTY cursor that places the span stays at the prompt start, and the overlay's opaque line div covers it). ## Security layers diff --git a/docs/wiki/Settings-Reference.md b/docs/wiki/Settings-Reference.md index be1a8bed..1864285e 100644 --- a/docs/wiki/Settings-Reference.md +++ b/docs/wiki/Settings-Reference.md @@ -63,11 +63,19 @@ non-updatable. See [Running As A Service](Running-As-A-Service). Chips for every optional header control, with a live preview of the resulting header: -Run, Font Size, System Stats, Redraw Terminal, Response Viewer, Away Digest, Session +Run, Font Size, System Stats, Redraw Terminal, Response Viewer, Codex files, Away Digest, Session Manager, Attachments, Edit history, File Viewer, Multi-monitor, Split, Tiles, Plan Usage, Lifecycle Log, Monitor, Project Insights, File Browser, Subagents, Approvals Inbox, Read My Mind, Ultracode Agents, Ultracode Windows, Cron. +**Codex files** (off by default, per device) switches on three extras for Codex sessions, together: +a **Response files** header button that lists the previewable files linked in the latest reply +(desktop only: phones keep File Viewer as their one header button, even with this on), a click on a +file name in Codex's own sidebar opening that file in the preview when it matches a single linked +file (off, the click goes to Codex), and a **Dock** button on file previews that, on a window 1180px +or wider with a single terminal, docks the preview beside the terminal. With it off none of the three +exists. Clicking a file name Codex underlined in the pane opens the preview either way. + **Host readings** (opt-in, both off by default and per device): **GPU Stats** adds three items after CPU and MEM: GPU load, graphics memory and the GPU clock, and **CPU MHz** adds the live CPU clock. Both sets of items live inside **System Stats**, so they show only while that chip is on, and nothing is fetched while it is off. An item appears only when the diff --git a/docs/wiki/Working-With-Files.md b/docs/wiki/Working-With-Files.md index 9541bf1b..0029cef1 100644 --- a/docs/wiki/Working-With-Files.md +++ b/docs/wiki/Working-With-Files.md @@ -142,6 +142,14 @@ File paths in a session are links. That works in two places: render as underlined monospace links. A Markdown link whose target is a path (`[report](/tmp/run/report.json)`, the way Codex cites files) opens the same way. +In a Codex session, clicking a file name Codex underlined opens it in Codeman's preview +when it names a single supported file from the conversation; anything else goes to Codex as +before. The **Codex files** setting (App Settings > Header buttons, per device, off by +default) adds three more: a **Response files** header button that lists the files linked in +the latest reply (desktop only), a file name in Codex's own sidebar opening the preview when it +matches a single linked file, and a **Dock** button that, on a wide window with a single +terminal, switches between a preview beside the terminal and a floating one. + Clicking one opens it in the preview: images and PDFs render, video and audio play with a working scrub bar, documents convert, text shows inline, Markdown renders and HTML opens as a page. The exception is a plain text file (a log, `.txt`, `.json`, code) inside the workspace diff --git a/src/web/CLAUDE.md b/src/web/CLAUDE.md index 3914b580..c7ec79e2 100644 --- a/src/web/CLAUDE.md +++ b/src/web/CLAUDE.md @@ -98,6 +98,8 @@ Frontend JS modules have `@fileoverview` with `@dependency`/`@loadorder` tags. L **SSE staleness watchdog** (`computeSseStale()` in constants.js, `_checkSseStale()` + a 5s interval in app.js): an `EventSource` can stop delivering without erroring, so the client forces a reconnect when nothing arrives. ⚠️ The server keepalive must stay the named `sse:heartbeat` event (`cleanupDeadClients()`, sse-stream-manager.ts), never an SSE comment, which `EventSource` cannot observe; its no-op client listener must stay registered. ⚠️ Judge staleness only while `connected` and online (the loop breaker). ⚠️ The liveness stamp lives inside `addListener`. ⚠️ Clear the interval only at the top of `connectSSE()`, or intervals stack. ⚠️ The watchdog cannot see an attempt that never OPENS (no response headers: no `open`, no `error`, never `connected`), so each attempt is bounded by `SSE_CONNECT_TIMEOUT_MS` (15s, `CodemanSseStale.CONNECT_TIMEOUT_MS`) and then retried through `_handleSseConnectionFailure()`, the same backoff `onerror` uses. Its timer is cleared at the top of `connectSSE()` BEFORE the offline early return, on `open`, and in `_handleSseConnectionFailure()`; the timer and the handler both ignore an `EventSource` that has been replaced. The window `offline` handler leaves it running on purpose (`navigator.onLine` can report offline on a working network). Tests: `test/sse-connect-timeout.test.ts`. → [architecture-invariants#sse-staleness-watchdog](../../docs/architecture-invariants.md#sse-staleness-watchdog) -**Z-index layers** (keep new overlays consistent with this stack): local echo overlay (7; with local echo on it also draws the iOS IME composition preview, as an underlined tail after its pending text via `setComposition`), iOS IME composition preview span when local echo is off (6 inside `.xterm-helpers`, whose own z-index 5 is its EFFECTIVE layer, so it sits UNDER the overlay and must never be used while the overlay shows text), terminal touch-selection bar (900, below floating agent windows), subagent windows + split picker menu + Tiles count menu (1000), mobile/tablet fixed header (1200), modals on ≤768px (1300, must beat the fixed header), log viewers (2000), connection-loss overlay (2500), image popups (3000), response viewer (5000, backdrop 4999), folder grid (5090, above the response viewer it opens from, below the file preview its tiles open), file-preview overlay (5100, must outrank the response viewer that launches it), toasts/path picker (10000+), custom-model center-status banner (10001; its `[hidden]` must re-assert `display: none` or `dismiss()` leaves an invisible click-blocker), custom-model swap-confirm/context-warning modals (10010). → [architecture-invariants#z-index-layers](../../docs/architecture-invariants.md#z-index-layers) +**Codex file previews** (`codexFilePreviewsEnabled`, App Settings > Header buttons > Codex files, per-device display key, absent from `SettingsUpdateSchema`, default OFF; `_codexFilePreviewsEnabled()` in app.js is the ONE reader): a session whose CLI publishes `transcript: 'codex-rollout'` opens the files Codex links in the file preview. The served CLI catalog (`window.__codemanCliCatalog`, server.ts) carries `transcript` for that check (`_supportsCodexResponseFiles()`), never a CLI id, and `_syncCliLaunchCatalog()` keeps it across a Settings refresh. A click on an underlined label in the pane is resolved against the conversation (`last-response?context=full`, cached per session while idle until the next `lastSubmitAt`, `_codexResponseMessages()`) and opens only a single, unambiguous, previewable file, else it is forwarded to Codex as before; this part is not behind the setting. Behind it are three things, all absent while it is off: the Response files header button (`toggleResponseViewer(true)`; marker `btn-response-files--hidden` for the setting, `hidden` for the capability, and `mobile.css` hides it on phones regardless, pinned by `test/mobile-header-buttons-policy.test.ts`), the Codex SIDEBAR file tabs (`codexSidebarFileRow()` in terminal-ui.js: with the setting on, `registerFilePathLinkProvider` drops its links on those rows, which are Codex chrome, and a click there is taken by `_codexTerminalLinkLabel()`; off, the row keeps its ordinary links and its click reaches Codex), and the Dock control. ⚠️ Docking MOVES `#filePreviewOverlay` out of its home and after `.terminal-wrap` (`_setFilePreviewDocked()`), only when the wrap is a direct child of `.main` without `.tiles-active`/`.webview-active` and the window is 1180px or wider; otherwise the preview floats. It moves back on close, on Escape inside it, when a split opens (`openSplitPane()` undocks first, or `closeSplitPane()` would remove the overlay with the split container) and when the setting is switched off. Tests: `test/codex-file-previews-setting.test.ts` (off-state of all three), `test/response-viewer-file-links.test.ts`, `test/terminal-link-provider-target.test.ts`, `test/terminal-touch-tap.test.ts`, `test/file-preview-window.test.ts`. + +**Z-index layers** (keep new overlays consistent with this stack): local echo overlay (7; with local echo on it also draws the iOS IME composition preview, as an underlined tail after its pending text via `setComposition`), iOS IME composition preview span when local echo is off (6 inside `.xterm-helpers`, whose own z-index 5 is its EFFECTIVE layer, so it sits UNDER the overlay and must never be used while the overlay shows text), terminal touch-selection bar (900, below floating agent windows), subagent windows + split picker menu + Tiles count menu (1000), mobile/tablet fixed header (1200), modals on ≤768px (1300, must beat the fixed header), log viewers (2000), connection-loss overlay (2500), image popups (3000), response viewer (5000, backdrop 4999), folder grid (5090, above the response viewer it opens from, below the file preview its tiles open), file-preview overlay (5100, must outrank the response viewer that launches it; DOCKED it is `z-index: auto`, page content beside the terminal, so it sits under every modal and the response viewer, pinned in `test/file-preview-window.test.ts`), toasts/path picker (10000+), custom-model center-status banner (10001; its `[hidden]` must re-assert `display: none` or `dismiss()` leaves an invisible click-blocker), custom-model swap-confirm/context-warning modals (10010). → [architecture-invariants#z-index-layers](../../docs/architecture-invariants.md#z-index-layers) **Keyboard shortcuts**: Escape (close), Ctrl+? (shortcut overlay), Ctrl/Cmd/Alt+K (session palette), Ctrl+Tab (next), Alt+[/] (prev/next tab), Alt+1-9 (switch tab), Ctrl+Shift+{/} (move tab left/right), Shift+Enter or Ctrl+Enter (newline), Ctrl+C (copy selection, else interrupt) / Ctrl+Shift+C (copy, never interrupts), Ctrl+L (clear), Ctrl+Shift+R (restore size), Ctrl+Shift+V (voice input), Ctrl/Cmd +/- (font), Shift+Wheel (local scrollback when mouse passthrough is active), Shift+drag (start a selection in a stripped-DECSET pane, where xterm's own Shift branch is unreachable and a Shift+drag used to select nothing; `_installShiftDragSelection`), right-click (copy the selection, the mintty/PuTTY convention, since xterm paints into a canvas and the native menu has no Copy for it; with nothing selected the native menu is left alone). Rebindable via the registry. ⚠️ **Ctrl+W is deliberately NOT bound** (owner decision): it is delete-word in every shell and agent CLI, and as Close Session it killed sessions with no confirm; `close-session` keeps `bindings: []` and stays bindable (`test/ctrl-w-never-closes.test.ts`). diff --git a/src/web/public/app.js b/src/web/public/app.js index f98715dc..e5ae767f 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -1427,6 +1427,7 @@ class CodemanApp { // Escape - close panels and modals (different logic: no preventDefault, no return) if (e.key === 'Escape') { + if (this._maybeCloseDockedFilePreviewOnEscape?.(e)) return; // An open group menu (or a grouped-rail drag) owns this Escape: close // just that, not every panel behind it. if (this._tabGroupMenu && this._tabGroupMenuKeydown) { @@ -2776,12 +2777,19 @@ class CodemanApp { * newline is the agent's line break, wrong for a file (the File Viewer passes * false), where a README hard-wrapped at 80 columns would break at every wrap. */ - _renderMarkdown(text, { breaks = true } = {}) { + _renderMarkdown(text, { breaks = true, localFileLinks = false } = {}) { const src = text || ''; if (typeof marked !== 'undefined' && marked.parse) { try { const prepared = this._preprocessAsciiArt(src); - let html = this._sanitizeHtml(marked.parse(prepared, { breaks, gfm: true })); + const options = { breaks, gfm: true }; + if (localFileLinks) { + options.walkTokens = (token) => { + // Convert local URI destinations to inert path references before sanitizing. + if (token.type === 'link' && /^file:\/\/\/(?!\/)/i.test(token.href)) token.href = token.href.slice(7); + }; + } + let html = this._sanitizeHtml(marked.parse(prepared, options)); // Wrap tables in a horizontal-scroll container so they overflow gracefully // on mobile without collapsing into block-level cells. html = html.replace(//g, '
') @@ -3228,19 +3236,166 @@ class CodemanApp { : 'Claude'; } - async toggleResponseViewer() { + closeResponseViewer() { + this._responseViewerRequest = null; + const viewer = document.getElementById('responseViewer'); + if (!viewer || !viewer.classList.contains('visible')) return false; + const backdrop = document.getElementById('responseViewerBackdrop'); + viewer.classList.remove('visible'); + if (backdrop) backdrop.classList.remove('visible'); + const terminal = this._responseViewerReturnTerminal; + this._responseViewerReturnTerminal = null; + if (terminal && terminal.element?.isConnected !== false && this._shouldFocusTerminalForTabSwitch()) { + try { + terminal.focus(); + } catch { + /* terminal may be detached mid-teardown */ + } + } + return true; + } + + _supportsCodexResponseFiles(sessionId) { + const mode = this.sessions?.get(sessionId)?.mode; + return window.__codemanCliCatalog?.find((entry) => entry.id === mode)?.transcript === 'codex-rollout'; + } + + /** + * Per-device opt-in (`codexFilePreviewsEnabled`, App Settings > Header buttons > Codex files), + * default OFF. It gates the three Codex file-preview extras together: the Response files header + * button, taking a click on a file tab in Codex's own sidebar (and the link suppression on those + * rows), and the Dock control on file previews. With it off none of them exists and sidebar clicks + * reach Codex as before. + */ + _codexFilePreviewsEnabled() { + const settings = this.loadAppSettingsFromStorage?.() || {}; + const defaults = this.getDefaultSettings?.() || {}; + return (settings.codexFilePreviewsEnabled ?? defaults.codexFilePreviewsEnabled ?? false) === true; + } + + /** + * The Response files button shows only with the setting on (its --hidden marker; phones keep it + * hidden via mobile.css regardless) AND in a session whose CLI publishes a Codex rollout + * transcript (the `hidden` attribute). + */ + _syncResponseFilesButton() { + const button = document.getElementById('responseFilesBtn'); + if (!button) return; + button.classList.toggle('btn-response-files--hidden', !this._codexFilePreviewsEnabled()); + button.hidden = !this._supportsCodexResponseFiles(this.activeSessionId); + } + + _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) { + 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(text, { localFileLinks: true }); + const links = Array.from(rendered.content.querySelectorAll('a')).filter( + (link) => sidebar || link.textContent.trim() === label + ); + if (!links.length) continue; + + this._linkifyFilePaths(rendered.content); + for (const link of links) { + 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. + const matchesEnds = + abbreviated && basename.length > prefix.length + suffix.length && + basename.startsWith(prefix) && basename.endsWith(suffix); + if (basename !== label && !matchesEnds) continue; + } + // Ambiguity includes web URLs and unsupported files with the same label. + if (!link.dataset.linkified || link.dataset.folder || !/^\/(?!\/)/.test(path) || !previewsInFileViewer(path)) { + return null; + } + if (match && match !== path) return null; + match = path; + } + } + return match; + } + + _openResponseFile(path, sessionId) { + 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) { + const list = document.createElement('ul'); + list.className = 'response-files-list'; + const seen = new Set(); + for (const response of responses) { + const rendered = document.createElement('template'); + rendered.innerHTML = this._renderMarkdown(response, { localFileLinks: true }); + this._linkifyFilePaths(rendered.content); + for (const link of rendered.content.querySelectorAll('a.rv-path')) { + if (link.dataset.folder) continue; + 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'); + // A button, not : under a middle-click on "#" opens the app root. + const action = document.createElement('button'); + action.type = 'button'; + action.className = 'response-files-item'; + action.textContent = link.textContent.trim() || path.split('/').pop(); + action.title = path; + action.addEventListener('click', (event) => { + event.preventDefault(); + this.closeResponseViewer(); + this._openResponseFile(path, sessionId); + }); + item.appendChild(action); + list.appendChild(item); + } + } + if (seen.size) body.replaceChildren(list); + else { + const empty = 'No previewable files in the latest response.'; + body.textContent = window.codemanT?.(empty) || empty; + } + } + + async toggleResponseViewer(filesOnly = false) { const viewer = document.getElementById('responseViewer'); const backdrop = document.getElementById('responseViewerBackdrop'); if (!viewer) return; const isOpen = viewer.classList.contains('visible'); - if (isOpen) { - viewer.classList.remove('visible'); - backdrop.classList.remove('visible'); + if (isOpen && (viewer.dataset.filesOnly === 'true') === filesOnly) { + this.closeResponseViewer(); return; } if (!this.activeSessionId) return; + const responseSessionId = this.activeSessionId; + const session = this.sessions?.get?.(responseSessionId); + if (filesOnly && !(this._codexFilePreviewsEnabled() && this._supportsCodexResponseFiles(responseSessionId))) return; + const returnTerminal = isOpen ? this._responseViewerReturnTerminal : this._focusedPane?.().terminal; + const request = Symbol('response-viewer'); + this._responseViewerRequest = request; try { // Source 1: Transcript JSONL (best quality — clean structured text from Claude). // `context=turn` asks for the last ANSWERED turn as messages: a Claude @@ -3249,8 +3404,10 @@ class CodemanApp { // rows before it. Readers that know no `turn` context (Codex, the pane // parser, an older server) answer with `text` only, and that path is // unchanged below. - const res = await fetch(`/api/sessions/${this.activeSessionId}/last-response?context=turn`); + const res = await fetch(`/api/sessions/${responseSessionId}/last-response?context=turn`); + if (filesOnly && !res.ok) throw new Error('Unable to load response files'); const data = (await res.json())?.data ?? {}; + if (this._responseViewerRequest !== request || this.activeSessionId !== responseSessionId) return; let lastResponse = data.text || ''; const turnMessages = (Array.isArray(data.messages) ? data.messages : []).filter( (msg) => msg && msg.role === 'assistant' && typeof msg.text === 'string' && msg.text.trim() @@ -3261,13 +3418,13 @@ class CodemanApp { // shell sessions have no transcript source at all; for TUI modes // (codex/opencode/gemini/antigravity) it yields repaint garbage, so a clear // placeholder beats a messy screen dump there. - const sessionMode = this.sessions.get(this.activeSessionId)?.mode || 'claude'; + const sessionMode = session?.mode || 'claude'; if (!lastResponse && (sessionMode === 'claude' || sessionMode === 'shell')) { // The no-param form is capped only by `terminalBufferMaxBytes` (32MB by // default), so it is the largest body the frontend asks for anywhere — // it gets the full-history budget, not the tail one. const termCapture = await this._fetchTerminalCapture( - `/api/sessions/${this.activeSessionId}/terminal`, + `/api/sessions/${responseSessionId}/terminal`, { full: true } ); const termData = termCapture.json?.data ?? {}; @@ -3276,10 +3433,14 @@ class CodemanApp { } } + if (this._responseViewerRequest !== request || this.activeSessionId !== responseSessionId) return; this._responseViewerMarkdown = this._responseViewerMarkdownFrom(turnMessages) || lastResponse; const body = document.getElementById('responseViewerBody'); - if (turnMessages.length > 0) { + if (filesOnly) { + const responses = turnMessages.length ? turnMessages.map((message) => message.text) : [lastResponse]; + 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 // numeric-`turn` gate as loadFullContext, never same-role adjacency. @@ -3308,9 +3469,15 @@ class CodemanApp { // Reset state for fresh open const title = document.getElementById('responseViewerTitle'); const moreBtn = document.getElementById('responseViewerMore'); - if (title) title.textContent = 'Last Response'; - if (moreBtn) { moreBtn.style.display = ''; moreBtn.textContent = 'More'; } + viewer.dataset.filesOnly = String(filesOnly); + const titleText = filesOnly ? 'Response files' : 'Last Response'; + if (title) title.textContent = window.codemanT?.(titleText) || titleText; + if (moreBtn) { + moreBtn.style.display = ''; + moreBtn.textContent = window.codemanT?.('More') || 'More'; + } + this._responseViewerReturnTerminal = returnTerminal; viewer.classList.add('visible'); backdrop.classList.add('visible'); // A multi-row turn opens at its NEWEST text, matching loadFullContext's @@ -3318,9 +3485,13 @@ class CodemanApp { // brief view was a single card holding the last row; with the whole turn // rendered, the top is the turn's first narration line and the answer the // eye button exists to show can be several screens down. - body.scrollTop = turnMessages.length > 1 ? body.scrollHeight : 0; + body.scrollTop = !filesOnly && turnMessages.length > 1 ? body.scrollHeight : 0; } catch (err) { console.error('Failed to load response:', err); + if (filesOnly && this._responseViewerRequest === request && this.activeSessionId === responseSessionId) { + const message = 'Unable to load response files'; + this.showToast(window.codemanT?.(message) || message, 'error'); + } } } @@ -6592,6 +6763,7 @@ class CodemanApp { // ═══════════════════════════════════════════════════════════════ renderSessionTabs({ immediate = false } = {}) { + this._syncResponseFilesButton(); // Don't re-render while user is typing in the inline rename input if (this._inlineRenameActive) return; if (immediate) { diff --git a/src/web/public/i18n.js b/src/web/public/i18n.js index d12db773..bb15e098 100644 --- a/src/web/public/i18n.js +++ b/src/web/public/i18n.js @@ -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', @@ -481,6 +487,9 @@ 'CPU MHz': 'CPU 频率', 'Lifecycle Log': '生命周期日志', 'Response Viewer': '回复查看器', + 'Codex files': 'Codex 文件', + 'Codex sessions: a Response files header button, Codex sidebar file tabs open in the preview, and a Dock control on file previews': + 'Codex 会话:标题栏的回复中的文件按钮、在预览中打开 Codex 侧边栏文件标签,以及文件预览上的停靠控件', 'Attachments Button': '附件按钮', 'Multi-monitor Button': '多显示器按钮', 'Session Manager Button': '会话管理器按钮', diff --git a/src/web/public/index.html b/src/web/public/index.html index 6368c3c6..1deea1c9 100644 --- a/src/web/public/index.html +++ b/src/web/public/index.html @@ -206,6 +206,7 @@ + + @@ -735,12 +737,12 @@
- +
-
+