cowork-cli 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cowork-cli",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "work with cowork",
5
5
  "bin": {
6
6
  "cwk": "bin/cli.js"
@@ -1,3 +1,5 @@
1
+ import { parse } from 'node-html-parser';
2
+
1
3
  const TIMEOUT_MS = 10000;
2
4
  const MAX_RESULTS_HARD_LIMIT = 20;
3
5
 
@@ -38,23 +40,20 @@ export default async function webSearch({ query, limit = 5 }) {
38
40
  const html = await response.text();
39
41
  const results = [];
40
42
 
41
- // Split HTML into result blocks.
42
- // The slice(1) skips the header block before the first result.
43
- const blocks = html.split('class="links_main links_deep result__body"').slice(1);
43
+ const root = parse(html);
44
+ const resultNodes = root.querySelectorAll('.result__body');
44
45
 
45
- for (const block of blocks) {
46
+ for (const node of resultNodes) {
46
47
  if (results.length >= maxLimit) break;
47
48
 
48
- const titleMatch = block.match(/<h2 class="result__title">[\s\S]*?<a[^>]*>([\s\S]*?)<\/a>/i);
49
- const snippetMatch = block.match(/<a class="result__snippet[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/i);
49
+ const titleEl = node.querySelector('.result__title a');
50
+ const snippetEl = node.querySelector('.result__snippet');
50
51
 
51
- if (titleMatch && snippetMatch) {
52
- // Strip nested HTML tags (like <b> tags for highlighted keywords)
53
- const title = titleMatch[1].replace(/<[^>]+>/g, '').trim();
54
- const snippet = snippetMatch[2].replace(/<[^>]+>/g, '').trim();
52
+ if (titleEl && snippetEl) {
53
+ const title = titleEl.textContent.replace(/\s+/g, ' ').trim();
54
+ const snippet = snippetEl.textContent.replace(/\s+/g, ' ').trim();
55
55
 
56
- // Clean DuckDuckGo's tracking wrapper from the URL
57
- let url = snippetMatch[1];
56
+ let url = titleEl.getAttribute('href') || '';
58
57
  if (url.startsWith('//duckduckgo.com/l/?uddg=')) {
59
58
  url = decodeURIComponent(url.split('uddg=')[1].split('&')[0]);
60
59
  }