@causyne/agent 1.20.0 → 1.20.7

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.
Files changed (130) hide show
  1. package/README.md +13 -9
  2. package/SECURITY.md +1 -4
  3. package/package.json +1 -1
  4. package/src/acp/client.js +176 -26
  5. package/src/acp/client.ts +167 -25
  6. package/src/acp/protocol.js +116 -0
  7. package/src/acp/protocol.ts +163 -0
  8. package/src/acp/server.js +5 -6
  9. package/src/acp/server.ts +4 -6
  10. package/src/agentLoop.d.ts +1 -0
  11. package/src/agentLoop.js +681 -245
  12. package/src/agentLoop.ts +708 -262
  13. package/src/agentPolicy.js +9 -0
  14. package/src/agentPolicy.ts +9 -0
  15. package/src/approvalPolicy.js +55 -0
  16. package/src/approvalPolicy.ts +66 -0
  17. package/src/browser/browserRuntime.js +217 -14
  18. package/src/browser/browserRuntime.ts +255 -14
  19. package/src/browser/causyneBrowser.js +1215 -68
  20. package/src/browser/causyneBrowser.ts +1340 -72
  21. package/src/cliMode.js +52 -29
  22. package/src/commands.js +141 -17
  23. package/src/config.js +22 -12
  24. package/src/continuum/ui/continuumPicker.js +18 -1
  25. package/src/continuum/ui/continuumPicker.ts +19 -1
  26. package/src/dynamicCatalogue.js +87 -20
  27. package/src/dynamicCatalogue.ts +85 -15
  28. package/src/launchIntent.js +40 -0
  29. package/src/launchIntent.ts +49 -0
  30. package/src/memoryManager.js +26 -2
  31. package/src/modelCatalogue.js +2 -0
  32. package/src/planCache.js +320 -11
  33. package/src/planCache.ts +402 -13
  34. package/src/providers/acp.js +173 -18
  35. package/src/providers/acp.ts +169 -19
  36. package/src/providers/antigravity.d.ts +5 -1
  37. package/src/providers/antigravity.js +674 -34
  38. package/src/providers/antigravity.ts +707 -35
  39. package/src/providers/base.d.ts +10 -0
  40. package/src/providers/factory.js +2 -0
  41. package/src/providers/pi.js +161 -0
  42. package/src/providers/pi.ts +148 -0
  43. package/src/provisioning/capabilityProvisioner.js +17 -0
  44. package/src/provisioning/capabilityTools.js +1 -1
  45. package/src/sandbox.js +30 -39
  46. package/src/sessionJournal.js +53 -10
  47. package/src/sessionJournal.ts +64 -10
  48. package/src/taskShape.js +9 -9
  49. package/src/taskShape.ts +9 -9
  50. package/src/timeMachine.js +124 -0
  51. package/src/timeMachine.ts +141 -0
  52. package/src/toolPacks.js +4 -10
  53. package/src/tools/archive.js +196 -59
  54. package/src/tools/archive.ts +220 -0
  55. package/src/tools/browserAutomator.js +78 -9
  56. package/src/tools/browserAutomator.ts +90 -9
  57. package/src/tools/desktopOpen.js +114 -31
  58. package/src/tools/desktopOpen.ts +144 -0
  59. package/src/tools/gitExec.js +5 -3
  60. package/src/tools/nativeEngine.js +4 -3
  61. package/src/tools/nativeEngine.ts +5 -3
  62. package/src/tools/openSourceToolProvisioner.js +5 -4
  63. package/src/tools/openSourceToolProvisioner.ts +5 -4
  64. package/src/tools/registry.js +3 -0
  65. package/src/tools/screenshot.js +55 -71
  66. package/src/tools/screenshot.ts +70 -0
  67. package/src/tools/sysRun.js +284 -117
  68. package/src/tools/sysRun.ts +347 -0
  69. package/src/tools/toolSelfRepair.js +109 -2
  70. package/src/tools/toolSelfRepair.ts +100 -2
  71. package/src/tools/updatePlan.js +49 -1
  72. package/src/tools/updatePlan.ts +43 -1
  73. package/src/tools/viewImage.js +93 -78
  74. package/src/tools/viewImage.ts +116 -0
  75. package/src/tools/webFetch.js +20 -6
  76. package/src/tools/webFetch.ts +26 -6
  77. package/src/tui/activityLayout.js +9 -0
  78. package/src/tui/activityLayout.ts +10 -0
  79. package/src/tui/block.d.ts +1 -0
  80. package/src/tui/chatRenderer.d.ts +23 -0
  81. package/src/tui/chatRenderer.js +49 -49
  82. package/src/tui/clipboardSync.js +28 -1
  83. package/src/tui/clipboardSync.ts +26 -1
  84. package/src/tui/codeProgress.js +299 -0
  85. package/src/tui/codeProgress.ts +304 -0
  86. package/src/tui/codeStreamRenderer.js +132 -0
  87. package/src/tui/codeStreamRenderer.ts +141 -0
  88. package/src/tui/commandPresentation.js +11 -0
  89. package/src/tui/commandPresentation.ts +18 -0
  90. package/src/tui/completion.js +45 -13
  91. package/src/tui/composerControls.js +131 -0
  92. package/src/tui/composerControls.ts +184 -0
  93. package/src/tui/diff.d.ts +2 -0
  94. package/src/tui/home.js +4 -2
  95. package/src/tui/homeTransition.js +21 -0
  96. package/src/tui/homeTransition.ts +27 -0
  97. package/src/tui/homeView.js +62 -0
  98. package/src/tui/homeView.ts +91 -0
  99. package/src/tui/layout.js +46 -0
  100. package/src/tui/layout.ts +52 -0
  101. package/src/tui/messageActionPlacement.js +16 -0
  102. package/src/tui/messageActionPlacement.ts +25 -0
  103. package/src/tui/messageInteraction.js +221 -0
  104. package/src/tui/messageInteraction.ts +275 -0
  105. package/src/tui/modelPicker.js +4 -24
  106. package/src/tui/modelPicker.ts +4 -20
  107. package/src/tui/mouseHover.js +6 -0
  108. package/src/tui/mouseHover.ts +5 -0
  109. package/src/tui/prompt.js +175 -101
  110. package/src/tui/resizeRecovery.js +15 -0
  111. package/src/tui/resizeRecovery.ts +27 -0
  112. package/src/tui/scrollInteraction.js +97 -0
  113. package/src/tui/scrollInteraction.ts +189 -0
  114. package/src/tui/sessionLayout.js +12 -0
  115. package/src/tui/sessionLayout.ts +12 -0
  116. package/src/tui/sessionPicker.js +111 -16
  117. package/src/tui/sessionPicker.ts +121 -16
  118. package/src/tui/sessionSidebar.js +78 -0
  119. package/src/tui/sessionSidebar.ts +95 -0
  120. package/src/tui/setup.js +1 -1
  121. package/src/tui/setup.ts +1 -1
  122. package/src/tui/stageSurface.js +120 -58
  123. package/src/tui/text.d.ts +6 -0
  124. package/src/tui/textLayout.js +23 -0
  125. package/src/tui/textLayout.ts +28 -0
  126. package/src/tui/viewport.js +204 -279
  127. package/src/tui/viewport.ts +326 -0
  128. package/src/types/contracts.ts +54 -0
  129. package/src/utils/paths.js +5 -4
  130. package/src/utils/paths.ts +5 -5
@@ -28,13 +28,8 @@
28
28
  // genuinely the right number. The fractional accumulator is what allows a
29
29
  // non-integer speed without drifting.
30
30
  //
31
- // Pure JS. No dependency, no shell.
32
-
33
- // Rows per wheel notch. opencode's default, and its acceleration is opt-in for
34
- // good reason: an accelerating wheel in a transcript overshoots the thing you
35
- // were trying to read.
31
+ // Pure TypeScript. No dependency, no shell.
36
32
  export const DEFAULT_SCROLL_SPEED = 3;
37
-
38
33
  /**
39
34
  * Opt-in wheel acceleration, the same shape opencode uses.
40
35
  *
@@ -47,291 +42,221 @@ export const DEFAULT_SCROLL_SPEED = 3;
47
42
  * the same few milliseconds, and counting both makes the curve run away.
48
43
  */
49
44
  export class ScrollAcceleration {
50
- constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 } = {}) {
51
- this.historySize = history;
52
- this.streakTimeout = streakTimeout;
53
- this.minTickInterval = minTickInterval;
54
- this.intervals = [];
55
- this.lastTick = 0;
56
- }
57
-
58
- reset() {
59
- this.intervals = [];
60
- this.lastTick = 0;
61
- }
62
-
63
- tick(now = Date.now()) {
64
- const A = 0.8;
65
- const tau = 3;
66
- const maxMultiplier = 6;
67
-
68
- const gap = this.lastTick ? now - this.lastTick : Infinity;
69
- if (gap === Infinity || gap > this.streakTimeout) {
70
- this.lastTick = now;
71
- this.intervals = [];
72
- return 1;
45
+ historySize;
46
+ streakTimeout;
47
+ minTickInterval;
48
+ intervals;
49
+ lastTick;
50
+ constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 } = {}) {
51
+ this.historySize = history;
52
+ this.streakTimeout = streakTimeout;
53
+ this.minTickInterval = minTickInterval;
54
+ this.intervals = [];
55
+ this.lastTick = 0;
56
+ }
57
+ reset() {
58
+ this.intervals = [];
59
+ this.lastTick = 0;
60
+ }
61
+ tick(now = Date.now()) {
62
+ const A = 0.8;
63
+ const tau = 3;
64
+ const maxMultiplier = 6;
65
+ const gap = this.lastTick ? now - this.lastTick : Infinity;
66
+ if (gap === Infinity || gap > this.streakTimeout) {
67
+ this.lastTick = now;
68
+ this.intervals = [];
69
+ return 1;
70
+ }
71
+ if (gap < this.minTickInterval)
72
+ return 1;
73
+ this.lastTick = now;
74
+ this.intervals.push(gap);
75
+ if (this.intervals.length > this.historySize)
76
+ this.intervals.shift();
77
+ const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
78
+ const velocity = 100 / average;
79
+ return Math.min(1 + A * (Math.exp(velocity / tau) - 1), maxMultiplier);
73
80
  }
74
- if (gap < this.minTickInterval) return 1;
75
-
76
- this.lastTick = now;
77
- this.intervals.push(gap);
78
- if (this.intervals.length > this.historySize) this.intervals.shift();
79
-
80
- const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
81
- const velocity = 100 / average;
82
- return Math.min(1 + A * (Math.exp(velocity / tau) - 1), maxMultiplier);
83
- }
84
81
  }
85
-
86
82
  // How close to the bottom counts as "back at the bottom" for the purposes of
87
83
  // resuming follow.
88
84
  const REENGAGE_TOLERANCE = 1;
89
-
90
85
  export class Viewport {
91
- constructor({ transcript, height = 20, width = 80, speed = DEFAULT_SCROLL_SPEED, acceleration = null } = {}) {
92
- this.transcript = transcript;
93
- this.viewHeight = Math.max(1, Math.floor(height));
94
- this.viewWidth = Math.max(1, Math.floor(width));
95
- this.speed = speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
96
- // null means a flat speed, which is the default and the right one.
97
- this.acceleration = acceleration || null;
98
-
99
- this.scrollTop = 0;
100
- // Derived, never assigned from an event. See the header.
101
- this.manual = false;
102
- this.applyingSticky = false;
103
- this.accumulator = 0;
104
- // Rows that arrived while the user was reading somewhere else.
105
- this.unseen = 0;
106
- }
107
-
108
- get height() { return this.viewHeight; }
109
- get width() { return this.viewWidth; }
110
-
111
- /**
112
- * Geometry changed — a resize, or the input box growing under the viewport.
113
- *
114
- * Resizing must not silently unfollow: growing the viewport reduces
115
- * maxScrollTop, which would leave scrollTop above it and read as "the user
116
- * scrolled away". refresh() re-derives from the new geometry instead.
117
- */
118
- resize({ height, width } = {}) {
119
- if (Number.isFinite(height) && height > 0) this.viewHeight = Math.floor(height);
120
- if (Number.isFinite(width) && width > 0) this.viewWidth = Math.floor(width);
121
- this.refresh();
122
- }
123
-
124
- contentHeight() {
125
- return this.transcript ? this.transcript.height(this.viewWidth) : 0;
126
- }
127
-
128
- maxScrollTop() {
129
- return Math.max(0, this.contentHeight() - this.viewHeight);
130
- }
131
-
132
- /**
133
- * Is there enough content for scrolling to mean anything?
134
- *
135
- * The `> 1` rather than `> 0` is deliberate and comes from the reference: one
136
- * row of overflow is not a scroll, and treating it as one makes the follow
137
- * flag flicker on every wrapped line during streaming.
138
- */
139
- scrollable() {
140
- return this.maxScrollTop() > 1;
141
- }
142
-
143
- atBottom() {
144
- return this.scrollTop >= this.maxScrollTop();
145
- }
146
-
147
- get following() {
148
- return !this.manual;
149
- }
150
-
151
- /**
152
- * Re-derive the follow flag from where we now are. Called after EVERY scroll
153
- * mutation, whoever caused it.
154
- */
155
- sync() {
156
- if (this.applyingSticky) {
157
- // A move we made ourselves. It is only allowed to CLEAR the flag — by
158
- // arriving back at the bottom — never to set it.
159
- if (this.manual && this.scrollable() && this.atBottom()) {
86
+ transcript;
87
+ viewHeight;
88
+ viewWidth;
89
+ speed;
90
+ acceleration;
91
+ scrollTop;
92
+ manual;
93
+ applyingSticky;
94
+ accumulator;
95
+ unseen;
96
+ lastWheelMoved;
97
+ constructor({ transcript = null, height = 20, width = 80, speed = DEFAULT_SCROLL_SPEED, acceleration = null } = {}) {
98
+ this.transcript = transcript;
99
+ this.viewHeight = Math.max(1, Math.floor(height));
100
+ this.viewWidth = Math.max(1, Math.floor(width));
101
+ this.speed = speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
102
+ this.acceleration = acceleration || null;
103
+ this.scrollTop = 0;
160
104
  this.manual = false;
105
+ this.applyingSticky = false;
106
+ this.accumulator = 0;
161
107
  this.unseen = 0;
162
- }
163
- return;
108
+ this.lastWheelMoved = false;
164
109
  }
165
- this.manual = this.scrollable() && !this.atBottom();
166
- if (!this.manual) this.unseen = 0;
167
- }
168
-
169
- /**
170
- * The content changed height — a token arrived, a tool printed, a frame was
171
- * evicted. This is where auto-scroll actually happens.
172
- */
173
- refresh(grownBy = 0) {
174
- const wasApplying = this.applyingSticky;
175
- this.applyingSticky = true;
176
- try {
177
- const max = this.maxScrollTop();
178
-
179
- // The tolerance applies to GROWTH only, and this is where Causyne departs
180
- // from the reference on purpose.
181
- //
182
- // opencode applies it on any size change (ScrollBox.ts:766-774), and
183
- // refresh() runs here on every frame because the viewport is re-measured
184
- // whenever the input box changes height. With a flat tolerance, scrolling
185
- // up exactly one row leaves scrollTop at max - 1, and the very next
186
- // keystroke re-engages and snaps it back — so a one-line scroll is a key
187
- // that visibly does nothing. "You came back to the bottom while content
188
- // was streaming" is a statement about growth; without growth, the bottom
189
- // means the bottom.
190
- const tolerance = grownBy > 0 ? REENGAGE_TOLERANCE : 0;
191
-
192
- if (!this.manual) {
193
- this.scrollTop = max;
194
- this.unseen = 0;
195
- } else if (max > 0 && this.scrollTop >= max - tolerance) {
196
- // The user came back to the bottom while content was streaming.
110
+ get height() { return this.viewHeight; }
111
+ get width() { return this.viewWidth; }
112
+ /**
113
+ * Geometry changed — a resize, or the input box growing under the viewport.
114
+ */
115
+ resize({ height, width } = {}) {
116
+ if (height !== undefined && Number.isFinite(height) && height > 0)
117
+ this.viewHeight = Math.floor(height);
118
+ if (width !== undefined && Number.isFinite(width) && width > 0)
119
+ this.viewWidth = Math.floor(width);
120
+ this.refresh();
121
+ }
122
+ contentHeight() {
123
+ return this.transcript ? this.transcript.height(this.viewWidth) : 0;
124
+ }
125
+ maxScrollTop() {
126
+ return Math.max(0, this.contentHeight() - this.viewHeight);
127
+ }
128
+ scrollable() {
129
+ return this.maxScrollTop() > 1;
130
+ }
131
+ atBottom() {
132
+ return this.scrollTop >= this.maxScrollTop();
133
+ }
134
+ get following() {
135
+ return !this.manual;
136
+ }
137
+ /**
138
+ * Re-derive the follow flag from where we now are. Called after EVERY scroll
139
+ * mutation, whoever caused it.
140
+ */
141
+ sync() {
142
+ if (this.applyingSticky) {
143
+ if (this.manual && this.scrollable() && this.atBottom()) {
144
+ this.manual = false;
145
+ this.unseen = 0;
146
+ }
147
+ return;
148
+ }
149
+ this.manual = this.scrollable() && !this.atBottom();
150
+ if (!this.manual)
151
+ this.unseen = 0;
152
+ }
153
+ /**
154
+ * The content changed height — a token arrived, a tool printed, a frame was
155
+ * evicted. This is where auto-scroll actually happens.
156
+ */
157
+ refresh(grownBy = 0) {
158
+ const wasApplying = this.applyingSticky;
159
+ this.applyingSticky = true;
160
+ try {
161
+ const max = this.maxScrollTop();
162
+ const tolerance = grownBy > 0 ? REENGAGE_TOLERANCE : 0;
163
+ if (!this.manual) {
164
+ this.scrollTop = max;
165
+ this.unseen = 0;
166
+ }
167
+ else if (max > 0 && this.scrollTop >= max - tolerance) {
168
+ this.manual = false;
169
+ this.scrollTop = max;
170
+ this.unseen = 0;
171
+ }
172
+ else {
173
+ this.scrollTop = Math.min(this.scrollTop, max);
174
+ if (grownBy > 0)
175
+ this.unseen += grownBy;
176
+ }
177
+ }
178
+ finally {
179
+ this.applyingSticky = wasApplying;
180
+ }
181
+ }
182
+ scrollTo(position, { snap = false } = {}) {
183
+ const max = this.maxScrollTop();
184
+ let next = Math.max(0, Math.min(Math.round(position), max));
185
+ if (snap && next > this.scrollTop && max - next <= REENGAGE_TOLERANCE)
186
+ next = max;
187
+ if (next !== this.scrollTop)
188
+ this.scrollTop = next;
189
+ this.sync();
190
+ return this.scrollTop;
191
+ }
192
+ scrollBy(delta) {
193
+ return this.scrollTo(this.scrollTop + delta, { snap: delta > 0 });
194
+ }
195
+ /**
196
+ * One wheel notch. `direction` is 'up' or 'down'.
197
+ *
198
+ * The accumulator carries the fraction so a speed of, say, 1.5 does not
199
+ * quietly round to 1 or 2 forever.
200
+ */
201
+ wheel(direction, notches = 1, now = Date.now()) {
202
+ const before = this.scrollTop;
203
+ const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
204
+ const amount = Math.abs(notches) * this.speed * multiplier;
205
+ this.accumulator += direction === 'up' ? -amount : amount;
206
+ const whole = Math.trunc(this.accumulator);
207
+ if (whole !== 0) {
208
+ this.accumulator -= whole;
209
+ this.scrollBy(whole);
210
+ }
211
+ this.lastWheelMoved = this.scrollTop !== before;
212
+ return this.scrollTop;
213
+ }
214
+ pageUp() { return this.scrollBy(-Math.max(1, this.viewHeight - 1)); }
215
+ pageDown() { return this.scrollBy(Math.max(1, this.viewHeight - 1)); }
216
+ halfPageUp() { return this.scrollBy(-Math.max(1, Math.floor(this.viewHeight / 2))); }
217
+ halfPageDown() { return this.scrollBy(Math.max(1, Math.floor(this.viewHeight / 2))); }
218
+ lineUp(n = 1) { return this.scrollBy(-n); }
219
+ lineDown(n = 1) { return this.scrollBy(n); }
220
+ toTop() { return this.scrollTo(0); }
221
+ toBottom() {
197
222
  this.manual = false;
198
- this.scrollTop = max;
199
223
  this.unseen = 0;
200
- } else {
201
- // Reading somewhere else: hold position, but never let a shrinking
202
- // transcript strand the view past the end of it.
203
- this.scrollTop = Math.min(this.scrollTop, max);
204
- if (grownBy > 0) this.unseen += grownBy;
205
- }
206
- } finally {
207
- this.applyingSticky = wasApplying;
224
+ this.refresh();
225
+ return this.scrollTop;
226
+ }
227
+ jump(direction, kinds = null) {
228
+ if (!this.transcript || typeof this.transcript.markers !== 'function')
229
+ return this.scrollTop;
230
+ const markers = this.transcript.markers(this.viewWidth)
231
+ .filter((m) => !kinds || kinds.includes(m.kind));
232
+ if (markers.length === 0)
233
+ return this.scrollTop;
234
+ if (direction < 0) {
235
+ const previous = markers.filter((m) => m.row < this.scrollTop).pop();
236
+ return this.scrollTo(previous ? previous.row : 0);
237
+ }
238
+ const next = markers.find((m) => m.row > this.scrollTop);
239
+ return next ? this.scrollTo(next.row) : this.toBottom();
208
240
  }
209
- }
210
-
211
- scrollTo(position, { snap = false } = {}) {
212
- const max = this.maxScrollTop();
213
- let next = Math.max(0, Math.min(Math.round(position), max));
214
-
215
- // THE TOLERANCE BELONGS TO DOWNWARD MOTION, not to the repaint.
216
- //
217
- // The reference puts it in the growth handler (ScrollBox.ts:497-512), where
218
- // it covers the case that actually annoys people: a wheel of three rows per
219
- // notch lands you one row short of the bottom, and follow never resumes.
220
- // But that handler runs on every repaint here, so a flat tolerance also
221
- // undoes a deliberate one-row scroll UP — a key that visibly does nothing.
222
- //
223
- // The two are mechanically identical and differ only in intent, and the
224
- // direction of travel is the one piece of intent that IS available. So the
225
- // snap is applied to downward motion only: scrolling down to within a row
226
- // of the end means the end; scrolling up by one row means one row.
227
- if (snap && next > this.scrollTop && max - next <= REENGAGE_TOLERANCE) next = max;
228
-
229
- if (next !== this.scrollTop) this.scrollTop = next;
230
- this.sync();
231
- return this.scrollTop;
232
- }
233
-
234
- scrollBy(delta) {
235
- return this.scrollTo(this.scrollTop + delta, { snap: delta > 0 });
236
- }
237
-
238
- /**
239
- * One wheel notch. `direction` is 'up' or 'down'.
240
- *
241
- * The accumulator carries the fraction so a speed of, say, 1.5 does not
242
- * quietly round to 1 or 2 forever.
243
- */
244
- wheel(direction, notches = 1, now = Date.now()) {
245
- const before = this.scrollTop;
246
- const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
247
- const amount = Math.abs(notches) * this.speed * multiplier;
248
- this.accumulator += direction === 'up' ? -amount : amount;
249
- const whole = Math.trunc(this.accumulator);
250
- if (whole !== 0) {
251
- this.accumulator -= whole;
252
- this.scrollBy(whole);
241
+ rows() {
242
+ const window = this.transcript && typeof this.transcript.slice === 'function'
243
+ ? this.transcript.slice(this.viewWidth, this.scrollTop, this.viewHeight)
244
+ : [];
245
+ const out = window.slice(0, this.viewHeight);
246
+ while (out.length < this.viewHeight)
247
+ out.push('');
248
+ return out;
253
249
  }
254
- // `moved` is what lets the caller tell "scrolled" from "already at the
255
- // end". Without it the wheel was swallowed unconditionally, so reaching the
256
- // top of the band meant the terminal's own scrollback — which holds the
257
- // rest of the conversation — could not be reached by wheel at all.
258
- this.lastWheelMoved = this.scrollTop !== before;
259
- return this.scrollTop;
260
- }
261
-
262
- // A page keeps one row of overlap, which is what every pager does and what
263
- // lets the eye carry across the jump. (opencode calls height/2 a "page" and
264
- // height/4 a "half page"; both are half of what their names claim, and there
265
- // is no reason to inherit that.)
266
- pageUp() { return this.scrollBy(-Math.max(1, this.viewHeight - 1)); }
267
- pageDown() { return this.scrollBy(Math.max(1, this.viewHeight - 1)); }
268
- halfPageUp() { return this.scrollBy(-Math.max(1, Math.floor(this.viewHeight / 2))); }
269
- halfPageDown() { return this.scrollBy(Math.max(1, Math.floor(this.viewHeight / 2))); }
270
- lineUp(n = 1) { return this.scrollBy(-n); }
271
- lineDown(n = 1) { return this.scrollBy(n); }
272
- toTop() { return this.scrollTo(0); }
273
-
274
- /**
275
- * Jump to the bottom and resume following.
276
- *
277
- * scrollTo() alone would land at the bottom and sync() would clear the flag,
278
- * but only if the content is scrollable; going through the sticky path makes
279
- * "follow again" unconditional, which is what the user means by pressing it.
280
- */
281
- toBottom() {
282
- this.manual = false;
283
- this.unseen = 0;
284
- this.refresh();
285
- return this.scrollTop;
286
- }
287
-
288
- /**
289
- * Frame boundaries, for step-to-step and turn-to-turn jumps.
290
- */
291
- jump(direction, kinds = null) {
292
- if (!this.transcript) return this.scrollTop;
293
- const markers = this.transcript.markers(this.viewWidth)
294
- .filter((m) => !kinds || kinds.includes(m.kind));
295
- if (markers.length === 0) return this.scrollTop;
296
-
297
- if (direction < 0) {
298
- const previous = markers.filter((m) => m.row < this.scrollTop).pop();
299
- return this.scrollTo(previous ? previous.row : 0);
250
+ state() {
251
+ const max = this.maxScrollTop();
252
+ return {
253
+ scrollTop: this.scrollTop,
254
+ max,
255
+ height: this.viewHeight,
256
+ contentHeight: this.contentHeight(),
257
+ following: this.following,
258
+ unseen: this.unseen,
259
+ progress: max > 0 ? this.scrollTop / max : null
260
+ };
300
261
  }
301
- const next = markers.find((m) => m.row > this.scrollTop);
302
- return next ? this.scrollTo(next.row) : this.toBottom();
303
- }
304
-
305
- /**
306
- * The rows on screen, top-aligned and padded to the full height.
307
- *
308
- * Top-aligned because that is what the reference does: content starts at the
309
- * top of the box and the gap sits above the prompt, not below the first
310
- * message.
311
- */
312
- rows() {
313
- const window = this.transcript
314
- ? this.transcript.slice(this.viewWidth, this.scrollTop, this.viewHeight)
315
- : [];
316
- const out = window.slice(0, this.viewHeight);
317
- while (out.length < this.viewHeight) out.push('');
318
- return out;
319
- }
320
-
321
- /**
322
- * Where we are, for the rail and the "N new below" affordance.
323
- */
324
- state() {
325
- const max = this.maxScrollTop();
326
- return {
327
- scrollTop: this.scrollTop,
328
- max,
329
- height: this.viewHeight,
330
- contentHeight: this.contentHeight(),
331
- following: this.following,
332
- unseen: this.unseen,
333
- // 0..1, or null when there is nothing to scroll.
334
- progress: max > 0 ? this.scrollTop / max : null
335
- };
336
- }
337
262
  }