@causyne/agent 1.20.117 → 1.20.120

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 (82) hide show
  1. package/package.json +7 -2
  2. package/src/agentLoop.js +29 -12
  3. package/src/agentLoop.ts +29 -16
  4. package/src/browser/causyneBrowser.js +231 -136
  5. package/src/browser/causyneBrowser.ts +229 -140
  6. package/src/browser/searchProviders.js +41 -30
  7. package/src/browser/searchProviders.ts +24 -14
  8. package/src/browser/workspacePathSafety.js +50 -0
  9. package/src/browser/workspacePathSafety.ts +50 -0
  10. package/src/browser/workspacePreview.js +27 -4
  11. package/src/browser/workspacePreview.ts +28 -4
  12. package/src/cliMode.js +20 -4
  13. package/src/commands.js +12 -14
  14. package/src/creative/liveBridge.js +34 -1
  15. package/src/creative/liveBridge.ts +28 -1
  16. package/src/observer/evidence.js +23 -0
  17. package/src/observer/evidence.ts +21 -0
  18. package/src/plugins/pluginManager.js +74 -0
  19. package/src/providers/anthropic.js +33 -17
  20. package/src/providers/base.js +14 -0
  21. package/src/providers/dashscope-byok.js +13 -7
  22. package/src/providers/deepseek.js +13 -18
  23. package/src/providers/gemini.js +33 -25
  24. package/src/providers/moonshot.js +13 -12
  25. package/src/providers/ollama.js +21 -21
  26. package/src/providers/openai-compatible.js +12 -19
  27. package/src/providers/openrouter.js +20 -90
  28. package/src/providers/openrouter.ts +31 -94
  29. package/src/providers/qwen-byok.js +13 -7
  30. package/src/providers/toolContracts.js +9 -3
  31. package/src/providers/toolContracts.ts +9 -3
  32. package/src/providers/wireNormalizer.js +238 -0
  33. package/src/providers/wireNormalizer.ts +279 -0
  34. package/src/providers/xai.js +13 -12
  35. package/src/reporting.js +12 -4
  36. package/src/skillsManager.js +3 -2
  37. package/src/skillsManager.ts +3 -2
  38. package/src/tools/browserAutomator.js +13 -1
  39. package/src/tools/browserAutomator.ts +13 -0
  40. package/src/tools/creativeApps.js +2 -1
  41. package/src/tools/creativeApps.ts +2 -1
  42. package/src/tools/gameAssetFetcher.js +130 -26
  43. package/src/tools/gameAssetHarvester.js +80 -58
  44. package/src/tools/nativeEngine.js +1 -1
  45. package/src/tools/nativeEngine.ts +1 -1
  46. package/src/tools/pluginManager.js +17 -2
  47. package/src/tools/registry.js +13 -0
  48. package/src/tools/toolScanner.js +596 -140
  49. package/src/tools/toolScanner.ts +665 -147
  50. package/src/tools/toolSelfRepair.js +243 -114
  51. package/src/tools/toolSelfRepair.ts +262 -111
  52. package/src/tools/webFetch.js +161 -24
  53. package/src/tools/webFetch.ts +157 -22
  54. package/src/tools/webSearch.js +33 -4
  55. package/src/tools/webSearch.ts +27 -4
  56. package/src/tui/composerControls.js +16 -3
  57. package/src/tui/composerControls.ts +14 -3
  58. package/src/tui/prompt.js +122 -16
  59. package/src/tui/sessionPicker.js +132 -35
  60. package/src/tui/sessionPicker.ts +153 -32
  61. package/src/tui/sessionPickerView.js +277 -34
  62. package/src/tui/sessionPickerView.ts +328 -34
  63. package/src/tui/statusLine.js +3 -0
  64. package/src/tui/statusLine.ts +5 -0
  65. package/src/tui/usageCard.js +119 -47
  66. package/src/tui/usageCard.ts +133 -49
  67. package/src/tui/workspaceIdentity.js +133 -0
  68. package/src/tui/workspaceIdentity.ts +146 -0
  69. package/src/tui/workspaceSwitch.js +2 -0
  70. package/src/tui/workspaceSwitch.ts +1 -0
  71. package/src/verification/boundedExplorer.js +119 -0
  72. package/src/verification/cliProbe.js +116 -0
  73. package/src/verification/featureMap.js +78 -0
  74. package/src/verification/interactivePty.js +188 -0
  75. package/src/verification/propertyProbe.js +121 -0
  76. package/src/verification/ptyProbe.js +125 -0
  77. package/src/verification/skillCatalog.d.ts +1 -0
  78. package/src/verification/skillCatalog.js +60 -0
  79. package/src/verification/statechart.js +143 -0
  80. package/src/verification/uiRuntime.js +57 -0
  81. package/src/verificationPlan.js +1 -1
  82. package/src/verificationPlan.ts +1 -1
@@ -3,6 +3,12 @@
3
3
  // Source-available under BUSL-1.1.
4
4
 
5
5
  import { SessionPickerLayer } from './sessionPickerView.js';
6
+ import {
7
+ sameWorkspace,
8
+ shortenWorkspacePath,
9
+ workspaceDisplayName,
10
+ formatWorkspaceSectionTitle
11
+ } from './workspaceIdentity.js';
6
12
  // @ts-expect-error untyped local TUI theme
7
13
  import { GLYPHS } from './theme.js';
8
14
  import { safeDisplay } from './text.js';
@@ -31,10 +37,13 @@ export interface SessionPickerItemValue {
31
37
  isCurrent?: boolean | undefined;
32
38
  }
33
39
 
40
+ export type SessionPickerSection = 'actions' | 'workspace' | 'all';
41
+
34
42
  export interface SessionPickerItem {
35
43
  id: string;
36
44
  label: string;
37
45
  category: string;
46
+ section?: SessionPickerSection | undefined;
38
47
  description: string;
39
48
  searchText?: string;
40
49
  value: SessionPickerItemValue;
@@ -42,6 +51,7 @@ export interface SessionPickerItem {
42
51
 
43
52
  export interface InteractiveSessionPickerOptions {
44
53
  loop?: {
54
+ workspaceRoot?: string | undefined;
45
55
  taskId?: string;
46
56
  messages?: Array<{ role: string; content?: unknown }>;
47
57
  tokenTracker?: { reset?: () => void; sessionTokens?: number };
@@ -87,18 +97,24 @@ function dateGroup(timestamp: number): string {
87
97
  return date.toDateString() === yesterday.toDateString() ? 'Yesterday' : date.toDateString();
88
98
  }
89
99
 
90
- function shortenPath(p: string | undefined): string {
91
- if (!p) return '(default)';
92
- const home = process.env.HOME || '';
93
- if (home && p.startsWith(home)) {
94
- return '~' + p.slice(home.length);
95
- }
96
- return p.split('/').pop() || p;
100
+ function compareSessionsByDate(
101
+ a: { updatedAt: number },
102
+ b: { updatedAt: number }
103
+ ): number {
104
+ const aValid = Number.isFinite(a.updatedAt);
105
+ const bValid = Number.isFinite(b.updatedAt);
106
+ if (!aValid && !bValid) return 0;
107
+ if (!aValid) return 1;
108
+ if (!bValid) return -1;
109
+ return b.updatedAt === a.updatedAt ? 0 : b.updatedAt > a.updatedAt ? 1 : -1;
97
110
  }
98
111
 
99
112
  /**
100
113
  * Build item list for SelectLayer modal.
101
- * The top item is always "+ New Session" to guarantee clean separation and quick reset.
114
+ * Ordering:
115
+ * 1. Pinned Actions (`+ New Session`, optional `Fork Current Session`)
116
+ * 2. Current workspace sessions (sorted newest-first and grouped by date)
117
+ * 3. All other sessions (sorted newest-first and grouped by date, strictly deduplicated)
102
118
  */
103
119
  export function buildSessionPickerItems(
104
120
  sessions: Array<Omit<SessionRecord, 'messages'> & { messageCount: number }>,
@@ -106,14 +122,17 @@ export function buildSessionPickerItems(
106
122
  currentWorkspace: string
107
123
  ): SessionPickerItem[] {
108
124
  const items: SessionPickerItem[] = [];
125
+ const canonicalCache = new Map<string, string>();
126
+ const currentWsName = workspaceDisplayName(currentWorkspace, canonicalCache);
109
127
 
110
128
  // Pinned item 0: Create new clean conversation
111
129
  items.push({
112
130
  id: '__NEW_SESSION__',
113
131
  label: '+ New Session (Start fresh conversation)',
114
132
  category: 'Actions',
115
- description: 'Begin a clean session in this workspace without previous context',
116
- searchText: 'new session fresh clear reset start',
133
+ section: 'actions',
134
+ description: `Begin a clean session in ${currentWsName} without previous context`,
135
+ searchText: `new session fresh clear reset start ${currentWsName}`,
117
136
  value: {
118
137
  type: 'new'
119
138
  }
@@ -128,6 +147,7 @@ export function buildSessionPickerItems(
128
147
  id: '__FORK_SESSION__',
129
148
  label: `Branch / Fork Current Session ("${activeTitle}")`,
130
149
  category: 'Actions',
150
+ section: 'actions',
131
151
  description: 'Copy conversation history into a new branch without copying permissions',
132
152
  searchText: 'fork branch clone copy session fresh permissions',
133
153
  value: {
@@ -139,37 +159,38 @@ export function buildSessionPickerItems(
139
159
  }
140
160
  }
141
161
 
142
- const sortedSessions = [...sessions].sort((a, b) => {
143
- const aValid = Number.isFinite(a.updatedAt);
144
- const bValid = Number.isFinite(b.updatedAt);
145
- if (!aValid && !bValid) return 0;
146
- if (!aValid) return 1;
147
- if (!bValid) return -1;
148
- return b.updatedAt === a.updatedAt ? 0 : b.updatedAt > a.updatedAt ? 1 : -1;
149
- });
162
+ const sortedSessions = [...sessions].sort(compareSessionsByDate);
163
+ const seenIds = new Set<string>();
164
+ const workspaceItems: SessionPickerItem[] = [];
165
+ const otherItems: SessionPickerItem[] = [];
150
166
 
151
167
  for (const s of sortedSessions) {
168
+ if (!s || typeof s.id !== 'string' || !s.id || seenIds.has(s.id)) continue;
152
169
  // A session without any turns has no conversation to resume. Keep the
153
170
  // active one available, but do not fill the picker with abandoned starts.
154
171
  const safeMessageCount = Number.isFinite(s.messageCount) ? Math.max(0, Math.floor(s.messageCount)) : 0;
155
172
  if (safeMessageCount === 0 && s.id !== activeId) continue;
173
+ seenIds.add(s.id);
174
+
156
175
  const isCurrent = s.id === activeId;
176
+ const inCurrentWorkspace = sameWorkspace(s.workspace, currentWorkspace, canonicalCache);
157
177
  const timeAgo = formatTimeAgo(s.updatedAt);
158
- const wsLabel = shortenPath(s.workspace);
178
+ const wsLabel = shortenWorkspacePath(s.workspace);
179
+ const wsName = s.workspace ? workspaceDisplayName(s.workspace, canonicalCache) : '';
159
180
  const msgCount = `${safeMessageCount} msg${safeMessageCount === 1 ? '' : 's'}`;
160
-
161
181
  const category = dateGroup(s.updatedAt);
162
182
 
163
183
  const mark = isCurrent ? `● ` : ` `;
164
184
  const tag = isCurrent ? ` [active]` : '';
165
185
  const title = cleanTitle(s.title);
166
186
 
167
- items.push({
187
+ const pickerItem: SessionPickerItem = {
168
188
  id: s.id,
169
189
  label: `${mark}${title}${tag}`,
170
190
  category,
171
- description: `${msgCount} ${GLYPHS.dot} ${timeAgo} ${GLYPHS.dot} ${wsLabel}${s.workspace === currentWorkspace ? ' (current)' : ''}`,
172
- searchText: `${title} ${s.id} ${s.workspace || ''} ${category}`,
191
+ section: inCurrentWorkspace ? 'workspace' : 'all',
192
+ description: `${msgCount} ${GLYPHS.dot} ${timeAgo} ${GLYPHS.dot} ${wsLabel}${inCurrentWorkspace ? ' (current)' : ''}`,
193
+ searchText: `${title} ${s.id} ${s.workspace || ''} ${wsName} ${category}`,
173
194
  value: {
174
195
  type: 'switch',
175
196
  id: s.id,
@@ -179,12 +200,98 @@ export function buildSessionPickerItems(
179
200
  updatedAt: s.updatedAt,
180
201
  isCurrent
181
202
  }
182
- });
203
+ };
204
+
205
+ if (inCurrentWorkspace) {
206
+ workspaceItems.push(pickerItem);
207
+ } else {
208
+ otherItems.push(pickerItem);
209
+ }
183
210
  }
184
211
 
212
+ items.push(...workspaceItems, ...otherItems);
185
213
  return items;
186
214
  }
187
215
 
216
+ /**
217
+ * Format a plain-text `/sessions` report (for non-interactive or piped output)
218
+ * with the current workspace section first (or Empty) and deduplicated All Sessions below.
219
+ */
220
+ export function formatSessionsTextReport(
221
+ sessions: Array<Omit<SessionRecord, 'messages'> & { messageCount: number }>,
222
+ activeId: string | null,
223
+ currentWorkspace: string,
224
+ limit = 20
225
+ ): string {
226
+ const canonicalCache = new Map<string, string>();
227
+ const sorted = [...sessions].sort(compareSessionsByDate);
228
+ const seenIds = new Set<string>();
229
+ const workspaceRows: Array<Omit<SessionRecord, 'messages'> & { messageCount: number }> = [];
230
+ const otherRows: Array<Omit<SessionRecord, 'messages'> & { messageCount: number }> = [];
231
+
232
+ for (const s of sorted) {
233
+ if (!s || typeof s.id !== 'string' || !s.id || seenIds.has(s.id)) continue;
234
+ seenIds.add(s.id);
235
+ if (sameWorkspace(s.workspace, currentWorkspace, canonicalCache)) {
236
+ workspaceRows.push(s);
237
+ } else {
238
+ otherRows.push(s);
239
+ }
240
+ }
241
+
242
+ const formatRow = (s: Omit<SessionRecord, 'messages'> & { messageCount: number }): string => {
243
+ const when = Number.isFinite(s.updatedAt)
244
+ ? new Date(s.updatedAt).toISOString().slice(0, 16).replace('T', ' ')
245
+ : 'unknown date';
246
+ const where = s.workspace ? shortenWorkspacePath(s.workspace) : '(no workspace)';
247
+ const mark = s.id === activeId ? '*' : ' ';
248
+ const count = Number.isFinite(s.messageCount) ? Math.max(0, Math.floor(s.messageCount)) : 0;
249
+ return ` ${mark} ${s.id} ${when} ${String(count).padStart(4)} msg ${where}\n ${cleanTitle(s.title)}`;
250
+ };
251
+
252
+ const totalCount = workspaceRows.length + otherRows.length;
253
+ const maxShown = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : 20;
254
+ const lines: string[] = [
255
+ `${totalCount} session${totalCount === 1 ? '' : 's'} (* = active):`,
256
+ '',
257
+ `${formatWorkspaceSectionTitle(currentWorkspace, workspaceRows.length, canonicalCache)} (${shortenWorkspacePath(currentWorkspace)}):`
258
+ ];
259
+
260
+ let remaining = maxShown;
261
+ if (workspaceRows.length === 0) {
262
+ lines.push(' Empty — no sessions in this workspace yet');
263
+ } else {
264
+ let lastDate: string | null = null;
265
+ for (const row of workspaceRows.slice(0, remaining)) {
266
+ const group = dateGroup(row.updatedAt);
267
+ if (group !== lastDate) {
268
+ lines.push(` [${group}]`);
269
+ lastDate = group;
270
+ }
271
+ lines.push(formatRow(row));
272
+ }
273
+ remaining = Math.max(0, remaining - workspaceRows.length);
274
+ }
275
+
276
+ if (otherRows.length > 0 && remaining > 0) {
277
+ lines.push('');
278
+ lines.push(`ALL SESSIONS (${otherRows.length}):`);
279
+ let lastDate: string | null = null;
280
+ for (const row of otherRows.slice(0, remaining)) {
281
+ const group = dateGroup(row.updatedAt);
282
+ if (group !== lastDate) {
283
+ lines.push(` [${group}]`);
284
+ lastDate = group;
285
+ }
286
+ lines.push(formatRow(row));
287
+ }
288
+ }
289
+
290
+ lines.push('');
291
+ lines.push('Switch with /sessions switch <id>, fork with /fork [id], or run /sessions to open interactive modal picker.');
292
+ return lines.join('\n');
293
+ }
294
+
188
295
  /**
189
296
  * Launch the interactive Session Picker modal.
190
297
  * Single Enter switches session or creates a new one immediately.
@@ -192,6 +299,7 @@ export function buildSessionPickerItems(
192
299
  export async function runInteractiveSessionPicker(
193
300
  prompt: {
194
301
  openLayer: (layer: unknown) => void;
302
+ root?: string | undefined;
195
303
  editor?: { clear: () => void };
196
304
  scheduleDraw?: () => void;
197
305
  updateModel?: (provider?: string, model?: string) => void;
@@ -199,9 +307,12 @@ export async function runInteractiveSessionPicker(
199
307
  },
200
308
  options: InteractiveSessionPickerOptions = {}
201
309
  ): Promise<string> {
202
- const workspace = options.workspace || process.cwd();
310
+ const workspace = options.workspace
311
+ || options.loop?.workspaceRoot
312
+ || prompt.root
313
+ || process.cwd();
203
314
  const sessions = listSessions();
204
- const activeId = getActiveSessionId();
315
+ const activeId = options.loop?.memoryManager?.sessionId || getActiveSessionId();
205
316
 
206
317
  const items = buildSessionPickerItems(sessions, activeId, workspace);
207
318
 
@@ -221,11 +332,21 @@ export async function runInteractiveSessionPicker(
221
332
  resolve(item || null);
222
333
  }
223
334
  });
224
- // Opening the picker should highlight a conversation, not an action that
225
- // creates a new one. Actions remain available above the dated list.
226
- const selected = items.findIndex(item => item.id === activeId);
227
- const firstConversation = items.findIndex(item => item.value.type === 'switch');
228
- layer.list.moveTo(selected >= 0 ? selected : Math.max(0, firstConversation), 15);
335
+ // Prefer the active session when it belongs to the current workspace,
336
+ // otherwise the newest conversation in the current workspace. When the
337
+ // current workspace is empty, keep focus at index 0 (+ New Session) so the
338
+ // workspace header and Empty indicator remain immediately visible on open.
339
+ const ordered = layer.list.all;
340
+ const activeWorkspaceIdx = ordered.findIndex(
341
+ item => item.section === 'workspace' && item.id === activeId
342
+ );
343
+ const firstWorkspaceIdx = ordered.findIndex(item => item.section === 'workspace');
344
+ const initialIndex = activeWorkspaceIdx >= 0
345
+ ? activeWorkspaceIdx
346
+ : firstWorkspaceIdx >= 0
347
+ ? firstWorkspaceIdx
348
+ : 0;
349
+ layer.list.moveTo(initialIndex, 15);
229
350
  prompt.openLayer(layer);
230
351
  });
231
352
 
@@ -294,7 +415,7 @@ export async function runInteractiveSessionPicker(
294
415
  syncSessionSurface(newSession, []);
295
416
 
296
417
  cleanPrompt();
297
- return `Started new session: "${cleanTitle(newSession.title)}" (${newSession.id}) in ${shortenPath(workspace)}.`;
418
+ return `Started new session: "${cleanTitle(newSession.title)}" (${newSession.id}) in ${shortenWorkspacePath(workspace)}.`;
298
419
  }
299
420
 
300
421
  // Case 2: Fork session into a new branch without copying permissions