@causyne/agent 1.20.55 → 1.20.62

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 (56) hide show
  1. package/package.json +1 -1
  2. package/src/acp/agentCatalog.js +1 -1
  3. package/src/acp/agentCatalog.ts +1 -1
  4. package/src/acp/peerProfiles.js +3 -3
  5. package/src/acp/peerProfiles.ts +3 -3
  6. package/src/agentLoop.js +91 -19
  7. package/src/agentLoop.ts +102 -22
  8. package/src/checkpoints.js +23 -5
  9. package/src/cliMode.js +4 -2
  10. package/src/commands.js +503 -78
  11. package/src/contextManager.d.ts +3 -0
  12. package/src/contextManager.js +78 -5
  13. package/src/cortex/autoCondenser.js +105 -145
  14. package/src/cortex/autoCondenser.ts +185 -0
  15. package/src/cortex/cortexEngine.js +179 -0
  16. package/src/cortex/cortexEngine.ts +209 -0
  17. package/src/cortex/provisioner.js +12 -14
  18. package/src/cortex/provisioner.ts +29 -0
  19. package/src/cortex/vectorDb.js +307 -386
  20. package/src/cortex/vectorDb.ts +473 -0
  21. package/src/decisionPolicy.js +3 -3
  22. package/src/decisionPolicy.ts +3 -3
  23. package/src/observer/coldObserver.js +10 -4
  24. package/src/observer/coldObserver.ts +10 -4
  25. package/src/observer/evidence.js +8 -3
  26. package/src/observer/evidence.ts +8 -3
  27. package/src/reporting.js +30 -7
  28. package/src/sessionJournal.js +13 -0
  29. package/src/sessionJournal.ts +13 -0
  30. package/src/tokenTracker.js +22 -0
  31. package/src/tokenTracker.ts +28 -0
  32. package/src/tools/memoryWrite.js +11 -3
  33. package/src/tools/memoryWrite.ts +12 -3
  34. package/src/tools/toolSelfRepair.js +11 -0
  35. package/src/tools/toolSelfRepair.ts +10 -0
  36. package/src/tui/chatRenderer.js +8 -4
  37. package/src/tui/completion.js +34 -15
  38. package/src/tui/composerControls.js +5 -0
  39. package/src/tui/composerControls.ts +5 -0
  40. package/src/tui/layout.js +1 -1
  41. package/src/tui/layout.ts +1 -1
  42. package/src/tui/messageInteraction.js +1 -1
  43. package/src/tui/messageInteraction.ts +1 -1
  44. package/src/tui/observerPicker.js +323 -0
  45. package/src/tui/observerPicker.ts +386 -0
  46. package/src/tui/prompt.js +185 -23
  47. package/src/tui/stage.js +2 -2
  48. package/src/tui/stageSurface.js +22 -27
  49. package/src/tui/thinkingBox.js +2 -2
  50. package/src/tui/thinkingBox.ts +2 -2
  51. package/src/tui/usageCard.js +178 -0
  52. package/src/tui/usageCard.ts +240 -0
  53. package/src/utils/paths.js +30 -1
  54. package/src/utils/paths.ts +32 -1
  55. package/src/cortex/autoCondenser.d.ts +0 -2
  56. package/src/cortex/vectorDb.d.ts +0 -1
@@ -0,0 +1,386 @@
1
+ // Sovereign Interactive Cold Observer Setup & Picker — modal dialog for configuring Cold Observer.
2
+ // Authored in Strict TypeScript for Causyne Agent.
3
+ // Source-available under BUSL-1.1.
4
+
5
+ // @ts-expect-error untyped local TUI dialogs
6
+ import { SelectLayer, InputLayer, TextLayer } from './dialogs.js';
7
+ // @ts-expect-error untyped local TUI theme
8
+ import { paint, bold, dim, GLYPHS } from './theme.js';
9
+ import {
10
+ coldObserver,
11
+ type ObserverConfig,
12
+ type ObserverMode,
13
+ type ObserverStrictness,
14
+ type ColdObserverAuditRecord
15
+ } from '../observer/coldObserver.js';
16
+
17
+ export interface ObserverPickerItemValue {
18
+ action: 'toggle' | 'mode' | 'strictness' | 'endpoint' | 'model' | 'test' | 'audit' | 'reset';
19
+ data?: string;
20
+ }
21
+
22
+ export interface ObserverPickerItem {
23
+ id: string;
24
+ label: string;
25
+ category: string;
26
+ description: string;
27
+ searchText?: string;
28
+ value: ObserverPickerItemValue;
29
+ }
30
+
31
+ export interface PromptHost {
32
+ openLayer(layer: unknown): unknown;
33
+ closeLayer(): void;
34
+ draw(): void;
35
+ notice?: string;
36
+ }
37
+
38
+ class DetailTextLayer extends TextLayer {
39
+ private onDismiss?: (() => void) | undefined;
40
+ private dismissed = false;
41
+
42
+ constructor(options: {
43
+ title: string;
44
+ lines: string[];
45
+ width?: number;
46
+ height?: number;
47
+ onDismiss?: () => void;
48
+ }) {
49
+ super(options);
50
+ this.onDismiss = options.onDismiss;
51
+ }
52
+
53
+ answer(): void {
54
+ if (this.dismissed) return;
55
+ this.dismissed = true;
56
+ if (this.onDismiss) this.onDismiss();
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Build interactive menu items reflecting live Cold Observer configuration and state.
62
+ */
63
+ export function buildObserverPickerItems(
64
+ config: ObserverConfig,
65
+ auditCount: number,
66
+ vetoCount: number
67
+ ): ObserverPickerItem[] {
68
+ const items: ObserverPickerItem[] = [];
69
+
70
+ // 1. Toggle Protection
71
+ const activeStatus = config.enabled ? '[Active ●]' : '[Disabled ○]';
72
+ const toggleAction = config.enabled ? 'Click to Turn OFF' : 'Click to Turn ON';
73
+ items.push({
74
+ id: 'toggle',
75
+ label: `${activeStatus} — ${toggleAction}`,
76
+ category: 'Protection Status',
77
+ description: config.enabled
78
+ ? 'Cold Observer is actively verifying tool mutations and completion claims'
79
+ : 'Cold Observer is DISABLED — safety invariants and claim checks are disabled',
80
+ searchText: 'toggle enable disable active status turn off turn on switch protection',
81
+ value: { action: 'toggle' }
82
+ });
83
+
84
+ // 2. Review Mode
85
+ const modeLabel = config.mode === 'advisory' ? 'ADVISORY (Neural loopback)' : 'DETERMINISTIC (Fast rules)';
86
+ items.push({
87
+ id: 'mode',
88
+ label: `Review Mode: ${modeLabel}`,
89
+ category: 'Configuration',
90
+ description: config.mode === 'advisory'
91
+ ? 'Uses local neural loopback endpoint to verify task claims'
92
+ : 'Uses fast, zero-latency deterministic command & outcome analysis',
93
+ searchText: 'mode deterministic advisory neural rules review verify',
94
+ value: { action: 'mode' }
95
+ });
96
+
97
+ // 3. Strictness
98
+ const strictnessLabel = config.strictness.toUpperCase();
99
+ items.push({
100
+ id: 'strictness',
101
+ label: `Strictness: ${strictnessLabel}`,
102
+ category: 'Configuration',
103
+ description: config.strictness === 'strict'
104
+ ? 'Strict: requires explicit test/build confirmation before declaring complete'
105
+ : config.strictness === 'relaxed'
106
+ ? 'Relaxed: minimal false vetoes; allows standard developer autonomy'
107
+ : 'Standard: balanced oversight without false vetoes (recommended)',
108
+ searchText: 'strictness standard strict relaxed level threshold safety',
109
+ value: { action: 'strictness' }
110
+ });
111
+
112
+ // 4. Advisory Loopback Endpoint
113
+ const endpointDisplay = config.endpoint || '(not configured)';
114
+ items.push({
115
+ id: 'endpoint',
116
+ label: `Advisory Endpoint: ${endpointDisplay}`,
117
+ category: 'Advisory Endpoint',
118
+ description: 'Local loopback HTTP endpoint for neural verification (e.g. http://localhost:11434/v1 or none)',
119
+ searchText: 'endpoint url loopback ollama localhost http address advisory',
120
+ value: { action: 'endpoint' }
121
+ });
122
+
123
+ // 5. Advisory Model Name
124
+ const modelDisplay = config.model || '(unset)';
125
+ items.push({
126
+ id: 'model',
127
+ label: `Advisory Model: ${modelDisplay}`,
128
+ category: 'Advisory Endpoint',
129
+ description: 'Name of the local neural model (e.g. tiny, qwen, llama3, or none)',
130
+ searchText: 'model name llama qwen tiny advisory neural',
131
+ value: { action: 'model' }
132
+ });
133
+
134
+ // 6. Test Advisory Endpoint
135
+ items.push({
136
+ id: 'test',
137
+ label: 'Test Advisory Endpoint (Health Probe)',
138
+ category: 'Diagnostics',
139
+ description: 'Probe loopback advisory endpoint and report latency and model readiness',
140
+ searchText: 'test health check ping probe latency verify endpoint',
141
+ value: { action: 'test' }
142
+ });
143
+
144
+ // 7. Audit History
145
+ items.push({
146
+ id: 'audit',
147
+ label: `Audit History (${auditCount} events recorded, ${vetoCount} vetoes)`,
148
+ category: 'Diagnostics',
149
+ description: 'Inspect recent mutation reviews and safety veto records',
150
+ searchText: 'audit history logs events vetoes inspect recent records',
151
+ value: { action: 'audit' }
152
+ });
153
+
154
+ // 8. Reset to Defaults
155
+ items.push({
156
+ id: 'reset',
157
+ label: 'Reset Configuration to Defaults',
158
+ category: 'Actions',
159
+ description: 'Restore enabled state, deterministic mode, standard strictness, and cleared endpoint',
160
+ searchText: 'reset default restore factory clear settings',
161
+ value: { action: 'reset' }
162
+ });
163
+
164
+ return items;
165
+ }
166
+
167
+ /**
168
+ * Launch the Interactive Cold Observer Setup Modal in the live prompt.
169
+ */
170
+ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string> {
171
+ return new Promise((resolve) => {
172
+ let settled = false;
173
+ const finish = (msg: string): void => {
174
+ if (settled) return;
175
+ settled = true;
176
+ resolve(msg);
177
+ };
178
+
179
+ function openMenu(): void {
180
+ const cfg = coldObserver.getConfig();
181
+ const audits = coldObserver.getAuditHistory();
182
+ const vetoes = audits.filter((a: ColdObserverAuditRecord) => a.veto).length;
183
+ const items = buildObserverPickerItems(cfg, audits.length, vetoes);
184
+
185
+ const statusTag = cfg.enabled ? 'ACTIVE' : 'DISABLED';
186
+ const selectLayer = new SelectLayer({
187
+ title: `Cold Observer Setup (${statusTag} · ${cfg.mode.toUpperCase()})`,
188
+ placeholder: 'Search observer settings...',
189
+ emptyText: 'No matching observer settings found.',
190
+ items,
191
+ width: 76,
192
+ height: 20,
193
+ footer: `↑↓ choose ${GLYPHS.dot} enter toggle/edit ${GLYPHS.dot} esc finish`,
194
+ onPick: (picked: ObserverPickerItem | null): string | void => {
195
+ if (!picked) {
196
+ prompt.closeLayer();
197
+ const currentCfg = coldObserver.getConfig();
198
+ finish(`Cold Observer is ${currentCfg.enabled ? 'ACTIVE' : 'DISABLED'} (${currentCfg.mode}, ${currentCfg.strictness}).`);
199
+ return;
200
+ }
201
+
202
+ const action = picked.value.action;
203
+
204
+ // 1. Toggle Protection (Synchronous in-place toggle with visual confirmation)
205
+ if (action === 'toggle') {
206
+ const current = coldObserver.getConfig();
207
+ const newEnabled = !current.enabled;
208
+ coldObserver.updateConfig({ enabled: newEnabled });
209
+ prompt.notice = `Cold Observer is now ${newEnabled ? 'ACTIVE (Enabled)' : 'DISABLED (Inactive)'}`;
210
+ refreshLayer();
211
+ return 'keep';
212
+ }
213
+
214
+ // 2. Mode Toggle
215
+ if (action === 'mode') {
216
+ const current = coldObserver.getConfig();
217
+ const nextMode: ObserverMode = current.mode === 'deterministic' ? 'advisory' : 'deterministic';
218
+ coldObserver.updateConfig({ mode: nextMode });
219
+ prompt.notice = `Cold Observer mode set to "${nextMode.toUpperCase()}"`;
220
+ refreshLayer();
221
+ return 'keep';
222
+ }
223
+
224
+ // 3. Strictness Cycle
225
+ if (action === 'strictness') {
226
+ const current = coldObserver.getConfig();
227
+ let nextStrictness: ObserverStrictness = 'standard';
228
+ if (current.strictness === 'standard') nextStrictness = 'strict';
229
+ else if (current.strictness === 'strict') nextStrictness = 'relaxed';
230
+ else nextStrictness = 'standard';
231
+
232
+ coldObserver.updateConfig({ strictness: nextStrictness });
233
+ prompt.notice = `Cold Observer strictness set to "${nextStrictness}"`;
234
+ refreshLayer();
235
+ return 'keep';
236
+ }
237
+
238
+ // 4. Advisory Endpoint Input
239
+ if (action === 'endpoint') {
240
+ const current = coldObserver.getConfig();
241
+ prompt.closeLayer();
242
+ prompt.openLayer(new InputLayer({
243
+ title: 'Advisory Loopback Endpoint',
244
+ placeholder: 'http://localhost:11434/v1 (or "none" to clear)',
245
+ value: current.endpoint,
246
+ lines: [
247
+ 'Enter local loopback endpoint URL for advisory neural verification.',
248
+ 'Only loopback URLs (localhost, 127.0.0.1) are accepted for security.',
249
+ 'Type "none" to clear the endpoint.'
250
+ ],
251
+ onSubmit: (val: string) => {
252
+ const trimmed = val.trim();
253
+ try {
254
+ coldObserver.updateConfig({ endpoint: trimmed === 'none' ? '' : trimmed });
255
+ prompt.notice = coldObserver.getConfig().endpoint
256
+ ? `Advisory endpoint set to ${coldObserver.getConfig().endpoint}`
257
+ : 'Advisory endpoint cleared';
258
+ } catch (err) {
259
+ prompt.notice = err instanceof Error ? err.message : 'Invalid loopback endpoint';
260
+ }
261
+ openMenu();
262
+ },
263
+ onCancel: () => {
264
+ openMenu();
265
+ }
266
+ }));
267
+ return;
268
+ }
269
+
270
+ // 5. Advisory Model Input
271
+ if (action === 'model') {
272
+ const current = coldObserver.getConfig();
273
+ prompt.closeLayer();
274
+ prompt.openLayer(new InputLayer({
275
+ title: 'Advisory Model Name',
276
+ placeholder: 'model name (e.g. tiny, qwen2.5-coder) or "none"',
277
+ value: current.model,
278
+ lines: [
279
+ 'Enter local advisory model name served at the loopback endpoint.',
280
+ 'Type "none" to clear the model name.'
281
+ ],
282
+ onSubmit: (val: string) => {
283
+ const trimmed = val.trim();
284
+ coldObserver.updateConfig({ model: trimmed === 'none' ? '' : trimmed });
285
+ prompt.notice = coldObserver.getConfig().model
286
+ ? `Advisory model set to ${coldObserver.getConfig().model}`
287
+ : 'Advisory model cleared';
288
+ openMenu();
289
+ },
290
+ onCancel: () => {
291
+ openMenu();
292
+ }
293
+ }));
294
+ return;
295
+ }
296
+
297
+ // 6. Test Advisory Endpoint
298
+ if (action === 'test') {
299
+ prompt.closeLayer();
300
+ void coldObserver.healthCheck().then((health) => {
301
+ const textLines = health.endpoint
302
+ ? [
303
+ `Endpoint: ${health.endpoint}`,
304
+ `Model: ${health.model || '(unset)'}`,
305
+ `Status: ${health.healthy ? 'HEALTHY' : 'UNREACHABLE'} (${health.latencyMs}ms latency)`,
306
+ `Detail: ${health.detail}`,
307
+ '',
308
+ 'Press Esc or Enter to return to Observer setup.'
309
+ ]
310
+ : [
311
+ 'No advisory endpoint configured.',
312
+ 'The deterministic observer requires no endpoint and remains fully active.',
313
+ '',
314
+ 'Press Esc or Enter to return to Observer setup.'
315
+ ];
316
+
317
+ prompt.openLayer(new DetailTextLayer({
318
+ title: 'Advisory Endpoint Health Check',
319
+ lines: textLines,
320
+ width: 70,
321
+ height: 12,
322
+ onDismiss: () => openMenu()
323
+ }));
324
+ });
325
+ return;
326
+ }
327
+
328
+ // 7. Audit History
329
+ if (action === 'audit') {
330
+ prompt.closeLayer();
331
+ const recentAudits = coldObserver.getAuditHistory();
332
+ const lines = recentAudits.length === 0
333
+ ? ['No Cold Observer audit records yet.', '', 'Press Esc or Enter to return to Observer setup.']
334
+ : recentAudits.slice(-12).map((a: ColdObserverAuditRecord) => {
335
+ const time = new Date(a.timestamp).toLocaleTimeString();
336
+ const tag = a.type === 'mutation' ? `[mutation ${a.tool || ''}]` : '[verification]';
337
+ const score = typeof a.riskScore === 'number' ? `(${(a.riskScore * 100).toFixed(0)}% risk)` : '';
338
+ const veto = a.veto ? paint('danger', 'VETO') : paint('success', 'PASS');
339
+ return `${time} ${tag} ${veto} ${score} ${a.details}`;
340
+ });
341
+
342
+ prompt.openLayer(new DetailTextLayer({
343
+ title: `Cold Observer Audits (Last ${Math.min(12, recentAudits.length)})`,
344
+ lines,
345
+ width: 76,
346
+ height: 18,
347
+ onDismiss: () => openMenu()
348
+ }));
349
+ return;
350
+ }
351
+
352
+ // 8. Reset Defaults
353
+ if (action === 'reset') {
354
+ coldObserver.updateConfig({
355
+ enabled: true,
356
+ mode: 'deterministic',
357
+ endpoint: '',
358
+ model: '',
359
+ timeoutMs: 800,
360
+ strictness: 'standard'
361
+ });
362
+ prompt.notice = 'Cold Observer reset to default settings';
363
+ refreshLayer();
364
+ return 'keep';
365
+ }
366
+
367
+ return;
368
+ }
369
+ });
370
+
371
+ function refreshLayer(): void {
372
+ const updatedCfg = coldObserver.getConfig();
373
+ const updatedAudits = coldObserver.getAuditHistory();
374
+ const updatedVetoes = updatedAudits.filter((a: ColdObserverAuditRecord) => a.veto).length;
375
+ const newItems = buildObserverPickerItems(updatedCfg, updatedAudits.length, updatedVetoes);
376
+ selectLayer.title = `Cold Observer Setup (${updatedCfg.enabled ? 'ACTIVE' : 'DISABLED'} · ${updatedCfg.mode.toUpperCase()})`;
377
+ selectLayer.list.setItems(newItems);
378
+ prompt.draw();
379
+ }
380
+
381
+ prompt.openLayer(selectLayer);
382
+ }
383
+
384
+ openMenu();
385
+ });
386
+ }