@causyne/agent 1.20.112 → 1.20.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
package/src/tui/usageCard.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
6
6
|
import { paint, fill, bold, dim, GLYPHS, HAS_COLOR } from './theme.js';
|
|
7
|
-
import { visibleWidth, padEnd, truncate } from './text.js';
|
|
7
|
+
import { visibleWidth, padEnd, safeDisplay, truncate } from './text.js';
|
|
8
8
|
import { FRAME } from './overlay.js';
|
|
9
9
|
import { TokenTracker } from '../tokenTracker.js';
|
|
10
10
|
import { loadConfig } from '../config.js';
|
|
@@ -12,16 +12,26 @@ import { loadConfig } from '../config.js';
|
|
|
12
12
|
import { buildContextReport } from '../reporting.js';
|
|
13
13
|
import { isAntigravityProvider } from '../providers/antigravity.js';
|
|
14
14
|
import { isAcpProvider } from '../providers/acp.js';
|
|
15
|
+
function oneLineText(value) {
|
|
16
|
+
return safeDisplay(value).replace(/\s+/g, ' ').trim();
|
|
17
|
+
}
|
|
15
18
|
function formatNumber(value) {
|
|
16
|
-
|
|
19
|
+
const num = Number(value);
|
|
20
|
+
return (Number.isFinite(num) ? Math.max(0, Math.round(num)) : 0).toLocaleString('en-US');
|
|
21
|
+
}
|
|
22
|
+
function formatCostEstimate(costUsd) {
|
|
23
|
+
const num = Number(costUsd);
|
|
24
|
+
return Number.isFinite(num) && num > 0 ? ` ${dim(`$${num.toFixed(4)} est`)}` : '';
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* Render a visual progress bar for context capacity or token budget.
|
|
20
28
|
*/
|
|
21
29
|
export function renderProgressBar(percent, barLength = 24, invertColors = false) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
30
|
+
const safePercent = Number.isFinite(percent) ? percent : 0;
|
|
31
|
+
const safeLength = Number.isFinite(barLength) ? Math.max(1, Math.floor(barLength)) : 24;
|
|
32
|
+
const clamped = Math.max(0, Math.min(100, Math.round(safePercent)));
|
|
33
|
+
const filledChars = Math.max(0, Math.min(safeLength, Math.round((clamped / 100) * safeLength)));
|
|
34
|
+
const emptyChars = Math.max(0, safeLength - filledChars);
|
|
25
35
|
let role;
|
|
26
36
|
if (!invertColors) {
|
|
27
37
|
// Standard: higher percentage is good (e.g. % context remaining)
|
|
@@ -48,20 +58,38 @@ export async function collectUsageCardData(loop) {
|
|
|
48
58
|
const cumulative = await tracker.getCumulativeUsage();
|
|
49
59
|
const daily = await tracker.getDailyUsage();
|
|
50
60
|
const config = loadConfig();
|
|
51
|
-
const provider =
|
|
52
|
-
const model =
|
|
61
|
+
const provider = oneLineText(config.provider || 'default') || 'default';
|
|
62
|
+
const model = oneLineText(config.model || 'default') || 'default';
|
|
53
63
|
const isAgy = isAntigravityProvider(provider);
|
|
54
64
|
const isAcp = isAcpProvider(provider);
|
|
55
65
|
const billingNote = (isAgy || isAcp)
|
|
56
66
|
? 'Local CLI / ACP peer'
|
|
57
67
|
: 'BYOK (provider billed)';
|
|
68
|
+
const finiteNonNeg = (value, fallback = 0) => {
|
|
69
|
+
const n = Number(value);
|
|
70
|
+
return Number.isFinite(n) && n >= 0 ? n : fallback;
|
|
71
|
+
};
|
|
58
72
|
// Context accounting
|
|
59
73
|
const contextReport = buildContextReport();
|
|
60
|
-
const
|
|
74
|
+
const rawPoolTokens = finiteNonNeg(contextReport?.approxTokenPool, 250000);
|
|
75
|
+
const poolTokens = rawPoolTokens > 0 ? Math.floor(rawPoolTokens) : 250000;
|
|
61
76
|
// Measure active messages tokens
|
|
62
77
|
let messageChars = 0;
|
|
63
78
|
let messageCount = 0;
|
|
64
|
-
|
|
79
|
+
let rawMessages = [];
|
|
80
|
+
if (Array.isArray(loop?.messages)) {
|
|
81
|
+
rawMessages = loop.messages;
|
|
82
|
+
}
|
|
83
|
+
else if (typeof loop?.memoryManager?.loadHistory === 'function') {
|
|
84
|
+
try {
|
|
85
|
+
const loaded = loop.memoryManager.loadHistory();
|
|
86
|
+
if (Array.isArray(loaded))
|
|
87
|
+
rawMessages = loaded;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
rawMessages = [];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
65
93
|
if (Array.isArray(rawMessages)) {
|
|
66
94
|
messageCount = rawMessages.length;
|
|
67
95
|
for (const msg of rawMessages) {
|
|
@@ -79,27 +107,31 @@ export async function collectUsageCardData(loop) {
|
|
|
79
107
|
}
|
|
80
108
|
}
|
|
81
109
|
const messageTokens = Math.round(messageChars / 4);
|
|
82
|
-
const coreToolTokens = contextReport
|
|
110
|
+
const coreToolTokens = Math.floor(finiteNonNeg(contextReport?.core?.tokens, 5000));
|
|
83
111
|
const contextUsed = messageTokens + coreToolTokens;
|
|
84
112
|
const contextPctLeft = Math.max(0, Math.min(100, Math.round(((poolTokens - contextUsed) / poolTokens) * 100)));
|
|
85
113
|
// Budget
|
|
86
114
|
const budget = config.tokenBudget || {};
|
|
87
115
|
const budgetEnabled = Boolean(budget.enabled);
|
|
88
|
-
const budgetLimitTokens =
|
|
116
|
+
const budgetLimitTokens = Math.floor(finiteNonNeg(budget.maxTokensPerDay, 0));
|
|
117
|
+
const dailyTokens = finiteNonNeg(daily?.totalTokens, 0);
|
|
89
118
|
const budgetPercentUsed = budgetLimitTokens > 0
|
|
90
|
-
? Math.round((
|
|
119
|
+
? Math.round((dailyTokens / budgetLimitTokens) * 100)
|
|
91
120
|
: 0;
|
|
92
|
-
const
|
|
121
|
+
const rawCostCeiling = finiteNonNeg(budget.maxCostUsd, 0);
|
|
122
|
+
const sessionId = oneLineText(loop?.memoryManager?.sessionId || 'default') || 'default';
|
|
123
|
+
const sessionTokens = finiteNonNeg(tracker.sessionTokens, 0) || finiteNonNeg(tracker.taskTokens, 0);
|
|
124
|
+
const sessionCostUsd = finiteNonNeg(tracker.sessionCostUsd, 0) || finiteNonNeg(tracker.taskCostUsd, 0);
|
|
93
125
|
return {
|
|
94
126
|
sessionId,
|
|
95
127
|
sessionTurns: messageCount,
|
|
96
|
-
sessionTokens
|
|
97
|
-
sessionCostUsd
|
|
98
|
-
dailyTokens
|
|
99
|
-
dailyCostUsd: daily
|
|
100
|
-
lifetimeTokens: cumulative
|
|
101
|
-
lifetimeCostUsd: cumulative
|
|
102
|
-
lifetimeCalls: cumulative
|
|
128
|
+
sessionTokens,
|
|
129
|
+
sessionCostUsd,
|
|
130
|
+
dailyTokens,
|
|
131
|
+
dailyCostUsd: finiteNonNeg(daily?.totalCostUsd, 0),
|
|
132
|
+
lifetimeTokens: finiteNonNeg(cumulative?.totalTokens, 0),
|
|
133
|
+
lifetimeCostUsd: finiteNonNeg(cumulative?.totalCostUsd, 0),
|
|
134
|
+
lifetimeCalls: Math.floor(finiteNonNeg(cumulative?.totalCalls, 0)),
|
|
103
135
|
contextUsedTokens: contextUsed,
|
|
104
136
|
contextPoolTokens: poolTokens,
|
|
105
137
|
contextPercentLeft: contextPctLeft,
|
|
@@ -108,7 +140,7 @@ export async function collectUsageCardData(loop) {
|
|
|
108
140
|
billingNote,
|
|
109
141
|
budgetEnabled,
|
|
110
142
|
budgetLimitTokens,
|
|
111
|
-
budgetCostCeilingUsd:
|
|
143
|
+
budgetCostCeilingUsd: rawCostCeiling > 0 ? rawCostCeiling : undefined,
|
|
112
144
|
budgetPercentUsed
|
|
113
145
|
};
|
|
114
146
|
}
|
|
@@ -116,14 +148,15 @@ export async function collectUsageCardData(loop) {
|
|
|
116
148
|
* Render the usage card as an array of styled terminal rows, exactly matching `width`.
|
|
117
149
|
*/
|
|
118
150
|
export function renderUsageCardRows(data, width) {
|
|
119
|
-
const
|
|
151
|
+
const safeWidth = Number.isFinite(width) ? Math.floor(width) : 80;
|
|
152
|
+
const frameWidth = Math.max(40, safeWidth);
|
|
120
153
|
const innerWidth = Math.max(20, frameWidth - 4); // border (1) + pad (1) on each side
|
|
121
154
|
const borderRole = 'accent';
|
|
122
155
|
const surfaceRole = 'surface';
|
|
123
156
|
// Header row
|
|
124
157
|
const title = ` ${bold(paint('accent', 'Usage & Context'))} `;
|
|
125
158
|
const closeHint = ` ${dim('esc close')} `;
|
|
126
|
-
const hLineLength = Math.max(0, frameWidth -
|
|
159
|
+
const hLineLength = Math.max(0, frameWidth - 3 - visibleWidth(title) - visibleWidth(closeHint));
|
|
127
160
|
const topBorder = paint(borderRole, FRAME.tl + FRAME.h)
|
|
128
161
|
+ title
|
|
129
162
|
+ paint(borderRole, FRAME.h.repeat(hLineLength))
|
|
@@ -132,34 +165,36 @@ export function renderUsageCardRows(data, width) {
|
|
|
132
165
|
// Content lines inside card
|
|
133
166
|
const lines = [];
|
|
134
167
|
// 1. Session ID & Message count
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
168
|
+
const cleanSession = oneLineText(data.sessionId || 'default') || 'default';
|
|
169
|
+
const sessionChars = Array.from(cleanSession);
|
|
170
|
+
const shortSession = sessionChars.length > 24
|
|
171
|
+
? `${sessionChars.slice(0, 10).join('')}…${sessionChars.slice(-10).join('')}`
|
|
172
|
+
: cleanSession;
|
|
173
|
+
lines.push(`${dim('Session/Chat :')} ${paint('ink', shortSession)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`);
|
|
139
174
|
// 2. Context Window & Progress bar
|
|
140
|
-
const
|
|
141
|
-
|
|
175
|
+
const safePercentLeft = Number.isFinite(data.contextPercentLeft)
|
|
176
|
+
? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft)))
|
|
177
|
+
: 0;
|
|
178
|
+
const pBar = renderProgressBar(safePercentLeft, 22, false);
|
|
179
|
+
lines.push(`${dim('Context :')} ${bold(`${safePercentLeft}% left`)} ${dim(`(${formatNumber(data.contextUsedTokens)} used / ${formatNumber(data.contextPoolTokens)})`)} ${pBar}`);
|
|
142
180
|
// 3. This Session Usage
|
|
143
|
-
|
|
144
|
-
? ` ${dim(`$${data.sessionCostUsd.toFixed(4)} est`)}`
|
|
145
|
-
: '';
|
|
146
|
-
lines.push(`${dim('This Session :')} ${bold(formatNumber(data.sessionTokens))} tokens${sessionSpend}`);
|
|
181
|
+
lines.push(`${dim('This Session :')} ${bold(formatNumber(data.sessionTokens))} tokens${formatCostEstimate(data.sessionCostUsd)}`);
|
|
147
182
|
// 4. Daily Usage (Today)
|
|
148
|
-
|
|
149
|
-
? ` ${dim(`$${data.dailyCostUsd.toFixed(4)} est`)}`
|
|
150
|
-
: '';
|
|
151
|
-
lines.push(`${dim('Today (24h) :')} ${bold(formatNumber(data.dailyTokens))} tokens${dailySpend}`);
|
|
183
|
+
lines.push(`${dim('Today (24h) :')} ${bold(formatNumber(data.dailyTokens))} tokens${formatCostEstimate(data.dailyCostUsd)}`);
|
|
152
184
|
// 5. All-Time / Lifetime Usage
|
|
153
|
-
|
|
154
|
-
? ` ${dim(`$${data.lifetimeCostUsd.toFixed(4)} est`)}`
|
|
155
|
-
: '';
|
|
156
|
-
lines.push(`${dim('All-Time :')} ${bold(formatNumber(data.lifetimeTokens))} tokens${lifeSpend} ${dim(`(${formatNumber(data.lifetimeCalls)} calls)`)}`);
|
|
185
|
+
lines.push(`${dim('All-Time :')} ${bold(formatNumber(data.lifetimeTokens))} tokens${formatCostEstimate(data.lifetimeCostUsd)} ${dim(`(${formatNumber(data.lifetimeCalls)} calls)`)}`);
|
|
157
186
|
// 6. Model & Provider
|
|
158
|
-
|
|
187
|
+
const cleanProvider = oneLineText(data.provider || 'default') || 'default';
|
|
188
|
+
const cleanModel = oneLineText(data.model || 'default') || 'default';
|
|
189
|
+
const cleanBilling = oneLineText(data.billingNote || '');
|
|
190
|
+
lines.push(`${dim('Active Model :')} ${paint('accent', `${cleanProvider} / ${cleanModel}`)}${cleanBilling ? ` ${dim(`(${cleanBilling})`)}` : ''}`);
|
|
159
191
|
// 7. Optional Budget
|
|
160
|
-
if (data.budgetEnabled && data.budgetLimitTokens) {
|
|
161
|
-
const
|
|
162
|
-
|
|
192
|
+
if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
|
|
193
|
+
const safeBudgetPercent = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
|
|
194
|
+
? Math.max(0, Math.round(data.budgetPercentUsed))
|
|
195
|
+
: 0;
|
|
196
|
+
const bBar = renderProgressBar(safeBudgetPercent, 16, true);
|
|
197
|
+
lines.push(`${dim('Daily Budget :')} ${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tokens (${safeBudgetPercent}% used) ${bBar}`);
|
|
163
198
|
}
|
|
164
199
|
// Construct boxed rows
|
|
165
200
|
const edge = paint(borderRole, FRAME.v);
|
package/src/tui/usageCard.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
7
7
|
import { paint, fill, bold, dim, GLYPHS, HAS_COLOR } from './theme.js';
|
|
8
|
-
import { visibleWidth, padEnd, truncate } from './text.js';
|
|
8
|
+
import { visibleWidth, padEnd, safeDisplay, truncate } from './text.js';
|
|
9
9
|
import { FRAME } from './overlay.js';
|
|
10
10
|
import { TokenTracker } from '../tokenTracker.js';
|
|
11
11
|
import { loadConfig } from '../config.js';
|
|
@@ -36,17 +36,29 @@ export interface UsageCardData {
|
|
|
36
36
|
budgetPercentUsed?: number | undefined;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
function oneLineText(value: unknown): string {
|
|
40
|
+
return safeDisplay(value).replace(/\s+/g, ' ').trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
function formatNumber(value: number | undefined | null): string {
|
|
40
|
-
|
|
44
|
+
const num = Number(value);
|
|
45
|
+
return (Number.isFinite(num) ? Math.max(0, Math.round(num)) : 0).toLocaleString('en-US');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function formatCostEstimate(costUsd: number): string {
|
|
49
|
+
const num = Number(costUsd);
|
|
50
|
+
return Number.isFinite(num) && num > 0 ? ` ${dim(`$${num.toFixed(4)} est`)}` : '';
|
|
41
51
|
}
|
|
42
52
|
|
|
43
53
|
/**
|
|
44
54
|
* Render a visual progress bar for context capacity or token budget.
|
|
45
55
|
*/
|
|
46
56
|
export function renderProgressBar(percent: number, barLength: number = 24, invertColors: boolean = false): string {
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
57
|
+
const safePercent = Number.isFinite(percent) ? percent : 0;
|
|
58
|
+
const safeLength = Number.isFinite(barLength) ? Math.max(1, Math.floor(barLength)) : 24;
|
|
59
|
+
const clamped = Math.max(0, Math.min(100, Math.round(safePercent)));
|
|
60
|
+
const filledChars = Math.max(0, Math.min(safeLength, Math.round((clamped / 100) * safeLength)));
|
|
61
|
+
const emptyChars = Math.max(0, safeLength - filledChars);
|
|
50
62
|
|
|
51
63
|
let role: string;
|
|
52
64
|
if (!invertColors) {
|
|
@@ -78,25 +90,41 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
|
|
|
78
90
|
const daily = await tracker.getDailyUsage();
|
|
79
91
|
const config = loadConfig() as Record<string, any>;
|
|
80
92
|
|
|
81
|
-
const provider =
|
|
82
|
-
const model =
|
|
93
|
+
const provider = oneLineText(config.provider || 'default') || 'default';
|
|
94
|
+
const model = oneLineText(config.model || 'default') || 'default';
|
|
83
95
|
const isAgy = isAntigravityProvider(provider);
|
|
84
96
|
const isAcp = isAcpProvider(provider);
|
|
85
97
|
const billingNote = (isAgy || isAcp)
|
|
86
98
|
? 'Local CLI / ACP peer'
|
|
87
99
|
: 'BYOK (provider billed)';
|
|
88
100
|
|
|
101
|
+
const finiteNonNeg = (value: unknown, fallback = 0): number => {
|
|
102
|
+
const n = Number(value);
|
|
103
|
+
return Number.isFinite(n) && n >= 0 ? n : fallback;
|
|
104
|
+
};
|
|
105
|
+
|
|
89
106
|
// Context accounting
|
|
90
107
|
const contextReport = buildContextReport();
|
|
91
|
-
const
|
|
108
|
+
const rawPoolTokens = finiteNonNeg(contextReport?.approxTokenPool, 250000);
|
|
109
|
+
const poolTokens = rawPoolTokens > 0 ? Math.floor(rawPoolTokens) : 250000;
|
|
92
110
|
|
|
93
111
|
// Measure active messages tokens
|
|
94
112
|
let messageChars = 0;
|
|
95
113
|
let messageCount = 0;
|
|
96
|
-
|
|
114
|
+
let rawMessages: unknown[] = [];
|
|
115
|
+
if (Array.isArray(loop?.messages)) {
|
|
116
|
+
rawMessages = loop.messages;
|
|
117
|
+
} else if (typeof loop?.memoryManager?.loadHistory === 'function') {
|
|
118
|
+
try {
|
|
119
|
+
const loaded = loop.memoryManager.loadHistory();
|
|
120
|
+
if (Array.isArray(loaded)) rawMessages = loaded;
|
|
121
|
+
} catch {
|
|
122
|
+
rawMessages = [];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
97
125
|
if (Array.isArray(rawMessages)) {
|
|
98
126
|
messageCount = rawMessages.length;
|
|
99
|
-
for (const msg of rawMessages) {
|
|
127
|
+
for (const msg of rawMessages as Array<Record<string, any>>) {
|
|
100
128
|
if (typeof msg?.content === 'string') {
|
|
101
129
|
messageChars += msg.content.length;
|
|
102
130
|
} else if (Array.isArray(msg?.content)) {
|
|
@@ -109,30 +137,34 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
|
|
|
109
137
|
}
|
|
110
138
|
|
|
111
139
|
const messageTokens = Math.round(messageChars / 4);
|
|
112
|
-
const coreToolTokens = contextReport
|
|
140
|
+
const coreToolTokens = Math.floor(finiteNonNeg(contextReport?.core?.tokens, 5000));
|
|
113
141
|
const contextUsed = messageTokens + coreToolTokens;
|
|
114
142
|
const contextPctLeft = Math.max(0, Math.min(100, Math.round(((poolTokens - contextUsed) / poolTokens) * 100)));
|
|
115
143
|
|
|
116
144
|
// Budget
|
|
117
145
|
const budget = config.tokenBudget || {};
|
|
118
146
|
const budgetEnabled = Boolean(budget.enabled);
|
|
119
|
-
const budgetLimitTokens =
|
|
147
|
+
const budgetLimitTokens = Math.floor(finiteNonNeg(budget.maxTokensPerDay, 0));
|
|
148
|
+
const dailyTokens = finiteNonNeg(daily?.totalTokens, 0);
|
|
120
149
|
const budgetPercentUsed = budgetLimitTokens > 0
|
|
121
|
-
? Math.round((
|
|
150
|
+
? Math.round((dailyTokens / budgetLimitTokens) * 100)
|
|
122
151
|
: 0;
|
|
152
|
+
const rawCostCeiling = finiteNonNeg(budget.maxCostUsd, 0);
|
|
123
153
|
|
|
124
|
-
const sessionId =
|
|
154
|
+
const sessionId = oneLineText(loop?.memoryManager?.sessionId || 'default') || 'default';
|
|
155
|
+
const sessionTokens = finiteNonNeg(tracker.sessionTokens, 0) || finiteNonNeg(tracker.taskTokens, 0);
|
|
156
|
+
const sessionCostUsd = finiteNonNeg(tracker.sessionCostUsd, 0) || finiteNonNeg(tracker.taskCostUsd, 0);
|
|
125
157
|
|
|
126
158
|
return {
|
|
127
159
|
sessionId,
|
|
128
160
|
sessionTurns: messageCount,
|
|
129
|
-
sessionTokens
|
|
130
|
-
sessionCostUsd
|
|
131
|
-
dailyTokens
|
|
132
|
-
dailyCostUsd: daily
|
|
133
|
-
lifetimeTokens: cumulative
|
|
134
|
-
lifetimeCostUsd: cumulative
|
|
135
|
-
lifetimeCalls: cumulative
|
|
161
|
+
sessionTokens,
|
|
162
|
+
sessionCostUsd,
|
|
163
|
+
dailyTokens,
|
|
164
|
+
dailyCostUsd: finiteNonNeg(daily?.totalCostUsd, 0),
|
|
165
|
+
lifetimeTokens: finiteNonNeg(cumulative?.totalTokens, 0),
|
|
166
|
+
lifetimeCostUsd: finiteNonNeg(cumulative?.totalCostUsd, 0),
|
|
167
|
+
lifetimeCalls: Math.floor(finiteNonNeg(cumulative?.totalCalls, 0)),
|
|
136
168
|
contextUsedTokens: contextUsed,
|
|
137
169
|
contextPoolTokens: poolTokens,
|
|
138
170
|
contextPercentLeft: contextPctLeft,
|
|
@@ -141,7 +173,7 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
|
|
|
141
173
|
billingNote,
|
|
142
174
|
budgetEnabled,
|
|
143
175
|
budgetLimitTokens,
|
|
144
|
-
budgetCostCeilingUsd:
|
|
176
|
+
budgetCostCeilingUsd: rawCostCeiling > 0 ? rawCostCeiling : undefined,
|
|
145
177
|
budgetPercentUsed
|
|
146
178
|
};
|
|
147
179
|
}
|
|
@@ -150,7 +182,8 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
|
|
|
150
182
|
* Render the usage card as an array of styled terminal rows, exactly matching `width`.
|
|
151
183
|
*/
|
|
152
184
|
export function renderUsageCardRows(data: UsageCardData, width: number): string[] {
|
|
153
|
-
const
|
|
185
|
+
const safeWidth = Number.isFinite(width) ? Math.floor(width) : 80;
|
|
186
|
+
const frameWidth = Math.max(40, safeWidth);
|
|
154
187
|
const innerWidth = Math.max(20, frameWidth - 4); // border (1) + pad (1) on each side
|
|
155
188
|
const borderRole = 'accent';
|
|
156
189
|
const surfaceRole = 'surface';
|
|
@@ -158,7 +191,7 @@ export function renderUsageCardRows(data: UsageCardData, width: number): string[
|
|
|
158
191
|
// Header row
|
|
159
192
|
const title = ` ${bold(paint('accent', 'Usage & Context'))} `;
|
|
160
193
|
const closeHint = ` ${dim('esc close')} `;
|
|
161
|
-
const hLineLength = Math.max(0, frameWidth -
|
|
194
|
+
const hLineLength = Math.max(0, frameWidth - 3 - visibleWidth(title) - visibleWidth(closeHint));
|
|
162
195
|
const topBorder = paint(borderRole, FRAME.tl + FRAME.h)
|
|
163
196
|
+ title
|
|
164
197
|
+ paint(borderRole, FRAME.h.repeat(hLineLength))
|
|
@@ -169,53 +202,55 @@ export function renderUsageCardRows(data: UsageCardData, width: number): string[
|
|
|
169
202
|
const lines: string[] = [];
|
|
170
203
|
|
|
171
204
|
// 1. Session ID & Message count
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
const cleanSession = oneLineText(data.sessionId || 'default') || 'default';
|
|
206
|
+
const sessionChars = Array.from(cleanSession);
|
|
207
|
+
const shortSession = sessionChars.length > 24
|
|
208
|
+
? `${sessionChars.slice(0, 10).join('')}…${sessionChars.slice(-10).join('')}`
|
|
209
|
+
: cleanSession;
|
|
175
210
|
lines.push(
|
|
176
|
-
`${dim('Session/Chat :')} ${paint('ink', shortSession)} ${dim(`(${data.sessionTurns} messages)`)}`
|
|
211
|
+
`${dim('Session/Chat :')} ${paint('ink', shortSession)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`
|
|
177
212
|
);
|
|
178
213
|
|
|
179
214
|
// 2. Context Window & Progress bar
|
|
180
|
-
const
|
|
215
|
+
const safePercentLeft = Number.isFinite(data.contextPercentLeft)
|
|
216
|
+
? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft)))
|
|
217
|
+
: 0;
|
|
218
|
+
const pBar = renderProgressBar(safePercentLeft, 22, false);
|
|
181
219
|
lines.push(
|
|
182
|
-
`${dim('Context :')} ${bold(`${
|
|
220
|
+
`${dim('Context :')} ${bold(`${safePercentLeft}% left`)} ${dim(`(${formatNumber(data.contextUsedTokens)} used / ${formatNumber(data.contextPoolTokens)})`)} ${pBar}`
|
|
183
221
|
);
|
|
184
222
|
|
|
185
223
|
// 3. This Session Usage
|
|
186
|
-
const sessionSpend = data.sessionCostUsd > 0
|
|
187
|
-
? ` ${dim(`$${data.sessionCostUsd.toFixed(4)} est`)}`
|
|
188
|
-
: '';
|
|
189
224
|
lines.push(
|
|
190
|
-
`${dim('This Session :')} ${bold(formatNumber(data.sessionTokens))} tokens${
|
|
225
|
+
`${dim('This Session :')} ${bold(formatNumber(data.sessionTokens))} tokens${formatCostEstimate(data.sessionCostUsd)}`
|
|
191
226
|
);
|
|
192
227
|
|
|
193
228
|
// 4. Daily Usage (Today)
|
|
194
|
-
const dailySpend = data.dailyCostUsd > 0
|
|
195
|
-
? ` ${dim(`$${data.dailyCostUsd.toFixed(4)} est`)}`
|
|
196
|
-
: '';
|
|
197
229
|
lines.push(
|
|
198
|
-
`${dim('Today (24h) :')} ${bold(formatNumber(data.dailyTokens))} tokens${
|
|
230
|
+
`${dim('Today (24h) :')} ${bold(formatNumber(data.dailyTokens))} tokens${formatCostEstimate(data.dailyCostUsd)}`
|
|
199
231
|
);
|
|
200
232
|
|
|
201
233
|
// 5. All-Time / Lifetime Usage
|
|
202
|
-
const lifeSpend = data.lifetimeCostUsd > 0
|
|
203
|
-
? ` ${dim(`$${data.lifetimeCostUsd.toFixed(4)} est`)}`
|
|
204
|
-
: '';
|
|
205
234
|
lines.push(
|
|
206
|
-
`${dim('All-Time :')} ${bold(formatNumber(data.lifetimeTokens))} tokens${
|
|
235
|
+
`${dim('All-Time :')} ${bold(formatNumber(data.lifetimeTokens))} tokens${formatCostEstimate(data.lifetimeCostUsd)} ${dim(`(${formatNumber(data.lifetimeCalls)} calls)`)}`
|
|
207
236
|
);
|
|
208
237
|
|
|
209
238
|
// 6. Model & Provider
|
|
239
|
+
const cleanProvider = oneLineText(data.provider || 'default') || 'default';
|
|
240
|
+
const cleanModel = oneLineText(data.model || 'default') || 'default';
|
|
241
|
+
const cleanBilling = oneLineText(data.billingNote || '');
|
|
210
242
|
lines.push(
|
|
211
|
-
`${dim('Active Model :')} ${paint('accent', `${
|
|
243
|
+
`${dim('Active Model :')} ${paint('accent', `${cleanProvider} / ${cleanModel}`)}${cleanBilling ? ` ${dim(`(${cleanBilling})`)}` : ''}`
|
|
212
244
|
);
|
|
213
245
|
|
|
214
246
|
// 7. Optional Budget
|
|
215
|
-
if (data.budgetEnabled && data.budgetLimitTokens) {
|
|
216
|
-
const
|
|
247
|
+
if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
|
|
248
|
+
const safeBudgetPercent = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
|
|
249
|
+
? Math.max(0, Math.round(data.budgetPercentUsed))
|
|
250
|
+
: 0;
|
|
251
|
+
const bBar = renderProgressBar(safeBudgetPercent, 16, true);
|
|
217
252
|
lines.push(
|
|
218
|
-
`${dim('Daily Budget :')} ${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tokens (${
|
|
253
|
+
`${dim('Daily Budget :')} ${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tokens (${safeBudgetPercent}% used) ${bBar}`
|
|
219
254
|
);
|
|
220
255
|
}
|
|
221
256
|
|
package/src/tui/viewport.js
CHANGED
|
@@ -48,9 +48,9 @@ export class ScrollAcceleration {
|
|
|
48
48
|
intervals;
|
|
49
49
|
lastTick;
|
|
50
50
|
constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 } = {}) {
|
|
51
|
-
this.historySize = history;
|
|
52
|
-
this.streakTimeout = streakTimeout;
|
|
53
|
-
this.minTickInterval = minTickInterval;
|
|
51
|
+
this.historySize = Number.isFinite(history) ? Math.max(0, Math.floor(history)) : 3;
|
|
52
|
+
this.streakTimeout = Number.isFinite(streakTimeout) && streakTimeout >= 0 ? streakTimeout : 150;
|
|
53
|
+
this.minTickInterval = Number.isFinite(minTickInterval) && minTickInterval >= 0 ? minTickInterval : 6;
|
|
54
54
|
this.intervals = [];
|
|
55
55
|
this.lastTick = 0;
|
|
56
56
|
}
|
|
@@ -59,6 +59,8 @@ export class ScrollAcceleration {
|
|
|
59
59
|
this.lastTick = 0;
|
|
60
60
|
}
|
|
61
61
|
tick(now = Date.now()) {
|
|
62
|
+
if (!Number.isFinite(now))
|
|
63
|
+
return 1;
|
|
62
64
|
const A = 0.8;
|
|
63
65
|
const tau = 3;
|
|
64
66
|
const maxMultiplier = 6;
|
|
@@ -68,12 +70,16 @@ export class ScrollAcceleration {
|
|
|
68
70
|
this.intervals = [];
|
|
69
71
|
return 1;
|
|
70
72
|
}
|
|
71
|
-
if (gap < this.minTickInterval)
|
|
73
|
+
if (gap < Math.max(0, this.minTickInterval))
|
|
72
74
|
return 1;
|
|
73
75
|
this.lastTick = now;
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
this.intervals.
|
|
76
|
+
if (this.historySize > 0) {
|
|
77
|
+
this.intervals.push(gap);
|
|
78
|
+
while (this.intervals.length > this.historySize)
|
|
79
|
+
this.intervals.shift();
|
|
80
|
+
}
|
|
81
|
+
if (this.intervals.length === 0)
|
|
82
|
+
return 1;
|
|
77
83
|
const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
|
|
78
84
|
const velocity = 100 / average;
|
|
79
85
|
return Math.min(1 + A * (Math.exp(velocity / tau) - 1), maxMultiplier);
|
|
@@ -96,11 +102,12 @@ export class Viewport {
|
|
|
96
102
|
unseen;
|
|
97
103
|
lastWheelMoved;
|
|
98
104
|
lastWheelDirection;
|
|
99
|
-
constructor(
|
|
105
|
+
constructor(options = {}) {
|
|
106
|
+
const { transcript = null, height = 20, width = 80, speed = DEFAULT_SCROLL_SPEED, acceleration = null } = options || {};
|
|
100
107
|
this.transcript = transcript;
|
|
101
|
-
this.viewHeight = Math.max(1, Math.floor(height));
|
|
102
|
-
this.viewWidth = Math.max(1, Math.floor(width));
|
|
103
|
-
this.speed = speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
|
|
108
|
+
this.viewHeight = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 20;
|
|
109
|
+
this.viewWidth = Number.isFinite(width) ? Math.max(1, Math.floor(width)) : 80;
|
|
110
|
+
this.speed = Number.isFinite(speed) && speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
|
|
104
111
|
this.acceleration = acceleration || null;
|
|
105
112
|
this.scrollTop = 0;
|
|
106
113
|
this.manual = false;
|
|
@@ -115,19 +122,21 @@ export class Viewport {
|
|
|
115
122
|
/**
|
|
116
123
|
* Geometry changed — a resize, or the input box growing under the viewport.
|
|
117
124
|
*/
|
|
118
|
-
resize(
|
|
125
|
+
resize(options = {}) {
|
|
126
|
+
const { height, width } = options || {};
|
|
119
127
|
const nextHeight = height !== undefined && Number.isFinite(height) && height > 0
|
|
120
|
-
? Math.floor(height) : this.viewHeight;
|
|
128
|
+
? Math.max(1, Math.floor(height)) : this.viewHeight;
|
|
121
129
|
const nextWidth = width !== undefined && Number.isFinite(width) && width > 0
|
|
122
|
-
? Math.floor(width) : this.viewWidth;
|
|
130
|
+
? Math.max(1, Math.floor(width)) : this.viewWidth;
|
|
123
131
|
const reflow = nextWidth !== this.viewWidth;
|
|
124
132
|
const anchor = reflow && this.manual && this.transcript?.markers
|
|
125
133
|
? captureReadingAnchor(this.transcript.markers(this.viewWidth), this.scrollTop, this.transcript.height(this.viewWidth)) : null;
|
|
126
134
|
this.viewHeight = nextHeight;
|
|
127
135
|
this.viewWidth = nextWidth;
|
|
128
136
|
if (anchor && this.transcript?.markers) {
|
|
129
|
-
|
|
137
|
+
const restored = restoreReadingAnchor(anchor, this.transcript.markers(nextWidth), this.transcript.height(nextWidth), nextHeight);
|
|
130
138
|
const max = this.maxScrollTop();
|
|
139
|
+
this.scrollTop = Number.isFinite(restored) ? Math.max(0, Math.min(max, Math.floor(restored))) : max;
|
|
131
140
|
// A deliberate scroll must not suddenly become follow-mode just because
|
|
132
141
|
// a paragraph gained or lost wrapped rows during resize.
|
|
133
142
|
this.manual = max > 0 && this.scrollTop < max;
|
|
@@ -138,7 +147,8 @@ export class Viewport {
|
|
|
138
147
|
this.refresh();
|
|
139
148
|
}
|
|
140
149
|
contentHeight() {
|
|
141
|
-
|
|
150
|
+
const measured = this.transcript ? this.transcript.height(this.viewWidth) : 0;
|
|
151
|
+
return Number.isFinite(measured) ? Math.max(0, Math.floor(measured)) : 0;
|
|
142
152
|
}
|
|
143
153
|
maxScrollTop() {
|
|
144
154
|
return Math.max(0, this.contentHeight() - this.viewHeight);
|
|
@@ -173,31 +183,36 @@ export class Viewport {
|
|
|
173
183
|
* evicted. This is where auto-scroll actually happens.
|
|
174
184
|
*/
|
|
175
185
|
refresh(grownBy = 0) {
|
|
186
|
+
const safeGrownBy = Number.isFinite(grownBy) && grownBy > 0 ? grownBy : 0;
|
|
176
187
|
const wasApplying = this.applyingSticky;
|
|
177
188
|
this.applyingSticky = true;
|
|
178
189
|
try {
|
|
179
190
|
const max = this.maxScrollTop();
|
|
180
|
-
const tolerance =
|
|
181
|
-
if (!this.manual) {
|
|
191
|
+
const tolerance = safeGrownBy > 0 ? REENGAGE_TOLERANCE : 0;
|
|
192
|
+
if (!this.manual || max <= 0) {
|
|
193
|
+
this.manual = false;
|
|
182
194
|
this.scrollTop = max;
|
|
183
195
|
this.unseen = 0;
|
|
184
196
|
}
|
|
185
|
-
else if (
|
|
197
|
+
else if (this.scrollTop >= max - tolerance) {
|
|
186
198
|
this.manual = false;
|
|
187
199
|
this.scrollTop = max;
|
|
188
200
|
this.unseen = 0;
|
|
189
201
|
}
|
|
190
202
|
else {
|
|
191
203
|
this.scrollTop = Math.min(this.scrollTop, max);
|
|
192
|
-
if (
|
|
193
|
-
this.unseen +=
|
|
204
|
+
if (safeGrownBy > 0)
|
|
205
|
+
this.unseen += safeGrownBy;
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
finally {
|
|
197
209
|
this.applyingSticky = wasApplying;
|
|
198
210
|
}
|
|
199
211
|
}
|
|
200
|
-
scrollTo(position,
|
|
212
|
+
scrollTo(position, options = {}) {
|
|
213
|
+
const { snap = false } = options || {};
|
|
214
|
+
if (!Number.isFinite(position))
|
|
215
|
+
return this.scrollTop;
|
|
201
216
|
const max = this.maxScrollTop();
|
|
202
217
|
let next = Math.max(0, Math.min(Math.round(position), max));
|
|
203
218
|
if (snap && next > this.scrollTop && max - next <= REENGAGE_TOLERANCE)
|
|
@@ -217,6 +232,10 @@ export class Viewport {
|
|
|
217
232
|
* quietly round to 1 or 2 forever.
|
|
218
233
|
*/
|
|
219
234
|
wheel(direction, notches = 1, now = Date.now()) {
|
|
235
|
+
if (!Number.isFinite(notches) || !Number.isFinite(now)) {
|
|
236
|
+
this.lastWheelMoved = false;
|
|
237
|
+
return this.scrollTop;
|
|
238
|
+
}
|
|
220
239
|
const before = this.scrollTop;
|
|
221
240
|
if (this.lastWheelDirection && this.lastWheelDirection !== direction) {
|
|
222
241
|
this.accumulator = 0;
|
|
@@ -224,6 +243,10 @@ export class Viewport {
|
|
|
224
243
|
this.lastWheelDirection = direction;
|
|
225
244
|
const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
|
|
226
245
|
const amount = Math.abs(notches) * this.speed * multiplier;
|
|
246
|
+
if (!Number.isFinite(amount)) {
|
|
247
|
+
this.lastWheelMoved = false;
|
|
248
|
+
return this.scrollTop;
|
|
249
|
+
}
|
|
227
250
|
this.accumulator += direction === 'up' ? -amount : amount;
|
|
228
251
|
const whole = Math.trunc(this.accumulator);
|
|
229
252
|
if (whole !== 0) {
|
|
@@ -247,10 +270,12 @@ export class Viewport {
|
|
|
247
270
|
return this.scrollTop;
|
|
248
271
|
}
|
|
249
272
|
jump(direction, kinds = null) {
|
|
273
|
+
if (!Number.isFinite(direction) || direction === 0)
|
|
274
|
+
return this.scrollTop;
|
|
250
275
|
if (!this.transcript || typeof this.transcript.markers !== 'function')
|
|
251
276
|
return this.scrollTop;
|
|
252
277
|
const markers = this.transcript.markers(this.viewWidth)
|
|
253
|
-
.filter((m) => !kinds || kinds.includes(m.kind));
|
|
278
|
+
.filter((m) => Boolean(m && Number.isFinite(m.row) && (!kinds || kinds.includes(m.kind))));
|
|
254
279
|
if (markers.length === 0)
|
|
255
280
|
return this.scrollTop;
|
|
256
281
|
if (direction < 0) {
|