@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.
Files changed (169) hide show
  1. package/docs/ARCHITECTURE.md +29 -0
  2. package/package.json +1 -1
  3. package/src/agentLoop.js +153 -68
  4. package/src/agentLoop.ts +152 -71
  5. package/src/browser/browserRuntime.js +13 -8
  6. package/src/browser/browserRuntime.ts +16 -8
  7. package/src/browser/causyneBrowser.js +37 -9
  8. package/src/browser/causyneBrowser.ts +37 -9
  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/cliMode.js +5 -1
  18. package/src/computerUse/visionGrounding.js +31 -27
  19. package/src/computerUse/visionGrounding.ts +27 -27
  20. package/src/continuum/ui/continuumPicker.js +14 -6
  21. package/src/continuum/ui/continuumPicker.ts +13 -6
  22. package/src/continuum/ui/continuumPickerView.js +24 -15
  23. package/src/continuum/ui/continuumPickerView.ts +24 -16
  24. package/src/memory/scopedFacts.js +171 -0
  25. package/src/memory/scopedFacts.ts +214 -0
  26. package/src/memory.d.ts +13 -1
  27. package/src/memory.js +9 -12
  28. package/src/observer/advisory.js +32 -22
  29. package/src/observer/advisory.ts +30 -18
  30. package/src/observer/coldObserver.js +21 -33
  31. package/src/observer/coldObserver.ts +20 -33
  32. package/src/observer/evidence.js +20 -13
  33. package/src/observer/evidence.ts +21 -13
  34. package/src/observer.js +47 -12
  35. package/src/observer.ts +50 -18
  36. package/src/perception.js +124 -3
  37. package/src/perception.ts +128 -4
  38. package/src/planCache.js +17 -3
  39. package/src/planCache.ts +17 -3
  40. package/src/pluginsFactory/discovery.js +28 -16
  41. package/src/pluginsFactory/discovery.ts +29 -16
  42. package/src/pluginsFactory/pluginsFactory.js +213 -38
  43. package/src/pluginsFactory/pluginsFactory.ts +218 -39
  44. package/src/pluginsFactory/strategy.js +26 -16
  45. package/src/pluginsFactory/strategy.ts +34 -19
  46. package/src/pluginsFactory/templates.js +183 -62
  47. package/src/pluginsFactory/templates.ts +174 -54
  48. package/src/smartToolsUse.js +4 -5
  49. package/src/smartToolsUse.ts +4 -6
  50. package/src/taskShape.js +49 -7
  51. package/src/taskShape.ts +55 -7
  52. package/src/timeMachine.js +43 -22
  53. package/src/timeMachine.ts +44 -22
  54. package/src/tool-scripts/desktop_act.applescript +1 -0
  55. package/src/toolPacks.js +27 -5
  56. package/src/toolPacks.ts +32 -5
  57. package/src/tools/computerUse.js +23 -10
  58. package/src/tools/computerUse.ts +19 -8
  59. package/src/tools/desktopAct.js +12 -1
  60. package/src/tools/memoryWrite.js +8 -10
  61. package/src/tools/memoryWrite.ts +13 -11
  62. package/src/tools/pluginsFactory.js +108 -5
  63. package/src/tools/pluginsFactory.ts +115 -5
  64. package/src/tui/CausyneRotor.js +24 -10
  65. package/src/tui/CausyneRotor.ts +25 -10
  66. package/src/tui/activityLayout.js +9 -5
  67. package/src/tui/activityLayout.ts +9 -5
  68. package/src/tui/ask.js +34 -14
  69. package/src/tui/banner.js +55 -18
  70. package/src/tui/banner.ts +52 -17
  71. package/src/tui/block.js +47 -20
  72. package/src/tui/block.ts +54 -27
  73. package/src/tui/chatRenderer.js +139 -84
  74. package/src/tui/chatboxClipboard.js +12 -5
  75. package/src/tui/chatboxClipboard.ts +10 -4
  76. package/src/tui/clipboardImage.js +52 -42
  77. package/src/tui/clipboardImage.ts +50 -39
  78. package/src/tui/clipboardSync.js +12 -1
  79. package/src/tui/clipboardSync.ts +9 -1
  80. package/src/tui/codeProgress.js +60 -28
  81. package/src/tui/codeProgress.ts +60 -27
  82. package/src/tui/codeStreamRenderer.js +94 -23
  83. package/src/tui/codeStreamRenderer.ts +92 -23
  84. package/src/tui/commandPresentation.js +9 -2
  85. package/src/tui/commandPresentation.ts +9 -2
  86. package/src/tui/completion.js +45 -23
  87. package/src/tui/composerControls.js +21 -10
  88. package/src/tui/composerControls.ts +18 -10
  89. package/src/tui/composerGeometry.js +6 -4
  90. package/src/tui/composerGeometry.ts +6 -4
  91. package/src/tui/consoleGuard.js +29 -7
  92. package/src/tui/consoleGuard.ts +28 -7
  93. package/src/tui/dialogs.js +134 -71
  94. package/src/tui/diff.js +8 -4
  95. package/src/tui/history.js +6 -5
  96. package/src/tui/home.js +25 -13
  97. package/src/tui/homeView.js +37 -18
  98. package/src/tui/homeView.ts +38 -18
  99. package/src/tui/inlineSlash.js +6 -5
  100. package/src/tui/inlineSlash.ts +6 -5
  101. package/src/tui/keys.js +36 -18
  102. package/src/tui/layout.js +27 -9
  103. package/src/tui/layout.ts +26 -9
  104. package/src/tui/lineEditor.js +49 -23
  105. package/src/tui/markdownMath.js +64 -14
  106. package/src/tui/markdownMath.ts +69 -13
  107. package/src/tui/messageActionPlacement.js +28 -13
  108. package/src/tui/messageActionPlacement.ts +28 -13
  109. package/src/tui/messageInteraction.js +111 -46
  110. package/src/tui/messageInteraction.ts +115 -47
  111. package/src/tui/modelPicker.js +44 -15
  112. package/src/tui/modelPicker.ts +48 -15
  113. package/src/tui/observerPicker.js +56 -13
  114. package/src/tui/observerPicker.ts +73 -30
  115. package/src/tui/overlay.js +79 -35
  116. package/src/tui/overlay.ts +81 -34
  117. package/src/tui/prompt.js +186 -94
  118. package/src/tui/runningLight.js +1 -1
  119. package/src/tui/runningLight.ts +1 -1
  120. package/src/tui/scrollInteraction.js +64 -36
  121. package/src/tui/scrollInteraction.ts +70 -37
  122. package/src/tui/selectList.js +60 -32
  123. package/src/tui/sessionLayout.js +11 -3
  124. package/src/tui/sessionLayout.ts +10 -3
  125. package/src/tui/sessionPicker.js +74 -46
  126. package/src/tui/sessionPicker.ts +73 -48
  127. package/src/tui/sessionPickerView.js +32 -19
  128. package/src/tui/sessionPickerView.ts +31 -18
  129. package/src/tui/sessionSidebar.js +87 -57
  130. package/src/tui/sessionSidebar.ts +90 -54
  131. package/src/tui/setup.js +28 -3
  132. package/src/tui/setup.ts +27 -3
  133. package/src/tui/skillAuthoring.js +11 -5
  134. package/src/tui/skillAuthoring.ts +11 -5
  135. package/src/tui/smartLinkClick.js +75 -23
  136. package/src/tui/smartLinkClick.ts +86 -26
  137. package/src/tui/stage.js +47 -16
  138. package/src/tui/stage.ts +53 -18
  139. package/src/tui/stageSurface.js +232 -51
  140. package/src/tui/statusLine.js +85 -53
  141. package/src/tui/statusLine.ts +82 -46
  142. package/src/tui/terminalInputFramer.js +5 -2
  143. package/src/tui/text.js +117 -46
  144. package/src/tui/text.ts +113 -43
  145. package/src/tui/textLayout.js +6 -4
  146. package/src/tui/textLayout.ts +11 -5
  147. package/src/tui/theme.js +17 -8
  148. package/src/tui/thinkingBox.js +95 -95
  149. package/src/tui/thinkingBox.ts +105 -80
  150. package/src/tui/toolActivityPolicy.js +8 -1
  151. package/src/tui/toolActivityPolicy.ts +7 -1
  152. package/src/tui/toolDisplay.js +15 -6
  153. package/src/tui/toolDisplay.ts +16 -6
  154. package/src/tui/toolOutputNormalizer.js +16 -3
  155. package/src/tui/toolOutputNormalizer.ts +13 -3
  156. package/src/tui/transcript.js +15 -9
  157. package/src/tui/turnRail.js +176 -80
  158. package/src/tui/turnRail.ts +173 -71
  159. package/src/tui/usageCard.js +136 -80
  160. package/src/tui/usageCard.ts +145 -103
  161. package/src/tui/viewport.js +48 -23
  162. package/src/tui/viewport.ts +48 -27
  163. package/src/tui/viewportAnchor.js +2 -2
  164. package/src/tui/viewportAnchor.ts +2 -2
  165. package/src/tui/workspaceFileIndex.js +8 -6
  166. package/src/tui/workspaceFileIndex.ts +8 -6
  167. package/src/tui/workspaceSwitch.js +13 -10
  168. package/src/tui/workspaceSwitch.ts +11 -7
  169. package/src/types/contracts.ts +3 -0
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
  }