@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.
- package/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +153 -68
- package/src/agentLoop.ts +152 -71
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +37 -9
- package/src/browser/causyneBrowser.ts +37 -9
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/cliMode.js +5 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/memory/scopedFacts.js +171 -0
- package/src/memory/scopedFacts.ts +214 -0
- package/src/memory.d.ts +13 -1
- package/src/memory.js +9 -12
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/perception.js +124 -3
- package/src/perception.ts +128 -4
- package/src/planCache.js +17 -3
- package/src/planCache.ts +17 -3
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/smartToolsUse.js +4 -5
- package/src/smartToolsUse.ts +4 -6
- package/src/taskShape.js +49 -7
- package/src/taskShape.ts +55 -7
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/toolPacks.js +27 -5
- package/src/toolPacks.ts +32 -5
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/memoryWrite.js +8 -10
- package/src/tools/memoryWrite.ts +13 -11
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +139 -84
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +60 -28
- package/src/tui/codeProgress.ts +60 -27
- package/src/tui/codeStreamRenderer.js +94 -23
- package/src/tui/codeStreamRenderer.ts +92 -23
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +36 -18
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +186 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +232 -51
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +176 -80
- package/src/tui/turnRail.ts +173 -71
- package/src/tui/usageCard.js +136 -80
- package/src/tui/usageCard.ts +145 -103
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
- package/src/types/contracts.ts +3 -0
package/src/tui/modelPicker.js
CHANGED
|
@@ -11,6 +11,7 @@ import { fuzzyFilter } from './selectList.js';
|
|
|
11
11
|
import { loadConfig, saveConfig } from '../config.js';
|
|
12
12
|
import { startLoopbackAuth, saveOpenRouterKey, disconnectOpenRouter } from '../auth/openrouterAuth.js';
|
|
13
13
|
import { setTransientNotice } from './consoleGuard.js';
|
|
14
|
+
import { truncate } from './text.js';
|
|
14
15
|
import { getAvailableProvidersOverview, resolveAvailableProvidersOverview, resolveAvailableModels } from '../dynamicCatalogue.js';
|
|
15
16
|
async function showConfiguringAnimation(providerLabel, promptHost) {
|
|
16
17
|
if (promptHost && typeof promptHost.scheduleDraw === 'function') {
|
|
@@ -33,14 +34,26 @@ async function showConfiguringAnimation(providerLabel, promptHost) {
|
|
|
33
34
|
*/
|
|
34
35
|
export function buildModelPickerItems(config, overview, options = {}) {
|
|
35
36
|
const items = [];
|
|
36
|
-
const
|
|
37
|
-
const
|
|
37
|
+
const safeConfig = config && typeof config === 'object' ? config : {};
|
|
38
|
+
const acpPeers = Array.isArray(overview?.acp) ? overview.acp : [];
|
|
39
|
+
const byokProviders = Array.isArray(overview?.byok) ? overview.byok : [];
|
|
40
|
+
const activeProvider = safeConfig.provider || '';
|
|
41
|
+
const activeModel = safeConfig.model || '';
|
|
38
42
|
const tab = options.tab || 'all';
|
|
39
43
|
const expandedPeers = options.expandedPeers || new Set();
|
|
40
|
-
const
|
|
44
|
+
const defaultMaxAcp = tab === 'all' ? Infinity : 10;
|
|
45
|
+
let maxAcp = defaultMaxAcp;
|
|
46
|
+
if (typeof options.maxAcpPerPeer === 'number') {
|
|
47
|
+
if (options.maxAcpPerPeer === Infinity) {
|
|
48
|
+
maxAcp = Infinity;
|
|
49
|
+
}
|
|
50
|
+
else if (Number.isFinite(options.maxAcpPerPeer)) {
|
|
51
|
+
maxAcp = Math.max(1, Math.floor(options.maxAcpPerPeer));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
41
54
|
// 1. ACP Peer Agents & Sovereign Local Engines
|
|
42
55
|
if (tab === 'all' || tab === 'acp') {
|
|
43
|
-
for (const peer of
|
|
56
|
+
for (const peer of acpPeers) {
|
|
44
57
|
const isCurrentProvider = activeProvider === peer.providerKey;
|
|
45
58
|
const catTitle = peer.installed
|
|
46
59
|
? `ACP · ${peer.label} (ready)`
|
|
@@ -122,7 +135,7 @@ export function buildModelPickerItems(config, overview, options = {}) {
|
|
|
122
135
|
value: {
|
|
123
136
|
type: 'acp',
|
|
124
137
|
providerId: peer.providerKey,
|
|
125
|
-
modelId: peer.models[0] || peer.id,
|
|
138
|
+
modelId: (Array.isArray(peer.models) ? peer.models[0] : undefined) || peer.id,
|
|
126
139
|
providerLabel: peer.label,
|
|
127
140
|
installed: false,
|
|
128
141
|
isCurrent: false,
|
|
@@ -135,7 +148,7 @@ export function buildModelPickerItems(config, overview, options = {}) {
|
|
|
135
148
|
}
|
|
136
149
|
// 2. BYOK Providers (Cloud & Local APIs) — excluding OpenRouter in BYOK tab
|
|
137
150
|
if (tab === 'all' || tab === 'byok') {
|
|
138
|
-
for (const p of
|
|
151
|
+
for (const p of byokProviders) {
|
|
139
152
|
if (p.id === 'openrouter') {
|
|
140
153
|
continue;
|
|
141
154
|
}
|
|
@@ -174,8 +187,8 @@ export function buildModelPickerItems(config, overview, options = {}) {
|
|
|
174
187
|
}
|
|
175
188
|
// 3. Free Cloud Models (OpenRouter Free)
|
|
176
189
|
if (tab === 'all' || tab === 'free') {
|
|
177
|
-
const isConfigured = Boolean((
|
|
178
|
-
|
|
190
|
+
const isConfigured = Boolean((safeConfig.provider === 'openrouter' && safeConfig.apiKey) ||
|
|
191
|
+
safeConfig.providerKeys?.openrouter ||
|
|
179
192
|
process.env.OPENROUTER_API_KEY);
|
|
180
193
|
const isCurrentProvider = activeProvider === 'openrouter';
|
|
181
194
|
const catTitle = isConfigured
|
|
@@ -273,7 +286,8 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
273
286
|
maxAcpPerPeer: isSearching ? Infinity : 10
|
|
274
287
|
});
|
|
275
288
|
this.filtered = fuzzyFilter(tabItems, this.query);
|
|
276
|
-
|
|
289
|
+
const prevSelected = Number.isFinite(this.selected) ? Math.max(0, Math.floor(this.selected)) : 0;
|
|
290
|
+
this.selected = Math.min(prevSelected, Math.max(0, this.filtered.length - 1));
|
|
277
291
|
this.offset = 0;
|
|
278
292
|
return this;
|
|
279
293
|
};
|
|
@@ -323,13 +337,15 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
323
337
|
return 2 + 2 + this.list.filtered.length + categories.size + 2;
|
|
324
338
|
}
|
|
325
339
|
body(width, height) {
|
|
340
|
+
const safeWidth = Number.isFinite(width) ? Math.max(4, Math.floor(width)) : 64;
|
|
341
|
+
const safeHeight = Number.isFinite(height) ? Math.max(3, Math.floor(height)) : 12;
|
|
326
342
|
const tabACP = this.activeTab === 'acp' ? paint('accent', bold('● ACP')) : dim('ACP');
|
|
327
343
|
const tabBYOK = this.activeTab === 'byok' ? paint('accent', bold('● BYOK')) : dim('BYOK');
|
|
328
344
|
const tabFREE = this.activeTab === 'free' ? paint('accent', bold('● FREE')) : dim('FREE');
|
|
329
|
-
const tabBar = ` | ${tabACP} | ${tabBYOK} | ${tabFREE} | ${dim('(Tab / ← → switch tab)')}
|
|
330
|
-
const separator = paint('rule', GLYPHS.hLine.repeat(
|
|
331
|
-
const listHeight = Math.max(1,
|
|
332
|
-
const { rows } = this.list.render(
|
|
345
|
+
const tabBar = truncate(` | ${tabACP} | ${tabBYOK} | ${tabFREE} | ${dim('(Tab / ← → switch tab)')}`, safeWidth, '');
|
|
346
|
+
const separator = paint('rule', GLYPHS.hLine.repeat(safeWidth));
|
|
347
|
+
const listHeight = Math.max(1, safeHeight - 2);
|
|
348
|
+
const { rows } = this.list.render(safeWidth, listHeight);
|
|
333
349
|
this.cursor = { x: this.list.cursorColumn(), y: 2 };
|
|
334
350
|
return [tabBar, separator, ...rows];
|
|
335
351
|
}
|
|
@@ -385,7 +401,10 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
385
401
|
return 'handled';
|
|
386
402
|
}
|
|
387
403
|
// 2. Delegate to SelectList for navigation / query typing
|
|
388
|
-
const
|
|
404
|
+
const fallbackRows = Number.isFinite(this.height) ? Math.max(1, Math.floor(this.height) - 7) : 10;
|
|
405
|
+
const visibleRows = Number.isFinite(this.list.lastItemRows) && this.list.lastItemRows > 0
|
|
406
|
+
? Math.floor(this.list.lastItemRows)
|
|
407
|
+
: fallbackRows;
|
|
389
408
|
const action = this.list.handleKey(event, visibleRows);
|
|
390
409
|
if (action === 'select') {
|
|
391
410
|
const item = this.list.current;
|
|
@@ -399,8 +418,10 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
399
418
|
this.settled = false;
|
|
400
419
|
return result === 'keep' ? 'handled' : 'close';
|
|
401
420
|
}
|
|
402
|
-
if (action === 'cancel')
|
|
421
|
+
if (action === 'cancel') {
|
|
422
|
+
this.settled = true;
|
|
403
423
|
return 'close';
|
|
424
|
+
}
|
|
404
425
|
return action ? 'handled' : null;
|
|
405
426
|
}
|
|
406
427
|
}
|
|
@@ -542,6 +563,10 @@ export async function runInteractiveModelPicker(prompt, store = { loadConfig, sa
|
|
|
542
563
|
const { apiKey } = await startLoopbackAuth({ timeoutMs: 120_000, openBrowser: true });
|
|
543
564
|
saveOpenRouterKey(apiKey, { setAsActive: true, store });
|
|
544
565
|
const updatedConfig = store.loadConfig();
|
|
566
|
+
if (target.modelId && updatedConfig.model !== target.modelId) {
|
|
567
|
+
updatedConfig.model = target.modelId;
|
|
568
|
+
store.saveConfig(updatedConfig);
|
|
569
|
+
}
|
|
545
570
|
if (options.loop) {
|
|
546
571
|
options.loop.config = updatedConfig;
|
|
547
572
|
if (typeof options.loop.updateTierLimits === 'function') {
|
|
@@ -572,6 +597,10 @@ export async function runInteractiveModelPicker(prompt, store = { loadConfig, sa
|
|
|
572
597
|
await showConfiguringAnimation('OpenRouter', prompt);
|
|
573
598
|
saveOpenRouterKey(cleanInput, { setAsActive: true, store });
|
|
574
599
|
const updatedConfig = store.loadConfig();
|
|
600
|
+
if (target.modelId && updatedConfig.model !== target.modelId) {
|
|
601
|
+
updatedConfig.model = target.modelId;
|
|
602
|
+
store.saveConfig(updatedConfig);
|
|
603
|
+
}
|
|
575
604
|
if (options.loop) {
|
|
576
605
|
options.loop.config = updatedConfig;
|
|
577
606
|
if (typeof options.loop.updateTierLimits === 'function') {
|
package/src/tui/modelPicker.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { fuzzyFilter } from './selectList.js';
|
|
|
12
12
|
import { loadConfig, saveConfig } from '../config.js';
|
|
13
13
|
import { startLoopbackAuth, saveOpenRouterKey, disconnectOpenRouter } from '../auth/openrouterAuth.js';
|
|
14
14
|
import { setTransientNotice } from './consoleGuard.js';
|
|
15
|
+
import { truncate } from './text.js';
|
|
15
16
|
import {
|
|
16
17
|
getAvailableProvidersOverview,
|
|
17
18
|
resolveAvailableProvidersOverview,
|
|
@@ -92,15 +93,26 @@ export function buildModelPickerItems(
|
|
|
92
93
|
options: BuildModelPickerOptions = {}
|
|
93
94
|
): ModelPickerItem[] {
|
|
94
95
|
const items: ModelPickerItem[] = [];
|
|
95
|
-
const
|
|
96
|
-
const
|
|
96
|
+
const safeConfig = config && typeof config === 'object' ? config : {};
|
|
97
|
+
const acpPeers = Array.isArray(overview?.acp) ? overview.acp : [];
|
|
98
|
+
const byokProviders = Array.isArray(overview?.byok) ? overview.byok : [];
|
|
99
|
+
const activeProvider = safeConfig.provider || '';
|
|
100
|
+
const activeModel = safeConfig.model || '';
|
|
97
101
|
const tab = options.tab || 'all';
|
|
98
102
|
const expandedPeers = options.expandedPeers || new Set<string>();
|
|
99
|
-
const
|
|
103
|
+
const defaultMaxAcp = tab === 'all' ? Infinity : 10;
|
|
104
|
+
let maxAcp = defaultMaxAcp;
|
|
105
|
+
if (typeof options.maxAcpPerPeer === 'number') {
|
|
106
|
+
if (options.maxAcpPerPeer === Infinity) {
|
|
107
|
+
maxAcp = Infinity;
|
|
108
|
+
} else if (Number.isFinite(options.maxAcpPerPeer)) {
|
|
109
|
+
maxAcp = Math.max(1, Math.floor(options.maxAcpPerPeer));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
100
112
|
|
|
101
113
|
// 1. ACP Peer Agents & Sovereign Local Engines
|
|
102
114
|
if (tab === 'all' || tab === 'acp') {
|
|
103
|
-
for (const peer of
|
|
115
|
+
for (const peer of acpPeers) {
|
|
104
116
|
const isCurrentProvider = activeProvider === peer.providerKey;
|
|
105
117
|
const catTitle = peer.installed
|
|
106
118
|
? `ACP · ${peer.label} (ready)`
|
|
@@ -183,7 +195,7 @@ export function buildModelPickerItems(
|
|
|
183
195
|
value: {
|
|
184
196
|
type: 'acp',
|
|
185
197
|
providerId: peer.providerKey,
|
|
186
|
-
modelId: peer.models[0] || peer.id,
|
|
198
|
+
modelId: (Array.isArray(peer.models) ? peer.models[0] : undefined) || peer.id,
|
|
187
199
|
providerLabel: peer.label,
|
|
188
200
|
installed: false,
|
|
189
201
|
isCurrent: false,
|
|
@@ -197,7 +209,7 @@ export function buildModelPickerItems(
|
|
|
197
209
|
|
|
198
210
|
// 2. BYOK Providers (Cloud & Local APIs) — excluding OpenRouter in BYOK tab
|
|
199
211
|
if (tab === 'all' || tab === 'byok') {
|
|
200
|
-
for (const p of
|
|
212
|
+
for (const p of byokProviders) {
|
|
201
213
|
if (p.id === 'openrouter') {
|
|
202
214
|
continue;
|
|
203
215
|
}
|
|
@@ -239,8 +251,8 @@ export function buildModelPickerItems(
|
|
|
239
251
|
// 3. Free Cloud Models (OpenRouter Free)
|
|
240
252
|
if (tab === 'all' || tab === 'free') {
|
|
241
253
|
const isConfigured = Boolean(
|
|
242
|
-
(
|
|
243
|
-
|
|
254
|
+
(safeConfig.provider === 'openrouter' && safeConfig.apiKey) ||
|
|
255
|
+
safeConfig.providerKeys?.openrouter ||
|
|
244
256
|
process.env.OPENROUTER_API_KEY
|
|
245
257
|
);
|
|
246
258
|
const isCurrentProvider = activeProvider === 'openrouter';
|
|
@@ -361,7 +373,8 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
361
373
|
maxAcpPerPeer: isSearching ? Infinity : 10
|
|
362
374
|
});
|
|
363
375
|
this.filtered = fuzzyFilter(tabItems, this.query);
|
|
364
|
-
|
|
376
|
+
const prevSelected = Number.isFinite(this.selected) ? Math.max(0, Math.floor(this.selected)) : 0;
|
|
377
|
+
this.selected = Math.min(prevSelected, Math.max(0, this.filtered.length - 1));
|
|
365
378
|
this.offset = 0;
|
|
366
379
|
return this;
|
|
367
380
|
};
|
|
@@ -414,14 +427,20 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
414
427
|
}
|
|
415
428
|
|
|
416
429
|
body(width: number, height: number): string[] {
|
|
430
|
+
const safeWidth = Number.isFinite(width) ? Math.max(4, Math.floor(width)) : 64;
|
|
431
|
+
const safeHeight = Number.isFinite(height) ? Math.max(3, Math.floor(height)) : 12;
|
|
417
432
|
const tabACP = this.activeTab === 'acp' ? paint('accent', bold('● ACP')) : dim('ACP');
|
|
418
433
|
const tabBYOK = this.activeTab === 'byok' ? paint('accent', bold('● BYOK')) : dim('BYOK');
|
|
419
434
|
const tabFREE = this.activeTab === 'free' ? paint('accent', bold('● FREE')) : dim('FREE');
|
|
420
|
-
const tabBar =
|
|
421
|
-
|
|
435
|
+
const tabBar = truncate(
|
|
436
|
+
` | ${tabACP} | ${tabBYOK} | ${tabFREE} | ${dim('(Tab / ← → switch tab)')}`,
|
|
437
|
+
safeWidth,
|
|
438
|
+
''
|
|
439
|
+
);
|
|
440
|
+
const separator = paint('rule', GLYPHS.hLine.repeat(safeWidth));
|
|
422
441
|
|
|
423
|
-
const listHeight = Math.max(1,
|
|
424
|
-
const { rows } = this.list.render(
|
|
442
|
+
const listHeight = Math.max(1, safeHeight - 2);
|
|
443
|
+
const { rows } = this.list.render(safeWidth, listHeight);
|
|
425
444
|
|
|
426
445
|
this.cursor = { x: this.list.cursorColumn(), y: 2 };
|
|
427
446
|
return [tabBar, separator, ...rows];
|
|
@@ -473,7 +492,10 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
473
492
|
}
|
|
474
493
|
|
|
475
494
|
// 2. Delegate to SelectList for navigation / query typing
|
|
476
|
-
const
|
|
495
|
+
const fallbackRows = Number.isFinite(this.height) ? Math.max(1, Math.floor(this.height) - 7) : 10;
|
|
496
|
+
const visibleRows = Number.isFinite(this.list.lastItemRows) && this.list.lastItemRows > 0
|
|
497
|
+
? Math.floor(this.list.lastItemRows)
|
|
498
|
+
: fallbackRows;
|
|
477
499
|
const action = this.list.handleKey(event, visibleRows);
|
|
478
500
|
|
|
479
501
|
if (action === 'select') {
|
|
@@ -489,7 +511,10 @@ export class ModelPickerLayer extends SelectLayer {
|
|
|
489
511
|
return result === 'keep' ? 'handled' : 'close';
|
|
490
512
|
}
|
|
491
513
|
|
|
492
|
-
if (action === 'cancel')
|
|
514
|
+
if (action === 'cancel') {
|
|
515
|
+
this.settled = true;
|
|
516
|
+
return 'close';
|
|
517
|
+
}
|
|
493
518
|
return action ? 'handled' : null;
|
|
494
519
|
}
|
|
495
520
|
}
|
|
@@ -654,6 +679,10 @@ export async function runInteractiveModelPicker(
|
|
|
654
679
|
saveOpenRouterKey(apiKey, { setAsActive: true, store });
|
|
655
680
|
|
|
656
681
|
const updatedConfig = store.loadConfig();
|
|
682
|
+
if (target.modelId && updatedConfig.model !== target.modelId) {
|
|
683
|
+
updatedConfig.model = target.modelId;
|
|
684
|
+
store.saveConfig(updatedConfig);
|
|
685
|
+
}
|
|
657
686
|
if (options.loop) {
|
|
658
687
|
options.loop.config = updatedConfig;
|
|
659
688
|
if (typeof options.loop.updateTierLimits === 'function') {
|
|
@@ -686,6 +715,10 @@ export async function runInteractiveModelPicker(
|
|
|
686
715
|
await showConfiguringAnimation('OpenRouter', prompt);
|
|
687
716
|
saveOpenRouterKey(cleanInput, { setAsActive: true, store });
|
|
688
717
|
const updatedConfig = store.loadConfig();
|
|
718
|
+
if (target.modelId && updatedConfig.model !== target.modelId) {
|
|
719
|
+
updatedConfig.model = target.modelId;
|
|
720
|
+
store.saveConfig(updatedConfig);
|
|
721
|
+
}
|
|
689
722
|
if (options.loop) {
|
|
690
723
|
options.loop.config = updatedConfig;
|
|
691
724
|
if (typeof options.loop.updateTierLimits === 'function') {
|
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
import { SelectLayer, InputLayer, TextLayer } from './dialogs.js';
|
|
6
6
|
// @ts-expect-error untyped local TUI theme
|
|
7
7
|
import { paint, bold, dim, GLYPHS } from './theme.js';
|
|
8
|
+
import { safeDisplay } from './text.js';
|
|
8
9
|
import { coldObserver } from '../observer/coldObserver.js';
|
|
10
|
+
function cleanSingleLine(value) {
|
|
11
|
+
return safeDisplay(typeof value === 'string' ? value : String(value ?? '')).replace(/[\r\n]+/g, ' ').trim();
|
|
12
|
+
}
|
|
13
|
+
function clampCount(value) {
|
|
14
|
+
const n = Number(value);
|
|
15
|
+
return Number.isFinite(n) ? Math.max(0, Math.floor(n)) : 0;
|
|
16
|
+
}
|
|
9
17
|
class DetailTextLayer extends TextLayer {
|
|
10
18
|
onDismiss;
|
|
11
19
|
dismissed = false;
|
|
@@ -66,7 +74,7 @@ export function buildObserverPickerItems(config, auditCount, vetoCount) {
|
|
|
66
74
|
value: { action: 'strictness' }
|
|
67
75
|
});
|
|
68
76
|
// 4. Advisory Loopback Endpoint
|
|
69
|
-
const endpointDisplay = config.endpoint || '(not configured)';
|
|
77
|
+
const endpointDisplay = cleanSingleLine(config.endpoint) || '(not configured)';
|
|
70
78
|
items.push({
|
|
71
79
|
id: 'endpoint',
|
|
72
80
|
label: `Advisory Endpoint: ${endpointDisplay}`,
|
|
@@ -76,7 +84,7 @@ export function buildObserverPickerItems(config, auditCount, vetoCount) {
|
|
|
76
84
|
value: { action: 'endpoint' }
|
|
77
85
|
});
|
|
78
86
|
// 5. Advisory Model Name
|
|
79
|
-
const modelDisplay = config.model || '(unset)';
|
|
87
|
+
const modelDisplay = cleanSingleLine(config.model) || '(unset)';
|
|
80
88
|
items.push({
|
|
81
89
|
id: 'model',
|
|
82
90
|
label: `Advisory Model: ${modelDisplay}`,
|
|
@@ -95,9 +103,11 @@ export function buildObserverPickerItems(config, auditCount, vetoCount) {
|
|
|
95
103
|
value: { action: 'test' }
|
|
96
104
|
});
|
|
97
105
|
// 7. Audit History
|
|
106
|
+
const safeAudits = clampCount(auditCount);
|
|
107
|
+
const safeVetoes = clampCount(vetoCount);
|
|
98
108
|
items.push({
|
|
99
109
|
id: 'audit',
|
|
100
|
-
label: `Audit History (${
|
|
110
|
+
label: `Audit History (${safeAudits} events recorded, ${safeVetoes} vetoes)`,
|
|
101
111
|
category: 'Diagnostics',
|
|
102
112
|
description: 'Inspect recent mutation reviews and safety veto records',
|
|
103
113
|
searchText: 'audit history logs events vetoes inspect recent records',
|
|
@@ -120,13 +130,16 @@ export function buildObserverPickerItems(config, auditCount, vetoCount) {
|
|
|
120
130
|
export function runInteractiveObserverPicker(prompt) {
|
|
121
131
|
return new Promise((resolve) => {
|
|
122
132
|
let settled = false;
|
|
133
|
+
let menuVersion = 0;
|
|
123
134
|
const finish = (msg) => {
|
|
124
135
|
if (settled)
|
|
125
136
|
return;
|
|
126
137
|
settled = true;
|
|
138
|
+
menuVersion++;
|
|
127
139
|
resolve(msg);
|
|
128
140
|
};
|
|
129
141
|
function openMenu() {
|
|
142
|
+
menuVersion++;
|
|
130
143
|
const cfg = coldObserver.getConfig();
|
|
131
144
|
const audits = coldObserver.getAuditHistory();
|
|
132
145
|
const vetoes = audits.filter((a) => a.veto).length;
|
|
@@ -239,13 +252,21 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
239
252
|
}
|
|
240
253
|
// 6. Test Advisory Endpoint
|
|
241
254
|
if (action === 'test') {
|
|
242
|
-
|
|
243
|
-
|
|
255
|
+
const probeVersion = menuVersion;
|
|
256
|
+
void coldObserver.healthCheck()
|
|
257
|
+
.then((health) => {
|
|
258
|
+
if (settled || menuVersion !== probeVersion)
|
|
259
|
+
return;
|
|
260
|
+
const endpoint = cleanSingleLine(health.endpoint);
|
|
261
|
+
const model = cleanSingleLine(health.model) || '(unset)';
|
|
262
|
+
const detail = cleanSingleLine(health.detail);
|
|
263
|
+
const latency = clampCount(health.latencyMs);
|
|
264
|
+
const textLines = endpoint
|
|
244
265
|
? [
|
|
245
|
-
`Endpoint: ${
|
|
246
|
-
`Model: ${
|
|
247
|
-
`Status: ${health.healthy ? 'HEALTHY' : 'UNREACHABLE'} (${
|
|
248
|
-
`Detail: ${
|
|
266
|
+
`Endpoint: ${endpoint}`,
|
|
267
|
+
`Model: ${model}`,
|
|
268
|
+
`Status: ${health.healthy ? 'HEALTHY' : 'UNREACHABLE'} (${latency}ms latency)`,
|
|
269
|
+
`Detail: ${detail}`,
|
|
249
270
|
'',
|
|
250
271
|
'Press Esc or Enter to return to Observer setup.'
|
|
251
272
|
]
|
|
@@ -262,6 +283,23 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
262
283
|
height: 12,
|
|
263
284
|
onDismiss: () => openMenu()
|
|
264
285
|
}));
|
|
286
|
+
})
|
|
287
|
+
.catch((err) => {
|
|
288
|
+
if (settled || menuVersion !== probeVersion)
|
|
289
|
+
return;
|
|
290
|
+
const detail = cleanSingleLine(err instanceof Error ? err.message : err) || 'Health probe failed';
|
|
291
|
+
prompt.openLayer(new DetailTextLayer({
|
|
292
|
+
title: 'Advisory Endpoint Health Check',
|
|
293
|
+
lines: [
|
|
294
|
+
`Status: UNREACHABLE`,
|
|
295
|
+
`Detail: ${detail}`,
|
|
296
|
+
'',
|
|
297
|
+
'Press Esc or Enter to return to Observer setup.'
|
|
298
|
+
],
|
|
299
|
+
width: 70,
|
|
300
|
+
height: 12,
|
|
301
|
+
onDismiss: () => openMenu()
|
|
302
|
+
}));
|
|
265
303
|
});
|
|
266
304
|
return 'handled';
|
|
267
305
|
}
|
|
@@ -271,11 +309,16 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
271
309
|
const lines = recentAudits.length === 0
|
|
272
310
|
? ['No Cold Observer audit records yet.', '', 'Press Esc or Enter to return to Observer setup.']
|
|
273
311
|
: recentAudits.slice(-12).map((a) => {
|
|
274
|
-
const
|
|
275
|
-
const
|
|
276
|
-
const
|
|
312
|
+
const dt = typeof a.timestamp === 'number' && Number.isFinite(a.timestamp) ? new Date(a.timestamp) : null;
|
|
313
|
+
const time = dt && Number.isFinite(dt.getTime()) ? dt.toLocaleTimeString() : '--:--:--';
|
|
314
|
+
const toolName = cleanSingleLine(a.tool);
|
|
315
|
+
const tag = a.type === 'mutation' ? `[mutation${toolName ? ` ${toolName}` : ''}]` : '[verification]';
|
|
316
|
+
const score = typeof a.riskScore === 'number' && Number.isFinite(a.riskScore)
|
|
317
|
+
? `(${Math.max(0, Math.min(100, Math.round(a.riskScore * 100)))}% risk)`
|
|
318
|
+
: '';
|
|
277
319
|
const veto = a.veto ? paint('danger', 'VETO') : paint('success', 'PASS');
|
|
278
|
-
|
|
320
|
+
const details = cleanSingleLine(a.details);
|
|
321
|
+
return `${time} ${tag} ${veto}${score ? ` ${score}` : ''} ${details}`.trim();
|
|
279
322
|
});
|
|
280
323
|
prompt.openLayer(new DetailTextLayer({
|
|
281
324
|
title: `Cold Observer Audits (Last ${Math.min(12, recentAudits.length)})`,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { SelectLayer, InputLayer, TextLayer } from './dialogs.js';
|
|
7
7
|
// @ts-expect-error untyped local TUI theme
|
|
8
8
|
import { paint, bold, dim, GLYPHS } from './theme.js';
|
|
9
|
+
import { safeDisplay } from './text.js';
|
|
9
10
|
import {
|
|
10
11
|
coldObserver,
|
|
11
12
|
type ObserverConfig,
|
|
@@ -14,6 +15,15 @@ import {
|
|
|
14
15
|
type ColdObserverAuditRecord
|
|
15
16
|
} from '../observer/coldObserver.js';
|
|
16
17
|
|
|
18
|
+
function cleanSingleLine(value: unknown): string {
|
|
19
|
+
return safeDisplay(typeof value === 'string' ? value : String(value ?? '')).replace(/[\r\n]+/g, ' ').trim();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function clampCount(value: unknown): number {
|
|
23
|
+
const n = Number(value);
|
|
24
|
+
return Number.isFinite(n) ? Math.max(0, Math.floor(n)) : 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
export interface ObserverPickerItemValue {
|
|
18
28
|
action: 'toggle' | 'mode' | 'strictness' | 'endpoint' | 'model' | 'test' | 'audit' | 'reset';
|
|
19
29
|
data?: string;
|
|
@@ -110,7 +120,7 @@ export function buildObserverPickerItems(
|
|
|
110
120
|
});
|
|
111
121
|
|
|
112
122
|
// 4. Advisory Loopback Endpoint
|
|
113
|
-
const endpointDisplay = config.endpoint || '(not configured)';
|
|
123
|
+
const endpointDisplay = cleanSingleLine(config.endpoint) || '(not configured)';
|
|
114
124
|
items.push({
|
|
115
125
|
id: 'endpoint',
|
|
116
126
|
label: `Advisory Endpoint: ${endpointDisplay}`,
|
|
@@ -121,7 +131,7 @@ export function buildObserverPickerItems(
|
|
|
121
131
|
});
|
|
122
132
|
|
|
123
133
|
// 5. Advisory Model Name
|
|
124
|
-
const modelDisplay = config.model || '(unset)';
|
|
134
|
+
const modelDisplay = cleanSingleLine(config.model) || '(unset)';
|
|
125
135
|
items.push({
|
|
126
136
|
id: 'model',
|
|
127
137
|
label: `Advisory Model: ${modelDisplay}`,
|
|
@@ -142,9 +152,11 @@ export function buildObserverPickerItems(
|
|
|
142
152
|
});
|
|
143
153
|
|
|
144
154
|
// 7. Audit History
|
|
155
|
+
const safeAudits = clampCount(auditCount);
|
|
156
|
+
const safeVetoes = clampCount(vetoCount);
|
|
145
157
|
items.push({
|
|
146
158
|
id: 'audit',
|
|
147
|
-
label: `Audit History (${
|
|
159
|
+
label: `Audit History (${safeAudits} events recorded, ${safeVetoes} vetoes)`,
|
|
148
160
|
category: 'Diagnostics',
|
|
149
161
|
description: 'Inspect recent mutation reviews and safety veto records',
|
|
150
162
|
searchText: 'audit history logs events vetoes inspect recent records',
|
|
@@ -170,13 +182,16 @@ export function buildObserverPickerItems(
|
|
|
170
182
|
export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string> {
|
|
171
183
|
return new Promise((resolve) => {
|
|
172
184
|
let settled = false;
|
|
185
|
+
let menuVersion = 0;
|
|
173
186
|
const finish = (msg: string): void => {
|
|
174
187
|
if (settled) return;
|
|
175
188
|
settled = true;
|
|
189
|
+
menuVersion++;
|
|
176
190
|
resolve(msg);
|
|
177
191
|
};
|
|
178
192
|
|
|
179
193
|
function openMenu(): void {
|
|
194
|
+
menuVersion++;
|
|
180
195
|
const cfg = coldObserver.getConfig();
|
|
181
196
|
const audits = coldObserver.getAuditHistory();
|
|
182
197
|
const vetoes = audits.filter((a: ColdObserverAuditRecord) => a.veto).length;
|
|
@@ -294,31 +309,54 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
294
309
|
|
|
295
310
|
// 6. Test Advisory Endpoint
|
|
296
311
|
if (action === 'test') {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
312
|
+
const probeVersion = menuVersion;
|
|
313
|
+
void coldObserver.healthCheck()
|
|
314
|
+
.then((health) => {
|
|
315
|
+
if (settled || menuVersion !== probeVersion) return;
|
|
316
|
+
const endpoint = cleanSingleLine(health.endpoint);
|
|
317
|
+
const model = cleanSingleLine(health.model) || '(unset)';
|
|
318
|
+
const detail = cleanSingleLine(health.detail);
|
|
319
|
+
const latency = clampCount(health.latencyMs);
|
|
320
|
+
const textLines = endpoint
|
|
321
|
+
? [
|
|
322
|
+
`Endpoint: ${endpoint}`,
|
|
323
|
+
`Model: ${model}`,
|
|
324
|
+
`Status: ${health.healthy ? 'HEALTHY' : 'UNREACHABLE'} (${latency}ms latency)`,
|
|
325
|
+
`Detail: ${detail}`,
|
|
326
|
+
'',
|
|
327
|
+
'Press Esc or Enter to return to Observer setup.'
|
|
328
|
+
]
|
|
329
|
+
: [
|
|
330
|
+
'No advisory endpoint configured.',
|
|
331
|
+
'The deterministic observer requires no endpoint and remains fully active.',
|
|
332
|
+
'',
|
|
333
|
+
'Press Esc or Enter to return to Observer setup.'
|
|
334
|
+
];
|
|
335
|
+
|
|
336
|
+
prompt.openLayer(new DetailTextLayer({
|
|
337
|
+
title: 'Advisory Endpoint Health Check',
|
|
338
|
+
lines: textLines,
|
|
339
|
+
width: 70,
|
|
340
|
+
height: 12,
|
|
341
|
+
onDismiss: () => openMenu()
|
|
342
|
+
}));
|
|
343
|
+
})
|
|
344
|
+
.catch((err) => {
|
|
345
|
+
if (settled || menuVersion !== probeVersion) return;
|
|
346
|
+
const detail = cleanSingleLine(err instanceof Error ? err.message : err) || 'Health probe failed';
|
|
347
|
+
prompt.openLayer(new DetailTextLayer({
|
|
348
|
+
title: 'Advisory Endpoint Health Check',
|
|
349
|
+
lines: [
|
|
350
|
+
`Status: UNREACHABLE`,
|
|
351
|
+
`Detail: ${detail}`,
|
|
304
352
|
'',
|
|
305
353
|
'Press Esc or Enter to return to Observer setup.'
|
|
306
|
-
]
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
];
|
|
313
|
-
|
|
314
|
-
prompt.openLayer(new DetailTextLayer({
|
|
315
|
-
title: 'Advisory Endpoint Health Check',
|
|
316
|
-
lines: textLines,
|
|
317
|
-
width: 70,
|
|
318
|
-
height: 12,
|
|
319
|
-
onDismiss: () => openMenu()
|
|
320
|
-
}));
|
|
321
|
-
});
|
|
354
|
+
],
|
|
355
|
+
width: 70,
|
|
356
|
+
height: 12,
|
|
357
|
+
onDismiss: () => openMenu()
|
|
358
|
+
}));
|
|
359
|
+
});
|
|
322
360
|
return 'handled';
|
|
323
361
|
}
|
|
324
362
|
|
|
@@ -328,11 +366,16 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
328
366
|
const lines = recentAudits.length === 0
|
|
329
367
|
? ['No Cold Observer audit records yet.', '', 'Press Esc or Enter to return to Observer setup.']
|
|
330
368
|
: recentAudits.slice(-12).map((a: ColdObserverAuditRecord) => {
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
const
|
|
369
|
+
const dt = typeof a.timestamp === 'number' && Number.isFinite(a.timestamp) ? new Date(a.timestamp) : null;
|
|
370
|
+
const time = dt && Number.isFinite(dt.getTime()) ? dt.toLocaleTimeString() : '--:--:--';
|
|
371
|
+
const toolName = cleanSingleLine(a.tool);
|
|
372
|
+
const tag = a.type === 'mutation' ? `[mutation${toolName ? ` ${toolName}` : ''}]` : '[verification]';
|
|
373
|
+
const score = typeof a.riskScore === 'number' && Number.isFinite(a.riskScore)
|
|
374
|
+
? `(${Math.max(0, Math.min(100, Math.round(a.riskScore * 100)))}% risk)`
|
|
375
|
+
: '';
|
|
334
376
|
const veto = a.veto ? paint('danger', 'VETO') : paint('success', 'PASS');
|
|
335
|
-
|
|
377
|
+
const details = cleanSingleLine(a.details);
|
|
378
|
+
return `${time} ${tag} ${veto}${score ? ` ${score}` : ''} ${details}`.trim();
|
|
336
379
|
});
|
|
337
380
|
|
|
338
381
|
prompt.openLayer(new DetailTextLayer({
|