@causyne/agent 1.20.76 → 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.76",
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,8 @@
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';
5
+ import { getProcessEntitlementGate, EntitlementAccessError } from './licensing/entitlements.js';
2
6
  import { PEER_COLLABORATION_POLICY } from './providers/collaborationPolicy.js';
3
7
  import { createHash, randomUUID } from 'crypto';
4
8
  import { execFileSync } from 'node:child_process';
@@ -541,6 +545,8 @@ export class AgentLoop {
541
545
  this.consecutiveCommands = 0;
542
546
  this.circuitBreakerUnlocked = false;
543
547
  this.stopRequested = false;
548
+ this._causyneTaskOutcome = 'incomplete';
549
+ this._networkHostGuard = new NetworkHostGuard();
544
550
  this.pendingApprovals = new Map(); // Maps toolCallId -> resolve function
545
551
  this.waitForDecision = async () => null;
546
552
  this._decisionAnswers = new Map();
@@ -1484,7 +1490,15 @@ export class AgentLoop {
1484
1490
  return remembered;
1485
1491
  this.emitEvent({ type: 'decision_request', request });
1486
1492
  auditLog.log({ event: 'decision_requested', taskId: this.taskId, kind: request.kind, optionCount: request.options.length });
1487
- const answer = await this.waitForDecision(request);
1493
+ // CAUSYNE_ENTITLEMENT_V1: unresolved durable decisions do not consume fresh leases.
1494
+ this._entitlementGate?.pause();
1495
+ let answer;
1496
+ try {
1497
+ answer = await this.waitForDecision(request);
1498
+ }
1499
+ finally {
1500
+ this._entitlementGate?.resume();
1501
+ }
1488
1502
  if (!answer || typeof answer.label !== 'string' || !answer.label.trim()) {
1489
1503
  this.emitEvent({ type: 'decision_result', request, answer: null });
1490
1504
  return null;
@@ -1561,7 +1575,40 @@ export class AgentLoop {
1561
1575
  }
1562
1576
  this.maxCircuitBreaker = this.maxSteps;
1563
1577
  }
1578
+ // CAUSYNE_ENTITLEMENT_V1: outer lifecycle wrapper, no agent-orchestration rewrite.
1564
1579
  async run() {
1580
+ this.rearmAbortController();
1581
+ this._causyneTaskOutcome = 'incomplete';
1582
+ this._networkHostGuard.reset();
1583
+ const gate = getProcessEntitlementGate();
1584
+ const onEntitlementBlocked = (error) => {
1585
+ if (this.stopRequested)
1586
+ return;
1587
+ this.stopRequested = true;
1588
+ const explanation = error instanceof Error ? error.message : 'Entitlement check failed.';
1589
+ this.emitEvent({ type: 'error', message: `Causyne access paused: ${explanation} No workspace state was removed.` });
1590
+ };
1591
+ try {
1592
+ await gate.begin(onEntitlementBlocked);
1593
+ }
1594
+ catch (error) {
1595
+ if (error instanceof EntitlementAccessError) {
1596
+ this.emitEvent({ type: 'error', message: `Causyne access unavailable: ${error.message}` });
1597
+ return;
1598
+ }
1599
+ throw error;
1600
+ }
1601
+ this._entitlementGate = gate;
1602
+ try {
1603
+ await this.runLicensedCore();
1604
+ }
1605
+ finally {
1606
+ this._entitlementGate = null;
1607
+ gate.end(onEntitlementBlocked);
1608
+ }
1609
+ }
1610
+ /** Existing run implementation moved unchanged; wrapper above owns metering. */
1611
+ async runLicensedCore() {
1565
1612
  this.stopRequested = false;
1566
1613
  // A task that was stopped must not poison the next one — see
1567
1614
  // rearmAbortController(). This has to happen before any tool can run.
@@ -1907,6 +1954,15 @@ export class AgentLoop {
1907
1954
  let emptyResponseRecoveries = 0;
1908
1955
  // The core loop governed by Sovereign Human-in-the-Loop Checkpoints
1909
1956
  while (!this.stopRequested) {
1957
+ // CAUSYNE_ENTITLEMENT_V1: verify an authorized lease before each model step.
1958
+ try {
1959
+ await this._entitlementGate?.beforeStep();
1960
+ }
1961
+ catch (error) {
1962
+ this.emitEvent({ type: 'error', message: error instanceof Error
1963
+ ? `Causyne access paused: ${error.message}` : 'Causyne access paused.' });
1964
+ break;
1965
+ }
1910
1966
  if (this.stopRequested) {
1911
1967
  this.emitEvent({ type: 'error', message: 'Task killed by user.' });
1912
1968
  auditLog.log({ event: 'task_killed', taskId: this.taskId });
@@ -3028,74 +3084,23 @@ You are operating in a text-and-code modality without direct image pixel renderi
3028
3084
  const isAcpTurnNotice = typeof contentText === 'string'
3029
3085
  && (contentText.startsWith('Antigravity executed:') || /^Turn completed by .+ over ACP\.$/i.test(contentText.trim()));
3030
3086
  if ((hasExternalActions || isAcpTurnNotice) && (isIncompleteTurn || isMidTaskProgress || isAcpTurnNotice)) {
3031
- const cleanSubstantive = (text) => {
3032
- if (typeof text !== 'string')
3033
- return '';
3034
- 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 || '')
3035
3093
  .replace(/^Antigravity executed:[^\n]*\n*/i, '')
3036
3094
  .replace(/^Turn completed by [^\n]+ over ACP\.\s*/i, '')
3037
3095
  .trim();
3038
- };
3039
- const currentSubstantive = cleanSubstantive(contentText);
3040
- if (currentSubstantive.length >= 60) {
3041
- this.emitEvent({
3042
- type: 'agent_message',
3043
- content: currentSubstantive
3044
- });
3045
- this.emitEvent({
3046
- type: 'status',
3047
- message: 'Task completed with verified deliverables.'
3048
- });
3049
- this.memoryManager.saveHistory(this.messages);
3050
- break;
3051
- }
3052
- const recentSubstantiveAssistant = [...this.messages].reverse().find(m => m.role === 'assistant'
3053
- && typeof m.content === 'string'
3054
- && cleanSubstantive(m.content).length >= 60);
3055
- if (recentSubstantiveAssistant && typeof recentSubstantiveAssistant.content === 'string') {
3056
- this.emitEvent({
3057
- type: 'agent_message',
3058
- content: cleanSubstantive(recentSubstantiveAssistant.content)
3059
- });
3060
- this.emitEvent({
3061
- type: 'status',
3062
- message: 'Task completed with verified deliverables.'
3063
- });
3064
- this.memoryManager.saveHistory(this.messages);
3065
- break;
3066
- }
3067
- if (isLaunchOnlyPrompt(taskPrompt) && this.stepsCompleted > 0) {
3068
- const launchSummary = 'Project opened in your default browser. Verification checks completed.';
3069
- this.emitEvent({
3070
- type: 'agent_message',
3071
- content: launchSummary
3072
- });
3073
- this.emitEvent({
3074
- type: 'status',
3075
- message: 'Task completed: project launched and verified.'
3076
- });
3077
- this.memoryManager.saveHistory(this.messages);
3078
- break;
3079
- }
3080
- if (this.stepsCompleted > 0) {
3081
- const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
3082
- this.emitEvent({
3083
- type: 'agent_message',
3084
- content: summary
3085
- });
3086
- this.emitEvent({
3087
- type: 'status',
3088
- message: 'Task completed with verified deliverables.'
3089
- });
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.' });
3090
3101
  this.memoryManager.saveHistory(this.messages);
3091
3102
  break;
3092
3103
  }
3093
- this.emitEvent({
3094
- type: 'error',
3095
- message: 'The task stopped before completion after repeated incomplete turns without a final response. Work remains unfinished.'
3096
- });
3097
- this.memoryManager.saveHistory(this.messages);
3098
- break;
3099
3104
  }
3100
3105
  if (hasExternalActions && !isIncompleteTurn && !isMidTaskProgress) {
3101
3106
  incompleteTurnContinuations = 0;
@@ -3122,11 +3127,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
3122
3127
  break;
3123
3128
  }
3124
3129
  if (!hasExternalActions && (isIncompleteTurn || failedExternalActions.length > 0 || !contentText.trim())) {
3125
- if (allPlanCompleted || (this.stepsCompleted > 0 && !isIncompleteTurn && failedExternalActions.length === 0)) {
3126
- const planSummary = this._implementationPlan?.length > 0
3127
- ? ` All ${this._implementationPlan.length} plan steps have been executed and verified:\n\n`
3128
- + this._implementationPlan.map((s, idx) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n')
3129
- : ` 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');
3130
3133
  const summary = `Task completed successfully.${planSummary}`;
3131
3134
  this.emitEvent({
3132
3135
  type: 'agent_message',
@@ -3136,40 +3139,20 @@ You are operating in a text-and-code modality without direct image pixel renderi
3136
3139
  type: 'status',
3137
3140
  message: 'Task completed with verified deliverables.'
3138
3141
  });
3142
+ this._causyneTaskOutcome = 'completed';
3139
3143
  this.memoryManager.saveHistory(this.messages);
3140
3144
  break;
3141
3145
  }
3142
- if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2) {
3146
+ if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2 && failedExternalActions.length === 0) {
3143
3147
  incompleteTurnContinuations++;
3144
- this.emitEvent({ type: 'status', message: 'Requesting final deliverable and response...' });
3145
- this.emitEvent({ type: 'agent_activity', activity: 'Synthesizing final deliverable…' });
3146
- this.messages.push({
3147
- role: 'system',
3148
- 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.]`
3149
- });
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.' });
3150
3151
  this.memoryManager.saveHistory(this.messages);
3151
3152
  continue;
3152
3153
  }
3153
- if (this.stepsCompleted > 0) {
3154
- const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
3155
- this.emitEvent({
3156
- type: 'agent_message',
3157
- content: summary
3158
- });
3159
- this.emitEvent({
3160
- type: 'status',
3161
- message: 'Task completed with verified deliverables.'
3162
- });
3163
- this.memoryManager.saveHistory(this.messages);
3164
- break;
3165
- }
3166
- if (!contentText.trim()) {
3167
- this.messages.pop();
3168
- }
3169
- this.emitEvent({
3170
- type: 'error',
3171
- message: 'The task stopped before completion after repeated blocked or incomplete turns. Work remains unfinished.'
3172
- });
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.' });
3173
3156
  this.memoryManager.saveHistory(this.messages);
3174
3157
  break;
3175
3158
  }
@@ -3343,7 +3326,6 @@ You are operating in a text-and-code modality without direct image pixel renderi
3343
3326
  }
3344
3327
  const hasVisionCapability = this.llm.supportsVision !== false && visionReady && !visionDeclined;
3345
3328
  const isVerified = Boolean(this.webVerificationState.browserActUsed ||
3346
- hasBrowserActOutcome ||
3347
3329
  this.webVerificationState.screenshotTaken ||
3348
3330
  ((!browserReady || !hasVisionCapability) && this.webVerificationState.htmlInspected) ||
3349
3331
  hasPassingTests ||
@@ -3495,6 +3477,36 @@ You are operating in a text-and-code modality without direct image pixel renderi
3495
3477
  break;
3496
3478
  }
3497
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
+ }
3498
3510
  const cleanTerminalContent = (text) => {
3499
3511
  if (typeof text !== 'string')
3500
3512
  return '';
@@ -3578,6 +3590,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
3578
3590
  }
3579
3591
  }
3580
3592
  catch { /* never block completion on session summary recording */ }
3593
+ this._causyneTaskOutcome = 'completed';
3581
3594
  auditLog.log({ event: 'task_complete', taskId: this.taskId, steps: this.stepsCompleted });
3582
3595
  this.emitEvent({ type: 'task_complete', taskId: this.taskId });
3583
3596
  break;
@@ -3995,6 +4008,20 @@ You are operating in a text-and-code modality without direct image pixel renderi
3995
4008
  continue;
3996
4009
  }
3997
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
+ }
3998
4025
  // P2: snapshot the files this call is about to change, before it runs.
3999
4026
  // Only the mutating fs tools match; everything else returns immediately.
4000
4027
  // Fail-open by contract — this can never block or fail a tool call.
@@ -4043,6 +4070,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
4043
4070
  duration = 0;
4044
4071
  const errorType = this.classifyError(toolError);
4045
4072
  const failure = { success: false, error: String(toolError?.message || toolError) };
4073
+ this._networkHostGuard.after(functionName, args, failure);
4046
4074
  const alternativeRoute = lookupAlternativeStep({
4047
4075
  failedTool: functionName,
4048
4076
  why: failureClass(failure),
@@ -4095,6 +4123,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
4095
4123
  hookFeedback: (postHook.messages || []).join('\n') || undefined
4096
4124
  };
4097
4125
  }
4126
+ this._networkHostGuard.after(functionName, args, result);
4098
4127
  if (result && result.success !== false && !result.error && ['fs_write', 'fs_edit', 'MultiEdit'].includes(functionName)) {
4099
4128
  this.recordWebArtifact(args.path || args.file_path);
4100
4129
  }
@@ -4644,25 +4673,31 @@ You are operating in a text-and-code modality without direct image pixel renderi
4644
4673
  const signal = this.abortController?.signal;
4645
4674
  if (this.stopRequested || signal?.aborted)
4646
4675
  return false;
4647
- return new Promise((resolve) => {
4648
- let settled = false;
4649
- const finish = (approved) => {
4650
- if (settled)
4651
- return;
4652
- settled = true;
4653
- clearTimeout(timer);
4654
- signal?.removeEventListener('abort', onAbort);
4655
- this.pendingApprovals.delete(toolCallId);
4656
- resolve(approved === true);
4657
- };
4658
- const onAbort = () => finish(false);
4659
- const timer = setTimeout(() => finish(false), 3600000);
4660
- timer.unref();
4661
- this.pendingApprovals.set(toolCallId, finish);
4662
- signal?.addEventListener('abort', onAbort, { once: true });
4663
- if (signal?.aborted)
4664
- finish(false);
4665
- });
4676
+ this._entitlementGate?.pause();
4677
+ try {
4678
+ return await new Promise((resolve) => {
4679
+ let settled = false;
4680
+ const finish = (approved) => {
4681
+ if (settled)
4682
+ return;
4683
+ settled = true;
4684
+ clearTimeout(timer);
4685
+ signal?.removeEventListener('abort', onAbort);
4686
+ this.pendingApprovals.delete(toolCallId);
4687
+ resolve(approved === true);
4688
+ };
4689
+ const onAbort = () => finish(false);
4690
+ const timer = setTimeout(() => finish(false), 3600000);
4691
+ timer.unref();
4692
+ this.pendingApprovals.set(toolCallId, finish);
4693
+ signal?.addEventListener('abort', onAbort, { once: true });
4694
+ if (signal?.aborted)
4695
+ finish(false);
4696
+ });
4697
+ }
4698
+ finally {
4699
+ this._entitlementGate?.resume();
4700
+ }
4666
4701
  }
4667
4702
  /**
4668
4703
  * Wait before retrying, and stay interruptible while waiting.
@@ -4697,6 +4732,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
4697
4732
  if (spent > 0)
4698
4733
  return 'fatal';
4699
4734
  const msg = (error.message || '').toLowerCase();
4735
+ if (error?.name === 'OpenRouterPrivacyConstraintError'
4736
+ || msg.includes('matching the privacy policy')
4737
+ || msg.includes('data_collection=')) {
4738
+ return 'fatal';
4739
+ }
4700
4740
  if (msg.includes('free usage limit') || msg.includes('subscribe to opencode') || msg.includes('opencode.ai/go') || msg.includes('insufficient_quota') || msg.includes('credit balance is too low')) {
4701
4741
  return 'fatal';
4702
4742
  }