@causyne/agent 1.19.0 → 1.20.5

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 (128) hide show
  1. package/README.md +0 -18
  2. package/package.json +1 -1
  3. package/src/acp/client.js +2 -1
  4. package/src/acp/client.ts +2 -1
  5. package/src/acp/server.js +5 -6
  6. package/src/acp/server.ts +4 -6
  7. package/src/agentLoop.d.ts +1 -0
  8. package/src/agentLoop.js +505 -241
  9. package/src/agentLoop.ts +527 -258
  10. package/src/agentPolicy.js +9 -0
  11. package/src/agentPolicy.ts +9 -0
  12. package/src/approvalPolicy.js +55 -0
  13. package/src/approvalPolicy.ts +66 -0
  14. package/src/browser/browserRuntime.js +217 -14
  15. package/src/browser/browserRuntime.ts +255 -14
  16. package/src/browser/causyneBrowser.js +1215 -68
  17. package/src/browser/causyneBrowser.ts +1340 -72
  18. package/src/cliMode.js +66 -37
  19. package/src/commands.js +343 -72
  20. package/src/config.js +22 -12
  21. package/src/continuum/ingest.js +1 -1
  22. package/src/continuum/ingest.ts +1 -1
  23. package/src/continuum/ui/continuumPicker.js +18 -1
  24. package/src/continuum/ui/continuumPicker.ts +19 -1
  25. package/src/dynamicCatalogue.js +87 -20
  26. package/src/dynamicCatalogue.ts +85 -15
  27. package/src/launchIntent.js +40 -0
  28. package/src/launchIntent.ts +49 -0
  29. package/src/memoryManager.js +36 -8
  30. package/src/modelCatalogue.js +2 -0
  31. package/src/planCache.js +320 -11
  32. package/src/planCache.ts +402 -13
  33. package/src/providers/acp.js +67 -1
  34. package/src/providers/acp.ts +65 -2
  35. package/src/providers/antigravity.d.ts +5 -1
  36. package/src/providers/antigravity.js +643 -32
  37. package/src/providers/antigravity.ts +671 -33
  38. package/src/providers/base.d.ts +9 -0
  39. package/src/providers/factory.js +2 -0
  40. package/src/providers/pi.js +157 -0
  41. package/src/providers/pi.ts +144 -0
  42. package/src/provisioning/capabilityProvisioner.js +17 -0
  43. package/src/provisioning/capabilityTools.js +1 -1
  44. package/src/sandbox.js +30 -39
  45. package/src/sessionJournal.js +66 -10
  46. package/src/sessionJournal.ts +84 -10
  47. package/src/taskShape.js +9 -9
  48. package/src/taskShape.ts +9 -9
  49. package/src/timeMachine.js +124 -0
  50. package/src/timeMachine.ts +141 -0
  51. package/src/toolPacks.js +4 -10
  52. package/src/tools/archive.js +196 -59
  53. package/src/tools/archive.ts +220 -0
  54. package/src/tools/browserAutomator.js +78 -9
  55. package/src/tools/browserAutomator.ts +90 -9
  56. package/src/tools/desktopOpen.js +114 -31
  57. package/src/tools/desktopOpen.ts +144 -0
  58. package/src/tools/gitExec.js +5 -3
  59. package/src/tools/nativeEngine.js +4 -3
  60. package/src/tools/nativeEngine.ts +5 -3
  61. package/src/tools/openSourceToolProvisioner.js +5 -4
  62. package/src/tools/openSourceToolProvisioner.ts +5 -4
  63. package/src/tools/registry.js +3 -0
  64. package/src/tools/screenshot.js +55 -71
  65. package/src/tools/screenshot.ts +70 -0
  66. package/src/tools/sysRun.js +284 -117
  67. package/src/tools/sysRun.ts +347 -0
  68. package/src/tools/toolSelfRepair.js +109 -2
  69. package/src/tools/toolSelfRepair.ts +100 -2
  70. package/src/tools/updatePlan.js +49 -1
  71. package/src/tools/updatePlan.ts +43 -1
  72. package/src/tools/viewImage.js +93 -78
  73. package/src/tools/viewImage.ts +116 -0
  74. package/src/tools/webFetch.js +20 -6
  75. package/src/tools/webFetch.ts +26 -6
  76. package/src/tui/block.d.ts +1 -0
  77. package/src/tui/chatRenderer.d.ts +21 -0
  78. package/src/tui/chatRenderer.js +118 -45
  79. package/src/tui/clipboardSync.js +28 -1
  80. package/src/tui/clipboardSync.ts +26 -1
  81. package/src/tui/codeProgress.js +299 -0
  82. package/src/tui/codeProgress.ts +304 -0
  83. package/src/tui/codeStreamRenderer.js +116 -0
  84. package/src/tui/codeStreamRenderer.ts +124 -0
  85. package/src/tui/commandPresentation.js +11 -0
  86. package/src/tui/commandPresentation.ts +18 -0
  87. package/src/tui/completion.js +45 -13
  88. package/src/tui/composerControls.js +66 -0
  89. package/src/tui/composerControls.ts +78 -0
  90. package/src/tui/diff.d.ts +2 -0
  91. package/src/tui/home.js +4 -2
  92. package/src/tui/homeTransition.js +21 -0
  93. package/src/tui/homeTransition.ts +27 -0
  94. package/src/tui/homeView.js +62 -0
  95. package/src/tui/homeView.ts +91 -0
  96. package/src/tui/layout.js +46 -0
  97. package/src/tui/layout.ts +52 -0
  98. package/src/tui/messageActionPlacement.js +16 -0
  99. package/src/tui/messageActionPlacement.ts +25 -0
  100. package/src/tui/messageInteraction.js +221 -0
  101. package/src/tui/messageInteraction.ts +275 -0
  102. package/src/tui/modelPicker.js +13 -0
  103. package/src/tui/modelPicker.ts +12 -0
  104. package/src/tui/mouseHover.js +6 -0
  105. package/src/tui/mouseHover.ts +5 -0
  106. package/src/tui/prompt.js +199 -52
  107. package/src/tui/resizeRecovery.js +15 -0
  108. package/src/tui/resizeRecovery.ts +27 -0
  109. package/src/tui/scrollInteraction.js +97 -0
  110. package/src/tui/scrollInteraction.ts +189 -0
  111. package/src/tui/sessionLayout.js +12 -0
  112. package/src/tui/sessionLayout.ts +12 -0
  113. package/src/tui/sessionPicker.js +280 -0
  114. package/src/tui/sessionPicker.ts +364 -0
  115. package/src/tui/sessionSidebar.js +78 -0
  116. package/src/tui/sessionSidebar.ts +95 -0
  117. package/src/tui/setup.js +1 -1
  118. package/src/tui/setup.ts +1 -1
  119. package/src/tui/stageSurface.js +128 -57
  120. package/src/tui/statusLine.js +5 -5
  121. package/src/tui/text.d.ts +5 -0
  122. package/src/tui/textLayout.js +23 -0
  123. package/src/tui/textLayout.ts +28 -0
  124. package/src/tui/viewport.js +204 -279
  125. package/src/tui/viewport.ts +326 -0
  126. package/src/types/contracts.ts +54 -0
  127. package/src/utils/paths.js +5 -4
  128. package/src/utils/paths.ts +5 -5
@@ -0,0 +1,326 @@
1
+ // The scroll/follow state machine over a Transcript.
2
+ //
3
+ // This behavior is specified by the viewport contract: the wheel and the keyboard move
4
+ // the box, the terminal does not scroll, and while a task runs the view
5
+ // auto-scrolls — until you scroll up, at which point it stops and lets the
6
+ // content grow underneath you.
7
+ //
8
+ // THE ONE ALGORITHM WORTH PORTING VERBATIM, and the reason to port it rather
9
+ // than write the obvious version:
10
+ //
11
+ // The obvious version sets a "user scrolled away" flag when the user presses a
12
+ // key or turns the wheel. That is wrong in both directions — a programmatic
13
+ // scroll looks like user intent, and returning to the bottom by wheel does not
14
+ // clear it. @opentui/core's ScrollBox (ScrollBox.ts:224-242) instead DERIVES the
15
+ // flag from position on every scroll mutation:
16
+ //
17
+ // hasManualScroll = hasScrollableContent && !isAtStickyPosition()
18
+ //
19
+ // with a reentrancy guard around the auto-follow's own writes, so the follow
20
+ // logic cannot mistake itself for the user. Any scroll that leaves the bottom
21
+ // edge sets it; any scroll that lands on the bottom edge clears it; nobody has
22
+ // to enumerate the ways a scroll can happen. Re-engagement has a one-row
23
+ // tolerance (ScrollBox.ts:497-512), which is what makes "scroll back down and
24
+ // it starts following again" feel forgiving instead of pixel-precise.
25
+ //
26
+ // Wheel deltas: the wire always reports 1 (lib/parse.mouse.ts:166-171), so all
27
+ // speed lives here. Three rows per notch is opencode's default and it is
28
+ // genuinely the right number. The fractional accumulator is what allows a
29
+ // non-integer speed without drifting.
30
+ //
31
+ // Pure TypeScript. No dependency, no shell.
32
+
33
+ export const DEFAULT_SCROLL_SPEED = 3;
34
+
35
+ export interface ScrollAccelerationOptions {
36
+ history?: number;
37
+ streakTimeout?: number;
38
+ minTickInterval?: number;
39
+ }
40
+
41
+ /**
42
+ * Opt-in wheel acceleration, the same shape opencode uses.
43
+ *
44
+ * (`@opentui/core` `lib/scroll-acceleration.ts:34-97`.) A streak of notches
45
+ * arriving close together multiplies the distance; a gap resets it. It stays
46
+ * OPT-IN because an accelerating wheel in a transcript overshoots the thing you
47
+ * were trying to read, which is worse than a wheel that is merely slow.
48
+ *
49
+ * `minTickInterval` is not a nicety: some terminals emit a wheel notch twice in
50
+ * the same few milliseconds, and counting both makes the curve run away.
51
+ */
52
+ export class ScrollAcceleration {
53
+ readonly historySize: number;
54
+ readonly streakTimeout: number;
55
+ readonly minTickInterval: number;
56
+ intervals: number[];
57
+ lastTick: number;
58
+
59
+ constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 }: ScrollAccelerationOptions = {}) {
60
+ this.historySize = history;
61
+ this.streakTimeout = streakTimeout;
62
+ this.minTickInterval = minTickInterval;
63
+ this.intervals = [];
64
+ this.lastTick = 0;
65
+ }
66
+
67
+ reset(): void {
68
+ this.intervals = [];
69
+ this.lastTick = 0;
70
+ }
71
+
72
+ tick(now: number = Date.now()): number {
73
+ const A = 0.8;
74
+ const tau = 3;
75
+ const maxMultiplier = 6;
76
+
77
+ const gap = this.lastTick ? now - this.lastTick : Infinity;
78
+ if (gap === Infinity || gap > this.streakTimeout) {
79
+ this.lastTick = now;
80
+ this.intervals = [];
81
+ return 1;
82
+ }
83
+ if (gap < this.minTickInterval) return 1;
84
+
85
+ this.lastTick = now;
86
+ this.intervals.push(gap);
87
+ if (this.intervals.length > this.historySize) this.intervals.shift();
88
+
89
+ const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
90
+ const velocity = 100 / average;
91
+ return Math.min(1 + A * (Math.exp(velocity / tau) - 1), maxMultiplier);
92
+ }
93
+ }
94
+
95
+ // How close to the bottom counts as "back at the bottom" for the purposes of
96
+ // resuming follow.
97
+ const REENGAGE_TOLERANCE = 1;
98
+
99
+ export interface TranscriptMarker {
100
+ row: number;
101
+ kind: string;
102
+ }
103
+
104
+ export interface ViewportTranscript {
105
+ height(width: number): number;
106
+ markers?(width: number): TranscriptMarker[];
107
+ slice?(width: number, from: number, count: number): string[];
108
+ clear?(): void;
109
+ append?(item: unknown): number | null;
110
+ isEmpty?(): boolean;
111
+ }
112
+
113
+ export interface ViewportOptions {
114
+ transcript?: ViewportTranscript | null;
115
+ height?: number;
116
+ width?: number;
117
+ speed?: number;
118
+ acceleration?: ScrollAcceleration | null;
119
+ }
120
+
121
+ export interface ViewportState {
122
+ scrollTop: number;
123
+ max: number;
124
+ height: number;
125
+ contentHeight: number;
126
+ following: boolean;
127
+ unseen: number;
128
+ progress: number | null;
129
+ }
130
+
131
+ export class Viewport {
132
+ transcript: ViewportTranscript | null;
133
+ viewHeight: number;
134
+ viewWidth: number;
135
+ speed: number;
136
+ acceleration: ScrollAcceleration | null;
137
+
138
+ scrollTop: number;
139
+ manual: boolean;
140
+ applyingSticky: boolean;
141
+ accumulator: number;
142
+ unseen: number;
143
+ lastWheelMoved: boolean;
144
+
145
+ constructor({
146
+ transcript = null,
147
+ height = 20,
148
+ width = 80,
149
+ speed = DEFAULT_SCROLL_SPEED,
150
+ acceleration = null
151
+ }: ViewportOptions = {}) {
152
+ this.transcript = transcript;
153
+ this.viewHeight = Math.max(1, Math.floor(height));
154
+ this.viewWidth = Math.max(1, Math.floor(width));
155
+ this.speed = speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
156
+ this.acceleration = acceleration || null;
157
+
158
+ this.scrollTop = 0;
159
+ this.manual = false;
160
+ this.applyingSticky = false;
161
+ this.accumulator = 0;
162
+ this.unseen = 0;
163
+ this.lastWheelMoved = false;
164
+ }
165
+
166
+ get height(): number { return this.viewHeight; }
167
+ get width(): number { return this.viewWidth; }
168
+
169
+ /**
170
+ * Geometry changed — a resize, or the input box growing under the viewport.
171
+ */
172
+ resize({ height, width }: { height?: number; width?: number } = {}): void {
173
+ if (height !== undefined && Number.isFinite(height) && height > 0) this.viewHeight = Math.floor(height);
174
+ if (width !== undefined && Number.isFinite(width) && width > 0) this.viewWidth = Math.floor(width);
175
+ this.refresh();
176
+ }
177
+
178
+ contentHeight(): number {
179
+ return this.transcript ? this.transcript.height(this.viewWidth) : 0;
180
+ }
181
+
182
+ maxScrollTop(): number {
183
+ return Math.max(0, this.contentHeight() - this.viewHeight);
184
+ }
185
+
186
+ scrollable(): boolean {
187
+ return this.maxScrollTop() > 1;
188
+ }
189
+
190
+ atBottom(): boolean {
191
+ return this.scrollTop >= this.maxScrollTop();
192
+ }
193
+
194
+ get following(): boolean {
195
+ return !this.manual;
196
+ }
197
+
198
+ /**
199
+ * Re-derive the follow flag from where we now are. Called after EVERY scroll
200
+ * mutation, whoever caused it.
201
+ */
202
+ sync(): void {
203
+ if (this.applyingSticky) {
204
+ if (this.manual && this.scrollable() && this.atBottom()) {
205
+ this.manual = false;
206
+ this.unseen = 0;
207
+ }
208
+ return;
209
+ }
210
+ this.manual = this.scrollable() && !this.atBottom();
211
+ if (!this.manual) this.unseen = 0;
212
+ }
213
+
214
+ /**
215
+ * The content changed height — a token arrived, a tool printed, a frame was
216
+ * evicted. This is where auto-scroll actually happens.
217
+ */
218
+ refresh(grownBy: number = 0): void {
219
+ const wasApplying = this.applyingSticky;
220
+ this.applyingSticky = true;
221
+ try {
222
+ const max = this.maxScrollTop();
223
+ const tolerance = grownBy > 0 ? REENGAGE_TOLERANCE : 0;
224
+
225
+ if (!this.manual) {
226
+ this.scrollTop = max;
227
+ this.unseen = 0;
228
+ } else if (max > 0 && this.scrollTop >= max - tolerance) {
229
+ this.manual = false;
230
+ this.scrollTop = max;
231
+ this.unseen = 0;
232
+ } else {
233
+ this.scrollTop = Math.min(this.scrollTop, max);
234
+ if (grownBy > 0) this.unseen += grownBy;
235
+ }
236
+ } finally {
237
+ this.applyingSticky = wasApplying;
238
+ }
239
+ }
240
+
241
+ scrollTo(position: number, { snap = false }: { snap?: boolean } = {}): number {
242
+ const max = this.maxScrollTop();
243
+ let next = Math.max(0, Math.min(Math.round(position), max));
244
+
245
+ if (snap && next > this.scrollTop && max - next <= REENGAGE_TOLERANCE) next = max;
246
+
247
+ if (next !== this.scrollTop) this.scrollTop = next;
248
+ this.sync();
249
+ return this.scrollTop;
250
+ }
251
+
252
+ scrollBy(delta: number): number {
253
+ return this.scrollTo(this.scrollTop + delta, { snap: delta > 0 });
254
+ }
255
+
256
+ /**
257
+ * One wheel notch. `direction` is 'up' or 'down'.
258
+ *
259
+ * The accumulator carries the fraction so a speed of, say, 1.5 does not
260
+ * quietly round to 1 or 2 forever.
261
+ */
262
+ wheel(direction: 'up' | 'down', notches: number = 1, now: number = Date.now()): number {
263
+ const before = this.scrollTop;
264
+ const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
265
+ const amount = Math.abs(notches) * this.speed * multiplier;
266
+ this.accumulator += direction === 'up' ? -amount : amount;
267
+ const whole = Math.trunc(this.accumulator);
268
+ if (whole !== 0) {
269
+ this.accumulator -= whole;
270
+ this.scrollBy(whole);
271
+ }
272
+ this.lastWheelMoved = this.scrollTop !== before;
273
+ return this.scrollTop;
274
+ }
275
+
276
+ pageUp(): number { return this.scrollBy(-Math.max(1, this.viewHeight - 1)); }
277
+ pageDown(): number { return this.scrollBy(Math.max(1, this.viewHeight - 1)); }
278
+ halfPageUp(): number { return this.scrollBy(-Math.max(1, Math.floor(this.viewHeight / 2))); }
279
+ halfPageDown(): number { return this.scrollBy(Math.max(1, Math.floor(this.viewHeight / 2))); }
280
+ lineUp(n: number = 1): number { return this.scrollBy(-n); }
281
+ lineDown(n: number = 1): number { return this.scrollBy(n); }
282
+ toTop(): number { return this.scrollTo(0); }
283
+
284
+ toBottom(): number {
285
+ this.manual = false;
286
+ this.unseen = 0;
287
+ this.refresh();
288
+ return this.scrollTop;
289
+ }
290
+
291
+ jump(direction: number, kinds: string[] | null = null): number {
292
+ if (!this.transcript || typeof this.transcript.markers !== 'function') 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);
300
+ }
301
+ const next = markers.find((m) => m.row > this.scrollTop);
302
+ return next ? this.scrollTo(next.row) : this.toBottom();
303
+ }
304
+
305
+ rows(): string[] {
306
+ const window = this.transcript && typeof this.transcript.slice === 'function'
307
+ ? this.transcript.slice(this.viewWidth, this.scrollTop, this.viewHeight)
308
+ : [];
309
+ const out = window.slice(0, this.viewHeight);
310
+ while (out.length < this.viewHeight) out.push('');
311
+ return out;
312
+ }
313
+
314
+ state(): ViewportState {
315
+ const max = this.maxScrollTop();
316
+ return {
317
+ scrollTop: this.scrollTop,
318
+ max,
319
+ height: this.viewHeight,
320
+ contentHeight: this.contentHeight(),
321
+ following: this.following,
322
+ unseen: this.unseen,
323
+ progress: max > 0 ? this.scrollTop / max : null
324
+ };
325
+ }
326
+ }
@@ -187,6 +187,60 @@ export interface PlanMatch {
187
187
  };
188
188
  }
189
189
 
190
+ /** APC pipeline wall-clock latency breakdown matching Table 3 (Page 9) */
191
+ export interface APCPipelineLatency {
192
+ planMs: number;
193
+ actMs: number;
194
+ keywordExtractionMs: number;
195
+ cacheLookupMs: number;
196
+ cacheGenerationMs: number;
197
+ totalMs: number;
198
+ }
199
+
200
+ /** APC model and cache overhead cost breakdown matching Table 2 (Page 9) */
201
+ export interface APCCostBreakdown {
202
+ largePlannerCost: number;
203
+ smallPlannerCost: number;
204
+ actorCost: number;
205
+ cacheOverhead: {
206
+ keywordExtractionCost: number;
207
+ cacheGenerationCost: number;
208
+ totalOverheadCost: number;
209
+ overheadPercentage: number;
210
+ };
211
+ totalCost: number;
212
+ }
213
+
214
+ /** APC cache lookup scalability benchmark entry matching Table 5 (Page 10) */
215
+ export interface APCLookupScalabilityPoint {
216
+ cacheSize: number;
217
+ exactHitLatencyUs: number;
218
+ exactMissLatencyUs: number;
219
+ fuzzyHitLatencyUs: number;
220
+ fuzzyMissLatencyUs: number;
221
+ }
222
+
223
+ /** APC fuzzy keyword matching similarity threshold profile matching Table 6 (Page 10) */
224
+ export interface APCFuzzyThresholdProfile {
225
+ threshold: number;
226
+ hitRate: number;
227
+ cost: number;
228
+ accuracy: number;
229
+ planningLatencySec: number;
230
+ totalLatencySec: number;
231
+ }
232
+
233
+ /** APC cold-start progression entry matching Table 7 (Page 10) */
234
+ export interface APCColdStartPoint {
235
+ queryPercentile: number;
236
+ cacheEntries: number;
237
+ hitRate: number;
238
+ cost: number;
239
+ planningLatencySec: number;
240
+ cacheGenLatencySec: number;
241
+ totalLatencySec: number;
242
+ }
243
+
190
244
  export type PluginCapability = 'workspace:read' | 'workspace:write' | 'network' | 'subprocess';
191
245
 
192
246
  export interface PluginToolManifest {
@@ -26,9 +26,10 @@ export function resolveUserPath(input) {
26
26
  }
27
27
  return path.resolve(raw);
28
28
  }
29
- const STATE_ROOT = process.env['CAUSYNE_HOME'] && String(process.env['CAUSYNE_HOME']).trim()
30
- ? path.resolve(String(process.env['CAUSYNE_HOME']).trim())
31
- : path.join(os.homedir(), '.causyne');
32
29
  export function causyneHome() {
33
- return STATE_ROOT;
30
+ const envHome = process.env['CAUSYNE_HOME'];
31
+ if (envHome && String(envHome).trim()) {
32
+ return path.resolve(String(envHome).trim());
33
+ }
34
+ return path.join(os.homedir(), '.causyne');
34
35
  }
@@ -27,10 +27,10 @@ export function resolveUserPath(input: string): string {
27
27
  return path.resolve(raw);
28
28
  }
29
29
 
30
- const STATE_ROOT = process.env['CAUSYNE_HOME'] && String(process.env['CAUSYNE_HOME']).trim()
31
- ? path.resolve(String(process.env['CAUSYNE_HOME']).trim())
32
- : path.join(os.homedir(), '.causyne');
33
-
34
30
  export function causyneHome(): string {
35
- return STATE_ROOT;
31
+ const envHome = process.env['CAUSYNE_HOME'];
32
+ if (envHome && String(envHome).trim()) {
33
+ return path.resolve(String(envHome).trim());
34
+ }
35
+ return path.join(os.homedir(), '.causyne');
36
36
  }