@causyne/agent 1.20.111 → 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
@@ -124,8 +124,14 @@ function fallbackDisplay(toolName, args) {
124
124
  *
125
125
  * Never throws: a display helper must not be able to break the transcript.
126
126
  */
127
+ function cleanSingleLine(text) {
128
+ return safeDisplay(text).replace(/\s+/g, ' ').trim();
129
+ }
130
+ function normalizeRecordArgs(args) {
131
+ return args && typeof args === 'object' && !Array.isArray(args) ? args : {};
132
+ }
127
133
  export function describeTool(toolName, args) {
128
- const safeArgs = args && typeof args === 'object' ? args : {};
134
+ const safeArgs = normalizeRecordArgs(args);
129
135
  const safeName = typeof toolName === 'string' ? toolName : '';
130
136
  let display;
131
137
  try {
@@ -136,9 +142,9 @@ export function describeTool(toolName, args) {
136
142
  display = fallbackDisplay(safeName, safeArgs);
137
143
  }
138
144
  return {
139
- verb: safeDisplay(display.verb || ''),
145
+ verb: cleanSingleLine(display.verb || ''),
140
146
  // Untrusted: an argument can carry escapes or a credential the model echoed.
141
- detail: safeDisplay(display.detail || '').replace(/\s+/g, ' ').trim()
147
+ detail: cleanSingleLine(display.detail || '')
142
148
  };
143
149
  }
144
150
  /** True when a curated entry exists — used by tests and by /help style output. */
@@ -150,13 +156,16 @@ export function hasCuratedDisplay(toolName) {
150
156
  * row. Reuses the same ordering and the same redaction.
151
157
  */
152
158
  export function describeToolForApproval(args) {
153
- const safeArgs = args && typeof args === 'object' ? args : {};
159
+ const safeArgs = normalizeRecordArgs(args);
154
160
  const lines = [];
155
161
  for (const key of FALLBACK_KEYS) {
156
162
  const value = safeArgs[key];
157
163
  if (typeof value !== 'string' || value.length === 0)
158
164
  continue;
159
- lines.push(`${key}: ${safeDisplay(shortenHome(value))}`);
165
+ const cleaned = cleanSingleLine(shortenHome(value));
166
+ if (!cleaned)
167
+ continue;
168
+ lines.push(`${key}: ${cleaned}`);
160
169
  if (lines.length >= 4)
161
170
  break;
162
171
  }
@@ -164,7 +173,7 @@ export function describeToolForApproval(args) {
164
173
  try {
165
174
  const compact = JSON.stringify(safeArgs);
166
175
  if (compact && compact !== '{}')
167
- lines.push(safeDisplay(compact));
176
+ lines.push(cleanSingleLine(compact));
168
177
  }
169
178
  catch { /* nothing showable */ }
170
179
  }
@@ -142,8 +142,16 @@ function fallbackDisplay(toolName: string, args: Record<string, unknown>): ToolD
142
142
  *
143
143
  * Never throws: a display helper must not be able to break the transcript.
144
144
  */
145
+ function cleanSingleLine(text: string): string {
146
+ return safeDisplay(text).replace(/\s+/g, ' ').trim();
147
+ }
148
+
149
+ function normalizeRecordArgs(args?: Record<string, unknown> | null): Record<string, unknown> {
150
+ return args && typeof args === 'object' && !Array.isArray(args) ? args : {};
151
+ }
152
+
145
153
  export function describeTool(toolName?: string, args?: Record<string, unknown> | null): ToolDisplayResult {
146
- const safeArgs = args && typeof args === 'object' ? args : {};
154
+ const safeArgs = normalizeRecordArgs(args);
147
155
  const safeName = typeof toolName === 'string' ? toolName : '';
148
156
  let display: ToolDisplayResult;
149
157
 
@@ -155,9 +163,9 @@ export function describeTool(toolName?: string, args?: Record<string, unknown> |
155
163
  }
156
164
 
157
165
  return {
158
- verb: safeDisplay(display.verb || ''),
166
+ verb: cleanSingleLine(display.verb || ''),
159
167
  // Untrusted: an argument can carry escapes or a credential the model echoed.
160
- detail: safeDisplay(display.detail || '').replace(/\s+/g, ' ').trim()
168
+ detail: cleanSingleLine(display.detail || '')
161
169
  };
162
170
  }
163
171
 
@@ -171,20 +179,22 @@ export function hasCuratedDisplay(toolName: string): boolean {
171
179
  * row. Reuses the same ordering and the same redaction.
172
180
  */
173
181
  export function describeToolForApproval(args?: Record<string, unknown> | null): string[] {
174
- const safeArgs = args && typeof args === 'object' ? args : {};
182
+ const safeArgs = normalizeRecordArgs(args);
175
183
  const lines: string[] = [];
176
184
 
177
185
  for (const key of FALLBACK_KEYS) {
178
186
  const value = safeArgs[key];
179
187
  if (typeof value !== 'string' || value.length === 0) continue;
180
- lines.push(`${key}: ${safeDisplay(shortenHome(value))}`);
188
+ const cleaned = cleanSingleLine(shortenHome(value));
189
+ if (!cleaned) continue;
190
+ lines.push(`${key}: ${cleaned}`);
181
191
  if (lines.length >= 4) break;
182
192
  }
183
193
 
184
194
  if (lines.length === 0) {
185
195
  try {
186
196
  const compact = JSON.stringify(safeArgs);
187
- if (compact && compact !== '{}') lines.push(safeDisplay(compact));
197
+ if (compact && compact !== '{}') lines.push(cleanSingleLine(compact));
188
198
  } catch { /* nothing showable */ }
189
199
  }
190
200
  return lines;
@@ -100,8 +100,17 @@ function readSpillPreview(spillPath, maxBytes = 4096) {
100
100
  }
101
101
  }
102
102
  function extractSpillPathFromDecay(content) {
103
- const match = /\bat (\/[^\s]+)\s+—\s+read or search\b/.exec(content);
104
- return match?.[1];
103
+ const markerIndex = content.indexOf('— read or search');
104
+ if (markerIndex < 0)
105
+ return undefined;
106
+ const prefix = content.slice(0, markerIndex).trimEnd();
107
+ const atIndex = prefix.lastIndexOf(' at ');
108
+ if (atIndex < 0)
109
+ return undefined;
110
+ const candidate = prefix.slice(atIndex + 4).trim();
111
+ if (!candidate || candidate.includes('\n') || candidate.includes('\r'))
112
+ return undefined;
113
+ return candidate.startsWith('/') || /^[A-Za-z]:[\\/]/.test(candidate) ? candidate : undefined;
105
114
  }
106
115
  function recoverBrokenJsonOutput(raw, spillPath) {
107
116
  const prefixMatch = /^\s*\{\s*"success"\s*:\s*(true|false)\b/.exec(raw);
@@ -140,6 +149,10 @@ function recoverBrokenJsonOutput(raw, spillPath) {
140
149
  * `[decayed]` or shortened tool observations.
141
150
  */
142
151
  export function normalizeHistoricalToolResult(toolName, toolMsg, options = {}) {
152
+ if (!toolMsg || typeof toolMsg !== 'object') {
153
+ return { skipStep: false, result: { success: true, output: '' } };
154
+ }
155
+ const safeOptions = options && typeof options === 'object' ? options : {};
143
156
  const explicitSpill = typeof toolMsg.spillPath === 'string' && toolMsg.spillPath.trim()
144
157
  ? toolMsg.spillPath.trim()
145
158
  : undefined;
@@ -151,7 +164,7 @@ export function normalizeHistoricalToolResult(toolName, toolMsg, options = {}) {
151
164
  const success = !isFailure;
152
165
  if (toolName === 'update_plan') {
153
166
  return {
154
- skipStep: Boolean(options.unpaired),
167
+ skipStep: Boolean(safeOptions.unpaired),
155
168
  result: { success: true, output: '' }
156
169
  };
157
170
  }
@@ -134,8 +134,14 @@ function readSpillPreview(spillPath: string, maxBytes = 4096): string {
134
134
  }
135
135
 
136
136
  function extractSpillPathFromDecay(content: string): string | undefined {
137
- const match = /\bat (\/[^\s]+)\s+—\s+read or search\b/.exec(content);
138
- return match?.[1];
137
+ const markerIndex = content.indexOf('— read or search');
138
+ if (markerIndex < 0) return undefined;
139
+ const prefix = content.slice(0, markerIndex).trimEnd();
140
+ const atIndex = prefix.lastIndexOf(' at ');
141
+ if (atIndex < 0) return undefined;
142
+ const candidate = prefix.slice(atIndex + 4).trim();
143
+ if (!candidate || candidate.includes('\n') || candidate.includes('\r')) return undefined;
144
+ return candidate.startsWith('/') || /^[A-Za-z]:[\\/]/.test(candidate) ? candidate : undefined;
139
145
  }
140
146
 
141
147
  function recoverBrokenJsonOutput(raw: string, spillPath?: string | undefined): Record<string, unknown> | null {
@@ -179,6 +185,10 @@ export function normalizeHistoricalToolResult(
179
185
  toolMsg: HistoricalToolMessage,
180
186
  options: { unpaired?: boolean | undefined } = {}
181
187
  ): NormalizedHistoricalToolResult {
188
+ if (!toolMsg || typeof toolMsg !== 'object') {
189
+ return { skipStep: false, result: { success: true, output: '' } };
190
+ }
191
+ const safeOptions = options && typeof options === 'object' ? options : {};
182
192
  const explicitSpill = typeof toolMsg.spillPath === 'string' && toolMsg.spillPath.trim()
183
193
  ? toolMsg.spillPath.trim()
184
194
  : undefined;
@@ -191,7 +201,7 @@ export function normalizeHistoricalToolResult(
191
201
  const success = !isFailure;
192
202
  if (toolName === 'update_plan') {
193
203
  return {
194
- skipStep: Boolean(options.unpaired),
204
+ skipStep: Boolean(safeOptions.unpaired),
195
205
  result: { success: true, output: '' }
196
206
  };
197
207
  }
@@ -39,10 +39,10 @@ function normalizeRows(produced) {
39
39
  if (!Array.isArray(produced)) return [];
40
40
  const rows = [];
41
41
  for (const row of produced) {
42
- const text = row == null ? '' : String(row);
43
- // A frame may never contain a newline: the Stage paints with relative
44
- // cursor motion only, and one embedded '\n' would scroll the terminal out
45
- // from under the whole block. Split rather than drop, so nothing is lost.
42
+ const text = (row == null ? '' : String(row)).replace(/\r\n/g, '\n').replace(/\r/g, '\n');
43
+ // A frame may never contain a newline or carriage return: the Stage paints
44
+ // with relative cursor motion only, and an embedded '\n' or '\r' corrupts
45
+ // the terminal band. Split cleanly rather than drop, so nothing is lost.
46
46
  if (text.includes('\n')) rows.push(...text.split('\n'));
47
47
  else rows.push(text);
48
48
  }
@@ -50,9 +50,11 @@ function normalizeRows(produced) {
50
50
  }
51
51
 
52
52
  export class Transcript {
53
- constructor({ maxFrames = MAX_FRAMES, onEvict = null, onChange = null } = {}) {
53
+ constructor(options = {}) {
54
+ const { maxFrames = MAX_FRAMES, onEvict = null, onChange = null } =
55
+ options && typeof options === 'object' ? options : {};
54
56
  this.frames = [];
55
- this.maxFrames = Math.max(1, maxFrames);
57
+ this.maxFrames = Number.isFinite(maxFrames) ? Math.max(1, Math.floor(maxFrames)) : MAX_FRAMES;
56
58
  this.onEvict = typeof onEvict === 'function' ? onEvict : null;
57
59
  // Fired after any structural change. In scrollback mode the renderer's
58
60
  // onAfterWrite hook is what tells the prompt to repaint; in stage mode no
@@ -88,7 +90,9 @@ export class Transcript {
88
90
  * `produce` is called lazily and may be called again at a different width.
89
91
  * It must not mutate anything the caller will read later.
90
92
  */
91
- append({ kind = 'notice', produce, meta = null } = {}) {
93
+ append(options = {}) {
94
+ const { kind = 'notice', produce, meta = null } =
95
+ options && typeof options === 'object' ? options : {};
92
96
  if (typeof produce !== 'function') return null;
93
97
  const frame = {
94
98
  id: this.nextId++,
@@ -114,7 +118,9 @@ export class Transcript {
114
118
  * tokens arrive, and appending a frame per token would make the rail useless
115
119
  * and the flatten quadratic.
116
120
  */
117
- replaceTail({ kind, produce, meta } = {}) {
121
+ replaceTail(options = {}) {
122
+ const { kind, produce, meta } =
123
+ options && typeof options === 'object' ? options : {};
118
124
  const frame = this.frames[this.frames.length - 1];
119
125
  if (!frame || typeof produce !== 'function') return this.append({ kind, produce, meta });
120
126
  if (kind && KINDS.includes(kind)) frame.kind = kind;
@@ -189,7 +195,7 @@ export class Transcript {
189
195
  * unchanged transcript costs one comparison.
190
196
  */
191
197
  flatten(width) {
192
- const w = Math.max(1, Math.floor(width) || 1);
198
+ const w = Number.isFinite(width) && width > 0 ? Math.max(1, Math.floor(width)) : this.lastWidth;
193
199
  if (this.cache && this.cache.width === w && this.cache.revision === this.revision) {
194
200
  return this.cache;
195
201
  }