@causyne/agent 1.20.13 → 1.20.15
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/package.json +1 -1
- package/src/SmartTools.js +33 -0
- package/src/SmartTools.ts +37 -0
- package/src/acp/client.js +157 -4
- package/src/acp/client.ts +152 -5
- package/src/agentLoop.js +857 -178
- package/src/agentLoop.ts +865 -183
- package/src/browser/browserRuntime.js +8 -1
- package/src/browser/browserRuntime.ts +8 -1
- package/src/browser/causyneBrowser.js +20 -4
- package/src/browser/causyneBrowser.ts +20 -4
- package/src/browser/urlPolicy.js +35 -0
- package/src/browser/urlPolicy.ts +34 -0
- package/src/cliMode.js +6 -2
- package/src/commands.js +14 -0
- package/src/contextManager.d.ts +1 -0
- package/src/core/contextCompactor.js +277 -0
- package/src/core/contextCompactor.ts +353 -0
- package/src/decideTools.js +157 -0
- package/src/decideTools.ts +195 -0
- package/src/decisionPolicy.js +5 -3
- package/src/decisionPolicy.ts +5 -3
- package/src/implementationPlan.js +284 -0
- package/src/implementationPlan.ts +275 -0
- package/src/observer/coldObserver.js +10 -4
- package/src/observer/coldObserver.ts +15 -7
- package/src/observer/evidence.js +11 -5
- package/src/observer/evidence.ts +13 -6
- package/src/observer.js +196 -0
- package/src/observer.ts +287 -0
- package/src/providers/acp.js +362 -109
- package/src/providers/acp.ts +359 -111
- package/src/providers/antigravity.js +133 -105
- package/src/providers/antigravity.ts +130 -109
- package/src/providers/base.d.ts +3 -0
- package/src/providers/budgetEnforcer.js +23 -2
- package/src/providers/budgetEnforcer.ts +20 -5
- package/src/provisioning/capabilityProvisioner.js +14 -10
- package/src/sandbox.js +4 -2
- package/src/saveTools.js +146 -0
- package/src/saveTools.ts +169 -0
- package/src/session/cachePressure.js +77 -0
- package/src/session/cachePressure.ts +122 -0
- package/src/smartToolsUse.js +96 -15
- package/src/smartToolsUse.ts +133 -15
- package/src/taskShape.js +7 -7
- package/src/taskShape.ts +7 -7
- package/src/timeMachine.js +55 -20
- package/src/timeMachine.ts +64 -20
- package/src/toolPacks.js +217 -310
- package/src/toolPacks.ts +505 -0
- package/src/tools/deferredMcpSearch.js +21 -13
- package/src/tools/deferredMcpSearch.ts +23 -15
- package/src/tools/updatePlan.js +2 -2
- package/src/tools/updatePlan.ts +2 -2
- package/src/toolsList.js +203 -0
- package/src/toolsList.ts +224 -0
- package/src/tui/chatRenderer.js +49 -14
- package/src/tui/codeStreamRenderer.js +16 -5
- package/src/tui/codeStreamRenderer.ts +14 -4
- package/src/tui/prompt.js +4 -2
- package/src/tui/sessionSidebar.js +10 -2
- package/src/tui/sessionSidebar.ts +10 -3
- package/src/tui/stageSurface.js +27 -1
- package/src/tui/text.d.ts +1 -0
- package/src/tui/turnRail.js +274 -0
- package/src/tui/turnRail.ts +334 -0
- package/src/types/contracts.ts +103 -0
- package/src/verificationPlan.js +141 -0
- package/src/verificationPlan.ts +166 -0
- package/src/toolPacks.d.ts +0 -10
|
@@ -57,3 +57,278 @@ export function summarizePlan(plan: readonly PlanStep[]): string {
|
|
|
57
57
|
return `${completed}/${plan.length} completed${active ? `; in progress: ${active.step}` : ''}`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
export function normalizePeerPlanEntries(value: unknown): PlanUpdate | null {
|
|
61
|
+
if (!value) return null;
|
|
62
|
+
let rawList: unknown[] | null = null;
|
|
63
|
+
let explanation = '';
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
rawList = value;
|
|
66
|
+
} else if (typeof value === 'object') {
|
|
67
|
+
const obj = value as Record<string, unknown>;
|
|
68
|
+
if (typeof obj.explanation === 'string') {
|
|
69
|
+
explanation = obj.explanation.replace(/\s+/g, ' ').trim().slice(0, 500);
|
|
70
|
+
}
|
|
71
|
+
const candidate = obj.plan ?? obj.todos ?? obj.entries ?? obj.steps ?? obj.items ?? obj.tasks
|
|
72
|
+
?? (obj.metadata && typeof obj.metadata === 'object' ? (obj.metadata as Record<string, unknown>).todos : undefined);
|
|
73
|
+
if (Array.isArray(candidate)) {
|
|
74
|
+
rawList = candidate;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!rawList || rawList.length === 0) return null;
|
|
78
|
+
|
|
79
|
+
const ids = new Set<string>();
|
|
80
|
+
let activeSeen = false;
|
|
81
|
+
const steps: PlanStep[] = [];
|
|
82
|
+
|
|
83
|
+
for (let i = 0; i < Math.min(rawList.length, MAX_STEPS); i++) {
|
|
84
|
+
const raw = rawList[i];
|
|
85
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) continue;
|
|
86
|
+
const item = raw as Record<string, unknown>;
|
|
87
|
+
const rawText = item.step ?? item.content ?? item.text ?? item.title ?? item.name ?? item.description;
|
|
88
|
+
if (typeof rawText !== 'string') continue;
|
|
89
|
+
const step = rawText.replace(/\s+/g, ' ').trim().slice(0, 240);
|
|
90
|
+
if (!step) continue;
|
|
91
|
+
|
|
92
|
+
const baseId = typeof item.id === 'string' && item.id.trim()
|
|
93
|
+
? item.id.replace(/\s+/g, ' ').trim().slice(0, 56)
|
|
94
|
+
: `step-${steps.length + 1}`;
|
|
95
|
+
let id = baseId;
|
|
96
|
+
let suffix = 2;
|
|
97
|
+
while (ids.has(id)) {
|
|
98
|
+
id = `${baseId}-${suffix++}`;
|
|
99
|
+
}
|
|
100
|
+
ids.add(id);
|
|
101
|
+
|
|
102
|
+
const rawStatus = String(item.status ?? item.state ?? 'pending').toLowerCase().trim();
|
|
103
|
+
let status: PlanStatus = 'pending';
|
|
104
|
+
if (rawStatus === 'completed' || rawStatus === 'done' || rawStatus === 'complete' || rawStatus === 'finished') {
|
|
105
|
+
status = 'completed';
|
|
106
|
+
} else if (rawStatus === 'in_progress' || rawStatus === 'in-progress' || rawStatus === 'in progress' || rawStatus === 'active' || rawStatus === 'running' || rawStatus === 'working') {
|
|
107
|
+
status = 'in_progress';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (status === 'in_progress') {
|
|
111
|
+
if (activeSeen) {
|
|
112
|
+
status = 'pending';
|
|
113
|
+
} else {
|
|
114
|
+
activeSeen = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
steps.push({ id, step, status });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (steps.length === 0) return null;
|
|
122
|
+
if (!activeSeen && steps.some(s => s.status === 'pending')) {
|
|
123
|
+
const firstPending = steps.find(s => s.status === 'pending');
|
|
124
|
+
if (firstPending) firstPending.status = 'in_progress';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { explanation, plan: steps };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function extractToolCallJsonObjects(text: string): Array<Record<string, unknown>> {
|
|
131
|
+
const results: Array<Record<string, unknown>> = [];
|
|
132
|
+
if (!text || typeof text !== 'string') return results;
|
|
133
|
+
|
|
134
|
+
const tagRegex = /<tool_call>/gi;
|
|
135
|
+
let tagMatch: RegExpExecArray | null;
|
|
136
|
+
while ((tagMatch = tagRegex.exec(text)) !== null) {
|
|
137
|
+
const startSearch = tagMatch.index + tagMatch[0].length;
|
|
138
|
+
const braceStart = text.indexOf('{', startSearch);
|
|
139
|
+
if (braceStart === -1) continue;
|
|
140
|
+
// Ensure only whitespace separates <tool_call> and '{'
|
|
141
|
+
if (text.slice(startSearch, braceStart).trim().length > 0) continue;
|
|
142
|
+
|
|
143
|
+
let depth = 0;
|
|
144
|
+
let inString = false;
|
|
145
|
+
let escaped = false;
|
|
146
|
+
let endBrace = -1;
|
|
147
|
+
for (let i = braceStart; i < text.length; i++) {
|
|
148
|
+
const ch = text[i];
|
|
149
|
+
if (inString) {
|
|
150
|
+
if (escaped) {
|
|
151
|
+
escaped = false;
|
|
152
|
+
} else if (ch === '\\') {
|
|
153
|
+
escaped = true;
|
|
154
|
+
} else if (ch === '"') {
|
|
155
|
+
inString = false;
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
if (ch === '"') {
|
|
159
|
+
inString = true;
|
|
160
|
+
} else if (ch === '{') {
|
|
161
|
+
depth++;
|
|
162
|
+
} else if (ch === '}') {
|
|
163
|
+
depth--;
|
|
164
|
+
if (depth === 0) {
|
|
165
|
+
endBrace = i;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (endBrace !== -1) {
|
|
173
|
+
const candidate = text.slice(braceStart, endBrace + 1);
|
|
174
|
+
try {
|
|
175
|
+
const parsed = JSON.parse(candidate);
|
|
176
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
177
|
+
results.push(parsed as Record<string, unknown>);
|
|
178
|
+
tagRegex.lastIndex = endBrace + 1;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
// Fall through to suffix healing below
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Unclosed or truncated JSON after <tool_call>: strip trailing XML/DSML closing tags and heal
|
|
187
|
+
const nextTagIndex = text.indexOf('<tool_call>', braceStart + 1);
|
|
188
|
+
const sliceEnd = nextTagIndex === -1 ? text.length : nextTagIndex;
|
|
189
|
+
const rawSlice = text
|
|
190
|
+
.slice(braceStart, sliceEnd)
|
|
191
|
+
.replace(/(?:\s*<\/?(?:tool_call|[||]DSML[||][^>]*|invoke|parameter|calls|function_calls)>)+[\s\S]*$/i, '')
|
|
192
|
+
.trim();
|
|
193
|
+
for (const suffix of ['', '}', '}}', '}}}', '"}', '"}}', '"}}}', '"}]}}', '"]}}', '"]}}}']) {
|
|
194
|
+
try {
|
|
195
|
+
const parsed = JSON.parse(rawSlice + suffix);
|
|
196
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
197
|
+
results.push(parsed as Record<string, unknown>);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
} catch {
|
|
201
|
+
// try next suffix
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (results.length === 0) {
|
|
207
|
+
const dsmlInvokeRegex = /<[||]DSML[||]\s*invoke\s+name="([^"]+)"[^>]*>([\s\S]*?)<\/[||]DSML[||]\s*invoke>/gi;
|
|
208
|
+
let invokeMatch: RegExpExecArray | null;
|
|
209
|
+
while ((invokeMatch = dsmlInvokeRegex.exec(text)) !== null) {
|
|
210
|
+
const name = (invokeMatch[1] || '').trim();
|
|
211
|
+
const body = invokeMatch[2] || '';
|
|
212
|
+
if (!name) continue;
|
|
213
|
+
const args: Record<string, unknown> = {};
|
|
214
|
+
const paramRegex = /<[||]DSML[||]\s*parameter\s+name="([^"]+)"[^>]*>([\s\S]*?)<\/[||]DSML[||]\s*parameter>/gi;
|
|
215
|
+
let paramMatch: RegExpExecArray | null;
|
|
216
|
+
while ((paramMatch = paramRegex.exec(body)) !== null) {
|
|
217
|
+
const key = (paramMatch[1] || '').trim();
|
|
218
|
+
const valRaw = (paramMatch[2] || '').trim();
|
|
219
|
+
if (!key) continue;
|
|
220
|
+
try {
|
|
221
|
+
args[key] = JSON.parse(valRaw);
|
|
222
|
+
} catch {
|
|
223
|
+
args[key] = valRaw;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
results.push({ name, arguments: args });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (results.length === 0) {
|
|
231
|
+
const fenceRegex = /```(?:tool_call|json)?\s*(\{[\s\S]*?"name"\s*:\s*[\s\S]*?\})\s*```/g;
|
|
232
|
+
let fenceMatch: RegExpExecArray | null;
|
|
233
|
+
while ((fenceMatch = fenceRegex.exec(text)) !== null) {
|
|
234
|
+
try {
|
|
235
|
+
const parsed = JSON.parse((fenceMatch[1] || '').trim());
|
|
236
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
237
|
+
results.push(parsed as Record<string, unknown>);
|
|
238
|
+
}
|
|
239
|
+
} catch {
|
|
240
|
+
// ignore invalid fence
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return results;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function stripToolCallMarkup(text: string): string {
|
|
249
|
+
if (!text || typeof text !== 'string') return '';
|
|
250
|
+
return text
|
|
251
|
+
.replace(/<tool_call>[\s\S]*?(?:<\/tool_call>|(?:\s*<\/?[||]DSML[||][^>]*>)+|$)/gi, '')
|
|
252
|
+
.replace(/<[||]DSML[||][\s\S]*?(?:<\/[||]DSML[||]\s*calls>|$)/gi, '')
|
|
253
|
+
.replace(/(?:\s*<\/?[||]DSML[||][^>]*>)+/gi, '')
|
|
254
|
+
.trim();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function stripThinkBlocks(text: string): string {
|
|
258
|
+
if (!text || typeof text !== 'string') return '';
|
|
259
|
+
return text
|
|
260
|
+
.replace(/<(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>[\s\S]*?(?:<\/(?:think|thought|reasoning|thinking|REASONING_SCRATCHPAD)>|$)/gi, '')
|
|
261
|
+
.trim();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function extractLivePlanFromText(text: string, allowTrailing = false): PlanUpdate | null {
|
|
265
|
+
if (!text || typeof text !== 'string') return null;
|
|
266
|
+
const cleanText = text.replace(/\r\n/g, '\n');
|
|
267
|
+
|
|
268
|
+
// 1. Check for inline <tool_call>{"name": "update_plan" | "todowrite", ...}</tool_call> (including DSML-closed blocks)
|
|
269
|
+
let latestToolPlan: PlanUpdate | null = null;
|
|
270
|
+
for (const parsed of extractToolCallJsonObjects(cleanText)) {
|
|
271
|
+
try {
|
|
272
|
+
const toolName = String(parsed?.name || parsed?.tool || '').toLowerCase().trim();
|
|
273
|
+
if (toolName === 'update_plan' || toolName === 'todowrite' || toolName === 'todo_write') {
|
|
274
|
+
const rawArgs = typeof parsed.arguments === 'string'
|
|
275
|
+
? JSON.parse(parsed.arguments)
|
|
276
|
+
: (parsed.arguments ?? parsed.parameters ?? parsed.input ?? parsed);
|
|
277
|
+
const normalized = normalizePeerPlanEntries(rawArgs);
|
|
278
|
+
if (normalized) latestToolPlan = normalized;
|
|
279
|
+
}
|
|
280
|
+
} catch {
|
|
281
|
+
// Ignore partial or invalid JSON inside <tool_call>
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (latestToolPlan) return latestToolPlan;
|
|
285
|
+
|
|
286
|
+
// 2. Check for an explicit Plan: / Implementation Plan: numbered or checkbox list in reasoning/text
|
|
287
|
+
const planHeaderRegex = /(?:^|\n)[ \t]*(?:#{1,4}[ \t]+|\*{1,2})?(?:(?:here\s+is\s+(?:the\s+)?|our\s+|my\s+|action\s+|execution\s+|implementation\s+)?(?:plan|rencana|langkah(?:-langkah)?|roadmap|steps))(?:\*{1,2})?[ \t]*:?[ \t]*\n((?:[ \t]*(?:\d+[.)]|[-*•][ \t]+\[[ xX✓▸>-]\])[ \t]+[^\n]+\n?){2,12})/gi;
|
|
288
|
+
let headerMatch: RegExpExecArray | null;
|
|
289
|
+
let latestBlock = '';
|
|
290
|
+
let latestEndIndex = -1;
|
|
291
|
+
while ((headerMatch = planHeaderRegex.exec(cleanText)) !== null) {
|
|
292
|
+
latestBlock = headerMatch[1] || '';
|
|
293
|
+
latestEndIndex = headerMatch.index + headerMatch[0].length;
|
|
294
|
+
}
|
|
295
|
+
if (!latestBlock) return null;
|
|
296
|
+
|
|
297
|
+
// While streaming, verify that the captured block ended cleanly with a newline
|
|
298
|
+
if (!allowTrailing && latestEndIndex > 0) {
|
|
299
|
+
const remainder = cleanText.slice(latestEndIndex);
|
|
300
|
+
if (remainder.length === 0 && !latestBlock.endsWith('\n')) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const lines = latestBlock
|
|
306
|
+
.split('\n')
|
|
307
|
+
.map(l => l.trim())
|
|
308
|
+
.filter(Boolean);
|
|
309
|
+
if (lines.length < 2) return null;
|
|
310
|
+
|
|
311
|
+
const rawItems: Array<{ id: string; step: string; status: PlanStatus }> = [];
|
|
312
|
+
for (let i = 0; i < Math.min(lines.length, MAX_STEPS); i++) {
|
|
313
|
+
const line = lines[i]!;
|
|
314
|
+
const itemMatch = /^(?:(\d+)[.)]|[-*•]\s*\[([ xX✓▸>-])\])\s+(.+)$/.exec(line);
|
|
315
|
+
if (!itemMatch) continue;
|
|
316
|
+
const checkMark = (itemMatch[2] || '').toLowerCase();
|
|
317
|
+
const stepText = (itemMatch[3] || '').replace(/\s+/g, ' ').trim().slice(0, 240);
|
|
318
|
+
if (!stepText || stepText.length < 4) continue;
|
|
319
|
+
const status: PlanStatus = checkMark === 'x' || checkMark === '✓'
|
|
320
|
+
? 'completed'
|
|
321
|
+
: checkMark === '>' || checkMark === '▸' || checkMark === '-'
|
|
322
|
+
? 'in_progress'
|
|
323
|
+
: 'pending';
|
|
324
|
+
rawItems.push({
|
|
325
|
+
id: `step-${rawItems.length + 1}`,
|
|
326
|
+
step: stepText,
|
|
327
|
+
status
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (rawItems.length < 2) return null;
|
|
332
|
+
return normalizePeerPlanEntries({ plan: rawItems });
|
|
333
|
+
}
|
|
334
|
+
|
|
@@ -35,7 +35,9 @@ const TESTS_CLAIM = /\b(?:all\s+)?tests?\b[^.\n]{0,40}\b(?:pass|passed|passing|g
|
|
|
35
35
|
const BUILD_CLAIM = /\b(?:build|typecheck|types|lint|compilation)\b[^.\n]{0,40}\b(?:pass|passed|passing|clean|succeed|succeeded)\b/i;
|
|
36
36
|
const MUTATING_TOOLS = new Set([
|
|
37
37
|
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move',
|
|
38
|
-
'sysRun', 'sysRunBg', 'terminal_persistent_shell', 'gitOp'
|
|
38
|
+
'sysRun', 'sysRunBg', 'terminal_persistent_shell', 'gitOp',
|
|
39
|
+
'write_file', 'write_to_file', 'edit_file', 'replace_file_content',
|
|
40
|
+
'multi_replace_file_content', 'write', 'edit', 'multiedit', 'bash', 'execute'
|
|
39
41
|
]);
|
|
40
42
|
function normalizeMode(value) {
|
|
41
43
|
if (value === 'deterministic')
|
|
@@ -376,15 +378,16 @@ export class ColdObserver {
|
|
|
376
378
|
return { verified: true, overconfident: false, confidence: 0, discrepancy: '', coldDirective: '' };
|
|
377
379
|
}
|
|
378
380
|
const journal = turnState.taskId ? this.journals.get(turnState.taskId) : undefined;
|
|
381
|
+
const isToolOutcome = (entry) => (entry !== null && typeof entry === 'object' && typeof entry.at === 'number');
|
|
379
382
|
const outcomes = journal && journal.length > 0
|
|
380
383
|
? journal
|
|
381
|
-
: turnState.toolHistory.map(normalizeOutcome);
|
|
384
|
+
: turnState.toolHistory.map((item) => isToolOutcome(item) ? item : normalizeOutcome(item));
|
|
382
385
|
const caveat = hasHonestCaveat(claim);
|
|
383
386
|
const lastFailure = outcomes.findLastIndex((outcome) => !outcome.success);
|
|
384
387
|
const successAfterFailure = lastFailure >= 0
|
|
385
388
|
&& outcomes.slice(lastFailure + 1).some((outcome) => outcome.success);
|
|
386
389
|
const isCodeMutation = (outcome) => outcome.success
|
|
387
|
-
&& ['fs_write', 'fs_edit', 'MultiEdit'].includes(outcome.tool)
|
|
390
|
+
&& ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content', 'write', 'edit', 'multiedit'].includes(outcome.tool)
|
|
388
391
|
&& /\.(?:[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);
|
|
389
392
|
const lastCodeChange = outcomes.findLastIndex(isCodeMutation);
|
|
390
393
|
const checks = outcomes.slice(lastCodeChange + 1);
|
|
@@ -395,6 +398,9 @@ export class ColdObserver {
|
|
|
395
398
|
const modifiedCode = lastCodeChange >= 0;
|
|
396
399
|
const declarativeOnly = modifiedCode && outcomes.filter(isCodeMutation).every(outcome => /\.(?:html|css)$/i.test(outcome.path));
|
|
397
400
|
const hasRenderedCheck = checks.some(outcome => outcome.success && outcome.rendered === true);
|
|
401
|
+
const hasDeclarativeInspection = checks.some(outcome => outcome.success
|
|
402
|
+
&& ['fs_read', 'read_file', 'view_file', 'read', 'cat'].includes(outcome.tool)
|
|
403
|
+
&& /\.(?:html|css)$/i.test(outcome.path));
|
|
398
404
|
let overconfident = false;
|
|
399
405
|
let confidence = 0;
|
|
400
406
|
let discrepancy = '';
|
|
@@ -417,7 +423,7 @@ export class ColdObserver {
|
|
|
417
423
|
discrepancy = 'claimed a passing build or check without a successful verification command';
|
|
418
424
|
coldDirective = '[OBSERVER] You claimed that a build or check passed, but no successful verification command appears in this task. Run the relevant command and report its actual result, or state that it is unverified.';
|
|
419
425
|
}
|
|
420
|
-
else if (!caveat && modifiedCode && !hasBuildRun && !hasTestRun && !(declarativeOnly && hasRenderedCheck)) {
|
|
426
|
+
else if (!caveat && modifiedCode && !hasBuildRun && !hasTestRun && !(declarativeOnly && (hasRenderedCheck || hasDeclarativeInspection))) {
|
|
421
427
|
overconfident = true;
|
|
422
428
|
confidence = 0.72;
|
|
423
429
|
discrepancy = 'code was modified without a successful test or syntax check';
|
|
@@ -57,7 +57,7 @@ export interface TurnState {
|
|
|
57
57
|
taskId?: string;
|
|
58
58
|
userPrompt: string;
|
|
59
59
|
agentClaim: string;
|
|
60
|
-
toolHistory: TurnToolEvidence[];
|
|
60
|
+
toolHistory: readonly TurnToolEvidence[] | readonly ToolOutcome[];
|
|
61
61
|
stepsCompleted: number;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -97,7 +97,9 @@ const BUILD_CLAIM = /\b(?:build|typecheck|types|lint|compilation)\b[^.\n]{0,40}\
|
|
|
97
97
|
|
|
98
98
|
const MUTATING_TOOLS = new Set([
|
|
99
99
|
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move',
|
|
100
|
-
'sysRun', 'sysRunBg', 'terminal_persistent_shell', 'gitOp'
|
|
100
|
+
'sysRun', 'sysRunBg', 'terminal_persistent_shell', 'gitOp',
|
|
101
|
+
'write_file', 'write_to_file', 'edit_file', 'replace_file_content',
|
|
102
|
+
'multi_replace_file_content', 'write', 'edit', 'multiedit', 'bash', 'execute'
|
|
101
103
|
]);
|
|
102
104
|
|
|
103
105
|
function normalizeMode(value: unknown): ObserverMode | null {
|
|
@@ -212,7 +214,7 @@ function hasHonestCaveat(claim: string): boolean {
|
|
|
212
214
|
return HONEST_CAVEATS.some((pattern) => pattern.test(claim));
|
|
213
215
|
}
|
|
214
216
|
|
|
215
|
-
function failureSummary(outcomes: ToolOutcome[]): string {
|
|
217
|
+
function failureSummary(outcomes: readonly ToolOutcome[]): string {
|
|
216
218
|
const last = [...outcomes].reverse().find((outcome) => !outcome.success);
|
|
217
219
|
if (!last) return 'a recent tool call failed';
|
|
218
220
|
const detail = last.error || last.command || last.path || 'no error text';
|
|
@@ -451,15 +453,18 @@ export class ColdObserver {
|
|
|
451
453
|
}
|
|
452
454
|
|
|
453
455
|
const journal = turnState.taskId ? this.journals.get(turnState.taskId) : undefined;
|
|
454
|
-
const
|
|
456
|
+
const isToolOutcome = (entry: unknown): entry is ToolOutcome => (
|
|
457
|
+
entry !== null && typeof entry === 'object' && typeof (entry as ToolOutcome).at === 'number'
|
|
458
|
+
);
|
|
459
|
+
const outcomes: readonly ToolOutcome[] = journal && journal.length > 0
|
|
455
460
|
? journal
|
|
456
|
-
: turnState.toolHistory.map(normalizeOutcome);
|
|
461
|
+
: turnState.toolHistory.map((item) => isToolOutcome(item) ? item : normalizeOutcome(item));
|
|
457
462
|
const caveat = hasHonestCaveat(claim);
|
|
458
463
|
const lastFailure = outcomes.findLastIndex((outcome) => !outcome.success);
|
|
459
464
|
const successAfterFailure = lastFailure >= 0
|
|
460
465
|
&& outcomes.slice(lastFailure + 1).some((outcome) => outcome.success);
|
|
461
466
|
const isCodeMutation = (outcome: ToolOutcome): boolean => outcome.success
|
|
462
|
-
&& ['fs_write', 'fs_edit', 'MultiEdit'].includes(outcome.tool)
|
|
467
|
+
&& ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content', 'write', 'edit', 'multiedit'].includes(outcome.tool)
|
|
463
468
|
&& /\.(?:[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);
|
|
464
469
|
const lastCodeChange = outcomes.findLastIndex(isCodeMutation);
|
|
465
470
|
const checks = outcomes.slice(lastCodeChange + 1);
|
|
@@ -470,6 +475,9 @@ export class ColdObserver {
|
|
|
470
475
|
const modifiedCode = lastCodeChange >= 0;
|
|
471
476
|
const declarativeOnly = modifiedCode && outcomes.filter(isCodeMutation).every(outcome => /\.(?:html|css)$/i.test(outcome.path));
|
|
472
477
|
const hasRenderedCheck = checks.some(outcome => outcome.success && outcome.rendered === true);
|
|
478
|
+
const hasDeclarativeInspection = checks.some(outcome => outcome.success
|
|
479
|
+
&& ['fs_read', 'read_file', 'view_file', 'read', 'cat'].includes(outcome.tool)
|
|
480
|
+
&& /\.(?:html|css)$/i.test(outcome.path));
|
|
473
481
|
|
|
474
482
|
let overconfident = false;
|
|
475
483
|
let confidence = 0;
|
|
@@ -491,7 +499,7 @@ export class ColdObserver {
|
|
|
491
499
|
confidence = 0.82;
|
|
492
500
|
discrepancy = 'claimed a passing build or check without a successful verification command';
|
|
493
501
|
coldDirective = '[OBSERVER] You claimed that a build or check passed, but no successful verification command appears in this task. Run the relevant command and report its actual result, or state that it is unverified.';
|
|
494
|
-
} else if (!caveat && modifiedCode && !hasBuildRun && !hasTestRun && !(declarativeOnly && hasRenderedCheck)) {
|
|
502
|
+
} else if (!caveat && modifiedCode && !hasBuildRun && !hasTestRun && !(declarativeOnly && (hasRenderedCheck || hasDeclarativeInspection))) {
|
|
495
503
|
overconfident = true;
|
|
496
504
|
confidence = 0.72;
|
|
497
505
|
discrepancy = 'code was modified without a successful test or syntax check';
|
package/src/observer/evidence.js
CHANGED
|
@@ -101,7 +101,7 @@ function resolveTarget(workspaceRoot, raw) {
|
|
|
101
101
|
return { lexical, physical, inside };
|
|
102
102
|
}
|
|
103
103
|
function pathArgument(args) {
|
|
104
|
-
for (const key of ['path', 'file_path', 'targetFile', 'file', 'source', 'destination', 'target', 'cwd']) {
|
|
104
|
+
for (const key of ['path', 'filePath', 'Path', 'file_path', 'targetFile', 'target_path', 'filename', 'file', 'source', 'destination', 'target', 'cwd']) {
|
|
105
105
|
const value = args[key];
|
|
106
106
|
if (typeof value === 'string' && value.trim())
|
|
107
107
|
return value.trim();
|
|
@@ -423,10 +423,15 @@ export function outcomeFromResult(tool, args, result, at) {
|
|
|
423
423
|
? args.command
|
|
424
424
|
: typeof args.cmd === 'string' ? args.cmd : '';
|
|
425
425
|
const browserData = Array.isArray(record.data) ? record.data : [];
|
|
426
|
-
const
|
|
426
|
+
const observedImage = success && record._is_image_marker === true && record.visionDelivered !== false;
|
|
427
|
+
const rendered = success && (observedImage || (tool === 'browser_act' && browserData.some((item) => {
|
|
428
|
+
if (!item || typeof item !== 'object')
|
|
429
|
+
return false;
|
|
427
430
|
const action = item;
|
|
428
|
-
return
|
|
429
|
-
|
|
431
|
+
return action.success !== false && !action.error
|
|
432
|
+
&& ['preview', 'snapshot', 'scrape', 'screenshot'].includes(action.action || '')
|
|
433
|
+
&& Array.isArray(action.data?.runtimeErrors) && action.data.runtimeErrors.length === 0;
|
|
434
|
+
})));
|
|
430
435
|
return {
|
|
431
436
|
tool,
|
|
432
437
|
args: boundedArgs(args),
|
|
@@ -436,6 +441,7 @@ export function outcomeFromResult(tool, args, result, at) {
|
|
|
436
441
|
command: command.slice(0, 600),
|
|
437
442
|
path: pathArgument(args).slice(0, 400),
|
|
438
443
|
at,
|
|
439
|
-
...(rendered ? { rendered: true } : {})
|
|
444
|
+
...(rendered ? { rendered: true } : {}),
|
|
445
|
+
...(observedImage ? { observedImage: true } : {})
|
|
440
446
|
};
|
|
441
447
|
}
|
package/src/observer/evidence.ts
CHANGED
|
@@ -39,6 +39,7 @@ export interface ToolOutcome {
|
|
|
39
39
|
path: string;
|
|
40
40
|
at: number;
|
|
41
41
|
rendered?: boolean;
|
|
42
|
+
observedImage?: boolean;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const SEVERITY_WEIGHT: Record<RiskSeverity, number> = {
|
|
@@ -154,7 +155,7 @@ function resolveTarget(workspaceRoot: string, raw: string): { lexical: string; p
|
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
function pathArgument(args: Record<string, unknown>): string {
|
|
157
|
-
for (const key of ['path', 'file_path', 'targetFile', 'file', 'source', 'destination', 'target', 'cwd']) {
|
|
158
|
+
for (const key of ['path', 'filePath', 'Path', 'file_path', 'targetFile', 'target_path', 'filename', 'file', 'source', 'destination', 'target', 'cwd']) {
|
|
158
159
|
const value = args[key];
|
|
159
160
|
if (typeof value === 'string' && value.trim()) return value.trim();
|
|
160
161
|
}
|
|
@@ -488,10 +489,15 @@ export function outcomeFromResult(tool: string, args: Record<string, unknown>, r
|
|
|
488
489
|
? args.command
|
|
489
490
|
: typeof args.cmd === 'string' ? args.cmd : '';
|
|
490
491
|
const browserData = Array.isArray(record.data) ? record.data : [];
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
492
|
+
const observedImage = success && record._is_image_marker === true && record.visionDelivered !== false;
|
|
493
|
+
const rendered = success && (observedImage || (tool === 'browser_act' && browserData.some((item: unknown) => {
|
|
494
|
+
if (!item || typeof item !== 'object') return false;
|
|
495
|
+
const action = item as { action?: string; success?: boolean; error?: unknown; data?: { runtimeErrors?: unknown[] } };
|
|
496
|
+
return action.success !== false && !action.error
|
|
497
|
+
&& ['preview', 'snapshot', 'scrape', 'screenshot'].includes(action.action || '')
|
|
498
|
+
&& Array.isArray(action.data?.runtimeErrors) && action.data.runtimeErrors.length === 0;
|
|
499
|
+
})));
|
|
500
|
+
|
|
495
501
|
return {
|
|
496
502
|
tool,
|
|
497
503
|
args: boundedArgs(args),
|
|
@@ -501,6 +507,7 @@ export function outcomeFromResult(tool: string, args: Record<string, unknown>, r
|
|
|
501
507
|
command: command.slice(0, 600),
|
|
502
508
|
path: pathArgument(args).slice(0, 400),
|
|
503
509
|
at,
|
|
504
|
-
...(rendered ? { rendered: true } : {})
|
|
510
|
+
...(rendered ? { rendered: true } : {}),
|
|
511
|
+
...(observedImage ? { observedImage: true } : {})
|
|
505
512
|
};
|
|
506
513
|
}
|