@jackwener/opencli 1.1.0 → 1.2.0
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/.agents/skills/cross-project-adapter-migration/SKILL.md +2 -2
- package/.github/pull_request_template.md +7 -0
- package/.github/workflows/doc-check.yml +36 -0
- package/.github/workflows/docs.yml +7 -42
- package/CHANGELOG.md +23 -0
- package/CLI-EXPLORER.md +9 -8
- package/CONTRIBUTING.md +39 -1
- package/README.md +33 -19
- package/README.zh-CN.md +64 -27
- package/SKILL.md +102 -33
- package/dist/browser/cdp.d.ts +4 -4
- package/dist/browser/cdp.js +45 -17
- package/dist/browser/daemon-client.d.ts +2 -1
- package/dist/browser/dom-helpers.js +38 -7
- package/dist/browser/dom-snapshot.d.ts +86 -0
- package/dist/browser/dom-snapshot.js +729 -0
- package/dist/browser/dom-snapshot.test.d.ts +11 -0
- package/dist/browser/dom-snapshot.test.js +212 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/page.d.ts +18 -25
- package/dist/browser/page.js +44 -5
- package/dist/build-manifest.d.ts +11 -4
- package/dist/build-manifest.js +79 -34
- package/dist/build-manifest.test.js +58 -2
- package/dist/cli-manifest.json +4273 -1771
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +255 -162
- package/dist/clis/apple-podcasts/commands.test.d.ts +2 -0
- package/dist/clis/apple-podcasts/commands.test.js +76 -0
- package/dist/clis/apple-podcasts/search.js +2 -2
- package/dist/clis/apple-podcasts/top.js +9 -2
- package/dist/clis/arxiv/search.js +1 -1
- package/dist/clis/barchart/greeks.js +1 -1
- package/dist/clis/barchart/options.js +1 -1
- package/dist/clis/barchart/quote.js +1 -1
- package/dist/clis/bilibili/download.js +1 -1
- package/dist/clis/bilibili/dynamic.js +1 -1
- package/dist/clis/bilibili/favorite.js +1 -1
- package/dist/clis/bilibili/feed.js +1 -1
- package/dist/clis/bilibili/following.js +2 -2
- package/dist/clis/bilibili/history.js +1 -1
- package/dist/clis/bilibili/me.js +1 -1
- package/dist/clis/bilibili/ranking.js +1 -1
- package/dist/clis/bilibili/search.js +3 -3
- package/dist/clis/bilibili/subtitle.js +2 -2
- package/dist/clis/bilibili/user-videos.js +2 -2
- package/dist/{bilibili.d.ts → clis/bilibili/utils.d.ts} +1 -1
- package/dist/clis/bloomberg/businessweek.js +17 -0
- package/dist/clis/bloomberg/economics.js +17 -0
- package/dist/clis/bloomberg/feeds.d.ts +1 -0
- package/dist/clis/bloomberg/feeds.js +15 -0
- package/dist/clis/bloomberg/industries.d.ts +1 -0
- package/dist/clis/bloomberg/industries.js +17 -0
- package/dist/clis/bloomberg/main.d.ts +1 -0
- package/dist/clis/bloomberg/main.js +17 -0
- package/dist/clis/bloomberg/markets.d.ts +1 -0
- package/dist/clis/bloomberg/markets.js +17 -0
- package/dist/clis/bloomberg/news.d.ts +1 -0
- package/dist/clis/bloomberg/news.js +105 -0
- package/dist/clis/bloomberg/opinions.d.ts +1 -0
- package/dist/clis/bloomberg/opinions.js +17 -0
- package/dist/clis/bloomberg/politics.d.ts +1 -0
- package/dist/clis/bloomberg/politics.js +17 -0
- package/dist/clis/bloomberg/tech.d.ts +1 -0
- package/dist/clis/bloomberg/tech.js +17 -0
- package/dist/clis/bloomberg/utils.d.ts +34 -0
- package/dist/clis/bloomberg/utils.js +364 -0
- package/dist/clis/bloomberg/utils.test.d.ts +1 -0
- package/dist/clis/bloomberg/utils.test.js +129 -0
- package/dist/clis/boss/batchgreet.js +12 -99
- package/dist/clis/boss/chatlist.js +9 -26
- package/dist/clis/boss/chatmsg.js +11 -42
- package/dist/clis/boss/common.d.ts +92 -0
- package/dist/clis/boss/common.js +223 -0
- package/dist/clis/boss/detail.js +8 -50
- package/dist/clis/boss/exchange.js +13 -79
- package/dist/clis/boss/greet.js +20 -147
- package/dist/clis/boss/invite.js +26 -121
- package/dist/clis/boss/joblist.js +6 -31
- package/dist/clis/boss/mark.js +12 -85
- package/dist/clis/boss/recommend.js +10 -49
- package/dist/clis/boss/resume.js +18 -118
- package/dist/clis/boss/search.js +13 -61
- package/dist/clis/boss/send.js +18 -152
- package/dist/clis/boss/stats.js +20 -71
- package/dist/clis/chaoxing/assignments.js +1 -1
- package/dist/clis/chaoxing/exams.js +1 -1
- package/dist/{chaoxing.d.ts → clis/chaoxing/utils.d.ts} +1 -1
- package/dist/{chaoxing.js → clis/chaoxing/utils.js} +0 -2
- package/dist/clis/chaoxing/utils.test.d.ts +1 -0
- package/dist/{chaoxing.test.js → clis/chaoxing/utils.test.js} +1 -1
- package/dist/clis/chatgpt/read.js +1 -1
- package/dist/clis/chatwise/export.js +1 -1
- package/dist/clis/chatwise/model.js +2 -2
- package/dist/clis/chatwise/screenshot.js +1 -1
- package/dist/clis/codex/export.js +1 -1
- package/dist/clis/codex/model.js +2 -2
- package/dist/clis/codex/screenshot.js +1 -1
- package/dist/clis/coupang/add-to-cart.js +3 -4
- package/dist/clis/coupang/search.js +2 -4
- package/dist/clis/coupang/utils.test.d.ts +1 -0
- package/dist/{coupang.test.js → clis/coupang/utils.test.js} +1 -1
- package/dist/clis/ctrip/search.js +1 -1
- package/dist/clis/cursor/export.js +1 -1
- package/dist/clis/cursor/model.js +2 -2
- package/dist/clis/cursor/screenshot.js +1 -1
- package/dist/clis/devto/tag.yaml +34 -0
- package/dist/clis/devto/top.yaml +29 -0
- package/dist/clis/devto/user.yaml +33 -0
- package/dist/clis/douban/book-hot.d.ts +1 -0
- package/dist/clis/douban/book-hot.js +14 -0
- package/dist/clis/douban/marks.d.ts +1 -0
- package/dist/clis/douban/marks.js +115 -0
- package/dist/clis/douban/movie-hot.d.ts +1 -0
- package/dist/clis/douban/movie-hot.js +14 -0
- package/dist/clis/douban/reviews.d.ts +1 -0
- package/dist/clis/douban/reviews.js +106 -0
- package/dist/clis/douban/search.d.ts +1 -0
- package/dist/clis/douban/search.js +16 -0
- package/dist/clis/douban/shared.d.ts +4 -0
- package/dist/clis/douban/shared.js +155 -0
- package/dist/clis/douban/subject.yaml +76 -0
- package/dist/clis/douban/top250.yaml +70 -0
- package/dist/clis/douban/utils.d.ts +35 -0
- package/dist/clis/douban/utils.js +48 -0
- package/dist/clis/facebook/add-friend.yaml +43 -0
- package/dist/clis/facebook/events.yaml +44 -0
- package/dist/clis/facebook/feed.yaml +63 -0
- package/dist/clis/facebook/friends.yaml +42 -0
- package/dist/clis/facebook/groups.yaml +50 -0
- package/dist/clis/facebook/join-group.yaml +44 -0
- package/dist/clis/facebook/memories.yaml +39 -0
- package/dist/clis/facebook/notifications.yaml +40 -0
- package/dist/clis/facebook/profile.yaml +37 -0
- package/dist/clis/facebook/search.yaml +46 -0
- package/dist/clis/google/news.d.ts +5 -0
- package/dist/clis/google/news.js +58 -0
- package/dist/clis/google/search.d.ts +10 -0
- package/dist/clis/google/search.js +127 -0
- package/dist/clis/google/suggest.d.ts +5 -0
- package/dist/clis/google/suggest.js +34 -0
- package/dist/clis/google/trends.d.ts +5 -0
- package/dist/clis/google/trends.js +38 -0
- package/dist/clis/google/utils.d.ts +9 -0
- package/dist/clis/google/utils.js +23 -0
- package/dist/clis/google/utils.test.d.ts +1 -0
- package/dist/clis/google/utils.test.js +75 -0
- package/dist/clis/grok/ask.d.ts +14 -0
- package/dist/clis/grok/ask.js +257 -65
- package/dist/clis/grok/ask.test.d.ts +1 -0
- package/dist/clis/grok/ask.test.js +36 -0
- package/dist/clis/instagram/comment.yaml +52 -0
- package/dist/clis/instagram/explore.yaml +43 -0
- package/dist/clis/instagram/follow.yaml +41 -0
- package/dist/clis/instagram/followers.yaml +51 -0
- package/dist/clis/instagram/following.yaml +51 -0
- package/dist/clis/instagram/like.yaml +46 -0
- package/dist/clis/instagram/profile.yaml +42 -0
- package/dist/clis/instagram/save.yaml +46 -0
- package/dist/clis/instagram/saved.yaml +40 -0
- package/dist/clis/instagram/search.yaml +43 -0
- package/dist/clis/instagram/unfollow.yaml +38 -0
- package/dist/clis/instagram/unlike.yaml +46 -0
- package/dist/clis/instagram/unsave.yaml +46 -0
- package/dist/clis/instagram/user.yaml +54 -0
- package/dist/clis/jike/comment.js +2 -3
- package/dist/clis/jike/create.js +1 -2
- package/dist/clis/jike/feed.js +0 -1
- package/dist/clis/jike/like.js +1 -2
- package/dist/clis/jike/notifications.js +0 -1
- package/dist/clis/jike/post.yaml +1 -0
- package/dist/clis/jike/repost.js +2 -3
- package/dist/clis/jike/search.js +2 -3
- package/dist/clis/jike/topic.yaml +1 -0
- package/dist/clis/jike/user.yaml +1 -0
- package/dist/clis/jimeng/generate.yaml +1 -0
- package/dist/clis/jimeng/history.yaml +0 -1
- package/dist/clis/linkedin/search.js +7 -7
- package/dist/clis/linux-do/category.yaml +2 -0
- package/dist/clis/linux-do/search.yaml +4 -3
- package/dist/clis/linux-do/topic.yaml +1 -0
- package/dist/clis/lobsters/active.yaml +29 -0
- package/dist/clis/lobsters/hot.yaml +29 -0
- package/dist/clis/lobsters/newest.yaml +29 -0
- package/dist/clis/lobsters/tag.yaml +34 -0
- package/dist/clis/medium/feed.d.ts +1 -0
- package/dist/clis/medium/feed.js +15 -0
- package/dist/clis/medium/search.d.ts +1 -0
- package/dist/clis/medium/search.js +15 -0
- package/dist/clis/medium/shared.d.ts +5 -0
- package/dist/clis/medium/shared.js +78 -0
- package/dist/clis/medium/user.d.ts +1 -0
- package/dist/clis/medium/user.js +15 -0
- package/dist/clis/notion/export.js +1 -1
- package/dist/clis/reddit/comment.js +3 -4
- package/dist/clis/reddit/read.js +4 -5
- package/dist/clis/reddit/save.js +2 -3
- package/dist/clis/reddit/saved.js +0 -1
- package/dist/clis/reddit/search.yaml +1 -0
- package/dist/clis/reddit/subreddit.yaml +1 -0
- package/dist/clis/reddit/subscribe.js +1 -2
- package/dist/clis/reddit/upvote.js +2 -3
- package/dist/clis/reddit/upvoted.js +0 -1
- package/dist/clis/reddit/user-comments.yaml +1 -0
- package/dist/clis/reddit/user-posts.yaml +1 -0
- package/dist/clis/reddit/user.yaml +1 -0
- package/dist/clis/reuters/search.js +1 -1
- package/dist/clis/sinablog/article.d.ts +1 -0
- package/dist/clis/sinablog/article.js +14 -0
- package/dist/clis/sinablog/hot.d.ts +1 -0
- package/dist/clis/sinablog/hot.js +14 -0
- package/dist/clis/sinablog/search.d.ts +1 -0
- package/dist/clis/sinablog/search.js +51 -0
- package/dist/clis/sinablog/shared.d.ts +7 -0
- package/dist/clis/sinablog/shared.js +187 -0
- package/dist/clis/sinablog/user.d.ts +1 -0
- package/dist/clis/sinablog/user.js +15 -0
- package/dist/clis/smzdm/search.js +2 -3
- package/dist/clis/stackoverflow/search.yaml +1 -0
- package/dist/clis/steam/top-sellers.yaml +29 -0
- package/dist/clis/substack/feed.d.ts +1 -0
- package/dist/clis/substack/feed.js +15 -0
- package/dist/clis/substack/publication.d.ts +1 -0
- package/dist/clis/substack/publication.js +15 -0
- package/dist/clis/substack/search.d.ts +1 -0
- package/dist/clis/substack/search.js +77 -0
- package/dist/clis/substack/shared.d.ts +4 -0
- package/dist/clis/substack/shared.js +129 -0
- package/dist/clis/tiktok/comment.yaml +66 -0
- package/dist/clis/tiktok/explore.yaml +39 -0
- package/dist/clis/tiktok/follow.yaml +39 -0
- package/dist/clis/tiktok/following.yaml +46 -0
- package/dist/clis/tiktok/friends.yaml +47 -0
- package/dist/clis/tiktok/like.yaml +38 -0
- package/dist/clis/tiktok/live.yaml +51 -0
- package/dist/clis/tiktok/notifications.yaml +52 -0
- package/dist/clis/tiktok/profile.yaml +45 -0
- package/dist/clis/tiktok/save.yaml +34 -0
- package/dist/clis/tiktok/search.yaml +46 -0
- package/dist/clis/tiktok/unfollow.yaml +44 -0
- package/dist/clis/tiktok/unlike.yaml +38 -0
- package/dist/clis/tiktok/unsave.yaml +36 -0
- package/dist/clis/tiktok/user.yaml +44 -0
- package/dist/clis/twitter/accept.js +2 -2
- package/dist/clis/twitter/article.js +2 -2
- package/dist/clis/twitter/block.d.ts +1 -0
- package/dist/clis/twitter/block.js +88 -0
- package/dist/clis/twitter/delete.js +1 -1
- package/dist/clis/twitter/download.d.ts +1 -1
- package/dist/clis/twitter/download.js +3 -3
- package/dist/clis/twitter/followers.js +1 -1
- package/dist/clis/twitter/following.js +1 -1
- package/dist/clis/twitter/hide-reply.d.ts +1 -0
- package/dist/clis/twitter/hide-reply.js +66 -0
- package/dist/clis/twitter/like.js +1 -1
- package/dist/clis/twitter/post.js +1 -1
- package/dist/clis/twitter/reply-dm.js +1 -1
- package/dist/clis/twitter/reply.js +2 -2
- package/dist/clis/twitter/search.js +1 -1
- package/dist/clis/twitter/thread.js +2 -2
- package/dist/clis/twitter/timeline.d.ts +23 -0
- package/dist/clis/twitter/timeline.js +42 -14
- package/dist/clis/twitter/timeline.test.d.ts +1 -0
- package/dist/clis/twitter/timeline.test.js +102 -0
- package/dist/clis/twitter/trending.d.ts +1 -0
- package/dist/clis/twitter/trending.js +91 -0
- package/dist/clis/twitter/unblock.d.ts +1 -0
- package/dist/clis/twitter/unblock.js +71 -0
- package/dist/clis/v2ex/topic.yaml +1 -0
- package/dist/clis/weibo/hot.js +0 -1
- package/dist/clis/weread/book.js +1 -1
- package/dist/clis/weread/highlights.js +1 -1
- package/dist/clis/weread/notes.js +1 -1
- package/dist/clis/weread/search.js +1 -1
- package/dist/clis/wikipedia/random.d.ts +1 -0
- package/dist/clis/wikipedia/random.js +19 -0
- package/dist/clis/wikipedia/search.js +4 -4
- package/dist/clis/wikipedia/summary.js +4 -9
- package/dist/clis/wikipedia/trending.d.ts +1 -0
- package/dist/clis/wikipedia/trending.js +35 -0
- package/dist/clis/wikipedia/utils.d.ts +28 -0
- package/dist/clis/wikipedia/utils.js +13 -0
- package/dist/clis/xiaohongshu/creator-note-detail.d.ts +15 -0
- package/dist/clis/xiaohongshu/creator-note-detail.js +69 -5
- package/dist/clis/xiaohongshu/creator-note-detail.test.js +82 -33
- package/dist/clis/xiaohongshu/creator-notes.js +35 -5
- package/dist/clis/xiaohongshu/creator-notes.test.js +37 -6
- package/dist/clis/xiaohongshu/creator-profile.js +0 -1
- package/dist/clis/xiaohongshu/creator-stats.js +0 -1
- package/dist/clis/xiaohongshu/download.js +2 -3
- package/dist/clis/xiaohongshu/feed.yaml +0 -1
- package/dist/clis/xiaohongshu/notifications.yaml +0 -1
- package/dist/clis/xiaohongshu/search.js +2 -2
- package/dist/clis/xiaohongshu/user.js +1 -2
- package/dist/clis/xueqiu/earnings-date.yaml +69 -0
- package/dist/clis/xueqiu/search.yaml +2 -1
- package/dist/clis/xueqiu/stock.yaml +2 -0
- package/dist/clis/yahoo-finance/quote.js +1 -2
- package/dist/clis/youtube/search.js +1 -1
- package/dist/clis/youtube/transcript.js +1 -1
- package/dist/clis/youtube/video.js +1 -1
- package/dist/clis/zhihu/download.js +1 -2
- package/dist/clis/zhihu/question.js +1 -1
- package/dist/clis/zhihu/search.yaml +4 -3
- package/dist/commanderAdapter.d.ts +21 -0
- package/dist/commanderAdapter.js +117 -0
- package/dist/{engine.d.ts → discovery.d.ts} +6 -4
- package/dist/{engine.js → discovery.js} +93 -104
- package/dist/doctor.js +3 -1
- package/dist/doctor.test.js +46 -2
- package/dist/download/index.d.ts +2 -6
- package/dist/download/index.js +19 -46
- package/dist/engine.test.d.ts +0 -3
- package/dist/engine.test.js +80 -11
- package/dist/execution.d.ts +24 -0
- package/dist/execution.js +153 -0
- package/dist/explore.d.ts +76 -3
- package/dist/explore.js +132 -111
- package/dist/external-clis.yaml +48 -0
- package/dist/external.d.ts +7 -2
- package/dist/external.js +11 -14
- package/dist/generate.d.ts +41 -2
- package/dist/generate.js +5 -4
- package/dist/main.js +2 -1
- package/dist/pipeline/executor.d.ts +2 -2
- package/dist/pipeline/executor.js +2 -2
- package/dist/pipeline/executor.test.js +33 -6
- package/dist/pipeline/registry.d.ts +1 -1
- package/dist/pipeline/steps/browser.d.ts +7 -7
- package/dist/pipeline/steps/browser.js +21 -7
- package/dist/pipeline/steps/fetch.d.ts +1 -1
- package/dist/pipeline/steps/fetch.js +11 -7
- package/dist/pipeline/steps/transform.d.ts +6 -5
- package/dist/pipeline/steps/transform.js +30 -9
- package/dist/pipeline/template.d.ts +6 -6
- package/dist/pipeline/template.js +43 -5
- package/dist/pipeline/template.test.js +18 -0
- package/dist/pipeline/transform.test.js +11 -0
- package/dist/plugin.d.ts +31 -0
- package/dist/plugin.js +216 -0
- package/dist/plugin.test.d.ts +4 -0
- package/dist/plugin.test.js +76 -0
- package/dist/registry-api.d.ts +11 -0
- package/dist/registry-api.js +9 -0
- package/dist/registry.d.ts +13 -0
- package/dist/registry.js +8 -1
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.js +8 -0
- package/dist/serialization.d.ts +34 -0
- package/dist/serialization.js +63 -0
- package/dist/synthesize.d.ts +94 -4
- package/dist/synthesize.js +5 -4
- package/dist/types.d.ts +43 -27
- package/dist/validate.js +8 -2
- package/docs/.vitepress/config.mts +20 -7
- package/docs/adapters/browser/arxiv.md +27 -0
- package/docs/adapters/browser/barchart.md +33 -0
- package/docs/adapters/browser/bilibili.md +9 -0
- package/docs/adapters/browser/bloomberg.md +70 -0
- package/docs/adapters/browser/chaoxing.md +39 -0
- package/docs/adapters/browser/devto.md +35 -0
- package/docs/adapters/browser/douban.md +38 -0
- package/docs/adapters/browser/facebook.md +36 -0
- package/docs/adapters/browser/google.md +62 -0
- package/docs/adapters/browser/grok.md +53 -0
- package/docs/adapters/browser/hf.md +42 -0
- package/docs/adapters/browser/instagram.md +46 -0
- package/docs/adapters/browser/jike.md +45 -0
- package/docs/adapters/browser/jimeng.md +39 -0
- package/docs/adapters/browser/linux-do.md +45 -0
- package/docs/adapters/browser/lobsters.md +32 -0
- package/docs/adapters/browser/medium.md +32 -0
- package/docs/adapters/browser/reddit.md +9 -0
- package/docs/adapters/browser/sinablog.md +36 -0
- package/docs/adapters/browser/sinafinance.md +35 -0
- package/docs/adapters/browser/stackoverflow.md +35 -0
- package/docs/adapters/browser/steam.md +26 -0
- package/docs/adapters/browser/substack.md +38 -0
- package/docs/adapters/browser/tiktok.md +68 -0
- package/docs/adapters/browser/twitter.md +3 -0
- package/docs/adapters/browser/weread.md +48 -0
- package/docs/adapters/browser/wikipedia.md +39 -0
- package/docs/adapters/browser/xiaohongshu.md +5 -1
- package/docs/adapters/browser/xueqiu.md +10 -0
- package/docs/adapters/browser/yahoo-finance.md +6 -5
- package/docs/adapters/desktop/antigravity.md +6 -0
- package/docs/adapters/desktop/chatgpt.md +5 -4
- package/docs/adapters/desktop/codex.md +5 -1
- package/docs/adapters/desktop/cursor.md +4 -0
- package/docs/adapters/desktop/discord.md +7 -7
- package/docs/adapters/index.md +14 -4
- package/docs/advanced/download.md +4 -4
- package/docs/developer/architecture.md +17 -4
- package/docs/guide/getting-started.md +1 -0
- package/docs/guide/plugins.md +153 -0
- package/docs/zh/guide/plugins.md +107 -0
- package/extension/src/background.ts +18 -11
- package/package.json +10 -5
- package/scripts/check-doc-coverage.sh +69 -0
- package/scripts/clean-dist.cjs +13 -0
- package/scripts/copy-yaml.cjs +7 -0
- package/src/browser/cdp.ts +77 -32
- package/src/browser/daemon-client.ts +2 -1
- package/src/browser/dom-helpers.ts +38 -7
- package/src/browser/dom-snapshot.test.ts +249 -0
- package/src/browser/dom-snapshot.ts +770 -0
- package/src/browser/index.ts +2 -0
- package/src/browser/page.ts +57 -20
- package/src/build-manifest.test.ts +70 -2
- package/src/build-manifest.ts +114 -40
- package/src/cli.ts +287 -139
- package/src/clis/apple-podcasts/commands.test.ts +95 -0
- package/src/clis/apple-podcasts/search.ts +2 -2
- package/src/clis/apple-podcasts/top.ts +12 -2
- package/src/clis/arxiv/search.ts +1 -1
- package/src/clis/barchart/greeks.ts +1 -1
- package/src/clis/barchart/options.ts +1 -1
- package/src/clis/barchart/quote.ts +1 -1
- package/src/clis/bilibili/download.ts +1 -1
- package/src/clis/bilibili/dynamic.ts +1 -1
- package/src/clis/bilibili/favorite.ts +1 -1
- package/src/clis/bilibili/feed.ts +1 -1
- package/src/clis/bilibili/following.ts +2 -2
- package/src/clis/bilibili/history.ts +1 -1
- package/src/clis/bilibili/me.ts +1 -1
- package/src/clis/bilibili/ranking.ts +1 -1
- package/src/clis/bilibili/search.ts +3 -3
- package/src/clis/bilibili/subtitle.ts +2 -2
- package/src/clis/bilibili/user-videos.ts +2 -2
- package/src/{bilibili.ts → clis/bilibili/utils.ts} +1 -1
- package/src/clis/bloomberg/businessweek.ts +18 -0
- package/src/clis/bloomberg/economics.ts +18 -0
- package/src/clis/bloomberg/feeds.ts +16 -0
- package/src/clis/bloomberg/industries.ts +18 -0
- package/src/clis/bloomberg/main.ts +18 -0
- package/src/clis/bloomberg/markets.ts +18 -0
- package/src/clis/bloomberg/news.ts +136 -0
- package/src/clis/bloomberg/opinions.ts +18 -0
- package/src/clis/bloomberg/politics.ts +18 -0
- package/src/clis/bloomberg/tech.ts +18 -0
- package/src/clis/bloomberg/utils.test.ts +135 -0
- package/src/clis/bloomberg/utils.ts +429 -0
- package/src/clis/boss/batchgreet.ts +16 -108
- package/src/clis/boss/chatlist.ts +13 -27
- package/src/clis/boss/chatmsg.ts +16 -40
- package/src/clis/boss/common.ts +287 -0
- package/src/clis/boss/detail.ts +9 -55
- package/src/clis/boss/exchange.ts +15 -89
- package/src/clis/boss/greet.ts +25 -162
- package/src/clis/boss/invite.ts +36 -133
- package/src/clis/boss/joblist.ts +7 -36
- package/src/clis/boss/mark.ts +13 -94
- package/src/clis/boss/recommend.ts +12 -57
- package/src/clis/boss/resume.ts +19 -124
- package/src/clis/boss/search.ts +14 -67
- package/src/clis/boss/send.ts +22 -162
- package/src/clis/boss/stats.ts +21 -76
- package/src/clis/chaoxing/assignments.ts +1 -1
- package/src/clis/chaoxing/exams.ts +1 -1
- package/src/{chaoxing.test.ts → clis/chaoxing/utils.test.ts} +1 -1
- package/src/{chaoxing.ts → clis/chaoxing/utils.ts} +1 -3
- package/src/clis/chatgpt/read.ts +1 -1
- package/src/clis/chatwise/export.ts +1 -1
- package/src/clis/chatwise/model.ts +2 -2
- package/src/clis/chatwise/screenshot.ts +1 -1
- package/src/clis/codex/export.ts +1 -1
- package/src/clis/codex/model.ts +2 -2
- package/src/clis/codex/screenshot.ts +1 -1
- package/src/clis/coupang/add-to-cart.ts +3 -4
- package/src/clis/coupang/search.ts +2 -4
- package/src/{coupang.test.ts → clis/coupang/utils.test.ts} +1 -1
- package/src/clis/ctrip/search.ts +1 -1
- package/src/clis/cursor/export.ts +1 -1
- package/src/clis/cursor/model.ts +2 -2
- package/src/clis/cursor/screenshot.ts +1 -1
- package/src/clis/devto/tag.yaml +34 -0
- package/src/clis/devto/top.yaml +29 -0
- package/src/clis/devto/user.yaml +33 -0
- package/src/clis/douban/book-hot.ts +15 -0
- package/src/clis/douban/marks.ts +135 -0
- package/src/clis/douban/movie-hot.ts +15 -0
- package/src/clis/douban/reviews.ts +127 -0
- package/src/clis/douban/search.ts +17 -0
- package/src/clis/douban/shared.ts +165 -0
- package/src/clis/douban/subject.yaml +76 -0
- package/src/clis/douban/top250.yaml +70 -0
- package/src/clis/douban/utils.ts +81 -0
- package/src/clis/facebook/add-friend.yaml +43 -0
- package/src/clis/facebook/events.yaml +44 -0
- package/src/clis/facebook/feed.yaml +63 -0
- package/src/clis/facebook/friends.yaml +42 -0
- package/src/clis/facebook/groups.yaml +50 -0
- package/src/clis/facebook/join-group.yaml +44 -0
- package/src/clis/facebook/memories.yaml +39 -0
- package/src/clis/facebook/notifications.yaml +40 -0
- package/src/clis/facebook/profile.yaml +37 -0
- package/src/clis/facebook/search.yaml +46 -0
- package/src/clis/google/news.ts +66 -0
- package/src/clis/google/search.ts +133 -0
- package/src/clis/google/suggest.ts +40 -0
- package/src/clis/google/trends.ts +44 -0
- package/src/clis/google/utils.test.ts +82 -0
- package/src/clis/google/utils.ts +24 -0
- package/src/clis/grok/ask.test.ts +53 -0
- package/src/clis/grok/ask.ts +300 -69
- package/src/clis/instagram/comment.yaml +52 -0
- package/src/clis/instagram/explore.yaml +43 -0
- package/src/clis/instagram/follow.yaml +41 -0
- package/src/clis/instagram/followers.yaml +51 -0
- package/src/clis/instagram/following.yaml +51 -0
- package/src/clis/instagram/like.yaml +46 -0
- package/src/clis/instagram/profile.yaml +42 -0
- package/src/clis/instagram/save.yaml +46 -0
- package/src/clis/instagram/saved.yaml +40 -0
- package/src/clis/instagram/search.yaml +43 -0
- package/src/clis/instagram/unfollow.yaml +38 -0
- package/src/clis/instagram/unlike.yaml +46 -0
- package/src/clis/instagram/unsave.yaml +46 -0
- package/src/clis/instagram/user.yaml +54 -0
- package/src/clis/jike/comment.ts +2 -3
- package/src/clis/jike/create.ts +1 -2
- package/src/clis/jike/feed.ts +0 -1
- package/src/clis/jike/like.ts +1 -2
- package/src/clis/jike/notifications.ts +0 -1
- package/src/clis/jike/post.yaml +1 -0
- package/src/clis/jike/repost.ts +2 -3
- package/src/clis/jike/search.ts +2 -3
- package/src/clis/jike/topic.yaml +1 -0
- package/src/clis/jike/user.yaml +1 -0
- package/src/clis/jimeng/generate.yaml +1 -0
- package/src/clis/jimeng/history.yaml +0 -1
- package/src/clis/linkedin/search.ts +7 -7
- package/src/clis/linux-do/category.yaml +2 -0
- package/src/clis/linux-do/search.yaml +4 -3
- package/src/clis/linux-do/topic.yaml +1 -0
- package/src/clis/lobsters/active.yaml +29 -0
- package/src/clis/lobsters/hot.yaml +29 -0
- package/src/clis/lobsters/newest.yaml +29 -0
- package/src/clis/lobsters/tag.yaml +34 -0
- package/src/clis/medium/feed.ts +16 -0
- package/src/clis/medium/search.ts +16 -0
- package/src/clis/medium/shared.ts +83 -0
- package/src/clis/medium/user.ts +16 -0
- package/src/clis/notion/export.ts +1 -1
- package/src/clis/reddit/comment.ts +3 -4
- package/src/clis/reddit/read.ts +4 -5
- package/src/clis/reddit/save.ts +2 -3
- package/src/clis/reddit/saved.ts +0 -1
- package/src/clis/reddit/search.yaml +1 -0
- package/src/clis/reddit/subreddit.yaml +1 -0
- package/src/clis/reddit/subscribe.ts +1 -2
- package/src/clis/reddit/upvote.ts +2 -3
- package/src/clis/reddit/upvoted.ts +0 -1
- package/src/clis/reddit/user-comments.yaml +1 -0
- package/src/clis/reddit/user-posts.yaml +1 -0
- package/src/clis/reddit/user.yaml +1 -0
- package/src/clis/reuters/search.ts +1 -1
- package/src/clis/sinablog/article.ts +15 -0
- package/src/clis/sinablog/hot.ts +15 -0
- package/src/clis/sinablog/search.ts +56 -0
- package/src/clis/sinablog/shared.ts +198 -0
- package/src/clis/sinablog/user.ts +16 -0
- package/src/clis/smzdm/search.ts +2 -3
- package/src/clis/stackoverflow/search.yaml +1 -0
- package/src/clis/steam/top-sellers.yaml +29 -0
- package/src/clis/substack/feed.ts +16 -0
- package/src/clis/substack/publication.ts +16 -0
- package/src/clis/substack/search.ts +91 -0
- package/src/clis/substack/shared.ts +132 -0
- package/src/clis/tiktok/comment.yaml +66 -0
- package/src/clis/tiktok/explore.yaml +39 -0
- package/src/clis/tiktok/follow.yaml +39 -0
- package/src/clis/tiktok/following.yaml +46 -0
- package/src/clis/tiktok/friends.yaml +47 -0
- package/src/clis/tiktok/like.yaml +38 -0
- package/src/clis/tiktok/live.yaml +51 -0
- package/src/clis/tiktok/notifications.yaml +52 -0
- package/src/clis/tiktok/profile.yaml +45 -0
- package/src/clis/tiktok/save.yaml +34 -0
- package/src/clis/tiktok/search.yaml +46 -0
- package/src/clis/tiktok/unfollow.yaml +44 -0
- package/src/clis/tiktok/unlike.yaml +38 -0
- package/src/clis/tiktok/unsave.yaml +36 -0
- package/src/clis/tiktok/user.yaml +44 -0
- package/src/clis/twitter/accept.ts +2 -2
- package/src/clis/twitter/article.ts +2 -2
- package/src/clis/twitter/block.ts +92 -0
- package/src/clis/twitter/delete.ts +1 -1
- package/src/clis/twitter/download.ts +3 -3
- package/src/clis/twitter/followers.ts +1 -1
- package/src/clis/twitter/following.ts +1 -1
- package/src/clis/twitter/hide-reply.ts +70 -0
- package/src/clis/twitter/like.ts +1 -1
- package/src/clis/twitter/post.ts +1 -1
- package/src/clis/twitter/reply-dm.ts +1 -1
- package/src/clis/twitter/reply.ts +2 -2
- package/src/clis/twitter/search.ts +1 -1
- package/src/clis/twitter/thread.ts +2 -2
- package/src/clis/twitter/timeline.test.ts +109 -0
- package/src/clis/twitter/timeline.ts +59 -19
- package/src/clis/twitter/trending.ts +113 -0
- package/src/clis/twitter/unblock.ts +75 -0
- package/src/clis/v2ex/topic.yaml +1 -0
- package/src/clis/weibo/hot.ts +0 -1
- package/src/clis/weread/book.ts +1 -1
- package/src/clis/weread/highlights.ts +1 -1
- package/src/clis/weread/notes.ts +1 -1
- package/src/clis/weread/search.ts +1 -1
- package/src/clis/wikipedia/random.ts +19 -0
- package/src/clis/wikipedia/search.ts +11 -5
- package/src/clis/wikipedia/summary.ts +4 -9
- package/src/clis/wikipedia/trending.ts +41 -0
- package/src/clis/wikipedia/utils.ts +31 -0
- package/src/clis/xiaohongshu/creator-note-detail.test.ts +84 -33
- package/src/clis/xiaohongshu/creator-note-detail.ts +89 -5
- package/src/clis/xiaohongshu/creator-notes.test.ts +41 -6
- package/src/clis/xiaohongshu/creator-notes.ts +44 -5
- package/src/clis/xiaohongshu/creator-profile.ts +0 -1
- package/src/clis/xiaohongshu/creator-stats.ts +0 -1
- package/src/clis/xiaohongshu/download.ts +2 -3
- package/src/clis/xiaohongshu/feed.yaml +0 -1
- package/src/clis/xiaohongshu/notifications.yaml +0 -1
- package/src/clis/xiaohongshu/search.ts +2 -2
- package/src/clis/xiaohongshu/user.ts +1 -2
- package/src/clis/xueqiu/earnings-date.yaml +69 -0
- package/src/clis/xueqiu/search.yaml +2 -1
- package/src/clis/xueqiu/stock.yaml +2 -0
- package/src/clis/yahoo-finance/quote.ts +1 -2
- package/src/clis/youtube/search.ts +1 -1
- package/src/clis/youtube/transcript.ts +1 -1
- package/src/clis/youtube/video.ts +1 -1
- package/src/clis/zhihu/download.ts +1 -2
- package/src/clis/zhihu/question.ts +1 -1
- package/src/clis/zhihu/search.yaml +4 -3
- package/src/commanderAdapter.ts +120 -0
- package/src/discovery.ts +277 -0
- package/src/doctor.test.ts +59 -2
- package/src/doctor.ts +4 -2
- package/src/download/index.ts +21 -54
- package/src/engine.test.ts +85 -11
- package/src/execution.ts +164 -0
- package/src/explore.ts +211 -117
- package/src/external-clis.yaml +9 -0
- package/src/external.ts +15 -12
- package/src/generate.ts +58 -9
- package/src/main.ts +2 -1
- package/src/pipeline/executor.test.ts +35 -6
- package/src/pipeline/executor.ts +11 -7
- package/src/pipeline/registry.ts +3 -3
- package/src/pipeline/steps/browser.ts +29 -15
- package/src/pipeline/steps/fetch.ts +18 -13
- package/src/pipeline/steps/transform.ts +40 -15
- package/src/pipeline/template.test.ts +18 -0
- package/src/pipeline/template.ts +86 -13
- package/src/pipeline/transform.test.ts +15 -2
- package/src/plugin.test.ts +86 -0
- package/src/plugin.ts +254 -0
- package/src/registry-api.ts +12 -0
- package/src/registry.ts +24 -1
- package/src/runtime.ts +9 -0
- package/src/serialization.ts +79 -0
- package/src/synthesize.ts +102 -21
- package/src/types.ts +45 -13
- package/src/validate.ts +19 -4
- package/tests/e2e/browser-public.test.ts +36 -0
- package/tests/e2e/public-commands.test.ts +119 -1
- package/dist/clis/feishu/new.d.ts +0 -1
- package/dist/clis/feishu/new.js +0 -27
- package/dist/clis/feishu/read.d.ts +0 -1
- package/dist/clis/feishu/read.js +0 -40
- package/dist/clis/feishu/search.d.ts +0 -1
- package/dist/clis/feishu/search.js +0 -30
- package/dist/clis/feishu/send.d.ts +0 -1
- package/dist/clis/feishu/send.js +0 -39
- package/dist/clis/feishu/status.d.ts +0 -1
- package/dist/clis/feishu/status.js +0 -28
- package/dist/clis/neteasemusic/like.d.ts +0 -1
- package/dist/clis/neteasemusic/like.js +0 -25
- package/dist/clis/neteasemusic/lyrics.d.ts +0 -1
- package/dist/clis/neteasemusic/lyrics.js +0 -47
- package/dist/clis/neteasemusic/next.d.ts +0 -1
- package/dist/clis/neteasemusic/next.js +0 -26
- package/dist/clis/neteasemusic/play.d.ts +0 -1
- package/dist/clis/neteasemusic/play.js +0 -26
- package/dist/clis/neteasemusic/playing.d.ts +0 -1
- package/dist/clis/neteasemusic/playing.js +0 -59
- package/dist/clis/neteasemusic/playlist.d.ts +0 -1
- package/dist/clis/neteasemusic/playlist.js +0 -46
- package/dist/clis/neteasemusic/prev.d.ts +0 -1
- package/dist/clis/neteasemusic/prev.js +0 -25
- package/dist/clis/neteasemusic/search.d.ts +0 -1
- package/dist/clis/neteasemusic/search.js +0 -52
- package/dist/clis/neteasemusic/status.d.ts +0 -1
- package/dist/clis/neteasemusic/status.js +0 -16
- package/dist/clis/neteasemusic/volume.d.ts +0 -1
- package/dist/clis/neteasemusic/volume.js +0 -54
- package/dist/clis/twitter/trending.yaml +0 -46
- package/dist/clis/wechat/chats.d.ts +0 -1
- package/dist/clis/wechat/chats.js +0 -28
- package/dist/clis/wechat/contacts.d.ts +0 -1
- package/dist/clis/wechat/contacts.js +0 -28
- package/dist/clis/wechat/read.d.ts +0 -1
- package/dist/clis/wechat/read.js +0 -58
- package/dist/clis/wechat/search.d.ts +0 -1
- package/dist/clis/wechat/search.js +0 -31
- package/dist/clis/wechat/send.d.ts +0 -1
- package/dist/clis/wechat/send.js +0 -42
- package/dist/clis/wechat/status.d.ts +0 -1
- package/dist/clis/wechat/status.js +0 -29
- package/dist/pipeline.d.ts +0 -7
- package/dist/pipeline.js +0 -7
- package/docs/adapters/browser/github.md +0 -26
- package/docs/adapters/desktop/feishu.md +0 -20
- package/docs/adapters/desktop/neteasemusic.md +0 -31
- package/docs/adapters/desktop/wechat.md +0 -28
- package/docs/public/CNAME +0 -1
- package/src/clis/antigravity/README.md +0 -5
- package/src/clis/antigravity/README.zh-CN.md +0 -51
- package/src/clis/chaoxing/README.md +0 -14
- package/src/clis/chaoxing/README.zh-CN.md +0 -35
- package/src/clis/chatgpt/README.md +0 -5
- package/src/clis/chatgpt/README.zh-CN.md +0 -44
- package/src/clis/chatwise/README.md +0 -5
- package/src/clis/chatwise/README.zh-CN.md +0 -38
- package/src/clis/codex/README.md +0 -5
- package/src/clis/codex/README.zh-CN.md +0 -33
- package/src/clis/cursor/README.md +0 -5
- package/src/clis/cursor/README.zh-CN.md +0 -33
- package/src/clis/discord-app/README.md +0 -5
- package/src/clis/discord-app/README.zh-CN.md +0 -28
- package/src/clis/feishu/README.md +0 -5
- package/src/clis/feishu/README.zh-CN.md +0 -20
- package/src/clis/feishu/new.ts +0 -32
- package/src/clis/feishu/read.ts +0 -48
- package/src/clis/feishu/search.ts +0 -35
- package/src/clis/feishu/send.ts +0 -46
- package/src/clis/feishu/status.ts +0 -34
- package/src/clis/neteasemusic/README.md +0 -5
- package/src/clis/neteasemusic/README.zh-CN.md +0 -31
- package/src/clis/neteasemusic/like.ts +0 -28
- package/src/clis/neteasemusic/lyrics.ts +0 -53
- package/src/clis/neteasemusic/next.ts +0 -30
- package/src/clis/neteasemusic/play.ts +0 -30
- package/src/clis/neteasemusic/playing.ts +0 -62
- package/src/clis/neteasemusic/playlist.ts +0 -51
- package/src/clis/neteasemusic/prev.ts +0 -29
- package/src/clis/neteasemusic/search.ts +0 -58
- package/src/clis/neteasemusic/status.ts +0 -18
- package/src/clis/neteasemusic/volume.ts +0 -61
- package/src/clis/notion/README.md +0 -5
- package/src/clis/notion/README.zh-CN.md +0 -29
- package/src/clis/twitter/trending.yaml +0 -46
- package/src/clis/wechat/README.md +0 -5
- package/src/clis/wechat/README.zh-CN.md +0 -28
- package/src/clis/wechat/chats.ts +0 -33
- package/src/clis/wechat/contacts.ts +0 -33
- package/src/clis/wechat/read.ts +0 -72
- package/src/clis/wechat/search.ts +0 -36
- package/src/clis/wechat/send.ts +0 -49
- package/src/clis/wechat/status.ts +0 -35
- package/src/engine.ts +0 -274
- package/src/pipeline.ts +0 -8
- /package/dist/{bilibili.js → clis/bilibili/utils.js} +0 -0
- /package/dist/{chaoxing.test.d.ts → clis/bloomberg/businessweek.d.ts} +0 -0
- /package/dist/{coupang.test.d.ts → clis/bloomberg/economics.d.ts} +0 -0
- /package/dist/{coupang.d.ts → clis/coupang/utils.d.ts} +0 -0
- /package/dist/{coupang.js → clis/coupang/utils.js} +0 -0
- /package/src/{coupang.ts → clis/coupang/utils.ts} +0 -0
|
@@ -0,0 +1,729 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM Snapshot Engine — Advanced DOM pruning for LLM consumption.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by browser-use's multi-layer pruning pipeline, adapted for opencli's
|
|
5
|
+
* Chrome Extension + CDP architecture. Runs entirely in-page via Runtime.evaluate.
|
|
6
|
+
*
|
|
7
|
+
* Pipeline:
|
|
8
|
+
* 1. Walk DOM tree, collect visibility + layout + interactivity signals
|
|
9
|
+
* 2. Prune invisible, zero-area, non-content elements
|
|
10
|
+
* 3. SVG & decoration collapse
|
|
11
|
+
* 4. Shadow DOM traversal
|
|
12
|
+
* 5. Same-origin iframe content extraction
|
|
13
|
+
* 6. Bounding-box parent-child dedup (link/button wrapping children)
|
|
14
|
+
* 7. Paint-order occlusion detection (overlay/modal coverage)
|
|
15
|
+
* 8. Attribute whitelist filtering
|
|
16
|
+
* 9. Table-aware serialization (markdown tables)
|
|
17
|
+
* 10. Token-efficient serialization with interactive indices
|
|
18
|
+
* 11. data-ref annotation for click/type targeting
|
|
19
|
+
* 12. Hidden interactive element hints (scroll-to-reveal)
|
|
20
|
+
* 13. Incremental diff (mark new elements with *)
|
|
21
|
+
*
|
|
22
|
+
* Additional tools:
|
|
23
|
+
* - scrollToRefJs(ref) — scroll to a data-opencli-ref element
|
|
24
|
+
* - getFormStateJs() — extract all form fields as structured JSON
|
|
25
|
+
*/
|
|
26
|
+
// ─── Utility JS Generators ───────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* Generate JS to scroll to an element identified by data-opencli-ref.
|
|
29
|
+
* Completes the snapshot→action loop: snapshot identifies `[3]<button>`,
|
|
30
|
+
* caller can then `scrollToRef('3')` to bring it into view.
|
|
31
|
+
*/
|
|
32
|
+
export function scrollToRefJs(ref) {
|
|
33
|
+
const safeRef = JSON.stringify(ref);
|
|
34
|
+
return `
|
|
35
|
+
(() => {
|
|
36
|
+
const ref = ${safeRef};
|
|
37
|
+
const el = document.querySelector('[data-opencli-ref="' + ref + '"]')
|
|
38
|
+
|| document.querySelector('[data-ref="' + ref + '"]');
|
|
39
|
+
if (!el) throw new Error('Element not found: ref=' + ref);
|
|
40
|
+
el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
|
|
41
|
+
return { scrolled: true, tag: el.tagName.toLowerCase(), text: (el.textContent || '').trim().slice(0, 80) };
|
|
42
|
+
})()
|
|
43
|
+
`.trim();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate JS to extract all form field values from the page.
|
|
47
|
+
* Returns structured JSON: { forms: [{ id, action, fields: [{ tag, type, name, value, ... }] }] }
|
|
48
|
+
*/
|
|
49
|
+
export function getFormStateJs() {
|
|
50
|
+
return `
|
|
51
|
+
(() => {
|
|
52
|
+
const result = { forms: [], orphanFields: [] };
|
|
53
|
+
|
|
54
|
+
// Collect all forms
|
|
55
|
+
for (const form of document.forms) {
|
|
56
|
+
const formData = {
|
|
57
|
+
id: form.id || null,
|
|
58
|
+
name: form.name || null,
|
|
59
|
+
action: form.action || null,
|
|
60
|
+
method: (form.method || 'get').toUpperCase(),
|
|
61
|
+
fields: [],
|
|
62
|
+
};
|
|
63
|
+
for (const el of form.elements) {
|
|
64
|
+
const field = extractField(el);
|
|
65
|
+
if (field) formData.fields.push(field);
|
|
66
|
+
}
|
|
67
|
+
if (formData.fields.length > 0) result.forms.push(formData);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Collect orphan fields (not inside a form)
|
|
71
|
+
const allInputs = document.querySelectorAll('input, textarea, select, [contenteditable="true"]');
|
|
72
|
+
for (const el of allInputs) {
|
|
73
|
+
if (el.form) continue; // already in a form
|
|
74
|
+
const field = extractField(el);
|
|
75
|
+
if (field) result.orphanFields.push(field);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function extractField(el) {
|
|
79
|
+
const tag = el.tagName.toLowerCase();
|
|
80
|
+
const type = (el.getAttribute('type') || (tag === 'textarea' ? 'textarea' : tag === 'select' ? 'select' : 'text')).toLowerCase();
|
|
81
|
+
if (type === 'hidden' || type === 'submit' || type === 'button' || type === 'reset') return null;
|
|
82
|
+
const name = el.name || el.id || null;
|
|
83
|
+
const ref = el.getAttribute('data-opencli-ref') || null;
|
|
84
|
+
const label = findLabel(el);
|
|
85
|
+
let value;
|
|
86
|
+
if (tag === 'select') {
|
|
87
|
+
const opt = el.options?.[el.selectedIndex];
|
|
88
|
+
value = opt ? opt.textContent.trim() : '';
|
|
89
|
+
} else if (type === 'checkbox' || type === 'radio') {
|
|
90
|
+
value = el.checked;
|
|
91
|
+
} else if (type === 'password') {
|
|
92
|
+
value = el.value ? '••••' : '';
|
|
93
|
+
} else if (el.isContentEditable) {
|
|
94
|
+
value = (el.textContent || '').trim().slice(0, 200);
|
|
95
|
+
} else {
|
|
96
|
+
value = (el.value || '').slice(0, 200);
|
|
97
|
+
}
|
|
98
|
+
return { tag, type, name, ref, label, value, required: el.required || false, disabled: el.disabled || false };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function findLabel(el) {
|
|
102
|
+
// 1. aria-label
|
|
103
|
+
if (el.getAttribute('aria-label')) return el.getAttribute('aria-label');
|
|
104
|
+
// 2. associated <label>
|
|
105
|
+
if (el.id) {
|
|
106
|
+
const label = document.querySelector('label[for="' + el.id + '"]');
|
|
107
|
+
if (label) return label.textContent.trim().slice(0, 80);
|
|
108
|
+
}
|
|
109
|
+
// 3. parent label
|
|
110
|
+
const parentLabel = el.closest('label');
|
|
111
|
+
if (parentLabel) return parentLabel.textContent.trim().slice(0, 80);
|
|
112
|
+
// 4. placeholder
|
|
113
|
+
return el.placeholder || null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return result;
|
|
117
|
+
})()
|
|
118
|
+
`.trim();
|
|
119
|
+
}
|
|
120
|
+
// ─── Main Snapshot JS Generator ──────────────────────────────────────
|
|
121
|
+
/**
|
|
122
|
+
* Generate JavaScript code that, when evaluated in a page context via CDP
|
|
123
|
+
* Runtime.evaluate, returns a pruned DOM snapshot string optimised for LLMs.
|
|
124
|
+
*
|
|
125
|
+
* The snapshot output format:
|
|
126
|
+
* [42]<button type=submit>Search</button>
|
|
127
|
+
* |scroll|<div> (0.5↑ 3.2↓)
|
|
128
|
+
* *[58]<a href=/r/1>Result 1</a>
|
|
129
|
+
* [59]<a href=/r/2>Result 2</a>
|
|
130
|
+
*
|
|
131
|
+
* - `[id]` — interactive element with backend index for targeting
|
|
132
|
+
* - `*` prefix — newly appeared element (incremental diff)
|
|
133
|
+
* - `|scroll|` — scrollable container with page counts
|
|
134
|
+
* - `|shadow|` — Shadow DOM boundary
|
|
135
|
+
* - `|iframe|` — iframe content
|
|
136
|
+
* - `|table|` — markdown table rendering
|
|
137
|
+
*/
|
|
138
|
+
export function generateSnapshotJs(opts = {}) {
|
|
139
|
+
const viewportExpand = opts.viewportExpand ?? 800;
|
|
140
|
+
const maxDepth = Math.max(1, Math.min(opts.maxDepth ?? 50, 200));
|
|
141
|
+
const interactiveOnly = opts.interactiveOnly ?? false;
|
|
142
|
+
const maxTextLength = opts.maxTextLength ?? 120;
|
|
143
|
+
const includeScrollInfo = opts.includeScrollInfo ?? true;
|
|
144
|
+
const bboxDedup = opts.bboxDedup ?? true;
|
|
145
|
+
const includeShadowDom = opts.includeShadowDom ?? true;
|
|
146
|
+
const includeIframes = opts.includeIframes ?? true;
|
|
147
|
+
const maxIframes = opts.maxIframes ?? 5;
|
|
148
|
+
const paintOrderCheck = opts.paintOrderCheck ?? true;
|
|
149
|
+
const annotateRefs = opts.annotateRefs ?? true;
|
|
150
|
+
const reportHidden = opts.reportHidden ?? true;
|
|
151
|
+
const filterAds = opts.filterAds ?? true;
|
|
152
|
+
const markdownTables = opts.markdownTables ?? true;
|
|
153
|
+
const previousHashes = opts.previousHashes ?? null;
|
|
154
|
+
return `
|
|
155
|
+
(() => {
|
|
156
|
+
'use strict';
|
|
157
|
+
|
|
158
|
+
// ── Config ─────────────────────────────────────────────────────────
|
|
159
|
+
const VIEWPORT_EXPAND = ${viewportExpand};
|
|
160
|
+
const MAX_DEPTH = ${maxDepth};
|
|
161
|
+
const INTERACTIVE_ONLY = ${interactiveOnly};
|
|
162
|
+
const MAX_TEXT_LEN = ${maxTextLength};
|
|
163
|
+
const INCLUDE_SCROLL_INFO = ${includeScrollInfo};
|
|
164
|
+
const BBOX_DEDUP = ${bboxDedup};
|
|
165
|
+
const INCLUDE_SHADOW_DOM = ${includeShadowDom};
|
|
166
|
+
const INCLUDE_IFRAMES = ${includeIframes};
|
|
167
|
+
const MAX_IFRAMES = ${maxIframes};
|
|
168
|
+
const PAINT_ORDER_CHECK = ${paintOrderCheck};
|
|
169
|
+
const ANNOTATE_REFS = ${annotateRefs};
|
|
170
|
+
const REPORT_HIDDEN = ${reportHidden};
|
|
171
|
+
const FILTER_ADS = ${filterAds};
|
|
172
|
+
const MARKDOWN_TABLES = ${markdownTables};
|
|
173
|
+
const PREV_HASHES = ${previousHashes ? `new Set(${previousHashes})` : 'null'};
|
|
174
|
+
|
|
175
|
+
// ── Constants ──────────────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
const SKIP_TAGS = new Set([
|
|
178
|
+
'script', 'style', 'noscript', 'link', 'meta', 'head',
|
|
179
|
+
'template', 'br', 'wbr', 'col', 'colgroup',
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
const SVG_CHILDREN = new Set([
|
|
183
|
+
'path', 'rect', 'g', 'circle', 'ellipse', 'line', 'polyline',
|
|
184
|
+
'polygon', 'use', 'defs', 'clippath', 'mask', 'pattern',
|
|
185
|
+
'text', 'tspan', 'lineargradient', 'radialgradient', 'stop',
|
|
186
|
+
'filter', 'fegaussianblur', 'fecolormatrix', 'feblend',
|
|
187
|
+
'symbol', 'marker', 'foreignobject', 'desc', 'title',
|
|
188
|
+
]);
|
|
189
|
+
|
|
190
|
+
const INTERACTIVE_TAGS = new Set([
|
|
191
|
+
'a', 'button', 'input', 'select', 'textarea', 'details',
|
|
192
|
+
'summary', 'option', 'optgroup',
|
|
193
|
+
]);
|
|
194
|
+
|
|
195
|
+
const INTERACTIVE_ROLES = new Set([
|
|
196
|
+
'button', 'link', 'menuitem', 'option', 'radio', 'checkbox',
|
|
197
|
+
'tab', 'textbox', 'combobox', 'slider', 'spinbutton',
|
|
198
|
+
'searchbox', 'switch', 'menuitemcheckbox', 'menuitemradio',
|
|
199
|
+
'treeitem', 'gridcell', 'row',
|
|
200
|
+
]);
|
|
201
|
+
|
|
202
|
+
const LANDMARK_ROLES = new Set([
|
|
203
|
+
'main', 'navigation', 'banner', 'search', 'region',
|
|
204
|
+
'complementary', 'contentinfo', 'form', 'dialog',
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
const LANDMARK_TAGS = new Set([
|
|
208
|
+
'nav', 'main', 'header', 'footer', 'aside', 'form',
|
|
209
|
+
'search', 'dialog', 'section', 'article',
|
|
210
|
+
]);
|
|
211
|
+
|
|
212
|
+
const ATTR_WHITELIST = new Set([
|
|
213
|
+
'id', 'name', 'type', 'value', 'placeholder', 'title', 'alt',
|
|
214
|
+
'role', 'aria-label', 'aria-expanded', 'aria-checked', 'aria-selected',
|
|
215
|
+
'aria-disabled', 'aria-valuemin', 'aria-valuemax', 'aria-valuenow',
|
|
216
|
+
'aria-haspopup', 'aria-live', 'aria-required',
|
|
217
|
+
'href', 'src', 'action', 'method', 'for', 'checked', 'selected',
|
|
218
|
+
'disabled', 'required', 'multiple', 'accept', 'min', 'max',
|
|
219
|
+
'pattern', 'maxlength', 'minlength', 'data-testid', 'data-test',
|
|
220
|
+
'contenteditable', 'tabindex', 'autocomplete',
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
const PROPAGATING_TAGS = new Set(['a', 'button']);
|
|
224
|
+
|
|
225
|
+
const AD_PATTERNS = [
|
|
226
|
+
'googleadservices.com', 'doubleclick.net', 'googlesyndication.com',
|
|
227
|
+
'facebook.com/tr', 'analytics.google.com', 'connect.facebook.net',
|
|
228
|
+
'ad.doubleclick', 'pagead', 'adsense',
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
const AD_SELECTOR_RE = /\\b(ad[_-]?(?:banner|container|wrapper|slot|unit|block|frame|leaderboard|sidebar)|google[_-]?ad|sponsored|adsbygoogle|banner[_-]?ad)\\b/i;
|
|
232
|
+
|
|
233
|
+
// ── Viewport & Layout Helpers ──────────────────────────────────────
|
|
234
|
+
|
|
235
|
+
const vw = window.innerWidth;
|
|
236
|
+
const vh = window.innerHeight;
|
|
237
|
+
|
|
238
|
+
function isInExpandedViewport(rect) {
|
|
239
|
+
if (!rect || (rect.width === 0 && rect.height === 0)) return false;
|
|
240
|
+
return rect.bottom > -VIEWPORT_EXPAND && rect.top < vh + VIEWPORT_EXPAND &&
|
|
241
|
+
rect.right > -VIEWPORT_EXPAND && rect.left < vw + VIEWPORT_EXPAND;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function isVisibleByCSS(el) {
|
|
245
|
+
const style = el.style;
|
|
246
|
+
if (style.display === 'none') return false;
|
|
247
|
+
if (style.visibility === 'hidden' || style.visibility === 'collapse') return false;
|
|
248
|
+
if (style.opacity === '0') return false;
|
|
249
|
+
try {
|
|
250
|
+
const cs = window.getComputedStyle(el);
|
|
251
|
+
if (cs.display === 'none') return false;
|
|
252
|
+
if (cs.visibility === 'hidden') return false;
|
|
253
|
+
if (parseFloat(cs.opacity) <= 0) return false;
|
|
254
|
+
if (cs.clip === 'rect(0px, 0px, 0px, 0px)' && cs.position === 'absolute') return false;
|
|
255
|
+
if (cs.overflow === 'hidden' && el.offsetWidth === 0 && el.offsetHeight === 0) return false;
|
|
256
|
+
} catch {}
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ── Paint Order Occlusion ──────────────────────────────────────────
|
|
261
|
+
|
|
262
|
+
function isOccludedByOverlay(el) {
|
|
263
|
+
if (!PAINT_ORDER_CHECK) return false;
|
|
264
|
+
try {
|
|
265
|
+
const rect = el.getBoundingClientRect();
|
|
266
|
+
if (rect.width === 0 || rect.height === 0) return false;
|
|
267
|
+
const cx = rect.left + rect.width / 2;
|
|
268
|
+
const cy = rect.top + rect.height / 2;
|
|
269
|
+
if (cx < 0 || cy < 0 || cx > vw || cy > vh) return false;
|
|
270
|
+
const topEl = document.elementFromPoint(cx, cy);
|
|
271
|
+
if (!topEl || topEl === el || el.contains(topEl) || topEl.contains(el)) return false;
|
|
272
|
+
const cs = window.getComputedStyle(topEl);
|
|
273
|
+
if (parseFloat(cs.opacity) < 0.5) return false;
|
|
274
|
+
const bg = cs.backgroundColor;
|
|
275
|
+
if (bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent') return false;
|
|
276
|
+
return true;
|
|
277
|
+
} catch { return false; }
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ── Ad/Noise Detection ─────────────────────────────────────────────
|
|
281
|
+
|
|
282
|
+
function isAdElement(el) {
|
|
283
|
+
if (!FILTER_ADS) return false;
|
|
284
|
+
try {
|
|
285
|
+
const id = el.id || '';
|
|
286
|
+
const cls = el.className || '';
|
|
287
|
+
const testStr = id + ' ' + (typeof cls === 'string' ? cls : '');
|
|
288
|
+
if (AD_SELECTOR_RE.test(testStr)) return true;
|
|
289
|
+
if (el.tagName === 'IFRAME') {
|
|
290
|
+
const src = el.src || '';
|
|
291
|
+
for (const p of AD_PATTERNS) { if (src.includes(p)) return true; }
|
|
292
|
+
}
|
|
293
|
+
if (el.hasAttribute('data-ad') || el.hasAttribute('data-ad-slot') ||
|
|
294
|
+
el.hasAttribute('data-adunit') || el.hasAttribute('data-google-query-id')) return true;
|
|
295
|
+
} catch {}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ── Interactivity Detection ────────────────────────────────────────
|
|
300
|
+
|
|
301
|
+
function isInteractive(el) {
|
|
302
|
+
const tag = el.tagName.toLowerCase();
|
|
303
|
+
if (INTERACTIVE_TAGS.has(tag)) {
|
|
304
|
+
if (tag === 'label' && el.hasAttribute('for')) return false;
|
|
305
|
+
if (el.disabled && (tag === 'button' || tag === 'input')) return false;
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
const role = el.getAttribute('role');
|
|
309
|
+
if (role && INTERACTIVE_ROLES.has(role)) return true;
|
|
310
|
+
if (el.hasAttribute('onclick') || el.hasAttribute('onmousedown') || el.hasAttribute('ontouchstart')) return true;
|
|
311
|
+
if (el.hasAttribute('tabindex') && el.getAttribute('tabindex') !== '-1') return true;
|
|
312
|
+
try { if (window.getComputedStyle(el).cursor === 'pointer') return true; } catch {}
|
|
313
|
+
if (el.isContentEditable && el.getAttribute('contenteditable') !== 'false') return true;
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function isLandmark(el) {
|
|
318
|
+
const role = el.getAttribute('role');
|
|
319
|
+
if (role && LANDMARK_ROLES.has(role)) return true;
|
|
320
|
+
return LANDMARK_TAGS.has(el.tagName.toLowerCase());
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ── Scrollability Detection ────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
function getScrollInfo(el) {
|
|
326
|
+
if (!INCLUDE_SCROLL_INFO) return null;
|
|
327
|
+
const sh = el.scrollHeight, ch = el.clientHeight;
|
|
328
|
+
const sw = el.scrollWidth, cw = el.clientWidth;
|
|
329
|
+
const isV = sh > ch + 5, isH = sw > cw + 5;
|
|
330
|
+
if (!isV && !isH) return null;
|
|
331
|
+
try {
|
|
332
|
+
const cs = window.getComputedStyle(el);
|
|
333
|
+
const scrollable = ['auto', 'scroll', 'overlay'];
|
|
334
|
+
const tag = el.tagName.toLowerCase();
|
|
335
|
+
const isBody = tag === 'body' || tag === 'html';
|
|
336
|
+
if (isV && !isBody && !scrollable.includes(cs.overflowY)) return null;
|
|
337
|
+
const info = {};
|
|
338
|
+
if (isV) {
|
|
339
|
+
const above = ch > 0 ? +(el.scrollTop / ch).toFixed(1) : 0;
|
|
340
|
+
const below = ch > 0 ? +((sh - ch - el.scrollTop) / ch).toFixed(1) : 0;
|
|
341
|
+
if (above > 0 || below > 0) info.v = { above, below };
|
|
342
|
+
}
|
|
343
|
+
if (isH && scrollable.includes(cs.overflowX)) {
|
|
344
|
+
info.h = { pct: cw > 0 ? Math.round(el.scrollLeft / (sw - cw) * 100) : 0 };
|
|
345
|
+
}
|
|
346
|
+
return Object.keys(info).length > 0 ? info : null;
|
|
347
|
+
} catch { return null; }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ── BBox Containment Check ─────────────────────────────────────────
|
|
351
|
+
|
|
352
|
+
function isContainedBy(childRect, parentRect, threshold) {
|
|
353
|
+
if (!childRect || !parentRect) return false;
|
|
354
|
+
const cArea = childRect.width * childRect.height;
|
|
355
|
+
if (cArea === 0) return false;
|
|
356
|
+
const xO = Math.max(0, Math.min(childRect.right, parentRect.right) - Math.max(childRect.left, parentRect.left));
|
|
357
|
+
const yO = Math.max(0, Math.min(childRect.bottom, parentRect.bottom) - Math.max(childRect.top, parentRect.top));
|
|
358
|
+
return (xO * yO) / cArea >= threshold;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ── Text Helpers ───────────────────────────────────────────────────
|
|
362
|
+
|
|
363
|
+
function getDirectText(el) {
|
|
364
|
+
let text = '';
|
|
365
|
+
for (const child of el.childNodes) {
|
|
366
|
+
if (child.nodeType === 3) {
|
|
367
|
+
const t = child.textContent.trim();
|
|
368
|
+
if (t) text += (text ? ' ' : '') + t;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return text;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function capText(s) {
|
|
375
|
+
if (!s) return '';
|
|
376
|
+
const t = s.replace(/\\s+/g, ' ').trim();
|
|
377
|
+
return t.length > MAX_TEXT_LEN ? t.slice(0, MAX_TEXT_LEN) + '…' : t;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ── Element Hashing (for incremental diff) ─────────────────────────
|
|
381
|
+
|
|
382
|
+
function hashElement(el) {
|
|
383
|
+
// Simple hash: tag + id + className + textContent prefix
|
|
384
|
+
const tag = el.tagName || '';
|
|
385
|
+
const id = el.id || '';
|
|
386
|
+
const cls = (typeof el.className === 'string' ? el.className : '').slice(0, 50);
|
|
387
|
+
const text = (el.textContent || '').trim().slice(0, 40);
|
|
388
|
+
const s = tag + '|' + id + '|' + cls + '|' + text;
|
|
389
|
+
let h = 0;
|
|
390
|
+
for (let i = 0; i < s.length; i++) {
|
|
391
|
+
h = ((h << 5) - h + s.charCodeAt(i)) | 0;
|
|
392
|
+
}
|
|
393
|
+
return '' + (h >>> 0); // unsigned
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// ── Attribute Serialization ────────────────────────────────────────
|
|
397
|
+
|
|
398
|
+
function serializeAttrs(el) {
|
|
399
|
+
const parts = [];
|
|
400
|
+
for (const attr of el.attributes) {
|
|
401
|
+
if (!ATTR_WHITELIST.has(attr.name)) continue;
|
|
402
|
+
let val = attr.value.trim();
|
|
403
|
+
if (!val) continue;
|
|
404
|
+
if (val.length > 120) val = val.slice(0, 100) + '…';
|
|
405
|
+
if (attr.name === 'type' && val.toLowerCase() === el.tagName.toLowerCase()) continue;
|
|
406
|
+
if (attr.name === 'value' && el.getAttribute('type') === 'password') { parts.push('value=••••'); continue; }
|
|
407
|
+
if (attr.name === 'href') {
|
|
408
|
+
if (val.startsWith('javascript:')) continue;
|
|
409
|
+
try {
|
|
410
|
+
const u = new URL(val, location.origin);
|
|
411
|
+
if (u.origin === location.origin) val = u.pathname + u.search + u.hash;
|
|
412
|
+
} catch {}
|
|
413
|
+
}
|
|
414
|
+
parts.push(attr.name + '=' + val);
|
|
415
|
+
}
|
|
416
|
+
// Synthetic attributes
|
|
417
|
+
const tag = el.tagName;
|
|
418
|
+
if (tag === 'INPUT') {
|
|
419
|
+
const type = (el.getAttribute('type') || 'text').toLowerCase();
|
|
420
|
+
const fmts = { 'date':'YYYY-MM-DD', 'time':'HH:MM', 'datetime-local':'YYYY-MM-DDTHH:MM', 'month':'YYYY-MM', 'week':'YYYY-W##' };
|
|
421
|
+
if (fmts[type]) parts.push('format=' + fmts[type]);
|
|
422
|
+
if (['text','email','tel','url','search','number','date','time','datetime-local','month','week'].includes(type)) {
|
|
423
|
+
if (el.value && !parts.some(p => p.startsWith('value='))) parts.push('value=' + capText(el.value));
|
|
424
|
+
}
|
|
425
|
+
if (type === 'password' && el.value && !parts.some(p => p.startsWith('value='))) parts.push('value=••••');
|
|
426
|
+
if ((type === 'checkbox' || type === 'radio') && el.checked && !parts.some(p => p.startsWith('checked'))) parts.push('checked');
|
|
427
|
+
if (type === 'file' && el.files && el.files.length > 0) parts.push('files=' + Array.from(el.files).map(f => f.name).join(','));
|
|
428
|
+
}
|
|
429
|
+
if (tag === 'TEXTAREA' && el.value && !parts.some(p => p.startsWith('value='))) parts.push('value=' + capText(el.value));
|
|
430
|
+
if (tag === 'SELECT') {
|
|
431
|
+
const sel = el.options?.[el.selectedIndex];
|
|
432
|
+
if (sel && !parts.some(p => p.startsWith('value='))) parts.push('value=' + capText(sel.textContent));
|
|
433
|
+
const optEls = Array.from(el.options || []).slice(0, 6);
|
|
434
|
+
if (optEls.length > 0) {
|
|
435
|
+
const ot = optEls.map(o => capText(o.textContent).slice(0, 30));
|
|
436
|
+
if (el.options.length > 6) ot.push('…' + (el.options.length - 6) + ' more');
|
|
437
|
+
parts.push('options=[' + ot.join('|') + ']');
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return parts.join(' ');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ── Table → Markdown Serialization ─────────────────────────────────
|
|
444
|
+
|
|
445
|
+
function serializeTable(table, depth) {
|
|
446
|
+
if (!MARKDOWN_TABLES) return false;
|
|
447
|
+
try {
|
|
448
|
+
const rows = table.querySelectorAll('tr');
|
|
449
|
+
if (rows.length === 0 || rows.length > 50) return false; // skip huge tables
|
|
450
|
+
const grid = [];
|
|
451
|
+
let maxCols = 0;
|
|
452
|
+
for (const row of rows) {
|
|
453
|
+
const cells = [];
|
|
454
|
+
for (const cell of row.querySelectorAll('th, td')) {
|
|
455
|
+
let text = capText(cell.textContent || '');
|
|
456
|
+
// Include interactive elements in cells
|
|
457
|
+
const links = cell.querySelectorAll('a[href]');
|
|
458
|
+
if (links.length === 1 && text) {
|
|
459
|
+
const href = links[0].getAttribute('href');
|
|
460
|
+
if (href && !href.startsWith('javascript:')) {
|
|
461
|
+
try {
|
|
462
|
+
const u = new URL(href, location.origin);
|
|
463
|
+
text = '[' + text + '](' + (u.origin === location.origin ? u.pathname + u.search : href) + ')';
|
|
464
|
+
} catch { text = '[' + text + '](' + href + ')'; }
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
cells.push(text || '');
|
|
468
|
+
}
|
|
469
|
+
if (cells.length > 0) {
|
|
470
|
+
grid.push(cells);
|
|
471
|
+
if (cells.length > maxCols) maxCols = cells.length;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (grid.length < 2 || maxCols === 0) return false; // need at least header + 1 row
|
|
475
|
+
// Pad rows to maxCols
|
|
476
|
+
for (const row of grid) { while (row.length < maxCols) row.push(''); }
|
|
477
|
+
// Compute column widths
|
|
478
|
+
const widths = [];
|
|
479
|
+
for (let c = 0; c < maxCols; c++) {
|
|
480
|
+
let w = 3;
|
|
481
|
+
for (const row of grid) { if (row[c].length > w) w = Math.min(row[c].length, 40); }
|
|
482
|
+
widths.push(w);
|
|
483
|
+
}
|
|
484
|
+
const indent = ' '.repeat(depth);
|
|
485
|
+
const tableLines = [];
|
|
486
|
+
// Header
|
|
487
|
+
tableLines.push(indent + '| ' + grid[0].map((c, i) => c.padEnd(widths[i])).join(' | ') + ' |');
|
|
488
|
+
tableLines.push(indent + '| ' + widths.map(w => '-'.repeat(w)).join(' | ') + ' |');
|
|
489
|
+
// Body
|
|
490
|
+
for (let r = 1; r < grid.length; r++) {
|
|
491
|
+
tableLines.push(indent + '| ' + grid[r].map((c, i) => c.padEnd(widths[i])).join(' | ') + ' |');
|
|
492
|
+
}
|
|
493
|
+
return tableLines;
|
|
494
|
+
} catch { return false; }
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// ── Main Tree Walk ─────────────────────────────────────────────────
|
|
498
|
+
|
|
499
|
+
let interactiveIndex = 0;
|
|
500
|
+
const lines = [];
|
|
501
|
+
const hiddenInteractives = [];
|
|
502
|
+
const currentHashes = [];
|
|
503
|
+
let iframeCount = 0;
|
|
504
|
+
|
|
505
|
+
function walk(el, depth, parentPropagatingRect) {
|
|
506
|
+
if (depth > MAX_DEPTH) return false;
|
|
507
|
+
if (el.nodeType !== 1) return false;
|
|
508
|
+
|
|
509
|
+
const tag = el.tagName.toLowerCase();
|
|
510
|
+
if (SKIP_TAGS.has(tag)) return false;
|
|
511
|
+
if (isAdElement(el)) return false;
|
|
512
|
+
|
|
513
|
+
// SVG: emit tag, collapse children
|
|
514
|
+
if (tag === 'svg') {
|
|
515
|
+
const attrs = serializeAttrs(el);
|
|
516
|
+
const interactive = isInteractive(el);
|
|
517
|
+
let prefix = '';
|
|
518
|
+
if (interactive) {
|
|
519
|
+
interactiveIndex++;
|
|
520
|
+
if (ANNOTATE_REFS) el.setAttribute('data-opencli-ref', '' + interactiveIndex);
|
|
521
|
+
prefix = '[' + interactiveIndex + ']';
|
|
522
|
+
}
|
|
523
|
+
lines.push(' '.repeat(depth) + prefix + '<svg' + (attrs ? ' ' + attrs : '') + ' />');
|
|
524
|
+
return interactive;
|
|
525
|
+
}
|
|
526
|
+
if (SVG_CHILDREN.has(tag)) return false;
|
|
527
|
+
|
|
528
|
+
// Table: try markdown serialization before generic walk
|
|
529
|
+
if (tag === 'table' && MARKDOWN_TABLES) {
|
|
530
|
+
const tableLines = serializeTable(el, depth);
|
|
531
|
+
if (tableLines) {
|
|
532
|
+
const indent = ' '.repeat(depth);
|
|
533
|
+
lines.push(indent + '|table|');
|
|
534
|
+
for (const tl of tableLines) lines.push(tl);
|
|
535
|
+
return false; // tables usually non-interactive
|
|
536
|
+
}
|
|
537
|
+
// Fall through to generic walk if markdown failed
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// iframe handling
|
|
541
|
+
if (tag === 'iframe' && INCLUDE_IFRAMES && iframeCount < MAX_IFRAMES) {
|
|
542
|
+
return walkIframe(el, depth);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Visibility check
|
|
546
|
+
let rect;
|
|
547
|
+
try { rect = el.getBoundingClientRect(); } catch { return false; }
|
|
548
|
+
const hasArea = rect.width > 0 && rect.height > 0;
|
|
549
|
+
if (hasArea && !isVisibleByCSS(el)) {
|
|
550
|
+
if (!(tag === 'input' && el.type === 'file')) return false;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const interactive = isInteractive(el);
|
|
554
|
+
|
|
555
|
+
// Viewport threshold pruning
|
|
556
|
+
if (hasArea && !isInExpandedViewport(rect)) {
|
|
557
|
+
if (interactive && REPORT_HIDDEN) {
|
|
558
|
+
const scrollDist = rect.top > vh ? rect.top - vh : -rect.bottom;
|
|
559
|
+
const pagesAway = Math.abs(scrollDist / vh).toFixed(1);
|
|
560
|
+
const direction = rect.top > vh ? 'below' : 'above';
|
|
561
|
+
const text = capText(getDirectText(el) || el.getAttribute('aria-label') || el.getAttribute('title') || '');
|
|
562
|
+
hiddenInteractives.push({ tag, text, direction, pagesAway });
|
|
563
|
+
}
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// Paint order occlusion
|
|
568
|
+
if (interactive && hasArea && isOccludedByOverlay(el)) return false;
|
|
569
|
+
|
|
570
|
+
const landmark = isLandmark(el);
|
|
571
|
+
const scrollInfo = getScrollInfo(el);
|
|
572
|
+
const isScrollable = scrollInfo !== null;
|
|
573
|
+
|
|
574
|
+
// BBox dedup
|
|
575
|
+
let excludedByParent = false;
|
|
576
|
+
if (BBOX_DEDUP && parentPropagatingRect && !interactive) {
|
|
577
|
+
if (hasArea && isContainedBy(rect, parentPropagatingRect, 0.95)) {
|
|
578
|
+
const hasSemantic = el.hasAttribute('aria-label') ||
|
|
579
|
+
(el.getAttribute('role') && INTERACTIVE_ROLES.has(el.getAttribute('role')));
|
|
580
|
+
if (!hasSemantic && !['input','select','textarea','label'].includes(tag)) {
|
|
581
|
+
excludedByParent = true;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
let propagateRect = parentPropagatingRect;
|
|
587
|
+
if (BBOX_DEDUP && PROPAGATING_TAGS.has(tag) && hasArea) propagateRect = rect;
|
|
588
|
+
|
|
589
|
+
// Process children
|
|
590
|
+
const origLen = lines.length;
|
|
591
|
+
let hasInteractiveDescendant = false;
|
|
592
|
+
|
|
593
|
+
for (const child of el.children) {
|
|
594
|
+
const r = walk(child, depth + 1, propagateRect);
|
|
595
|
+
if (r) hasInteractiveDescendant = true;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Shadow DOM
|
|
599
|
+
if (INCLUDE_SHADOW_DOM && el.shadowRoot) {
|
|
600
|
+
const shadowOrigLen = lines.length;
|
|
601
|
+
for (const child of el.shadowRoot.children) {
|
|
602
|
+
const r = walk(child, depth + 1, propagateRect);
|
|
603
|
+
if (r) hasInteractiveDescendant = true;
|
|
604
|
+
}
|
|
605
|
+
if (lines.length > shadowOrigLen) {
|
|
606
|
+
lines.splice(shadowOrigLen, 0, ' '.repeat(depth + 1) + '|shadow|');
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const childLinesCount = lines.length - origLen;
|
|
611
|
+
const text = capText(getDirectText(el));
|
|
612
|
+
|
|
613
|
+
// Decide whether to emit
|
|
614
|
+
if (INTERACTIVE_ONLY && !interactive && !landmark && !hasInteractiveDescendant && !text) {
|
|
615
|
+
lines.length = origLen;
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
if (excludedByParent && !interactive && !isScrollable) return hasInteractiveDescendant;
|
|
619
|
+
if (!interactive && !isScrollable && !text && childLinesCount === 0 && !landmark) return false;
|
|
620
|
+
|
|
621
|
+
// ── Emit node ────────────────────────────────────────────────────
|
|
622
|
+
const indent = ' '.repeat(depth);
|
|
623
|
+
let line = indent;
|
|
624
|
+
|
|
625
|
+
// Incremental diff: mark new elements with *
|
|
626
|
+
if (PREV_HASHES) {
|
|
627
|
+
const h = hashElement(el);
|
|
628
|
+
currentHashes.push(h);
|
|
629
|
+
if (!PREV_HASHES.has(h)) line += '*';
|
|
630
|
+
} else {
|
|
631
|
+
currentHashes.push(hashElement(el));
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// Scroll marker
|
|
635
|
+
if (isScrollable && !interactive) line += '|scroll|';
|
|
636
|
+
|
|
637
|
+
// Interactive index + data-ref
|
|
638
|
+
if (interactive) {
|
|
639
|
+
interactiveIndex++;
|
|
640
|
+
if (ANNOTATE_REFS) el.setAttribute('data-opencli-ref', '' + interactiveIndex);
|
|
641
|
+
line += isScrollable ? '|scroll[' + interactiveIndex + ']|' : '[' + interactiveIndex + ']';
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Tag + attributes
|
|
645
|
+
const attrs = serializeAttrs(el);
|
|
646
|
+
line += '<' + tag;
|
|
647
|
+
if (attrs) line += ' ' + attrs;
|
|
648
|
+
|
|
649
|
+
// Scroll info suffix, inline text, or self-close
|
|
650
|
+
if (isScrollable && scrollInfo) {
|
|
651
|
+
const parts = [];
|
|
652
|
+
if (scrollInfo.v) parts.push(scrollInfo.v.above + '↑ ' + scrollInfo.v.below + '↓');
|
|
653
|
+
if (scrollInfo.h) parts.push('h:' + scrollInfo.h.pct + '%');
|
|
654
|
+
line += ' /> (' + parts.join(', ') + ')';
|
|
655
|
+
} else if (text && childLinesCount === 0) {
|
|
656
|
+
line += '>' + text + '</' + tag + '>';
|
|
657
|
+
} else {
|
|
658
|
+
line += ' />';
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
lines.splice(origLen, 0, line);
|
|
662
|
+
if (text && childLinesCount > 0) lines.splice(origLen + 1, 0, indent + ' ' + text);
|
|
663
|
+
|
|
664
|
+
return interactive || hasInteractiveDescendant;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// ── iframe Processing ──────────────────────────────────────────────
|
|
668
|
+
|
|
669
|
+
function walkIframe(el, depth) {
|
|
670
|
+
const indent = ' '.repeat(depth);
|
|
671
|
+
try {
|
|
672
|
+
const doc = el.contentDocument;
|
|
673
|
+
if (!doc || !doc.body) {
|
|
674
|
+
const attrs = serializeAttrs(el);
|
|
675
|
+
lines.push(indent + '|iframe|<iframe' + (attrs ? ' ' + attrs : '') + ' /> (cross-origin)');
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
iframeCount++;
|
|
679
|
+
const attrs = serializeAttrs(el);
|
|
680
|
+
lines.push(indent + '|iframe|<iframe' + (attrs ? ' ' + attrs : '') + ' />');
|
|
681
|
+
let has = false;
|
|
682
|
+
for (const child of doc.body.children) {
|
|
683
|
+
if (walk(child, depth + 1, null)) has = true;
|
|
684
|
+
}
|
|
685
|
+
return has;
|
|
686
|
+
} catch {
|
|
687
|
+
const attrs = serializeAttrs(el);
|
|
688
|
+
lines.push(indent + '|iframe|<iframe' + (attrs ? ' ' + attrs : '') + ' /> (blocked)');
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// ── Entry Point ────────────────────────────────────────────────────
|
|
694
|
+
|
|
695
|
+
lines.push('url: ' + location.href);
|
|
696
|
+
lines.push('title: ' + document.title);
|
|
697
|
+
lines.push('viewport: ' + vw + 'x' + vh);
|
|
698
|
+
const pageScrollInfo = getScrollInfo(document.documentElement) || getScrollInfo(document.body);
|
|
699
|
+
if (pageScrollInfo && pageScrollInfo.v) {
|
|
700
|
+
lines.push('page_scroll: ' + pageScrollInfo.v.above + '↑ ' + pageScrollInfo.v.below + '↓');
|
|
701
|
+
}
|
|
702
|
+
lines.push('---');
|
|
703
|
+
|
|
704
|
+
const root = document.body || document.documentElement;
|
|
705
|
+
if (root) walk(root, 0, null);
|
|
706
|
+
|
|
707
|
+
// Hidden interactive elements hint
|
|
708
|
+
if (REPORT_HIDDEN && hiddenInteractives.length > 0) {
|
|
709
|
+
lines.push('---');
|
|
710
|
+
lines.push('hidden_interactive (' + hiddenInteractives.length + '):');
|
|
711
|
+
const shown = hiddenInteractives.slice(0, 10);
|
|
712
|
+
for (const h of shown) {
|
|
713
|
+
const label = h.text ? ' "' + h.text + '"' : '';
|
|
714
|
+
lines.push(' <' + h.tag + '>' + label + ' ~' + h.pagesAway + ' pages ' + h.direction);
|
|
715
|
+
}
|
|
716
|
+
if (hiddenInteractives.length > 10) lines.push(' …' + (hiddenInteractives.length - 10) + ' more');
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// Footer
|
|
720
|
+
lines.push('---');
|
|
721
|
+
lines.push('interactive: ' + interactiveIndex + ' | iframes: ' + iframeCount);
|
|
722
|
+
|
|
723
|
+
// Store hashes on window for next diff snapshot
|
|
724
|
+
try { window.__opencli_prev_hashes = JSON.stringify(currentHashes); } catch {}
|
|
725
|
+
|
|
726
|
+
return lines.join('\\n');
|
|
727
|
+
})()
|
|
728
|
+
`.trim();
|
|
729
|
+
}
|