@causyne/agent 1.20.112 → 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.
- package/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- 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/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/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/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/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- 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 +135 -83
- 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 +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- 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 +33 -17
- 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 +162 -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 +120 -49
- 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 +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- 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
|
@@ -82,12 +82,13 @@ function relativeTime(timestamp: number, now: number): string {
|
|
|
82
82
|
|
|
83
83
|
function countLabel(count: number): string {
|
|
84
84
|
if (!Number.isFinite(count) || count < 0) return '0 msgs';
|
|
85
|
-
|
|
85
|
+
const safeCount = Math.floor(count);
|
|
86
|
+
return `${safeCount.toLocaleString('en-US')} ${safeCount === 1 ? 'msg' : 'msgs'}`;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/** Fit two pieces of styled text in one terminal row, retaining the left title. */
|
|
89
90
|
function pairedRow(left: string, right: string, columns: number): string {
|
|
90
|
-
const width = Math.max(1, Math.floor(columns));
|
|
91
|
+
const width = Number.isFinite(columns) ? Math.max(1, Math.min(512, Math.floor(columns))) : 80;
|
|
91
92
|
const rightWidth = visibleWidth(right);
|
|
92
93
|
if (!right || width < 45 || rightWidth > width - 20) return truncate(left, width, '…');
|
|
93
94
|
const title = truncate(left, Math.max(1, width - rightWidth - 2), '…');
|
|
@@ -107,9 +108,11 @@ export function sortContinuumItems(items: ContinuumPickerItem[]): ContinuumPicke
|
|
|
107
108
|
return [...items].sort((a, b) => {
|
|
108
109
|
const groupA = order.get(a.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
109
110
|
const groupB = order.get(b.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
111
|
+
const timeA = Number.isFinite(Number(a.value.updatedAt)) ? Number(a.value.updatedAt) : 0;
|
|
112
|
+
const timeB = Number.isFinite(Number(b.value.updatedAt)) ? Number(b.value.updatedAt) : 0;
|
|
110
113
|
return groupA - groupB
|
|
111
|
-
||
|
|
112
|
-
|| a.value.id.localeCompare(b.value.id);
|
|
114
|
+
|| timeB - timeA
|
|
115
|
+
|| String(a.value.id ?? '').localeCompare(String(b.value.id ?? ''));
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
118
|
|
|
@@ -136,12 +139,14 @@ export function renderContinuumWindow(
|
|
|
136
139
|
width: number, budget: number, now = Date.now()
|
|
137
140
|
): ListWindow {
|
|
138
141
|
const rows: string[] = [];
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
+
const safeStart = Number.isFinite(start) ? Math.max(0, Math.floor(start)) : 0;
|
|
143
|
+
const safeSelected = Number.isFinite(selected) ? Math.max(0, Math.floor(selected)) : 0;
|
|
144
|
+
const safeWidth = Number.isFinite(width) ? Math.max(1, Math.min(512, Math.floor(width))) : 80;
|
|
145
|
+
const allowed = Number.isFinite(budget) ? Math.max(0, Math.min(200, Math.floor(budget))) : 0;
|
|
146
|
+
let lastIndex = safeStart - 1;
|
|
142
147
|
let itemCount = 0;
|
|
143
148
|
let previousGroup: string | null = null;
|
|
144
|
-
for (let index =
|
|
149
|
+
for (let index = safeStart; index < entries.length; index++) {
|
|
145
150
|
const item = entries[index]?.item;
|
|
146
151
|
if (!item) continue;
|
|
147
152
|
const group = sourceName(item.value);
|
|
@@ -153,12 +158,12 @@ export function renderContinuumWindow(
|
|
|
153
158
|
} else if (needHeader) {
|
|
154
159
|
rows.push(dim(` ${truncate(group.toUpperCase(), Math.max(1, safeWidth - 5), '…')}`));
|
|
155
160
|
}
|
|
156
|
-
rows.push(...renderedItem(item, index ===
|
|
161
|
+
rows.push(...renderedItem(item, index === safeSelected, safeWidth, now));
|
|
157
162
|
lastIndex = index;
|
|
158
163
|
itemCount++;
|
|
159
164
|
previousGroup = group;
|
|
160
165
|
}
|
|
161
|
-
return { rows, firstIndex:
|
|
166
|
+
return { rows, firstIndex: safeStart, lastIndex, itemCount };
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
export class ContinuumPickerLayer extends SelectLayer {
|
|
@@ -238,8 +243,9 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
238
243
|
}
|
|
239
244
|
if (event.name === 'pageup' || event.name === 'pagedown') {
|
|
240
245
|
const direction = event.name === 'pageup' ? -1 : 1;
|
|
241
|
-
|
|
242
|
-
|
|
246
|
+
const curSelected = Number.isFinite(this.list.selected) ? Math.max(0, Math.floor(this.list.selected)) : 0;
|
|
247
|
+
const safeVisible = Number.isFinite(this.visibleItems) ? Math.max(1, Math.floor(this.visibleItems)) : 5;
|
|
248
|
+
this.list.moveTo(curSelected + direction * Math.max(1, safeVisible - 1), safeVisible);
|
|
243
249
|
return 'handled';
|
|
244
250
|
}
|
|
245
251
|
const query = this.list.query;
|
|
@@ -252,8 +258,8 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
252
258
|
}
|
|
253
259
|
|
|
254
260
|
body(width: number, height: number): string[] {
|
|
255
|
-
const w = Math.max(8, Math.floor(width));
|
|
256
|
-
const h = Math.max(1, Math.floor(height));
|
|
261
|
+
const w = Number.isFinite(width) ? Math.max(8, Math.min(512, Math.floor(width))) : 80;
|
|
262
|
+
const h = Number.isFinite(height) ? Math.max(1, Math.min(200, Math.floor(height))) : 1;
|
|
257
263
|
const rows: string[] = [];
|
|
258
264
|
const scope = this.scope;
|
|
259
265
|
const label = scope === 'all' ? 'ALL SOURCES' : PLATFORM_NAMES[scope];
|
|
@@ -284,8 +290,10 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
284
290
|
if (rows.length < h - details) rows.push(dim(' No sessions match this filter.'));
|
|
285
291
|
if (rows.length < h - details) rows.push(dim(' Tab changes source. Ctrl+U clears search.'));
|
|
286
292
|
} else if (budget > 0) {
|
|
287
|
-
const
|
|
288
|
-
|
|
293
|
+
const rawSelected = Number.isFinite(this.list.selected) ? Math.floor(this.list.selected) : 0;
|
|
294
|
+
const rawOffset = Number.isFinite(this.list.offset) ? Math.floor(this.list.offset) : 0;
|
|
295
|
+
const selected = Math.min(Math.max(0, rawSelected), count - 1);
|
|
296
|
+
let from = Math.min(Math.max(0, rawOffset), selected);
|
|
289
297
|
let output = renderContinuumWindow(filtered, from, selected, w, budget);
|
|
290
298
|
while (output.lastIndex < selected && from < selected) {
|
|
291
299
|
from++;
|
package/src/observer/advisory.js
CHANGED
|
@@ -54,29 +54,36 @@ function compactArguments(args) {
|
|
|
54
54
|
return redact(JSON.stringify(allowed));
|
|
55
55
|
}
|
|
56
56
|
function parseVerdict(content) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
return null;
|
|
60
|
-
try {
|
|
61
|
-
const parsed = JSON.parse(match[0]);
|
|
62
|
-
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
63
|
-
return null;
|
|
64
|
-
const record = parsed;
|
|
65
|
-
const risk = record.risk;
|
|
66
|
-
const confidence = record.confidence;
|
|
67
|
-
if (typeof risk !== 'number' || !Number.isFinite(risk))
|
|
68
|
-
return null;
|
|
69
|
-
if (typeof confidence !== 'number' || !Number.isFinite(confidence))
|
|
70
|
-
return null;
|
|
71
|
-
return {
|
|
72
|
-
risk: Math.max(0, Math.min(1, risk)),
|
|
73
|
-
confidence: Math.max(0, Math.min(1, confidence)),
|
|
74
|
-
observation: typeof record.observation === 'string' ? record.observation.slice(0, 400) : ''
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
57
|
+
const closeIndex = content.lastIndexOf('}');
|
|
58
|
+
if (closeIndex < 0)
|
|
78
59
|
return null;
|
|
60
|
+
let searchEnd = closeIndex;
|
|
61
|
+
while (searchEnd >= 0) {
|
|
62
|
+
const openIndex = content.lastIndexOf('{', searchEnd);
|
|
63
|
+
if (openIndex < 0)
|
|
64
|
+
break;
|
|
65
|
+
const candidate = content.slice(openIndex, closeIndex + 1);
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(candidate);
|
|
68
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
69
|
+
const record = parsed;
|
|
70
|
+
const risk = record.risk;
|
|
71
|
+
const confidence = record.confidence;
|
|
72
|
+
if (typeof risk === 'number' && Number.isFinite(risk) && typeof confidence === 'number' && Number.isFinite(confidence)) {
|
|
73
|
+
return {
|
|
74
|
+
risk: Math.max(0, Math.min(1, risk)),
|
|
75
|
+
confidence: Math.max(0, Math.min(1, confidence)),
|
|
76
|
+
observation: typeof record.observation === 'string' ? record.observation.slice(0, 400) : ''
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Try an earlier opening brace if the suffix was nested inside outer braces.
|
|
83
|
+
}
|
|
84
|
+
searchEnd = openIndex - 1;
|
|
79
85
|
}
|
|
86
|
+
return null;
|
|
80
87
|
}
|
|
81
88
|
export async function queryAdvisory(input, options) {
|
|
82
89
|
if (!isLoopbackEndpoint(options.endpoint))
|
|
@@ -141,7 +148,10 @@ export async function probeAdvisory(options) {
|
|
|
141
148
|
}
|
|
142
149
|
const start = Date.now();
|
|
143
150
|
const controller = new AbortController();
|
|
144
|
-
const
|
|
151
|
+
const safeTimeoutMs = Number.isFinite(options.timeoutMs)
|
|
152
|
+
? Math.max(500, Math.min(30_000, Math.floor(options.timeoutMs)))
|
|
153
|
+
: 2500;
|
|
154
|
+
const timer = setTimeout(() => controller.abort(), safeTimeoutMs);
|
|
145
155
|
try {
|
|
146
156
|
const base = options.endpoint.replace(/\/+$/, '').replace(/\/chat\/completions$/, '');
|
|
147
157
|
const response = await fetch(`${base}/models`, { signal: controller.signal });
|
package/src/observer/advisory.ts
CHANGED
|
@@ -72,24 +72,33 @@ function compactArguments(args: Record<string, unknown>): string {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
function parseVerdict(content: string): AdvisoryVerdict | null {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
const closeIndex = content.lastIndexOf('}');
|
|
76
|
+
if (closeIndex < 0) return null;
|
|
77
|
+
let searchEnd = closeIndex;
|
|
78
|
+
while (searchEnd >= 0) {
|
|
79
|
+
const openIndex = content.lastIndexOf('{', searchEnd);
|
|
80
|
+
if (openIndex < 0) break;
|
|
81
|
+
const candidate = content.slice(openIndex, closeIndex + 1);
|
|
82
|
+
try {
|
|
83
|
+
const parsed: unknown = JSON.parse(candidate);
|
|
84
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
85
|
+
const record = parsed as Record<string, unknown>;
|
|
86
|
+
const risk = record.risk;
|
|
87
|
+
const confidence = record.confidence;
|
|
88
|
+
if (typeof risk === 'number' && Number.isFinite(risk) && typeof confidence === 'number' && Number.isFinite(confidence)) {
|
|
89
|
+
return {
|
|
90
|
+
risk: Math.max(0, Math.min(1, risk)),
|
|
91
|
+
confidence: Math.max(0, Math.min(1, confidence)),
|
|
92
|
+
observation: typeof record.observation === 'string' ? record.observation.slice(0, 400) : ''
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch {
|
|
97
|
+
// Try an earlier opening brace if the suffix was nested inside outer braces.
|
|
98
|
+
}
|
|
99
|
+
searchEnd = openIndex - 1;
|
|
92
100
|
}
|
|
101
|
+
return null;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
export async function queryAdvisory(
|
|
@@ -150,7 +159,10 @@ export async function probeAdvisory(options: AdvisoryOptions): Promise<{ healthy
|
|
|
150
159
|
}
|
|
151
160
|
const start = Date.now();
|
|
152
161
|
const controller = new AbortController();
|
|
153
|
-
const
|
|
162
|
+
const safeTimeoutMs = Number.isFinite(options.timeoutMs)
|
|
163
|
+
? Math.max(500, Math.min(30_000, Math.floor(options.timeoutMs)))
|
|
164
|
+
: 2500;
|
|
165
|
+
const timer = setTimeout(() => controller.abort(), safeTimeoutMs);
|
|
154
166
|
try {
|
|
155
167
|
const base = options.endpoint.replace(/\/+$/, '').replace(/\/chat\/completions$/, '');
|
|
156
168
|
const response = await fetch(`${base}/models`, { signal: controller.signal });
|
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { auditLog } from '../auditLog.js';
|
|
5
5
|
import { isLaunchOnlyPrompt } from '../launchIntent.js';
|
|
6
6
|
import { causyneHome } from '../utils/paths.js';
|
|
7
|
-
import {
|
|
7
|
+
import { outcomeFromResult, scanMutation } from './evidence.js';
|
|
8
8
|
import { isLoopbackEndpoint, probeAdvisory, queryAdvisory } from './advisory.js';
|
|
9
9
|
const CONFIG_FILE = path.join(causyneHome(), 'observer.json');
|
|
10
10
|
const MAX_AUDIT_RECORDS = 200;
|
|
@@ -122,39 +122,18 @@ function confirmThreshold(strictness) {
|
|
|
122
122
|
return 0.45;
|
|
123
123
|
return 0.62;
|
|
124
124
|
}
|
|
125
|
-
function nestedError(result) {
|
|
126
|
-
if (result === null || typeof result !== 'object' || Array.isArray(result))
|
|
127
|
-
return '';
|
|
128
|
-
const record = result;
|
|
129
|
-
return typeof record.error === 'string' ? record.error : '';
|
|
130
|
-
}
|
|
131
125
|
function normalizeOutcome(entry) {
|
|
132
126
|
const args = entry.args && typeof entry.args === 'object' && !Array.isArray(entry.args)
|
|
133
127
|
? entry.args
|
|
134
128
|
: {};
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|| (typeof args.command === 'string' ? args.command : '')
|
|
139
|
-
|| (typeof args.CommandLine === 'string' ? args.CommandLine : '')
|
|
140
|
-
|| (typeof args.commandLine === 'string' ? args.commandLine : '')
|
|
141
|
-
|| (typeof args.cmd === 'string' ? args.cmd : '')
|
|
142
|
-
|| (typeof args.script === 'string' ? args.script : '')
|
|
143
|
-
|| (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes(String(entry.tool || '').toLowerCase()) && typeof args.detail === 'string' ? args.detail : '');
|
|
129
|
+
const normalized = outcomeFromResult(entry.tool, args, entry.result, 0);
|
|
130
|
+
const command = typeof entry.command === 'string' && entry.command.trim() ? entry.command : normalized.command;
|
|
131
|
+
const targetPath = typeof entry.path === 'string' && entry.path.trim() ? entry.path : normalized.path;
|
|
144
132
|
return {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
success: entry.success === true && !error,
|
|
148
|
-
error: error.slice(0, 600),
|
|
149
|
-
exitCode: result !== null && typeof result === 'object' && !Array.isArray(result)
|
|
150
|
-
&& typeof result.exitCode === 'number'
|
|
151
|
-
? result.exitCode
|
|
152
|
-
: null,
|
|
133
|
+
...normalized,
|
|
134
|
+
success: entry.success === true && normalized.success,
|
|
153
135
|
command: command.slice(0, 600),
|
|
154
|
-
path:
|
|
155
|
-
|| (typeof args.path === 'string' ? args.path : '')
|
|
156
|
-
|| (typeof args.file_path === 'string' ? args.file_path : ''),
|
|
157
|
-
at: 0
|
|
136
|
+
path: targetPath.slice(0, 400)
|
|
158
137
|
};
|
|
159
138
|
}
|
|
160
139
|
function claimText(agentClaim) {
|
|
@@ -181,7 +160,16 @@ export class ColdObserver {
|
|
|
181
160
|
advisoryCooldownUntil = 0;
|
|
182
161
|
static instance = null;
|
|
183
162
|
constructor(configPartial) {
|
|
184
|
-
|
|
163
|
+
const base = { ...DEFAULT_CONFIG, ...readStoredConfig() };
|
|
164
|
+
const partial = configPartial || {};
|
|
165
|
+
this.config = {
|
|
166
|
+
enabled: typeof partial.enabled === 'boolean' ? partial.enabled : base.enabled,
|
|
167
|
+
mode: normalizeMode(partial.mode) ?? base.mode,
|
|
168
|
+
endpoint: typeof partial.endpoint === 'string' ? partial.endpoint.trim().replace(/\/+$/, '') : base.endpoint,
|
|
169
|
+
model: typeof partial.model === 'string' ? partial.model.trim().slice(0, 200) : base.model,
|
|
170
|
+
timeoutMs: boundedTimeout(partial.timeoutMs) ?? base.timeoutMs,
|
|
171
|
+
strictness: normalizeStrictness(partial.strictness) ?? base.strictness
|
|
172
|
+
};
|
|
185
173
|
}
|
|
186
174
|
static getInstance() {
|
|
187
175
|
if (!ColdObserver.instance)
|
|
@@ -401,10 +389,10 @@ export class ColdObserver {
|
|
|
401
389
|
&& /\.(?:[cm]?[jt]sx?|py|rb|php|go|rs|java|kt|kts|swift|c|cc|cpp|h|hpp|cs|fs|sh|sql|html|css|scss|sass|vue|svelte)$/i.test(outcome.path);
|
|
402
390
|
const lastCodeChange = outcomes.findLastIndex(isCodeMutation);
|
|
403
391
|
const checks = outcomes.slice(lastCodeChange + 1);
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
392
|
+
const testChecks = checks.filter((outcome) => TEST_COMMAND.test(outcome.command) || TEST_COMMAND.test(outcome.tool));
|
|
393
|
+
const buildChecks = checks.filter((outcome) => BUILD_OR_CHECK_COMMAND.test(outcome.command) || outcome.tool === 'code_verify_syntax');
|
|
394
|
+
const hasTestRun = testChecks.length > 0 && testChecks[testChecks.length - 1].success;
|
|
395
|
+
const hasBuildRun = buildChecks.length > 0 && buildChecks[buildChecks.length - 1].success;
|
|
408
396
|
const isLaunch = isLaunchOnlyPrompt(turnState.userPrompt || '');
|
|
409
397
|
const modifiedCode = lastCodeChange >= 0;
|
|
410
398
|
const declarativeOnly = modifiedCode && outcomes.filter(isCodeMutation).every(outcome => /\.(?:html|css)$/i.test(outcome.path));
|
|
@@ -5,7 +5,6 @@ import { auditLog } from '../auditLog.js';
|
|
|
5
5
|
import { isLaunchOnlyPrompt } from '../launchIntent.js';
|
|
6
6
|
import { causyneHome } from '../utils/paths.js';
|
|
7
7
|
import {
|
|
8
|
-
boundedArgs,
|
|
9
8
|
outcomeFromResult,
|
|
10
9
|
scanMutation
|
|
11
10
|
} from './evidence.js';
|
|
@@ -176,39 +175,18 @@ function confirmThreshold(strictness: ObserverStrictness): number {
|
|
|
176
175
|
return 0.62;
|
|
177
176
|
}
|
|
178
177
|
|
|
179
|
-
function nestedError(result: unknown): string {
|
|
180
|
-
if (result === null || typeof result !== 'object' || Array.isArray(result)) return '';
|
|
181
|
-
const record = result as Record<string, unknown>;
|
|
182
|
-
return typeof record.error === 'string' ? record.error : '';
|
|
183
|
-
}
|
|
184
|
-
|
|
185
178
|
function normalizeOutcome(entry: TurnToolEvidence): ToolOutcome {
|
|
186
179
|
const args = entry.args && typeof entry.args === 'object' && !Array.isArray(entry.args)
|
|
187
180
|
? entry.args
|
|
188
181
|
: {};
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
|| (typeof args.command === 'string' ? args.command : '')
|
|
193
|
-
|| (typeof args.CommandLine === 'string' ? args.CommandLine : '')
|
|
194
|
-
|| (typeof args.commandLine === 'string' ? args.commandLine : '')
|
|
195
|
-
|| (typeof args.cmd === 'string' ? args.cmd : '')
|
|
196
|
-
|| (typeof args.script === 'string' ? args.script : '')
|
|
197
|
-
|| (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes(String(entry.tool || '').toLowerCase()) && typeof args.detail === 'string' ? args.detail : '');
|
|
182
|
+
const normalized = outcomeFromResult(entry.tool, args, entry.result, 0);
|
|
183
|
+
const command = typeof entry.command === 'string' && entry.command.trim() ? entry.command : normalized.command;
|
|
184
|
+
const targetPath = typeof entry.path === 'string' && entry.path.trim() ? entry.path : normalized.path;
|
|
198
185
|
return {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
success: entry.success === true && !error,
|
|
202
|
-
error: error.slice(0, 600),
|
|
203
|
-
exitCode: result !== null && typeof result === 'object' && !Array.isArray(result)
|
|
204
|
-
&& typeof (result as Record<string, unknown>).exitCode === 'number'
|
|
205
|
-
? (result as Record<string, unknown>).exitCode as number
|
|
206
|
-
: null,
|
|
186
|
+
...normalized,
|
|
187
|
+
success: entry.success === true && normalized.success,
|
|
207
188
|
command: command.slice(0, 600),
|
|
208
|
-
path:
|
|
209
|
-
|| (typeof args.path === 'string' ? args.path : '')
|
|
210
|
-
|| (typeof args.file_path === 'string' ? args.file_path : ''),
|
|
211
|
-
at: 0
|
|
189
|
+
path: targetPath.slice(0, 400)
|
|
212
190
|
};
|
|
213
191
|
}
|
|
214
192
|
|
|
@@ -240,7 +218,16 @@ export class ColdObserver {
|
|
|
240
218
|
private static instance: ColdObserver | null = null;
|
|
241
219
|
|
|
242
220
|
constructor(configPartial?: Partial<ObserverConfig>) {
|
|
243
|
-
|
|
221
|
+
const base = { ...DEFAULT_CONFIG, ...readStoredConfig() };
|
|
222
|
+
const partial = configPartial || {};
|
|
223
|
+
this.config = {
|
|
224
|
+
enabled: typeof partial.enabled === 'boolean' ? partial.enabled : base.enabled,
|
|
225
|
+
mode: normalizeMode(partial.mode) ?? base.mode,
|
|
226
|
+
endpoint: typeof partial.endpoint === 'string' ? partial.endpoint.trim().replace(/\/+$/, '') : base.endpoint,
|
|
227
|
+
model: typeof partial.model === 'string' ? partial.model.trim().slice(0, 200) : base.model,
|
|
228
|
+
timeoutMs: boundedTimeout(partial.timeoutMs) ?? base.timeoutMs,
|
|
229
|
+
strictness: normalizeStrictness(partial.strictness) ?? base.strictness
|
|
230
|
+
};
|
|
244
231
|
}
|
|
245
232
|
|
|
246
233
|
static getInstance(): ColdObserver {
|
|
@@ -478,10 +465,10 @@ export class ColdObserver {
|
|
|
478
465
|
&& /\.(?:[cm]?[jt]sx?|py|rb|php|go|rs|java|kt|kts|swift|c|cc|cpp|h|hpp|cs|fs|sh|sql|html|css|scss|sass|vue|svelte)$/i.test(outcome.path);
|
|
479
466
|
const lastCodeChange = outcomes.findLastIndex(isCodeMutation);
|
|
480
467
|
const checks = outcomes.slice(lastCodeChange + 1);
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const
|
|
484
|
-
|
|
468
|
+
const testChecks = checks.filter((outcome) => TEST_COMMAND.test(outcome.command) || TEST_COMMAND.test(outcome.tool));
|
|
469
|
+
const buildChecks = checks.filter((outcome) => BUILD_OR_CHECK_COMMAND.test(outcome.command) || outcome.tool === 'code_verify_syntax');
|
|
470
|
+
const hasTestRun = testChecks.length > 0 && testChecks[testChecks.length - 1]!.success;
|
|
471
|
+
const hasBuildRun = buildChecks.length > 0 && buildChecks[buildChecks.length - 1]!.success;
|
|
485
472
|
const isLaunch = isLaunchOnlyPrompt(turnState.userPrompt || '');
|
|
486
473
|
const modifiedCode = lastCodeChange >= 0;
|
|
487
474
|
const declarativeOnly = modifiedCode && outcomes.filter(isCodeMutation).every(outcome => /\.(?:html|css)$/i.test(outcome.path));
|
package/src/observer/evidence.js
CHANGED
|
@@ -93,7 +93,10 @@ function physicalRoot(workspaceRoot) {
|
|
|
93
93
|
return realpathLoose(path.resolve(workspaceRoot));
|
|
94
94
|
}
|
|
95
95
|
function resolveTarget(workspaceRoot, raw) {
|
|
96
|
-
const
|
|
96
|
+
const trimmed = String(raw ?? '').trim();
|
|
97
|
+
const lexical = trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\') || path.isAbsolute(trimmed)
|
|
98
|
+
? resolveUserPath(trimmed)
|
|
99
|
+
: path.resolve(workspaceRoot, trimmed);
|
|
97
100
|
const physical = realpathLoose(lexical);
|
|
98
101
|
const root = physicalRoot(workspaceRoot);
|
|
99
102
|
const relative = path.relative(root, physical);
|
|
@@ -114,6 +117,9 @@ export function toolPath(args) {
|
|
|
114
117
|
export function isCodePath(target) {
|
|
115
118
|
return CODE_EXTENSIONS.has(path.extname(target).toLowerCase());
|
|
116
119
|
}
|
|
120
|
+
export function isRenderedNativeBrowserAction(tool) {
|
|
121
|
+
return ['browser_act', 'preview', 'snapshot'].includes(tool.toLowerCase());
|
|
122
|
+
}
|
|
117
123
|
export function isVerificationCommand(command) {
|
|
118
124
|
return VERIFICATION_COMMAND.test(command);
|
|
119
125
|
}
|
|
@@ -279,7 +285,7 @@ function scanWrite(toolName, args, workspaceRoot, evidence) {
|
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
287
|
else {
|
|
282
|
-
const edits = Array.isArray(args.edits) ? args.edits : [];
|
|
288
|
+
const edits = Array.isArray(args.edits) && args.edits.length > 0 ? args.edits : [args];
|
|
283
289
|
let delta = 0;
|
|
284
290
|
let sawEdit = false;
|
|
285
291
|
for (const edit of edits) {
|
|
@@ -288,20 +294,24 @@ function scanWrite(toolName, args, workspaceRoot, evidence) {
|
|
|
288
294
|
const record = edit;
|
|
289
295
|
const before = typeof record.old_string === 'string'
|
|
290
296
|
? record.old_string
|
|
291
|
-
: typeof record.searchContent === 'string'
|
|
297
|
+
: typeof record.searchContent === 'string'
|
|
298
|
+
? record.searchContent
|
|
299
|
+
: typeof record.oldText === 'string' ? record.oldText : null;
|
|
292
300
|
const after = typeof record.new_string === 'string'
|
|
293
301
|
? record.new_string
|
|
294
|
-
: typeof record.replaceContent === 'string'
|
|
302
|
+
: typeof record.replaceContent === 'string'
|
|
303
|
+
? record.replaceContent
|
|
304
|
+
: typeof record.newText === 'string' ? record.newText : null;
|
|
295
305
|
if (before === null || after === null)
|
|
296
306
|
continue;
|
|
297
307
|
delta += Buffer.byteLength(after, 'utf8') - Buffer.byteLength(before, 'utf8');
|
|
298
308
|
sawEdit = true;
|
|
299
309
|
}
|
|
300
310
|
if (sawEdit && originalSize !== null)
|
|
301
|
-
replacementSize = originalSize + delta;
|
|
311
|
+
replacementSize = Math.max(0, originalSize + delta);
|
|
302
312
|
}
|
|
303
313
|
if (originalSize !== null && replacementSize !== null && originalSize > 1024 && replacementSize < originalSize * 0.2) {
|
|
304
|
-
const lost = Math.round((1 - replacementSize / originalSize) * 100);
|
|
314
|
+
const lost = Math.min(100, Math.max(0, Math.round((1 - replacementSize / originalSize) * 100)));
|
|
305
315
|
add(evidence, 'write-large-shrink', 'high', `edit removes about ${lost}% of ${base}`, 0.78);
|
|
306
316
|
}
|
|
307
317
|
}
|
|
@@ -426,13 +436,10 @@ export function outcomeFromResult(tool, args, result, at) {
|
|
|
426
436
|
&& !(typeof record.exitCode === 'number' && (!Number.isFinite(record.exitCode) || record.exitCode !== 0));
|
|
427
437
|
const rawError = typeof record.error === 'string' ? record.error : '';
|
|
428
438
|
const exitCode = typeof record.exitCode === 'number' && Number.isFinite(record.exitCode) ? record.exitCode : null;
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
: typeof args.script === 'string' ? args.script
|
|
434
|
-
: (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes((tool || '').toLowerCase()) && typeof args.detail === 'string') ? args.detail
|
|
435
|
-
: '';
|
|
439
|
+
const detailFallback = ['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun']
|
|
440
|
+
.includes((tool || '').toLowerCase()) ? args.detail : undefined;
|
|
441
|
+
const rawCommand = [args.command, args.CommandLine, args.commandLine, args.cmd, args.script, detailFallback]
|
|
442
|
+
.find((value) => typeof value === 'string' && value.trim().length > 0) ?? '';
|
|
436
443
|
const command = rawCommand.trim();
|
|
437
444
|
const browserData = Array.isArray(record.data) ? record.data : [];
|
|
438
445
|
const imageCaptured = success && record._is_image_marker === true;
|
package/src/observer/evidence.ts
CHANGED
|
@@ -147,7 +147,10 @@ function physicalRoot(workspaceRoot: string): string {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
function resolveTarget(workspaceRoot: string, raw: string): { lexical: string; physical: string; inside: boolean } {
|
|
150
|
-
const
|
|
150
|
+
const trimmed = String(raw ?? '').trim();
|
|
151
|
+
const lexical = trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\') || path.isAbsolute(trimmed)
|
|
152
|
+
? resolveUserPath(trimmed)
|
|
153
|
+
: path.resolve(workspaceRoot, trimmed);
|
|
151
154
|
const physical = realpathLoose(lexical);
|
|
152
155
|
const root = physicalRoot(workspaceRoot);
|
|
153
156
|
const relative = path.relative(root, physical);
|
|
@@ -171,6 +174,10 @@ export function isCodePath(target: string): boolean {
|
|
|
171
174
|
return CODE_EXTENSIONS.has(path.extname(target).toLowerCase());
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
export function isRenderedNativeBrowserAction(tool: string): boolean {
|
|
178
|
+
return ['browser_act', 'preview', 'snapshot'].includes(tool.toLowerCase());
|
|
179
|
+
}
|
|
180
|
+
|
|
174
181
|
export function isVerificationCommand(command: string): boolean {
|
|
175
182
|
return VERIFICATION_COMMAND.test(command);
|
|
176
183
|
}
|
|
@@ -346,7 +353,7 @@ function scanWrite(toolName: string, args: Record<string, unknown>, workspaceRoo
|
|
|
346
353
|
}
|
|
347
354
|
}
|
|
348
355
|
} else {
|
|
349
|
-
const edits = Array.isArray(args.edits) ? args.edits : [];
|
|
356
|
+
const edits = Array.isArray(args.edits) && args.edits.length > 0 ? args.edits : [args];
|
|
350
357
|
let delta = 0;
|
|
351
358
|
let sawEdit = false;
|
|
352
359
|
for (const edit of edits) {
|
|
@@ -354,19 +361,23 @@ function scanWrite(toolName: string, args: Record<string, unknown>, workspaceRoo
|
|
|
354
361
|
const record = edit as Record<string, unknown>;
|
|
355
362
|
const before = typeof record.old_string === 'string'
|
|
356
363
|
? record.old_string
|
|
357
|
-
: typeof record.searchContent === 'string'
|
|
364
|
+
: typeof record.searchContent === 'string'
|
|
365
|
+
? record.searchContent
|
|
366
|
+
: typeof record.oldText === 'string' ? record.oldText : null;
|
|
358
367
|
const after = typeof record.new_string === 'string'
|
|
359
368
|
? record.new_string
|
|
360
|
-
: typeof record.replaceContent === 'string'
|
|
369
|
+
: typeof record.replaceContent === 'string'
|
|
370
|
+
? record.replaceContent
|
|
371
|
+
: typeof record.newText === 'string' ? record.newText : null;
|
|
361
372
|
if (before === null || after === null) continue;
|
|
362
373
|
delta += Buffer.byteLength(after, 'utf8') - Buffer.byteLength(before, 'utf8');
|
|
363
374
|
sawEdit = true;
|
|
364
375
|
}
|
|
365
|
-
if (sawEdit && originalSize !== null) replacementSize = originalSize + delta;
|
|
376
|
+
if (sawEdit && originalSize !== null) replacementSize = Math.max(0, originalSize + delta);
|
|
366
377
|
}
|
|
367
378
|
|
|
368
379
|
if (originalSize !== null && replacementSize !== null && originalSize > 1024 && replacementSize < originalSize * 0.2) {
|
|
369
|
-
const lost = Math.round((1 - replacementSize / originalSize) * 100);
|
|
380
|
+
const lost = Math.min(100, Math.max(0, Math.round((1 - replacementSize / originalSize) * 100)));
|
|
370
381
|
add(evidence, 'write-large-shrink', 'high', `edit removes about ${lost}% of ${base}`, 0.78);
|
|
371
382
|
}
|
|
372
383
|
}
|
|
@@ -490,13 +501,10 @@ export function outcomeFromResult(tool: string, args: Record<string, unknown>, r
|
|
|
490
501
|
&& !(typeof record.exitCode === 'number' && (!Number.isFinite(record.exitCode) || record.exitCode !== 0));
|
|
491
502
|
const rawError = typeof record.error === 'string' ? record.error : '';
|
|
492
503
|
const exitCode = typeof record.exitCode === 'number' && Number.isFinite(record.exitCode) ? record.exitCode : null;
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
: typeof
|
|
497
|
-
: typeof args.script === 'string' ? args.script
|
|
498
|
-
: (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes((tool || '').toLowerCase()) && typeof args.detail === 'string') ? args.detail
|
|
499
|
-
: '';
|
|
504
|
+
const detailFallback = ['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun']
|
|
505
|
+
.includes((tool || '').toLowerCase()) ? args.detail : undefined;
|
|
506
|
+
const rawCommand = [args.command, args.CommandLine, args.commandLine, args.cmd, args.script, detailFallback]
|
|
507
|
+
.find((value): value is string => typeof value === 'string' && value.trim().length > 0) ?? '';
|
|
500
508
|
const command = rawCommand.trim();
|
|
501
509
|
const browserData = Array.isArray(record.data) ? record.data : [];
|
|
502
510
|
const imageCaptured = success && record._is_image_marker === true;
|