@causyne/agent 1.20.7 → 1.20.9

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 (42) hide show
  1. package/package.json +1 -1
  2. package/src/acp/agentCatalog.js +9 -3
  3. package/src/acp/agentCatalog.ts +20 -4
  4. package/src/agentLoop.js +167 -34
  5. package/src/agentLoop.ts +188 -37
  6. package/src/commands.js +25 -10
  7. package/src/compiledSkills.js +7330 -319
  8. package/src/computerUse/types.js +8 -0
  9. package/src/computerUse/types.ts +121 -0
  10. package/src/computerUse/visionGrounding.js +87 -29
  11. package/src/computerUse/visionGrounding.ts +108 -36
  12. package/src/decisionPolicy.js +7 -9
  13. package/src/decisionPolicy.ts +7 -9
  14. package/src/documentEngine/antiSlopAuditor.js +13 -43
  15. package/src/documentEngine/antiSlopAuditor.ts +15 -47
  16. package/src/documentEngine/documentForge.js +3 -3
  17. package/src/documentEngine/documentForge.ts +3 -3
  18. package/src/dynamicCatalogue.js +568 -77
  19. package/src/dynamicCatalogue.ts +608 -79
  20. package/src/launchIntent.js +3 -3
  21. package/src/launchIntent.ts +3 -3
  22. package/src/planCache.js +4 -14
  23. package/src/planCache.ts +4 -14
  24. package/src/providers/acp.js +39 -4
  25. package/src/providers/acp.ts +42 -4
  26. package/src/providers/antigravity.d.ts +7 -1
  27. package/src/providers/antigravity.js +222 -34
  28. package/src/providers/antigravity.ts +220 -33
  29. package/src/providers/base.d.ts +2 -0
  30. package/src/providers/pi.js +3 -1
  31. package/src/providers/pi.ts +4 -2
  32. package/src/sandbox.js +7 -10
  33. package/src/smartToolsUse.js +203 -0
  34. package/src/smartToolsUse.ts +263 -0
  35. package/src/taskShape.js +7 -7
  36. package/src/taskShape.ts +7 -7
  37. package/src/toolPacks.js +5 -5
  38. package/src/tools/blenderAutomator.js +198 -11
  39. package/src/tools/documentForge.js +1 -1
  40. package/src/tools/documentForge.ts +1 -1
  41. package/src/tui/modelPicker.js +288 -69
  42. package/src/tui/modelPicker.ts +333 -72
@@ -4,8 +4,12 @@
4
4
  // No shell, zero malware, source-available under BUSL-1.1.
5
5
  // @ts-expect-error untyped local TUI dialogs
6
6
  import { SelectLayer, InputLayer } from './dialogs.js';
7
+ // @ts-expect-error untyped local TUI theme
8
+ import { paint, bold, dim, GLYPHS } from './theme.js';
9
+ // @ts-expect-error untyped local TUI selectList
10
+ import { fuzzyFilter } from './selectList.js';
7
11
  import { loadConfig, saveConfig } from '../config.js';
8
- import { getAvailableProvidersOverview } from '../dynamicCatalogue.js';
12
+ import { getAvailableProvidersOverview, resolveAvailableProvidersOverview } from '../dynamicCatalogue.js';
9
13
  async function showConfiguringAnimation(providerLabel) {
10
14
  if (!process.stdout.isTTY)
11
15
  return;
@@ -20,92 +24,304 @@ async function showConfiguringAnimation(providerLabel) {
20
24
  }
21
25
  /**
22
26
  * Build items for SelectLayer categorized by ACP peers and BYOK providers.
27
+ *
28
+ * Supports tab filtering ('acp' | 'byok' | 'all') and smart pagination
29
+ * for ACP peers exceeding maxAcpPerPeer (default 10 models).
23
30
  */
24
- export function buildModelPickerItems(config, overview) {
31
+ export function buildModelPickerItems(config, overview, options = {}) {
25
32
  const items = [];
26
33
  const activeProvider = config.provider || '';
27
34
  const activeModel = config.model || '';
35
+ const tab = options.tab || 'all';
36
+ const expandedPeers = options.expandedPeers || new Set();
37
+ const maxAcp = typeof options.maxAcpPerPeer === 'number' ? options.maxAcpPerPeer : (tab === 'all' ? Infinity : 10);
28
38
  // 1. ACP Peer Agents & Sovereign Local Engines
29
- for (const peer of overview.acp) {
30
- const isCurrentProvider = activeProvider === peer.providerKey;
31
- const catTitle = peer.installed
32
- ? `ACP · ${peer.label} (ready)`
33
- : `ACP · ${peer.label} (not installed)`;
34
- if (peer.installed && Array.isArray(peer.models) && peer.models.length > 0) {
35
- for (const m of peer.models) {
36
- const isCurrent = isCurrentProvider && activeModel === m;
39
+ if (tab === 'all' || tab === 'acp') {
40
+ for (const peer of overview.acp) {
41
+ const isCurrentProvider = activeProvider === peer.providerKey;
42
+ const catTitle = peer.installed
43
+ ? `ACP · ${peer.label} (ready)`
44
+ : `ACP · ${peer.label} (not installed)`;
45
+ if (peer.installed && Array.isArray(peer.models) && peer.models.length > 0) {
46
+ const isExpanded = expandedPeers.has(peer.providerKey) || peer.models.length <= maxAcp;
47
+ const visibleModels = isExpanded ? peer.models : peer.models.slice(0, maxAcp);
48
+ for (const m of visibleModels) {
49
+ const isCurrent = isCurrentProvider && activeModel === m;
50
+ items.push({
51
+ id: `${peer.providerKey}/${m}`,
52
+ label: m,
53
+ category: catTitle,
54
+ description: isCurrent ? '● active' : 'ready',
55
+ value: {
56
+ type: 'acp',
57
+ providerId: peer.providerKey,
58
+ modelId: m,
59
+ providerLabel: peer.label,
60
+ installed: true,
61
+ isCurrent,
62
+ isConfigured: true,
63
+ setupInstruction: peer.setupInstruction
64
+ }
65
+ });
66
+ }
67
+ // Toggle item: Load more / Load less for peers with > maxAcp models
68
+ if (peer.models.length > maxAcp) {
69
+ if (!isExpanded) {
70
+ const remaining = peer.models.length - maxAcp;
71
+ items.push({
72
+ id: `${peer.providerKey}:__load_more__`,
73
+ label: `▶ Load more (${remaining} more models)...`,
74
+ category: catTitle,
75
+ description: 'expand',
76
+ value: {
77
+ type: 'toggle',
78
+ providerId: peer.providerKey,
79
+ modelId: '__load_more__',
80
+ providerLabel: peer.label,
81
+ installed: true,
82
+ isCurrent: false,
83
+ isConfigured: true,
84
+ isToggle: true,
85
+ action: 'expand',
86
+ peerKey: peer.providerKey
87
+ }
88
+ });
89
+ }
90
+ else {
91
+ items.push({
92
+ id: `${peer.providerKey}:__load_less__`,
93
+ label: `▲ Load less (show top ${maxAcp})...`,
94
+ category: catTitle,
95
+ description: 'collapse',
96
+ value: {
97
+ type: 'toggle',
98
+ providerId: peer.providerKey,
99
+ modelId: '__load_less__',
100
+ providerLabel: peer.label,
101
+ installed: true,
102
+ isCurrent: false,
103
+ isConfigured: true,
104
+ isToggle: true,
105
+ action: 'collapse',
106
+ peerKey: peer.providerKey
107
+ }
108
+ });
109
+ }
110
+ }
111
+ }
112
+ else {
113
+ // Uninstalled ACP agent: show entry so user can see it's supported
37
114
  items.push({
38
- id: `${peer.providerKey}/${m}`,
39
- label: m,
115
+ id: `${peer.providerKey}:uninstalled`,
116
+ label: peer.label,
40
117
  category: catTitle,
41
- description: isCurrent ? '● active' : 'ready',
118
+ description: 'not installed — setup needed',
42
119
  value: {
43
120
  type: 'acp',
44
121
  providerId: peer.providerKey,
45
- modelId: m,
122
+ modelId: peer.models[0] || peer.id,
46
123
  providerLabel: peer.label,
124
+ installed: false,
125
+ isCurrent: false,
126
+ isConfigured: false,
127
+ setupInstruction: peer.setupInstruction
128
+ }
129
+ });
130
+ }
131
+ }
132
+ }
133
+ // 2. BYOK Providers (Cloud & Local APIs)
134
+ if (tab === 'all' || tab === 'byok') {
135
+ for (const p of overview.byok) {
136
+ const isCurrentProvider = activeProvider === p.id || (p.id === 'qwen' && activeProvider === 'dashscope-byok');
137
+ const catTitle = p.id === 'ollama'
138
+ ? `BYOK · ${p.label}`
139
+ : `BYOK · ${p.label} ${p.isConfigured ? '(configured)' : '(needs key)'}`;
140
+ const models = Array.isArray(p.models) && p.models.length > 0 ? p.models : [p.defaultModel];
141
+ for (const m of models) {
142
+ const isCurrent = isCurrentProvider && activeModel === m;
143
+ const desc = isCurrent ? '● active' : (p.id === 'ollama' ? 'local' : (p.isConfigured ? 'configured' : 'needs API key'));
144
+ items.push({
145
+ id: `${p.id}/${m}`,
146
+ label: m,
147
+ category: catTitle,
148
+ description: desc,
149
+ value: {
150
+ type: 'byok',
151
+ providerId: p.id,
152
+ modelId: m,
153
+ providerLabel: p.label,
47
154
  installed: true,
48
155
  isCurrent,
49
- isConfigured: true,
50
- setupInstruction: peer.setupInstruction
156
+ isConfigured: p.isConfigured,
157
+ envVar: p.envVar
51
158
  }
52
159
  });
53
160
  }
54
161
  }
55
- else {
56
- // Uninstalled ACP agent: show entry so user can see it's supported
57
- items.push({
58
- id: `${peer.providerKey}:uninstalled`,
59
- label: peer.label,
60
- category: catTitle,
61
- description: 'not installed — setup needed',
62
- value: {
63
- type: 'acp',
64
- providerId: peer.providerKey,
65
- modelId: peer.models[0] || peer.id,
66
- providerLabel: peer.label,
67
- installed: false,
68
- isCurrent: false,
69
- isConfigured: false,
70
- setupInstruction: peer.setupInstruction
71
- }
162
+ }
163
+ return items;
164
+ }
165
+ /**
166
+ * Sovereign Model Picker Layer with dual-tab support (| ACP | BYOK |)
167
+ * and interactive 10-model pagination.
168
+ */
169
+ export class ModelPickerLayer extends SelectLayer {
170
+ activeTab;
171
+ config;
172
+ overview;
173
+ expandedPeers;
174
+ promptHost;
175
+ allItems;
176
+ constructor(options) {
177
+ const activeProvider = (options.config.provider || '').toLowerCase().trim();
178
+ const initialTab = activeProvider === 'antigravity' ||
179
+ activeProvider === 'agy' ||
180
+ activeProvider === 'acp' ||
181
+ activeProvider.startsWith('acp/')
182
+ ? 'acp'
183
+ : 'byok';
184
+ const expandedPeers = new Set();
185
+ const allItems = buildModelPickerItems(options.config, options.overview, { tab: 'all', maxAcpPerPeer: Infinity });
186
+ super({
187
+ title: 'Select Model',
188
+ placeholder: 'type to filter (e.g. gemini, sonnet, opencode)…',
189
+ emptyText: 'No models matched your search in this tab',
190
+ items: allItems,
191
+ width: 78,
192
+ height: 22,
193
+ footer: 'tab / ← → switch tab • enter select • esc close',
194
+ onPick: options.onPick
195
+ });
196
+ this.config = options.config;
197
+ this.overview = options.overview;
198
+ this.promptHost = options.promptHost;
199
+ this.activeTab = initialTab;
200
+ this.expandedPeers = expandedPeers;
201
+ this.allItems = allItems;
202
+ // Custom refilter ensuring list renders only activeTab while keeping allItems intact
203
+ const self = this;
204
+ this.list.refilter = function () {
205
+ const isSearching = Boolean(this.query && this.query.trim());
206
+ const tabItems = buildModelPickerItems(self.config, self.overview, {
207
+ tab: self.activeTab,
208
+ expandedPeers: self.expandedPeers,
209
+ maxAcpPerPeer: isSearching ? Infinity : 10
72
210
  });
211
+ this.filtered = fuzzyFilter(tabItems, this.query);
212
+ this.selected = Math.min(this.selected || 0, Math.max(0, this.filtered.length - 1));
213
+ this.offset = 0;
214
+ return this;
215
+ };
216
+ // Initialize list with active tab items
217
+ this.list.refilter();
218
+ }
219
+ updateOverview(freshOverview) {
220
+ this.overview = freshOverview;
221
+ this.allItems = buildModelPickerItems(this.config, this.overview, { tab: 'all', maxAcpPerPeer: Infinity });
222
+ this.list.all = this.allItems;
223
+ this.list.refilter();
224
+ if (this.promptHost && typeof this.promptHost.scheduleDraw === 'function') {
225
+ this.promptHost.scheduleDraw();
73
226
  }
74
227
  }
75
- // 2. BYOK Providers (Cloud & Local APIs)
76
- for (const p of overview.byok) {
77
- const isCurrentProvider = activeProvider === p.id || (p.id === 'qwen' && activeProvider === 'dashscope-byok');
78
- const catTitle = p.id === 'ollama'
79
- ? `BYOK · ${p.label}`
80
- : `BYOK · ${p.label} ${p.isConfigured ? '(configured)' : '(needs key)'}`;
81
- const models = Array.isArray(p.models) && p.models.length > 0 ? p.models : [p.defaultModel];
82
- for (const m of models) {
83
- const isCurrent = isCurrentProvider && activeModel === m;
84
- const desc = isCurrent ? '● active' : (p.id === 'ollama' ? 'local' : (p.isConfigured ? 'configured' : 'needs API key'));
85
- items.push({
86
- id: `${p.id}/${m}`,
87
- label: m,
88
- category: catTitle,
89
- description: desc,
90
- value: {
91
- type: 'byok',
92
- providerId: p.id,
93
- modelId: m,
94
- providerLabel: p.label,
95
- installed: true,
96
- isCurrent,
97
- isConfigured: p.isConfigured,
98
- envVar: p.envVar
99
- }
100
- });
228
+ switchTab(tab) {
229
+ if (this.activeTab === tab)
230
+ return;
231
+ this.activeTab = tab;
232
+ this.list.refilter();
233
+ this.list.selected = 0;
234
+ this.list.offset = 0;
235
+ if (this.promptHost && typeof this.promptHost.scheduleDraw === 'function') {
236
+ this.promptHost.scheduleDraw();
101
237
  }
102
238
  }
103
- return items;
239
+ togglePeerExpand(peerKey) {
240
+ if (this.expandedPeers.has(peerKey)) {
241
+ this.expandedPeers.delete(peerKey);
242
+ }
243
+ else {
244
+ this.expandedPeers.add(peerKey);
245
+ }
246
+ const currentId = this.list.current?.id;
247
+ this.list.refilter();
248
+ if (currentId && Array.isArray(this.list.filtered)) {
249
+ const idx = this.list.filtered.findIndex((entry) => entry?.item?.id === currentId || entry?.item?.value?.peerKey === peerKey);
250
+ if (idx >= 0)
251
+ this.list.selected = idx;
252
+ }
253
+ if (this.promptHost && typeof this.promptHost.scheduleDraw === 'function') {
254
+ this.promptHost.scheduleDraw();
255
+ }
256
+ }
257
+ preferredHeight() {
258
+ const categories = new Set(this.list.filtered.map((entry) => entry.item?.category).filter(Boolean));
259
+ return 2 + 2 + this.list.filtered.length + categories.size + 2;
260
+ }
261
+ body(width, height) {
262
+ const tabACP = this.activeTab === 'acp' ? paint('accent', bold('● ACP')) : dim('ACP');
263
+ const tabBYOK = this.activeTab === 'byok' ? paint('accent', bold('● BYOK')) : dim('BYOK');
264
+ const tabBar = ` | ${tabACP} | ${tabBYOK} | ${dim('(Tab / ← → switch tab)')}`;
265
+ const separator = paint('rule', GLYPHS.hLine.repeat(Math.max(4, width)));
266
+ const listHeight = Math.max(1, height - 2);
267
+ const { rows } = this.list.render(width, listHeight);
268
+ this.cursor = { x: this.list.cursorColumn(), y: 2 };
269
+ return [tabBar, separator, ...rows];
270
+ }
271
+ key(event) {
272
+ if (!event)
273
+ return null;
274
+ // 1. Tab switching via Tab, Left/Right arrows, or PgLeft/PgRight mappings
275
+ if (event.name === 'tab') {
276
+ this.switchTab(this.activeTab === 'acp' ? 'byok' : 'acp');
277
+ return 'handled';
278
+ }
279
+ if (event.name === 'left' && this.activeTab === 'byok') {
280
+ if (!this.list.query || event.alt || event.ctrl || event.meta) {
281
+ this.switchTab('acp');
282
+ return 'handled';
283
+ }
284
+ }
285
+ if (event.name === 'right' && this.activeTab === 'acp') {
286
+ if (!this.list.query || event.alt || event.ctrl || event.meta) {
287
+ this.switchTab('byok');
288
+ return 'handled';
289
+ }
290
+ }
291
+ if (event.name === '[' || (event.name === 'pageup' && (event.shift || event.alt || event.ctrl))) {
292
+ this.switchTab('acp');
293
+ return 'handled';
294
+ }
295
+ if (event.name === ']' || (event.name === 'pagedown' && (event.shift || event.alt || event.ctrl))) {
296
+ this.switchTab('byok');
297
+ return 'handled';
298
+ }
299
+ // 2. Delegate to SelectList for navigation / query typing
300
+ const visibleRows = this.list.lastItemRows || Math.max(1, this.height - 7);
301
+ const action = this.list.handleKey(event, visibleRows);
302
+ if (action === 'select') {
303
+ const item = this.list.current;
304
+ if (item?.value?.isToggle && item?.value?.peerKey) {
305
+ this.togglePeerExpand(item.value.peerKey);
306
+ return 'handled';
307
+ }
308
+ this.settled = true;
309
+ const result = this.onPick ? this.onPick(item) : null;
310
+ if (result === 'keep')
311
+ this.settled = false;
312
+ return result === 'keep' ? 'handled' : 'close';
313
+ }
314
+ if (action === 'cancel')
315
+ return 'close';
316
+ return action ? 'handled' : null;
317
+ }
104
318
  }
105
319
  /**
106
320
  * Run interactive model picker in the provided TUI prompt.
107
321
  *
108
322
  * Automatically handles:
323
+ * - Dual-tab navigation (| ACP | BYOK |).
324
+ * - Smart 10-model pagination per ACP peer with in-place Load more / Load less.
109
325
  * - Direct selection of ACP models without prompting for an API key.
110
326
  * - Direct selection of configured BYOK models without prompting for an API key.
111
327
  * - InputLayer modal prompt for API key when selecting an unconfigured BYOK model,
@@ -118,18 +334,21 @@ export async function runInteractiveModelPicker(prompt, store = { loadConfig, sa
118
334
  }
119
335
  const config = store.loadConfig();
120
336
  const overview = getAvailableProvidersOverview(config);
121
- const items = buildModelPickerItems(config, overview);
122
337
  const picked = await new Promise((resolve) => {
123
- const layer = new SelectLayer({
124
- title: 'Select Model',
125
- placeholder: 'type to filter (e.g. gemini, sonnet, opencode)…',
126
- emptyText: 'No models matched your search',
127
- items,
128
- width: 76,
129
- height: 20,
338
+ const layer = new ModelPickerLayer({
339
+ config,
340
+ overview,
341
+ promptHost: prompt,
130
342
  onPick: resolve
131
343
  });
132
344
  prompt.openLayer(layer);
345
+ if (!process.env.NODE_TEST_CONTEXT) {
346
+ void resolveAvailableProvidersOverview(config).then((freshOverview) => {
347
+ if (layer.settled)
348
+ return;
349
+ layer.updateOverview(freshOverview);
350
+ }).catch(() => { });
351
+ }
133
352
  });
134
353
  const notifyPrompt = (providerId, modelId) => {
135
354
  if (typeof prompt.updateModel === 'function') {
@@ -141,7 +360,7 @@ export async function runInteractiveModelPicker(prompt, store = { loadConfig, sa
141
360
  prompt.scheduleDraw();
142
361
  }
143
362
  };
144
- if (!picked || !picked.value) {
363
+ if (!picked || !picked.value || picked.value.isToggle) {
145
364
  return 'Cancelled. Model was not changed.';
146
365
  }
147
366
  const target = picked.value;