@jackwener/opencli 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/browser/cdp.js +5 -0
  2. package/dist/browser/discover.js +11 -7
  3. package/dist/browser/index.d.ts +2 -0
  4. package/dist/browser/index.js +2 -0
  5. package/dist/browser/page.d.ts +4 -0
  6. package/dist/browser/page.js +52 -3
  7. package/dist/browser.test.js +5 -0
  8. package/dist/cli-manifest.json +460 -1
  9. package/dist/cli.js +34 -3
  10. package/dist/clis/apple-podcasts/commands.test.js +26 -3
  11. package/dist/clis/apple-podcasts/top.js +4 -1
  12. package/dist/clis/bluesky/feeds.yaml +29 -0
  13. package/dist/clis/bluesky/followers.yaml +33 -0
  14. package/dist/clis/bluesky/following.yaml +33 -0
  15. package/dist/clis/bluesky/profile.yaml +27 -0
  16. package/dist/clis/bluesky/search.yaml +34 -0
  17. package/dist/clis/bluesky/starter-packs.yaml +34 -0
  18. package/dist/clis/bluesky/thread.yaml +32 -0
  19. package/dist/clis/bluesky/trending.yaml +27 -0
  20. package/dist/clis/bluesky/user.yaml +34 -0
  21. package/dist/clis/twitter/trending.js +29 -61
  22. package/dist/clis/weread/shelf.js +132 -9
  23. package/dist/clis/weread/utils.js +5 -1
  24. package/dist/clis/xiaohongshu/publish.js +78 -42
  25. package/dist/clis/xiaohongshu/publish.test.js +20 -8
  26. package/dist/clis/xiaohongshu/search.d.ts +8 -1
  27. package/dist/clis/xiaohongshu/search.js +20 -1
  28. package/dist/clis/xiaohongshu/search.test.d.ts +1 -1
  29. package/dist/clis/xiaohongshu/search.test.js +32 -1
  30. package/dist/daemon.js +1 -0
  31. package/dist/discovery.js +40 -28
  32. package/dist/doctor.d.ts +1 -2
  33. package/dist/doctor.js +9 -5
  34. package/dist/engine.test.js +42 -0
  35. package/dist/errors.d.ts +1 -1
  36. package/dist/errors.js +2 -2
  37. package/dist/execution.js +45 -13
  38. package/dist/execution.test.d.ts +1 -0
  39. package/dist/execution.test.js +40 -0
  40. package/dist/extension-manifest-regression.test.d.ts +1 -0
  41. package/dist/extension-manifest-regression.test.js +12 -0
  42. package/dist/external.js +6 -1
  43. package/dist/main.js +1 -0
  44. package/dist/plugin-scaffold.d.ts +28 -0
  45. package/dist/plugin-scaffold.js +142 -0
  46. package/dist/plugin-scaffold.test.d.ts +4 -0
  47. package/dist/plugin-scaffold.test.js +83 -0
  48. package/dist/plugin.d.ts +55 -17
  49. package/dist/plugin.js +706 -154
  50. package/dist/plugin.test.js +836 -38
  51. package/dist/runtime.d.ts +1 -0
  52. package/dist/runtime.js +1 -1
  53. package/dist/types.d.ts +2 -0
  54. package/dist/weread-private-api-regression.test.js +185 -0
  55. package/docs/adapters/browser/bluesky.md +53 -0
  56. package/docs/guide/plugins.md +10 -0
  57. package/extension/dist/background.js +4 -2
  58. package/extension/manifest.json +4 -1
  59. package/extension/package-lock.json +2 -2
  60. package/extension/package.json +1 -1
  61. package/extension/src/background.ts +2 -1
  62. package/package.json +1 -1
  63. package/src/browser/cdp.ts +6 -0
  64. package/src/browser/discover.ts +10 -7
  65. package/src/browser/index.ts +2 -0
  66. package/src/browser/page.ts +49 -3
  67. package/src/browser.test.ts +6 -0
  68. package/src/cli.ts +34 -3
  69. package/src/clis/apple-podcasts/commands.test.ts +30 -2
  70. package/src/clis/apple-podcasts/top.ts +4 -1
  71. package/src/clis/bluesky/feeds.yaml +29 -0
  72. package/src/clis/bluesky/followers.yaml +33 -0
  73. package/src/clis/bluesky/following.yaml +33 -0
  74. package/src/clis/bluesky/profile.yaml +27 -0
  75. package/src/clis/bluesky/search.yaml +34 -0
  76. package/src/clis/bluesky/starter-packs.yaml +34 -0
  77. package/src/clis/bluesky/thread.yaml +32 -0
  78. package/src/clis/bluesky/trending.yaml +27 -0
  79. package/src/clis/bluesky/user.yaml +34 -0
  80. package/src/clis/twitter/trending.ts +29 -77
  81. package/src/clis/weread/shelf.ts +169 -9
  82. package/src/clis/weread/utils.ts +6 -1
  83. package/src/clis/xiaohongshu/publish.test.ts +22 -8
  84. package/src/clis/xiaohongshu/publish.ts +93 -52
  85. package/src/clis/xiaohongshu/search.test.ts +39 -1
  86. package/src/clis/xiaohongshu/search.ts +19 -1
  87. package/src/daemon.ts +1 -0
  88. package/src/discovery.ts +41 -33
  89. package/src/doctor.ts +11 -8
  90. package/src/engine.test.ts +38 -0
  91. package/src/errors.ts +6 -2
  92. package/src/execution.test.ts +47 -0
  93. package/src/execution.ts +39 -15
  94. package/src/extension-manifest-regression.test.ts +17 -0
  95. package/src/external.ts +6 -1
  96. package/src/main.ts +1 -0
  97. package/src/plugin-scaffold.test.ts +98 -0
  98. package/src/plugin-scaffold.ts +170 -0
  99. package/src/plugin.test.ts +881 -38
  100. package/src/plugin.ts +871 -158
  101. package/src/runtime.ts +2 -2
  102. package/src/types.ts +2 -0
  103. package/src/weread-private-api-regression.test.ts +207 -0
  104. package/tests/e2e/browser-public.test.ts +1 -1
  105. package/tests/e2e/output-formats.test.ts +10 -14
  106. package/tests/e2e/plugin-management.test.ts +4 -1
  107. package/tests/e2e/public-commands.test.ts +12 -1
  108. package/vitest.config.ts +1 -15
package/src/runtime.ts CHANGED
@@ -30,11 +30,11 @@ export const DEFAULT_BROWSER_EXPLORE_TIMEOUT = parseEnvTimeout('OPENCLI_BROWSER_
30
30
  */
31
31
  export async function runWithTimeout<T>(
32
32
  promise: Promise<T>,
33
- opts: { timeout: number; label?: string },
33
+ opts: { timeout: number; label?: string; hint?: string },
34
34
  ): Promise<T> {
35
35
  const label = opts.label ?? 'Operation';
36
36
  return withTimeoutMs(promise, opts.timeout * 1000,
37
- () => new TimeoutError(label, opts.timeout));
37
+ () => new TimeoutError(label, opts.timeout, opts.hint));
38
38
  }
39
39
 
40
40
  /**
package/src/types.ts CHANGED
@@ -66,4 +66,6 @@ export interface IPage {
66
66
  getInterceptedRequests(): Promise<any[]>;
67
67
  screenshot(options?: ScreenshotOptions): Promise<string>;
68
68
  closeWindow?(): Promise<void>;
69
+ /** Returns the current page URL, or null if unavailable. */
70
+ getCurrentUrl?(): Promise<string | null>;
69
71
  }
@@ -56,6 +56,24 @@ describe('weread private API regression', () => {
56
56
  await expect(fetchPrivateApi(mockPage, '/book/info')).rejects.toThrow('Not logged in');
57
57
  });
58
58
 
59
+ it('maps auth-expired API error codes to AUTH_REQUIRED even on HTTP 200', async () => {
60
+ const mockPage = {
61
+ getCookies: vi.fn().mockResolvedValue([]),
62
+ evaluate: vi.fn(),
63
+ } as any;
64
+
65
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
66
+ ok: true,
67
+ status: 200,
68
+ json: () => Promise.resolve({ errcode: -2012, errmsg: '登录超时' }),
69
+ }));
70
+
71
+ await expect(fetchPrivateApi(mockPage, '/book/info')).rejects.toMatchObject({
72
+ code: 'AUTH_REQUIRED',
73
+ message: 'Not logged in to WeRead',
74
+ });
75
+ });
76
+
59
77
  it('maps non-auth API errors to API_ERROR', async () => {
60
78
  const mockPage = {
61
79
  getCookies: vi.fn().mockResolvedValue([]),
@@ -147,4 +165,193 @@ describe('weread private API regression', () => {
147
165
  },
148
166
  ]);
149
167
  });
168
+
169
+ it('falls back to structured shelf cache when the private API reports AUTH_REQUIRED', async () => {
170
+ const command = getRegistry().get('weread/shelf');
171
+ expect(command?.func).toBeTypeOf('function');
172
+
173
+ const mockPage = {
174
+ getCookies: vi.fn()
175
+ .mockResolvedValueOnce([
176
+ { name: 'wr_skey', value: 'skey123', domain: '.weread.qq.com' },
177
+ ])
178
+ .mockResolvedValueOnce([
179
+ { name: 'wr_vid', value: 'vid-current', domain: '.weread.qq.com' },
180
+ ]),
181
+ goto: vi.fn().mockResolvedValue(undefined),
182
+ evaluate: vi.fn().mockImplementation(async (source: string) => {
183
+ expect(source).toContain('shelf:rawBooks:vid-current');
184
+ expect(source).toContain('shelf:shelfIndexes:vid-current');
185
+ return {
186
+ cacheFound: true,
187
+ rawBooks: [
188
+ {
189
+ bookId: '40055543',
190
+ title: '置身事内:中国政府与经济发展',
191
+ author: '兰小欢',
192
+ },
193
+ {
194
+ bookId: '29196155',
195
+ title: '文明、现代化、价值投资与中国',
196
+ author: '李录',
197
+ },
198
+ ],
199
+ shelfIndexes: [
200
+ { bookId: '29196155', idx: 0, role: 'book' },
201
+ { bookId: '40055543', idx: 1, role: 'book' },
202
+ ],
203
+ lastChapters: {
204
+ '29196155': 40,
205
+ '40055543': 60,
206
+ },
207
+ };
208
+ }),
209
+ } as any;
210
+
211
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
212
+ ok: false,
213
+ status: 401,
214
+ json: () => Promise.resolve({ errcode: -2012, errmsg: '登录超时' }),
215
+ }));
216
+
217
+ const result = await command!.func!(mockPage, { limit: 1 });
218
+
219
+ expect(mockPage.goto).toHaveBeenCalledWith('https://weread.qq.com/web/shelf');
220
+ expect(mockPage.getCookies).toHaveBeenCalledWith({ domain: 'weread.qq.com' });
221
+ expect(mockPage.evaluate).toHaveBeenCalledTimes(1);
222
+ expect(result).toEqual([
223
+ {
224
+ title: '文明、现代化、价值投资与中国',
225
+ author: '李录',
226
+ progress: '-',
227
+ bookId: '29196155',
228
+ },
229
+ ]);
230
+ });
231
+
232
+ it('rethrows AUTH_REQUIRED when the current session has no structured shelf cache', async () => {
233
+ const command = getRegistry().get('weread/shelf');
234
+ expect(command?.func).toBeTypeOf('function');
235
+
236
+ const mockPage = {
237
+ getCookies: vi.fn()
238
+ .mockResolvedValueOnce([
239
+ { name: 'wr_skey', value: 'skey123', domain: '.weread.qq.com' },
240
+ ])
241
+ .mockResolvedValueOnce([
242
+ { name: 'wr_vid', value: 'vid-current', domain: '.weread.qq.com' },
243
+ ]),
244
+ goto: vi.fn().mockResolvedValue(undefined),
245
+ evaluate: vi.fn().mockResolvedValue({
246
+ cacheFound: false,
247
+ rawBooks: [],
248
+ shelfIndexes: [],
249
+ lastChapters: {},
250
+ }),
251
+ } as any;
252
+
253
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
254
+ ok: false,
255
+ status: 401,
256
+ json: () => Promise.resolve({ errcode: -2012, errmsg: '登录超时' }),
257
+ }));
258
+
259
+ await expect(command!.func!(mockPage, { limit: 20 })).rejects.toMatchObject({
260
+ code: 'AUTH_REQUIRED',
261
+ message: 'Not logged in to WeRead',
262
+ });
263
+ expect(mockPage.goto).toHaveBeenCalledWith('https://weread.qq.com/web/shelf');
264
+ expect(mockPage.getCookies).toHaveBeenCalledWith({ domain: 'weread.qq.com' });
265
+ });
266
+
267
+ it('returns an empty list when the current session cache is confirmed but empty', async () => {
268
+ const command = getRegistry().get('weread/shelf');
269
+ expect(command?.func).toBeTypeOf('function');
270
+
271
+ const mockPage = {
272
+ getCookies: vi.fn()
273
+ .mockResolvedValueOnce([
274
+ { name: 'wr_skey', value: 'skey123', domain: '.weread.qq.com' },
275
+ ])
276
+ .mockResolvedValueOnce([
277
+ { name: 'wr_vid', value: 'vid-current', domain: '.weread.qq.com' },
278
+ ]),
279
+ goto: vi.fn().mockResolvedValue(undefined),
280
+ evaluate: vi.fn().mockResolvedValue({
281
+ cacheFound: true,
282
+ rawBooks: [],
283
+ shelfIndexes: [],
284
+ lastChapters: {},
285
+ }),
286
+ } as any;
287
+
288
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
289
+ ok: false,
290
+ status: 401,
291
+ json: () => Promise.resolve({ errcode: -2012, errmsg: '登录超时' }),
292
+ }));
293
+
294
+ const result = await command!.func!(mockPage, { limit: 20 });
295
+
296
+ expect(mockPage.goto).toHaveBeenCalledWith('https://weread.qq.com/web/shelf');
297
+ expect(mockPage.getCookies).toHaveBeenCalledWith({ domain: 'weread.qq.com' });
298
+ expect(result).toEqual([]);
299
+ });
300
+
301
+ it('falls back to raw book cache order when shelf indexes are unavailable', async () => {
302
+ const command = getRegistry().get('weread/shelf');
303
+ expect(command?.func).toBeTypeOf('function');
304
+
305
+ const mockPage = {
306
+ getCookies: vi.fn()
307
+ .mockResolvedValueOnce([
308
+ { name: 'wr_skey', value: 'skey123', domain: '.weread.qq.com' },
309
+ ])
310
+ .mockResolvedValueOnce([
311
+ { name: 'wr_vid', value: 'vid-current', domain: '.weread.qq.com' },
312
+ ]),
313
+ goto: vi.fn().mockResolvedValue(undefined),
314
+ evaluate: vi.fn().mockResolvedValue({
315
+ cacheFound: true,
316
+ rawBooks: [
317
+ {
318
+ bookId: '40055543',
319
+ title: '置身事内:中国政府与经济发展',
320
+ author: '兰小欢',
321
+ },
322
+ {
323
+ bookId: '29196155',
324
+ title: '文明、现代化、价值投资与中国',
325
+ author: '李录',
326
+ },
327
+ ],
328
+ shelfIndexes: [],
329
+ }),
330
+ } as any;
331
+
332
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
333
+ ok: false,
334
+ status: 401,
335
+ json: () => Promise.resolve({ errcode: -2012, errmsg: '登录超时' }),
336
+ }));
337
+
338
+ const result = await command!.func!(mockPage, { limit: 2 });
339
+
340
+ expect(mockPage.getCookies).toHaveBeenCalledWith({ url: 'https://i.weread.qq.com/shelf/sync?synckey=0&lectureSynckey=0' });
341
+ expect(mockPage.getCookies).toHaveBeenCalledWith({ domain: 'weread.qq.com' });
342
+ expect(result).toEqual([
343
+ {
344
+ title: '置身事内:中国政府与经济发展',
345
+ author: '兰小欢',
346
+ progress: '-',
347
+ bookId: '40055543',
348
+ },
349
+ {
350
+ title: '文明、现代化、价值投资与中国',
351
+ author: '李录',
352
+ progress: '-',
353
+ bookId: '29196155',
354
+ },
355
+ ]);
356
+ });
150
357
  });
@@ -35,7 +35,7 @@ function isImdbChallenge(result: CliResult): boolean {
35
35
 
36
36
  function isBrowserBridgeUnavailable(result: CliResult): boolean {
37
37
  const text = `${result.stderr}\n${result.stdout}`;
38
- return /Browser Extension is not connected|Browser Bridge extension.*not connected|Daemon is running but the Browser Extension is not connected/i.test(text);
38
+ return /Browser Bridge.*not connected|Extension.*not connected/i.test(text);
39
39
  }
40
40
 
41
41
  async function expectImdbDataOrChallengeSkip(args: string[], label: string): Promise<any[] | null> {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * E2E tests for output format rendering.
3
- * Uses hackernews (public, fast) as a stable data source.
3
+ * Uses the built-in list command so renderer coverage does not depend on
4
+ * external network availability.
4
5
  */
5
6
 
6
7
  import { describe, it, expect } from 'vitest';
@@ -10,19 +11,22 @@ const FORMATS = ['json', 'yaml', 'csv', 'md'] as const;
10
11
 
11
12
  describe('output formats E2E', () => {
12
13
  for (const fmt of FORMATS) {
13
- it(`hackernews top -f ${fmt} produces valid output`, async () => {
14
- const { stdout, code } = await runCli(['hackernews', 'top', '--limit', '2', '-f', fmt]);
14
+ it(`list -f ${fmt} produces valid output`, async () => {
15
+ const { stdout, code } = await runCli(['list', '-f', fmt]);
15
16
  expect(code).toBe(0);
16
17
  expect(stdout.trim().length).toBeGreaterThan(0);
17
18
 
18
19
  if (fmt === 'json') {
19
20
  const data = parseJsonOutput(stdout);
20
21
  expect(Array.isArray(data)).toBe(true);
21
- expect(data.length).toBe(2);
22
+ expect(data.length).toBeGreaterThan(50);
23
+ expect(data[0]).toHaveProperty('command');
24
+ expect(data[0]).toHaveProperty('site');
22
25
  }
23
26
 
24
27
  if (fmt === 'yaml') {
25
- expect(stdout).toContain('title:');
28
+ expect(stdout).toContain('command:');
29
+ expect(stdout).toContain('site:');
26
30
  }
27
31
 
28
32
  if (fmt === 'csv') {
@@ -33,16 +37,8 @@ describe('output formats E2E', () => {
33
37
 
34
38
  if (fmt === 'md') {
35
39
  // Markdown table should have pipe characters
36
- expect(stdout).toContain('|');
40
+ expect(stdout).toContain('| command |');
37
41
  }
38
42
  }, 30_000);
39
43
  }
40
-
41
- it('list -f csv produces valid csv', async () => {
42
- const { stdout, code } = await runCli(['list', '-f', 'csv']);
43
- expect(code).toBe(0);
44
- const lines = stdout.trim().split('\n');
45
- // Header + many data lines
46
- expect(lines.length).toBeGreaterThan(50);
47
- });
48
44
  });
@@ -60,7 +60,10 @@ describe('plugin management E2E', () => {
60
60
  const lock = JSON.parse(fs.readFileSync(LOCK_FILE, 'utf-8'));
61
61
  expect(lock[PLUGIN_NAME]).toBeDefined();
62
62
  expect(lock[PLUGIN_NAME].commitHash).toBeTruthy();
63
- expect(lock[PLUGIN_NAME].source).toContain('opencli-plugin-hot-digest');
63
+ expect(lock[PLUGIN_NAME].source).toMatchObject({
64
+ kind: 'git',
65
+ });
66
+ expect(lock[PLUGIN_NAME].source.url).toContain('opencli-plugin-hot-digest');
64
67
  expect(lock[PLUGIN_NAME].installedAt).toBeTruthy();
65
68
  }, 60_000);
66
69
 
@@ -21,7 +21,7 @@ function isExpectedChineseSiteRestriction(code: number, stderr: string): boolean
21
21
 
22
22
  function isExpectedApplePodcastsRestriction(code: number, stderr: string): boolean {
23
23
  if (code === 0) return false;
24
- return /Error \[FETCH_ERROR\]: (Charts API HTTP \d+|Unable to reach Apple Podcasts charts)/.test(stderr)
24
+ return /(?:Error \[FETCH_ERROR\]: )?(Charts API HTTP \d+|Unable to reach Apple Podcasts charts)/.test(stderr)
25
25
  || stderr === ''; // timeout killed the process before any output
26
26
  }
27
27
 
@@ -34,6 +34,17 @@ function isExpectedGoogleRestriction(code: number, stderr: string): boolean {
34
34
  // Keep old name as alias for existing tests
35
35
  const isExpectedXiaoyuzhouRestriction = isExpectedChineseSiteRestriction;
36
36
 
37
+ describe('public command restriction detectors', () => {
38
+ it('treats current Apple Podcasts CliError rendering as an expected restriction', () => {
39
+ expect(
40
+ isExpectedApplePodcastsRestriction(
41
+ 1,
42
+ '⚠️ Unable to reach Apple Podcasts charts for US\n→ Apple charts may be temporarily unavailable (ECONNRESET). Try again later.\n',
43
+ ),
44
+ ).toBe(true);
45
+ });
46
+ });
47
+
37
48
  describe('public commands E2E', () => {
38
49
  // ── bloomberg (RSS-backed, browser: false) ──
39
50
  it('bloomberg main returns structured headline data', async () => {
package/vitest.config.ts CHANGED
@@ -16,21 +16,7 @@ export default defineConfig({
16
16
  {
17
17
  test: {
18
18
  name: 'adapter',
19
- include: [
20
- 'src/clis/bilibili/**/*.test.ts',
21
- 'src/clis/imdb/**/*.test.ts',
22
- 'src/clis/jd/**/*.test.ts',
23
- 'src/clis/linux-do/**/*.test.ts',
24
- 'src/clis/xiaohongshu/**/*.test.ts',
25
- 'src/clis/twitter/**/*.test.ts',
26
- 'src/clis/douban/**/*.test.ts',
27
- 'src/clis/zhihu/**/*.test.ts',
28
- 'src/clis/v2ex/**/*.test.ts',
29
- 'src/clis/weread/**/*.test.ts',
30
- 'src/clis/36kr/**/*.test.ts',
31
- 'src/clis/producthunt/**/*.test.ts',
32
- 'src/clis/paperreview/**/*.test.ts',
33
- ],
19
+ include: ['src/clis/**/*.test.ts'],
34
20
  sequence: { groupOrder: 1 },
35
21
  },
36
22
  },