dsh-browserpaw 5.0.0 → 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.
@@ -0,0 +1,349 @@
1
+ {
2
+ "id": "youtube-video-read",
3
+ "name": "YouTube video metadata and subtitles reader",
4
+ "description": "Read a YouTube video's metadata and optional caption transcript directly from the watch page's player data and same-origin timedtext endpoint.",
5
+ "source": {
6
+ "type": "builtin",
7
+ "urls": [
8
+ "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
9
+ "https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ&format=json"
10
+ ]
11
+ },
12
+ "domains": [
13
+ "www.youtube.com",
14
+ "m.youtube.com",
15
+ "youtube.com",
16
+ "youtu.be"
17
+ ],
18
+ "keywords": [
19
+ "youtube",
20
+ "油管",
21
+ "video",
22
+ "subtitles",
23
+ "captions",
24
+ "transcript",
25
+ "视频",
26
+ "字幕",
27
+ "详情",
28
+ "油管视频",
29
+ "YouTube字幕",
30
+ "看视频信息"
31
+ ],
32
+ "startUrl": "https://www.youtube.com/watch?v={{videoId}}",
33
+ "inputSchema": {
34
+ "type": "object",
35
+ "properties": {
36
+ "videoId": {
37
+ "type": "string",
38
+ "pattern": "^[A-Za-z0-9_-]{11}$"
39
+ },
40
+ "includeSubtitles": {
41
+ "type": "boolean",
42
+ "default": true
43
+ },
44
+ "lang": {
45
+ "type": "string",
46
+ "pattern": "^[A-Za-z0-9,_-]{1,64}$",
47
+ "default": "zh-Hans,zh,en"
48
+ },
49
+ "maxSubtitleChars": {
50
+ "type": "integer",
51
+ "minimum": 500,
52
+ "maximum": 10000,
53
+ "default": 8000
54
+ }
55
+ },
56
+ "required": [
57
+ "videoId"
58
+ ],
59
+ "additionalProperties": false
60
+ },
61
+ "outputSchema": {
62
+ "type": "object",
63
+ "properties": {
64
+ "success": {
65
+ "const": true
66
+ },
67
+ "status": {
68
+ "const": "ok"
69
+ },
70
+ "video": {
71
+ "type": "object",
72
+ "properties": {
73
+ "videoId": {
74
+ "type": "string",
75
+ "pattern": "^[A-Za-z0-9_-]{11}$"
76
+ },
77
+ "title": {
78
+ "type": "string",
79
+ "minLength": 1
80
+ },
81
+ "url": {
82
+ "type": "string",
83
+ "pattern": "^https://www\\.youtube\\.com/watch\\?v=[A-Za-z0-9_-]{11}$"
84
+ },
85
+ "author": {
86
+ "type": "string"
87
+ },
88
+ "channelId": {
89
+ "type": "string"
90
+ },
91
+ "durationSeconds": {
92
+ "type": "integer",
93
+ "minimum": 0
94
+ },
95
+ "viewCount": {
96
+ "type": "integer",
97
+ "minimum": 0
98
+ },
99
+ "publishDate": {
100
+ "type": "string"
101
+ },
102
+ "description": {
103
+ "type": "string"
104
+ }
105
+ },
106
+ "required": [
107
+ "videoId",
108
+ "title",
109
+ "url",
110
+ "author",
111
+ "channelId",
112
+ "durationSeconds",
113
+ "viewCount",
114
+ "publishDate",
115
+ "description"
116
+ ],
117
+ "additionalProperties": false
118
+ },
119
+ "captionTracks": {
120
+ "type": "array",
121
+ "maxItems": 20,
122
+ "items": {
123
+ "type": "object",
124
+ "properties": {
125
+ "languageCode": {
126
+ "type": "string"
127
+ },
128
+ "name": {
129
+ "type": "string"
130
+ },
131
+ "kind": {
132
+ "type": "string"
133
+ }
134
+ },
135
+ "required": [
136
+ "languageCode",
137
+ "name",
138
+ "kind"
139
+ ],
140
+ "additionalProperties": false
141
+ }
142
+ },
143
+ "subtitle": {
144
+ "oneOf": [
145
+ {
146
+ "type": "null"
147
+ },
148
+ {
149
+ "type": "object",
150
+ "properties": {
151
+ "languageCode": {
152
+ "type": "string"
153
+ },
154
+ "kind": {
155
+ "type": "string"
156
+ },
157
+ "text": {
158
+ "type": "string"
159
+ },
160
+ "truncated": {
161
+ "type": "boolean"
162
+ }
163
+ },
164
+ "required": [
165
+ "languageCode",
166
+ "kind",
167
+ "text",
168
+ "truncated"
169
+ ],
170
+ "additionalProperties": false
171
+ }
172
+ ]
173
+ },
174
+ "sources": {
175
+ "type": "object",
176
+ "properties": {
177
+ "page": {
178
+ "type": "string",
179
+ "pattern": "^https://www\\.youtube\\.com/watch\\?v=[A-Za-z0-9_-]{11}$"
180
+ },
181
+ "subtitles": {
182
+ "oneOf": [
183
+ {
184
+ "type": "string",
185
+ "pattern": "^https://www\\.youtube\\.com/"
186
+ },
187
+ {
188
+ "type": "null"
189
+ }
190
+ ]
191
+ }
192
+ },
193
+ "required": [
194
+ "page",
195
+ "subtitles"
196
+ ],
197
+ "additionalProperties": false
198
+ }
199
+ },
200
+ "required": [
201
+ "success",
202
+ "status",
203
+ "video",
204
+ "captionTracks",
205
+ "subtitle",
206
+ "sources"
207
+ ],
208
+ "additionalProperties": false
209
+ },
210
+ "steps": [
211
+ {
212
+ "tool": "chrome_javascript",
213
+ "args": {
214
+ "code": "const videoId = String(input.videoId || '').trim();\nconst includeSubtitles = input.includeSubtitles !== false;\nconst preferredLangs = String(input.lang || 'zh-Hans,zh,en').split(',').map(v => v.trim().toLowerCase()).filter(Boolean);\nconst maxSubtitleChars = Math.max(500, Math.min(Number(input.maxSubtitleChars) || 8000, 10000));\nconst pageUrl = 'https://www.youtube.com/watch?v=' + videoId;\nconst currentOrigin = typeof location !== 'undefined' && typeof location.origin === 'string' ? location.origin : '';\nconst currentHref = typeof location !== 'undefined' && typeof location.href === 'string' ? location.href : pageUrl;\nconst currentPath = typeof location !== 'undefined' && typeof location.pathname === 'string' ? location.pathname : '';\nif (/^https:\\/\\/consent\\.youtube\\.com$/i.test(currentOrigin)) {\n return { success: false, status: 'consent_required', videoId, message: 'YouTube consent wall requires user acceptance', source: currentHref };\n}\nif (!/^https:\\/\\/(?:www\\.|m\\.)?youtube\\.com$/i.test(currentOrigin)) {\n return { success: false, status: 'page_not_ready', videoId, message: 'YouTube page origin is not ready', source: pageUrl };\n}\nif (/^\\/sorry(?:\\/|$)/i.test(currentPath)) {\n return { success: false, status: 'bot_check', videoId, requiresLogin: true, message: 'YouTube requested bot verification', source: currentHref };\n}\nconst sleep = ms => new Promise(resolve => setTimeout(resolve, ms));\nconst getPlayerEl = id => {\n if (typeof document === 'undefined' || !document) return null;\n if (typeof document.getElementById === 'function') {\n const byId = document.getElementById(id);\n if (byId) return byId;\n }\n if (typeof document.querySelector === 'function') {\n return document.querySelector('#' + id);\n }\n return null;\n};\nconst readPlayer = () => {\n const root = typeof globalThis !== 'undefined' ? globalThis : {};\n const candidates = [];\n for (const playerId of ['movie_player', 'shorts-player']) {\n const player = getPlayerEl(playerId);\n if (player && typeof player.getPlayerResponse === 'function') {\n try {\n const live = player.getPlayerResponse();\n if (live && typeof live === 'object') candidates.push(live);\n } catch {}\n }\n }\n if (typeof document !== 'undefined' && document && typeof document.querySelector === 'function') {\n const flexy = document.querySelector('ytd-watch-flexy');\n if (flexy && flexy.playerData && typeof flexy.playerData === 'object') candidates.push(flexy.playerData);\n }\n if (root.ytInitialPlayerResponse && typeof root.ytInitialPlayerResponse === 'object') {\n candidates.push(root.ytInitialPlayerResponse);\n }\n const exact = candidates.find(c => c.videoDetails && c.videoDetails.videoId === videoId);\n if (exact) return exact;\n return candidates.find(c => (!c.videoDetails || !c.videoDetails.videoId) && c.playabilityStatus) || null;\n};\nconst detectWall = () => {\n if (typeof document === 'undefined' || !document) return null;\n if (typeof document.querySelector === 'function') {\n const consentEl = document.querySelector('form[action*=\"consent.youtube.com\"], ytd-consent-bump-v2-lightbox, tp-yt-paper-dialog[aria-label*=\"consent\" i], #consent-bump');\n if (consentEl && !consentEl.hidden && consentEl.getAttribute?.('aria-hidden') !== 'true') {\n return { success: false, status: 'consent_required', videoId, message: 'YouTube consent wall is blocking video playback', source: currentHref };\n }\n }\n const bodyText = String((document.body && (document.body.innerText || document.body.textContent)) || '').trim();\n if (/sign in to confirm you(?:'|\\u2019)?re not a bot/i.test(bodyText)) {\n return { success: false, status: 'bot_check', videoId, requiresLogin: true, message: 'YouTube requested bot verification', source: currentHref };\n }\n if (/before you continue to youtube/i.test(bodyText)) {\n return { success: false, status: 'consent_required', videoId, message: 'YouTube consent wall is blocking video playback', source: currentHref };\n }\n return null;\n};\nlet playerResponse = null;\nlet wallError = null;\nfor (let attempt = 0; attempt < 20; attempt += 1) {\n const candidate = readPlayer();\n if (candidate && (candidate.videoDetails || candidate.playabilityStatus)) {\n playerResponse = candidate;\n break;\n }\n wallError = detectWall();\n if (wallError) break;\n if (attempt < 19) await sleep(200);\n}\nif (wallError) {\n return wallError;\n}\nif (!playerResponse) {\n return { success: false, status: 'loading_timeout', videoId, message: 'YouTube player response did not become available', source: pageUrl };\n}\nconst playability = playerResponse.playabilityStatus || {};\nconst playStatus = String(playability.status || '').trim();\nconst playReason = String(playability.reason || '').trim();\nif (playStatus === 'LOGIN_REQUIRED') {\n if (/not a bot/i.test(playReason)) {\n return { success: false, status: 'bot_check', videoId, requiresLogin: true, message: playReason, source: pageUrl };\n }\n return { success: false, status: 'requires_auth', videoId, requiresLogin: true, message: playReason || 'YouTube requires authentication', source: pageUrl };\n}\nif (playStatus === 'AGE_CHECK_REQUIRED') {\n return { success: false, status: 'age_restricted', videoId, requiresLogin: true, message: playReason || 'YouTube requires age verification', source: pageUrl };\n}\nif (playStatus === 'CONTENT_CHECK_REQUIRED') {\n return { success: false, status: 'content_check_required', videoId, message: playReason || 'YouTube requires content warning confirmation', source: pageUrl };\n}\nif (playStatus === 'ERROR' || playStatus === 'UNPLAYABLE' || playStatus === 'LIVE_STREAM_OFFLINE') {\n return { success: false, status: 'unavailable', videoId, playabilityStatus: playStatus, message: playReason || 'YouTube video is unavailable', source: pageUrl };\n}\nconst details = playerResponse.videoDetails || {};\nconst title = String(details.title || '').trim();\nif (!title) {\n if (playStatus && playStatus !== 'OK') {\n return { success: false, status: 'unavailable', videoId, playabilityStatus: playStatus, message: playReason || 'YouTube video is unavailable', source: pageUrl };\n }\n return { success: false, status: 'schema_changed', videoId, source: pageUrl };\n}\nconst microformat = (playerResponse.microformat && playerResponse.microformat.playerMicroformatRenderer) || {};\nconst rawTracks = (playerResponse.captions && playerResponse.captions.playerCaptionsTracklistRenderer && Array.isArray(playerResponse.captions.playerCaptionsTracklistRenderer.captionTracks)) ? playerResponse.captions.playerCaptionsTracklistRenderer.captionTracks : [];\nconst captionTracks = rawTracks.slice(0, 20).map(track => ({\n languageCode: String((track && track.languageCode) || '').trim(),\n name: String((track && track.name && (track.name.simpleText || (Array.isArray(track.name.runs) && track.name.runs.map(r => r.text).join('')))) || '').trim(),\n kind: String((track && track.kind) || 'standard').trim()\n}));\nlet subtitle = null;\nlet subtitleSource = null;\nif (includeSubtitles && rawTracks.length > 0) {\n let selected = null;\n for (const pref of preferredLangs) {\n selected = rawTracks.find(t => String((t && t.languageCode) || '').toLowerCase() === pref && (!t.kind || t.kind !== 'asr'))\n || rawTracks.find(t => String((t && t.languageCode) || '').toLowerCase() === pref)\n || rawTracks.find(t => String((t && t.languageCode) || '').toLowerCase().startsWith(pref + '-'));\n if (selected) break;\n }\n if (!selected) selected = rawTracks[0];\n if (selected && typeof selected.baseUrl === 'string' && selected.baseUrl) {\n try {\n const trackUrl = new URL(selected.baseUrl, currentOrigin);\n if (/^https:\\/\\/(?:www\\.|m\\.)?youtube\\.com$/i.test(trackUrl.origin)) {\n trackUrl.searchParams.set('fmt', 'json3');\n const subRes = await fetch(trackUrl.href, { credentials: 'include' });\n if (subRes.ok) {\n const subData = await subRes.json();\n const events = Array.isArray(subData && subData.events) ? subData.events : [];\n const lines = [];\n for (const ev of events) {\n const segs = Array.isArray(ev && ev.segs) ? ev.segs : [];\n const line = segs.map(s => String((s && s.utf8) || '')).join('').replace(/\\s+/g, ' ').trim();\n if (line) lines.push(line);\n }\n const joined = lines.join('\\n').trim();\n if (joined) {\n const truncated = joined.length > maxSubtitleChars;\n subtitle = {\n languageCode: String(selected.languageCode || ''),\n kind: String(selected.kind || 'standard'),\n text: truncated ? joined.slice(0, maxSubtitleChars) : joined,\n truncated\n };\n subtitleSource = subRes.url || trackUrl.href;\n }\n }\n }\n } catch {\n // Keep metadata output even when optional timedtext fetch fails.\n }\n }\n}\nreturn {\n success: true,\n status: 'ok',\n video: {\n videoId: String(details.videoId || videoId),\n title,\n url: pageUrl,\n author: String(details.author || '').trim(),\n channelId: String(details.channelId || '').trim(),\n durationSeconds: Math.max(0, Math.floor(Number(details.lengthSeconds) || 0)),\n viewCount: Math.max(0, Math.floor(Number(details.viewCount) || 0)),\n publishDate: String(microformat.publishDate || '').trim(),\n description: String(details.shortDescription || '').trim().slice(0, 3000)\n },\n captionTracks,\n subtitle,\n sources: {\n page: pageUrl,\n subtitles: subtitleSource\n }\n};",
215
+ "timeoutMs": 30000
216
+ },
217
+ "resultPath": "/result"
218
+ }
219
+ ],
220
+ "verification": {
221
+ "tool": "chrome_network_request",
222
+ "args": {
223
+ "url": "https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D{{videoId}}&format=json",
224
+ "method": "GET",
225
+ "timeout": 30000
226
+ },
227
+ "resultPath": "/response/body"
228
+ },
229
+ "tests": [
230
+ {
231
+ "inputs": {
232
+ "videoId": "dQw4w9WgXcQ",
233
+ "includeSubtitles": false
234
+ },
235
+ "expect": {
236
+ "type": "object",
237
+ "properties": {
238
+ "success": {
239
+ "const": true
240
+ },
241
+ "video": {
242
+ "type": "object",
243
+ "properties": {
244
+ "videoId": {
245
+ "const": "dQw4w9WgXcQ"
246
+ },
247
+ "title": {
248
+ "type": "string",
249
+ "minLength": 1
250
+ }
251
+ },
252
+ "required": [
253
+ "videoId",
254
+ "title"
255
+ ]
256
+ },
257
+ "sources": {
258
+ "type": "object",
259
+ "required": [
260
+ "page"
261
+ ]
262
+ }
263
+ },
264
+ "required": [
265
+ "success",
266
+ "video",
267
+ "captionTracks",
268
+ "sources"
269
+ ]
270
+ },
271
+ "observe": {
272
+ "type": "object",
273
+ "properties": {
274
+ "title": {
275
+ "type": "string",
276
+ "minLength": 1
277
+ },
278
+ "author_name": {
279
+ "type": "string",
280
+ "minLength": 1
281
+ }
282
+ },
283
+ "required": [
284
+ "title",
285
+ "author_name"
286
+ ]
287
+ }
288
+ },
289
+ {
290
+ "inputs": {
291
+ "videoId": "jNQXAC9IVRw",
292
+ "includeSubtitles": false
293
+ },
294
+ "expect": {
295
+ "type": "object",
296
+ "properties": {
297
+ "success": {
298
+ "const": true
299
+ },
300
+ "video": {
301
+ "type": "object",
302
+ "properties": {
303
+ "videoId": {
304
+ "const": "jNQXAC9IVRw"
305
+ },
306
+ "title": {
307
+ "type": "string",
308
+ "minLength": 1
309
+ }
310
+ },
311
+ "required": [
312
+ "videoId",
313
+ "title"
314
+ ]
315
+ },
316
+ "sources": {
317
+ "type": "object",
318
+ "required": [
319
+ "page"
320
+ ]
321
+ }
322
+ },
323
+ "required": [
324
+ "success",
325
+ "video",
326
+ "captionTracks",
327
+ "sources"
328
+ ]
329
+ },
330
+ "observe": {
331
+ "type": "object",
332
+ "properties": {
333
+ "title": {
334
+ "type": "string",
335
+ "minLength": 1
336
+ },
337
+ "author_name": {
338
+ "type": "string",
339
+ "minLength": 1
340
+ }
341
+ },
342
+ "required": [
343
+ "title",
344
+ "author_name"
345
+ ]
346
+ }
347
+ }
348
+ ]
349
+ }
@@ -7,12 +7,12 @@ Learned site skills and saved CLI recipes are stored under `~/.browserpaw` (`~/.
7
7
  1. Match by intent or URL before browsing manually (works even before Chrome connects):
8
8
  - `browserpaw recipe find twitter search`
9
9
  - `browserpaw recipe find --url https://x.com/search?q=ai`
10
- - `browserpaw recipe list --all` (includes unvalidated skills and recipe candidates)
10
+ - `browserpaw recipe list` (lists `active` workflows and trusted `bundled` read-only skills; pass `--all` to include unvalidated custom or repaired `candidate` workflows)
11
11
  2. Inspect required inputs and example syntax:
12
12
  - `browserpaw recipe show x-search-thread`
13
- 3. Validate a bundled, proposed, or repaired candidate once:
13
+ 3. Validate a bundled skill or a proposed/repaired candidate once (`SkillDefinition` validation runs its built-in `verification` and `tests` without taking CLI `key=value` inputs, while CLI step recipes validate their read-only steps with required `key=value` inputs):
14
14
  - `browserpaw recipe validate x-search-thread`
15
- - `browserpaw recipe validate x-search query="typescript"`
15
+ - `browserpaw recipe validate site-search query="typescript"`
16
16
  4. Execute directly with typed `KEY=VALUE` inputs (numbers, booleans, and JSON values are coerced from the schema):
17
17
  - `browserpaw recipe run x-search-thread query="typescript" limit=5`
18
18
 
@@ -41,6 +41,7 @@ Save a reviewed JSON file with `browserpaw recipe save FILE` (or `-` via stdin).
41
41
  - Placeholders inside `http(s)://` URLs are URL-encoded automatically; non-URL arguments keep their literal text.
42
42
  - Standalone recipes containing `open` automatically start and clean up a temporary task when called without `--task` or `--tab`. Pass `--task ID` or `--tab ID` to run inside an existing page context. A failure stops at the first failed step and returns its index, command, unexpanded template, completed count, and bounded URL/title/control summary when available.
43
43
  - Verified read-only skill definitions (`startUrl`, `inputSchema`, `outputSchema`, `verification`, `tests`) can also be proposed via `browserpaw recipe save FILE` and activated with `browserpaw recipe validate ID`.
44
+ - Trusted bundled read-only skills synced into `~/.browserpaw` (covering GitHub, X/Twitter, YouTube, Bilibili, Reddit, V2EX, MDN, and npm) are discoverable by default in `recipe find` and `recipe list` (`status: bundled`), auto-validate on first `recipe run`, and auto-upgrade when a newer bundled revision ships (falling back to the previous active version if validation fails, while preserving user-created workflows, disabled skills, and pinned rollbacks). User-proposed or repaired candidates remain `status: candidate` and stay out of default routing until validated with `browserpaw recipe validate ID`.
44
45
  - `recipe validate` automatically runs only candidates made from read-only commands such as `open`, `observe`, `text`, `find`, `wait`, and non-file screenshot reads. Write-capable candidates remain manual and never replace an active workflow through automatic validation.
45
46
  - Successful activation or removal refreshes `~/.browserpaw/learned-index.json` and the installed `SKILL.md` routing table. Candidates stay out of automatic routing.
46
47
  - Keep passwords, tokens, cookies, tab IDs, observed refs, and other transient values out of saved recipes.