mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-01 00:49:33 +01:00
Merge #815: fix(web): manual Reload history action for the tmux repaint gap above live output (#814)
# Conflicts: # src/web/CLAUDE.md
This commit is contained in:
commit
4936e07ca2
18 files changed
+2618
-57
No files matched your search
+258
-33
@@ -801,9 +801,13 @@ class CodemanApp {
|
||||
// the small `full=1` capture instead of the 1 MiB byte tail: see
|
||||
// _notePaneHistory and selectSession.
|
||||
this._paneHistoryLines = new Map(); // Map<sessionId, number>
|
||||
// Cooldown per session for the scroll-to-top "load more history" re-pull.
|
||||
// Per-session cooldown for top-of-buffer pulls; manual actions bypass it.
|
||||
this._fullHistoryRepullAt = new Map(); // Map<sessionId, timestamp>
|
||||
this._fullHistoryRepullInFlight = false;
|
||||
this._liveOutputSinceFullPull = new Set(); // Set<sessionId>
|
||||
this._historyReloadDismissed = new Set(); // Until the next successful full mux replay
|
||||
this._liveOutputGen = new Map(); // Map<sessionId, number>
|
||||
this._earlyReplayTravel = null; // { sessionId, moves: number[] } during a content-anchored replay
|
||||
// Sessions whose last re-pull came back THINNER than the live buffer (a
|
||||
// repaint-mode CLI pane, where tmux keeps no history of its own). The pull is
|
||||
// refused for those and retried far more slowly — see _maybeRefetchFullHistory.
|
||||
@@ -2596,13 +2600,41 @@ class CodemanApp {
|
||||
* @param {number} [queuedBytes] - render-queue bytes at the drop, for the crash trail
|
||||
*/
|
||||
_scheduleDroppedOutputRecovery(sessionId, attempt = 0, queuedBytes) {
|
||||
if (!sessionId || this._clientDropRecoveryTimer) return;
|
||||
if (!sessionId) return;
|
||||
// Nothing of the main terminal's to recover while the tile grid owns it.
|
||||
if (this._tilesOwnTerminal?.()) return;
|
||||
// A slow capture owns the live-output gate. Keep the recovery owed until
|
||||
// it releases instead of spending every retry against the same open load.
|
||||
if (this._isLoadingBuffer) {
|
||||
if (sessionId === this.activeSessionId) {
|
||||
if (this._pendingDroppedOutputRecovery?.sessionId !== sessionId && Number.isFinite(queuedBytes)) {
|
||||
_crashDiag.log(`TERMINAL DROP: ${(queuedBytes / 1024).toFixed(0)}KB queued (recovery deferred)`);
|
||||
}
|
||||
const pending = this._pendingDroppedOutputRecovery;
|
||||
this._pendingDroppedOutputRecovery = {
|
||||
sessionId,
|
||||
attempt: pending?.sessionId === sessionId ? Math.max(pending.attempt, attempt) : attempt,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this._clientDropRecoveryTimer) return;
|
||||
// Behind the debounce guard: one line per window, not per dropped frame.
|
||||
if (Number.isFinite(queuedBytes)) _crashDiag.log(`TERMINAL DROP: ${(queuedBytes / 1024).toFixed(0)}KB queued`);
|
||||
this._clientDropRecoveryTimer = setTimeout(async () => {
|
||||
this._clientDropRecoveryTimer = null;
|
||||
// A load may have opened after this timer was armed. Defer without
|
||||
// advancing the attempt; _finishBufferLoad resumes only the active tab.
|
||||
if (this._isLoadingBuffer) {
|
||||
if (sessionId === this.activeSessionId) {
|
||||
const pending = this._pendingDroppedOutputRecovery;
|
||||
this._pendingDroppedOutputRecovery = {
|
||||
sessionId,
|
||||
attempt: pending?.sessionId === sessionId ? Math.max(pending.attempt, attempt) : attempt,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
let repainted = false;
|
||||
let timedOut = false;
|
||||
try {
|
||||
@@ -3465,6 +3497,9 @@ class CodemanApp {
|
||||
if (this._terminalRefreshOwner?.sessionId === sessionId) return false;
|
||||
const refreshOwner = { sessionId };
|
||||
this._terminalRefreshOwner = refreshOwner;
|
||||
// Reload history stands aside for the length of this refresh (see
|
||||
// _historyReloadActionEligible); take it off an already-painted bar now.
|
||||
this._syncHistoryReloadAction?.();
|
||||
try {
|
||||
// A shell can retain a multi-megabyte/100k-line tmux history. Automatic
|
||||
// recovery stays bounded just like normal shell selection (tmux's rendered
|
||||
@@ -3473,6 +3508,8 @@ class CodemanApp {
|
||||
// TUI modes still recover the whole picture, with the downgrade guard for
|
||||
// repaint-mode panes whose tmux capture can be smaller than xterm's buffer.
|
||||
const useFullHistory = this.sessions.get(sessionId)?.mode !== 'shell';
|
||||
// Keep live output received during the capture marked for another full-history pull.
|
||||
const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0;
|
||||
let capture = await this._fetchTerminalCapture(
|
||||
useFullHistory
|
||||
? `/api/sessions/${sessionId}/terminal?full=1`
|
||||
@@ -3481,7 +3518,13 @@ class CodemanApp {
|
||||
);
|
||||
let headersReceivedAt = capture.headersAt;
|
||||
let data = capture.json?.data ?? {};
|
||||
// The full capture would shrink the buffer: tmux holds less than the browser,
|
||||
// the signal `_maybeRefetchFullHistory` retires Reload history on. Record it
|
||||
// and apply it past the ownership guard below, so the next tap does not run
|
||||
// another forced full capture only to be refused.
|
||||
let refusedFullCapture = false;
|
||||
if (useFullHistory && data.terminalBuffer && this._replayWouldShrinkBuffer(data.terminalBuffer)) {
|
||||
refusedFullCapture = true;
|
||||
capture = await this._fetchTerminalCapture(`/api/sessions/${sessionId}/terminal?tail=${TERMINAL_TAIL_SIZE}`);
|
||||
headersReceivedAt = capture.headersAt;
|
||||
data = capture.json?.data ?? {};
|
||||
@@ -3495,6 +3538,10 @@ class CodemanApp {
|
||||
// pane), and an error envelope is not a capture at all.
|
||||
if (this.activeSessionId !== sessionId || this._terminalRefreshOwner !== refreshOwner) return false;
|
||||
if (capture.json?.success !== false) this._notePaneHistory?.(sessionId, data);
|
||||
if (refusedFullCapture) {
|
||||
(this._historyReloadDismissed ||= new Set()).add(sessionId);
|
||||
this._syncHistoryReloadAction?.();
|
||||
}
|
||||
if (data.terminalBuffer) {
|
||||
// This refresh is SERVER-triggered, so a user quietly reading scrollback
|
||||
// did not ask for it and must not be dragged to the bottom by it (#259).
|
||||
@@ -3507,12 +3554,23 @@ class CodemanApp {
|
||||
// after them and fuse into the buffer written below. See
|
||||
// _resetTerminalForReplay.
|
||||
this._resetTerminalForReplay();
|
||||
await this.chunkedTerminalWrite(
|
||||
const { completed } = await this.chunkedTerminalWrite(
|
||||
data.terminalBuffer,
|
||||
TERMINAL_CHUNK_SIZE,
|
||||
undefined,
|
||||
this._bufferLoadFinishOpts(data, headersReceivedAt)
|
||||
);
|
||||
if (
|
||||
completed &&
|
||||
this.activeSessionId === sessionId &&
|
||||
this._terminalRefreshOwner === refreshOwner &&
|
||||
data.source === 'mux-full-history' &&
|
||||
(this._liveOutputGen?.get(sessionId) || 0) === liveOutputGen
|
||||
) {
|
||||
this._liveOutputSinceFullPull?.delete(sessionId);
|
||||
this._historyReloadDismissed?.delete(sessionId);
|
||||
this._syncHistoryReloadAction?.();
|
||||
}
|
||||
// A tail fetch can be partial, and the banner would otherwise keep
|
||||
// describing the pre-refresh buffer (#258).
|
||||
this._setHistoryTruncation(sessionId, data);
|
||||
@@ -3549,7 +3607,11 @@ class CodemanApp {
|
||||
console.error('needsRefresh reload failed:', err);
|
||||
return err?.name === 'AbortError' ? 'deadline' : false;
|
||||
} finally {
|
||||
if (this._terminalRefreshOwner === refreshOwner) this._terminalRefreshOwner = null;
|
||||
if (this._terminalRefreshOwner === refreshOwner) {
|
||||
this._terminalRefreshOwner = null;
|
||||
// Reload history stands aside while this refresh fetches; offer it again.
|
||||
this._syncHistoryReloadAction?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5039,6 +5101,9 @@ class CodemanApp {
|
||||
// Clear pending terminal writes
|
||||
this._clearTimer('syncWaitTimeout');
|
||||
this._clearTimer('_clientDropRecoveryTimer');
|
||||
// A recovery deferred behind a load would otherwise resume once the next
|
||||
// load (the reconnect's own refresh) finishes, and run a second full capture.
|
||||
this._pendingDroppedOutputRecovery = null;
|
||||
this.pendingWrites = [];
|
||||
this.writeFrameScheduled = false;
|
||||
// Release the one-chunk-in-flight gate with the rest of the write queue.
|
||||
@@ -6743,6 +6808,7 @@ class CodemanApp {
|
||||
if (state && state.generation !== selectGen) return;
|
||||
this.terminalLoadStates.delete(sessionId);
|
||||
this._updateTerminalLoadTab(sessionId);
|
||||
if (state) this._syncHistoryReloadAction?.();
|
||||
}
|
||||
|
||||
_updateTerminalLoadTab(sessionId) {
|
||||
@@ -9533,6 +9599,7 @@ class CodemanApp {
|
||||
this._tabCompletionBaseText = null;
|
||||
this._clearTimer('_tabCompletionFallback');
|
||||
this._clearTimer('_clientDropRecoveryTimer');
|
||||
this._pendingDroppedOutputRecovery = null;
|
||||
this._terminalRefreshOwner = null;
|
||||
|
||||
// Clean up pending terminal writes to prevent old session data from appearing in new session
|
||||
@@ -9662,8 +9729,8 @@ class CodemanApp {
|
||||
}
|
||||
|
||||
/**
|
||||
* "Load more history": re-pull the whole tmux scrollback when the user scrolls up
|
||||
* while already at the top of what the browser has.
|
||||
* Re-pull tmux history automatically at the top, or explicitly from the
|
||||
* history banner's Load full history / Reload history actions.
|
||||
*
|
||||
* xterm's buffer is only ever a WINDOW onto tmux's real history, and two things
|
||||
* shrink it. tmux repaints the pane rectangle instead of emitting linefeeds
|
||||
@@ -9674,9 +9741,11 @@ class CodemanApp {
|
||||
* everything (history-limit 100k by default), so the fix is to go ask for it with
|
||||
* the same `?full=1` capture a page reload uses (issue #205).
|
||||
*
|
||||
* On demand rather than automatic because that capture is unbounded-ish work: at
|
||||
* the default history limit it can be megabytes, which is fine to pay when the
|
||||
* user is explicitly reaching for history and not fine on every tab switch.
|
||||
* Automatic pulls are top-only and cooldown/latch guarded: a synchronous
|
||||
* capture can cost about 1 s at 100k lines (1,068 ms median for 12.1 MB of
|
||||
* 120-character lines, `capture-pane -p -e -J -S -100000`) and blocks the server event loop.
|
||||
* The manual Reload history action uses a content anchor to hold the reader's
|
||||
* place even when new history fills a gap below them.
|
||||
*
|
||||
* NEVER a downgrade: for a repaint-mode CLI pane tmux keeps no history of its
|
||||
* own, so the capture can be THINNER than what xterm already holds and the
|
||||
@@ -9685,9 +9754,13 @@ class CodemanApp {
|
||||
* gets a much longer cooldown so a hollow pane stops re-fetching megabytes on
|
||||
* every scroll-up (issue #205, round 2).
|
||||
*/
|
||||
async _maybeRefetchFullHistory({ force = false } = {}) {
|
||||
async _maybeRefetchFullHistory({ force = false, anchor = 'top' } = {}) {
|
||||
const sessionId = this.activeSessionId;
|
||||
if (!sessionId || this._fullHistoryRepullInFlight || this._isLoadingBuffer) return;
|
||||
// A drop-recovery refresh owns this session until its replay ends: a second
|
||||
// capture would run back to back with it, and its load would replace this
|
||||
// pull's queue, losing the output that arrived during the download.
|
||||
if (this._terminalRefreshOwner?.sessionId === sessionId) return;
|
||||
if (this.detachedSessions?.has(sessionId)) return;
|
||||
// The parked main terminal has no history to pull while tiles own the screen.
|
||||
if (this._tilesOwnTerminal?.()) return;
|
||||
@@ -9719,11 +9792,16 @@ class CodemanApp {
|
||||
if (!force && now - (this._fullHistoryRepullAt.get(sessionId) || 0) < cooldown) return;
|
||||
this._fullHistoryRepullAt.set(sessionId, now);
|
||||
this._fullHistoryRepullInFlight = true;
|
||||
const loadOwner = this._beginBufferLoad();
|
||||
let replayed = false;
|
||||
// The session-id check below cannot see a tab switch that came BACK during
|
||||
// the fetch (A -> B -> A): the id matches again while `selectSession` is
|
||||
// replaying its own capture, and the reset below would land in the middle
|
||||
// of that write. The select generation moves on every switch, so it can.
|
||||
const selectGen = this._selectGeneration;
|
||||
// Queued output replayed after this load may mark the session again. Never
|
||||
// clear that newer generation along with the capture's original mark.
|
||||
const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0;
|
||||
try {
|
||||
const requestStartedAt = performance.now();
|
||||
const capture = await this._fetchTerminalCapture(
|
||||
@@ -9742,6 +9820,22 @@ class CodemanApp {
|
||||
// recording its empty data would forget the count and hand the next
|
||||
// gesture back to the paging fallback, the bug this pull exists to avoid.
|
||||
if (selectGen === this._selectGeneration && capture.json?.success !== false) this._notePaneHistory?.(sessionId, payload);
|
||||
// A manual reload answered by anything but a full mux capture (an empty
|
||||
// response, or the byte-history fallback the route returns when the pane
|
||||
// capture is blank or failed) cannot fill the gap, and only a mux replay
|
||||
// clears the mark: offering it again would repeat the forced capture on
|
||||
// every tap. Retire it until the next `mux-full-history` replay. Only for
|
||||
// the request still current: a slow answer from before an A -> B -> A
|
||||
// switch must not retire the action a newer capture of A already cleared.
|
||||
if (
|
||||
anchor === 'content' &&
|
||||
this.activeSessionId === sessionId &&
|
||||
selectGen === this._selectGeneration &&
|
||||
capture.json?.success !== false &&
|
||||
payload.source !== 'mux-full-history'
|
||||
) {
|
||||
(this._historyReloadDismissed ||= new Set()).add(sessionId);
|
||||
}
|
||||
const buffer = payload.terminalBuffer;
|
||||
const timing = {
|
||||
trigger: force ? 'full-history-button' : 'full-history-scroll',
|
||||
@@ -9802,6 +9896,7 @@ class CodemanApp {
|
||||
timing.totalMs = performance.now() - requestStartedAt;
|
||||
this._recordTerminalLoadTiming(timing);
|
||||
(this._fullHistoryRepullUseless ||= new Set()).add(sessionId);
|
||||
(this._historyReloadDismissed ||= new Set()).add(sessionId);
|
||||
this._logScrollRouting?.('repull-refused-downgrade');
|
||||
// The browser already holds more than tmux can give back, so there is
|
||||
// nothing further to offer and the indicator must stop promising it.
|
||||
@@ -9819,6 +9914,9 @@ class CodemanApp {
|
||||
this._fullHistoryRepullUseless?.delete(sessionId);
|
||||
const rowsBefore = this.terminal.buffer.active.length;
|
||||
const replayStartedAt = performance.now();
|
||||
const viewportAnchor = anchor === 'content' ? this._captureViewportAnchor() : null;
|
||||
// Ordered, not summed: each move clamps at the buffer edge as it would live.
|
||||
if (anchor === 'content') this._earlyReplayTravel = { sessionId, moves: [] };
|
||||
this._resetTerminalForReplay();
|
||||
const {
|
||||
parsedAt,
|
||||
@@ -9827,11 +9925,17 @@ class CodemanApp {
|
||||
} = await this.chunkedTerminalWrite(
|
||||
buffer,
|
||||
TERMINAL_CHUNK_SIZE,
|
||||
sessionId,
|
||||
loadOwner,
|
||||
this._bufferLoadFinishOpts(payload, headersReceivedAt)
|
||||
);
|
||||
replayed = true; // chunkedTerminalWrite finished this load with the capture cutoff.
|
||||
timing.resetAndParseMs = parsedAt - replayStartedAt;
|
||||
if (!completed || this.activeSessionId !== sessionId || selectGen !== this._selectGeneration) return;
|
||||
if (payload.source === 'mux-full-history' && (this._liveOutputGen?.get(sessionId) || 0) === liveOutputGen) {
|
||||
this._liveOutputSinceFullPull?.delete(sessionId);
|
||||
this._historyReloadDismissed?.delete(sessionId);
|
||||
this._syncHistoryReloadAction?.();
|
||||
}
|
||||
// Keep shell tab restores bounded too. A user-triggered full-history pull
|
||||
// may be tens of MB; caching it would replay that whole payload again on
|
||||
// the next tab switch before the normal 1MB tail fetch replaces it.
|
||||
@@ -9844,9 +9948,26 @@ class CodemanApp {
|
||||
// UPWARD, so what used to be row 0 (what they were looking at) is now `delta`
|
||||
// rows down; scrolling there reveals the recovered history above it instead
|
||||
// of teleporting them to the bottom the way a normal buffer load does.
|
||||
const delta = parsedBufferLength - rowsBefore;
|
||||
if (delta > 0) this.terminal.scrollToLine(delta);
|
||||
else this.terminal.scrollToTop();
|
||||
if (anchor === 'content') {
|
||||
const baseY = this.terminal.buffer.active.baseY;
|
||||
const clamp = (row) => Math.max(0, Math.min(baseY, row));
|
||||
let row = this._restoreViewportAnchor(viewportAnchor);
|
||||
// Replay travel bypassed the live scroll handler's notice update, so
|
||||
// decide it per move as that handler would: an upward move that reaches
|
||||
// row 0 reveals the notice, a downward move back at live output retires it.
|
||||
let reveal = null;
|
||||
for (const move of this._earlyReplayTravel.moves) {
|
||||
row = clamp(row + move);
|
||||
if (move < 0 && row === 0) reveal = true;
|
||||
else if (move > 0 && row >= baseY - 2) reveal = false;
|
||||
}
|
||||
this.terminal.scrollToLine(row);
|
||||
if (reveal !== null) this._setHistoryNoticeRevealed?.(reveal ? sessionId : null);
|
||||
} else {
|
||||
const delta = parsedBufferLength - rowsBefore;
|
||||
if (delta > 0) this.terminal.scrollToLine(delta);
|
||||
else this.terminal.scrollToTop();
|
||||
}
|
||||
// The load's own replay sampled the sticky-scroll baseline while the
|
||||
// terminal sat at the bottom of a just-rewritten buffer, so the next
|
||||
// flush would scroll back down and undo the restore above. This path is
|
||||
@@ -9862,7 +9983,10 @@ class CodemanApp {
|
||||
} catch {
|
||||
// Transient (offline, 5xx) — the next scroll-up past the cooldown retries.
|
||||
} finally {
|
||||
if (!replayed) this._finishBufferLoad(loadOwner, { flushQueued: true, since: 0 });
|
||||
if (anchor === 'content') this._earlyReplayTravel = null;
|
||||
this._fullHistoryRepullInFlight = false;
|
||||
this._syncHistoryReloadAction?.();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9938,6 +10062,44 @@ class CodemanApp {
|
||||
this._renderHistoryTruncationBanner();
|
||||
}
|
||||
|
||||
/** Whether the active session can offer a manual, content-anchored repair. */
|
||||
_historyReloadActionEligible() {
|
||||
const sessionId = this.activeSessionId;
|
||||
const session = this.sessions.get(sessionId);
|
||||
// Cheap state checks first: the terminal is read only for a marked session.
|
||||
// `_paneHistoryLines` is deliberately not consulted: it is recorded at the last
|
||||
// load, so a session first opened empty keeps 0 after the very burst that
|
||||
// opens the gap (#814). A pane that really holds no history (fullscreen
|
||||
// Claude) captures one screen, `_replayWouldShrinkBuffer` refuses it, and the
|
||||
// refusal dismisses the action until the next `mux-full-history` replay.
|
||||
// Docker and adopted sessions are left out: their local pane hosts a nested
|
||||
// tmux client in the alternate screen, so `?full=1` returns one screen that
|
||||
// the downgrade guard always refuses (the exclusions `paneKeepsNoHistory`
|
||||
// uses in selectSession). Remote sessions stay eligible, since the route
|
||||
// splices the remote scrollback into their capture.
|
||||
return !!(this.loadAppSettingsFromStorage?.()?.historyReloadAction !== false &&
|
||||
session && session.mode !== 'shell' && !session.docker && !session.adopt &&
|
||||
this._liveOutputSinceFullPull?.has(sessionId) &&
|
||||
!this._isLoadingBuffer &&
|
||||
!this.terminalLoadStates?.has(sessionId) && // Tab switches set this before the buffer load opens.
|
||||
this._terminalRefreshOwner?.sessionId !== sessionId && // A drop-recovery refresh is fetching.
|
||||
!this._fullHistoryRepullInFlight && !this.detachedSessions?.has(sessionId) &&
|
||||
!this._historyReloadDismissed?.has(sessionId) && !this._tilesOwnTerminal?.() &&
|
||||
!this.isTerminalAtBottom());
|
||||
}
|
||||
|
||||
/** Only eligibility/session/loading transitions may rebuild the banner. */
|
||||
_syncHistoryReloadAction() {
|
||||
const sessionId = this.activeSessionId;
|
||||
const eligible = this._historyReloadActionEligible();
|
||||
const loading = !!sessionId && this._historyReloadActionLoadingFor === sessionId &&
|
||||
!this._historyReloadDismissed?.has(sessionId);
|
||||
const last = this._historyReloadActionState;
|
||||
if (last && last.sessionId === sessionId && last.eligible === eligible && last.loading === loading) return;
|
||||
this._historyReloadActionState = { sessionId, eligible, loading };
|
||||
this._renderHistoryTruncationBanner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the partial-history banner for the active session.
|
||||
*
|
||||
@@ -9945,12 +10107,12 @@ class CodemanApp {
|
||||
* is gone forever" are not the same message and the old single boolean could
|
||||
* not tell them apart:
|
||||
* - recoverable → offer to load the rest
|
||||
* - exhausted → say so plainly, offer nothing
|
||||
* - exhausted → say so plainly
|
||||
* - at the limit → the full capture ITSELF hit the byte ceiling
|
||||
*
|
||||
* Shown only while revealed (`_setHistoryNoticeRevealed`: the user scrolled
|
||||
* to the top of this tab's buffer) and never again for a session whose notice
|
||||
* the user dismissed on this page.
|
||||
* Notices wait for a scroll to the top and respect their page-long dismissal.
|
||||
* Independently, eligible marked sessions offer Reload history while reading;
|
||||
* the same bar carries it without duplicating a Load full history control.
|
||||
*/
|
||||
_renderHistoryTruncationBanner() {
|
||||
const bar = document.getElementById('historyTruncationBar');
|
||||
@@ -9958,47 +10120,96 @@ class CodemanApp {
|
||||
const sessionId = this.activeSessionId;
|
||||
const state = sessionId ? this._historyTruncation?.get(sessionId) : null;
|
||||
const notice = computeHistoryTruncationNotice(state || {});
|
||||
if (
|
||||
!notice.visible ||
|
||||
this._historyNoticeRevealedFor !== sessionId ||
|
||||
this._historyNoticeDismissed?.has(sessionId)
|
||||
) {
|
||||
const showNotice = notice.visible && this._historyNoticeRevealedFor === sessionId &&
|
||||
!this._historyNoticeDismissed?.has(sessionId);
|
||||
const eligible = this._historyReloadActionEligible?.() ?? false;
|
||||
const loading = !!sessionId && this._historyReloadActionLoadingFor === sessionId &&
|
||||
!this._historyReloadDismissed?.has(sessionId);
|
||||
this._historyReloadActionState = { sessionId, eligible, loading };
|
||||
if (!showNotice && !eligible && !loading) {
|
||||
bar.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// `#historyTruncationBar` is a polite live region. Only the truncation
|
||||
// notice is news worth announcing; a reload-only bar re-renders on every
|
||||
// eligible scroll-up in a busy tab, so it stays silent and is reached by Tab.
|
||||
// Set before the rewrite below, so the new content is judged by it.
|
||||
bar.setAttribute('aria-live', showNotice ? 'polite' : 'off');
|
||||
bar.textContent = '';
|
||||
const label = document.createElement('span');
|
||||
label.className = 'history-trunc-text';
|
||||
label.textContent = notice.message;
|
||||
label.textContent = showNotice ? notice.message : 'Recent output may be missing from this view.';
|
||||
bar.appendChild(label);
|
||||
|
||||
if (notice.canLoadMore) {
|
||||
if (showNotice && notice.canLoadMore) {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'history-trunc-load';
|
||||
btn.textContent = 'Load full history';
|
||||
// A content-anchored pull from here stands in for Reload history, so it
|
||||
// shares Reload's loading state: the pull flips Reload eligibility, and the
|
||||
// re-render that follows must not bring the button back enabled mid-pull.
|
||||
btn.disabled = loading;
|
||||
btn.textContent = loading ? 'Loading…' : 'Load full history';
|
||||
btn.onclick = () => {
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Loading…';
|
||||
// Forced: the cooldown exists to throttle scroll gestures, not choices.
|
||||
this._maybeRefetchFullHistory({ force: true }).finally(() => {
|
||||
// When Reload history is eligible, this button is shown in its place
|
||||
// (one load control per bar), so it must keep the reader's line the same
|
||||
// way. Checked at click time, not render time: the bar only re-renders on
|
||||
// eligibility transitions, and the reader may have scrolled since.
|
||||
const anchor = this._historyReloadActionEligible() ? 'content' : 'top';
|
||||
// The top anchor keeps no loading state: it would hold the bar up after
|
||||
// a scroll back to live output, where it hides today.
|
||||
if (anchor === 'content') {
|
||||
this._historyReloadActionLoadingFor = sessionId;
|
||||
this._syncHistoryReloadAction();
|
||||
}
|
||||
return this._maybeRefetchFullHistory({ force: true, anchor }).finally(() => {
|
||||
if (anchor === 'content' && this._historyReloadActionLoadingFor === sessionId) {
|
||||
this._historyReloadActionLoadingFor = null;
|
||||
}
|
||||
this._renderHistoryTruncationBanner();
|
||||
});
|
||||
};
|
||||
bar.appendChild(btn);
|
||||
} else if (eligible || loading) {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'history-trunc-load';
|
||||
btn.disabled = loading;
|
||||
btn.textContent = loading ? 'Loading…' : 'Reload history';
|
||||
btn.onclick = () => {
|
||||
if (!this._historyReloadActionEligible()) {
|
||||
this._syncHistoryReloadAction();
|
||||
return;
|
||||
}
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Loading…';
|
||||
this._historyReloadActionLoadingFor = sessionId;
|
||||
this._syncHistoryReloadAction();
|
||||
return this._maybeRefetchFullHistory({ force: true, anchor: 'content' }).finally(() => {
|
||||
if (this._historyReloadActionLoadingFor === sessionId) this._historyReloadActionLoadingFor = null;
|
||||
this._syncHistoryReloadAction();
|
||||
});
|
||||
};
|
||||
bar.appendChild(btn);
|
||||
}
|
||||
|
||||
const dismiss = document.createElement('button');
|
||||
dismiss.type = 'button';
|
||||
dismiss.className = 'history-trunc-dismiss';
|
||||
dismiss.setAttribute('aria-label', 'Dismiss history notice');
|
||||
// Name what the × actually dismisses: a reload-only bar has no notice.
|
||||
dismiss.setAttribute('aria-label', showNotice ? 'Dismiss history notice' : 'Dismiss Reload history');
|
||||
dismiss.textContent = '×';
|
||||
dismiss.onclick = () => {
|
||||
// Sticky for this session until the page reloads: a dismissed notice used
|
||||
// to come straight back on the next tab switch.
|
||||
(this._historyNoticeDismissed ||= new Set()).add(sessionId);
|
||||
bar.hidden = true;
|
||||
// One × dismisses everything this bar carried. A notice dismissal sticks
|
||||
// for the lifetime of this page; a reload dismissal lasts until a
|
||||
// successful full mux replay clears the session's mark.
|
||||
if (showNotice) (this._historyNoticeDismissed ||= new Set()).add(sessionId);
|
||||
if (eligible || loading) (this._historyReloadDismissed ||= new Set()).add(sessionId);
|
||||
this._renderHistoryTruncationBanner();
|
||||
};
|
||||
bar.appendChild(dismiss);
|
||||
|
||||
@@ -10118,6 +10329,7 @@ class CodemanApp {
|
||||
this.activeSessionId = sessionId;
|
||||
this._activateFileBrowserSession?.(sessionId);
|
||||
if (typeof CjkInput !== 'undefined') CjkInput.restoreDraft?.(sessionId);
|
||||
this._syncHistoryReloadAction?.();
|
||||
// A keyboard row hold belongs to the session it was taken for: release it here
|
||||
// if this one resizes instead (the geometry work below then fits it).
|
||||
this._reconcileKeyboardHold?.({ resize: false });
|
||||
@@ -10421,9 +10633,12 @@ class CodemanApp {
|
||||
!session?.remote && !session?.docker && !session?.adopt && this._paneHistoryLines?.get(sessionId) === 0;
|
||||
const useFullHistory = !shellSession && (paneKeepsNoHistory || !this._fullHistoryLoaded.has(sessionId));
|
||||
if (useFullHistory) this._fullHistoryLoaded.add(sessionId);
|
||||
// Sample before fetching, as other replays do, so output during download keeps the session marked.
|
||||
const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0;
|
||||
const fetchStartedAt = performance.now();
|
||||
const tailUrl = `/api/sessions/${sessionId}/terminal?tail=${TERMINAL_TAIL_SIZE}`;
|
||||
let capture;
|
||||
let fullHistoryReplay = useFullHistory;
|
||||
try {
|
||||
capture = await this._fetchTerminalCapture(
|
||||
useFullHistory
|
||||
@@ -10444,6 +10659,7 @@ class CodemanApp {
|
||||
_crashDiag.log('FULL CAPTURE ABORTED → tail');
|
||||
// It never loaded, so the next select must be allowed to try again.
|
||||
this._fullHistoryLoaded.delete(sessionId);
|
||||
fullHistoryReplay = false;
|
||||
capture = await this._fetchTerminalCapture(tailUrl);
|
||||
}
|
||||
const headersReceivedAt = capture.headersAt;
|
||||
@@ -10489,7 +10705,7 @@ class CodemanApp {
|
||||
// cannot be actioned, and is indistinguishable from real CLI output.
|
||||
this._setHistoryTruncation(sessionId, data);
|
||||
// Use chunked write for large buffers to avoid UI jank
|
||||
const { parsedAt: freshParsedAt } = await this.chunkedTerminalWrite(
|
||||
const { parsedAt: freshParsedAt, completed } = await this.chunkedTerminalWrite(
|
||||
data.terminalBuffer,
|
||||
TERMINAL_CHUNK_SIZE,
|
||||
bufferLoadOwner,
|
||||
@@ -10500,6 +10716,11 @@ class CodemanApp {
|
||||
this._clearTerminalLoadState(sessionId, selectGen);
|
||||
return;
|
||||
}
|
||||
if (fullHistoryReplay && data.source === 'mux-full-history' && completed && (this._liveOutputGen?.get(sessionId) || 0) === liveOutputGen) {
|
||||
this._liveOutputSinceFullPull?.delete(sessionId);
|
||||
this._historyReloadDismissed?.delete(sessionId);
|
||||
this._syncHistoryReloadAction?.();
|
||||
}
|
||||
// Ensure terminal is scrolled to bottom after buffer load
|
||||
this.terminal.scrollToBottom();
|
||||
}
|
||||
@@ -10915,6 +11136,10 @@ class CodemanApp {
|
||||
}
|
||||
this.terminalBuffers.delete(sessionId);
|
||||
this.terminalBufferCache.delete(sessionId);
|
||||
this._liveOutputSinceFullPull?.delete(sessionId);
|
||||
this._historyReloadDismissed?.delete(sessionId);
|
||||
this._syncHistoryReloadAction?.();
|
||||
this._liveOutputGen?.delete(sessionId);
|
||||
this._clearHistoryTruncation(sessionId);
|
||||
this._xtermSnapshots?.delete(sessionId);
|
||||
try { localStorage.removeItem(`codeman-xs-${sessionId}`); } catch {}
|
||||
|
||||
Reference in new issue
Block a user