@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
@@ -25,8 +25,15 @@ import { Stage, stageHeight } from './stage.js';
25
25
  import { Transcript } from './transcript.js';
26
26
  import { Viewport, ScrollAcceleration, DEFAULT_SCROLL_SPEED } from './viewport.js';
27
27
  import { paint, GLYPHS } from './theme.js';
28
+ import { markHoveredMessage } from './messageInteraction.js';
29
+ import { placeMessageActionPanel } from './messageActionPlacement.js';
28
30
  import { mouseTracking } from './keys.js';
31
+ import { mouseHoverTracking } from './mouseHover.js';
29
32
  import { truncate, padEnd, visibleWidth } from './text.js';
33
+ import { composerWidth } from './layout.js';
34
+ import { placeHome, placeDialog } from './homeView.js';
35
+ import { sidebarVisible, sessionMainWidth, sessionComposerWidth, sessionSidebarRows, joinSessionSidebar } from './sessionSidebar.js';
36
+ import { sessionStageHeight, alignTranscriptRows } from './sessionLayout.js';
30
37
 
31
38
  // Rows of evicted transcript held for the exit log. Eviction only happens after
32
39
  // MAX_FRAMES, so this is a bound on a pathological session, not a working limit.
@@ -36,24 +43,6 @@ const MAX_EVICTED_ROWS = 40000;
36
43
  // shown at all — which is a broken screen, so the prompt is trimmed instead.
37
44
  const MIN_VIEWPORT_ROWS = 2;
38
45
 
39
- // Fallback measure for the opening composition, used only when the caller does
40
- // not hand over the banner's real width.
41
- //
42
- // The session banner comes out ~82 columns wide (the wordmark beside its facts
43
- // column, and the workspace path under it). While the input box stretched the
44
- // full width of a large terminal, the two read as unrelated objects — a thin line
45
- // pulled across a wide emptiness under a block that stops two-thirds of the way.
46
- // Ninety sits just above the banner and just below the 100-column prose measure
47
- // theme.js already uses, so the opening reads as ONE panel.
48
- //
49
- // It applies ONLY while the transcript is empty. The session input box keeps
50
- // filling the window, which is an established layout invariant — tuiWidth
51
- // asserts "the input box fills a stretched terminal" after a hardcoded 120-column
52
- // ceiling was torn out of three modules for leaving a wide terminal two-thirds
53
- // covered. This does not reopen that: it is a different rule for a different
54
- // moment, and it lifts the instant a session begins.
55
- const OPENING_FALLBACK_WIDTH = 100;
56
-
57
46
  // The rail costs a column plus a column of air. On a narrow terminal those two
58
47
  // are worth more as text, so it turns itself off rather than crowding the
59
48
  // transcript it exists to help you navigate.
@@ -159,6 +148,7 @@ export class StageSurface {
159
148
  onEvict: (rows) => this.absorbEvicted(rows),
160
149
  onChange: () => this.handleChange()
161
150
  });
151
+ this.transcript.surface = this;
162
152
  const tuning = scrollSettings(env, config);
163
153
  this.viewport = new Viewport({
164
154
  transcript: this.transcript,
@@ -182,44 +172,57 @@ export class StageSurface {
182
172
  // in the way of.
183
173
  this.mouseWanted = String(env.CAUSYNE_MOUSE ?? '1') !== '0';
184
174
  this.mouseOn = false;
175
+ this.mouseCaptured = false;
176
+ this.detached = false;
185
177
 
186
- // The width the banner above the band actually used, handed over by the
187
- // caller that printed it. Zero means "nobody measured", and the fallback
188
- // applies.
178
+ // Retained for callers that pass a measured header width. The composer now
179
+ // uses a stable readable width even after the first transcript entry.
189
180
  this.openingWidth = Number.isFinite(openingWidth) && openingWidth > 0
190
181
  ? Math.floor(openingWidth)
191
182
  : 0;
192
183
 
193
- // Has anything ever landed in this session?
194
- //
195
- // NOT the same question as "is the transcript empty", and the difference is
196
- // a real defect: /print and ctrl+L empty the transcript, so keying on
197
- // emptiness narrowed the input box back to the banner's measure long after
198
- // the banner had scrolled out of view — the box visibly shrinking for a
199
- // reason the user cannot see. The opening measure belongs to THE opening,
200
- // once, not to every empty moment after it.
184
+ // Tracks whether this session has ever received transcript content.
201
185
  this.opened = false;
186
+ this.homeInfo = null;
187
+ this.homeSessionSelected = false;
188
+ this.sessionInfo = null;
189
+ this.sidebarStatus = null;
190
+ this.sidebarPlan = [];
191
+ this.fullSession = false;
192
+ this.lastPromptRows = [];
193
+ this.lastPromptCaret = null;
194
+ this.messageActionOverlay = null;
202
195
  }
203
196
 
204
197
  get width() {
205
198
  return this.stage.width();
206
199
  }
207
200
 
208
- /**
209
- * The width the prompt block should be composed to.
210
- *
211
- * Deliberately NOT centred, which is where Causyne parts company with the
212
- * reference on purpose. opencode centres its logo and prompt because its logo
213
- * is centred in a screen it owns (routes/home.tsx:72-90). Causyne's banner is
214
- * left-aligned in the user's real scrollback, so a centred input box below it
215
- * would be misaligned with the very thing it is supposed to belong to. Same
216
- * origin, same measure: the opening reads as a document block, not a splash.
217
- */
201
+ /** Home is compact; a session uses its full conversation column. */
218
202
  composeWidth() {
219
- const width = this.width;
220
- if (this.opened || !this.transcript.isEmpty()) return width;
221
- const measure = this.openingWidth > 0 ? this.openingWidth : OPENING_FALLBACK_WIDTH;
222
- return Math.min(width, measure);
203
+ return this.homeInfo
204
+ ? composerWidth(this.width)
205
+ : sessionComposerWidth(sessionMainWidth(this.width));
206
+ }
207
+
208
+ /** Keep Home distinct from a selected or newly started conversation. */
209
+ enterHome(info) {
210
+ this.homeInfo = info;
211
+ this.homeSessionSelected = false;
212
+ this.sessionInfo = { title: 'Untitled', cwd: info?.cwd, provider: info?.provider, model: info?.model };
213
+ this.fullSession = true;
214
+ this.stage.invalidate();
215
+ }
216
+
217
+ leaveHome(sessionSelected = false) {
218
+ if (this.homeInfo) this.stage.invalidate();
219
+ this.homeInfo = null;
220
+ if (sessionSelected) this.homeSessionSelected = true;
221
+ }
222
+
223
+ setSessionInfo(info) {
224
+ this.sessionInfo = { ...this.sessionInfo, ...info };
225
+ this.stage.invalidate();
223
226
  }
224
227
 
225
228
  /**
@@ -247,6 +250,7 @@ export class StageSurface {
247
250
  enableMouse() {
248
251
  if (!this.mouseWanted || this.mouseOn) return false;
249
252
  this.out.write(mouseTracking(true));
253
+ this.out.write(mouseHoverTracking(true, this.env));
250
254
  this.mouseCaptured = true;
251
255
  this.mouseOn = true;
252
256
  return true;
@@ -254,6 +258,7 @@ export class StageSurface {
254
258
 
255
259
  disableMouse() {
256
260
  if (!this.mouseOn) return false;
261
+ this.out.write(mouseHoverTracking(false, this.env));
257
262
  this.out.write(mouseTracking(false));
258
263
  this.mouseCaptured = false;
259
264
  this.mouseOn = false;
@@ -338,7 +343,9 @@ export class StageSurface {
338
343
  handleChange() {
339
344
  if (!this.transcript.isEmpty()) this.opened = true;
340
345
  const before = this.lastHeight;
341
- const after = this.transcript.height(this.width);
346
+ const mainWidth = sessionMainWidth(this.width);
347
+ const contentWidth = this.railEnabled(mainWidth) ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
348
+ const after = this.transcript.height(contentWidth);
342
349
  this.lastHeight = after;
343
350
  // Growth is what drives auto-scroll. Handing the delta over is also what
344
351
  // lets the "N new below" affordance count only what arrived while the user
@@ -365,22 +372,37 @@ export class StageSurface {
365
372
  present(promptRows, caret = null) {
366
373
  if (!this.stage.reserved) return 0;
367
374
 
375
+ if (!this.messageActionOverlay) {
376
+ this.lastPromptRows = promptRows;
377
+ this.lastPromptCaret = caret;
378
+ }
379
+
380
+ if (this.homeInfo || (caret?.modal && !caret?.inline)) {
381
+ if (this.stage.height < this.stage.maxHeight) {
382
+ this.stage.grow(this.stage.maxHeight - this.stage.height);
383
+ }
384
+ const view = caret?.modal
385
+ ? placeDialog(promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0)
386
+ : placeHome(this.homeInfo, promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0);
387
+ return this.stage.paint(view.rows, { row: view.caretRow, col: view.caretCol });
388
+ }
389
+
368
390
  const width = this.width;
369
- const rail = this.railEnabled(width);
370
- const contentWidth = rail ? Math.max(20, width - RAIL_BUDGET) : width;
391
+ const sidebar = sidebarVisible(width);
392
+ const mainWidth = sessionMainWidth(width);
393
+ const rail = this.railEnabled(mainWidth);
394
+ const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
371
395
 
372
396
  let block = promptRows;
373
397
  let caretRow = caret && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
374
398
 
375
399
  // Grow the band to what there is to show, before deciding anything else.
376
400
  //
377
- // An empty session wants exactly the prompt and no more — no viewport, no
378
- // void, and no rows taken from the user's terminal that nothing is going to
379
- // fill. As the transcript grows the band follows it, up to the ceiling; it
380
- // never shrinks, because shrinking would mean erasing rows the diff believes
381
- // it owns and fighting the resize path for them.
401
+ // Direct chat keeps its printed header and grows with content. A session
402
+ // entered from Home occupies the available height at every terminal width.
403
+ // Its short transcript is placed next to the input below.
382
404
  const contentRows = this.transcript.height(contentWidth);
383
- const desired = Math.min(this.stage.maxHeight, block.length + contentRows);
405
+ const desired = sessionStageHeight(this.stage.maxHeight, block.length, contentRows, this.fullSession || caret?.inline);
384
406
  if (desired > this.stage.height) this.stage.grow(desired - this.stage.height);
385
407
 
386
408
  const height = this.stage.height;
@@ -390,7 +412,9 @@ export class StageSurface {
390
412
  // footer and the caret row are the last rows and the ones worth keeping,
391
413
  // and an input box that has scrolled its own oldest row off is a smaller lie
392
414
  // than a transcript that has vanished.
393
- const floor = contentRows > 0 ? MIN_VIEWPORT_ROWS : 0;
415
+ const floor = contentRows > 0
416
+ ? Math.max(MIN_VIEWPORT_ROWS, this.messageActionOverlay?.panel.length || 0)
417
+ : 0;
394
418
  const maxBlock = Math.max(1, height - floor);
395
419
  if (block.length > maxBlock) {
396
420
  const cut = block.length - maxBlock;
@@ -402,9 +426,18 @@ export class StageSurface {
402
426
  let rows = [];
403
427
  if (budget > 0) {
404
428
  this.viewport.resize({ height: budget, width: contentWidth });
405
- rows = this.viewport.rows();
429
+ rows = alignTranscriptRows(this.viewport.rows(), contentRows);
406
430
  this.decorate(rows, contentWidth);
431
+ markHoveredMessage(rows, this, contentWidth);
407
432
  if (rail) this.attachRail(rows, contentWidth);
433
+ if (this.messageActionOverlay) {
434
+ const overlay = this.messageActionOverlay;
435
+ const placed = placeMessageActionPanel(rows, overlay.panel, contentWidth,
436
+ (this.out.rows || height) - height, overlay.layer.anchorY,
437
+ overlay.layer.items.length);
438
+ rows = placed.rows;
439
+ overlay.layer.actionLayout = placed.layout;
440
+ }
408
441
  }
409
442
 
410
443
  // DO NOT PAINT WHILE THE TERMINAL OWNS THE SCROLL.
@@ -422,12 +455,33 @@ export class StageSurface {
422
455
  // left it, so every write would land somewhere wrong.
423
456
  if (this.detached) return false;
424
457
 
425
- return this.stage.paint(rows.concat(block), {
458
+ const mainRows = rows.concat(block);
459
+ const panelRows = sidebar ? sessionSidebarRows({
460
+ ...this.sessionInfo,
461
+ cwd: this.sidebarStatus?.cwd || this.sessionInfo?.cwd,
462
+ provider: this.sidebarStatus?.provider || this.sessionInfo?.provider,
463
+ model: this.sidebarStatus?.model || this.sessionInfo?.model,
464
+ contextChars: this.sidebarStatus?.contextChars,
465
+ contextLimit: this.sidebarStatus?.contextLimit,
466
+ plan: this.sidebarPlan
467
+ }, mainRows.length) : [];
468
+ const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth) : mainRows;
469
+ return this.stage.paint(painted, {
426
470
  row: rows.length + caretRow,
427
471
  col: caret ? caret.col : 0
428
472
  });
429
473
  }
430
474
 
475
+ /** Draw message actions over the transcript while retaining the live composer. */
476
+ presentMessageActions(panel, layer) {
477
+ this.messageActionOverlay = { panel, layer };
478
+ try {
479
+ return this.present(this.lastPromptRows, this.lastPromptCaret);
480
+ } finally {
481
+ this.messageActionOverlay = null;
482
+ }
483
+ }
484
+
431
485
  /**
432
486
  * The one thing on screen that opencode does not have: while the view is held
433
487
  * away from the bottom, say so and say how much arrived.
@@ -469,6 +523,19 @@ export class StageSurface {
469
523
  return rows.length;
470
524
  }
471
525
 
526
+ /** Clear the transcript without printing through to scrollback (for session switching). */
527
+ clearTranscript() {
528
+ this.evicted = [];
529
+ this.transcript.clear();
530
+ this.lastHeight = 0;
531
+ this.stage.invalidate();
532
+ if (this.viewport) {
533
+ this.viewport.manual = false;
534
+ this.viewport.unseen = 0;
535
+ this.viewport.toBottom();
536
+ }
537
+ }
538
+
472
539
  /**
473
540
  * The terminal changed size. Callers must debounce — ChatPrompt already
474
541
  * settles resize at RESIZE_SETTLE_MS.
@@ -487,8 +554,10 @@ export class StageSurface {
487
554
  this.stage.invalidate();
488
555
  // Re-derive from the new geometry: growing the viewport lowers maxScrollTop,
489
556
  // and leaving scrollTop above it would read as "the user scrolled away".
490
- this.viewport.resize({ height: Math.max(MIN_VIEWPORT_ROWS, this.stage.height - 2), width: this.width });
491
- this.lastHeight = this.transcript.height(this.width);
557
+ const mainWidth = sessionMainWidth(this.width);
558
+ const contentWidth = this.railEnabled(mainWidth) ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
559
+ this.viewport.resize({ height: Math.max(MIN_VIEWPORT_ROWS, this.stage.height - 2), width: contentWidth });
560
+ this.lastHeight = this.transcript.height(contentWidth);
492
561
  return this.stage.reserved;
493
562
  }
494
563
 
@@ -572,6 +641,7 @@ export class StageSurface {
572
641
  */
573
642
  releaseMouse() {
574
643
  if (!this.mouseCaptured) return false;
644
+ this.out.write(mouseHoverTracking(false, this.env));
575
645
  this.out.write(mouseTracking(false));
576
646
  this.mouseCaptured = false;
577
647
  this.detached = true;
@@ -582,6 +652,7 @@ export class StageSurface {
582
652
  captureMouse() {
583
653
  if (this.mouseCaptured) return false;
584
654
  this.out.write(mouseTracking(true));
655
+ this.out.write(mouseHoverTracking(true, this.env));
585
656
  this.mouseCaptured = true;
586
657
  this.detached = false;
587
658
  // Every row the diff remembers is stale — the terminal has scrolled under
@@ -80,14 +80,14 @@ export class StatusLine {
80
80
 
81
81
  /** Session-lifetime facts, set once from the same info as the header. */
82
82
  setSession(info = {}) {
83
- this.model = shortModel(info.model);
84
- this.provider = info.provider ? String(info.provider) : '';
85
- this.tier = info.tier ? String(info.tier) : '';
83
+ if (info.model !== undefined) this.model = shortModel(info.model);
84
+ if (info.provider !== undefined) this.provider = info.provider ? String(info.provider) : '';
85
+ if (info.tier !== undefined) this.tier = info.tier ? String(info.tier) : '';
86
86
  // The idle footer answers "where am I and how much room is left", which is
87
87
  // what opencode's permanent footer shows (cwd left, context right). Neither
88
88
  // fact was reachable once the session header had scrolled away.
89
- this.cwd = info.cwd ? String(info.cwd) : '';
90
- this.contextLimit = Number(info.contextLimit) || 0;
89
+ if (info.cwd !== undefined) this.cwd = info.cwd ? String(info.cwd) : '';
90
+ if (info.contextLimit !== undefined) this.contextLimit = Number(info.contextLimit) || 0;
91
91
  return this;
92
92
  }
93
93
 
@@ -0,0 +1,5 @@
1
+ export function safeDisplay(value: string): string;
2
+ export function truncate(value: string, width: number, ellipsis?: string): string;
3
+ export function padEnd(value: string, width: number): string;
4
+ export function visibleWidth(value: string): number;
5
+ export function wrap(value: string, width: number): string[];
@@ -0,0 +1,23 @@
1
+ import { visibleWidth, wrap } from './text.js';
2
+ // The terminal palette remains a JavaScript module during the TypeScript migration.
3
+ // @ts-expect-error theme.js does not have a declaration yet.
4
+ import { paint } from './theme.js';
5
+ /** Width of text inside the current conversation column, with room for its inset. */
6
+ export function chatTextWidth(columns) {
7
+ const available = Number.isFinite(columns) ? Math.floor(columns) : 80;
8
+ return Math.max(8, available - 4);
9
+ }
10
+ /** Widen prose gradually on large screens so lines remain readable. */
11
+ export function chatProseWidth(columns) {
12
+ const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
13
+ if (available <= 100)
14
+ return available;
15
+ return Math.min(chatTextWidth(available), Math.round(100 + 24 * Math.log2(available / 100)));
16
+ }
17
+ /** Keep every line of a labeled message visible when the terminal is resized. */
18
+ export function wrappedChatRows(message, columns, prefix, tone) {
19
+ const inset = visibleWidth(prefix);
20
+ const room = Math.max(1, chatTextWidth(columns) - inset);
21
+ const continuation = ' '.repeat(inset);
22
+ return wrap(message, room).map((line, index) => `${index === 0 ? prefix : continuation}${paint(tone, line)}`);
23
+ }
@@ -0,0 +1,28 @@
1
+ import { visibleWidth, wrap } from './text.js';
2
+ // The terminal palette remains a JavaScript module during the TypeScript migration.
3
+ // @ts-expect-error theme.js does not have a declaration yet.
4
+ import { paint } from './theme.js';
5
+
6
+ export type MessageTone = 'danger' | 'warn' | 'muted' | 'accent';
7
+
8
+ /** Width of text inside the current conversation column, with room for its inset. */
9
+ export function chatTextWidth(columns: number): number {
10
+ const available = Number.isFinite(columns) ? Math.floor(columns) : 80;
11
+ return Math.max(8, available - 4);
12
+ }
13
+
14
+ /** Widen prose gradually on large screens so lines remain readable. */
15
+ export function chatProseWidth(columns: number): number {
16
+ const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
17
+ if (available <= 100) return available;
18
+ return Math.min(chatTextWidth(available), Math.round(100 + 24 * Math.log2(available / 100)));
19
+ }
20
+
21
+ /** Keep every line of a labeled message visible when the terminal is resized. */
22
+ export function wrappedChatRows(message: string, columns: number, prefix: string, tone: MessageTone): string[] {
23
+ const inset = visibleWidth(prefix);
24
+ const room = Math.max(1, chatTextWidth(columns) - inset);
25
+ const continuation = ' '.repeat(inset);
26
+ return wrap(message, room).map((line: string, index: number) =>
27
+ `${index === 0 ? prefix : continuation}${paint(tone, line)}`);
28
+ }