agentiqa 1.1.63 → 1.1.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -877,7 +877,7 @@ ${U.join(`
877
877
  `)}`:"")}else{let X=n.steps[0]?.text??"",q=(U,Y,ee)=>{this._startupNavigateLastMilestone=Y,this._startupNavigateLastElapsedMs=Date.now()-f,this.log("info","StartupNavigate",`startup_navigate:${Y}`,{...ee,sessionId:U,sinceStartupMs:Date.now()-f})};this.deps.computerUseService.setStartupNavigateReporter?.(q);let B;try{B=await this.startupStage(Mo({computerUseService:this.deps.computerUseService,sessionId:e.id,config:e.config,projectId:e.projectId,sourceText:X,memoryItems:b,isFirstMessage:!0,sourceLabel:"step",logPrefix:"RunnerRuntime"}),f,"initial browser state")}finally{this.deps.computerUseService.setStartupNavigateReporter?.(void 0)}N=B.env.screenshot,G=`Execute the test plan now.
878
878
  ${B.contextText}`}if(P.mode==="probe"&&!S){let X=n.steps.find(B=>B.authRole==="probe"&&B.authCheck),q=!1;try{q=await this.deps.computerUseService.checkAuthState?.(this.sessionId,X.authCheck)??!1}catch(B){this.log("warn","RunnerRuntime","authPrepass:probe_error",{error:String(B?.message??B)}),q=!1}q?(this._prepassSkippedStepIndexes=P.setupStepIndexes,this.log("info","RunnerRuntime","authPrepass:skip",{authCheck:X.authCheck,skippedStepIndexes:P.setupStepIndexes})):this.log("info","RunnerRuntime","authPrepass:run_all",{reason:"probe_failed",authCheck:X.authCheck})}p=await this.startupStage(this.setupScreencast(e),f,"screencast startup");let F=[{text:G}];v||F.push({inlineData:{mimeType:"image/png",data:N}}),k.push({role:"user",parts:F}),await this.startupStage(this.persistConversationTrace(e,k),f,"initial trace persistence");let $=e.config?.maxIterationsPerTurn??300;if(this.log("info","RunnerRuntime","startRun:entering_loop",{maxIterations:$,traceLength:k.length,isRunning:this._isRunning,startupElapsedMs:Date.now()-f,startupStageTimeline:this._startupStageTimings}),!this._isRunning)throw new Ra("Saved test-plan startup failed before runner work began: the runtime was stopped before the runner loop could start. No browser or LLM actions were attempted.","runner loop entry");let J=`Executing test plan "${n.title}"`,K=await this.runLoop({session:e,maxIterations:$,snapshotOnly:v,isMobile:S,devicePlatform:E,taskDescription:J,supervisorHints:e.config?.extensionPath?'Browser extension context: The agent is testing a web app with a browser extension (e.g. MetaMask). If the extension shows an unlock/login screen, the agent should enter the password \u2014 NEVER suggest clicking "Forgot password", "Import wallet", or resetting the wallet. The wallet is already set up; it just needs to be unlocked.':void 0});if(await this.attemptConcludingRunComplete(e,l,K),K.blocked&&l.status==="running"){let X=this.hasControlUnresponsiveEvidence();l.status="blocked",l.summary=X?QN({reason:"control_unresponsive",testPlan:this._activeTestPlan,currentStepIndex:this._currentStepIndex,detail:K.blockedReason}):K.blockedReason||"Agent was blocked",l.terminationReason=K.blockKind==="agent"?"blocked_by_issue":X?"control_unresponsive":"supervisor_halted",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.deps.testPlanV2RunRepo.upsert(l)}}catch(m){let y=String(m?.message??m),S=m?.stack?String(m.stack).split(`
879
879
  `).slice(0,8).join(`
880
- `):void 0,E=m?.name??"Error",w=this.getStopReason(),x=L9(m);if(D9({stopReason:w,errMsg:y,errName:E,isStartupFailure:x})){if(this.log("warn","RunnerRuntime","startRun:cancelled",{errMsg:y,errName:E,stack:S,runId:l?.id,stopReason:w}),this.trimDanglingToolCalls(this.conversationTrace),l){if(l.status=w==="error"?"error":"cancelled",w==="error"){let b=this._forcedErrorSummary??this.extractErrorMessage(y);l.summary=b,l.errorMessage=b}l.terminationReason=w==="user_followup"?"user_stopped":w??"error",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.deps.testPlanV2RunRepo.upsert(l)}}else if(l&&wl(m)){let b=wl(m);this.log("warn","RunnerRuntime","startRun:browser_unobservable_blocked",{url:b.url,consecutiveCaptures:b.consecutiveCaptures,limit:b.limit,runId:l.id});let g=Date.now();zp(l,g,{reason:"browser_unobservable",testPlan:this._activeTestPlan,currentStepIndex:this._currentStepIndex}),await this.deps.testPlanV2RunRepo.upsert(l);let T={id:ye("msg"),sessionId:e.id,role:"model",text:b.message,timestamp:g,actionName:"run_complete",actionArgs:{status:l.status,stepResults:l.stepResults??[],synthesized:!0},runId:l.id};await this.persistMessage(T),this.emit("message:added",{sessionId:e.id,message:T})}else if(l&&H9(m)){let b=this.extractErrorMessage(y);this.log("warn","RunnerRuntime","startRun:target_app_slowness_blocked",{errMsg:b,errName:E,runId:l.id}),m instanceof jr&&this.baseDeps.sink.emit({kind:"log",ts:Date.now(),sessionId:e.id,level:"info",message:`[slow-site] url=${m.url} totalTimeoutMs=${m.totalTimeoutMs} attempts=${m.attemptCount}`});let g=Date.now();zp(l,g,{reason:"slow_site",testPlan:this._activeTestPlan,currentStepIndex:this._currentStepIndex,detail:b}),await this.deps.testPlanV2RunRepo.upsert(l);let T={id:ye("msg"),sessionId:e.id,role:"model",text:b,timestamp:g,runId:l.id};await this.persistMessage(T),this.emit("message:added",{sessionId:e.id,message:T})}else{let b=this.extractErrorMessage(y),g=Ls(b),T=Mr(b),k=g?Fs():T?al():b;if(this.log("error","RunnerRuntime",x?"startRun:startup_failure":"startRun:error",{errMsg:y,cleanMsg:b,errName:E,stack:S,runId:l?.id,...x?{lastStartupNavigateMilestone:this._startupNavigateLastMilestone,startupNavigateElapsedMs:this._startupNavigateLastElapsedMs,startupElapsedMs:Date.now()-f,startupStalledStage:this.startupStageInFlight?.stage??null,startupStalledForMs:this.startupStageInFlight?Date.now()-this.startupStageInFlight.startedAt:null,startupStageTimeline:this._startupStageTimings}:{}}),this.emit("session:error",{sessionId:e.id,error:k}),l&&(l.status="error",l.summary=k,l.errorMessage=k,l.terminationReason="error",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.deps.testPlanV2RunRepo.upsert(l),x)){let I={id:ye("msg"),sessionId:e.id,role:"model",text:k,timestamp:Date.now(),runId:l.id};await this.persistMessage(I),this.emit("message:added",{sessionId:e.id,message:I})}this.baseDeps.errorReporter?.captureException(m,{tags:{source:"runner_runtime",sessionId:e.id}})}}finally{this.unattendedRun=!1;let m=Object.fromEntries(this._runMemory),y=await this.teardownScreencast(p,c.id);if(y&&l&&(l.videoUrl=y,await this.bestEffortTerminalWrite("video_url",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l))),h)try{await U9(this.deps.computerUseService.cleanupSession(this.sessionId),5e3)}catch{}if(l){l.status==="running"&&this._forcedErrorSummary&&(l.status="error",l.summary=this._forcedErrorSummary,l.errorMessage=this._forcedErrorSummary,l.terminationReason="error",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.bestEffortTerminalWrite("forced_error_summary",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l))),l.terminationReason||(l.terminationReason="error"),l.status==="error"&&!l.errorMessage?.trim()&&(l.errorMessage=l.summary?.trim()||this._forcedErrorSummary?.trim()||"Run ended unexpectedly",await this.bestEffortTerminalWrite("error_message",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l))),zp(l,Date.now())&&await this.bestEffortTerminalWrite("synthesized_blocked_verdict",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l)),this.synthesizeTerminalStepResults(l)&&await this.bestEffortTerminalWrite("terminal_step_results",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l));try{let E=await this.baseDeps.chatRepo.listMessages(e.id),{messages:w,usedFallback:x}=lc(E,l.id);x&&this.log("warn","RunnerRuntime","enrich_run_messages:strict_empty_fallback",{sessionId:e.id,runId:l.id,allMsgCount:E.length,permissiveMsgCount:w.length}),this.log("info","RunnerRuntime","enrich_run_messages",{sessionId:e.id,runId:l.id,allMsgCount:E.length,runMsgCount:w.length}),l.messages=w.filter(v=>v.role==="user"||v.role==="model"&&(v.actionName||v.text&&!/^(<ctrl\d+>\s*)+$/.test(v.text))||v.role==="system"&&v.hasScreenshot).map(v=>({id:v.id,role:v.role,text:v.text,timestamp:v.timestamp,actionName:v.actionName,actionArgs:this.lightRunArgs(v.actionArgs,v.actionName),url:v.url,hasScreenshot:v.hasScreenshot||!1,runId:v.runId})),await this.deps.testPlanV2RunRepo.upsert(l),this.log("info","RunnerRuntime","enrich_run_messages:done",{runId:l.id,visibleMsgCount:l.messages?.length??0})}catch(E){this.log("warn","RunnerRuntime","enrich_run_messages:error",{error:E instanceof Error?E.message:String(E)})}if(this.emitRunVerdictAnalytics(e.id,l,this._activeTestPlan?.title,!0),this.emit("run:completed",{sessionId:e.id,run:l,runMemory:m}),this.deps.testPlanV2RunRepo.finalize){try{await this.baseDeps.sink.flush()}catch(E){this.log("warn","RunnerRuntime","finalize_run:flush_error",{runId:l.id,error:E instanceof Error?E.message:String(E)})}try{await this.deps.testPlanV2RunRepo.finalize(l.id,l.terminationReason??null),this.log("info","RunnerRuntime","finalize_run:done",{runId:l.id,terminationReason:l.terminationReason??null})}catch(E){this.log("warn","RunnerRuntime","finalize_run:error",{runId:l.id,error:E instanceof Error?E.message:String(E)})}}}let S=l?.status;this._activeRun=void 0,this._activeTestPlan=void 0,this._activeAuthoredTestPlan=void 0,this._activeCredentialRoleOverrides=[],this._projectCredentials=[],this._currentRunId=void 0,this._runMemory=new Map,this._onRunMemoryUpdate=null,this._forcedErrorSummary=null,this._verifyEvidenceStepIndexes.clear(),this._stepActionErrors.clear(),this._autoVerifyEvidenceStepIndexes.clear(),this._consecutiveBrowserShortCircuits=0,this._consecutiveBrowserShortCircuitStep=null,this._currentStepStartedAtMs=null,this._currentStepStartedIndex=null,this._verifyMarkerIsolationBlockCounts.clear(),this._pinGroundingShadowStepIndexes.clear(),this._groundedStateExtractCandidates.clear(),this._groundedStateDifferentialCandidates.clear(),this._groundedStateCountCandidates.clear(),this._domGroundableCandidates.clear(),this._predicateBasisCompileCache.clear(),this._reobserveState.clear(),this._reobservedSteps.clear(),this._conflictReconcileSnapshotTaken=!1,this._verifyObservationSeq=0,this._lastVerifyObservationSeqByStep.clear(),this._conflictBounceObservationSeq=null,this._canonicalCaptureByStep.clear(),this._canonicalCapturedBatches.clear(),this._fullSnapshotByStep.clear(),this._fullSnapshotCanvasByStep.clear(),this._fullSnapshotOriginByStep.clear(),this._verifyOracleFailureStepIndexes.clear(),this._verifyOracleFailureDetails.clear(),this._stableVerifyPageSnapshot=null,this._stableVerifySnapshotStep=null,this._retainedVerifyFrame=null,this._retainedFrameAbstainedSteps.clear(),this.endRun(),this.baseDeps.sink.emit({kind:"session_end",ts:Date.now(),sessionId:e.id,status:W9(S),endKind:this.getLastEndKind()}),await this.baseDeps.sink.flush(),e.projectId&&this.emit("session:coverage-requested",{sessionId:e.id,projectId:e.projectId})}}failStalledRun(e){return this._forcedErrorSummary=e,this.stop("error")}async bestEffortTerminalWrite(e,n,r){try{await r()}catch(s){this.log("warn","RunnerRuntime","terminal_write_failed",{tag:e,runId:n,error:s instanceof Error?s.message:String(s)})}}lightRunArgs(e,n){if(!e)return;let r={};if(e.stepText&&(r.stepText=e.stepText),typeof e.planStepIndex=="number"&&(r.planStepIndex=e.planStepIndex),e.status&&(r.status=e.status),n==="report_issue")for(let s of["title","description","severity","confidence","issueId","issueConfirmed","issueDismissed"])e[s]!==void 0&&(r[s]=e[s]);if(n==="propose_update")for(let s of["reason","stepIndex","action","newStep","newSteps","updates","applied","cancelled"])e[s]!==void 0&&(r[s]=e[s]);return n==="spawn_agent"&&e.childAgent&&(r.childAgent=e.childAgent),n==="child_completed"&&e.childAgent&&(r.childAgent=e.childAgent,e.status&&(r.status=e.status),e.summary&&(r.summary=e.summary)),n==="run_complete"&&Array.isArray(e.screenshots)&&(r.screenshots=e.screenshots.map(({base64:s,...i})=>i)),n==="run_complete"&&e.synthesized===!0&&(r.synthesized=!0),Object.keys(r).length>0?r:void 0}async buildChatModeSystemPrompt(e){return this._runTokenTimestamp=Math.floor(Date.now()/1e3),HN(e.testPlan,"chat",e.memoryItems,e.credentials,e.knownIssues,e.isMobile,e.snapshotOnly,e.mobileVisionOnly,this.deps,e.devicePlatform,{},e.testingEmailPolicy,[],[],this._runTokenTimestamp)}async sendMessage(e,n,r,s){if(this._isRunning||(this.unattendedRun=!1),this._isRunning){this.injectUserMessage(r);let l={id:ye("msg"),sessionId:e.id,role:"user",text:r,timestamp:Date.now(),...this._currentRunId?{runId:this._currentRunId}:{}};await this.persistMessage(l),this.emit("message:added",{sessionId:e.id,message:l});return}if(Vw(r)){await this.startRun(e,n);return}if(this.deps.authService.isAuthRequired()&&!await this.deps.authService.ensureAuthenticated()){this.emit("auth:required",{sessionId:this.sessionId,action:"send_message"});return}if(!await(this.baseDeps.llmAccessService?.hasApiKey()??Promise.resolve(!0))){this.emit("session:error",{sessionId:this.sessionId,error:"Gemini API key not set"});return}this.beginRun(),this._activeRun=void 0,this._activeTestPlan=n,this._activeAuthoredTestPlan=n,this._currentStepIndex=null,this._maxStepEverActivated=0,this._maxStepEverExecuted=0,this._reverifyTaintedSteps.clear(),this._currentStepText=null,this._screenshots=[],this._verifyEvidenceStepIndexes.clear(),this._stepActionErrors.clear(),this._autoVerifyEvidenceStepIndexes.clear(),this._consecutiveBrowserShortCircuits=0,this._consecutiveBrowserShortCircuitStep=null,this._currentStepStartedAtMs=null,this._currentStepStartedIndex=null,this._verifyMarkerIsolationBlockCounts.clear(),this._pinGroundingShadowStepIndexes.clear(),this._groundedStateExtractCandidates.clear(),this._groundedStateDifferentialCandidates.clear(),this._groundedStateCountCandidates.clear(),this._domGroundableCandidates.clear(),this._predicateBasisCompileCache.clear(),this._reobserveState.clear(),this._reobservedSteps.clear(),this._conflictReconcileSnapshotTaken=!1,this._verifyObservationSeq=0,this._lastVerifyObservationSeqByStep.clear(),this._conflictBounceObservationSeq=null,this._canonicalCaptureByStep.clear(),this._canonicalCapturedBatches.clear(),this._fullSnapshotByStep.clear(),this._fullSnapshotCanvasByStep.clear(),this._fullSnapshotOriginByStep.clear(),this._verifyOracleFailureStepIndexes.clear(),this._verifyOracleFailureDetails.clear(),this._stableVerifyPageSnapshot=null,this._stableVerifySnapshotStep=null,this._retainedVerifyFrame=null,this._retainedFrameAbstainedSteps.clear(),this._suppressNotifications=!1;let o={id:ye("msg"),sessionId:e.id,role:"user",text:r,timestamp:Date.now(),...s?.length&&{attachments:s.map(l=>({id:l.id,originalName:l.originalName,mimeType:l.mimeType,sizeBytes:l.sizeBytes}))}};if(await this.persistMessage(o),this.emit("message:added",{sessionId:e.id,message:o}),s?.length&&this.deps.testPlanV2Repo){let l=ca(s);if(l.length>0){let c=up(n.steps,l);if(c&&c!==n.steps){let d={...n,steps:c,updatedAt:Date.now()};await this.deps.testPlanV2Repo.upsert(d),n=d}}}let a=!1;try{let l=await this.ensureConversationTraceLoaded(e);this.repairDanglingToolCalls(l);let c=l.length===0,d=z8(l,r,n),u=zy(r)||d,f=zN(r,n,{pendingClarification:!zy(r)&&YN(l)});if(f){let I=(e.config?.platform||"web")==="mobile",A=I?e.config?.mobileConfig?.platform||"android":void 0,O=I&&qs(e.config?.mobileConfig),P=!I&&(e.config?.snapshotOnly??!1);c&&(this.systemPromptText=await this.buildChatModeSystemPrompt({testPlan:n,memoryItems:await this.deps.memoryRepo.list(n.projectId),credentials:await this.deps.secretsService.listProjectCredentials(n.projectId),knownIssues:await this.deps.issuesRepo.list(n.projectId,{status:["confirmed","dismissed"]}),isMobile:I,snapshotOnly:P,mobileVisionOnly:O,devicePlatform:A,testingEmailPolicy:Vt(e.config)}),l.push({role:"user",parts:[{text:this.systemPromptText}]})),l.push({role:"user",parts:[{text:r}]}),l.push({role:"model",parts:[{text:f.message}]}),await this.persistConversationTrace(e,l);let V={id:ye("msg"),sessionId:e.id,role:"model",text:f.message,timestamp:Date.now()};await this.persistMessage(V),this.emit("message:added",{sessionId:e.id,message:V});return}let p=(e.config?.platform||"web")==="mobile",h=p?e.config?.mobileConfig?.platform||"android":void 0,m=h==="ios",y=p&&qs(e.config?.mobileConfig),S=!p&&(e.config?.snapshotOnly??!1),E=await this.deps.memoryRepo.list(n.projectId),w=await this.deps.secretsService.listProjectCredentials(n.projectId);await Mi(e.id,n.projectId,this.deps),this._lastSeededSessionId=e.id;let x=await this.deps.issuesRepo.list(n.projectId,{status:["confirmed","dismissed"]});c&&(this.systemPromptText=await this.buildChatModeSystemPrompt({testPlan:n,memoryItems:E,credentials:w,knownIssues:x,isMobile:p,snapshotOnly:S,mobileVisionOnly:y,devicePlatform:h,testingEmailPolicy:Vt(e.config)}),l.push({role:"user",parts:[{text:this.systemPromptText}]}));let v,b,g=u?"edit":"explore";if(p){let I=e.config?.mobileConfig,A;if(c){let O=await this.baseDeps.mobileMcpService.initializeSession(e.id,{deviceType:h,deviceMode:I.deviceMode,avdName:I?.avdName,deviceId:I?.deviceId,simulatorUdid:I?.simulatorUdid,apkPath:I?.apkPath,appPath:I?.appPath,appIdentifier:I?.appIdentifier,shouldReinstallApp:I?.shouldReinstallApp??!0,appLoadWaitSeconds:I?.appLoadWaitSeconds??5});this.mobileActionExecutor.setScreenSize(O.screenSize),v=O.screenshot.base64,A=O.initWarnings}else v=(await this.baseDeps.mobileMcpService.takeScreenshot(e.id)).base64;b=`User: ${r}
880
+ `):void 0,E=m?.name??"Error",w=this.getStopReason(),x=L9(m);if(D9({stopReason:w,errMsg:y,errName:E,isStartupFailure:x})){if(this.log("warn","RunnerRuntime","startRun:cancelled",{errMsg:y,errName:E,stack:S,runId:l?.id,stopReason:w}),this.trimDanglingToolCalls(this.conversationTrace),l){if(l.status=w==="error"?"error":"cancelled",w==="error"){let b=this._forcedErrorSummary??this.extractErrorMessage(y);l.summary=b,l.errorMessage=b}l.terminationReason=w==="user_followup"?"user_stopped":w??"error",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.deps.testPlanV2RunRepo.upsert(l)}}else if(l&&wl(m)){let b=wl(m);this.log("warn","RunnerRuntime","startRun:browser_unobservable_blocked",{url:b.url,consecutiveCaptures:b.consecutiveCaptures,limit:b.limit,runId:l.id});let g=Date.now();zp(l,g,{reason:"browser_unobservable",testPlan:this._activeTestPlan,currentStepIndex:this._currentStepIndex}),await this.deps.testPlanV2RunRepo.upsert(l);let T={id:ye("msg"),sessionId:e.id,role:"model",text:b.message,timestamp:g,actionName:"run_complete",actionArgs:{status:l.status,stepResults:l.stepResults??[],synthesized:!0},runId:l.id};await this.persistMessage(T),this.emit("message:added",{sessionId:e.id,message:T})}else if(l&&H9(m)){let b=this.extractErrorMessage(y);this.log("warn","RunnerRuntime","startRun:target_app_slowness_blocked",{errMsg:b,errName:E,runId:l.id}),m instanceof jr&&this.baseDeps.sink.emit({kind:"log",ts:Date.now(),sessionId:e.id,level:"info",message:`[slow-site] url=${m.url} totalTimeoutMs=${m.totalTimeoutMs} attempts=${m.attemptCount}`});let g=Date.now();zp(l,g,{reason:"slow_site",testPlan:this._activeTestPlan,currentStepIndex:this._currentStepIndex,detail:b}),await this.deps.testPlanV2RunRepo.upsert(l);let T={id:ye("msg"),sessionId:e.id,role:"model",text:b,timestamp:g,runId:l.id};await this.persistMessage(T),this.emit("message:added",{sessionId:e.id,message:T})}else{let b=this.extractErrorMessage(y),g=Ls(b),T=Mr(b),k=g?Fs():T?al():b;if(this.log("error","RunnerRuntime",x?"startRun:startup_failure":"startRun:error",{errMsg:y,cleanMsg:b,errName:E,stack:S,runId:l?.id,...x?{lastStartupNavigateMilestone:this._startupNavigateLastMilestone,startupNavigateElapsedMs:this._startupNavigateLastElapsedMs}:{},startupElapsedMs:Date.now()-f,startupStalledStage:this.startupStageInFlight?.stage??null,startupStalledForMs:this.startupStageInFlight?Date.now()-this.startupStageInFlight.startedAt:null,startupStageTimeline:this._startupStageTimings}),this.emit("session:error",{sessionId:e.id,error:k}),l&&(l.status="error",l.summary=k,l.errorMessage=k,l.terminationReason="error",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.deps.testPlanV2RunRepo.upsert(l),x)){let I={id:ye("msg"),sessionId:e.id,role:"model",text:k,timestamp:Date.now(),runId:l.id};await this.persistMessage(I),this.emit("message:added",{sessionId:e.id,message:I})}this.baseDeps.errorReporter?.captureException(m,{tags:{source:"runner_runtime",sessionId:e.id}})}}finally{this.unattendedRun=!1;let m=Object.fromEntries(this._runMemory),y=await this.teardownScreencast(p,c.id);if(y&&l&&(l.videoUrl=y,await this.bestEffortTerminalWrite("video_url",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l))),h)try{await U9(this.deps.computerUseService.cleanupSession(this.sessionId),5e3)}catch{}if(l){l.status==="running"&&this._forcedErrorSummary&&(l.status="error",l.summary=this._forcedErrorSummary,l.errorMessage=this._forcedErrorSummary,l.terminationReason="error",l.endedAt=Date.now(),l.updatedAt=Date.now(),await this.bestEffortTerminalWrite("forced_error_summary",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l))),l.terminationReason||(l.terminationReason="error"),l.status==="error"&&!l.errorMessage?.trim()&&(l.errorMessage=l.summary?.trim()||this._forcedErrorSummary?.trim()||"Run ended unexpectedly",await this.bestEffortTerminalWrite("error_message",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l))),zp(l,Date.now())&&await this.bestEffortTerminalWrite("synthesized_blocked_verdict",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l)),this.synthesizeTerminalStepResults(l)&&await this.bestEffortTerminalWrite("terminal_step_results",l.id,()=>this.deps.testPlanV2RunRepo.upsert(l));try{let E=await this.baseDeps.chatRepo.listMessages(e.id),{messages:w,usedFallback:x}=lc(E,l.id);x&&this.log("warn","RunnerRuntime","enrich_run_messages:strict_empty_fallback",{sessionId:e.id,runId:l.id,allMsgCount:E.length,permissiveMsgCount:w.length}),this.log("info","RunnerRuntime","enrich_run_messages",{sessionId:e.id,runId:l.id,allMsgCount:E.length,runMsgCount:w.length}),l.messages=w.filter(v=>v.role==="user"||v.role==="model"&&(v.actionName||v.text&&!/^(<ctrl\d+>\s*)+$/.test(v.text))||v.role==="system"&&v.hasScreenshot).map(v=>({id:v.id,role:v.role,text:v.text,timestamp:v.timestamp,actionName:v.actionName,actionArgs:this.lightRunArgs(v.actionArgs,v.actionName),url:v.url,hasScreenshot:v.hasScreenshot||!1,runId:v.runId})),await this.deps.testPlanV2RunRepo.upsert(l),this.log("info","RunnerRuntime","enrich_run_messages:done",{runId:l.id,visibleMsgCount:l.messages?.length??0})}catch(E){this.log("warn","RunnerRuntime","enrich_run_messages:error",{error:E instanceof Error?E.message:String(E)})}if(this.emitRunVerdictAnalytics(e.id,l,this._activeTestPlan?.title,!0),this.emit("run:completed",{sessionId:e.id,run:l,runMemory:m}),this.deps.testPlanV2RunRepo.finalize){try{await this.baseDeps.sink.flush()}catch(E){this.log("warn","RunnerRuntime","finalize_run:flush_error",{runId:l.id,error:E instanceof Error?E.message:String(E)})}try{await this.deps.testPlanV2RunRepo.finalize(l.id,l.terminationReason??null),this.log("info","RunnerRuntime","finalize_run:done",{runId:l.id,terminationReason:l.terminationReason??null})}catch(E){this.log("warn","RunnerRuntime","finalize_run:error",{runId:l.id,error:E instanceof Error?E.message:String(E)})}}}let S=l?.status;this._activeRun=void 0,this._activeTestPlan=void 0,this._activeAuthoredTestPlan=void 0,this._activeCredentialRoleOverrides=[],this._projectCredentials=[],this._currentRunId=void 0,this._runMemory=new Map,this._onRunMemoryUpdate=null,this._forcedErrorSummary=null,this._verifyEvidenceStepIndexes.clear(),this._stepActionErrors.clear(),this._autoVerifyEvidenceStepIndexes.clear(),this._consecutiveBrowserShortCircuits=0,this._consecutiveBrowserShortCircuitStep=null,this._currentStepStartedAtMs=null,this._currentStepStartedIndex=null,this._verifyMarkerIsolationBlockCounts.clear(),this._pinGroundingShadowStepIndexes.clear(),this._groundedStateExtractCandidates.clear(),this._groundedStateDifferentialCandidates.clear(),this._groundedStateCountCandidates.clear(),this._domGroundableCandidates.clear(),this._predicateBasisCompileCache.clear(),this._reobserveState.clear(),this._reobservedSteps.clear(),this._conflictReconcileSnapshotTaken=!1,this._verifyObservationSeq=0,this._lastVerifyObservationSeqByStep.clear(),this._conflictBounceObservationSeq=null,this._canonicalCaptureByStep.clear(),this._canonicalCapturedBatches.clear(),this._fullSnapshotByStep.clear(),this._fullSnapshotCanvasByStep.clear(),this._fullSnapshotOriginByStep.clear(),this._verifyOracleFailureStepIndexes.clear(),this._verifyOracleFailureDetails.clear(),this._stableVerifyPageSnapshot=null,this._stableVerifySnapshotStep=null,this._retainedVerifyFrame=null,this._retainedFrameAbstainedSteps.clear(),this.endRun(),this.baseDeps.sink.emit({kind:"session_end",ts:Date.now(),sessionId:e.id,status:W9(S),endKind:this.getLastEndKind()}),await this.baseDeps.sink.flush(),e.projectId&&this.emit("session:coverage-requested",{sessionId:e.id,projectId:e.projectId})}}failStalledRun(e){return this._forcedErrorSummary=e,this.stop("error")}async bestEffortTerminalWrite(e,n,r){try{await r()}catch(s){this.log("warn","RunnerRuntime","terminal_write_failed",{tag:e,runId:n,error:s instanceof Error?s.message:String(s)})}}lightRunArgs(e,n){if(!e)return;let r={};if(e.stepText&&(r.stepText=e.stepText),typeof e.planStepIndex=="number"&&(r.planStepIndex=e.planStepIndex),e.status&&(r.status=e.status),n==="report_issue")for(let s of["title","description","severity","confidence","issueId","issueConfirmed","issueDismissed"])e[s]!==void 0&&(r[s]=e[s]);if(n==="propose_update")for(let s of["reason","stepIndex","action","newStep","newSteps","updates","applied","cancelled"])e[s]!==void 0&&(r[s]=e[s]);return n==="spawn_agent"&&e.childAgent&&(r.childAgent=e.childAgent),n==="child_completed"&&e.childAgent&&(r.childAgent=e.childAgent,e.status&&(r.status=e.status),e.summary&&(r.summary=e.summary)),n==="run_complete"&&Array.isArray(e.screenshots)&&(r.screenshots=e.screenshots.map(({base64:s,...i})=>i)),n==="run_complete"&&e.synthesized===!0&&(r.synthesized=!0),Object.keys(r).length>0?r:void 0}async buildChatModeSystemPrompt(e){return this._runTokenTimestamp=Math.floor(Date.now()/1e3),HN(e.testPlan,"chat",e.memoryItems,e.credentials,e.knownIssues,e.isMobile,e.snapshotOnly,e.mobileVisionOnly,this.deps,e.devicePlatform,{},e.testingEmailPolicy,[],[],this._runTokenTimestamp)}async sendMessage(e,n,r,s){if(this._isRunning||(this.unattendedRun=!1),this._isRunning){this.injectUserMessage(r);let l={id:ye("msg"),sessionId:e.id,role:"user",text:r,timestamp:Date.now(),...this._currentRunId?{runId:this._currentRunId}:{}};await this.persistMessage(l),this.emit("message:added",{sessionId:e.id,message:l});return}if(Vw(r)){await this.startRun(e,n);return}if(this.deps.authService.isAuthRequired()&&!await this.deps.authService.ensureAuthenticated()){this.emit("auth:required",{sessionId:this.sessionId,action:"send_message"});return}if(!await(this.baseDeps.llmAccessService?.hasApiKey()??Promise.resolve(!0))){this.emit("session:error",{sessionId:this.sessionId,error:"Gemini API key not set"});return}this.beginRun(),this._activeRun=void 0,this._activeTestPlan=n,this._activeAuthoredTestPlan=n,this._currentStepIndex=null,this._maxStepEverActivated=0,this._maxStepEverExecuted=0,this._reverifyTaintedSteps.clear(),this._currentStepText=null,this._screenshots=[],this._verifyEvidenceStepIndexes.clear(),this._stepActionErrors.clear(),this._autoVerifyEvidenceStepIndexes.clear(),this._consecutiveBrowserShortCircuits=0,this._consecutiveBrowserShortCircuitStep=null,this._currentStepStartedAtMs=null,this._currentStepStartedIndex=null,this._verifyMarkerIsolationBlockCounts.clear(),this._pinGroundingShadowStepIndexes.clear(),this._groundedStateExtractCandidates.clear(),this._groundedStateDifferentialCandidates.clear(),this._groundedStateCountCandidates.clear(),this._domGroundableCandidates.clear(),this._predicateBasisCompileCache.clear(),this._reobserveState.clear(),this._reobservedSteps.clear(),this._conflictReconcileSnapshotTaken=!1,this._verifyObservationSeq=0,this._lastVerifyObservationSeqByStep.clear(),this._conflictBounceObservationSeq=null,this._canonicalCaptureByStep.clear(),this._canonicalCapturedBatches.clear(),this._fullSnapshotByStep.clear(),this._fullSnapshotCanvasByStep.clear(),this._fullSnapshotOriginByStep.clear(),this._verifyOracleFailureStepIndexes.clear(),this._verifyOracleFailureDetails.clear(),this._stableVerifyPageSnapshot=null,this._stableVerifySnapshotStep=null,this._retainedVerifyFrame=null,this._retainedFrameAbstainedSteps.clear(),this._suppressNotifications=!1;let o={id:ye("msg"),sessionId:e.id,role:"user",text:r,timestamp:Date.now(),...s?.length&&{attachments:s.map(l=>({id:l.id,originalName:l.originalName,mimeType:l.mimeType,sizeBytes:l.sizeBytes}))}};if(await this.persistMessage(o),this.emit("message:added",{sessionId:e.id,message:o}),s?.length&&this.deps.testPlanV2Repo){let l=ca(s);if(l.length>0){let c=up(n.steps,l);if(c&&c!==n.steps){let d={...n,steps:c,updatedAt:Date.now()};await this.deps.testPlanV2Repo.upsert(d),n=d}}}let a=!1;try{let l=await this.ensureConversationTraceLoaded(e);this.repairDanglingToolCalls(l);let c=l.length===0,d=z8(l,r,n),u=zy(r)||d,f=zN(r,n,{pendingClarification:!zy(r)&&YN(l)});if(f){let I=(e.config?.platform||"web")==="mobile",A=I?e.config?.mobileConfig?.platform||"android":void 0,O=I&&qs(e.config?.mobileConfig),P=!I&&(e.config?.snapshotOnly??!1);c&&(this.systemPromptText=await this.buildChatModeSystemPrompt({testPlan:n,memoryItems:await this.deps.memoryRepo.list(n.projectId),credentials:await this.deps.secretsService.listProjectCredentials(n.projectId),knownIssues:await this.deps.issuesRepo.list(n.projectId,{status:["confirmed","dismissed"]}),isMobile:I,snapshotOnly:P,mobileVisionOnly:O,devicePlatform:A,testingEmailPolicy:Vt(e.config)}),l.push({role:"user",parts:[{text:this.systemPromptText}]})),l.push({role:"user",parts:[{text:r}]}),l.push({role:"model",parts:[{text:f.message}]}),await this.persistConversationTrace(e,l);let V={id:ye("msg"),sessionId:e.id,role:"model",text:f.message,timestamp:Date.now()};await this.persistMessage(V),this.emit("message:added",{sessionId:e.id,message:V});return}let p=(e.config?.platform||"web")==="mobile",h=p?e.config?.mobileConfig?.platform||"android":void 0,m=h==="ios",y=p&&qs(e.config?.mobileConfig),S=!p&&(e.config?.snapshotOnly??!1),E=await this.deps.memoryRepo.list(n.projectId),w=await this.deps.secretsService.listProjectCredentials(n.projectId);await Mi(e.id,n.projectId,this.deps),this._lastSeededSessionId=e.id;let x=await this.deps.issuesRepo.list(n.projectId,{status:["confirmed","dismissed"]});c&&(this.systemPromptText=await this.buildChatModeSystemPrompt({testPlan:n,memoryItems:E,credentials:w,knownIssues:x,isMobile:p,snapshotOnly:S,mobileVisionOnly:y,devicePlatform:h,testingEmailPolicy:Vt(e.config)}),l.push({role:"user",parts:[{text:this.systemPromptText}]}));let v,b,g=u?"edit":"explore";if(p){let I=e.config?.mobileConfig,A;if(c){let O=await this.baseDeps.mobileMcpService.initializeSession(e.id,{deviceType:h,deviceMode:I.deviceMode,avdName:I?.avdName,deviceId:I?.deviceId,simulatorUdid:I?.simulatorUdid,apkPath:I?.apkPath,appPath:I?.appPath,appIdentifier:I?.appIdentifier,shouldReinstallApp:I?.shouldReinstallApp??!0,appLoadWaitSeconds:I?.appLoadWaitSeconds??5});this.mobileActionExecutor.setScreenSize(O.screenSize),v=O.screenshot.base64,A=O.initWarnings}else v=(await this.baseDeps.mobileMcpService.takeScreenshot(e.id)).base64;b=`User: ${r}
881
881
 
882
882
  Platform: mobile (${m?"iOS":"Android"})
883
883
  Device: ${I?.deviceMode==="connected"?I?.deviceId??"unknown":I?.avdName??"unknown"}`+(A?.length?`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentiqa",
3
- "version": "1.1.63",
3
+ "version": "1.1.64",
4
4
  "description": "AI-powered testing for web and mobile apps",
5
5
  "type": "module",
6
6
  "bin": "dist/cli.js",