browserpaw 0.0.0-stage → 5.0.1

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 (69) hide show
  1. package/LICENSE +681 -0
  2. package/README.md +4 -2
  3. package/dist/v5/cli-files.cjs +147 -0
  4. package/dist/v5/cli.cjs +4900 -0
  5. package/dist/v5/extension/assets/popup-Djl4pI1R.css +359 -0
  6. package/dist/v5/extension/background.js +39389 -0
  7. package/dist/v5/extension/browserpaw-build.json +191 -0
  8. package/dist/v5/extension/chunks/popup-BSqTH70w.js +6575 -0
  9. package/dist/v5/extension/content-scripts/agent-cursor.js +1475 -0
  10. package/dist/v5/extension/icon/128.png +0 -0
  11. package/dist/v5/extension/icon/16.png +0 -0
  12. package/dist/v5/extension/icon/32.png +0 -0
  13. package/dist/v5/extension/icon/48.png +0 -0
  14. package/dist/v5/extension/icon/96.png +0 -0
  15. package/dist/v5/extension/images/cursor-chat.png +0 -0
  16. package/dist/v5/extension/inject-scripts/accessibility-tree-helper.js +2031 -0
  17. package/dist/v5/extension/inject-scripts/keyboard-helper.js +412 -0
  18. package/dist/v5/extension/inject-scripts/network-helper.js +378 -0
  19. package/dist/v5/extension/inject-scripts/screenshot-helper.js +449 -0
  20. package/dist/v5/extension/inpage-engine.js +9437 -0
  21. package/dist/v5/extension/manifest.json +1 -0
  22. package/dist/v5/extension/popup.html +14 -0
  23. package/dist/v5/host.cjs +19813 -0
  24. package/dist/v5/recipes/bilibili-popular-videos.json +364 -0
  25. package/dist/v5/recipes/bilibili-video-detail.json +395 -0
  26. package/dist/v5/recipes/developer.mozilla.org.md +15 -0
  27. package/dist/v5/recipes/github-issue-thread.json +313 -0
  28. package/dist/v5/recipes/github-releases.json +218 -0
  29. package/dist/v5/recipes/github-repo-readme.json +306 -0
  30. package/dist/v5/recipes/github-repo-search.json +313 -0
  31. package/dist/v5/recipes/mdn-search.json +219 -0
  32. package/dist/v5/recipes/npm-compare.json +458 -0
  33. package/dist/v5/recipes/reddit-post-read.json +289 -0
  34. package/dist/v5/recipes/reddit-subreddit-posts.json +331 -0
  35. package/dist/v5/recipes/v2ex-node-topics.json +334 -0
  36. package/dist/v5/recipes/v2ex-topic-read.json +325 -0
  37. package/dist/v5/recipes/x-profile-posts.json +332 -0
  38. package/dist/v5/recipes/x-search-thread.json +293 -0
  39. package/dist/v5/recipes/x-visible-thread.json +260 -0
  40. package/dist/v5/recipes/youtube-search-videos.json +279 -0
  41. package/dist/v5/recipes/youtube-video-read.json +349 -0
  42. package/dist/v5/run_host.bat +7 -0
  43. package/dist/v5/run_host.sh +6 -0
  44. package/dist/v5/skill/browserpaw/SKILL.md +48 -0
  45. package/dist/v5/skill/browserpaw/assets/recipes/bilibili-popular-videos.json +364 -0
  46. package/dist/v5/skill/browserpaw/assets/recipes/bilibili-video-detail.json +395 -0
  47. package/dist/v5/skill/browserpaw/assets/recipes/developer.mozilla.org.md +15 -0
  48. package/dist/v5/skill/browserpaw/assets/recipes/github-issue-thread.json +313 -0
  49. package/dist/v5/skill/browserpaw/assets/recipes/github-releases.json +218 -0
  50. package/dist/v5/skill/browserpaw/assets/recipes/github-repo-readme.json +306 -0
  51. package/dist/v5/skill/browserpaw/assets/recipes/github-repo-search.json +313 -0
  52. package/dist/v5/skill/browserpaw/assets/recipes/mdn-search.json +219 -0
  53. package/dist/v5/skill/browserpaw/assets/recipes/npm-compare.json +458 -0
  54. package/dist/v5/skill/browserpaw/assets/recipes/reddit-post-read.json +289 -0
  55. package/dist/v5/skill/browserpaw/assets/recipes/reddit-subreddit-posts.json +331 -0
  56. package/dist/v5/skill/browserpaw/assets/recipes/v2ex-node-topics.json +334 -0
  57. package/dist/v5/skill/browserpaw/assets/recipes/v2ex-topic-read.json +325 -0
  58. package/dist/v5/skill/browserpaw/assets/recipes/x-profile-posts.json +332 -0
  59. package/dist/v5/skill/browserpaw/assets/recipes/x-search-thread.json +293 -0
  60. package/dist/v5/skill/browserpaw/assets/recipes/x-visible-thread.json +260 -0
  61. package/dist/v5/skill/browserpaw/assets/recipes/youtube-search-videos.json +279 -0
  62. package/dist/v5/skill/browserpaw/assets/recipes/youtube-video-read.json +349 -0
  63. package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.md +7 -0
  64. package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.zh-CN.md +5 -0
  65. package/dist/v5/skill/browserpaw/references/browser-data.md +33 -0
  66. package/dist/v5/skill/browserpaw/references/commands.md +103 -0
  67. package/dist/v5/skill/browserpaw/references/debugging.md +32 -0
  68. package/dist/v5/skill/browserpaw/references/recipe-contract.md +47 -0
  69. package/package.json +67 -4
@@ -0,0 +1,289 @@
1
+ {
2
+ "id": "reddit-post-read",
3
+ "name": "Reddit post and comments reader",
4
+ "description": "Read a Reddit post and its top comments using Chrome's session via same-origin JSON with visible DOM fallback.",
5
+ "source": {
6
+ "type": "builtin",
7
+ "urls": [
8
+ "https://old.reddit.com/r/programming/comments/f9ut5f/",
9
+ "https://old.reddit.com/r/programming/comments/226xun/"
10
+ ]
11
+ },
12
+ "domains": [
13
+ "www.reddit.com",
14
+ "reddit.com",
15
+ "old.reddit.com"
16
+ ],
17
+ "keywords": [
18
+ "reddit",
19
+ "红迪",
20
+ "post",
21
+ "thread",
22
+ "comments",
23
+ "discussion",
24
+ "帖子",
25
+ "评论",
26
+ "详情",
27
+ "红迪帖子",
28
+ "Reddit评论",
29
+ "读帖"
30
+ ],
31
+ "startUrl": "https://old.reddit.com/r/{{subreddit}}/comments/{{postId}}/",
32
+ "inputSchema": {
33
+ "type": "object",
34
+ "properties": {
35
+ "subreddit": {
36
+ "type": "string",
37
+ "pattern": "^[A-Za-z0-9_]{2,50}$"
38
+ },
39
+ "postId": {
40
+ "type": "string",
41
+ "pattern": "^[A-Za-z0-9]{1,16}$"
42
+ },
43
+ "limit": {
44
+ "type": "integer",
45
+ "minimum": 1,
46
+ "maximum": 25,
47
+ "default": 15
48
+ }
49
+ },
50
+ "required": [
51
+ "subreddit",
52
+ "postId"
53
+ ],
54
+ "additionalProperties": false
55
+ },
56
+ "outputSchema": {
57
+ "type": "object",
58
+ "properties": {
59
+ "success": {
60
+ "const": true
61
+ },
62
+ "status": {
63
+ "const": "ok"
64
+ },
65
+ "post": {
66
+ "type": "object",
67
+ "properties": {
68
+ "id": {
69
+ "type": "string",
70
+ "minLength": 1
71
+ },
72
+ "subreddit": {
73
+ "type": "string"
74
+ },
75
+ "title": {
76
+ "type": "string",
77
+ "minLength": 1
78
+ },
79
+ "author": {
80
+ "type": "string"
81
+ },
82
+ "score": {
83
+ "type": "integer"
84
+ },
85
+ "commentsCount": {
86
+ "type": "integer",
87
+ "minimum": 0
88
+ },
89
+ "url": {
90
+ "type": "string",
91
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/r/"
92
+ },
93
+ "body": {
94
+ "type": "string"
95
+ }
96
+ },
97
+ "required": [
98
+ "id",
99
+ "subreddit",
100
+ "title",
101
+ "author",
102
+ "score",
103
+ "commentsCount",
104
+ "url",
105
+ "body"
106
+ ],
107
+ "additionalProperties": false
108
+ },
109
+ "comments": {
110
+ "type": "array",
111
+ "maxItems": 25,
112
+ "items": {
113
+ "type": "object",
114
+ "properties": {
115
+ "id": {
116
+ "type": "string"
117
+ },
118
+ "author": {
119
+ "type": "string"
120
+ },
121
+ "score": {
122
+ "type": "integer"
123
+ },
124
+ "body": {
125
+ "type": "string"
126
+ }
127
+ },
128
+ "required": [
129
+ "id",
130
+ "author",
131
+ "score",
132
+ "body"
133
+ ],
134
+ "additionalProperties": false
135
+ }
136
+ },
137
+ "sources": {
138
+ "type": "object",
139
+ "properties": {
140
+ "api": {
141
+ "oneOf": [
142
+ {
143
+ "type": "string",
144
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
145
+ },
146
+ {
147
+ "type": "null"
148
+ }
149
+ ]
150
+ },
151
+ "page": {
152
+ "type": "string",
153
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
154
+ }
155
+ },
156
+ "required": [
157
+ "api",
158
+ "page"
159
+ ],
160
+ "additionalProperties": false
161
+ }
162
+ },
163
+ "required": [
164
+ "success",
165
+ "status",
166
+ "post",
167
+ "comments",
168
+ "sources"
169
+ ],
170
+ "additionalProperties": false
171
+ },
172
+ "steps": [
173
+ {
174
+ "tool": "chrome_javascript",
175
+ "args": {
176
+ "code": "const subreddit = String(input.subreddit || '').trim();\nconst postId = String(input.postId || '').trim();\nconst limit = Math.max(1, Math.min(Number(input.limit) || 15, 25));\nconst fallbackUrl = 'https://old.reddit.com/r/' + encodeURIComponent(subreddit) + '/comments/' + encodeURIComponent(postId) + '/';\nconst origin = typeof location !== 'undefined' && typeof location.origin === 'string' && /^https:\\/\\/(?:(?:www|old|new|sh)\\.)?reddit\\.com$/i.test(location.origin) ? location.origin : '';\nif (!origin) {\n return { success: false, status: 'page_not_ready', subreddit, postId, message: 'Reddit page origin is not ready', source: fallbackUrl };\n}\nconst pageUrl = new URL('/r/' + encodeURIComponent(subreddit) + '/comments/' + encodeURIComponent(postId) + '/', origin).href;\nconst fetchLimit = Math.min(500, Math.max(limit * 4, 100));\nconst jsonUrl = new URL('/r/' + encodeURIComponent(subreddit) + '/comments/' + encodeURIComponent(postId) + '.json?limit=' + fetchLimit + '&raw_json=1', origin).href;\nlet blockedStatus = null;\ntry {\n const response = await fetch(jsonUrl, { credentials: 'include', headers: { Accept: 'application/json' } });\n if (response.status === 429) {\n blockedStatus = { success: false, status: 'rate_limited', subreddit, postId, httpStatus: 429, source: response.url || jsonUrl };\n } else if (response.status === 404) {\n return { success: false, status: 'not_found', subreddit, postId, httpStatus: 404, source: response.url || jsonUrl };\n } else if (response.status === 401) {\n blockedStatus = { success: false, status: 'requires_auth', subreddit, postId, requiresLogin: true, httpStatus: 401, source: response.url || jsonUrl };\n } else if (response.status === 403) {\n let reason = '';\n try {\n const errBody = await response.json();\n reason = String((errBody && (errBody.reason || errBody.message)) || '').toLowerCase();\n } catch {}\n if (reason.includes('quarantin') || reason.includes('over18')) {\n blockedStatus = { success: false, status: 'over18_or_quarantined', subreddit, postId, httpStatus: 403, message: 'Reddit post is quarantined or requires 18+ confirmation', source: response.url || jsonUrl };\n } else if (reason.includes('private')) {\n blockedStatus = { success: false, status: 'requires_auth', subreddit, postId, requiresLogin: true, httpStatus: 403, message: 'Reddit community is private or requires authentication', source: response.url || jsonUrl };\n } else {\n blockedStatus = { success: false, status: 'blocked', subreddit, postId, httpStatus: 403, message: 'Reddit returned HTTP 403 for this post', source: response.url || jsonUrl };\n }\n } else if (response.ok) {\n const data = await response.json();\n if (data && !Array.isArray(data) && (String(data.reason || '').toLowerCase().includes('quarantin') || String(data.reason || '').toLowerCase().includes('over18'))) {\n blockedStatus = { success: false, status: 'over18_or_quarantined', subreddit, postId, message: 'Reddit post is quarantined or requires 18+ confirmation', source: response.url || jsonUrl };\n }\n if (Array.isArray(data) && data.length >= 2) {\n const postEntry = data[0] && data[0].data && Array.isArray(data[0].data.children) ? data[0].data.children[0] : null;\n const d = postEntry && postEntry.data;\n if (d && d.title) {\n const permalink = String(d.permalink || '').trim();\n const rawComments = data[1] && data[1].data && Array.isArray(data[1].data.children) ? data[1].data.children : [];\n const comments = rawComments\n .filter(c => c && c.kind === 't1' && c.data && typeof c.data.body === 'string' && c.data.body.trim())\n .slice(0, limit)\n .map(c => ({\n id: String(c.data.id || '').trim(),\n author: String(c.data.author || '').trim(),\n score: Math.floor(Number(c.data.score) || 0),\n body: String(c.data.body || '').trim().slice(0, 1500)\n }));\n return {\n success: true,\n status: 'ok',\n post: {\n id: String(d.id || postId).trim(),\n subreddit: String(d.subreddit || subreddit).trim(),\n title: String(d.title || '').trim(),\n author: String(d.author || '').trim(),\n score: Math.floor(Number(d.score) || 0),\n commentsCount: Math.max(comments.length, Math.floor(Number(d.num_comments) || 0)),\n url: permalink ? new URL(permalink, 'https://www.reddit.com').href : pageUrl,\n body: String(d.selftext || '').trim().slice(0, 6000)\n },\n comments,\n sources: { api: response.url || jsonUrl, page: permalink ? new URL(permalink, 'https://www.reddit.com').href : pageUrl }\n };\n }\n }\n }\n} catch {\n // Fall back to visible DOM below.\n}\nif (typeof document !== 'undefined' && document && typeof document.querySelector === 'function') {\n const postEl = document.querySelector('shreddit-post');\n if (postEl) {\n const title = String(postEl.getAttribute('post-title') || '').trim();\n const permalink = String(postEl.getAttribute('permalink') || '').trim();\n const bodyEl = postEl.querySelector('[slot=\"text-body\"], div[id$=\"-post-rtjson-content\"]');\n if (title) {\n const commentEls = typeof document.querySelectorAll === 'function' ? Array.from(document.querySelectorAll('shreddit-comment')) : [];\n const comments = commentEls.map(el => {\n const commentBody = el.querySelector('[slot=\"comment\"], div[id$=\"-post-rtjson-content\"]');\n return {\n id: String(el.getAttribute('thingid') || '').replace(/^t1_/, '').trim(),\n author: String(el.getAttribute('author') || '').trim(),\n score: Math.floor(Number(el.getAttribute('score')) || 0),\n body: String((commentBody && (commentBody.innerText || commentBody.textContent)) || '').trim().slice(0, 1500)\n };\n }).filter(c => c.body && (c.id || c.author)).slice(0, limit);\n const resolvedUrl = permalink ? new URL(permalink, origin).href : pageUrl;\n return {\n success: true,\n status: 'ok',\n post: {\n id: String(postEl.getAttribute('id') || postId).replace(/^t3_/, '').trim(),\n subreddit: String(postEl.getAttribute('subreddit-prefixed-name') || subreddit).replace(/^r\\//, '').trim(),\n title,\n author: String(postEl.getAttribute('author') || '').trim(),\n score: Math.floor(Number(postEl.getAttribute('score')) || 0),\n commentsCount: Math.max(comments.length, Math.floor(Number(postEl.getAttribute('comment-count')) || 0)),\n url: resolvedUrl,\n body: String((bodyEl && (bodyEl.innerText || bodyEl.textContent)) || '').trim().slice(0, 6000)\n },\n comments,\n sources: { api: null, page: location.href || resolvedUrl }\n };\n }\n }\n const oldPostEl = document.querySelector('#siteTable .thing.link, .thing.link');\n if (oldPostEl) {\n const titleEl = oldPostEl.querySelector('a.title');\n const title = String((titleEl && (titleEl.innerText || titleEl.textContent)) || '').trim();\n const permalink = String(oldPostEl.getAttribute('data-permalink') || '').trim();\n const bodyEl = oldPostEl.querySelector('.expando .usertext-body .md, .usertext-body .md');\n if (title) {\n const topCommentEls = typeof document.querySelectorAll === 'function' ? Array.from(document.querySelectorAll('.commentarea > .sitetable > .thing.comment')) : [];\n const oldCommentEls = topCommentEls.length ? topCommentEls : (typeof document.querySelectorAll === 'function' ? Array.from(document.querySelectorAll('.commentarea .thing.comment')) : []);\n const comments = oldCommentEls.map(el => {\n const scoreEl = el.querySelector(':scope > .entry .score.unvoted') || el.querySelector('.entry .score.unvoted');\n const rawScore = scoreEl ? (scoreEl.getAttribute('title') || scoreEl.textContent || '') : '';\n const scoreMatch = String(rawScore).match(/-?\\d+/);\n const commentBody = el.querySelector(':scope > .entry .usertext-body .md') || el.querySelector('.entry .usertext-body .md');\n return {\n id: String(el.getAttribute('data-fullname') || '').replace(/^t1_/, '').trim(),\n author: String(el.getAttribute('data-author') || '').trim(),\n score: scoreMatch ? Math.floor(Number(scoreMatch[0]) || 0) : 0,\n body: String((commentBody && (commentBody.innerText || commentBody.textContent)) || '').trim().slice(0, 1500)\n };\n }).filter(c => c.body && (c.id || c.author)).slice(0, limit);\n const resolvedUrl = permalink ? new URL(permalink, origin).href : pageUrl;\n return {\n success: true,\n status: 'ok',\n post: {\n id: String(oldPostEl.getAttribute('data-fullname') || postId).replace(/^t3_/, '').trim(),\n subreddit: String(oldPostEl.getAttribute('data-subreddit') || subreddit).replace(/^r\\//, '').trim(),\n title,\n author: String(oldPostEl.getAttribute('data-author') || '').trim(),\n score: Math.floor(Number(oldPostEl.getAttribute('data-score')) || 0),\n commentsCount: Math.max(comments.length, Math.floor(Number(oldPostEl.getAttribute('data-comments-count')) || 0)),\n url: resolvedUrl,\n body: String((bodyEl && (bodyEl.innerText || bodyEl.textContent)) || '').trim().slice(0, 6000)\n },\n comments,\n sources: { api: null, page: location.href || resolvedUrl }\n };\n }\n }\n}\nconst pathname = String(location.pathname || '');\nif (typeof document !== 'undefined' && document && typeof document.querySelector === 'function') {\n if (/^\\/over18(?:\\/|$)/i.test(pathname) || document.querySelector('form[action*=\"/over18\"], shreddit-over18-interstitial, [data-testid=\"nsfw-interstitial\"], button[name=\"over18\"]')) {\n return { success: false, status: 'over18_or_quarantined', subreddit, postId, message: 'Reddit requires NSFW (18+) confirmation for this post', source: location.href || pageUrl };\n }\n if (document.querySelector('.quarantine-notice, form[action*=\"/quarantine\"], [data-testid=\"quarantine-interstitial\"]')) {\n return { success: false, status: 'over18_or_quarantined', subreddit, postId, message: 'This Reddit community is quarantined', source: location.href || pageUrl };\n }\n}\nif (blockedStatus) return blockedStatus;\nif (/^\\/login(?:\\/|$)/i.test(pathname) || (typeof document !== 'undefined' && document && typeof document.querySelector === 'function' && document.querySelector('form[action*=\"/login\"], input[name=\"username\"]'))) {\n return { success: false, status: 'requires_auth', subreddit, postId, requiresLogin: true, message: 'Reddit requires authentication for this post', source: location.href || pageUrl };\n}\nreturn { success: false, status: 'blocked', subreddit, postId, message: 'Reddit post was not readable via JSON API or visible DOM', source: location.href || pageUrl };",
177
+ "timeoutMs": 25000
178
+ },
179
+ "resultPath": "/result"
180
+ }
181
+ ],
182
+ "verification": {
183
+ "tool": "chrome_read_dom",
184
+ "args": {
185
+ "format": "compact",
186
+ "selector": "main, [role=\"main\"]",
187
+ "activeViewportOnly": false,
188
+ "limit": 80,
189
+ "maxTextLength": 220
190
+ },
191
+ "resultPath": "/treeString"
192
+ },
193
+ "tests": [
194
+ {
195
+ "inputs": {
196
+ "subreddit": "programming",
197
+ "postId": "f9ut5f",
198
+ "limit": 5
199
+ },
200
+ "expect": {
201
+ "type": "object",
202
+ "properties": {
203
+ "success": {
204
+ "const": true
205
+ },
206
+ "post": {
207
+ "type": "object",
208
+ "properties": {
209
+ "id": {
210
+ "const": "f9ut5f"
211
+ },
212
+ "title": {
213
+ "type": "string",
214
+ "minLength": 1
215
+ }
216
+ },
217
+ "required": [
218
+ "id",
219
+ "title"
220
+ ]
221
+ },
222
+ "sources": {
223
+ "type": "object",
224
+ "required": [
225
+ "page"
226
+ ]
227
+ }
228
+ },
229
+ "required": [
230
+ "success",
231
+ "post",
232
+ "comments",
233
+ "sources"
234
+ ]
235
+ },
236
+ "observe": {
237
+ "type": "string",
238
+ "pattern": "programming|comments|Reddit"
239
+ }
240
+ },
241
+ {
242
+ "inputs": {
243
+ "subreddit": "programming",
244
+ "postId": "226xun",
245
+ "limit": 5
246
+ },
247
+ "expect": {
248
+ "type": "object",
249
+ "properties": {
250
+ "success": {
251
+ "const": true
252
+ },
253
+ "post": {
254
+ "type": "object",
255
+ "properties": {
256
+ "id": {
257
+ "const": "226xun"
258
+ },
259
+ "title": {
260
+ "type": "string",
261
+ "minLength": 1
262
+ }
263
+ },
264
+ "required": [
265
+ "id",
266
+ "title"
267
+ ]
268
+ },
269
+ "sources": {
270
+ "type": "object",
271
+ "required": [
272
+ "page"
273
+ ]
274
+ }
275
+ },
276
+ "required": [
277
+ "success",
278
+ "post",
279
+ "comments",
280
+ "sources"
281
+ ]
282
+ },
283
+ "observe": {
284
+ "type": "string",
285
+ "pattern": "programming|comments|Reddit"
286
+ }
287
+ }
288
+ ]
289
+ }
@@ -0,0 +1,331 @@
1
+ {
2
+ "id": "reddit-subreddit-posts",
3
+ "name": "Reddit subreddit posts reader",
4
+ "description": "Read posts in a Reddit subreddit using Chrome's session via same-origin JSON with visible shreddit-post DOM fallback.",
5
+ "source": {
6
+ "type": "builtin",
7
+ "urls": [
8
+ "https://www.reddit.com/r/programming/hot/",
9
+ "https://www.reddit.com/r/javascript/hot/"
10
+ ]
11
+ },
12
+ "domains": [
13
+ "www.reddit.com",
14
+ "reddit.com",
15
+ "old.reddit.com"
16
+ ],
17
+ "keywords": [
18
+ "reddit",
19
+ "红迪",
20
+ "subreddit",
21
+ "posts",
22
+ "feed",
23
+ "hot",
24
+ "new",
25
+ "top",
26
+ "板块",
27
+ "帖子",
28
+ "Reddit帖子",
29
+ "版块热帖"
30
+ ],
31
+ "startUrl": "https://www.reddit.com/r/{{subreddit}}/{{sort}}/",
32
+ "inputSchema": {
33
+ "type": "object",
34
+ "properties": {
35
+ "subreddit": {
36
+ "type": "string",
37
+ "pattern": "^[A-Za-z0-9_]{2,50}$"
38
+ },
39
+ "sort": {
40
+ "type": "string",
41
+ "enum": [
42
+ "hot",
43
+ "new",
44
+ "top",
45
+ "rising"
46
+ ],
47
+ "default": "hot"
48
+ },
49
+ "limit": {
50
+ "type": "integer",
51
+ "minimum": 1,
52
+ "maximum": 20,
53
+ "default": 8
54
+ }
55
+ },
56
+ "required": [
57
+ "subreddit"
58
+ ],
59
+ "additionalProperties": false
60
+ },
61
+ "outputSchema": {
62
+ "oneOf": [
63
+ {
64
+ "type": "object",
65
+ "properties": {
66
+ "success": {
67
+ "const": true
68
+ },
69
+ "status": {
70
+ "const": "ok"
71
+ },
72
+ "subreddit": {
73
+ "type": "string",
74
+ "minLength": 1
75
+ },
76
+ "sort": {
77
+ "type": "string"
78
+ },
79
+ "posts": {
80
+ "type": "array",
81
+ "minItems": 1,
82
+ "maxItems": 20,
83
+ "items": {
84
+ "type": "object",
85
+ "properties": {
86
+ "id": {
87
+ "type": "string",
88
+ "minLength": 1
89
+ },
90
+ "title": {
91
+ "type": "string",
92
+ "minLength": 1
93
+ },
94
+ "author": {
95
+ "type": "string"
96
+ },
97
+ "score": {
98
+ "type": "integer"
99
+ },
100
+ "commentsCount": {
101
+ "type": "integer",
102
+ "minimum": 0
103
+ },
104
+ "url": {
105
+ "type": "string",
106
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/r/"
107
+ },
108
+ "externalUrl": {
109
+ "type": "string"
110
+ },
111
+ "createdUtc": {
112
+ "type": "integer",
113
+ "minimum": 0
114
+ }
115
+ },
116
+ "required": [
117
+ "id",
118
+ "title",
119
+ "author",
120
+ "score",
121
+ "commentsCount",
122
+ "url",
123
+ "externalUrl",
124
+ "createdUtc"
125
+ ],
126
+ "additionalProperties": false
127
+ }
128
+ },
129
+ "sources": {
130
+ "type": "object",
131
+ "properties": {
132
+ "api": {
133
+ "oneOf": [
134
+ {
135
+ "type": "string",
136
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
137
+ },
138
+ {
139
+ "type": "null"
140
+ }
141
+ ]
142
+ },
143
+ "page": {
144
+ "type": "string",
145
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
146
+ }
147
+ },
148
+ "required": [
149
+ "api",
150
+ "page"
151
+ ],
152
+ "additionalProperties": false
153
+ }
154
+ },
155
+ "required": [
156
+ "success",
157
+ "status",
158
+ "subreddit",
159
+ "sort",
160
+ "posts",
161
+ "sources"
162
+ ],
163
+ "additionalProperties": false
164
+ },
165
+ {
166
+ "type": "object",
167
+ "properties": {
168
+ "success": {
169
+ "const": true
170
+ },
171
+ "status": {
172
+ "const": "empty"
173
+ },
174
+ "subreddit": {
175
+ "type": "string",
176
+ "minLength": 1
177
+ },
178
+ "sort": {
179
+ "type": "string"
180
+ },
181
+ "posts": {
182
+ "type": "array",
183
+ "minItems": 0,
184
+ "maxItems": 0
185
+ },
186
+ "sources": {
187
+ "type": "object",
188
+ "properties": {
189
+ "api": {
190
+ "oneOf": [
191
+ {
192
+ "type": "string",
193
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
194
+ },
195
+ {
196
+ "type": "null"
197
+ }
198
+ ]
199
+ },
200
+ "page": {
201
+ "type": "string",
202
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
203
+ }
204
+ },
205
+ "required": [
206
+ "api",
207
+ "page"
208
+ ],
209
+ "additionalProperties": false
210
+ }
211
+ },
212
+ "required": [
213
+ "success",
214
+ "status",
215
+ "subreddit",
216
+ "sort",
217
+ "posts",
218
+ "sources"
219
+ ],
220
+ "additionalProperties": false
221
+ }
222
+ ]
223
+ },
224
+ "steps": [
225
+ {
226
+ "tool": "chrome_javascript",
227
+ "args": {
228
+ "code": "const subreddit = String(input.subreddit || '').trim();\nconst rawSort = String((input && input.sort) || '').trim().toLowerCase();\nconst sort = ['hot', 'new', 'top', 'rising'].includes(rawSort) ? rawSort : 'hot';\nconst limit = Math.max(1, Math.min(Number(input.limit) || 8, 20));\nconst fallbackUrl = 'https://www.reddit.com/r/' + encodeURIComponent(subreddit) + '/' + encodeURIComponent(sort) + '/';\nconst origin = typeof location !== 'undefined' && typeof location.origin === 'string' && /^https:\\/\\/(?:(?:www|old|new|sh)\\.)?reddit\\.com$/i.test(location.origin) ? location.origin : '';\nif (!origin) {\n return { success: false, status: 'page_not_ready', subreddit, sort, message: 'Reddit page origin is not ready', source: fallbackUrl };\n}\nconst pageUrl = new URL('/r/' + encodeURIComponent(subreddit) + '/' + encodeURIComponent(sort) + '/', origin).href;\nconst fetchLimit = Math.min(100, Math.max(limit * 2, 25));\nconst jsonUrl = new URL('/r/' + encodeURIComponent(subreddit) + '/' + encodeURIComponent(sort) + '.json?limit=' + fetchLimit + '&raw_json=1', origin).href;\nconst redditPostUrlRe = /^https:\\/\\/(?:(?:www|old|sh|new)\\.)?reddit\\.com\\/r\\//i;\nlet blockedStatus = null;\ntry {\n const response = await fetch(jsonUrl, { credentials: 'include', headers: { Accept: 'application/json' } });\n if (response.status === 429) {\n blockedStatus = { success: false, status: 'rate_limited', subreddit, sort, httpStatus: 429, source: response.url || jsonUrl };\n } else if (response.status === 404) {\n return { success: false, status: 'not_found', subreddit, sort, httpStatus: 404, source: response.url || jsonUrl };\n } else if (response.status === 401) {\n blockedStatus = { success: false, status: 'requires_auth', subreddit, sort, requiresLogin: true, httpStatus: 401, source: response.url || jsonUrl };\n } else if (response.status === 403) {\n let reason = '';\n try {\n const errBody = await response.json();\n reason = String((errBody && (errBody.reason || errBody.message)) || '').toLowerCase();\n } catch {}\n if (reason.includes('quarantin') || reason.includes('over18')) {\n blockedStatus = { success: false, status: 'over18_or_quarantined', subreddit, sort, httpStatus: 403, message: 'Reddit subreddit is quarantined or requires 18+ confirmation', source: response.url || jsonUrl };\n } else if (reason.includes('private')) {\n blockedStatus = { success: false, status: 'requires_auth', subreddit, sort, requiresLogin: true, httpStatus: 403, message: 'Reddit subreddit is private or requires authentication', source: response.url || jsonUrl };\n } else {\n blockedStatus = { success: false, status: 'blocked', subreddit, sort, httpStatus: 403, message: 'Reddit returned HTTP 403 for this subreddit', source: response.url || jsonUrl };\n }\n } else if (response.ok) {\n const data = await response.json();\n const reason = String((data && data.reason) || '').toLowerCase();\n if (reason.includes('quarantin') || reason.includes('over18')) {\n blockedStatus = { success: false, status: 'over18_or_quarantined', subreddit, sort, message: 'Reddit subreddit is quarantined or requires 18+ confirmation', source: response.url || jsonUrl };\n }\n const children = data && data.data && Array.isArray(data.data.children) ? data.data.children : null;\n if (children) {\n if (children.length === 0) {\n return { success: true, status: 'empty', subreddit, sort, posts: [], sources: { api: response.url || jsonUrl, page: pageUrl } };\n }\n const posts = children.map(entry => {\n const d = (entry && entry.data) || {};\n if (d.promoted) return null;\n const permalink = String(d.permalink || '').trim();\n return {\n id: String(d.id || '').trim(),\n title: String(d.title || '').trim(),\n author: String(d.author || '').trim(),\n score: Math.floor(Number(d.score) || 0),\n commentsCount: Math.max(0, Math.floor(Number(d.num_comments) || 0)),\n url: permalink ? new URL(permalink, 'https://www.reddit.com').href : '',\n externalUrl: String(d.url || '').trim(),\n createdUtc: Math.max(0, Math.floor(Number(d.created_utc) || 0))\n };\n }).filter(post => post && post.id && post.title && redditPostUrlRe.test(post.url)).slice(0, limit);\n if (posts.length > 0) {\n return { success: true, status: 'ok', subreddit, sort, posts, sources: { api: response.url || jsonUrl, page: pageUrl } };\n }\n }\n }\n} catch {\n // Fall back to visible DOM below.\n}\nif (typeof document !== 'undefined' && document && typeof document.querySelectorAll === 'function') {\n const shredditPosts = Array.from(document.querySelectorAll('shreddit-post')).map(el => {\n const hasPromoted = (typeof el.hasAttribute === 'function' && el.hasAttribute('promoted')) || (typeof el.getAttribute === 'function' && el.getAttribute('promoted') !== null && el.getAttribute('promoted') !== undefined);\n if (hasPromoted) return null;\n const rawId = String(el.getAttribute('id') || '').replace(/^t3_/, '').trim();\n const permalink = String(el.getAttribute('permalink') || '').trim();\n const title = String(el.getAttribute('post-title') || '').trim();\n return {\n id: rawId,\n title,\n author: String(el.getAttribute('author') || '').trim(),\n score: Math.floor(Number(el.getAttribute('score')) || 0),\n commentsCount: Math.max(0, Math.floor(Number(el.getAttribute('comment-count')) || 0)),\n url: permalink ? new URL(permalink, origin).href : '',\n externalUrl: String(el.getAttribute('content-href') || '').trim(),\n createdUtc: 0\n };\n }).filter(post => post && post.id && post.title && redditPostUrlRe.test(post.url)).slice(0, limit);\n if (shredditPosts.length > 0) {\n return { success: true, status: 'ok', subreddit, sort, posts: shredditPosts, sources: { api: null, page: location.href || pageUrl } };\n }\n const oldPosts = Array.from(document.querySelectorAll('#siteTable .thing.link, .thing.link')).map(el => {\n const cls = String(el.className || (typeof el.getAttribute === 'function' ? el.getAttribute('class') : '') || '');\n if (/\\bpromoted\\b/i.test(cls)) return null;\n const titleEl = typeof el.querySelector === 'function' ? el.querySelector('a.title') : null;\n const title = String((titleEl && (titleEl.innerText || titleEl.textContent)) || '').trim();\n const permalink = String((typeof el.getAttribute === 'function' && el.getAttribute('data-permalink')) || '').trim();\n const rawHref = String((typeof el.getAttribute === 'function' && el.getAttribute('data-url')) || (titleEl && typeof titleEl.getAttribute === 'function' && titleEl.getAttribute('href')) || '').trim();\n let externalUrl = rawHref;\n if (rawHref && rawHref.startsWith('/')) {\n try { externalUrl = new URL(rawHref, origin).href; } catch {}\n }\n const rawCommentsCount = typeof el.getAttribute === 'function' ? el.getAttribute('data-comments-count') : null;\n const commentsLink = rawCommentsCount === null && typeof el.querySelector === 'function' ? el.querySelector('a.comments') : null;\n const commentsMatch = commentsLink ? String(commentsLink.innerText || commentsLink.textContent || '').match(/\\d+/) : null;\n const rawTs = typeof el.getAttribute === 'function' ? Number(el.getAttribute('data-timestamp')) : 0;\n return {\n id: String((typeof el.getAttribute === 'function' && el.getAttribute('data-fullname')) || '').replace(/^t3_/, '').trim(),\n title,\n author: String((typeof el.getAttribute === 'function' && el.getAttribute('data-author')) || '').trim(),\n score: Math.floor(Number(typeof el.getAttribute === 'function' ? el.getAttribute('data-score') : 0) || 0),\n commentsCount: Math.max(0, Math.floor(Number(rawCommentsCount !== null && rawCommentsCount !== undefined ? rawCommentsCount : (commentsMatch ? commentsMatch[0] : 0)) || 0)),\n url: permalink ? new URL(permalink, origin).href : '',\n externalUrl,\n createdUtc: rawTs > 0 ? Math.floor(rawTs / 1000) : 0\n };\n }).filter(post => post && post.id && post.title && redditPostUrlRe.test(post.url)).slice(0, limit);\n if (oldPosts.length > 0) {\n return { success: true, status: 'ok', subreddit, sort, posts: oldPosts, sources: { api: null, page: location.href || pageUrl } };\n }\n}\nconst pathname = String(location.pathname || '');\nif (typeof document !== 'undefined' && document && typeof document.querySelector === 'function') {\n if (/^\\/over18(?:\\/|$)/i.test(pathname) || document.querySelector('form[action*=\"/over18\"], shreddit-over18-interstitial, [data-testid=\"nsfw-interstitial\"], button[name=\"over18\"]')) {\n return { success: false, status: 'over18_or_quarantined', subreddit, sort, message: 'Reddit requires NSFW (18+) confirmation for this subreddit', source: location.href || pageUrl };\n }\n if (document.querySelector('.quarantine-notice, form[action*=\"/quarantine\"], [data-testid=\"quarantine-interstitial\"]')) {\n return { success: false, status: 'over18_or_quarantined', subreddit, sort, message: 'This Reddit subreddit is quarantined', source: location.href || pageUrl };\n }\n}\nif (blockedStatus) return blockedStatus;\nif (/^\\/login(?:\\/|$)/i.test(pathname) || (typeof document !== 'undefined' && document && typeof document.querySelector === 'function' && document.querySelector('form[action*=\"/login\"], input[name=\"username\"]'))) {\n return { success: false, status: 'requires_auth', subreddit, sort, requiresLogin: true, message: 'Reddit requires authentication for this page', source: location.href || pageUrl };\n}\nreturn { success: false, status: 'blocked', subreddit, sort, message: 'Reddit posts were not readable via JSON API or visible DOM', source: location.href || pageUrl };",
229
+ "timeoutMs": 25000
230
+ },
231
+ "resultPath": "/result"
232
+ }
233
+ ],
234
+ "verification": {
235
+ "tool": "chrome_read_dom",
236
+ "args": {
237
+ "format": "compact",
238
+ "selector": "main",
239
+ "activeViewportOnly": false,
240
+ "limit": 80,
241
+ "maxTextLength": 220
242
+ },
243
+ "resultPath": "/treeString"
244
+ },
245
+ "tests": [
246
+ {
247
+ "inputs": {
248
+ "subreddit": "programming",
249
+ "sort": "hot",
250
+ "limit": 3
251
+ },
252
+ "expect": {
253
+ "type": "object",
254
+ "properties": {
255
+ "success": {
256
+ "const": true
257
+ },
258
+ "status": {
259
+ "const": "ok"
260
+ },
261
+ "subreddit": {
262
+ "const": "programming"
263
+ },
264
+ "posts": {
265
+ "type": "array",
266
+ "minItems": 1
267
+ },
268
+ "sources": {
269
+ "type": "object",
270
+ "required": [
271
+ "page"
272
+ ]
273
+ }
274
+ },
275
+ "required": [
276
+ "success",
277
+ "status",
278
+ "subreddit",
279
+ "posts",
280
+ "sources"
281
+ ]
282
+ },
283
+ "observe": {
284
+ "type": "string",
285
+ "pattern": "programming|r/programming|Reddit"
286
+ }
287
+ },
288
+ {
289
+ "inputs": {
290
+ "subreddit": "javascript",
291
+ "sort": "hot",
292
+ "limit": 3
293
+ },
294
+ "expect": {
295
+ "type": "object",
296
+ "properties": {
297
+ "success": {
298
+ "const": true
299
+ },
300
+ "status": {
301
+ "const": "ok"
302
+ },
303
+ "subreddit": {
304
+ "const": "javascript"
305
+ },
306
+ "posts": {
307
+ "type": "array",
308
+ "minItems": 1
309
+ },
310
+ "sources": {
311
+ "type": "object",
312
+ "required": [
313
+ "page"
314
+ ]
315
+ }
316
+ },
317
+ "required": [
318
+ "success",
319
+ "status",
320
+ "subreddit",
321
+ "posts",
322
+ "sources"
323
+ ]
324
+ },
325
+ "observe": {
326
+ "type": "string",
327
+ "pattern": "javascript|r/javascript|Reddit"
328
+ }
329
+ }
330
+ ]
331
+ }