testchimp-runner-core 0.0.34 → 0.0.36

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 (150) hide show
  1. package/dist/execution-service.d.ts +1 -4
  2. package/dist/execution-service.d.ts.map +1 -1
  3. package/dist/execution-service.js +155 -468
  4. package/dist/execution-service.js.map +1 -1
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +11 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/orchestrator/decision-parser.d.ts +18 -0
  10. package/dist/orchestrator/decision-parser.d.ts.map +1 -0
  11. package/dist/orchestrator/decision-parser.js +127 -0
  12. package/dist/orchestrator/decision-parser.js.map +1 -0
  13. package/dist/orchestrator/index.d.ts +4 -2
  14. package/dist/orchestrator/index.d.ts.map +1 -1
  15. package/dist/orchestrator/index.js +14 -2
  16. package/dist/orchestrator/index.js.map +1 -1
  17. package/dist/orchestrator/orchestrator-agent.d.ts +17 -14
  18. package/dist/orchestrator/orchestrator-agent.d.ts.map +1 -1
  19. package/dist/orchestrator/orchestrator-agent.js +534 -204
  20. package/dist/orchestrator/orchestrator-agent.js.map +1 -1
  21. package/dist/orchestrator/orchestrator-prompts.d.ts +14 -2
  22. package/dist/orchestrator/orchestrator-prompts.d.ts.map +1 -1
  23. package/dist/orchestrator/orchestrator-prompts.js +529 -247
  24. package/dist/orchestrator/orchestrator-prompts.js.map +1 -1
  25. package/dist/orchestrator/page-som-handler.d.ts +106 -0
  26. package/dist/orchestrator/page-som-handler.d.ts.map +1 -0
  27. package/dist/orchestrator/page-som-handler.js +1353 -0
  28. package/dist/orchestrator/page-som-handler.js.map +1 -0
  29. package/dist/orchestrator/som-types.d.ts +149 -0
  30. package/dist/orchestrator/som-types.d.ts.map +1 -0
  31. package/dist/orchestrator/som-types.js +87 -0
  32. package/dist/orchestrator/som-types.js.map +1 -0
  33. package/dist/orchestrator/tool-registry.d.ts +2 -0
  34. package/dist/orchestrator/tool-registry.d.ts.map +1 -1
  35. package/dist/orchestrator/tool-registry.js.map +1 -1
  36. package/dist/orchestrator/tools/index.d.ts +4 -1
  37. package/dist/orchestrator/tools/index.d.ts.map +1 -1
  38. package/dist/orchestrator/tools/index.js +7 -2
  39. package/dist/orchestrator/tools/index.js.map +1 -1
  40. package/dist/orchestrator/tools/refresh-som-markers.d.ts +12 -0
  41. package/dist/orchestrator/tools/refresh-som-markers.d.ts.map +1 -0
  42. package/dist/orchestrator/tools/refresh-som-markers.js +64 -0
  43. package/dist/orchestrator/tools/refresh-som-markers.js.map +1 -0
  44. package/dist/orchestrator/tools/view-previous-screenshot.d.ts +15 -0
  45. package/dist/orchestrator/tools/view-previous-screenshot.d.ts.map +1 -0
  46. package/dist/orchestrator/tools/view-previous-screenshot.js +92 -0
  47. package/dist/orchestrator/tools/view-previous-screenshot.js.map +1 -0
  48. package/dist/orchestrator/types.d.ts +23 -1
  49. package/dist/orchestrator/types.d.ts.map +1 -1
  50. package/dist/orchestrator/types.js +11 -1
  51. package/dist/orchestrator/types.js.map +1 -1
  52. package/dist/scenario-service.d.ts +5 -0
  53. package/dist/scenario-service.d.ts.map +1 -1
  54. package/dist/scenario-service.js +17 -0
  55. package/dist/scenario-service.js.map +1 -1
  56. package/dist/scenario-worker-class.d.ts +4 -0
  57. package/dist/scenario-worker-class.d.ts.map +1 -1
  58. package/dist/scenario-worker-class.js +18 -3
  59. package/dist/scenario-worker-class.js.map +1 -1
  60. package/dist/testing/agent-tester.d.ts +35 -0
  61. package/dist/testing/agent-tester.d.ts.map +1 -0
  62. package/dist/testing/agent-tester.js +84 -0
  63. package/dist/testing/agent-tester.js.map +1 -0
  64. package/dist/testing/ref-translator-tester.d.ts +44 -0
  65. package/dist/testing/ref-translator-tester.d.ts.map +1 -0
  66. package/dist/testing/ref-translator-tester.js +104 -0
  67. package/dist/testing/ref-translator-tester.js.map +1 -0
  68. package/dist/utils/hierarchical-selector.d.ts +47 -0
  69. package/dist/utils/hierarchical-selector.d.ts.map +1 -0
  70. package/dist/utils/hierarchical-selector.js +212 -0
  71. package/dist/utils/hierarchical-selector.js.map +1 -0
  72. package/dist/utils/page-info-retry.d.ts +14 -0
  73. package/dist/utils/page-info-retry.d.ts.map +1 -0
  74. package/dist/utils/page-info-retry.js +60 -0
  75. package/dist/utils/page-info-retry.js.map +1 -0
  76. package/dist/utils/page-info-utils.d.ts +1 -0
  77. package/dist/utils/page-info-utils.d.ts.map +1 -1
  78. package/dist/utils/page-info-utils.js +46 -18
  79. package/dist/utils/page-info-utils.js.map +1 -1
  80. package/dist/utils/ref-attacher.d.ts +21 -0
  81. package/dist/utils/ref-attacher.d.ts.map +1 -0
  82. package/dist/utils/ref-attacher.js +149 -0
  83. package/dist/utils/ref-attacher.js.map +1 -0
  84. package/dist/utils/ref-translator.d.ts +49 -0
  85. package/dist/utils/ref-translator.d.ts.map +1 -0
  86. package/dist/utils/ref-translator.js +276 -0
  87. package/dist/utils/ref-translator.js.map +1 -0
  88. package/package.json +6 -1
  89. package/RELEASE_0.0.26.md +0 -165
  90. package/RELEASE_0.0.27.md +0 -236
  91. package/RELEASE_0.0.28.md +0 -286
  92. package/plandocs/BEFORE_AFTER_VERIFICATION.md +0 -148
  93. package/plandocs/COORDINATE_MODE_DIAGNOSIS.md +0 -144
  94. package/plandocs/CREDIT_CALLBACK_ARCHITECTURE.md +0 -253
  95. package/plandocs/HUMAN_LIKE_IMPROVEMENTS.md +0 -642
  96. package/plandocs/IMPLEMENTATION_STATUS.md +0 -108
  97. package/plandocs/INTEGRATION_COMPLETE.md +0 -322
  98. package/plandocs/MULTI_AGENT_ARCHITECTURE_REVIEW.md +0 -844
  99. package/plandocs/ORCHESTRATOR_MVP_SUMMARY.md +0 -539
  100. package/plandocs/PHASE1_ABSTRACTION_COMPLETE.md +0 -241
  101. package/plandocs/PHASE1_FINAL_STATUS.md +0 -210
  102. package/plandocs/PHASE_1_COMPLETE.md +0 -165
  103. package/plandocs/PHASE_1_SUMMARY.md +0 -184
  104. package/plandocs/PLANNING_SESSION_SUMMARY.md +0 -372
  105. package/plandocs/PROMPT_OPTIMIZATION_ANALYSIS.md +0 -120
  106. package/plandocs/PROMPT_SANITY_CHECK.md +0 -120
  107. package/plandocs/SCRIPT_CLEANUP_FEATURE.md +0 -201
  108. package/plandocs/SCRIPT_GENERATION_ARCHITECTURE.md +0 -364
  109. package/plandocs/SELECTOR_IMPROVEMENTS.md +0 -139
  110. package/plandocs/SESSION_SUMMARY_v0.0.33.md +0 -151
  111. package/plandocs/TROUBLESHOOTING_SESSION.md +0 -72
  112. package/plandocs/VISION_DIAGNOSTICS_IMPROVEMENTS.md +0 -336
  113. package/plandocs/VISUAL_AGENT_EVOLUTION_PLAN.md +0 -396
  114. package/plandocs/WHATS_NEW_v0.0.33.md +0 -183
  115. package/src/auth-config.ts +0 -84
  116. package/src/credit-usage-service.ts +0 -188
  117. package/src/env-loader.ts +0 -103
  118. package/src/execution-service.ts +0 -1413
  119. package/src/file-handler.ts +0 -104
  120. package/src/index.ts +0 -422
  121. package/src/llm-facade.ts +0 -821
  122. package/src/llm-provider.ts +0 -53
  123. package/src/model-constants.ts +0 -35
  124. package/src/orchestrator/index.ts +0 -34
  125. package/src/orchestrator/orchestrator-agent.ts +0 -862
  126. package/src/orchestrator/orchestrator-agent.ts.backup +0 -1386
  127. package/src/orchestrator/orchestrator-prompts.ts +0 -474
  128. package/src/orchestrator/tool-registry.ts +0 -182
  129. package/src/orchestrator/tools/check-page-ready.ts +0 -75
  130. package/src/orchestrator/tools/extract-data.ts +0 -92
  131. package/src/orchestrator/tools/index.ts +0 -12
  132. package/src/orchestrator/tools/inspect-page.ts +0 -42
  133. package/src/orchestrator/tools/recall-history.ts +0 -72
  134. package/src/orchestrator/tools/take-screenshot.ts +0 -128
  135. package/src/orchestrator/tools/verify-action-result.ts +0 -159
  136. package/src/orchestrator/types.ts +0 -248
  137. package/src/playwright-mcp-service.ts +0 -224
  138. package/src/progress-reporter.ts +0 -144
  139. package/src/prompts.ts +0 -842
  140. package/src/providers/backend-proxy-llm-provider.ts +0 -91
  141. package/src/providers/local-llm-provider.ts +0 -38
  142. package/src/scenario-service.ts +0 -232
  143. package/src/scenario-worker-class.ts +0 -1089
  144. package/src/script-utils.ts +0 -203
  145. package/src/types.ts +0 -239
  146. package/src/utils/browser-utils.ts +0 -348
  147. package/src/utils/coordinate-converter.ts +0 -162
  148. package/src/utils/page-info-utils.ts +0 -250
  149. package/testchimp-runner-core-0.0.33.tgz +0 -0
  150. package/tsconfig.json +0 -19
@@ -1,248 +0,0 @@
1
- /**
2
- * Orchestrator Agent Types
3
- * Core types for the tool-using, memory-maintaining orchestrator agent
4
- */
5
-
6
- /**
7
- * Self-reflection guidance for next iteration
8
- */
9
- export interface SelfReflection {
10
- guidanceForNext: string; // Free-form text: "Try data-testid selectors instead of text"
11
- detectingLoop: boolean; // Agent signals if it's repeating same approach
12
- loopReasoning?: string; // "Tried text-based selectors 3 times, switching to IDs"
13
- }
14
-
15
- /**
16
- * Note to future self - iteration-specific memory for tactical continuity
17
- * More flexible than structured SelfReflection - agent can write freely
18
- */
19
- export interface NoteToFutureSelf {
20
- fromIteration: number;
21
- content: string; // FREE-FORM - agent writes whatever tactical info it needs for next iteration
22
- // Examples:
23
- // - "Tried #menu-btn, failed. Will try SVG child next."
24
- // - "Plan: Hover over menu to reveal dropdown, then click Profile option."
25
- // - "Element loads async. Wait 2s after page load before clicking."
26
- }
27
-
28
- /**
29
- * Coordinate-based action (fallback when selectors fail)
30
- * Uses percentage-based positioning for resolution independence
31
- */
32
- export interface CoordinateAction {
33
- type: 'coordinate';
34
- action: 'click' | 'doubleClick' | 'rightClick' | 'hover' | 'drag' | 'fill' | 'scroll';
35
-
36
- // Primary coordinates as percentages (0.0 to 100.0, 3 decimal precision for ~1px accuracy)
37
- xPercent: number; // 0 = left edge, 100 = right edge
38
- yPercent: number; // 0 = top edge, 100 = bottom edge
39
-
40
- // For drag actions
41
- toXPercent?: number;
42
- toYPercent?: number;
43
-
44
- // For fill actions (click then type)
45
- value?: string;
46
-
47
- // For scroll actions
48
- scrollAmount?: number; // Positive = scroll down, negative = scroll up
49
- }
50
-
51
- /**
52
- * Journey memory - tracks the agent's journey through the scenario
53
- */
54
- export interface JourneyMemory {
55
- // Step-by-step history (TEXT only, no screenshots)
56
- history: MemoryStep[];
57
-
58
- // Learnings accumulated throughout journey
59
- experiences: string[];
60
-
61
- // Data extracted and saved for later steps
62
- extractedData: Record<string, string>;
63
-
64
- // Latest note from agent (persists across steps for continuity)
65
- latestNote?: NoteToFutureSelf;
66
- }
67
-
68
- /**
69
- * Individual step in journey history
70
- */
71
- export interface MemoryStep {
72
- stepNumber: number;
73
- iteration?: number;
74
- action: string; // Human-readable: "Filled login form"
75
- code: string; // Executed code: "await page.fill('#email', ...)"
76
- result: 'success' | 'failure';
77
- observation: string; // What was observed: "Form submitted, redirected to dashboard"
78
- error?: string; // Error details if failed
79
- url: string; // URL after action
80
- timestamp: number;
81
- }
82
-
83
- /**
84
- * Tool call request from agent
85
- */
86
- export interface ToolCall {
87
- name: string;
88
- params: Record<string, any>;
89
- }
90
-
91
- /**
92
- * Tool execution result
93
- */
94
- export interface ToolResult {
95
- success: boolean;
96
- data?: any;
97
- error?: string;
98
- learning?: string; // For exploratory actions: text-based learning extracted from screenshot
99
- }
100
-
101
- /**
102
- * Agent decision output
103
- */
104
- export interface AgentDecision {
105
- // Tool requests (agent can call multiple tools)
106
- toolCalls?: ToolCall[];
107
- toolReasoning?: string;
108
- needsToolResults?: boolean; // Wait for tool results before proceeding with commands
109
-
110
- // Command batch (executed sequentially)
111
- commands?: string[];
112
- commandReasoning?: string;
113
-
114
- // Self-reflection for next iteration
115
- selfReflection?: SelfReflection;
116
-
117
- // Note to future self (NEW - free-form iteration memory)
118
- noteToFutureSelf?: string; // Free-form tactical note for next iteration
119
-
120
- // Coordinate-based action (NEW - fallback when selectors fail)
121
- coordinateAction?: CoordinateAction;
122
-
123
- // Memory updates
124
- memoryUpdate?: {
125
- action: string;
126
- observation: string;
127
- extractedData?: Record<string, any>;
128
- };
129
-
130
- // Learnings to add to experiences
131
- experiences?: string[];
132
-
133
- // Termination decision
134
- status: 'complete' | 'stuck' | 'infeasible' | 'continue';
135
- statusReasoning: string;
136
- reasoning: string; // Overall reasoning for this iteration
137
-
138
- // Blocker detection (e.g., unexpected modals, tours, cookie consents)
139
- blockerDetected?: {
140
- description: string; // What's blocking (e.g., "Cookie consent modal")
141
- clearingCommands: string[]; // Commands to dismiss/clear it
142
- };
143
-
144
- // Step re-evaluation (last resort after repeated failures)
145
- stepReEvaluation?: {
146
- detected: boolean; // True if agent is questioning current step
147
- issue: 'prior_incomplete' | 'already_done' | 'wrong_order' | null;
148
- explanation: string; // Why agent thinks step order is off
149
- };
150
- }
151
-
152
- /**
153
- * Context provided to agent each iteration
154
- */
155
- export interface AgentContext {
156
- // Goals & progress
157
- overallGoal: string;
158
- currentStepGoal: string;
159
- stepNumber: number;
160
- totalSteps: number;
161
- completedSteps: string[];
162
- remainingSteps: string[];
163
-
164
- // Current state (fresh)
165
- currentPageInfo: any; // PageInfo from getEnhancedPageInfo
166
- currentURL: string;
167
-
168
- // Recent memory (6-7 steps)
169
- recentSteps: MemoryStep[];
170
-
171
- // Learnings & data
172
- experiences: string[];
173
- extractedData: Record<string, string>;
174
-
175
- // Self-reflection from previous iteration
176
- previousIterationGuidance?: SelfReflection;
177
-
178
- // Note from previous iteration (NEW - tactical continuity)
179
- noteFromPreviousIteration?: NoteToFutureSelf;
180
-
181
- // Tool results from this iteration (if any)
182
- toolResults?: Record<string, ToolResult>;
183
- }
184
-
185
- /**
186
- * Configurable guardrails
187
- */
188
- export interface AgentConfig {
189
- // Per-step limits
190
- maxIterationsPerStep?: number; // Default: 8
191
- maxToolCallsPerIteration?: number; // Default: 5
192
- maxCommandsPerIteration?: number; // Default: 5
193
- maxExploratoryActionsPerIteration?: number; // Default: 3 (Phase 2)
194
- maxExploratoryActionsPerStep?: number; // Default: 10 (Phase 2)
195
-
196
- // Scenario-wide limits
197
- maxConsecutiveStepFailures?: number; // Default: 3 (increased from 2 to allow for UI changes)
198
- maxTotalIterations?: number; // Default: 50 (across all steps)
199
- continueOnStepFailure?: boolean; // Default: true (try subsequent steps even if commands fail)
200
- // NOTE: ALWAYS stops on agent_stuck/infeasible (explicit agent decision)
201
-
202
- // Memory limits
203
- maxExperiences?: number; // Default: 20
204
- maxHistorySize?: number; // Default: 100
205
- recentStepsCount?: number; // Default: 7
206
-
207
- // Timeouts
208
- commandTimeout?: number; // Default: 30000 (30s)
209
- explorationTimeout?: number; // Default: 2000 (2s) (Phase 2)
210
-
211
- // Allowed actions
212
- allowedExplorationActions?: string[]; // Default: ['hover', 'click_info', 'click_menu', 'focus'] (Phase 2)
213
- allowedDomains?: string[]; // For navigate_to_url validation
214
- }
215
-
216
- /**
217
- * Step execution result from orchestrator
218
- */
219
- export interface OrchestratorStepResult {
220
- success: boolean;
221
- commands: string[];
222
- iterations: number;
223
- terminationReason?: 'complete' | 'stuck' | 'infeasible' | 'system_limit' | 'agent_stuck';
224
- memory: JourneyMemory;
225
- error?: string;
226
- }
227
-
228
- /**
229
- * Default config values
230
- */
231
- export const DEFAULT_AGENT_CONFIG: Required<AgentConfig> = {
232
- maxIterationsPerStep: 8,
233
- maxToolCallsPerIteration: 5,
234
- maxCommandsPerIteration: 5,
235
- maxExploratoryActionsPerIteration: 3,
236
- maxExploratoryActionsPerStep: 10,
237
- maxConsecutiveStepFailures: 3, // Increased from 2
238
- maxTotalIterations: 50,
239
- continueOnStepFailure: true, // Try subsequent steps even if one fails
240
- maxExperiences: 20,
241
- maxHistorySize: 100,
242
- recentStepsCount: 7,
243
- commandTimeout: 30000,
244
- explorationTimeout: 2000,
245
- allowedExplorationActions: ['hover', 'click_info', 'click_menu', 'focus'],
246
- allowedDomains: []
247
- };
248
-
@@ -1,224 +0,0 @@
1
- import { ScriptResult, PlaywrightConfig } from './types';
2
- import { initializeBrowser } from './utils/browser-utils';
3
-
4
- /**
5
- * Service for executing Playwright scripts using worker pool
6
- */
7
- export class PlaywrightMCPService {
8
- private isConnected = false;
9
- private logger?: (message: string, level?: 'log' | 'error' | 'warn') => void;
10
-
11
- constructor() {
12
- // No initialization needed for direct Playwright execution
13
- }
14
-
15
- /**
16
- * Set a logger callback for capturing execution logs
17
- */
18
- setLogger(logger: (message: string, level?: 'log' | 'error' | 'warn') => void): void {
19
- this.logger = logger;
20
- }
21
-
22
- /**
23
- * Log a message using the configured logger
24
- */
25
- private log(message: string, level: 'log' | 'error' | 'warn' = 'log'): void {
26
- if (this.logger) {
27
- this.logger(message, level);
28
- }
29
- // No console fallback - logs are routed to consumer
30
- }
31
-
32
- /**
33
- * Initialize the service
34
- */
35
- async initialize(): Promise<void> {
36
- try {
37
- this.log('Initializing Playwright service...');
38
-
39
- // No specific initialization needed for direct Playwright execution
40
- this.isConnected = true;
41
- this.log('Playwright service initialized successfully');
42
- } catch (error) {
43
- throw new Error(`Failed to initialize Playwright service: ${error}`);
44
- }
45
- }
46
-
47
- /**
48
- * Execute a complete job (prescript + script + postscript) using worker pool
49
- */
50
- async executeJob(prescript: string | undefined, script: string, postscript: string | undefined, config?: PlaywrightConfig): Promise<{
51
- success: boolean;
52
- results: {
53
- prescript?: ScriptResult;
54
- script: ScriptResult;
55
- postscript?: ScriptResult;
56
- };
57
- executionTime: number;
58
- error?: string;
59
- }> {
60
- if (!this.isConnected) {
61
- throw new Error('Service not initialized');
62
- }
63
-
64
- try {
65
- // Execute the job directly using Playwright
66
- return await this.executeScriptDirectly(prescript, script, postscript, config);
67
- } catch (error) {
68
- return {
69
- success: false,
70
- results: {
71
- script: { success: false, output: '', error: '', executionTime: 0 }
72
- },
73
- executionTime: 0,
74
- error: error instanceof Error ? error.message : 'Unknown error occurred'
75
- };
76
- }
77
- }
78
-
79
-
80
-
81
- /**
82
- * Prepare the script content for execution
83
- */
84
- private prepareScript(script: string, config?: PlaywrightConfig): string {
85
- // If the script looks like a test file, return as-is
86
- if (script.includes('test(') || script.includes('describe(')) {
87
- return script;
88
- }
89
-
90
- // If it's a list of Playwright commands, wrap in a test
91
- return `
92
- test('executed script', async ({ page }) => {
93
- ${script}
94
- });
95
- `;
96
- }
97
-
98
- /**
99
- * Close the service
100
- */
101
- /**
102
- * Execute script directly using Playwright
103
- */
104
- private async executeScriptDirectly(
105
- prescript: string | undefined,
106
- script: string,
107
- postscript: string | undefined,
108
- config?: PlaywrightConfig
109
- ): Promise<{
110
- success: boolean;
111
- results: {
112
- prescript?: ScriptResult;
113
- script: ScriptResult;
114
- postscript?: ScriptResult;
115
- };
116
- executionTime: number;
117
- error?: string;
118
- }> {
119
- const startTime = Date.now();
120
-
121
- // Dynamically import Playwright types
122
- const playwright = require('playwright');
123
-
124
- let browser: any | undefined;
125
- let context: any | undefined;
126
- let page: any | undefined;
127
-
128
- try {
129
- // Use the centralized browser initialization utility
130
- const browserInstance = await initializeBrowser(config, undefined, undefined, this.logger);
131
- browser = browserInstance.browser;
132
- context = browserInstance.context;
133
- page = browserInstance.page;
134
-
135
- const results: {
136
- prescript?: ScriptResult;
137
- script: ScriptResult;
138
- postscript?: ScriptResult;
139
- } = {
140
- script: { success: false, output: '', error: '', executionTime: 0 }
141
- };
142
-
143
- // Execute prescript
144
- if (prescript) {
145
- try {
146
- const scriptFunction = new Function('page', 'browser', 'context', `
147
- return (async () => {
148
- ${prescript}
149
- })();
150
- `);
151
- await scriptFunction(page, browser, context);
152
- results.prescript = { success: true, output: 'Prescript executed successfully', error: '', executionTime: 0 };
153
- } catch (error: any) {
154
- results.prescript = { success: false, output: '', error: error.message, executionTime: 0 };
155
- }
156
- }
157
-
158
- // Execute main script
159
- try {
160
- const scriptFunction = new Function('page', 'browser', 'context', `
161
- return (async () => {
162
- ${script}
163
- })();
164
- `);
165
- await scriptFunction(page, browser, context);
166
- results.script = { success: true, output: 'Script executed successfully', error: '', executionTime: 0 };
167
- } catch (error: any) {
168
- results.script = { success: false, output: '', error: error.message, executionTime: 0 };
169
- }
170
-
171
- // Execute postscript
172
- if (postscript) {
173
- try {
174
- const scriptFunction = new Function('page', 'browser', 'context', `
175
- return (async () => {
176
- ${postscript}
177
- })();
178
- `);
179
- await scriptFunction(page, browser, context);
180
- results.postscript = { success: true, output: 'Postscript executed successfully', error: '', executionTime: 0 };
181
- } catch (error: any) {
182
- results.postscript = { success: false, output: '', error: error.message, executionTime: 0 };
183
- }
184
- }
185
-
186
- return {
187
- success: results.script.success,
188
- results,
189
- executionTime: Date.now() - startTime
190
- };
191
-
192
- } catch (error: any) {
193
- return {
194
- success: false,
195
- results: {
196
- script: { success: false, output: '', error: error.message, executionTime: 0 }
197
- },
198
- executionTime: Date.now() - startTime,
199
- error: error.message
200
- };
201
- } finally {
202
- if (browser) {
203
- await browser.close();
204
- }
205
- }
206
- }
207
-
208
- async close(): Promise<void> {
209
- try {
210
- // No cleanup needed for direct Playwright execution
211
- this.isConnected = false;
212
- this.log('Playwright service closed');
213
- } catch (error) {
214
- this.log(`Error during shutdown: ${error}`, 'error');
215
- }
216
- }
217
-
218
- /**
219
- * Check if the service is ready
220
- */
221
- isReady(): boolean {
222
- return this.isConnected;
223
- }
224
- }
@@ -1,144 +0,0 @@
1
- /**
2
- * Progress Reporter Interface
3
- * Allows consumers to track execution progress (logs, DB writes, etc.)
4
- */
5
-
6
- /**
7
- * Execution status for a step
8
- * Matches scriptservice StepExecutionStatus enum
9
- */
10
- export enum StepExecutionStatus {
11
- SUCCESS = 'SUCCESS_STEP_EXECUTION',
12
- FAILURE = 'FAILURE_STEP_EXECUTION',
13
- IN_PROGRESS = 'IN_PROGRESS_STEP_EXECUTION'
14
- }
15
-
16
- /**
17
- * Step progress report - camelCase for TypeScript
18
- * Structure matches scriptservice's SmartTestExecutionStep / ScriptGenStep
19
- */
20
- export interface StepProgress {
21
- jobId: string; // Job ID for DB keying
22
- stepId?: string; // Unique step identifier
23
- stepNumber: number; // Step index (1-based)
24
- description: string; // Step description
25
- code?: string; // Playwright command executed
26
- screenshotDataUrl?: string; // Screenshot as data URL (data:image/png;base64,...)
27
- status: StepExecutionStatus; // Execution status
28
- error?: string; // Error message if failed
29
- wasRepaired?: boolean; // For repair mode
30
- subActionCount?: number; // Internal tracking
31
- attempt?: number; // Internal tracking
32
-
33
- // Agent transparency (for orchestrator mode)
34
- agentIteration?: number; // Which iteration of the agent loop
35
- agentReasoning?: string; // Agent's reasoning for this iteration
36
- agentSelfReflection?: any; // SelfReflection guidance for next iteration
37
- agentExperiences?: string[]; // Learnings from this iteration
38
- agentToolsUsed?: string[]; // Tools the agent used
39
- agentStatus?: string; // Agent's status decision
40
- }
41
-
42
- /**
43
- * Job progress report - camelCase for TypeScript
44
- */
45
- export interface JobProgress {
46
- jobId: string; // Job identifier
47
- status: 'started' | 'in_progress' | 'completed' | 'failed';
48
- currentStep?: number; // Current step being executed
49
- totalSteps?: number; // Total steps in scenario
50
- testName?: string; // Test name
51
- script?: string; // Generated/repaired script
52
- error?: string; // Error message if failed
53
- }
54
-
55
- /**
56
- * Token usage tracking
57
- */
58
- export interface TokenUsage {
59
- jobId: string;
60
- stepNumber?: number;
61
- iteration?: number;
62
- inputTokens: number;
63
- outputTokens: number;
64
- includesImage: boolean;
65
- model: string;
66
- timestamp: number;
67
- }
68
-
69
- /**
70
- * Additional step info for lifecycle callbacks
71
- */
72
- export interface StepInfo {
73
- stepId?: string;
74
- stepNumber: number;
75
- description: string;
76
- code?: string;
77
- }
78
-
79
- /**
80
- * Progress reporter interface for external consumers
81
- */
82
- export interface ProgressReporter {
83
- /**
84
- * Called when a step starts, updates, or completes
85
- * - VS Extension/GitHub: Log to console
86
- * - Script Service: Write to DB, upload screenshot to GCS
87
- */
88
- onStepProgress?(progress: StepProgress): Promise<void>;
89
-
90
- /**
91
- * Called when overall job status changes
92
- * - VS Extension/GitHub: Log status
93
- * - Script Service: Update job in DB
94
- */
95
- onJobProgress?(progress: JobProgress): Promise<void>;
96
-
97
- /**
98
- * Called when script is generated/updated
99
- */
100
- onScriptGenerated?(jobId: string, script: string, testName: string): Promise<void>;
101
-
102
- /**
103
- * Called when script is repaired/updated
104
- */
105
- onScriptRepaired?(jobId: string, originalScript: string, repairedScript: string, confidence: number): Promise<void>;
106
-
107
- /**
108
- * Called when tokens are used (for cost tracking)
109
- * - VS Extension/GitHub: Log token usage
110
- * - Script Service: Store in DB for analytics
111
- */
112
- onTokensUsed?(usage: TokenUsage): Promise<void>;
113
-
114
- /**
115
- * Generic logging (for environments that don't need structured progress)
116
- */
117
- log?(message: string, level?: 'log' | 'error' | 'warn'): void;
118
-
119
- /**
120
- * LIFECYCLE CALLBACKS (optional - used by scriptservice, ignored by local clients)
121
- */
122
-
123
- /**
124
- * Called before test execution starts
125
- * - Script Service: Initialize browser context, set up DB records
126
- * - VS Extension/GitHub: Not used (ignore)
127
- */
128
- beforeStartTest?(page: any, browser: any, context: any): Promise<void>;
129
-
130
- /**
131
- * Called before each step execution
132
- * - Script Service: Update step status to IN_PROGRESS in DB
133
- * - VS Extension/GitHub: Not used (ignore)
134
- */
135
- beforeStepStart?(step: StepInfo, page: any): Promise<void>;
136
-
137
- /**
138
- * Called after test execution completes (success or failure)
139
- * - Script Service: Write final status to DB, cleanup resources
140
- * - VS Extension/GitHub: Not used (return value is sufficient)
141
- */
142
- afterEndTest?(status: 'passed' | 'failed', error?: string, page?: any): Promise<void>;
143
- }
144
-