@causyne/agent 1.20.112 → 1.20.117
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 +153 -68
- package/src/agentLoop.ts +152 -71
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +37 -9
- package/src/browser/causyneBrowser.ts +37 -9
- 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/cliMode.js +5 -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/memory/scopedFacts.js +171 -0
- package/src/memory/scopedFacts.ts +214 -0
- package/src/memory.d.ts +13 -1
- package/src/memory.js +9 -12
- 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/perception.js +124 -3
- package/src/perception.ts +128 -4
- package/src/planCache.js +17 -3
- package/src/planCache.ts +17 -3
- 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/smartToolsUse.js +4 -5
- package/src/smartToolsUse.ts +4 -6
- package/src/taskShape.js +49 -7
- package/src/taskShape.ts +55 -7
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/toolPacks.js +27 -5
- package/src/toolPacks.ts +32 -5
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/memoryWrite.js +8 -10
- package/src/tools/memoryWrite.ts +13 -11
- 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 +139 -84
- 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 +60 -28
- package/src/tui/codeProgress.ts +60 -27
- package/src/tui/codeStreamRenderer.js +94 -23
- package/src/tui/codeStreamRenderer.ts +92 -23
- 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 +36 -18
- 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 +186 -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 +232 -51
- 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 +176 -80
- package/src/tui/turnRail.ts +173 -71
- package/src/tui/usageCard.js +136 -80
- package/src/tui/usageCard.ts +145 -103
- 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/types/contracts.ts +3 -0
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) {
|
package/src/tui/viewport.ts
CHANGED
|
@@ -57,9 +57,9 @@ export class ScrollAcceleration {
|
|
|
57
57
|
lastTick: number;
|
|
58
58
|
|
|
59
59
|
constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 }: ScrollAccelerationOptions = {}) {
|
|
60
|
-
this.historySize = history;
|
|
61
|
-
this.streakTimeout = streakTimeout;
|
|
62
|
-
this.minTickInterval = minTickInterval;
|
|
60
|
+
this.historySize = Number.isFinite(history) ? Math.max(0, Math.floor(history)) : 3;
|
|
61
|
+
this.streakTimeout = Number.isFinite(streakTimeout) && streakTimeout >= 0 ? streakTimeout : 150;
|
|
62
|
+
this.minTickInterval = Number.isFinite(minTickInterval) && minTickInterval >= 0 ? minTickInterval : 6;
|
|
63
63
|
this.intervals = [];
|
|
64
64
|
this.lastTick = 0;
|
|
65
65
|
}
|
|
@@ -70,6 +70,7 @@ export class ScrollAcceleration {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
tick(now: number = Date.now()): number {
|
|
73
|
+
if (!Number.isFinite(now)) return 1;
|
|
73
74
|
const A = 0.8;
|
|
74
75
|
const tau = 3;
|
|
75
76
|
const maxMultiplier = 6;
|
|
@@ -80,11 +81,14 @@ export class ScrollAcceleration {
|
|
|
80
81
|
this.intervals = [];
|
|
81
82
|
return 1;
|
|
82
83
|
}
|
|
83
|
-
if (gap < this.minTickInterval) return 1;
|
|
84
|
+
if (gap < Math.max(0, this.minTickInterval)) return 1;
|
|
84
85
|
|
|
85
86
|
this.lastTick = now;
|
|
86
|
-
this.
|
|
87
|
-
|
|
87
|
+
if (this.historySize > 0) {
|
|
88
|
+
this.intervals.push(gap);
|
|
89
|
+
while (this.intervals.length > this.historySize) this.intervals.shift();
|
|
90
|
+
}
|
|
91
|
+
if (this.intervals.length === 0) return 1;
|
|
88
92
|
|
|
89
93
|
const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
|
|
90
94
|
const velocity = 100 / average;
|
|
@@ -146,17 +150,18 @@ export class Viewport {
|
|
|
146
150
|
lastWheelMoved: boolean;
|
|
147
151
|
lastWheelDirection: 'up' | 'down' | null;
|
|
148
152
|
|
|
149
|
-
constructor({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
constructor(options: ViewportOptions | null = {}) {
|
|
154
|
+
const {
|
|
155
|
+
transcript = null,
|
|
156
|
+
height = 20,
|
|
157
|
+
width = 80,
|
|
158
|
+
speed = DEFAULT_SCROLL_SPEED,
|
|
159
|
+
acceleration = null
|
|
160
|
+
} = options || {};
|
|
156
161
|
this.transcript = transcript;
|
|
157
|
-
this.viewHeight = Math.max(1, Math.floor(height));
|
|
158
|
-
this.viewWidth = Math.max(1, Math.floor(width));
|
|
159
|
-
this.speed = speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
|
|
162
|
+
this.viewHeight = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 20;
|
|
163
|
+
this.viewWidth = Number.isFinite(width) ? Math.max(1, Math.floor(width)) : 80;
|
|
164
|
+
this.speed = Number.isFinite(speed) && speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
|
|
160
165
|
this.acceleration = acceleration || null;
|
|
161
166
|
|
|
162
167
|
this.scrollTop = 0;
|
|
@@ -174,11 +179,12 @@ export class Viewport {
|
|
|
174
179
|
/**
|
|
175
180
|
* Geometry changed — a resize, or the input box growing under the viewport.
|
|
176
181
|
*/
|
|
177
|
-
resize(
|
|
182
|
+
resize(options: { height?: number; width?: number } | null = {}): void {
|
|
183
|
+
const { height, width } = options || {};
|
|
178
184
|
const nextHeight = height !== undefined && Number.isFinite(height) && height > 0
|
|
179
|
-
? Math.floor(height) : this.viewHeight;
|
|
185
|
+
? Math.max(1, Math.floor(height)) : this.viewHeight;
|
|
180
186
|
const nextWidth = width !== undefined && Number.isFinite(width) && width > 0
|
|
181
|
-
? Math.floor(width) : this.viewWidth;
|
|
187
|
+
? Math.max(1, Math.floor(width)) : this.viewWidth;
|
|
182
188
|
const reflow = nextWidth !== this.viewWidth;
|
|
183
189
|
const anchor = reflow && this.manual && this.transcript?.markers
|
|
184
190
|
? captureReadingAnchor(this.transcript.markers(this.viewWidth), this.scrollTop,
|
|
@@ -187,9 +193,10 @@ export class Viewport {
|
|
|
187
193
|
this.viewHeight = nextHeight;
|
|
188
194
|
this.viewWidth = nextWidth;
|
|
189
195
|
if (anchor && this.transcript?.markers) {
|
|
190
|
-
|
|
196
|
+
const restored = restoreReadingAnchor(anchor, this.transcript.markers(nextWidth),
|
|
191
197
|
this.transcript.height(nextWidth), nextHeight);
|
|
192
198
|
const max = this.maxScrollTop();
|
|
199
|
+
this.scrollTop = Number.isFinite(restored) ? Math.max(0, Math.min(max, Math.floor(restored))) : max;
|
|
193
200
|
// A deliberate scroll must not suddenly become follow-mode just because
|
|
194
201
|
// a paragraph gained or lost wrapped rows during resize.
|
|
195
202
|
this.manual = max > 0 && this.scrollTop < max;
|
|
@@ -200,7 +207,8 @@ export class Viewport {
|
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
contentHeight(): number {
|
|
203
|
-
|
|
210
|
+
const measured = this.transcript ? this.transcript.height(this.viewWidth) : 0;
|
|
211
|
+
return Number.isFinite(measured) ? Math.max(0, Math.floor(measured)) : 0;
|
|
204
212
|
}
|
|
205
213
|
|
|
206
214
|
maxScrollTop(): number {
|
|
@@ -240,29 +248,33 @@ export class Viewport {
|
|
|
240
248
|
* evicted. This is where auto-scroll actually happens.
|
|
241
249
|
*/
|
|
242
250
|
refresh(grownBy: number = 0): void {
|
|
251
|
+
const safeGrownBy = Number.isFinite(grownBy) && grownBy > 0 ? grownBy : 0;
|
|
243
252
|
const wasApplying = this.applyingSticky;
|
|
244
253
|
this.applyingSticky = true;
|
|
245
254
|
try {
|
|
246
255
|
const max = this.maxScrollTop();
|
|
247
|
-
const tolerance =
|
|
256
|
+
const tolerance = safeGrownBy > 0 ? REENGAGE_TOLERANCE : 0;
|
|
248
257
|
|
|
249
|
-
if (!this.manual) {
|
|
258
|
+
if (!this.manual || max <= 0) {
|
|
259
|
+
this.manual = false;
|
|
250
260
|
this.scrollTop = max;
|
|
251
261
|
this.unseen = 0;
|
|
252
|
-
} else if (
|
|
262
|
+
} else if (this.scrollTop >= max - tolerance) {
|
|
253
263
|
this.manual = false;
|
|
254
264
|
this.scrollTop = max;
|
|
255
265
|
this.unseen = 0;
|
|
256
266
|
} else {
|
|
257
267
|
this.scrollTop = Math.min(this.scrollTop, max);
|
|
258
|
-
if (
|
|
268
|
+
if (safeGrownBy > 0) this.unseen += safeGrownBy;
|
|
259
269
|
}
|
|
260
270
|
} finally {
|
|
261
271
|
this.applyingSticky = wasApplying;
|
|
262
272
|
}
|
|
263
273
|
}
|
|
264
274
|
|
|
265
|
-
scrollTo(position: number,
|
|
275
|
+
scrollTo(position: number, options: { snap?: boolean } | null = {}): number {
|
|
276
|
+
const { snap = false } = options || {};
|
|
277
|
+
if (!Number.isFinite(position)) return this.scrollTop;
|
|
266
278
|
const max = this.maxScrollTop();
|
|
267
279
|
let next = Math.max(0, Math.min(Math.round(position), max));
|
|
268
280
|
|
|
@@ -284,6 +296,10 @@ export class Viewport {
|
|
|
284
296
|
* quietly round to 1 or 2 forever.
|
|
285
297
|
*/
|
|
286
298
|
wheel(direction: 'up' | 'down', notches: number = 1, now: number = Date.now()): number {
|
|
299
|
+
if (!Number.isFinite(notches) || !Number.isFinite(now)) {
|
|
300
|
+
this.lastWheelMoved = false;
|
|
301
|
+
return this.scrollTop;
|
|
302
|
+
}
|
|
287
303
|
const before = this.scrollTop;
|
|
288
304
|
if (this.lastWheelDirection && this.lastWheelDirection !== direction) {
|
|
289
305
|
this.accumulator = 0;
|
|
@@ -292,6 +308,10 @@ export class Viewport {
|
|
|
292
308
|
|
|
293
309
|
const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
|
|
294
310
|
const amount = Math.abs(notches) * this.speed * multiplier;
|
|
311
|
+
if (!Number.isFinite(amount)) {
|
|
312
|
+
this.lastWheelMoved = false;
|
|
313
|
+
return this.scrollTop;
|
|
314
|
+
}
|
|
295
315
|
this.accumulator += direction === 'up' ? -amount : amount;
|
|
296
316
|
const whole = Math.trunc(this.accumulator);
|
|
297
317
|
if (whole !== 0) {
|
|
@@ -318,9 +338,10 @@ export class Viewport {
|
|
|
318
338
|
}
|
|
319
339
|
|
|
320
340
|
jump(direction: number, kinds: string[] | null = null): number {
|
|
341
|
+
if (!Number.isFinite(direction) || direction === 0) return this.scrollTop;
|
|
321
342
|
if (!this.transcript || typeof this.transcript.markers !== 'function') return this.scrollTop;
|
|
322
343
|
const markers = this.transcript.markers(this.viewWidth)
|
|
323
|
-
.filter((m) => !kinds || kinds.includes(m.kind));
|
|
344
|
+
.filter((m) => Boolean(m && Number.isFinite(m.row) && (!kinds || kinds.includes(m.kind))));
|
|
324
345
|
if (markers.length === 0) return this.scrollTop;
|
|
325
346
|
|
|
326
347
|
if (direction < 0) {
|
|
@@ -59,8 +59,8 @@ export function restoreReadingAnchor(anchor, markers, totalHeight, viewportHeigh
|
|
|
59
59
|
let selected = anchor.id == null
|
|
60
60
|
? -1
|
|
61
61
|
: entries.findIndex(marker => marker.id === anchor.id);
|
|
62
|
-
if (selected < 0 && anchor.id == null
|
|
63
|
-
selected = anchor.index;
|
|
62
|
+
if (selected < 0 && anchor.id == null) {
|
|
63
|
+
selected = entries.findIndex(marker => marker.originalIndex === anchor.index);
|
|
64
64
|
}
|
|
65
65
|
if (selected < 0) {
|
|
66
66
|
// When the anchored frame was evicted, recover in the surviving transcript.
|
|
@@ -86,8 +86,8 @@ export function restoreReadingAnchor(
|
|
|
86
86
|
let selected = anchor.id == null
|
|
87
87
|
? -1
|
|
88
88
|
: entries.findIndex(marker => marker.id === anchor.id);
|
|
89
|
-
if (selected < 0 && anchor.id == null
|
|
90
|
-
selected = anchor.index;
|
|
89
|
+
if (selected < 0 && anchor.id == null) {
|
|
90
|
+
selected = entries.findIndex(marker => marker.originalIndex === anchor.index);
|
|
91
91
|
}
|
|
92
92
|
if (selected < 0) {
|
|
93
93
|
// When the anchored frame was evicted, recover in the surviving transcript.
|
|
@@ -38,11 +38,13 @@ export class WorkspaceFileIndex {
|
|
|
38
38
|
maxDepth;
|
|
39
39
|
refreshMs;
|
|
40
40
|
constructor(root, options = {}) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
41
|
+
const safeRoot = typeof root === 'string' && root.length > 0 ? root : '.';
|
|
42
|
+
const safeOptions = options && typeof options === 'object' ? options : {};
|
|
43
|
+
this.root = path.resolve(safeRoot);
|
|
44
|
+
this.maxEntries = finiteInt(safeOptions.maxEntries, DEFAULT_MAX_ENTRIES);
|
|
45
|
+
this.maxDirs = finiteInt(safeOptions.maxDirs, DEFAULT_MAX_DIRS);
|
|
46
|
+
this.maxDepth = finiteInt(safeOptions.maxDepth, DEFAULT_MAX_DEPTH);
|
|
47
|
+
this.refreshMs = finiteInt(safeOptions.refreshMs, DEFAULT_REFRESH_MS, 0);
|
|
46
48
|
}
|
|
47
49
|
get isReady() { return this.entries !== null; }
|
|
48
50
|
get isBuilding() { return this.building !== null; }
|
|
@@ -108,7 +110,7 @@ export class WorkspaceFileIndex {
|
|
|
108
110
|
}
|
|
109
111
|
/** Contiguous matches take priority; fuzzy matching remains the JS fallback. */
|
|
110
112
|
candidates(query) {
|
|
111
|
-
if (!query)
|
|
113
|
+
if (typeof query !== 'string' || !query)
|
|
112
114
|
return this.entries ?? [];
|
|
113
115
|
const needle = query.toLocaleLowerCase();
|
|
114
116
|
const direct = this.indexed.filter(entry => entry.folded.includes(needle));
|
|
@@ -55,11 +55,13 @@ export class WorkspaceFileIndex {
|
|
|
55
55
|
private readonly refreshMs: number;
|
|
56
56
|
|
|
57
57
|
constructor(root: string, options: WorkspaceFileIndexOptions = {}) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
58
|
+
const safeRoot = typeof root === 'string' && root.length > 0 ? root : '.';
|
|
59
|
+
const safeOptions = options && typeof options === 'object' ? options : {};
|
|
60
|
+
this.root = path.resolve(safeRoot);
|
|
61
|
+
this.maxEntries = finiteInt(safeOptions.maxEntries, DEFAULT_MAX_ENTRIES);
|
|
62
|
+
this.maxDirs = finiteInt(safeOptions.maxDirs, DEFAULT_MAX_DIRS);
|
|
63
|
+
this.maxDepth = finiteInt(safeOptions.maxDepth, DEFAULT_MAX_DEPTH);
|
|
64
|
+
this.refreshMs = finiteInt(safeOptions.refreshMs, DEFAULT_REFRESH_MS, 0);
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
get isReady(): boolean { return this.entries !== null; }
|
|
@@ -120,7 +122,7 @@ export class WorkspaceFileIndex {
|
|
|
120
122
|
|
|
121
123
|
/** Contiguous matches take priority; fuzzy matching remains the JS fallback. */
|
|
122
124
|
candidates(query: string): string[] {
|
|
123
|
-
if (!query) return this.entries ?? [];
|
|
125
|
+
if (typeof query !== 'string' || !query) return this.entries ?? [];
|
|
124
126
|
const needle = query.toLocaleLowerCase();
|
|
125
127
|
const direct = this.indexed.filter(entry => entry.folded.includes(needle));
|
|
126
128
|
return (direct.length > 0 ? direct.map(entry => entry.value) : this.entries ?? []);
|
|
@@ -26,7 +26,8 @@ export function switchChatWorkspace({ workspaceRoot, createLoop, prompt = null,
|
|
|
26
26
|
replacement.waitForApproval = approvalHandler;
|
|
27
27
|
replacement.waitForDecision = decisionHandler;
|
|
28
28
|
if (prompt) {
|
|
29
|
-
prompt.setWorkingRoot
|
|
29
|
+
if (typeof prompt.setWorkingRoot === 'function')
|
|
30
|
+
prompt.setWorkingRoot(workspaceRoot);
|
|
30
31
|
prompt.messageActionLoop = replacement;
|
|
31
32
|
// A workspace switch is also a change of task context. Do not transfer
|
|
32
33
|
// queued attachments or active skills from the previous workspace.
|
|
@@ -35,18 +36,20 @@ export function switchChatWorkspace({ workspaceRoot, createLoop, prompt = null,
|
|
|
35
36
|
if (typeof prompt.scheduleDraw === 'function')
|
|
36
37
|
prompt.scheduleDraw();
|
|
37
38
|
}
|
|
39
|
+
const workspaceLabel = replacement.sandbox?.grantAllAccess
|
|
40
|
+
? 'ALL ACCESS'
|
|
41
|
+
: (Array.isArray(replacement.sandbox?.workspacePaths) ? replacement.sandbox.workspacePaths.join(', ') : '');
|
|
38
42
|
if (headerInfo) {
|
|
39
43
|
headerInfo.cwd = workspaceRoot;
|
|
40
|
-
headerInfo.workspace =
|
|
41
|
-
|
|
42
|
-
: replacement.sandbox?.workspacePaths?.join(', ') ?? '';
|
|
43
|
-
if (renderer?.status?.setSession)
|
|
44
|
+
headerInfo.workspace = workspaceLabel;
|
|
45
|
+
if (typeof renderer?.status?.setSession === 'function')
|
|
44
46
|
renderer.status.setSession(headerInfo);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
}
|
|
48
|
+
if (typeof surface?.setSessionInfo === 'function') {
|
|
49
|
+
surface.setSessionInfo({
|
|
50
|
+
...(headerInfo || { cwd: workspaceRoot, workspace: workspaceLabel }),
|
|
51
|
+
activeSkill: null
|
|
52
|
+
});
|
|
50
53
|
}
|
|
51
54
|
return replacement;
|
|
52
55
|
}
|
|
@@ -54,7 +54,7 @@ export function switchChatWorkspace<TLoop extends {
|
|
|
54
54
|
replacement.waitForDecision = decisionHandler;
|
|
55
55
|
|
|
56
56
|
if (prompt) {
|
|
57
|
-
prompt.setWorkingRoot(workspaceRoot);
|
|
57
|
+
if (typeof prompt.setWorkingRoot === 'function') prompt.setWorkingRoot(workspaceRoot);
|
|
58
58
|
prompt.messageActionLoop = replacement;
|
|
59
59
|
// A workspace switch is also a change of task context. Do not transfer
|
|
60
60
|
// queued attachments or active skills from the previous workspace.
|
|
@@ -63,14 +63,18 @@ export function switchChatWorkspace<TLoop extends {
|
|
|
63
63
|
if (typeof prompt.scheduleDraw === 'function') prompt.scheduleDraw();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
const workspaceLabel = replacement.sandbox?.grantAllAccess
|
|
67
|
+
? 'ALL ACCESS'
|
|
68
|
+
: (Array.isArray(replacement.sandbox?.workspacePaths) ? replacement.sandbox.workspacePaths.join(', ') : '');
|
|
69
|
+
|
|
66
70
|
if (headerInfo) {
|
|
67
71
|
headerInfo.cwd = workspaceRoot;
|
|
68
|
-
headerInfo.workspace =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
...headerInfo,
|
|
72
|
+
headerInfo.workspace = workspaceLabel;
|
|
73
|
+
if (typeof renderer?.status?.setSession === 'function') renderer.status.setSession(headerInfo);
|
|
74
|
+
}
|
|
75
|
+
if (typeof surface?.setSessionInfo === 'function') {
|
|
76
|
+
surface.setSessionInfo({
|
|
77
|
+
...(headerInfo || { cwd: workspaceRoot, workspace: workspaceLabel }),
|
|
74
78
|
activeSkill: null
|
|
75
79
|
});
|
|
76
80
|
}
|
package/src/types/contracts.ts
CHANGED
|
@@ -298,6 +298,9 @@ export interface WorkspaceContext {
|
|
|
298
298
|
projectType?: string;
|
|
299
299
|
designSystem?: string;
|
|
300
300
|
keyFiles?: string[];
|
|
301
|
+
subprojectStacks?: string[];
|
|
302
|
+
docFiles?: string[];
|
|
303
|
+
buildFiles?: string[];
|
|
301
304
|
applicationRoot?: string;
|
|
302
305
|
workspaceRoot?: string;
|
|
303
306
|
allowedReadRoots?: string[];
|