@kosuke-ai/cli 0.0.13 → 0.0.14

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 (35) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +54 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/kosuke/commands/test.d.ts +27 -0
  6. package/dist/kosuke/commands/test.d.ts.map +1 -0
  7. package/dist/kosuke/commands/test.js +338 -0
  8. package/dist/kosuke/commands/test.js.map +1 -0
  9. package/dist/kosuke/types.d.ts +37 -1
  10. package/dist/kosuke/types.d.ts.map +1 -1
  11. package/dist/kosuke/utils/error-analyzer.d.ts +32 -0
  12. package/dist/kosuke/utils/error-analyzer.d.ts.map +1 -0
  13. package/dist/kosuke/utils/error-analyzer.js +129 -0
  14. package/dist/kosuke/utils/error-analyzer.js.map +1 -0
  15. package/dist/kosuke/utils/log-collector.d.ts +81 -0
  16. package/dist/kosuke/utils/log-collector.d.ts.map +1 -0
  17. package/dist/kosuke/utils/log-collector.js +226 -0
  18. package/dist/kosuke/utils/log-collector.js.map +1 -0
  19. package/dist/kosuke/utils/playwright-agent.d.ts +39 -0
  20. package/dist/kosuke/utils/playwright-agent.d.ts.map +1 -0
  21. package/dist/kosuke/utils/playwright-agent.js +245 -0
  22. package/dist/kosuke/utils/playwright-agent.js.map +1 -0
  23. package/dist/kosuke/utils/test-generator.d.ts +22 -0
  24. package/dist/kosuke/utils/test-generator.d.ts.map +1 -0
  25. package/dist/kosuke/utils/test-generator.js +174 -0
  26. package/dist/kosuke/utils/test-generator.js.map +1 -0
  27. package/dist/kosuke/utils/visual-tester.d.ts +71 -0
  28. package/dist/kosuke/utils/visual-tester.d.ts.map +1 -0
  29. package/dist/kosuke/utils/visual-tester.js +202 -0
  30. package/dist/kosuke/utils/visual-tester.js.map +1 -0
  31. package/dist/lib.d.ts +2 -1
  32. package/dist/lib.d.ts.map +1 -1
  33. package/dist/lib.js +1 -0
  34. package/dist/lib.js.map +1 -1
  35. package/package.json +6 -1
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Error Analyzer - Analyze test failures and apply fixes
3
+ *
4
+ * Uses Claude to:
5
+ * - Analyze test failures, console errors, network failures, and backend logs
6
+ * - Identify root causes
7
+ * - Apply fixes to the codebase
8
+ */
9
+ import { runAgent } from './claude-agent.js';
10
+ /**
11
+ * Analyze test failures and apply fixes
12
+ */
13
+ export async function analyzeAndFix(ticket, testFailures, logs, tracePath, cwd = process.cwd()) {
14
+ console.log(`\n${'='.repeat(60)}`);
15
+ console.log(`šŸ” Analyzing Test Failures`);
16
+ console.log(`${'='.repeat(60)}\n`);
17
+ const systemPrompt = buildAnalysisPrompt(ticket, testFailures, logs, tracePath);
18
+ const result = await runAgent(`Analyze and fix test failures for ticket ${ticket.id}`, {
19
+ systemPrompt,
20
+ cwd,
21
+ maxTurns: 30,
22
+ verbosity: 'normal',
23
+ });
24
+ console.log(`\n✨ Analysis complete`);
25
+ console.log(` šŸ”§ Fixes applied: ${result.fixCount}`);
26
+ return {
27
+ rootCause: result.response,
28
+ fixesApplied: result.fixCount,
29
+ tokensUsed: result.tokensUsed,
30
+ cost: result.cost,
31
+ };
32
+ }
33
+ /**
34
+ * Build system prompt for error analysis
35
+ */
36
+ function buildAnalysisPrompt(ticket, testFailures, logs, tracePath) {
37
+ const sections = [];
38
+ // Ticket context
39
+ sections.push(`You are debugging failed end-to-end tests for a feature implementation.
40
+
41
+ **Ticket Information:**
42
+ - ID: ${ticket.id}
43
+ - Title: ${ticket.title}
44
+ - Description:
45
+ ${ticket.description}
46
+
47
+ **Your Task:**
48
+ 1. Analyze the test failures, logs, and errors below
49
+ 2. Identify the root cause of the failures
50
+ 3. Apply fixes to resolve the issues
51
+ 4. Make minimal, targeted changes that align with the ticket requirements`);
52
+ // Test failures
53
+ if (testFailures.length > 0) {
54
+ sections.push(`\n**Test Failures (${testFailures.length}):**`);
55
+ for (const failure of testFailures) {
56
+ sections.push(`\nTest: ${failure.testName}`);
57
+ sections.push(`Error: ${failure.errorMessage}`);
58
+ if (failure.expected) {
59
+ sections.push(`Expected: ${failure.expected}`);
60
+ }
61
+ if (failure.received) {
62
+ sections.push(`Received: ${failure.received}`);
63
+ }
64
+ }
65
+ }
66
+ // Console errors
67
+ if (logs.console.length > 0) {
68
+ sections.push(`\n**Console Errors (${logs.console.length}):**`);
69
+ for (const log of logs.console) {
70
+ const location = log.location ? ` (${log.location})` : '';
71
+ sections.push(`[${log.type.toUpperCase()}]${location} ${log.message}`);
72
+ }
73
+ }
74
+ // Network failures
75
+ if (logs.network.length > 0) {
76
+ sections.push(`\n**Network Failures (${logs.network.length}):**`);
77
+ for (const log of logs.network) {
78
+ sections.push(`\n[${log.method}] ${log.url}`);
79
+ sections.push(`Status: ${log.status} ${log.statusText}`);
80
+ if (log.requestBody) {
81
+ sections.push(`Request: ${log.requestBody.substring(0, 300)}`);
82
+ }
83
+ if (log.responseBody) {
84
+ sections.push(`Response: ${log.responseBody.substring(0, 300)}`);
85
+ }
86
+ }
87
+ }
88
+ // Docker logs
89
+ if (logs.docker.length > 0) {
90
+ sections.push(`\n**Backend Logs (Docker Compose - last ${logs.docker.length} entries):**`);
91
+ for (const log of logs.docker) {
92
+ sections.push(`[${log.service}] ${log.message}`);
93
+ }
94
+ }
95
+ // Trace information
96
+ sections.push(`\n**Playwright Trace:**`);
97
+ sections.push(`Available at: ${tracePath}`);
98
+ sections.push(`(Contains detailed timeline, screenshots, network activity)`);
99
+ // Instructions
100
+ sections.push(`\n**Critical Instructions:**
101
+ 1. Read the relevant source files in the current workspace
102
+ 2. Identify the root cause by correlating:
103
+ - Test failures (what the test expected vs what happened)
104
+ - Console errors (frontend runtime issues)
105
+ - Network failures (API/backend issues)
106
+ - Backend logs (server-side errors)
107
+ 3. Determine if the issue is:
108
+ - Frontend code (React components, forms, routing, state)
109
+ - Backend code (tRPC routes, database, validation)
110
+ - Test code (incorrect selectors, wrong assertions, timing issues)
111
+ - Configuration (environment, API endpoints, CORS)
112
+ 4. Apply fixes using search_replace or write tools
113
+ 5. Focus on the specific feature described in the ticket
114
+ 6. Ensure fixes are production-ready and follow best practices
115
+
116
+ **Common Issues to Check:**
117
+ - Mismatched field names between frontend and backend
118
+ - Missing tRPC route definitions
119
+ - Incorrect API endpoint URLs
120
+ - Missing form validation
121
+ - Async timing issues (missing awaits, race conditions)
122
+ - Incorrect Playwright selectors (wrong role, text, or ID)
123
+ - CORS or authentication issues
124
+ - Database schema mismatches
125
+
126
+ Begin by exploring the codebase, then identify and fix the root cause.`);
127
+ return sections.join('\n');
128
+ }
129
+ //# sourceMappingURL=error-analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-analyzer.js","sourceRoot":"","sources":["../../../kosuke/utils/error-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAuB7C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,YAA2B,EAC3B,IAAmB,EACnB,SAAiB,EACjB,MAAc,OAAO,CAAC,GAAG,EAAE;IAE3B,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,YAAY,GAAG,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAEhF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,4CAA4C,MAAM,CAAC,EAAE,EAAE,EAAE;QACrF,YAAY;QACZ,GAAG;QACH,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;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C,CAAC;YACnE,CAAC;QACH,CAAC;IACH,CAAC;IAED,cAAc;IACd,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,QAAQ,CAAC,IAAI,CAAC,2CAA2C,IAAI,CAAC,MAAM,CAAC,MAAM,cAAc,CAAC,CAAC;QAC3F,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC9B,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,oBAAoB;IACpB,QAAQ,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,SAAS,EAAE,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC;IAE7E,eAAe;IACf,QAAQ,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;uEA0BuD,CAAC,CAAC;IAEvE,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Log Collector - Collect logs from multiple sources
3
+ *
4
+ * Collects and aggregates logs from:
5
+ * - Browser console (errors, warnings)
6
+ * - Network requests (failed requests, status codes)
7
+ * - Docker Compose logs (backend logs)
8
+ * - Playwright traces
9
+ */
10
+ import type { Page } from '@playwright/test';
11
+ export interface ConsoleLog {
12
+ type: 'error' | 'warning' | 'info';
13
+ message: string;
14
+ timestamp: Date;
15
+ location?: string;
16
+ }
17
+ export interface NetworkLog {
18
+ url: string;
19
+ method: string;
20
+ status: number;
21
+ statusText: string;
22
+ timestamp: Date;
23
+ responseBody?: string;
24
+ requestBody?: string;
25
+ }
26
+ export interface DockerLog {
27
+ service: string;
28
+ message: string;
29
+ timestamp: Date;
30
+ }
31
+ export interface CollectedLogs {
32
+ console: ConsoleLog[];
33
+ network: NetworkLog[];
34
+ docker: DockerLog[];
35
+ }
36
+ /**
37
+ * Log collector class that attaches to a Playwright page
38
+ */
39
+ export declare class LogCollector {
40
+ private consoleLogs;
41
+ private networkLogs;
42
+ private dockerLogs;
43
+ private page;
44
+ /**
45
+ * Attach log collectors to a Playwright page
46
+ */
47
+ attach(page: Page): void;
48
+ /**
49
+ * Attach console listener
50
+ */
51
+ private attachConsoleListener;
52
+ /**
53
+ * Attach network listener
54
+ */
55
+ private attachNetworkListener;
56
+ /**
57
+ * Collect Docker Compose logs
58
+ */
59
+ collectDockerLogs(since?: string): Promise<void>;
60
+ /**
61
+ * Get all collected logs
62
+ */
63
+ getLogs(): CollectedLogs;
64
+ /**
65
+ * Get only error logs
66
+ */
67
+ getErrors(): CollectedLogs;
68
+ /**
69
+ * Check if there are any errors
70
+ */
71
+ hasErrors(): boolean;
72
+ /**
73
+ * Format logs as human-readable text
74
+ */
75
+ formatLogs(logs: CollectedLogs): string;
76
+ /**
77
+ * Clear all collected logs
78
+ */
79
+ clear(): void;
80
+ }
81
+ //# sourceMappingURL=log-collector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-collector.d.ts","sourceRoot":"","sources":["../../../kosuke/utils/log-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,IAAI,CAAqB;IAEjC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAMxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAwB7B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAoD7B;;OAEG;IACG,iBAAiB,CAAC,KAAK,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA6C7D;;OAEG;IACH,OAAO,IAAI,aAAa;IAQxB;;OAEG;IACH,SAAS,IAAI,aAAa;IAa1B;;OAEG;IACH,SAAS,IAAI,OAAO;IAKpB;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM;IAqCvC;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd"}
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Log Collector - Collect logs from multiple sources
3
+ *
4
+ * Collects and aggregates logs from:
5
+ * - Browser console (errors, warnings)
6
+ * - Network requests (failed requests, status codes)
7
+ * - Docker Compose logs (backend logs)
8
+ * - Playwright traces
9
+ */
10
+ import { execSync } from 'child_process';
11
+ /**
12
+ * Log collector class that attaches to a Playwright page
13
+ */
14
+ export class LogCollector {
15
+ constructor() {
16
+ this.consoleLogs = [];
17
+ this.networkLogs = [];
18
+ this.dockerLogs = [];
19
+ this.page = null;
20
+ }
21
+ /**
22
+ * Attach log collectors to a Playwright page
23
+ */
24
+ attach(page) {
25
+ this.page = page;
26
+ this.attachConsoleListener(page);
27
+ this.attachNetworkListener(page);
28
+ }
29
+ /**
30
+ * Attach console listener
31
+ */
32
+ attachConsoleListener(page) {
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ page.on('console', (msg) => {
35
+ const type = msg.type();
36
+ if (type === 'error' || type === 'warning' || type === 'info') {
37
+ this.consoleLogs.push({
38
+ type: type,
39
+ message: msg.text(),
40
+ timestamp: new Date(),
41
+ location: msg.location()?.url,
42
+ });
43
+ }
44
+ });
45
+ // Also capture page errors
46
+ page.on('pageerror', (error) => {
47
+ this.consoleLogs.push({
48
+ type: 'error',
49
+ message: error.message,
50
+ timestamp: new Date(),
51
+ });
52
+ });
53
+ }
54
+ /**
55
+ * Attach network listener
56
+ */
57
+ attachNetworkListener(page) {
58
+ page.on('response', async (response) => {
59
+ const status = response.status();
60
+ // Only log failed requests or important status codes
61
+ if (status >= 400 || status === 0) {
62
+ let responseBody;
63
+ let requestBody;
64
+ try {
65
+ // Try to get response body (might fail for non-text responses)
66
+ responseBody = await response.text();
67
+ }
68
+ catch {
69
+ // Ignore if we can't get the body
70
+ }
71
+ try {
72
+ // Try to get request body
73
+ const request = response.request();
74
+ const postData = request.postData();
75
+ if (postData) {
76
+ requestBody = postData;
77
+ }
78
+ }
79
+ catch {
80
+ // Ignore if we can't get request data
81
+ }
82
+ this.networkLogs.push({
83
+ url: response.url(),
84
+ method: response.request().method(),
85
+ status,
86
+ statusText: response.statusText(),
87
+ timestamp: new Date(),
88
+ responseBody,
89
+ requestBody,
90
+ });
91
+ }
92
+ });
93
+ // Capture request failures
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ page.on('requestfailed', (request) => {
96
+ this.networkLogs.push({
97
+ url: request.url(),
98
+ method: request.method(),
99
+ status: 0,
100
+ statusText: request.failure()?.errorText || 'Request failed',
101
+ timestamp: new Date(),
102
+ });
103
+ });
104
+ }
105
+ /**
106
+ * Collect Docker Compose logs
107
+ */
108
+ async collectDockerLogs(since = '30s') {
109
+ try {
110
+ // Check if docker compose is available
111
+ try {
112
+ execSync('docker compose version', { stdio: 'ignore' });
113
+ }
114
+ catch {
115
+ console.log(' ā„¹ļø Docker Compose not available, skipping backend logs');
116
+ return;
117
+ }
118
+ // Get logs from all services
119
+ const logs = execSync(`docker compose logs --tail=100 --since=${since} --no-color`, {
120
+ encoding: 'utf-8',
121
+ stdio: ['pipe', 'pipe', 'ignore'], // Ignore stderr
122
+ });
123
+ // Parse logs
124
+ const lines = logs.split('\n');
125
+ for (const line of lines) {
126
+ if (!line.trim())
127
+ continue;
128
+ // Docker compose log format: service-name | message
129
+ const match = line.match(/^([a-zA-Z0-9_-]+)\s+\|\s+(.+)$/);
130
+ if (match) {
131
+ const [, service, message] = match;
132
+ this.dockerLogs.push({
133
+ service: service.trim(),
134
+ message: message.trim(),
135
+ timestamp: new Date(),
136
+ });
137
+ }
138
+ else {
139
+ // Fallback: just store the line as-is
140
+ this.dockerLogs.push({
141
+ service: 'unknown',
142
+ message: line,
143
+ timestamp: new Date(),
144
+ });
145
+ }
146
+ }
147
+ }
148
+ catch (error) {
149
+ console.log(' āš ļø Failed to collect Docker logs:', error);
150
+ // Don't throw - backend logs are optional
151
+ }
152
+ }
153
+ /**
154
+ * Get all collected logs
155
+ */
156
+ getLogs() {
157
+ return {
158
+ console: this.consoleLogs,
159
+ network: this.networkLogs,
160
+ docker: this.dockerLogs,
161
+ };
162
+ }
163
+ /**
164
+ * Get only error logs
165
+ */
166
+ getErrors() {
167
+ return {
168
+ console: this.consoleLogs.filter((log) => log.type === 'error'),
169
+ network: this.networkLogs.filter((log) => log.status >= 400 || log.status === 0),
170
+ docker: this.dockerLogs.filter((log) => log.message.toLowerCase().includes('error') ||
171
+ log.message.toLowerCase().includes('exception') ||
172
+ log.message.toLowerCase().includes('failed')),
173
+ };
174
+ }
175
+ /**
176
+ * Check if there are any errors
177
+ */
178
+ hasErrors() {
179
+ const errors = this.getErrors();
180
+ return errors.console.length > 0 || errors.network.length > 0 || errors.docker.length > 0;
181
+ }
182
+ /**
183
+ * Format logs as human-readable text
184
+ */
185
+ formatLogs(logs) {
186
+ const sections = [];
187
+ // Console logs
188
+ if (logs.console.length > 0) {
189
+ sections.push('=== Console Logs ===');
190
+ for (const log of logs.console) {
191
+ const location = log.location ? ` (${log.location})` : '';
192
+ sections.push(`[${log.type.toUpperCase()}]${location} ${log.message}`);
193
+ }
194
+ }
195
+ // Network logs
196
+ if (logs.network.length > 0) {
197
+ sections.push('\n=== Network Logs ===');
198
+ for (const log of logs.network) {
199
+ sections.push(`[${log.method}] ${log.url} - ${log.status} ${log.statusText}`);
200
+ if (log.requestBody) {
201
+ sections.push(` Request: ${log.requestBody.substring(0, 200)}`);
202
+ }
203
+ if (log.responseBody) {
204
+ sections.push(` Response: ${log.responseBody.substring(0, 200)}`);
205
+ }
206
+ }
207
+ }
208
+ // Docker logs
209
+ if (logs.docker.length > 0) {
210
+ sections.push('\n=== Docker Compose Logs ===');
211
+ for (const log of logs.docker) {
212
+ sections.push(`[${log.service}] ${log.message}`);
213
+ }
214
+ }
215
+ return sections.join('\n');
216
+ }
217
+ /**
218
+ * Clear all collected logs
219
+ */
220
+ clear() {
221
+ this.consoleLogs = [];
222
+ this.networkLogs = [];
223
+ this.dockerLogs = [];
224
+ }
225
+ }
226
+ //# sourceMappingURL=log-collector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-collector.js","sourceRoot":"","sources":["../../../kosuke/utils/log-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgCzC;;GAEG;AACH,MAAM,OAAO,YAAY;IAAzB;QACU,gBAAW,GAAiB,EAAE,CAAC;QAC/B,gBAAW,GAAiB,EAAE,C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Y,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;gBACrE,CAAC;YACH,CAAC;QACH,CAAC;QAED,cAAc;QACd,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,QAAQ,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;YAC/C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC9B,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Playwright Agent - Test execution orchestration
3
+ *
4
+ * Executes Playwright tests with logging and visual regression
5
+ */
6
+ import type { TestFailure } from './error-analyzer.js';
7
+ export interface PlaywrightResult {
8
+ success: boolean;
9
+ testsRun: number;
10
+ testsPassed: number;
11
+ testsFailed: number;
12
+ failures: TestFailure[];
13
+ tracePath: string;
14
+ duration: number;
15
+ }
16
+ export interface PlaywrightOptions {
17
+ testFile: string;
18
+ baseUrl: string;
19
+ headed?: boolean;
20
+ debug?: boolean;
21
+ cwd?: string;
22
+ }
23
+ /**
24
+ * Run Playwright tests
25
+ */
26
+ export declare function runPlaywrightTests(options: PlaywrightOptions): Promise<PlaywrightResult>;
27
+ /**
28
+ * Check if Playwright is installed
29
+ */
30
+ export declare function isPlaywrightInstalled(cwd?: string): boolean;
31
+ /**
32
+ * Install Playwright
33
+ */
34
+ export declare function installPlaywright(cwd?: string): Promise<void>;
35
+ /**
36
+ * Ensure Playwright config exists
37
+ */
38
+ export declare function ensurePlaywrightConfig(cwd?: string): void;
39
+ //# sourceMappingURL=playwright-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-agent.d.ts","sourceRoot":"","sources":["../../../kosuke/utils/playwright-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6D9F;AA4HD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAW1E;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,GAAE,MAAsB,GAAG,IAAI,CAmCxE"}