@jackwener/opencli 0.7.0 → 0.7.3

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 (50) hide show
  1. package/LICENSE +190 -28
  2. package/README.md +6 -5
  3. package/README.zh-CN.md +5 -4
  4. package/SKILL.md +18 -4
  5. package/dist/browser.js +2 -3
  6. package/dist/cli-manifest.json +195 -22
  7. package/dist/clis/linkedin/search.d.ts +1 -0
  8. package/dist/clis/linkedin/search.js +366 -0
  9. package/dist/clis/reddit/read.d.ts +1 -0
  10. package/dist/clis/reddit/read.js +184 -0
  11. package/dist/clis/youtube/transcript-group.d.ts +44 -0
  12. package/dist/clis/youtube/transcript-group.js +226 -0
  13. package/dist/clis/youtube/transcript-group.test.d.ts +1 -0
  14. package/dist/clis/youtube/transcript-group.test.js +99 -0
  15. package/dist/clis/youtube/transcript.d.ts +1 -0
  16. package/dist/clis/youtube/transcript.js +264 -0
  17. package/dist/clis/youtube/utils.d.ts +8 -0
  18. package/dist/clis/youtube/utils.js +28 -0
  19. package/dist/clis/youtube/video.d.ts +1 -0
  20. package/dist/clis/youtube/video.js +114 -0
  21. package/dist/engine.js +2 -1
  22. package/dist/main.js +10 -2
  23. package/dist/output.js +2 -1
  24. package/dist/registry.d.ts +1 -8
  25. package/dist/snapshotFormatter.d.ts +9 -0
  26. package/dist/snapshotFormatter.js +352 -15
  27. package/dist/snapshotFormatter.test.d.ts +7 -0
  28. package/dist/snapshotFormatter.test.js +521 -0
  29. package/dist/validate.d.ts +14 -2
  30. package/dist/verify.d.ts +14 -2
  31. package/package.json +2 -2
  32. package/src/browser.ts +2 -4
  33. package/src/clis/linkedin/search.ts +416 -0
  34. package/src/clis/reddit/read.ts +186 -0
  35. package/src/clis/youtube/transcript-group.test.ts +108 -0
  36. package/src/clis/youtube/transcript-group.ts +287 -0
  37. package/src/clis/youtube/transcript.ts +280 -0
  38. package/src/clis/youtube/utils.ts +28 -0
  39. package/src/clis/youtube/video.ts +116 -0
  40. package/src/engine.ts +4 -1
  41. package/src/main.ts +10 -2
  42. package/src/output.ts +2 -1
  43. package/src/registry.ts +1 -8
  44. package/src/snapshotFormatter.test.ts +579 -0
  45. package/src/snapshotFormatter.ts +399 -13
  46. package/src/validate.ts +19 -4
  47. package/src/verify.ts +17 -3
  48. package/vitest.config.ts +15 -1
  49. package/dist/clis/reddit/read.yaml +0 -76
  50. package/src/clis/reddit/read.yaml +0 -76
@@ -1,35 +1,268 @@
1
1
  /**
2
2
  * Aria snapshot formatter: parses Playwright MCP snapshot text into clean format.
3
+ *
4
+ * Multi-pass pipeline:
5
+ * 1. Parse & filter: strip annotations, metadata, noise roles, ads, decorators
6
+ * 2. Deduplicate: generic/text child matching parent label
7
+ * 3. Deduplicate: heading + link with identical labels
8
+ * 4. Deduplicate: nested identical links
9
+ * 5. Prune: empty containers (iterative bottom-up)
10
+ * 6. Collapse: single-child containers
3
11
  */
4
12
 
5
13
  export interface FormatOptions {
6
14
  interactive?: boolean;
7
15
  compact?: boolean;
8
16
  maxDepth?: number;
17
+ maxTextLength?: number;
18
+ }
19
+
20
+ const DEFAULT_MAX_TEXT_LENGTH = 200;
21
+
22
+ // Roles that are pure noise and should always be filtered
23
+ const NOISE_ROLES = new Set([
24
+ 'none', 'presentation', 'separator', 'paragraph', 'tooltip', 'status',
25
+ ]);
26
+
27
+ // Roles whose entire subtree should be removed (footer boilerplate, etc.)
28
+ const SUBTREE_NOISE_ROLES = new Set([
29
+ 'contentinfo',
30
+ ]);
31
+
32
+ // Roles considered interactive (clickable/typeable)
33
+ const INTERACTIVE_ROLES = new Set([
34
+ 'button', 'link', 'textbox', 'checkbox', 'radio',
35
+ 'combobox', 'tab', 'menuitem', 'option', 'switch',
36
+ 'slider', 'spinbutton', 'searchbox',
37
+ ]);
38
+
39
+ // Structural landmark roles kept even in interactive mode
40
+ const LANDMARK_ROLES = new Set([
41
+ 'main', 'navigation', 'banner', 'heading', 'search',
42
+ 'region', 'list', 'listitem', 'article', 'complementary',
43
+ 'group', 'toolbar', 'tablist',
44
+ ]);
45
+
46
+ // Container roles eligible for pruning and collapse
47
+ const CONTAINER_ROLES = new Set([
48
+ 'list', 'listitem', 'group', 'toolbar', 'tablist',
49
+ 'navigation', 'region', 'complementary',
50
+ 'search', 'article', 'paragraph', 'figure',
51
+ ]);
52
+
53
+ // Decorator / separator text that adds no semantic value
54
+ const DECORATOR_TEXT = new Set(['•', '·', '|', '—', '-', '/', '\\']);
55
+
56
+ // Ad-related URL patterns
57
+ const AD_URL_PATTERNS = [
58
+ 'googleadservices.com/pagead/',
59
+ 'alb.reddit.com/cr?',
60
+ 'doubleclick.net/',
61
+ 'cm.bilibili.com/cm/api/fees/',
62
+ ];
63
+
64
+ // Boilerplate button labels to filter (back-to-top, etc.)
65
+ const BOILERPLATE_LABELS = [
66
+ '回到顶部', 'back to top', 'scroll to top', 'go to top',
67
+ ];
68
+
69
+ /**
70
+ * Parse role and text from a trimmed snapshot line.
71
+ * Handles quoted labels and trailing text after colon correctly,
72
+ * including lines wrapped in single quotes by Playwright.
73
+ */
74
+ function parseLine(trimmed: string): { role: string; text: string; hasText: boolean; trailingText: string } {
75
+ // Unwrap outer single quotes if present (Playwright wraps lines with special chars)
76
+ let line = trimmed;
77
+ if (line.startsWith("'") && line.endsWith("':")) {
78
+ line = line.slice(1, -2) + ':';
79
+ } else if (line.startsWith("'") && line.endsWith("'")) {
80
+ line = line.slice(1, -1);
81
+ }
82
+
83
+ // Role is the first word
84
+ const roleMatch = line.match(/^([a-zA-Z]+)\b/);
85
+ const role = roleMatch ? roleMatch[1].toLowerCase() : '';
86
+
87
+ // Extract quoted text content (the semantic label)
88
+ const textMatch = line.match(/"([^"]*)"/);
89
+ const text = textMatch ? textMatch[1] : '';
90
+
91
+ // For trailing text: strip annotations and quoted strings first, then check after last colon
92
+ // This avoids matching colons inside quoted labels like "Account: user@email.com"
93
+ let stripped = line;
94
+ // Remove all quoted strings
95
+ stripped = stripped.replace(/"[^"]*"/g, '""');
96
+ // Remove all bracket annotations
97
+ stripped = stripped.replace(/\[[^\]]*\]/g, '');
98
+
99
+ const colonIdx = stripped.lastIndexOf(':');
100
+ let trailingText = '';
101
+ if (colonIdx !== -1) {
102
+ const afterColon = stripped.slice(colonIdx + 1).trim();
103
+ if (afterColon.length > 0) {
104
+ // Get the actual trailing text from original line at same position
105
+ const origColonIdx = line.lastIndexOf(':');
106
+ if (origColonIdx !== -1) {
107
+ trailingText = line.slice(origColonIdx + 1).trim();
108
+ }
109
+ }
110
+ }
111
+
112
+ return { role, text, hasText: text.length > 0 || trailingText.length > 0, trailingText };
113
+ }
114
+
115
+ /**
116
+ * Strip ALL bracket annotations from a content line, preserving quoted strings.
117
+ * Handles both double-quoted and outer single-quoted lines from Playwright.
118
+ */
119
+ function stripAnnotations(content: string): string {
120
+ // Unwrap outer single quotes first
121
+ let line = content;
122
+ if (line.startsWith("'") && (line.endsWith("':") || line.endsWith("'"))) {
123
+ if (line.endsWith("':")) {
124
+ line = line.slice(1, -2) + ':';
125
+ } else {
126
+ line = line.slice(1, -1);
127
+ }
128
+ }
129
+
130
+ // Split by double quotes to protect quoted content
131
+ const parts = line.split('"');
132
+ for (let i = 0; i < parts.length; i += 2) {
133
+ // Only strip annotations from non-quoted parts (even indices)
134
+ parts[i] = parts[i].replace(/\s*\[[^\]]*\]/g, '');
135
+ }
136
+ let result = parts.join('"').replace(/\s{2,}/g, ' ').trim();
137
+
138
+ return result;
139
+ }
140
+
141
+ /**
142
+ * Check if a line is a metadata-only line (like /url: ...).
143
+ */
144
+ function isMetadataLine(trimmed: string): boolean {
145
+ return /^\/[a-zA-Z]+:/.test(trimmed);
146
+ }
147
+
148
+ /**
149
+ * Check if text content is purely decorative (separators, dots, etc.)
150
+ */
151
+ function isDecoratorText(text: string): boolean {
152
+ return DECORATOR_TEXT.has(text.trim());
153
+ }
154
+
155
+ /**
156
+ * Check if a node is ad-related based on its text content.
157
+ */
158
+ function isAdNode(text: string, trailingText: string): boolean {
159
+ const t = (text + ' ' + trailingText).toLowerCase();
160
+ if (t.includes('sponsored') || t.includes('advertisement')) return true;
161
+ if (t.includes('广告')) return true;
162
+ // Check for ad tracking URLs in the label
163
+ for (const pattern of AD_URL_PATTERNS) {
164
+ if (text.includes(pattern) || trailingText.includes(pattern)) return true;
165
+ }
166
+ return false;
167
+ }
168
+
169
+ /**
170
+ * Check if a node is boilerplate UI (back-to-top, etc.)
171
+ */
172
+ function isBoilerplateNode(text: string): boolean {
173
+ const t = text.toLowerCase();
174
+ return BOILERPLATE_LABELS.some(label => t.includes(label));
175
+ }
176
+
177
+ /**
178
+ * Check if a role is noise that should be filtered.
179
+ */
180
+ function isNoiseNode(role: string, hasText: boolean, text: string, trailingText: string): boolean {
181
+ if (NOISE_ROLES.has(role)) return true;
182
+ // generic without text is a wrapper
183
+ if (role === 'generic' && !hasText) return true;
184
+ // img without alt text is noise
185
+ if (role === 'img' && !hasText) return true;
186
+ // Decorator-only text nodes
187
+ if ((role === 'generic' || role === 'text') && hasText) {
188
+ const content = trailingText || text;
189
+ if (isDecoratorText(content)) return true;
190
+ }
191
+ return false;
192
+ }
193
+
194
+ interface Entry {
195
+ depth: number;
196
+ content: string;
197
+ role: string;
198
+ text: string;
199
+ trailingText: string;
200
+ isInteractive: boolean;
201
+ isLandmark: boolean;
202
+ isSubtreeSkip: boolean; // ad nodes or boilerplate — skip entire subtree
9
203
  }
10
204
 
11
205
  export function formatSnapshot(raw: string, opts: FormatOptions = {}): string {
12
206
  if (!raw || typeof raw !== 'string') return '';
207
+
208
+ const maxTextLen = opts.maxTextLength ?? DEFAULT_MAX_TEXT_LENGTH;
13
209
  const lines = raw.split('\n');
14
- const result: string[] = [];
210
+
211
+ // === Pass 1: Parse, filter, and collect entries ===
212
+ const entries: Entry[] = [];
15
213
  let refCounter = 0;
214
+ let skipUntilDepth = -1; // When >= 0, skip all nodes at depth > this value
16
215
 
17
- for (const line of lines) {
216
+ for (let i = 0; i < lines.length; i++) {
217
+ const line = lines[i];
18
218
  if (!line.trim()) continue;
219
+
19
220
  const indent = line.length - line.trimStart().length;
20
221
  const depth = Math.floor(indent / 2);
21
- if (opts.maxDepth && depth > opts.maxDepth) continue;
222
+
223
+ // If we're in a subtree skip zone, check depth
224
+ if (skipUntilDepth >= 0) {
225
+ if (depth > skipUntilDepth) continue; // still inside subtree
226
+ skipUntilDepth = -1; // exited subtree
227
+ }
22
228
 
23
229
  let content = line.trimStart();
24
230
 
25
- // Skip non-interactive elements in interactive mode
26
- if (opts.interactive) {
27
- const interactiveRoles = ['button', 'link', 'textbox', 'checkbox', 'radio', 'combobox', 'tab', 'menuitem', 'option'];
28
- const role = content.split(/[\s[]/)[0]?.toLowerCase() ?? '';
29
- if (!interactiveRoles.some(r => role.includes(r)) && depth > 1) continue;
231
+ // Strip leading "- "
232
+ if (content.startsWith('- ')) {
233
+ content = content.slice(2);
30
234
  }
31
235
 
32
- // Compact: strip verbose role descriptions
236
+ // Skip metadata lines
237
+ if (isMetadataLine(content)) continue;
238
+
239
+ // Apply maxDepth filter
240
+ if (opts.maxDepth !== undefined && depth > opts.maxDepth) continue;
241
+
242
+ const { role, text, hasText, trailingText } = parseLine(content);
243
+
244
+ // Skip noise nodes
245
+ if (isNoiseNode(role, hasText, text, trailingText)) continue;
246
+
247
+ // Skip subtree noise roles (contentinfo footer, etc.) — skip entire subtree
248
+ if (SUBTREE_NOISE_ROLES.has(role)) {
249
+ skipUntilDepth = depth;
250
+ continue;
251
+ }
252
+
253
+ // Strip annotations
254
+ content = stripAnnotations(content);
255
+
256
+ // Check if node should trigger subtree skip (ads, boilerplate)
257
+ const isSubtreeSkip = isAdNode(text, trailingText) || isBoilerplateNode(text);
258
+
259
+ // Interactive mode filter
260
+ const isInteractive = INTERACTIVE_ROLES.has(role);
261
+ const isLandmark = LANDMARK_ROLES.has(role);
262
+
263
+ if (opts.interactive && !isInteractive && !isLandmark && !hasText) continue;
264
+
265
+ // Compact mode
33
266
  if (opts.compact) {
34
267
  content = content
35
268
  .replace(/\s*\[.*?\]\s*/g, ' ')
@@ -37,15 +270,168 @@ export function formatSnapshot(raw: string, opts: FormatOptions = {}): string {
37
270
  .trim();
38
271
  }
39
272
 
273
+ // Text truncation
274
+ if (maxTextLen > 0 && content.length > maxTextLen) {
275
+ content = content.slice(0, maxTextLen) + '…';
276
+ }
277
+
40
278
  // Assign refs to interactive elements
41
- const interactivePattern = /^(button|link|textbox|checkbox|radio|combobox|tab|menuitem|option)\b/i;
42
- if (interactivePattern.test(content)) {
279
+ if (isInteractive) {
43
280
  refCounter++;
44
281
  content = `[@${refCounter}] ${content}`;
45
282
  }
46
283
 
47
- result.push(' '.repeat(depth) + content);
284
+ entries.push({ depth, content, role, text, trailingText, isInteractive, isLandmark, isSubtreeSkip });
285
+ }
286
+
287
+ // === Pass 2: Remove subtree-skip nodes (ads, boilerplate, contentinfo) ===
288
+ let noAds: Entry[] = [];
289
+ for (let i = 0; i < entries.length; i++) {
290
+ const entry = entries[i];
291
+ if (entry.isSubtreeSkip) {
292
+ const skipDepth = entry.depth;
293
+ i++;
294
+ while (i < entries.length && entries[i].depth > skipDepth) {
295
+ i++;
296
+ }
297
+ i--;
298
+ continue;
299
+ }
300
+ noAds.push(entry);
301
+ }
302
+
303
+ // === Pass 3: Deduplicate child generic/text matching parent label ===
304
+ let deduped: Entry[] = [];
305
+ for (let i = 0; i < noAds.length; i++) {
306
+ const entry = noAds[i];
307
+
308
+ if (entry.role === 'generic' || entry.role === 'text') {
309
+ let parent: Entry | undefined;
310
+ for (let j = deduped.length - 1; j >= 0; j--) {
311
+ if (deduped[j].depth < entry.depth) {
312
+ parent = deduped[j];
313
+ break;
314
+ }
315
+ if (deduped[j].depth === entry.depth) break;
316
+ }
317
+
318
+ if (parent) {
319
+ const childText = entry.trailingText || entry.text;
320
+ if (childText && parent.text && childText === parent.text) {
321
+ continue;
322
+ }
323
+ }
324
+ }
325
+
326
+ deduped.push(entry);
327
+ }
328
+
329
+ // === Pass 4: Deduplicate heading + child link with identical label ===
330
+ // Pattern: heading "Title": → link "Title": (same text) → skip the link
331
+ const deduped2: Entry[] = [];
332
+ for (let i = 0; i < deduped.length; i++) {
333
+ const entry = deduped[i];
334
+
335
+ if (entry.role === 'heading' && entry.text) {
336
+ const next = deduped[i + 1];
337
+ if (next && next.role === 'link' && next.text === entry.text && next.depth === entry.depth + 1) {
338
+ // Keep the heading, skip the link. But preserve link's children re-parented.
339
+ deduped2.push(entry);
340
+ i++; // skip the link
341
+ continue;
342
+ }
343
+ }
344
+
345
+ deduped2.push(entry);
346
+ }
347
+
348
+ // === Pass 5: Deduplicate nested identical links ===
349
+ const deduped3: Entry[] = [];
350
+ for (let i = 0; i < deduped2.length; i++) {
351
+ const entry = deduped2[i];
352
+
353
+ if (entry.role === 'link' && entry.text) {
354
+ const next = deduped2[i + 1];
355
+ if (next && next.role === 'link' && next.text === entry.text && next.depth === entry.depth + 1) {
356
+ continue; // Skip parent, keep child
357
+ }
358
+ }
359
+
360
+ deduped3.push(entry);
361
+ }
362
+
363
+ // === Pass 6: Iteratively prune empty containers (bottom-up) ===
364
+ let current = deduped3;
365
+ let changed = true;
366
+ while (changed) {
367
+ changed = false;
368
+ const next: Entry[] = [];
369
+ for (let i = 0; i < current.length; i++) {
370
+ const entry = current[i];
371
+ if (CONTAINER_ROLES.has(entry.role) && !entry.text && !entry.trailingText) {
372
+ let hasChildren = false;
373
+ for (let j = i + 1; j < current.length; j++) {
374
+ if (current[j].depth <= entry.depth) break;
375
+ if (current[j].depth > entry.depth) {
376
+ hasChildren = true;
377
+ break;
378
+ }
379
+ }
380
+ if (!hasChildren) {
381
+ changed = true;
382
+ continue;
383
+ }
384
+ }
385
+ next.push(entry);
386
+ }
387
+ current = next;
388
+ }
389
+
390
+ // === Pass 7: Collapse single-child containers ===
391
+ const collapsed: Entry[] = [];
392
+ for (let i = 0; i < current.length; i++) {
393
+ const entry = current[i];
394
+
395
+ if (CONTAINER_ROLES.has(entry.role) && !entry.text && !entry.trailingText) {
396
+ let childCount = 0;
397
+ let childIdx = -1;
398
+ for (let j = i + 1; j < current.length; j++) {
399
+ if (current[j].depth <= entry.depth) break;
400
+ if (current[j].depth === entry.depth + 1) {
401
+ childCount++;
402
+ if (childCount === 1) childIdx = j;
403
+ }
404
+ }
405
+
406
+ if (childCount === 1 && childIdx !== -1) {
407
+ const child = current[childIdx];
408
+ let hasGrandchildren = false;
409
+ for (let j = childIdx + 1; j < current.length; j++) {
410
+ if (current[j].depth <= child.depth) break;
411
+ if (current[j].depth > child.depth) {
412
+ hasGrandchildren = true;
413
+ break;
414
+ }
415
+ }
416
+
417
+ if (!hasGrandchildren) {
418
+ const mergedContent = entry.content.replace(/:$/, '') + ' > ' + child.content;
419
+ collapsed.push({
420
+ ...entry,
421
+ content: mergedContent,
422
+ role: child.role,
423
+ text: child.text,
424
+ trailingText: child.trailingText,
425
+ isInteractive: child.isInteractive,
426
+ });
427
+ i++;
428
+ continue;
429
+ }
430
+ }
431
+ }
432
+
433
+ collapsed.push(entry);
48
434
  }
49
435
 
50
- return result.join('\n');
436
+ return collapsed.map(e => ' '.repeat(e.depth) + e.content).join('\n');
51
437
  }
package/src/validate.ts CHANGED
@@ -11,8 +11,22 @@ const KNOWN_STEP_NAMES = new Set([
11
11
  'intercept', 'tap',
12
12
  ]);
13
13
 
14
- export function validateClisWithTarget(dirs: string[], target?: string): any {
15
- const results: any[] = [];
14
+ export interface FileValidationResult {
15
+ path: string;
16
+ errors: string[];
17
+ warnings: string[];
18
+ }
19
+
20
+ export interface ValidationReport {
21
+ ok: boolean;
22
+ results: FileValidationResult[];
23
+ errors: number;
24
+ warnings: number;
25
+ files: number;
26
+ }
27
+
28
+ export function validateClisWithTarget(dirs: string[], target?: string): ValidationReport {
29
+ const results: FileValidationResult[] = [];
16
30
  let errors = 0; let warnings = 0; let files = 0;
17
31
  for (const dir of dirs) {
18
32
  if (!fs.existsSync(dir)) continue;
@@ -35,7 +49,7 @@ export function validateClisWithTarget(dirs: string[], target?: string): any {
35
49
  return { ok: errors === 0, results, errors, warnings, files };
36
50
  }
37
51
 
38
- function validateYamlFile(filePath: string): any {
52
+ function validateYamlFile(filePath: string): FileValidationResult {
39
53
  const errors: string[] = []; const warnings: string[] = [];
40
54
  try {
41
55
  const raw = fs.readFileSync(filePath, 'utf-8');
@@ -64,7 +78,7 @@ function validateYamlFile(filePath: string): any {
64
78
  return { path: filePath, errors, warnings };
65
79
  }
66
80
 
67
- export function renderValidationReport(report: any): string {
81
+ export function renderValidationReport(report: ValidationReport): string {
68
82
  const lines = [`opencli validate: ${report.ok ? 'PASS' : 'FAIL'}`, `Checked ${report.results.length} CLI(s) in ${report.files} file(s)`, `Errors: ${report.errors} Warnings: ${report.warnings}`];
69
83
  for (const r of report.results) {
70
84
  if (r.errors.length > 0 || r.warnings.length > 0) {
@@ -75,3 +89,4 @@ export function renderValidationReport(report: any): string {
75
89
  }
76
90
  return lines.join('\n');
77
91
  }
92
+
package/src/verify.ts CHANGED
@@ -6,13 +6,27 @@
6
6
  * to the `opencli test` command or CI pipelines.
7
7
  */
8
8
 
9
- import { validateClisWithTarget, renderValidationReport } from './validate.js';
9
+ import { validateClisWithTarget, renderValidationReport, type ValidationReport } from './validate.js';
10
10
 
11
- export async function verifyClis(opts: any): Promise<any> {
11
+ export interface VerifyOptions {
12
+ builtinClis: string;
13
+ userClis: string;
14
+ target?: string;
15
+ smoke?: boolean;
16
+ }
17
+
18
+ export interface VerifyReport {
19
+ ok: boolean;
20
+ validation: ValidationReport;
21
+ smoke: null;
22
+ }
23
+
24
+ export async function verifyClis(opts: VerifyOptions): Promise<VerifyReport> {
12
25
  const report = validateClisWithTarget([opts.builtinClis, opts.userClis], opts.target);
13
26
  return { ok: report.ok, validation: report, smoke: null };
14
27
  }
15
28
 
16
- export function renderVerifyReport(report: any): string {
29
+ export function renderVerifyReport(report: VerifyReport): string {
17
30
  return renderValidationReport(report.validation);
18
31
  }
32
+
package/vitest.config.ts CHANGED
@@ -2,6 +2,20 @@ import { defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- include: ['src/**/*.test.ts', 'tests/**/*.test.ts'],
5
+ projects: [
6
+ {
7
+ test: {
8
+ name: 'unit',
9
+ include: ['src/**/*.test.ts'],
10
+ },
11
+ },
12
+ {
13
+ test: {
14
+ name: 'e2e',
15
+ include: ['tests/**/*.test.ts'],
16
+ maxWorkers: 2,
17
+ },
18
+ },
19
+ ],
6
20
  },
7
21
  });
@@ -1,76 +0,0 @@
1
- site: reddit
2
- name: read
3
- description: Read a Reddit post and its comments
4
- domain: reddit.com
5
- strategy: cookie
6
- browser: true
7
-
8
- args:
9
- post_id:
10
- type: string
11
- required: true
12
- description: "Post ID (e.g. 1abc123) or full URL"
13
- sort:
14
- type: string
15
- default: best
16
- description: "Comment sort: best, top, new, controversial, old, qa"
17
- limit:
18
- type: int
19
- default: 25
20
- description: Number of top-level comments to fetch
21
-
22
- columns: [type, author, score, text]
23
-
24
- pipeline:
25
- - navigate: https://www.reddit.com
26
- - evaluate: |
27
- (async () => {
28
- let postId = ${{ args.post_id | json }};
29
- const urlMatch = postId.match(/comments\/([a-z0-9]+)/);
30
- if (urlMatch) postId = urlMatch[1];
31
-
32
- const sort = ${{ args.sort | json }};
33
- const limit = ${{ args.limit }};
34
- const res = await fetch('/comments/' + postId + '.json?sort=' + sort + '&limit=' + limit + '&raw_json=1', {
35
- credentials: 'include'
36
- });
37
- const data = await res.json();
38
- if (!Array.isArray(data) || data.length < 1) return [];
39
-
40
- const results = [];
41
-
42
- // First element: post itself
43
- const post = data[0]?.data?.children?.[0]?.data;
44
- if (post) {
45
- let body = post.selftext || '';
46
- if (body.length > 2000) body = body.slice(0, 2000) + '\n... [truncated]';
47
- results.push({
48
- type: '📰 POST',
49
- author: post.author,
50
- score: post.score,
51
- text: post.title + (body ? '\n\n' + body : '') + (post.url && !post.is_self ? '\n🔗 ' + post.url : ''),
52
- });
53
- }
54
-
55
- // Second element: comments
56
- const comments = data[1]?.data?.children || [];
57
- for (const c of comments) {
58
- if (c.kind !== 't1') continue;
59
- const d = c.data;
60
- let body = d.body || '';
61
- if (body.length > 500) body = body.slice(0, 500) + '...';
62
- results.push({
63
- type: '💬 COMMENT',
64
- author: d.author || '[deleted]',
65
- score: d.score || 0,
66
- text: body,
67
- });
68
- }
69
-
70
- return results;
71
- })()
72
- - map:
73
- type: ${{ item.type }}
74
- author: ${{ item.author }}
75
- score: ${{ item.score }}
76
- text: ${{ item.text }}