@causyne/agent 1.20.112 → 1.20.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/docs/ARCHITECTURE.md +29 -0
  2. package/package.json +1 -1
  3. package/src/agentLoop.js +72 -37
  4. package/src/agentLoop.ts +70 -38
  5. package/src/browser/browserRuntime.js +13 -8
  6. package/src/browser/browserRuntime.ts +16 -8
  7. package/src/browser/causyneBrowser.js +7 -2
  8. package/src/browser/causyneBrowser.ts +8 -2
  9. package/src/browser/searchProviders.js +18 -7
  10. package/src/browser/searchProviders.ts +17 -5
  11. package/src/browser/snapshotWindow.js +1 -1
  12. package/src/browser/snapshotWindow.ts +1 -1
  13. package/src/browser/urlPolicy.js +21 -10
  14. package/src/browser/urlPolicy.ts +19 -10
  15. package/src/browser/workspacePreview.js +13 -1
  16. package/src/browser/workspacePreview.ts +11 -1
  17. package/src/computerUse/visionGrounding.js +31 -27
  18. package/src/computerUse/visionGrounding.ts +27 -27
  19. package/src/continuum/ui/continuumPicker.js +14 -6
  20. package/src/continuum/ui/continuumPicker.ts +13 -6
  21. package/src/continuum/ui/continuumPickerView.js +24 -15
  22. package/src/continuum/ui/continuumPickerView.ts +24 -16
  23. package/src/observer/advisory.js +32 -22
  24. package/src/observer/advisory.ts +30 -18
  25. package/src/observer/coldObserver.js +21 -33
  26. package/src/observer/coldObserver.ts +20 -33
  27. package/src/observer/evidence.js +20 -13
  28. package/src/observer/evidence.ts +21 -13
  29. package/src/observer.js +47 -12
  30. package/src/observer.ts +50 -18
  31. package/src/pluginsFactory/discovery.js +28 -16
  32. package/src/pluginsFactory/discovery.ts +29 -16
  33. package/src/pluginsFactory/pluginsFactory.js +213 -38
  34. package/src/pluginsFactory/pluginsFactory.ts +218 -39
  35. package/src/pluginsFactory/strategy.js +26 -16
  36. package/src/pluginsFactory/strategy.ts +34 -19
  37. package/src/pluginsFactory/templates.js +183 -62
  38. package/src/pluginsFactory/templates.ts +174 -54
  39. package/src/timeMachine.js +43 -22
  40. package/src/timeMachine.ts +44 -22
  41. package/src/tool-scripts/desktop_act.applescript +1 -0
  42. package/src/tools/computerUse.js +23 -10
  43. package/src/tools/computerUse.ts +19 -8
  44. package/src/tools/desktopAct.js +12 -1
  45. package/src/tools/pluginsFactory.js +108 -5
  46. package/src/tools/pluginsFactory.ts +115 -5
  47. package/src/tui/CausyneRotor.js +24 -10
  48. package/src/tui/CausyneRotor.ts +25 -10
  49. package/src/tui/activityLayout.js +9 -5
  50. package/src/tui/activityLayout.ts +9 -5
  51. package/src/tui/ask.js +34 -14
  52. package/src/tui/banner.js +55 -18
  53. package/src/tui/banner.ts +52 -17
  54. package/src/tui/block.js +47 -20
  55. package/src/tui/block.ts +54 -27
  56. package/src/tui/chatRenderer.js +135 -83
  57. package/src/tui/chatboxClipboard.js +12 -5
  58. package/src/tui/chatboxClipboard.ts +10 -4
  59. package/src/tui/clipboardImage.js +52 -42
  60. package/src/tui/clipboardImage.ts +50 -39
  61. package/src/tui/clipboardSync.js +12 -1
  62. package/src/tui/clipboardSync.ts +9 -1
  63. package/src/tui/codeProgress.js +57 -26
  64. package/src/tui/codeProgress.ts +57 -25
  65. package/src/tui/codeStreamRenderer.js +59 -14
  66. package/src/tui/codeStreamRenderer.ts +58 -14
  67. package/src/tui/commandPresentation.js +9 -2
  68. package/src/tui/commandPresentation.ts +9 -2
  69. package/src/tui/completion.js +45 -23
  70. package/src/tui/composerControls.js +21 -10
  71. package/src/tui/composerControls.ts +18 -10
  72. package/src/tui/composerGeometry.js +6 -4
  73. package/src/tui/composerGeometry.ts +6 -4
  74. package/src/tui/consoleGuard.js +29 -7
  75. package/src/tui/consoleGuard.ts +28 -7
  76. package/src/tui/dialogs.js +134 -71
  77. package/src/tui/diff.js +8 -4
  78. package/src/tui/history.js +6 -5
  79. package/src/tui/home.js +25 -13
  80. package/src/tui/homeView.js +37 -18
  81. package/src/tui/homeView.ts +38 -18
  82. package/src/tui/inlineSlash.js +6 -5
  83. package/src/tui/inlineSlash.ts +6 -5
  84. package/src/tui/keys.js +33 -17
  85. package/src/tui/layout.js +27 -9
  86. package/src/tui/layout.ts +26 -9
  87. package/src/tui/lineEditor.js +49 -23
  88. package/src/tui/markdownMath.js +64 -14
  89. package/src/tui/markdownMath.ts +69 -13
  90. package/src/tui/messageActionPlacement.js +28 -13
  91. package/src/tui/messageActionPlacement.ts +28 -13
  92. package/src/tui/messageInteraction.js +111 -46
  93. package/src/tui/messageInteraction.ts +115 -47
  94. package/src/tui/modelPicker.js +44 -15
  95. package/src/tui/modelPicker.ts +48 -15
  96. package/src/tui/observerPicker.js +56 -13
  97. package/src/tui/observerPicker.ts +73 -30
  98. package/src/tui/overlay.js +79 -35
  99. package/src/tui/overlay.ts +81 -34
  100. package/src/tui/prompt.js +162 -94
  101. package/src/tui/runningLight.js +1 -1
  102. package/src/tui/runningLight.ts +1 -1
  103. package/src/tui/scrollInteraction.js +64 -36
  104. package/src/tui/scrollInteraction.ts +70 -37
  105. package/src/tui/selectList.js +60 -32
  106. package/src/tui/sessionLayout.js +11 -3
  107. package/src/tui/sessionLayout.ts +10 -3
  108. package/src/tui/sessionPicker.js +74 -46
  109. package/src/tui/sessionPicker.ts +73 -48
  110. package/src/tui/sessionPickerView.js +32 -19
  111. package/src/tui/sessionPickerView.ts +31 -18
  112. package/src/tui/sessionSidebar.js +87 -57
  113. package/src/tui/sessionSidebar.ts +90 -54
  114. package/src/tui/setup.js +28 -3
  115. package/src/tui/setup.ts +27 -3
  116. package/src/tui/skillAuthoring.js +11 -5
  117. package/src/tui/skillAuthoring.ts +11 -5
  118. package/src/tui/smartLinkClick.js +75 -23
  119. package/src/tui/smartLinkClick.ts +86 -26
  120. package/src/tui/stage.js +47 -16
  121. package/src/tui/stage.ts +53 -18
  122. package/src/tui/stageSurface.js +120 -49
  123. package/src/tui/statusLine.js +85 -53
  124. package/src/tui/statusLine.ts +82 -46
  125. package/src/tui/terminalInputFramer.js +5 -2
  126. package/src/tui/text.js +117 -46
  127. package/src/tui/text.ts +113 -43
  128. package/src/tui/textLayout.js +6 -4
  129. package/src/tui/textLayout.ts +11 -5
  130. package/src/tui/theme.js +17 -8
  131. package/src/tui/thinkingBox.js +95 -95
  132. package/src/tui/thinkingBox.ts +105 -80
  133. package/src/tui/toolActivityPolicy.js +8 -1
  134. package/src/tui/toolActivityPolicy.ts +7 -1
  135. package/src/tui/toolDisplay.js +15 -6
  136. package/src/tui/toolDisplay.ts +16 -6
  137. package/src/tui/toolOutputNormalizer.js +16 -3
  138. package/src/tui/toolOutputNormalizer.ts +13 -3
  139. package/src/tui/transcript.js +15 -9
  140. package/src/tui/turnRail.js +156 -67
  141. package/src/tui/turnRail.ts +155 -58
  142. package/src/tui/usageCard.js +80 -45
  143. package/src/tui/usageCard.ts +81 -46
  144. package/src/tui/viewport.js +48 -23
  145. package/src/tui/viewport.ts +48 -27
  146. package/src/tui/viewportAnchor.js +2 -2
  147. package/src/tui/viewportAnchor.ts +2 -2
  148. package/src/tui/workspaceFileIndex.js +8 -6
  149. package/src/tui/workspaceFileIndex.ts +8 -6
  150. package/src/tui/workspaceSwitch.js +13 -10
  151. package/src/tui/workspaceSwitch.ts +11 -7
package/src/tui/block.js CHANGED
@@ -27,6 +27,12 @@ import { visibleWidth, padEnd, truncate, wrap } from './text.js';
27
27
  // Columns between the bar and the text. opencode uses paddingLeft={2} inside its
28
28
  // bordered box; one column belongs to the bar, so the gutter is one more.
29
29
  const GUTTER = 1;
30
+ function finiteWidth(width, fallback = 80) {
31
+ return typeof width === 'number' && Number.isFinite(width) ? Math.floor(width) : fallback;
32
+ }
33
+ function collapseLine(value) {
34
+ return String(value == null ? '' : value).replace(/[\r\n]+/g, ' ');
35
+ }
30
36
  /**
31
37
  * Render `lines` as one block with a left accent bar.
32
38
  * Uses a continuous unbroken box-drawing heavy rule (barHeavy '┃')
@@ -36,21 +42,25 @@ const GUTTER = 1;
36
42
  * @param options configuration options
37
43
  * @returns rows, each exactly `width` columns wide
38
44
  */
39
- export function barBlock(lines, { width = 80, role = 'accent', filled = true, surface = 'surface', punctuate = false } = {}) {
45
+ export function barBlock(lines, options = {}) {
46
+ const { width = 80, role = 'accent', filled = true, surface = 'surface', punctuate = false } = options || {};
47
+ void punctuate;
40
48
  // Use continuous heavy vertical line ('┃') for clean, solid, unbroken alignment.
41
49
  // Box-drawing characters connect seamlessly across lines in all terminal fonts without line-height leading gaps.
42
50
  const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
43
51
  const barWidth = visibleWidth(glyph);
44
- const body = Math.max(1, width - barWidth - GUTTER);
52
+ const body = Math.max(1, finiteWidth(width) - barWidth - GUTTER);
45
53
  const bar = paint(role, glyph);
46
54
  const gutter = ' '.repeat(GUTTER);
47
- return lines.map((line) => {
55
+ return (Array.isArray(lines) ? lines : []).map((rawLine) => {
48
56
  // Clip first, then pad: a line longer than the block would otherwise push
49
57
  // the fill past the right edge and wrap, which is the failure ChatPrompt
50
58
  // clampRows() exists to prevent one layer up.
59
+ const line = collapseLine(rawLine);
51
60
  const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
52
61
  const padded = padEnd(clipped, body);
53
- const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
62
+ const tailReset = !filled && clipped.includes('\x1b[') ? '\x1b[0m' : '';
63
+ const inner = filled ? fill(surface, gutter + padded) : gutter + padded + tailReset;
54
64
  return bar + inner;
55
65
  });
56
66
  }
@@ -61,20 +71,26 @@ export function barBlock(lines, { width = 80, role = 'accent', filled = true, su
61
71
  * rows individually (the prompt editor, a status row) use barBlock directly.
62
72
  */
63
73
  export function blockOf(text, options = {}) {
64
- const width = options.width || 80;
74
+ const safeOptions = options || {};
75
+ const safeWidth = Math.max(4, finiteWidth(safeOptions.width));
65
76
  const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
66
- const inner = Math.max(1, width - visibleWidth(glyph) - GUTTER);
77
+ const inner = Math.max(1, safeWidth - visibleWidth(glyph) - GUTTER);
67
78
  const lines = wrap(String(text == null ? '' : text), inner);
68
- return barBlock(lines.length ? lines : [''], options);
79
+ return barBlock(lines.length ? lines : [''], { ...safeOptions, width: safeWidth });
69
80
  }
70
81
  /**
71
82
  * A bordered panel with its title inset into the top border.
72
83
  */
73
- export function panel(rows, { width = 80, title = '', role = 'rule' } = {}) {
74
- const inner = Math.max(4, width - 2);
84
+ export function panel(rows, options = {}) {
85
+ const { width = 80, title = '', role = 'rule' } = options || {};
86
+ const inner = Math.max(4, finiteWidth(width) - 2);
75
87
  const h = GLYPHS.hLine;
76
- const label = title ? ` ${title} ` : '';
77
- const clippedLabel = visibleWidth(label) > inner - 2 ? '' : label;
88
+ const cleanTitle = collapseLine(title).trim();
89
+ const maxTitleChars = inner - 3;
90
+ const boundedTitle = cleanTitle && maxTitleChars >= 3
91
+ ? truncate(cleanTitle, maxTitleChars, GLYPHS.ellipsis)
92
+ : '';
93
+ const clippedLabel = boundedTitle ? ` ${boundedTitle} ` : '';
78
94
  const lead = clippedLabel ? h : '';
79
95
  const trail = h.repeat(Math.max(0, inner - visibleWidth(clippedLabel) - visibleWidth(lead)));
80
96
  const top = paint(role, GLYPHS.topLeft + lead)
@@ -82,9 +98,11 @@ export function panel(rows, { width = 80, title = '', role = 'rule' } = {}) {
82
98
  + paint(role, trail + GLYPHS.topRight);
83
99
  const bottom = paint(role, GLYPHS.bottomLeft + h.repeat(inner) + GLYPHS.bottomRight);
84
100
  const side = paint(role, GLYPHS.vLine);
85
- const middle = rows.map((row) => {
101
+ const middle = (Array.isArray(rows) ? rows : []).map((rawRow) => {
102
+ const row = collapseLine(rawRow);
86
103
  const clipped = visibleWidth(row) > inner ? truncate(row, inner, GLYPHS.ellipsis) : row;
87
- return side + padEnd(clipped, inner) + side;
104
+ const borderReset = clipped.includes('\x1b[') ? '\x1b[0m' : '';
105
+ return side + padEnd(clipped, inner) + borderReset + side;
88
106
  });
89
107
  return [top, ...middle, bottom];
90
108
  }
@@ -92,15 +110,24 @@ export function panel(rows, { width = 80, title = '', role = 'rule' } = {}) {
92
110
  * `9.2K (5%)` — what the context window has left, at a glance.
93
111
  */
94
112
  export function contextMeter(usedTokens, limitTokens) {
95
- const used = Number(usedTokens) || 0;
96
- const limit = Number(limitTokens) || 0;
113
+ const rawUsed = Number(usedTokens);
114
+ const rawLimit = Number(limitTokens);
115
+ const used = Number.isFinite(rawUsed) ? rawUsed : 0;
116
+ const limit = Number.isFinite(rawLimit) ? rawLimit : 0;
97
117
  if (used <= 0)
98
118
  return '';
99
- const compact = used < 1000
100
- ? String(Math.round(used))
101
- : used < 1000000
102
- ? `${(used / 1000).toFixed(used < 10000 ? 1 : 0)}K`
103
- : `${(used / 1000000).toFixed(1)}M`;
119
+ const rounded = Math.round(used);
120
+ let compact;
121
+ if (rounded < 1000) {
122
+ compact = String(rounded);
123
+ }
124
+ else if (used < 9950) {
125
+ compact = `${(used / 1000).toFixed(1)}K`;
126
+ }
127
+ else {
128
+ const thousands = Math.round(used / 1000);
129
+ compact = thousands < 1000 ? `${thousands}K` : `${(used / 1000000).toFixed(1)}M`;
130
+ }
104
131
  if (limit <= 0)
105
132
  return compact;
106
133
  return `${compact} (${Math.round((used / limit) * 100)}%)`;
package/src/tui/block.ts CHANGED
@@ -30,6 +30,14 @@ import { visibleWidth, padEnd, truncate, wrap } from './text.js';
30
30
  // bordered box; one column belongs to the bar, so the gutter is one more.
31
31
  const GUTTER = 1;
32
32
 
33
+ function finiteWidth(width: number | undefined, fallback = 80): number {
34
+ return typeof width === 'number' && Number.isFinite(width) ? Math.floor(width) : fallback;
35
+ }
36
+
37
+ function collapseLine(value: unknown): string {
38
+ return String(value == null ? '' : value).replace(/[\r\n]+/g, ' ');
39
+ }
40
+
33
41
  export interface BarBlockOptions {
34
42
  width?: number;
35
43
  role?: string;
@@ -47,29 +55,33 @@ export interface BarBlockOptions {
47
55
  * @param options configuration options
48
56
  * @returns rows, each exactly `width` columns wide
49
57
  */
50
- export function barBlock(lines: string[], {
51
- width = 80,
52
- role = 'accent',
53
- filled = true,
54
- surface = 'surface',
55
- punctuate = false
56
- }: BarBlockOptions = {}): string[] {
58
+ export function barBlock(lines: string[], options: BarBlockOptions | null = {}): string[] {
59
+ const {
60
+ width = 80,
61
+ role = 'accent',
62
+ filled = true,
63
+ surface = 'surface',
64
+ punctuate = false
65
+ } = options || {};
66
+ void punctuate;
57
67
  // Use continuous heavy vertical line ('┃') for clean, solid, unbroken alignment.
58
68
  // Box-drawing characters connect seamlessly across lines in all terminal fonts without line-height leading gaps.
59
69
  const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
60
70
 
61
71
  const barWidth = visibleWidth(glyph);
62
- const body = Math.max(1, width - barWidth - GUTTER);
72
+ const body = Math.max(1, finiteWidth(width) - barWidth - GUTTER);
63
73
  const bar = paint(role, glyph);
64
74
  const gutter = ' '.repeat(GUTTER);
65
75
 
66
- return lines.map((line) => {
76
+ return (Array.isArray(lines) ? lines : []).map((rawLine) => {
67
77
  // Clip first, then pad: a line longer than the block would otherwise push
68
78
  // the fill past the right edge and wrap, which is the failure ChatPrompt
69
79
  // clampRows() exists to prevent one layer up.
80
+ const line = collapseLine(rawLine);
70
81
  const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
71
82
  const padded = padEnd(clipped, body);
72
- const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
83
+ const tailReset = !filled && clipped.includes('\x1b[') ? '\x1b[0m' : '';
84
+ const inner = filled ? fill(surface, gutter + padded) : gutter + padded + tailReset;
73
85
  return bar + inner;
74
86
  });
75
87
  }
@@ -80,12 +92,13 @@ export function barBlock(lines: string[], {
80
92
  * The convenience form for plain prose. Callers that have already styled their
81
93
  * rows individually (the prompt editor, a status row) use barBlock directly.
82
94
  */
83
- export function blockOf(text: string, options: BarBlockOptions = {}): string[] {
84
- const width = options.width || 80;
95
+ export function blockOf(text: string, options: BarBlockOptions | null = {}): string[] {
96
+ const safeOptions = options || {};
97
+ const safeWidth = Math.max(4, finiteWidth(safeOptions.width));
85
98
  const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
86
- const inner = Math.max(1, width - visibleWidth(glyph) - GUTTER);
99
+ const inner = Math.max(1, safeWidth - visibleWidth(glyph) - GUTTER);
87
100
  const lines = wrap(String(text == null ? '' : text), inner);
88
- return barBlock(lines.length ? lines : [''], options);
101
+ return barBlock(lines.length ? lines : [''], { ...safeOptions, width: safeWidth });
89
102
  }
90
103
 
91
104
  export interface PanelOptions {
@@ -97,11 +110,16 @@ export interface PanelOptions {
97
110
  /**
98
111
  * A bordered panel with its title inset into the top border.
99
112
  */
100
- export function panel(rows: string[], { width = 80, title = '', role = 'rule' }: PanelOptions = {}): string[] {
101
- const inner = Math.max(4, width - 2);
113
+ export function panel(rows: string[], options: PanelOptions | null = {}): string[] {
114
+ const { width = 80, title = '', role = 'rule' } = options || {};
115
+ const inner = Math.max(4, finiteWidth(width) - 2);
102
116
  const h = GLYPHS.hLine;
103
- const label = title ? ` ${title} ` : '';
104
- const clippedLabel = visibleWidth(label) > inner - 2 ? '' : label;
117
+ const cleanTitle = collapseLine(title).trim();
118
+ const maxTitleChars = inner - 3;
119
+ const boundedTitle = cleanTitle && maxTitleChars >= 3
120
+ ? truncate(cleanTitle, maxTitleChars, GLYPHS.ellipsis)
121
+ : '';
122
+ const clippedLabel = boundedTitle ? ` ${boundedTitle} ` : '';
105
123
  const lead = clippedLabel ? h : '';
106
124
  const trail = h.repeat(Math.max(0, inner - visibleWidth(clippedLabel) - visibleWidth(lead)));
107
125
 
@@ -111,9 +129,11 @@ export function panel(rows: string[], { width = 80, title = '', role = 'rule' }:
111
129
  const bottom = paint(role, GLYPHS.bottomLeft + h.repeat(inner) + GLYPHS.bottomRight);
112
130
 
113
131
  const side = paint(role, GLYPHS.vLine);
114
- const middle = rows.map((row) => {
132
+ const middle = (Array.isArray(rows) ? rows : []).map((rawRow) => {
133
+ const row = collapseLine(rawRow);
115
134
  const clipped = visibleWidth(row) > inner ? truncate(row, inner, GLYPHS.ellipsis) : row;
116
- return side + padEnd(clipped, inner) + side;
135
+ const borderReset = clipped.includes('\x1b[') ? '\x1b[0m' : '';
136
+ return side + padEnd(clipped, inner) + borderReset + side;
117
137
  });
118
138
 
119
139
  return [top, ...middle, bottom];
@@ -123,14 +143,21 @@ export function panel(rows: string[], { width = 80, title = '', role = 'rule' }:
123
143
  * `9.2K (5%)` — what the context window has left, at a glance.
124
144
  */
125
145
  export function contextMeter(usedTokens: number, limitTokens: number): string {
126
- const used = Number(usedTokens) || 0;
127
- const limit = Number(limitTokens) || 0;
146
+ const rawUsed = Number(usedTokens);
147
+ const rawLimit = Number(limitTokens);
148
+ const used = Number.isFinite(rawUsed) ? rawUsed : 0;
149
+ const limit = Number.isFinite(rawLimit) ? rawLimit : 0;
128
150
  if (used <= 0) return '';
129
- const compact = used < 1000
130
- ? String(Math.round(used))
131
- : used < 1000000
132
- ? `${(used / 1000).toFixed(used < 10000 ? 1 : 0)}K`
133
- : `${(used / 1000000).toFixed(1)}M`;
151
+ const rounded = Math.round(used);
152
+ let compact: string;
153
+ if (rounded < 1000) {
154
+ compact = String(rounded);
155
+ } else if (used < 9950) {
156
+ compact = `${(used / 1000).toFixed(1)}K`;
157
+ } else {
158
+ const thousands = Math.round(used / 1000);
159
+ compact = thousands < 1000 ? `${thousands}K` : `${(used / 1000000).toFixed(1)}M`;
160
+ }
134
161
  if (limit <= 0) return compact;
135
162
  return `${compact} (${Math.round((used / limit) * 100)}%)`;
136
163
  }