mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 11:19:33 +01:00
Merge pull request #583: fix(terminal): partial-history notice only when there is history to load
This commit is contained in:
commit
f2d5af2b4c
14 files changed
+561
-15
No files matched your search
+38
-3
@@ -8877,6 +8877,9 @@ class CodemanApp {
|
||||
// Set once a full-history pull has been refused as a downgrade: the
|
||||
// browser holds more than the server can return, so there is no more.
|
||||
exhausted: !!payload.exhausted,
|
||||
// tmux scrollback above the frame (null = not reported). 0 is a pane with
|
||||
// nothing a pull could add, which hides the notice outright.
|
||||
paneHistoryLines: payload.paneHistoryLines ?? null,
|
||||
});
|
||||
if (sessionId === this.activeSessionId) this._renderHistoryTruncationBanner();
|
||||
}
|
||||
@@ -8884,9 +8887,27 @@ class CodemanApp {
|
||||
/** Drop banner state for a session that is going away. */
|
||||
_clearHistoryTruncation(sessionId) {
|
||||
this._historyTruncation?.delete(sessionId);
|
||||
this._historyNoticeDismissed?.delete(sessionId);
|
||||
if (sessionId === this.activeSessionId) this._renderHistoryTruncationBanner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the partial-history notice up for `sessionId`, or retire it (null).
|
||||
*
|
||||
* The notice is LAZY: a tail replay is truncated on nearly every tab switch,
|
||||
* and a bar over the top rows on every switch described history the user had
|
||||
* not reached for. It now waits for the scroll gesture that reaches the top of
|
||||
* the browser's buffer (the moment the missing part matters, and the same
|
||||
* gesture that already re-pulls history), and goes away again once the user
|
||||
* scrolls back down to live output. A tab switch retires it (selectSession).
|
||||
*/
|
||||
_setHistoryNoticeRevealed(sessionId) {
|
||||
const next = sessionId || null;
|
||||
if ((this._historyNoticeRevealedFor ?? null) === next) return;
|
||||
this._historyNoticeRevealedFor = next;
|
||||
this._renderHistoryTruncationBanner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the partial-history banner for the active session.
|
||||
*
|
||||
@@ -8896,13 +8917,22 @@ class CodemanApp {
|
||||
* - recoverable → offer to load the rest
|
||||
* - exhausted → say so plainly, offer nothing
|
||||
* - 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.
|
||||
*/
|
||||
_renderHistoryTruncationBanner() {
|
||||
const bar = document.getElementById('historyTruncationBar');
|
||||
if (!bar) return;
|
||||
const state = this.activeSessionId ? this._historyTruncation?.get(this.activeSessionId) : null;
|
||||
const sessionId = this.activeSessionId;
|
||||
const state = sessionId ? this._historyTruncation?.get(sessionId) : null;
|
||||
const notice = computeHistoryTruncationNotice(state || {});
|
||||
if (!notice.visible) {
|
||||
if (
|
||||
!notice.visible ||
|
||||
this._historyNoticeRevealedFor !== sessionId ||
|
||||
this._historyNoticeDismissed?.has(sessionId)
|
||||
) {
|
||||
bar.hidden = true;
|
||||
return;
|
||||
}
|
||||
@@ -8935,6 +8965,9 @@ class CodemanApp {
|
||||
dismiss.setAttribute('aria-label', 'Dismiss history notice');
|
||||
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;
|
||||
};
|
||||
bar.appendChild(dismiss);
|
||||
@@ -9048,7 +9081,9 @@ class CodemanApp {
|
||||
this._activateFileBrowserSession?.(sessionId);
|
||||
// Repaint the partial-history banner for the tab being switched TO. The
|
||||
// replay paths refresh it when their fetch lands; without this the previous
|
||||
// session's notice stays on screen until then (#258).
|
||||
// session's notice stays on screen until then (#258). The switch lands at
|
||||
// live output, so the notice waits for a scroll to the top again.
|
||||
this._historyNoticeRevealedFor = null;
|
||||
this._renderHistoryTruncationBanner();
|
||||
try { localStorage.setItem('codeman-active-session', sessionId); } catch {}
|
||||
// Narrow SSE filter to the active session — server stops streaming
|
||||
|
||||
@@ -1860,7 +1860,10 @@ function escapeHtml(text) {
|
||||
function formatHistoryBytes(bytes) {
|
||||
const n = typeof bytes === 'number' && isFinite(bytes) && bytes > 0 ? bytes : 0;
|
||||
if (n < 1024) return 'less than 1 KB';
|
||||
if (n < 1024 * 1024) return `${Math.round(n / 1024)} KB`;
|
||||
// Switch on the ROUNDED value: a 1 MiB tail cut back to a line boundary is
|
||||
// just under 1 MiB and used to print as "1024 KB".
|
||||
const kb = Math.round(n / 1024);
|
||||
if (kb < 1024) return `${kb} KB`;
|
||||
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
@@ -1874,12 +1877,27 @@ function formatHistoryBytes(bytes) {
|
||||
* - atCeiling: the FULL capture itself hit the byte ceiling
|
||||
* - exhausted: a full pull was refused as a downgrade, so this is all there is
|
||||
*
|
||||
* ⚠️ `truncated` measures the server's BYTE stream, not history a pull can
|
||||
* return. `paneHistoryLines` (tmux `#{history_size}`) is the latter: 0 means the
|
||||
* pane keeps no scrollback at all (a fullscreen CLI in the alternate screen,
|
||||
* whose transcript lives in the CLI and is scrolled there), so the bytes a tail
|
||||
* cut dropped are old repaint frames that `full=1` cannot bring back. Measured
|
||||
* on live fullscreen claude panes: "4.8 MB more" was ~33 copies of one frame,
|
||||
* and the button only ever ended in the downgrade refusal. Nothing to offer,
|
||||
* nothing to say. Absent means unknown and keeps the byte-based behaviour.
|
||||
*
|
||||
* @param {{truncated?: boolean, reason?: string|null, source?: string|null,
|
||||
* fullSize?: number, retainedBytes?: number, exhausted?: boolean}} state
|
||||
* fullSize?: number, retainedBytes?: number, exhausted?: boolean,
|
||||
* paneHistoryLines?: number|null}} state
|
||||
* @returns {{visible: boolean, message: string, canLoadMore: boolean}}
|
||||
*/
|
||||
function computeHistoryTruncationNotice(state = {}) {
|
||||
if (!state.truncated) return { visible: false, message: '', canLoadMore: false };
|
||||
const historyLines =
|
||||
typeof state.paneHistoryLines === 'number' && Number.isFinite(state.paneHistoryLines)
|
||||
? Math.max(0, state.paneHistoryLines)
|
||||
: null;
|
||||
if (historyLines === 0) return { visible: false, message: '', canLoadMore: false };
|
||||
|
||||
const retained = Math.max(0, state.retainedBytes || 0);
|
||||
const dropped = Math.max(0, (state.fullSize || 0) - retained);
|
||||
@@ -1902,9 +1920,15 @@ function computeHistoryTruncationNotice(state = {}) {
|
||||
canLoadMore: false,
|
||||
};
|
||||
}
|
||||
// Name what a pull can actually return when the server said: the byte gap
|
||||
// counts repaints and redraw bloat, and overstates it many times over.
|
||||
const more =
|
||||
historyLines !== null
|
||||
? `${historyLines.toLocaleString('en-US')} ${historyLines === 1 ? 'line of scrollback is' : 'lines of scrollback are'} retained.`
|
||||
: `${formatHistoryBytes(dropped)} more may still be retained.`;
|
||||
return {
|
||||
visible: true,
|
||||
message: `Showing the most recent ${shown} of this session. ${formatHistoryBytes(dropped)} more may still be retained.`,
|
||||
message: `Showing the most recent ${shown} of this session. ${more}`,
|
||||
canLoadMore: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3669,10 +3669,24 @@ Object.assign(CodemanApp.prototype, {
|
||||
* the unbounded path. Must be called AFTER scrollLines(), since the check is on
|
||||
* the resulting position, and it is deliberately not folded into
|
||||
* _noteTerminalUserScroll for exactly that reason.
|
||||
*
|
||||
* It is also what brings up the partial-history notice, and what retires it
|
||||
* once a downward scroll is back at live output (_setHistoryNoticeRevealed).
|
||||
* The reveal waits for the pull this gesture started, so the notice describes
|
||||
* what the pull left rather than flashing the state it is about to replace.
|
||||
*/
|
||||
_maybeLoadMoreHistoryOnScroll(lines) {
|
||||
if (lines >= 0) return;
|
||||
if (this.terminal?.buffer?.active?.viewportY === 0) this._maybeRefetchFullHistory?.();
|
||||
if (lines > 0) {
|
||||
if (this.isTerminalAtBottom()) this._setHistoryNoticeRevealed?.(null);
|
||||
return;
|
||||
}
|
||||
if (lines === 0 || this.terminal?.buffer?.active?.viewportY !== 0) return;
|
||||
const sessionId = this.activeSessionId;
|
||||
Promise.resolve(this._maybeRefetchFullHistory?.())
|
||||
.catch(() => {})
|
||||
.then(() => {
|
||||
if (sessionId && this.activeSessionId === sessionId) this._setHistoryNoticeRevealed?.(sessionId);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -3279,6 +3279,12 @@ export function registerSessionRoutes(
|
||||
// damage that does not exist.
|
||||
captureCols: hasLiveMuxBuffer ? captureOpts.capturedGeometry?.cols : undefined,
|
||||
captureRows: hasLiveMuxBuffer ? captureOpts.capturedGeometry?.rows : undefined,
|
||||
// Rows tmux holds above the visible frame, which is the most a `full=1`
|
||||
// pull can add. `truncated` measures the BYTE stream, and for a pane that
|
||||
// keeps no scrollback (a fullscreen CLI in the alternate screen) the bytes
|
||||
// a tail cut drops are old repaints that no request can bring back, so a
|
||||
// client must not offer to load them. Absent when the pane was not read.
|
||||
paneHistoryLines: hasLiveMuxBuffer ? captureOpts.capturedHistoryLines : undefined,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user