@causyne/agent 1.20.78 → 1.20.79

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.78",
3
+ "version": "1.20.79",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
package/src/agentLoop.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { clearSysRunCache } from './tools/sysRun.js';
2
+ import { NetworkHostGuard } from './reliability/networkHostGuard.js';
3
+ import { inspectRequestedImageAssets } from './reliability/assetEvidence.js';
4
+ import { inspect3DVisualEvidence } from './reliability/visualEvidence.js';
2
5
  import { getProcessEntitlementGate, EntitlementAccessError } from './licensing/entitlements.js';
3
6
  import { PEER_COLLABORATION_POLICY } from './providers/collaborationPolicy.js';
4
7
  import { createHash, randomUUID } from 'crypto';
@@ -542,6 +545,8 @@ export class AgentLoop {
542
545
  this.consecutiveCommands = 0;
543
546
  this.circuitBreakerUnlocked = false;
544
547
  this.stopRequested = false;
548
+ this._causyneTaskOutcome = 'incomplete';
549
+ this._networkHostGuard = new NetworkHostGuard();
545
550
  this.pendingApprovals = new Map(); // Maps toolCallId -> resolve function
546
551
  this.waitForDecision = async () => null;
547
552
  this._decisionAnswers = new Map();
@@ -1573,6 +1578,8 @@ export class AgentLoop {
1573
1578
  // CAUSYNE_ENTITLEMENT_V1: outer lifecycle wrapper, no agent-orchestration rewrite.
1574
1579
  async run() {
1575
1580
  this.rearmAbortController();
1581
+ this._causyneTaskOutcome = 'incomplete';
1582
+ this._networkHostGuard.reset();
1576
1583
  const gate = getProcessEntitlementGate();
1577
1584
  const onEntitlementBlocked = (error) => {
1578
1585
  if (this.stopRequested)
@@ -3077,74 +3084,23 @@ You are operating in a text-and-code modality without direct image pixel renderi
3077
3084
  const isAcpTurnNotice = typeof contentText === 'string'
3078
3085
  && (contentText.startsWith('Antigravity executed:') || /^Turn completed by .+ over ACP\.$/i.test(contentText.trim()));
3079
3086
  if ((hasExternalActions || isAcpTurnNotice) && (isIncompleteTurn || isMidTaskProgress || isAcpTurnNotice)) {
3080
- const cleanSubstantive = (text) => {
3081
- if (typeof text !== 'string')
3082
- return '';
3083
- return text
3087
+ if (isAcpTurnNotice && !isIncompleteTurn && !isMidTaskProgress) {
3088
+ // A completed peer turn must pass the normal host verification
3089
+ // gates below. The ACP notice itself is never completion proof.
3090
+ }
3091
+ else {
3092
+ const partial = String(contentText || '')
3084
3093
  .replace(/^Antigravity executed:[^\n]*\n*/i, '')
3085
3094
  .replace(/^Turn completed by [^\n]+ over ACP\.\s*/i, '')
3086
3095
  .trim();
3087
- };
3088
- const currentSubstantive = cleanSubstantive(contentText);
3089
- if (currentSubstantive.length >= 60) {
3090
- this.emitEvent({
3091
- type: 'agent_message',
3092
- content: currentSubstantive
3093
- });
3094
- this.emitEvent({
3095
- type: 'status',
3096
- message: 'Task completed with verified deliverables.'
3097
- });
3098
- this.memoryManager.saveHistory(this.messages);
3099
- break;
3100
- }
3101
- const recentSubstantiveAssistant = [...this.messages].reverse().find(m => m.role === 'assistant'
3102
- && typeof m.content === 'string'
3103
- && cleanSubstantive(m.content).length >= 60);
3104
- if (recentSubstantiveAssistant && typeof recentSubstantiveAssistant.content === 'string') {
3105
- this.emitEvent({
3106
- type: 'agent_message',
3107
- content: cleanSubstantive(recentSubstantiveAssistant.content)
3108
- });
3109
- this.emitEvent({
3110
- type: 'status',
3111
- message: 'Task completed with verified deliverables.'
3112
- });
3113
- this.memoryManager.saveHistory(this.messages);
3114
- break;
3115
- }
3116
- if (isLaunchOnlyPrompt(taskPrompt) && this.stepsCompleted > 0) {
3117
- const launchSummary = 'Project opened in your default browser. Verification checks completed.';
3118
- this.emitEvent({
3119
- type: 'agent_message',
3120
- content: launchSummary
3121
- });
3122
- this.emitEvent({
3123
- type: 'status',
3124
- message: 'Task completed: project launched and verified.'
3125
- });
3126
- this.memoryManager.saveHistory(this.messages);
3127
- break;
3128
- }
3129
- if (this.stepsCompleted > 0) {
3130
- const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
3131
- this.emitEvent({
3132
- type: 'agent_message',
3133
- content: summary
3134
- });
3135
- this.emitEvent({
3136
- type: 'status',
3137
- message: 'Task completed with verified deliverables.'
3138
- });
3096
+ if (partial.length >= 20) {
3097
+ this.emitEvent({ type: 'agent_message', content: partial });
3098
+ }
3099
+ this.emitEvent({ type: 'error', message: 'The peer ended with an incomplete or progress-only turn. ' +
3100
+ 'Actions may have changed files, but completion is not established.' });
3139
3101
  this.memoryManager.saveHistory(this.messages);
3140
3102
  break;
3141
3103
  }
3142
- this.emitEvent({
3143
- type: 'error',
3144
- message: 'The task stopped before completion after repeated incomplete turns without a final response. Work remains unfinished.'
3145
- });
3146
- this.memoryManager.saveHistory(this.messages);
3147
- break;
3148
3104
  }
3149
3105
  if (hasExternalActions && !isIncompleteTurn && !isMidTaskProgress) {
3150
3106
  incompleteTurnContinuations = 0;
@@ -3171,11 +3127,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
3171
3127
  break;
3172
3128
  }
3173
3129
  if (!hasExternalActions && (isIncompleteTurn || failedExternalActions.length > 0 || !contentText.trim())) {
3174
- if (allPlanCompleted || (this.stepsCompleted > 0 && !isIncompleteTurn && failedExternalActions.length === 0)) {
3175
- const planSummary = this._implementationPlan?.length > 0
3176
- ? ` All ${this._implementationPlan.length} plan steps have been executed and verified:\n\n`
3177
- + this._implementationPlan.map((s, idx) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n')
3178
- : ` All verified deliverables and actions are in place (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed).`;
3130
+ if (allPlanCompleted) {
3131
+ const planSummary = ` All ${this._implementationPlan.length} plan steps have been completed and verified:\n\n`
3132
+ + this._implementationPlan.map((s, idx) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n');
3179
3133
  const summary = `Task completed successfully.${planSummary}`;
3180
3134
  this.emitEvent({
3181
3135
  type: 'agent_message',
@@ -3185,40 +3139,20 @@ You are operating in a text-and-code modality without direct image pixel renderi
3185
3139
  type: 'status',
3186
3140
  message: 'Task completed with verified deliverables.'
3187
3141
  });
3142
+ this._causyneTaskOutcome = 'completed';
3188
3143
  this.memoryManager.saveHistory(this.messages);
3189
3144
  break;
3190
3145
  }
3191
- if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2) {
3146
+ if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2 && failedExternalActions.length === 0) {
3192
3147
  incompleteTurnContinuations++;
3193
- this.emitEvent({ type: 'status', message: 'Requesting final deliverable and response...' });
3194
- this.emitEvent({ type: 'agent_activity', activity: 'Synthesizing final deliverable…' });
3195
- this.messages.push({
3196
- role: 'system',
3197
- content: `[TASK COMPLETION MANDATE: You have completed your tool execution steps (${this.stepsCompleted} steps performed). Provide your complete final response, deliverables summary, and conclusions directly to the user now. Do not run any more background commands.]`
3198
- });
3148
+ this.emitEvent({ type: 'status', message: 'Requesting the missing final response…' });
3149
+ this.messages.push({ role: 'system', content: '[FINAL RESPONSE REQUIRED] Report actual completed and incomplete work from tool results. ' +
3150
+ 'Do not call plan steps or file writes proof of verification.' });
3199
3151
  this.memoryManager.saveHistory(this.messages);
3200
3152
  continue;
3201
3153
  }
3202
- if (this.stepsCompleted > 0) {
3203
- const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
3204
- this.emitEvent({
3205
- type: 'agent_message',
3206
- content: summary
3207
- });
3208
- this.emitEvent({
3209
- type: 'status',
3210
- message: 'Task completed with verified deliverables.'
3211
- });
3212
- this.memoryManager.saveHistory(this.messages);
3213
- break;
3214
- }
3215
- if (!contentText.trim()) {
3216
- this.messages.pop();
3217
- }
3218
- this.emitEvent({
3219
- type: 'error',
3220
- message: 'The task stopped before completion after repeated blocked or incomplete turns. Work remains unfinished.'
3221
- });
3154
+ this.emitEvent({ type: 'error', message: 'The task stopped with failed actions, an incomplete turn, or no final response. ' +
3155
+ 'Existing files were preserved; completion was not verified.' });
3222
3156
  this.memoryManager.saveHistory(this.messages);
3223
3157
  break;
3224
3158
  }
@@ -3543,6 +3477,36 @@ You are operating in a text-and-code modality without direct image pixel renderi
3543
3477
  break;
3544
3478
  }
3545
3479
  }
3480
+ // CAUSYNE_RELIABILITY_V1: require real downloaded images
3481
+ // if image acquisition was part of the user's explicit request.
3482
+ const imageAssetEvidence = await inspectRequestedImageAssets({
3483
+ prompt: taskPrompt,
3484
+ workspaceRoot: this.workspaceRoot,
3485
+ webArtifacts: [...this.webArtifacts]
3486
+ });
3487
+ if (!imageAssetEvidence.ok) {
3488
+ this.emitEvent({ type: 'error', message: imageAssetEvidence.reason ||
3489
+ 'Required downloaded website images were not verified.' });
3490
+ this.memoryManager.saveHistory(this.messages);
3491
+ break;
3492
+ }
3493
+ // A preview or DOM snapshot is not proof that a Three.js/WebGL
3494
+ // rendering was actually examined by a vision-capable model.
3495
+ const visualEvidence = inspect3DVisualEvidence(taskPrompt, coldObserver.getToolOutcomes(this.taskId));
3496
+ if (!visualEvidence.ok) {
3497
+ this.emitEvent({ type: 'error', message: visualEvidence.reason ||
3498
+ '3D visual output was not verified.' });
3499
+ this.memoryManager.saveHistory(this.messages);
3500
+ break;
3501
+ }
3502
+ const finalToolOutcomes = coldObserver.getToolOutcomes(this.taskId);
3503
+ const finalToolOutcome = finalToolOutcomes[finalToolOutcomes.length - 1];
3504
+ if (this.stepsCompleted > 0 && finalToolOutcome && !finalToolOutcome.success) {
3505
+ this.emitEvent({ type: 'error', message: `The last observed tool action failed (${finalToolOutcome.tool}). ` +
3506
+ 'Resolve the error or report partial work; no success has been recorded.' });
3507
+ this.memoryManager.saveHistory(this.messages);
3508
+ break;
3509
+ }
3546
3510
  const cleanTerminalContent = (text) => {
3547
3511
  if (typeof text !== 'string')
3548
3512
  return '';
@@ -3626,6 +3590,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
3626
3590
  }
3627
3591
  }
3628
3592
  catch { /* never block completion on session summary recording */ }
3593
+ this._causyneTaskOutcome = 'completed';
3629
3594
  auditLog.log({ event: 'task_complete', taskId: this.taskId, steps: this.stepsCompleted });
3630
3595
  this.emitEvent({ type: 'task_complete', taskId: this.taskId });
3631
3596
  break;
@@ -4043,6 +4008,20 @@ You are operating in a text-and-code modality without direct image pixel renderi
4043
4008
  continue;
4044
4009
  }
4045
4010
  }
4011
+ // CAUSYNE_RELIABILITY_V1: refuse repeated timeouts to one host.
4012
+ // This is not a network authorization rule; sandbox and approval ran above.
4013
+ const networkDecision = this._networkHostGuard.before(functionName, args);
4014
+ if (!networkDecision.allowed) {
4015
+ const error = String(networkDecision.error);
4016
+ const failure = { success: false, error, code: 'NETWORK_HOST_UNAVAILABLE' };
4017
+ coldObserver.recordToolOutcome(this.taskId, functionName, args, failure);
4018
+ this.messages.push({ role: 'tool', tool_call_id: toolCall.id,
4019
+ name: functionName, content: JSON.stringify(failure) });
4020
+ this.emitEvent({ type: 'step_error', tool: functionName,
4021
+ error, toolCallId: toolCall.id });
4022
+ this.memoryManager.saveHistory(this.messages);
4023
+ continue;
4024
+ }
4046
4025
  // P2: snapshot the files this call is about to change, before it runs.
4047
4026
  // Only the mutating fs tools match; everything else returns immediately.
4048
4027
  // Fail-open by contract — this can never block or fail a tool call.
@@ -4091,6 +4070,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
4091
4070
  duration = 0;
4092
4071
  const errorType = this.classifyError(toolError);
4093
4072
  const failure = { success: false, error: String(toolError?.message || toolError) };
4073
+ this._networkHostGuard.after(functionName, args, failure);
4094
4074
  const alternativeRoute = lookupAlternativeStep({
4095
4075
  failedTool: functionName,
4096
4076
  why: failureClass(failure),
@@ -4143,6 +4123,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
4143
4123
  hookFeedback: (postHook.messages || []).join('\n') || undefined
4144
4124
  };
4145
4125
  }
4126
+ this._networkHostGuard.after(functionName, args, result);
4146
4127
  if (result && result.success !== false && !result.error && ['fs_write', 'fs_edit', 'MultiEdit'].includes(functionName)) {
4147
4128
  this.recordWebArtifact(args.path || args.file_path);
4148
4129
  }
package/src/agentLoop.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { clearSysRunCache } from './tools/sysRun.js';
2
+ import { NetworkHostGuard } from './reliability/networkHostGuard.js';
3
+ import { inspectRequestedImageAssets } from './reliability/assetEvidence.js';
4
+ import { inspect3DVisualEvidence } from './reliability/visualEvidence.js';
2
5
  import { getProcessEntitlementGate, EntitlementAccessError } from './licensing/entitlements.js';
3
6
  import { PEER_COLLABORATION_POLICY } from './providers/collaborationPolicy.js';
4
7
  import type { RequestPermissionRequest, RequestPermissionResponse } from './acp/protocol.js';
@@ -640,6 +643,8 @@ export class AgentLoop {
640
643
  this.consecutiveCommands = 0;
641
644
  this.circuitBreakerUnlocked = false;
642
645
  this.stopRequested = false;
646
+ this._causyneTaskOutcome = 'incomplete';
647
+ this._networkHostGuard = new NetworkHostGuard();
643
648
  this.pendingApprovals = new Map(); // Maps toolCallId -> resolve function
644
649
  this.waitForDecision = async () => null;
645
650
  this._decisionAnswers = new Map();
@@ -1640,6 +1645,8 @@ export class AgentLoop {
1640
1645
  // CAUSYNE_ENTITLEMENT_V1: outer lifecycle wrapper, no agent-orchestration rewrite.
1641
1646
  async run() {
1642
1647
  this.rearmAbortController();
1648
+ this._causyneTaskOutcome = 'incomplete';
1649
+ this._networkHostGuard.reset();
1643
1650
  const gate = getProcessEntitlementGate();
1644
1651
  const onEntitlementBlocked = (error: unknown): void => {
1645
1652
  if (this.stopRequested) return;
@@ -3215,83 +3222,24 @@ You are operating in a text-and-code modality without direct image pixel renderi
3215
3222
  && (contentText.startsWith('Antigravity executed:') || /^Turn completed by .+ over ACP\.$/i.test(contentText.trim()));
3216
3223
 
3217
3224
  if ((hasExternalActions || isAcpTurnNotice) && (isIncompleteTurn || isMidTaskProgress || isAcpTurnNotice)) {
3218
- const cleanSubstantive = (text: unknown): string => {
3219
- if (typeof text !== 'string') return '';
3220
- return text
3225
+ if (isAcpTurnNotice && !isIncompleteTurn && !isMidTaskProgress) {
3226
+ // A completed peer turn must pass the normal host verification
3227
+ // gates below. The ACP notice itself is never completion proof.
3228
+ } else {
3229
+ const partial = String(contentText || '')
3221
3230
  .replace(/^Antigravity executed:[^\n]*\n*/i, '')
3222
3231
  .replace(/^Turn completed by [^\n]+ over ACP\.\s*/i, '')
3223
3232
  .trim();
3224
- };
3225
-
3226
- const currentSubstantive = cleanSubstantive(contentText);
3227
- if (currentSubstantive.length >= 60) {
3228
- this.emitEvent({
3229
- type: 'agent_message',
3230
- content: currentSubstantive
3231
- });
3232
- this.emitEvent({
3233
- type: 'status',
3234
- message: 'Task completed with verified deliverables.'
3235
- });
3236
- this.memoryManager.saveHistory(this.messages);
3237
- break;
3238
- }
3239
-
3240
- const recentSubstantiveAssistant = [...this.messages].reverse().find(m =>
3241
- m.role === 'assistant'
3242
- && typeof m.content === 'string'
3243
- && cleanSubstantive(m.content).length >= 60
3244
- );
3245
-
3246
- if (recentSubstantiveAssistant && typeof recentSubstantiveAssistant.content === 'string') {
3247
- this.emitEvent({
3248
- type: 'agent_message',
3249
- content: cleanSubstantive(recentSubstantiveAssistant.content)
3250
- });
3251
- this.emitEvent({
3252
- type: 'status',
3253
- message: 'Task completed with verified deliverables.'
3254
- });
3255
- this.memoryManager.saveHistory(this.messages);
3256
- break;
3257
- }
3258
-
3259
- if (isLaunchOnlyPrompt(taskPrompt) && this.stepsCompleted > 0) {
3260
- const launchSummary = 'Project opened in your default browser. Verification checks completed.';
3261
- this.emitEvent({
3262
- type: 'agent_message',
3263
- content: launchSummary
3264
- });
3265
- this.emitEvent({
3266
- type: 'status',
3267
- message: 'Task completed: project launched and verified.'
3268
- });
3269
- this.memoryManager.saveHistory(this.messages);
3270
- break;
3271
- }
3272
-
3273
- if (this.stepsCompleted > 0) {
3274
- const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
3275
- this.emitEvent({
3276
- type: 'agent_message',
3277
- content: summary
3278
- });
3279
- this.emitEvent({
3280
- type: 'status',
3281
- message: 'Task completed with verified deliverables.'
3282
- });
3233
+ if (partial.length >= 20) {
3234
+ this.emitEvent({ type: 'agent_message', content: partial });
3235
+ }
3236
+ this.emitEvent({ type: 'error', message:
3237
+ 'The peer ended with an incomplete or progress-only turn. ' +
3238
+ 'Actions may have changed files, but completion is not established.' });
3283
3239
  this.memoryManager.saveHistory(this.messages);
3284
3240
  break;
3285
3241
  }
3286
-
3287
- this.emitEvent({
3288
- type: 'error',
3289
- message: 'The task stopped before completion after repeated incomplete turns without a final response. Work remains unfinished.'
3290
- });
3291
- this.memoryManager.saveHistory(this.messages);
3292
- break;
3293
3242
  }
3294
-
3295
3243
  if (hasExternalActions && !isIncompleteTurn && !isMidTaskProgress) {
3296
3244
  incompleteTurnContinuations = 0;
3297
3245
  }
@@ -3321,11 +3269,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
3321
3269
  }
3322
3270
 
3323
3271
  if (!hasExternalActions && (isIncompleteTurn || failedExternalActions.length > 0 || !contentText.trim())) {
3324
- if (allPlanCompleted || (this.stepsCompleted > 0 && !isIncompleteTurn && failedExternalActions.length === 0)) {
3325
- const planSummary = this._implementationPlan?.length > 0
3326
- ? ` All ${this._implementationPlan.length} plan steps have been executed and verified:\n\n`
3327
- + this._implementationPlan.map((s: any, idx: number) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n')
3328
- : ` All verified deliverables and actions are in place (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed).`;
3272
+ if (allPlanCompleted) {
3273
+ const planSummary = ` All ${this._implementationPlan.length} plan steps have been completed and verified:\n\n`
3274
+ + this._implementationPlan.map((s: any, idx: number) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n');
3329
3275
  const summary = `Task completed successfully.${planSummary}`;
3330
3276
  this.emitEvent({
3331
3277
  type: 'agent_message',
@@ -3335,47 +3281,25 @@ You are operating in a text-and-code modality without direct image pixel renderi
3335
3281
  type: 'status',
3336
3282
  message: 'Task completed with verified deliverables.'
3337
3283
  });
3284
+ this._causyneTaskOutcome = 'completed';
3338
3285
  this.memoryManager.saveHistory(this.messages);
3339
3286
  break;
3340
3287
  }
3341
-
3342
- if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2) {
3288
+ if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2 && failedExternalActions.length === 0) {
3343
3289
  incompleteTurnContinuations++;
3344
- this.emitEvent({ type: 'status', message: 'Requesting final deliverable and response...' });
3345
- this.emitEvent({ type: 'agent_activity', activity: 'Synthesizing final deliverable…' });
3346
- this.messages.push({
3347
- role: 'system',
3348
- content: `[TASK COMPLETION MANDATE: You have completed your tool execution steps (${this.stepsCompleted} steps performed). Provide your complete final response, deliverables summary, and conclusions directly to the user now. Do not run any more background commands.]`
3349
- });
3290
+ this.emitEvent({ type: 'status', message: 'Requesting the missing final response…' });
3291
+ this.messages.push({ role: 'system', content:
3292
+ '[FINAL RESPONSE REQUIRED] Report actual completed and incomplete work from tool results. ' +
3293
+ 'Do not call plan steps or file writes proof of verification.' });
3350
3294
  this.memoryManager.saveHistory(this.messages);
3351
3295
  continue;
3352
3296
  }
3353
-
3354
- if (this.stepsCompleted > 0) {
3355
- const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
3356
- this.emitEvent({
3357
- type: 'agent_message',
3358
- content: summary
3359
- });
3360
- this.emitEvent({
3361
- type: 'status',
3362
- message: 'Task completed with verified deliverables.'
3363
- });
3364
- this.memoryManager.saveHistory(this.messages);
3365
- break;
3366
- }
3367
-
3368
- if (!contentText.trim()) {
3369
- this.messages.pop();
3370
- }
3371
- this.emitEvent({
3372
- type: 'error',
3373
- message: 'The task stopped before completion after repeated blocked or incomplete turns. Work remains unfinished.'
3374
- });
3297
+ this.emitEvent({ type: 'error', message:
3298
+ 'The task stopped with failed actions, an incomplete turn, or no final response. ' +
3299
+ 'Existing files were preserved; completion was not verified.' });
3375
3300
  this.memoryManager.saveHistory(this.messages);
3376
3301
  break;
3377
3302
  }
3378
-
3379
3303
  // --- COMPLETION GUARDS ---
3380
3304
  // Two hard rules learned the expensive way:
3381
3305
  // 1. Match on word boundaries. Substring matching made 'ui' fire on
@@ -3711,6 +3635,43 @@ You are operating in a text-and-code modality without direct image pixel renderi
3711
3635
  }
3712
3636
  }
3713
3637
 
3638
+ // CAUSYNE_RELIABILITY_V1: require real downloaded images
3639
+ // if image acquisition was part of the user's explicit request.
3640
+ const imageAssetEvidence = await inspectRequestedImageAssets({
3641
+ prompt: taskPrompt,
3642
+ workspaceRoot: this.workspaceRoot,
3643
+ webArtifacts: [...this.webArtifacts]
3644
+ });
3645
+ if (!imageAssetEvidence.ok) {
3646
+ this.emitEvent({ type: 'error', message: imageAssetEvidence.reason ||
3647
+ 'Required downloaded website images were not verified.' });
3648
+ this.memoryManager.saveHistory(this.messages);
3649
+ break;
3650
+ }
3651
+
3652
+ // A preview or DOM snapshot is not proof that a Three.js/WebGL
3653
+ // rendering was actually examined by a vision-capable model.
3654
+ const visualEvidence = inspect3DVisualEvidence(
3655
+ taskPrompt,
3656
+ coldObserver.getToolOutcomes(this.taskId)
3657
+ );
3658
+ if (!visualEvidence.ok) {
3659
+ this.emitEvent({ type: 'error', message: visualEvidence.reason ||
3660
+ '3D visual output was not verified.' });
3661
+ this.memoryManager.saveHistory(this.messages);
3662
+ break;
3663
+ }
3664
+
3665
+ const finalToolOutcomes = coldObserver.getToolOutcomes(this.taskId);
3666
+ const finalToolOutcome = finalToolOutcomes[finalToolOutcomes.length - 1];
3667
+ if (this.stepsCompleted > 0 && finalToolOutcome && !finalToolOutcome.success) {
3668
+ this.emitEvent({ type: 'error', message:
3669
+ `The last observed tool action failed (${finalToolOutcome.tool}). ` +
3670
+ 'Resolve the error or report partial work; no success has been recorded.' });
3671
+ this.memoryManager.saveHistory(this.messages);
3672
+ break;
3673
+ }
3674
+
3714
3675
  const cleanTerminalContent = (text: unknown): string => {
3715
3676
  if (typeof text !== 'string') return '';
3716
3677
  return text
@@ -3795,6 +3756,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
3795
3756
  }
3796
3757
  } catch { /* never block completion on session summary recording */ }
3797
3758
 
3759
+ this._causyneTaskOutcome = 'completed';
3798
3760
  auditLog.log({ event: 'task_complete', taskId: this.taskId, steps: this.stepsCompleted });
3799
3761
  this.emitEvent({ type: 'task_complete', taskId: this.taskId });
3800
3762
  break;
@@ -4252,6 +4214,21 @@ You are operating in a text-and-code modality without direct image pixel renderi
4252
4214
  }
4253
4215
  }
4254
4216
 
4217
+ // CAUSYNE_RELIABILITY_V1: refuse repeated timeouts to one host.
4218
+ // This is not a network authorization rule; sandbox and approval ran above.
4219
+ const networkDecision = this._networkHostGuard.before(functionName, args);
4220
+ if (!networkDecision.allowed) {
4221
+ const error = String(networkDecision.error);
4222
+ const failure = { success: false, error, code: 'NETWORK_HOST_UNAVAILABLE' };
4223
+ coldObserver.recordToolOutcome(this.taskId, functionName, args, failure);
4224
+ this.messages.push({ role: 'tool', tool_call_id: toolCall.id,
4225
+ name: functionName, content: JSON.stringify(failure) });
4226
+ this.emitEvent({ type: 'step_error', tool: functionName,
4227
+ error, toolCallId: toolCall.id });
4228
+ this.memoryManager.saveHistory(this.messages);
4229
+ continue;
4230
+ }
4231
+
4255
4232
  // P2: snapshot the files this call is about to change, before it runs.
4256
4233
  // Only the mutating fs tools match; everything else returns immediately.
4257
4234
  // Fail-open by contract — this can never block or fail a tool call.
@@ -4303,6 +4280,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
4303
4280
  duration = 0;
4304
4281
  const errorType = this.classifyError(toolError);
4305
4282
  const failure = { success: false, error: String(toolError?.message || toolError) };
4283
+ this._networkHostGuard.after(functionName, args, failure);
4306
4284
  const alternativeRoute = lookupAlternativeStep({
4307
4285
  failedTool: functionName,
4308
4286
  why: failureClass(failure),
@@ -4358,6 +4336,8 @@ You are operating in a text-and-code modality without direct image pixel renderi
4358
4336
  };
4359
4337
  }
4360
4338
 
4339
+ this._networkHostGuard.after(functionName, args, result);
4340
+
4361
4341
  if (result && result.success !== false && !result.error && ['fs_write', 'fs_edit', 'MultiEdit'].includes(functionName)) {
4362
4342
  this.recordWebArtifact(args.path || args.file_path);
4363
4343
  }
package/src/cliMode.js CHANGED
@@ -264,8 +264,13 @@ export async function runTask(task) {
264
264
  loop.waitForDecision = makeDecisionHandler(conn);
265
265
 
266
266
  await loop.run();
267
- console.log('\n\x1b[32m[DONE]\x1b[0m Task completed.\n');
268
- process.exit(0);
267
+ const completed = loop._causyneTaskOutcome === 'completed';
268
+ if (completed) {
269
+ console.log('\n\x1b[32m[DONE]\x1b[0m Task completed and verified.\n');
270
+ } else {
271
+ console.error('\n\x1b[31m[INCOMPLETE]\x1b[0m No verified task completion was recorded.\n');
272
+ }
273
+ process.exitCode = completed ? 0 : 1;
269
274
  }
270
275
 
271
276